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