]> git.tdb.fi Git - r2c2.git/blob - source/designer/designer.cpp
Use GL::Renderables and a Pipeline for rendering
[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_object(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_object = new GL::Object;
90                         DataFile::load(*base_object, 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         pipeline = new GL::Pipeline(screen_w, screen_h, false);
130         pipeline->add_renderable(layout_3d->get_scene());
131         if(base_object)
132                 pipeline->add_renderable(*base_object);
133
134         light.set_position(0, -0.259, 0.966, 0);
135         lighting.attach(0, light);
136
137         GL::PipelinePass *pass = &pipeline->add_pass(GL::Tag());
138         pass->lighting = &lighting;
139
140         DataFile::load(ui_res, "marklin.res");
141         root = new GLtk::Root(ui_res, *wnd);
142
143         lbl_tooltip = new GLtk::Label(ui_res);
144         lbl_tooltip->set_style("tooltip");
145         root->add(*lbl_tooltip);
146         lbl_tooltip->set_visible(false);
147
148         toolbar = new Toolbar(*this);
149         root->add(*toolbar);
150         toolbar->set_position(0, screen_h-toolbar->get_geometry().h);
151         toolbar->set_visible(true);
152
153
154         wnd->signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press));
155         wnd->signal_key_release.connect(sigc::mem_fun(this, &Designer::key_release));
156         wnd->signal_button_press.connect(sigc::mem_fun(this, &Designer::button_press));
157         wnd->signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion));
158
159         mode = SELECT;
160
161         Application::main();
162
163         delete root;
164
165         delete glc;
166         delete wnd;
167         delete dpy;
168
169         return exit_code;
170 }
171
172 void Designer::save()
173 {
174         input = new ::Input(*this, "Save layout", filename);
175         input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
176         input->signal_accept.connect(sigc::mem_fun(this, &Designer::save_accept));
177         mode = INPUT;
178 }
179
180 void Designer::quit()
181 {
182         exit(0);
183 }
184
185 void Designer::edit_route(Route &r)
186 {
187         cur_route = &r;
188 }
189
190 void Designer::add_selection_to_route()
191 {
192         if(!cur_route)
193                 return;
194
195         try
196         {
197                 const set<Track *> &stracks = selection->get_tracks();
198                 set<const Track *> tracks(stracks.begin(), stracks.end());
199                 cur_route->add_tracks(tracks);
200         }
201         catch(const Exception &e)
202         {
203                 IO::print("%s\n", e.what());
204         }
205 }
206
207 void Designer::map_pointer_coords(int x, int y, float &gx, float &gy)
208 {
209         float cos_pitch = cos(cam_pitch);
210         float sin_pitch = sin(cam_pitch);
211         float cos_yaw = cos(cam_yaw);
212         float sin_yaw = sin(cam_yaw);
213
214         float rx = sin_yaw*0.55228;
215         float ry = -cos_yaw*0.55228;
216
217         float ux = cos_yaw*-sin_pitch*0.41421;
218         float uy = sin_yaw*-sin_pitch*0.41421;
219         float uz = cos_pitch*0.41421;
220
221         float xf = static_cast<float>(x)*2/screen_w-1;
222         float yf = static_cast<float>(y)*2/screen_h-1;
223
224         float vx = cos_yaw*cos_pitch + xf*rx + yf*ux;
225         float vy = sin_yaw*cos_pitch + xf*ry + yf*uy;
226         float vz = sin_pitch + yf*uz;
227
228         gx = cam_pos.x-vx*cam_pos.z/vz;
229         gy = cam_pos.y-vy*cam_pos.z/vz;
230 }
231
232 void Designer::tick()
233 {
234         const Msp::Time::TimeStamp t = Msp::Time::now();
235         float dt = (t-last_tick)/Msp::Time::sec;
236         last_tick = t;
237
238         dpy->tick();
239
240         if(move_y)
241         {
242                 cam_pos.x += cos(cam_yaw)*dt*move_y;
243                 cam_pos.y += sin(cam_yaw)*dt*move_y;
244         }
245         if(move_x)
246         {
247                 cam_pos.x += sin(cam_yaw)*dt*move_x;
248                 cam_pos.y += -cos(cam_yaw)*dt*move_x;
249         }
250         if(zoom)
251         {
252                 cam_pos.x += cos(cam_yaw)*cos(cam_pitch)*dt*zoom;
253                 cam_pos.y += sin(cam_yaw)*cos(cam_pitch)*dt*zoom;
254                 cam_pos.z += sin(cam_pitch)*dt*zoom;
255         }
256         if(rotate)
257         {
258                 float vx = cos(cam_yaw)*cos(cam_pitch);
259                 float vy = sin(cam_yaw)*cos(cam_pitch);
260                 float vz = sin(cam_pitch);
261
262                 float gx = cam_pos.x-vx*cam_pos.z/vz;
263                 float gy = cam_pos.y-vy*cam_pos.z/vz;
264                 float d = sqrt(vx*vx+vy*vy)*cam_pos.z/vz;
265
266                 cam_yaw += M_PI*dt*rotate;
267                 if(cam_yaw>M_PI*2)
268                         cam_yaw -= M_PI*2;
269                 else if(cam_yaw<0)
270                         cam_yaw += M_PI*2;
271
272                 cam_pos.x = gx+cos(cam_yaw)*d;
273                 cam_pos.y = gy+sin(cam_yaw)*d;
274         }
275         if(pitch)
276         {
277                 cam_pitch += M_PI/2*dt*pitch;
278                 if(cam_pitch>M_PI/12)
279                         cam_pitch = M_PI/12;
280                 else if(cam_pitch<-M_PI/2)
281                         cam_pitch = -M_PI/2;
282         }
283
284         if(tooltip_timeout && t>tooltip_timeout)
285         {
286                 Track3D *t3d = 0;
287
288                 if(mode==CATALOGUE)
289                         t3d = pick_track(pointer_x, pointer_y);
290                 else
291                         t3d = pick_track(pointer_x, pointer_y);
292
293                 if(t3d)
294                 {
295                         const Track &track = t3d->get_track();
296                         const TrackType &ttype = track.get_type();
297                         string info = format("%d %s", ttype.get_article_number(), ttype.get_description());
298                         if(mode!=CATALOGUE && abs(track.get_slope())>1e-4)
299                                 info += format(" (slope %.1f%%)", abs(track.get_slope()/ttype.get_total_length()*100));
300                         if(track.get_turnout_id())
301                                 info += format(" (turnout %d)", track.get_turnout_id());
302                         else if(track.get_sensor_id())
303                                 info += format(" (sensor %d)", track.get_sensor_id());
304
305                         set_tooltip(pointer_x, pointer_y, info);
306                 }
307                 else
308                         clear_tooltip();
309
310                 tooltip_timeout = Msp::Time::TimeStamp();
311         }
312
313         render();
314
315         glc->swap_buffers();
316 }
317
318 void Designer::key_press(unsigned code, unsigned mod, wchar_t)
319 {
320         unsigned key = Msp::Input::key_from_sys(code);
321
322         if(mode==INPUT)
323                 return;
324
325         if(key==Msp::Input::KEY_SHIFT_L || key==Msp::Input::KEY_SHIFT_R)
326                 shift = true;
327
328         if(key==Msp::Input::KEY_N)
329                 mode = CATALOGUE;
330         else if(key==Msp::Input::KEY_G)
331         {
332                 manipulator->start_move();
333                 mode = MANIPULATE;
334         }
335         else if(key==Msp::Input::KEY_R)
336         {
337                 manipulator->start_rotate();
338                 mode = MANIPULATE;
339         }
340         else if(key==Msp::Input::KEY_D)
341         {
342                 manipulator->duplicate();
343                 manipulator->start_move();
344                 mode = MANIPULATE;
345         }
346         else if(key==Msp::Input::KEY_W)
347                 save();
348         else if(key==Msp::Input::KEY_PLUS)
349                 selection->select_more();
350         else if(key==Msp::Input::KEY_L && (mod&1))
351         {
352                 const set<Track *> &tracks = layout->get_tracks();
353                 float len = 0;
354                 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
355                         len += (*i)->get_type().get_total_length();
356                 IO::print("Total length: %.1fm\n", len);
357         }
358         else if(key==Msp::Input::KEY_L)
359                 selection->select_linked();
360         else if(key==Msp::Input::KEY_M)
361         {
362                 measure->start();
363                 mode = MEASURE;
364         }
365         else if(key==Msp::Input::KEY_Z)
366         {
367                 manipulator->start_elevate();
368                 mode = MANIPULATE;
369         }
370         else if(key==Msp::Input::KEY_ESC)
371         {
372                 if(mode==MANIPULATE)
373                         manipulator->cancel();
374                 else if(mode==CATALOGUE)
375                         mode = SELECT;
376                 else
377                         selection->clear();
378         }
379         else if(key==Msp::Input::KEY_X)
380         {
381                 set<Track *> tracks = selection->get_tracks();
382                 selection->clear();
383                 for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
384                 {
385                         layout->remove_track(**i);
386                         delete *i;
387                 }
388         }
389         else if(key==Msp::Input::KEY_F && (mod&1))
390         {
391                 const set<Track *> &tracks = selection->get_tracks();
392                 const set<Track *> &ltracks = layout->get_tracks();
393                 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
394                 {
395                         (*i)->set_flex(!(*i)->get_flex());
396                         (*i)->break_links();
397                         for(set<Track *>::const_iterator j=ltracks.begin(); j!=ltracks.end(); ++j)
398                                 if(*j!=*i)
399                                         (*i)->snap_to(**j, true);
400
401                         update_track_color(layout_3d->get_track(**i));
402                 }
403         }
404         else if(key==Msp::Input::KEY_F)
405                 manipulator->flatten();
406         else if(key==Msp::Input::KEY_E && (mod&1))
407                 manipulator->even_slope(true);
408         else if(key==Msp::Input::KEY_E)
409                 manipulator->even_slope();
410         else if(key==Msp::Input::KEY_T)
411         {
412                 Track *track = selection->get_track();
413                 if(selection->size()==1 && track->get_type().get_n_paths()>1)
414                 {
415                         input = new ::Input(*this, "Turnout ID", lexical_cast(track->get_turnout_id()));
416                         input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
417                         input->signal_accept.connect(sigc::mem_fun(this, &Designer::turnout_id_accept));
418                         mode = INPUT;
419                 }
420         }
421         else if(key==Msp::Input::KEY_S)
422         {
423                 const set<Track *> &tracks = selection->get_tracks();
424                 bool ok = false;
425                 int id = -1;
426                 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
427                 {
428                         if((*i)->get_type().get_n_paths()==1)
429                                 ok = true;
430                         if(static_cast<int>((*i)->get_sensor_id())!=id)
431                         {
432                                 if(id==-1)
433                                         id = (*i)->get_sensor_id();
434                                 else
435                                         id = -2;
436                         }
437                 }
438                 if(ok)
439                 {
440                         input = new ::Input(*this, "Sensor ID", (id>=0 ? lexical_cast(id) : string()));
441                         input->signal_cancel.connect(sigc::mem_fun(this, &Designer::input_dismiss));
442                         input->signal_accept.connect(sigc::mem_fun(this, &Designer::sensor_id_accept));
443                         mode = INPUT;
444                 }
445         }
446         else if(key==Msp::Input::KEY_A)
447                 add_selection_to_route();
448         else if(key==Msp::Input::KEY_RIGHT)
449                 rotate = -1;
450         else if(key==Msp::Input::KEY_LEFT)
451                 rotate = 1;
452         else if(key==Msp::Input::KEY_UP)
453                 move_y = 1;
454         else if(key==Msp::Input::KEY_DOWN)
455                 move_y = -1;
456         else if(key==Msp::Input::KEY_INSERT)
457                 zoom = -1;
458         else if(key==Msp::Input::KEY_PGUP)
459                 zoom = 1;
460         else if(key==Msp::Input::KEY_HOME)
461                 pitch = 1;
462         else if(key==Msp::Input::KEY_END)
463                 pitch = -1;
464         else if(key==Msp::Input::KEY_DELETE)
465                 move_x = -1;
466         else if(key==Msp::Input::KEY_PGDN)
467                 move_x = 1;
468 }
469
470 void Designer::key_release(unsigned code, unsigned)
471 {
472         unsigned key = Msp::Input::key_from_sys(code);
473
474         if(mode==INPUT)
475                 return;
476
477         if(key==Msp::Input::KEY_SHIFT_L || key==Msp::Input::KEY_SHIFT_R)
478                 shift = false;
479         else if(key==Msp::Input::KEY_RIGHT || key==Msp::Input::KEY_LEFT)
480                 rotate = 0;
481         else if(key==Msp::Input::KEY_UP || key==Msp::Input::KEY_DOWN)
482                 move_y = 0;
483         else if(key==Msp::Input::KEY_INSERT || key==Msp::Input::KEY_PGUP)
484                 zoom = 0;
485         else if(key==Msp::Input::KEY_HOME || key==Msp::Input::KEY_END)
486                 pitch = 0;
487         else if(key==Msp::Input::KEY_DELETE || key==Msp::Input::KEY_PGDN)
488                 move_x = 0;
489 }
490
491 void Designer::button_press(int x, int y, unsigned btn, unsigned)
492 {
493         y = screen_h-y-1;
494
495         float gx, gy;
496         map_pointer_coords(x, y, gx, gy);
497
498         if(mode==CATALOGUE)
499         {
500                 if(btn==1)
501                 {
502                         Track3D *ctrack = pick_track(x, y);
503                         if(ctrack)
504                         {
505                                 Track *track = ctrack->get_track().copy();
506                                 track->set_position(Point(gx, gy, 0));
507                                 layout->add_track(*track);
508
509                                 selection->clear();
510                                 selection->add_track(track);
511
512                                 mode = SELECT;
513                         }
514                 }
515                 else
516                         mode = SELECT;
517         }
518         else if(mode==SELECT)
519         {
520                 if(btn==1)
521                 {
522                         Track3D *track = pick_track(x, y);
523                         if(track)
524                         {
525                                 if(!shift)
526                                         selection->clear();
527                                 selection->toggle_track(&track->get_track());
528                         }
529                 }
530         }
531         else if(mode==MANIPULATE)
532                 manipulator->button_press(x, y, gx, gy, btn);
533         else if(mode==MEASURE)
534                 measure->button_press(x, y, gx, gy, btn);
535 }
536
537 void Designer::pointer_motion(int x, int y)
538 {
539         y = screen_h-y-1;
540
541         pointer_x = x;
542         pointer_y = y;
543
544         if(mode==SELECT || mode==CATALOGUE)
545                 tooltip_timeout = Msp::Time::now()+100*Msp::Time::msec;
546
547         clear_tooltip();
548
549         if(mode!=INPUT)
550         {
551                 float gx, gy;
552                 map_pointer_coords(x, y, gx, gy);
553                 manipulator->pointer_motion(x, y, gx, gy);
554                 measure->pointer_motion(x, y, gx, gy);
555         }
556 }
557
558 void Designer::project_3d()
559 {
560         glMatrixMode(GL_PROJECTION);
561         glLoadIdentity();
562         glFrustum(-0.055228, 0.055228, -0.041421, 0.041421, 0.1, 10);
563         glMatrixMode(GL_MODELVIEW);
564 }
565
566 void Designer::apply_camera()
567 {
568         glLoadIdentity();
569         if(mode==CATALOGUE)
570                 glTranslatef(0, 0, -1);
571         else
572         {
573                 glRotatef(-cam_pitch*180/M_PI-90, 1, 0, 0);
574                 glRotatef(90-cam_yaw*180/M_PI, 0, 0, 1);
575                 glTranslatef(-cam_pos.x, -cam_pos.y, -cam_pos.z);
576         }
577 }
578
579 void Designer::render()
580 {
581         glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
582         GL::enable(GL::DEPTH_TEST);
583         GL::Texture::unbind();
584
585         project_3d();
586         apply_camera();
587         if(mode==CATALOGUE)
588                 cat_layout_3d->get_scene().render();
589         else
590         {
591                 pipeline->render_all();
592                 layout_3d->get_endpoint_scene().render();
593                 GL::enable(GL_CULL_FACE);
594                 /*if(cur_route)
595                 {
596                         glColor4f(0.5, 0.8, 1.0, 1.0);
597                         const set<const Track *> &rtracks = cur_route->get_tracks();
598                         const map<unsigned, int> &turnouts = cur_route->get_turnouts();
599                         for(set<const Track *>::const_iterator i=rtracks.begin(); i!=rtracks.end(); ++i)
600                         {
601                                 unsigned path = 0;
602                                 if(unsigned tid=(*i)->get_turnout_id())
603                                 {
604                                         map<unsigned, int>::const_iterator j = turnouts.find(tid);
605                                         if(j!=turnouts.end())
606                                                 path = j->second;
607                                 }
608                                 layout_3d->get_track(**i).render_path(path);
609                         }
610                 }*/
611
612                 manipulator->render();
613                 if(mode==MEASURE)
614                         measure->render();
615         }
616
617         GL::matrix_mode(GL::PROJECTION);
618         GL::load_identity();
619         GL::ortho_bottomleft(screen_w, screen_h);
620         GL::matrix_mode(GL::MODELVIEW);
621         GL::load_identity();
622
623         GL::disable(GL::DEPTH_TEST);
624
625         root->render();
626 }
627
628 Track3D *Designer::pick_track(int x, int y)
629 {
630         Layout3D *l = layout_3d;
631         if(mode==CATALOGUE)
632                 l = cat_layout_3d;
633
634         float xx = (static_cast<float>(x-static_cast<int>(screen_w)/2)/screen_h)*0.82843;
635         float yy = (static_cast<float>(y)/screen_h-0.5)*0.82843;
636         float size = 4.0/screen_h*0.82843;
637
638         project_3d();
639         apply_camera();
640
641         return l->pick_track(xx, yy, size);
642 }
643
644 void Designer::update_track_color(Track3D &track)
645 {
646         if(track.get_track().get_sensor_id())
647         {
648                 if(track.get_track().get_flex())
649                         track.set_color(GL::Color(1, 0.6, 1));
650                 else
651                         track.set_color(GL::Color(0.7, 0.7, 1));
652         }
653         else if(track.get_track().get_turnout_id())
654                 track.set_color(GL::Color(0.8, 1, 0.8));
655         else if(track.get_track().get_flex())
656                 track.set_color(GL::Color(1, 0.8, 0.8));
657         else
658                 track.set_color(GL::Color(1, 1, 1));
659 }
660
661 void Designer::manipulation_status(const string &status)
662 {
663         set_tooltip(pointer_x, pointer_y, status);
664 }
665
666 void Designer::manipulation_done(bool)
667 {
668         mode = SELECT;
669 }
670
671 void Designer::measure_changed()
672 {
673         float pard = measure->get_parallel_distance()*1000;
674         float perpd = measure->get_perpendicular_distance()*1000;
675         float d = sqrt(pard*pard+perpd*perpd);
676         float adiff = measure->get_angle_difference()*180/M_PI;
677         string info = format("Par %.1fmm - Perp %.1fmm - Total %.1fmm - Angle %.1f°", pard, perpd, d, adiff);
678         set_tooltip(pointer_x, pointer_y, info);
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 }