]> git.tdb.fi Git - r2c2.git/blob - source/designer/designer.cpp
Use Msp::IO::print instead of std::cout
[r2c2.git] / source / designer / designer.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <signal.h>
9 #include <cmath>
10 #include <GL/gl.h>
11 #include <msp/gl/matrix.h>
12 #include <msp/gl/misc.h>
13 #include <msp/gl/projection.h>
14 #include <msp/gl/rendermode.h>
15 #include <msp/gl/select.h>
16 #include <msp/gl/tests.h>
17 #include <msp/gl/texture2d.h>
18 #include <msp/input/keys.h>
19 #include <msp/io/print.h>
20 #include <msp/strings/codec.h>
21 #include <msp/strings/lexicalcast.h>
22 #include <msp/strings/utf8.h>
23 #include <msp/strings/utils.h>
24 #include <msp/time/units.h>
25 #include <msp/time/utils.h>
26 #include "libmarklin/tracktype.h"
27 #include "designer.h"
28 #include "input.h"
29 #include "manipulator.h"
30 #include "measure.h"
31 #include "selection.h"
32 #include "toolbar.h"
33
34 using namespace std;
35 using namespace Marklin;
36 using namespace Msp;
37
38 Application::RegApp<Designer> Designer::reg;
39
40 Designer::Designer(int argc, char **argv):
41         screen_w(1280),
42         screen_h(960),
43         base_mesh(0),
44         cur_route(0),
45         mode(SELECT),
46         input(0),
47         cam_yaw(M_PI/2),
48         cam_pitch(-M_PI/4),
49         cam_pos(0, -0.5, 0.5),
50         shift(false),
51         move_x(0),
52         move_y(0),
53         zoom(0),
54         rotate(0),
55         pitch(0)
56 {
57         DataFile::load(catalogue, "tracks.dat");
58
59         cat_layout = new Layout(catalogue);
60         cat_layout_3d = new Layout3D(*cat_layout);
61
62         const map<unsigned, TrackType *> &ctracks = catalogue.get_tracks();
63         unsigned n = 0;
64         for(map<unsigned, TrackType *>::const_iterator i=ctracks.begin(); i!=ctracks.end(); ++i, ++n)
65         {
66                 Track *track = new Track(*i->second);
67                 track->set_position(Point((n%11)*0.1-0.5, 0.2-n/11*0.3, 0));
68                 track->set_rotation(M_PI/2);
69                 cat_layout->add_track(*track);
70         }
71
72         manipulator = new Manipulator(*this);
73         manipulator->signal_status.connect(sigc::mem_fun(this, &Designer::manipulation_status));
74         manipulator->signal_done.connect(sigc::mem_fun(this, &Designer::manipulation_done));
75
76         layout = new Layout(catalogue);
77         layout_3d = new Layout3D(*layout);
78
79         if(argc>1)
80         {
81                 filename = argv[1];
82                 DataFile::load(*layout, argv[1]);
83                 const list<Track3D *> &ltracks = layout_3d->get_tracks();
84                 for(list<Track3D *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
85                         update_track_color(**i);
86
87                 if(!layout->get_base().empty())
88                 {
89                         base_mesh = new GL::Mesh;
90                         DataFile::load(*base_mesh, layout->get_base());
91                 }
92         }
93
94         selection = new Selection;
95         manipulator->set_selection(selection);
96
97         measure = new Measure(*this);
98         measure->signal_changed.connect(sigc::mem_fun(this, &Designer::measure_changed));
99         measure->signal_done.connect(sigc::mem_fun(this, &Designer::measure_done));
100 }
101
102 Designer::~Designer()
103 {
104         delete manipulator;
105         delete selection;
106         delete layout;
107         delete layout_3d;
108         delete cat_layout;
109         delete cat_layout_3d;
110         delete measure;
111 }
112
113 int Designer::main()
114 {
115         dpy = new Graphics::Display;
116         wnd = new Graphics::Window(*dpy, screen_w, screen_h);
117         glc = new Graphics::GLContext(*wnd);
118         wnd->set_title("Railway Designer");
119
120         wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &Designer::exit), 0));
121         wnd->show();
122
123         glEnableClientState(GL_VERTEX_ARRAY);
124         glEnable(GL_DEPTH_TEST);
125         glEnable(GL_BLEND);
126         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
127         glEnable(GL_CULL_FACE);
128
129         DataFile::load(ui_res, "marklin.res");
130         root = new GLtk::Root(ui_res, *wnd);
131
132         lbl_tooltip = new GLtk::Label(ui_res);
133         lbl_tooltip->set_style("tooltip");
134         root->add(*lbl_tooltip);
135         lbl_tooltip->set_visible(false);
136
137         toolbar = new Toolbar(*this);
138         root->add(*toolbar);
139         toolbar->set_position(0, screen_h-toolbar->get_geometry().h);
140         toolbar->set_visible(true);
141
142
143         wnd->signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press));
144         wnd->signal_key_release.connect(sigc::mem_fun(this, &Designer::key_release));
145         wnd->signal_button_press.connect(sigc::mem_fun(this, &Designer::button_press));
146         wnd->signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion));
147
148         mode = SELECT;
149
150         Application::main();
151
152         delete root;
153
154         delete glc;
155         delete wnd;
156         delete dpy;
157
158         return exit_code;
159 }
160
161 void Designer::save()
162 {
163         input = new ::Input(*this, "Save layout", filename);
164         input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
165         input->signal_accept.connect(sigc::mem_fun(this, &Designer::save_accept));
166         mode = INPUT;
167 }
168
169 void Designer::quit()
170 {
171         exit(0);
172 }
173
174 void Designer::edit_route(Route &r)
175 {
176         cur_route = &r;
177 }
178
179 void Designer::add_selection_to_route()
180 {
181         if(!cur_route)
182                 return;
183
184         try
185         {
186                 const set<Track *> &stracks = selection->get_tracks();
187                 set<const Track *> tracks(stracks.begin(), stracks.end());
188                 cur_route->add_tracks(tracks);
189         }
190         catch(const Exception &e)
191         {
192                 IO::print("%s\n", e.what());
193         }
194 }
195
196 void Designer::map_pointer_coords(int x, int y, float &gx, float &gy)
197 {
198         float cos_pitch = cos(cam_pitch);
199         float sin_pitch = sin(cam_pitch);
200         float cos_yaw = cos(cam_yaw);
201         float sin_yaw = sin(cam_yaw);
202
203         float rx = sin_yaw*0.55228;
204         float ry = -cos_yaw*0.55228;
205
206         float ux = cos_yaw*-sin_pitch*0.41421;
207         float uy = sin_yaw*-sin_pitch*0.41421;
208         float uz = cos_pitch*0.41421;
209
210         float xf = static_cast<float>(x)*2/screen_w-1;
211         float yf = static_cast<float>(y)*2/screen_h-1;
212
213         float vx = cos_yaw*cos_pitch + xf*rx + yf*ux;
214         float vy = sin_yaw*cos_pitch + xf*ry + yf*uy;
215         float vz = sin_pitch + yf*uz;
216
217         gx = cam_pos.x-vx*cam_pos.z/vz;
218         gy = cam_pos.y-vy*cam_pos.z/vz;
219 }
220
221 void Designer::tick()
222 {
223         const Msp::Time::TimeStamp t = Msp::Time::now();
224         float dt = (t-last_tick)/Msp::Time::sec;
225         last_tick = t;
226
227         dpy->tick();
228
229         if(move_y)
230         {
231                 cam_pos.x += cos(cam_yaw)*dt*move_y;
232                 cam_pos.y += sin(cam_yaw)*dt*move_y;
233         }
234         if(move_x)
235         {
236                 cam_pos.x += sin(cam_yaw)*dt*move_x;
237                 cam_pos.y += -cos(cam_yaw)*dt*move_x;
238         }
239         if(zoom)
240         {
241                 cam_pos.x += cos(cam_yaw)*cos(cam_pitch)*dt*zoom;
242                 cam_pos.y += sin(cam_yaw)*cos(cam_pitch)*dt*zoom;
243                 cam_pos.z += sin(cam_pitch)*dt*zoom;
244         }
245         if(rotate)
246         {
247                 float vx = cos(cam_yaw)*cos(cam_pitch);
248                 float vy = sin(cam_yaw)*cos(cam_pitch);
249                 float vz = sin(cam_pitch);
250
251                 float gx = cam_pos.x-vx*cam_pos.z/vz;
252                 float gy = cam_pos.y-vy*cam_pos.z/vz;
253                 float d = sqrt(vx*vx+vy*vy)*cam_pos.z/vz;
254
255                 cam_yaw += M_PI*dt*rotate;
256                 if(cam_yaw>M_PI*2)
257                         cam_yaw -= M_PI*2;
258                 else if(cam_yaw<0)
259                         cam_yaw += M_PI*2;
260
261                 cam_pos.x = gx+cos(cam_yaw)*d;
262                 cam_pos.y = gy+sin(cam_yaw)*d;
263         }
264         if(pitch)
265         {
266                 cam_pitch += M_PI/2*dt*pitch;
267                 if(cam_pitch>M_PI/12)
268                         cam_pitch = M_PI/12;
269                 else if(cam_pitch<-M_PI/2)
270                         cam_pitch = -M_PI/2;
271         }
272
273         if(tooltip_timeout && t>tooltip_timeout)
274         {
275                 Track3D *t3d = 0;
276
277                 if(mode==CATALOGUE)
278                         t3d = pick_track(pointer_x, pointer_y);
279                 else
280                         t3d = pick_track(pointer_x, pointer_y);
281
282                 if(t3d)
283                 {
284                         const Track &track = t3d->get_track();
285                         const TrackType &ttype = track.get_type();
286                         string info = format("%d %s", ttype.get_article_number(), ttype.get_description());
287                         if(mode!=CATALOGUE && abs(track.get_slope())>1e-4)
288                                 info += format(" (slope %.1f%%)", abs(track.get_slope()/ttype.get_total_length()*100));
289                         if(track.get_turnout_id())
290                                 info += format(" (turnout %d)", track.get_turnout_id());
291                         else if(track.get_sensor_id())
292                                 info += format(" (sensor %d)", track.get_sensor_id());
293
294                         set_tooltip(pointer_x, pointer_y, info);
295                 }
296                 else
297                         clear_tooltip();
298
299                 tooltip_timeout = Msp::Time::TimeStamp();
300         }
301
302         render();
303
304         glc->swap_buffers();
305 }
306
307 void Designer::key_press(unsigned code, unsigned mod, wchar_t)
308 {
309         unsigned key = Msp::Input::key_from_sys(code);
310
311         if(mode==INPUT)
312                 return;
313
314         if(key==Msp::Input::KEY_SHIFT_L || key==Msp::Input::KEY_SHIFT_R)
315                 shift = true;
316
317         if(key==Msp::Input::KEY_N)
318                 mode = CATALOGUE;
319         else if(key==Msp::Input::KEY_G)
320         {
321                 manipulator->start_move();
322                 mode = MANIPULATE;
323         }
324         else if(key==Msp::Input::KEY_R)
325         {
326                 manipulator->start_rotate();
327                 mode = MANIPULATE;
328         }
329         else if(key==Msp::Input::KEY_D)
330         {
331                 manipulator->duplicate();
332                 manipulator->start_move();
333                 mode = MANIPULATE;
334         }
335         else if(key==Msp::Input::KEY_W)
336                 save();
337         else if(key==Msp::Input::KEY_PLUS)
338                 selection->select_more();
339         else if(key==Msp::Input::KEY_L && (mod&1))
340         {
341                 const set<Track *> &tracks = layout->get_tracks();
342                 float len = 0;
343                 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
344                         len += (*i)->get_type().get_total_length();
345                 IO::print("Total length: %.1fm\n", len);
346         }
347         else if(key==Msp::Input::KEY_L)
348                 selection->select_linked();
349         else if(key==Msp::Input::KEY_M)
350         {
351                 measure->start();
352                 mode = MEASURE;
353         }
354         else if(key==Msp::Input::KEY_Z)
355         {
356                 manipulator->start_elevate();
357                 mode = MANIPULATE;
358         }
359         else if(key==Msp::Input::KEY_ESC)
360         {
361                 if(mode==MANIPULATE)
362                         manipulator->cancel();
363                 else if(mode==CATALOGUE)
364                         mode = SELECT;
365                 else
366                         selection->clear();
367         }
368         else if(key==Msp::Input::KEY_X)
369         {
370                 set<Track *> tracks = selection->get_tracks();
371                 selection->clear();
372                 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
373                 {
374                         layout->remove_track(**i);
375                         delete *i;
376                 }
377         }
378         else if(key==Msp::Input::KEY_F && (mod&1))
379         {
380                 const set<Track *> &tracks = selection->get_tracks();
381                 const set<Track *> &ltracks = layout->get_tracks();
382                 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
383                 {
384                         (*i)->set_flex(!(*i)->get_flex());
385                         (*i)->break_links();
386                         for(set<Track *>::const_iterator j=ltracks.begin(); j!=ltracks.end(); ++j)
387                                 if(*j!=*i)
388                                         (*i)->snap_to(**j, true);
389
390                         update_track_color(layout_3d->get_track(**i));
391                 }
392         }
393         else if(key==Msp::Input::KEY_F)
394                 manipulator->flatten();
395         else if(key==Msp::Input::KEY_E && (mod&1))
396                 manipulator->even_slope(true);
397         else if(key==Msp::Input::KEY_E)
398                 manipulator->even_slope();
399         else if(key==Msp::Input::KEY_T)
400         {
401                 Track *track = selection->get_track();
402                 if(selection->size()==1 && track->get_type().get_n_paths()>1)
403                 {
404                         input = new ::Input(*this, "Turnout ID", lexical_cast(track->get_turnout_id()));
405                         input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
406                         input->signal_accept.connect(sigc::mem_fun(this, &Designer::turnout_id_accept));
407                         mode = INPUT;
408                 }
409         }
410         else if(key==Msp::Input::KEY_S)
411         {
412                 const set<Track *> &tracks = selection->get_tracks();
413                 bool ok = false;
414                 int id = -1;
415                 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
416                 {
417                         if((*i)->get_type().get_n_paths()==1)
418                                 ok = true;
419                         if(static_cast<int>((*i)->get_sensor_id())!=id)
420                         {
421                                 if(id==-1)
422                                         id = (*i)->get_sensor_id();
423                                 else
424                                         id = -2;
425                         }
426                 }
427                 if(ok)
428                 {
429                         input = new ::Input(*this, "Sensor ID", (id>=0 ? lexical_cast(id) : string()));
430                         input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
431                         input->signal_accept.connect(sigc::mem_fun(this, &Designer::sensor_id_accept));
432                         mode = INPUT;
433                 }
434         }
435         else if(key==Msp::Input::KEY_A)
436                 add_selection_to_route();
437         else if(key==Msp::Input::KEY_RIGHT)
438                 rotate = -1;
439         else if(key==Msp::Input::KEY_LEFT)
440                 rotate = 1;
441         else if(key==Msp::Input::KEY_UP)
442                 move_y = 1;
443         else if(key==Msp::Input::KEY_DOWN)
444                 move_y = -1;
445         else if(key==Msp::Input::KEY_INSERT)
446                 zoom = -1;
447         else if(key==Msp::Input::KEY_PGUP)
448                 zoom = 1;
449         else if(key==Msp::Input::KEY_HOME)
450                 pitch = 1;
451         else if(key==Msp::Input::KEY_END)
452                 pitch = -1;
453         else if(key==Msp::Input::KEY_DELETE)
454                 move_x = -1;
455         else if(key==Msp::Input::KEY_PGDN)
456                 move_x = 1;
457 }
458
459 void Designer::key_release(unsigned code, unsigned)
460 {
461         unsigned key = Msp::Input::key_from_sys(code);
462
463         if(mode==INPUT)
464                 return;
465
466         if(key==Msp::Input::KEY_SHIFT_L || key==Msp::Input::KEY_SHIFT_R)
467                 shift = false;
468         else if(key==Msp::Input::KEY_RIGHT || key==Msp::Input::KEY_LEFT)
469                 rotate = 0;
470         else if(key==Msp::Input::KEY_UP || key==Msp::Input::KEY_DOWN)
471                 move_y = 0;
472         else if(key==Msp::Input::KEY_INSERT || key==Msp::Input::KEY_PGUP)
473                 zoom = 0;
474         else if(key==Msp::Input::KEY_HOME || key==Msp::Input::KEY_END)
475                 pitch = 0;
476         else if(key==Msp::Input::KEY_DELETE || key==Msp::Input::KEY_PGDN)
477                 move_x = 0;
478 }
479
480 void Designer::button_press(int x, int y, unsigned btn, unsigned)
481 {
482         y = screen_h-y-1;
483
484         float gx, gy;
485         map_pointer_coords(x, y, gx, gy);
486
487         if(mode==CATALOGUE)
488         {
489                 if(btn==1)
490                 {
491                         Track3D *ctrack = pick_track(x, y);
492                         if(ctrack)
493                         {
494                                 Track *track = ctrack->get_track().copy();
495                                 track->set_position(Point(gx, gy, 0));
496                                 layout->add_track(*track);
497
498                                 selection->clear();
499                                 selection->add_track(track);
500
501                                 mode = SELECT;
502                         }
503                 }
504                 else
505                         mode = SELECT;
506         }
507         else if(mode==SELECT)
508         {
509                 if(btn==1)
510                 {
511                         Track3D *track = pick_track(x, y);
512                         if(track)
513                         {
514                                 if(!shift)
515                                         selection->clear();
516                                 selection->toggle_track(&track->get_track());
517                         }
518                 }
519         }
520         else if(mode==MANIPULATE)
521                 manipulator->button_press(x, y, gx, gy, btn);
522         else if(mode==MEASURE)
523                 measure->button_press(x, y, gx, gy, btn);
524 }
525
526 void Designer::pointer_motion(int x, int y)
527 {
528         y = screen_h-y-1;
529
530         pointer_x = x;
531         pointer_y = y;
532
533         if(mode==SELECT || mode==CATALOGUE)
534                 tooltip_timeout = Msp::Time::now()+100*Msp::Time::msec;
535
536         clear_tooltip();
537
538         if(mode!=INPUT)
539         {
540                 float gx, gy;
541                 map_pointer_coords(x, y, gx, gy);
542                 manipulator->pointer_motion(x, y, gx, gy);
543                 measure->pointer_motion(x, y, gx, gy);
544         }
545 }
546
547 void Designer::project_3d()
548 {
549         glMatrixMode(GL_PROJECTION);
550         glLoadIdentity();
551         glFrustum(-0.055228, 0.055228, -0.041421, 0.041421, 0.1, 10);
552         glMatrixMode(GL_MODELVIEW);
553 }
554
555 void Designer::apply_camera()
556 {
557         glLoadIdentity();
558         if(mode==CATALOGUE)
559                 glTranslatef(0, 0, -1);
560         else
561         {
562                 glRotatef(-cam_pitch*180/M_PI-90, 1, 0, 0);
563                 glRotatef(90-cam_yaw*180/M_PI, 0, 0, 1);
564                 glTranslatef(-cam_pos.x, -cam_pos.y, -cam_pos.z);
565         }
566 }
567
568 void Designer::render()
569 {
570         glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
571         GL::enable(GL::DEPTH_TEST);
572
573         project_3d();
574         apply_camera();
575         if(mode==CATALOGUE)
576                 cat_layout_3d->render();
577         else
578         {
579                 if(base_mesh)
580                 {
581                         GL::Texture::unbind();
582                         base_mesh->draw();
583                 }
584                 layout_3d->render(true);
585                 if(cur_route)
586                 {
587                         glColor4f(0.5, 0.8, 1.0, 1.0);
588                         const set<const Track *> &rtracks = cur_route->get_tracks();
589                         const map<unsigned, int> &turnouts = cur_route->get_turnouts();
590                         for(set<const Track *>::const_iterator i=rtracks.begin(); i!=rtracks.end(); ++i)
591                         {
592                                 unsigned path = 0;
593                                 if(unsigned tid=(*i)->get_turnout_id())
594                                 {
595                                         map<unsigned, int>::const_iterator j = turnouts.find(tid);
596                                         if(j!=turnouts.end())
597                                                 path = j->second;
598                                 }
599                                 layout_3d->get_track(**i).render_path(path);
600                         }
601                 }
602                 manipulator->render();
603                 if(mode==MEASURE)
604                         measure->render();
605         }
606
607         GL::matrix_mode(GL::PROJECTION);
608         GL::load_identity();
609         GL::ortho_bottomleft(screen_w, screen_h);
610         GL::matrix_mode(GL::MODELVIEW);
611         GL::load_identity();
612
613         GL::disable(GL::DEPTH_TEST);
614
615         root->render();
616 }
617
618 Track3D *Designer::pick_track(int x, int y)
619 {
620         Layout3D *l = layout_3d;
621         if(mode==CATALOGUE)
622                 l = cat_layout_3d;
623
624         float xx = (static_cast<float>(x-static_cast<int>(screen_w)/2)/screen_h)*0.82843;
625         float yy = (static_cast<float>(y)/screen_h-0.5)*0.82843;
626         float size = 4.0/screen_h*0.82843;
627
628         project_3d();
629         apply_camera();
630
631         return l->pick_track(xx, yy, size);
632 }
633
634 void Designer::update_track_color(Track3D &track)
635 {
636         if(track.get_track().get_sensor_id())
637         {
638                 if(track.get_track().get_flex())
639                         track.set_color(GL::Color(1, 0.6, 1));
640                 else
641                         track.set_color(GL::Color(0.7, 0.7, 1));
642         }
643         else if(track.get_track().get_turnout_id())
644                 track.set_color(GL::Color(0.8, 1, 0.8));
645         else if(track.get_track().get_flex())
646                 track.set_color(GL::Color(1, 0.8, 0.8));
647         else
648                 track.set_color(GL::Color(1, 1, 1));
649 }
650
651 void Designer::manipulation_status(const string &status)
652 {
653         set_tooltip(pointer_x, pointer_y, status);
654 }
655
656 void Designer::manipulation_done(bool)
657 {
658         mode = SELECT;
659 }
660
661 void Designer::measure_changed()
662 {
663         float pard = measure->get_parallel_distance()*1000;
664         float perpd = measure->get_perpendicular_distance()*1000;
665         float d = sqrt(pard*pard+perpd*perpd);
666         float adiff = measure->get_angle_difference()*180/M_PI;
667         string info = format("Par %.1fmm - Perp %.1fmm - Total %.1fmm - Angle %.1f°", pard, perpd, d, adiff);
668         set_tooltip(pointer_x, pointer_y, info);
669 }
670
671 void Designer::measure_done()
672 {
673         mode = SELECT;
674 }
675
676 void Designer::set_tooltip(int x, int y, const std::string &text)
677 {
678         int fontsize = ui_res.get_default_font().get_default_size();
679         int h = fontsize+6;
680         int w = static_cast<int>(ui_res.get_default_font().get_string_width(text)*fontsize)+6;
681         x = max(min(static_cast<int>(screen_w)-w, x), 0);
682         y = max(min(static_cast<int>(screen_h)-h, y), 0);
683         lbl_tooltip->set_text(text);
684         lbl_tooltip->set_geometry(GLtk::Geometry(x, y, w, h));
685         lbl_tooltip->set_visible(true);
686 }
687
688 void Designer::clear_tooltip()
689 {
690         lbl_tooltip->set_visible(false);
691 }
692
693 void Designer::save_accept()
694 {
695         layout->save(input->get_text());
696
697         input_dismiss();
698 }
699
700 void Designer::turnout_id_accept()
701 {
702         Track *track = selection->get_track();
703         unsigned id = lexical_cast<unsigned>(input->get_text());
704         track->set_turnout_id(id);
705
706         update_track_color(layout_3d->get_track(*track));
707
708         input_dismiss();
709 }
710
711 void Designer::sensor_id_accept()
712 {
713         const set<Track *> &tracks = selection->get_tracks();
714         unsigned id = lexical_cast<unsigned>(input->get_text());
715         for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
716         {
717                 (*i)->set_sensor_id(id);
718
719                 update_track_color(layout_3d->get_track(**i));
720         }
721
722         input_dismiss();
723 }
724
725 void Designer::input_dismiss()
726 {
727         delete input;
728         input = 0;
729         mode = SELECT;
730 }