X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Frouteselect.cpp;h=00bf6cfdcd19cf79d97c316df2def12be7c24785;hb=2d44923e135a119fde31a7a50e5fcd3e400e4f41;hp=3413220a46aea4c8cac349230c29cdc486cd7850;hpb=025c23f199c411cc2ec1a6d2e85bf24460150ceb;p=r2c2.git diff --git a/source/engineer/routeselect.cpp b/source/engineer/routeselect.cpp index 3413220..00bf6cf 100644 --- a/source/engineer/routeselect.cpp +++ b/source/engineer/routeselect.cpp @@ -1,54 +1,65 @@ /* $Id$ -This file is part of the MSP Märklin suite +This file is part of R²C² Copyright © 2009 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ #include #include "engineer.h" -#include "libmarklin/route.h" +#include "libr2c2/route.h" #include "routeselect.h" using namespace std; using namespace Msp; -using namespace Marklin; +using namespace R2C2; -RouteSelect::RouteSelect(Engineer &e, const GLtk::Resources &r, Train &t): - GLtk::Widget(r), - Dialog(r), +RouteSelect::RouteSelect(Engineer &e, Train &t): engineer(e), train(t) { set_size(200, 95); GLtk::Label *label; - add(*(label = new GLtk::Label(res, "Select route"))); + add(*(label = new GLtk::Label("Select route"))); label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20)); - add(*(drp_route = new GLtk::Dropdown(res))); + add(*(drp_route = new GLtk::Dropdown)); drp_route->set_geometry(GLtk::Geometry(10, geom.h-50, geom.w-20, 20)); drp_route->append("(none)"); drp_route->set_selected_index(0); - const map &routes = engineer.get_layout().get_routes(); + const set &routes = engineer.get_layout().get_routes(); unsigned n = 1; - for(map::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n) - { - drp_route->append(i->second->get_name()); - if(i->second==train.get_route()) - drp_route->set_selected_index(n); - } + for(set::const_iterator i=routes.begin(); i!=routes.end(); ++i) + if(!(*i)->is_temporary()) + { + drp_route->append((*i)->get_name()); + if(*i==train.get_route()) + drp_route->set_selected_index(n); + ++n; + } } void RouteSelect::on_ok_clicked() { if(drp_route->get_selected_index()>0) { - const map &routes = engineer.get_layout().get_routes(); - map::const_iterator i = routes.begin(); - advance(i, drp_route->get_selected_index()-1); + const set &routes = engineer.get_layout().get_routes(); + set::const_iterator i = routes.begin(); + unsigned n = drp_route->get_selected_index()-1; + while(i!=routes.end()) + { + if(!(*i)->is_temporary()) + { + if(!n) + break; + --n; + } + ++i; + } - train.set_route(i->second); + if(!train.set_route(*i)) + engineer.set_status("Could not set route"); } else train.set_route(0);