#include <SDL.h>
#include <msp/gl/rendermode.h>
#include <msp/gl/select.h>
+#include <msp/gl/texture2d.h>
#include <msp/strings/codec.h>
#include <msp/strings/lexicalcast.h>
#include <msp/strings/utf8.h>
#include <msp/strings/utils.h>
#include <msp/time/units.h>
#include <msp/time/utils.h>
+#include "libmarklin/tracktype.h"
#include "designer.h"
#include "input.h"
#include "manipulator.h"
cat_layout=new Layout(catalogue);
cat_layout_3d=new Layout3D(*cat_layout);
- const Catalogue::TrackMap &ctracks=catalogue.get_tracks();
+ const map<unsigned, TrackType *> &ctracks=catalogue.get_tracks();
unsigned n=0;
- for(Catalogue::TrackMap::const_iterator i=ctracks.begin(); i!=ctracks.end(); ++i, ++n)
+ for(map<unsigned, TrackType *>::const_iterator i=ctracks.begin(); i!=ctracks.end(); ++i, ++n)
{
- Track *track=i->second->copy();
+ Track *track=new Track(*i->second);
track->set_position(Point((n%11)*0.1-0.5, 0.2-n/11*0.3, 0));
track->set_rotation(M_PI/2);
- cat_layout->add_track(track);
+ cat_layout->add_track(*track);
}
manipulator=new Manipulator(*this);
if(argc>1)
{
layout->load(argv[1]);
- const Track3DSeq <racks=layout_3d->get_tracks();
- for(Track3DSeq::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
+ const list<Track3D *> <racks=layout_3d->get_tracks();
+ for(list<Track3D *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
{
if((*i)->get_track().get_sensor_id())
- (*i)->set_color(Color(1, 1, 0.5));
+ (*i)->set_color(GL::Color(1, 1, 0.5));
else if((*i)->get_track().get_turnout_id())
- (*i)->set_color(Color(0.5, 1, 1));
+ (*i)->set_color(GL::Color(0.5, 1, 1));
else if((*i)->get_track().get_flex())
- (*i)->set_color(Color(1, 0.5, 1));
+ (*i)->set_color(GL::Color(1, 0.5, 1));
}
}
measure->signal_done.connect(sigc::mem_fun(this, &Designer::measure_done));
}
+Designer::~Designer()
+{
+ delete manipulator;
+ delete selection;
+ delete layout;
+ delete layout_3d;
+ delete cat_layout;
+ delete cat_layout_3d;
+ delete measure;
+}
+
int Designer::main()
{
setenv("__GL_SYNC_TO_VBLANK", "1", 0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_CULL_FACE);
+ GL::Texture2D *font_tex=new GL::Texture2D;
+ font_tex->set_min_filter(GL::LINEAR);
+ font_tex->load_image("dejavu-20.png");
font=new GL::Font();
- Parser::load(*font, "dejavu-20.font");
+ font->set_texture(*font_tex);
+ DataFile::load(*font, "dejavu-20.font");
mode=SELECT;
Application::main();
delete font;
+ delete font_tex;
delete input;
SDL_Quit();
float uy=sin_yaw*-sin_pitch*0.41421;
float uz=cos_pitch*0.41421;
- float xf=(float)x*2/screen_w-1;
- float yf=1-(float)y*2/screen_h;
+ float xf=static_cast<float>(x)*2/screen_w-1;
+ float yf=1-static_cast<float>(y)*2/screen_h;
float vx=cos_yaw*cos_pitch + xf*rx + yf*ux;
float vy=sin_yaw*cos_pitch + xf*ry + yf*uy;
SDL_Event event;
while(SDL_PollEvent(&event))
{
- float gx,gy;
+ float gx, gy;
switch(event.type)
{
case SDL_MOUSEBUTTONDOWN:
if(t3d)
{
const Track &track=t3d->get_track();
+ const TrackType &ttype=track.get_type();
ostringstream ss;
ss.precision(2);
- ss<<track.get_article_number()<<' '<<track.get_description();
+ ss<<ttype.get_article_number()<<' '<<ttype.get_description();
if(mode!=CATALOGUE)
- ss<<" (slope "<<track.get_slope()/track.get_length()*100<<"%)";
+ ss<<" (slope "<<track.get_slope()/ttype.get_total_length()*100<<"%)";
if(track.get_turnout_id())
ss<<" (turnout "<<track.get_turnout_id()<<')';
else if(track.get_sensor_id())
ss<<" (sensor "<<track.get_sensor_id()<<')';
- tooltip=decode<Utf8>(ss.str());
+ tooltip=ss.str();
move_tooltip(pointer_x, pointer_y);
}
else
- tooltip=L"";
+ tooltip="";
tooltip_timeout=Time::TimeStamp();
}
SDL_GL_SwapBuffers();
}
-Designer::~Designer()
-{
- delete manipulator;
- delete selection;
- delete layout;
- delete layout_3d;
- delete cat_layout;
- delete cat_layout_3d;
- delete measure;
-}
-
/*** private ***/
void Designer::key_press(unsigned key, unsigned mod, wchar_t ch)
selection->select_more();
else if(key==SDLK_l && (mod&KMOD_SHIFT))
{
- const TrackSeq &tracks=layout->get_tracks();
+ const set<Track *> &tracks=layout->get_tracks();
float len=0;
- for(TrackSeq::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
- len+=(*i)->get_total_length();
+ for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ len+=(*i)->get_type().get_total_length();
cout<<"Total length: "<<len<<"m\n";
}
else if(key==SDLK_l)
}
else if(key==SDLK_x)
{
- Selection::TrackSet tracks=selection->get_tracks();
+ set<Track *> tracks=selection->get_tracks();
selection->clear();
- for(Selection::TrackSet::iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
{
- layout->remove_track(*i);
+ layout->remove_track(**i);
delete *i;
}
}
else if(key==SDLK_f && (mod&KMOD_SHIFT))
{
- const Selection::TrackSet &tracks=selection->get_tracks();
- const TrackSeq <racks=layout->get_tracks();
- for(Selection::TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ const set<Track *> &tracks=selection->get_tracks();
+ const set<Track *> <racks=layout->get_tracks();
+ for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
{
(*i)->set_flex(!(*i)->get_flex());
(*i)->break_links();
- for(TrackSeq::const_iterator j=ltracks.begin(); j!=ltracks.end(); ++j)
+ for(set<Track *>::const_iterator j=ltracks.begin(); j!=ltracks.end(); ++j)
if(*j!=*i)
(*i)->snap_to(**j, true);
- Track3D *t3d=layout_3d->get_track(*i);
+ Track3D &t3d=layout_3d->get_track(**i);
if((*i)->get_flex())
- t3d->set_color(Color(1, 0.5, 1));
+ t3d.set_color(GL::Color(1, 0.5, 1));
else
- t3d->set_color(Color(1, 1, 1));
+ t3d.set_color(GL::Color(1, 1, 1));
}
}
else if(key==SDLK_f)
else if(key==SDLK_t)
{
Track *track=selection->get_track();
- if(selection->size()==1 && track->get_n_routes()>1)
+ if(selection->size()==1 && track->get_type().get_n_routes()>1)
{
ostringstream ss;
ss<<track->get_turnout_id();
else if(key==SDLK_s)
{
Track *track=selection->get_track();
- if(selection->size()==1 && track->get_n_routes()==1)
+ if(selection->size()==1 && track->get_type().get_n_routes()==1)
{
ostringstream ss;
ss<<track->get_sensor_id();
{
Track *track=ctrack->get_track().copy();
track->set_position(Point(gx, gy, 0));
- layout->add_track(track);
+ layout->add_track(*track);
selection->clear();
selection->add_track(track);
measure->render();
}
- /*glBegin(GL_LINES);
- glColor4f(1, 0, 0, 1);
- glVertex3f(0, 0, 0);
- glVertex3f(0.5, 0, 0);
- glColor4f(0, 1, 0, 1);
- glVertex3f(0, 0, 0);
- glVertex3f(0, 0.5, 0);
- glColor4f(0, 0, 1, 1);
- glVertex3f(0, 0, 0);
- glVertex3f(0, 0, 0.5);
- glEnd();*/
-
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, screen_w, 0, screen_h, 0, 1);
if(mode==CATALOGUE)
l=cat_layout_3d;
- float xx=((float)(x-(int)screen_w/2)/screen_h)*0.82843;
- float yy=((float)y/screen_h-0.5)*0.82843;
- float size=(float)4/screen_h*0.82843;
+ float xx=(static_cast<float>(x-static_cast<int>(screen_w)/2)/screen_h)*0.82843;
+ float yy=(static_cast<float>(y)/screen_h-0.5)*0.82843;
+ float size=4.0/screen_h*0.82843;
project_3d();
apply_camera();
void Designer::manipulation_status(const string &status)
{
- tooltip=decode<Utf8>(status);
+ tooltip=status;
}
void Designer::manipulation_done(bool)
ostringstream ss;
ss.precision(3);
ss<<"Par "<<pard<<"mm - Perp "<<perpd<<"mm - Total "<<d<<"mm - Angle "<<adiff<<"°";
- tooltip=decode<Utf8>(ss.str());
+ tooltip=ss.str();
}
void Designer::measure_done()
void Designer::move_tooltip(int x, int y)
{
- int w=(int)(font->get_string_width(tooltip)*20);
- tooltip_x=max(min((int)screen_w-w, x), 0);
- tooltip_y=max(min((int)screen_h-20, y), 0);
+ int w=static_cast<int>(font->get_string_width(tooltip)*20);
+ tooltip_x=max(min(static_cast<int>(screen_w)-w, x), 0);
+ tooltip_y=max(min(static_cast<int>(screen_h)-20, y), 0);
}
void Designer::save_accept()
unsigned id=lexical_cast<unsigned>(input->get_text());
track->set_turnout_id(id);
- Track3D *t3d=layout_3d->get_track(track);
+ Track3D &t3d=layout_3d->get_track(*track);
if(id)
- t3d->set_color(Color(0.5, 1, 1));
+ t3d.set_color(GL::Color(0.5, 1, 1));
else
- t3d->set_color(Color(1, 1, 1));
+ t3d.set_color(GL::Color(1, 1, 1));
input_dismiss();
}
unsigned id=lexical_cast<unsigned>(input->get_text());
track->set_sensor_id(id);
- Track3D *t3d=layout_3d->get_track(track);
+ Track3D &t3d=layout_3d->get_track(*track);
if(id)
- t3d->set_color(Color(1, 1, 0.5));
+ t3d.set_color(GL::Color(1, 1, 0.5));
else
- t3d->set_color(Color(1, 1, 1));
+ t3d.set_color(GL::Color(1, 1, 1));
input_dismiss();
}