]> git.tdb.fi Git - r2c2.git/blob - source/engineer/routeselect.cpp
Add framework for generating simple meshes for vehicles
[r2c2.git] / source / engineer / routeselect.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <msp/gltk/label.h>
9 #include "engineer.h"
10 #include "libmarklin/route.h"
11 #include "routeselect.h"
12
13 using namespace std;
14 using namespace Msp;
15 using namespace Marklin;
16
17 RouteSelect::RouteSelect(Engineer &e, const GLtk::Resources &r, Train &t):
18         GLtk::Widget(r),
19         Dialog(r),
20         engineer(e),
21         train(t)
22 {
23         set_size(200, 95);
24
25         GLtk::Label *label;
26         add(*(label = new GLtk::Label(res, "Select route")));
27         label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20));
28
29         add(*(drp_route = new GLtk::Dropdown(res)));
30         drp_route->set_geometry(GLtk::Geometry(10, geom.h-50, geom.w-20, 20));
31         drp_route->append("(none)");
32         drp_route->set_selected_index(0);
33         const set<Route *> &routes = engineer.get_layout().get_routes();
34         unsigned n = 1;
35         for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
36                 if(!(*i)->is_temporary())
37                 {
38                         drp_route->append((*i)->get_name());
39                         if(*i==train.get_route())
40                                 drp_route->set_selected_index(n);
41                         ++n;
42                 }
43 }
44
45 void RouteSelect::on_ok_clicked()
46 {
47         if(drp_route->get_selected_index()>0)
48         {
49                 const set<Route *> &routes = engineer.get_layout().get_routes();
50                 set<Route *>::const_iterator i = routes.begin();
51                 unsigned n = drp_route->get_selected_index()-1;
52                 while(i!=routes.end())
53                 {
54                         if(!(*i)->is_temporary())
55                         {
56                                 if(!n)
57                                         break;
58                                 --n;
59                         }
60                         ++i;
61                 }
62                 
63                 if(!train.set_route(*i))
64                         engineer.set_status("Could not set route");
65         }
66         else
67                 train.set_route(0);
68 }