3 This file is part of the MSP Märklin suite
4 Copyright © 2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/label.h>
10 #include "libmarklin/route.h"
11 #include "routeselect.h"
15 using namespace Marklin;
17 RouteSelect::RouteSelect(Engineer &e, const GLtk::Resources &r, Train &t):
26 add(*(label = new GLtk::Label(res, "Select route")));
27 label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20));
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();
35 for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
36 if(!(*i)->is_temporary())
38 drp_route->append((*i)->get_name());
39 if(*i==train.get_route())
40 drp_route->set_selected_index(n);
45 void RouteSelect::on_ok_clicked()
47 if(drp_route->get_selected_index()>0)
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())
54 if(!(*i)->is_temporary())
63 if(!train.set_route(*i))
64 engineer.set_status("Could not set route");