X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fengineer%2Frouteselect.cpp;h=00bf6cfdcd19cf79d97c316df2def12be7c24785;hb=1ff06c5bc46a677fa389ef86c6b26664368f1653;hp=8b526aeab75b80fdb42613c0ce90346c0cea2dab;hpb=7587f018794f53974409a2aad76a0a421cea2d24;p=r2c2.git diff --git a/source/engineer/routeselect.cpp b/source/engineer/routeselect.cpp index 8b526ae..00bf6cf 100644 --- a/source/engineer/routeselect.cpp +++ b/source/engineer/routeselect.cpp @@ -1,43 +1,43 @@ /* $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 set &routes = engineer.get_layout().get_routes(); unsigned n = 1; - for(set::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n) - { - drp_route->append((*i)->get_name()); - if(*i==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() @@ -46,9 +46,20 @@ void RouteSelect::on_ok_clicked() { const set &routes = engineer.get_layout().get_routes(); set::const_iterator i = routes.begin(); - advance(i, drp_route->get_selected_index()-1); + 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); + if(!train.set_route(*i)) + engineer.set_status("Could not set route"); } else train.set_route(0);