X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainpanel.cpp;h=dce1387f58540c604e3b8b45c4e661ace7d523a6;hb=c12e074c6b9b5136e72931fb47a562e40e0a24f9;hp=5a1e531dda3457099cddd9bed2ab1b00be546221;hpb=296d83d8a04e767e2b622ebc0570515617859275;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index 5a1e531..dce1387 100644 --- a/source/engineer/trainpanel.cpp +++ b/source/engineer/trainpanel.cpp @@ -1,13 +1,13 @@ /* $Id$ This file is part of the MSP Märklin suite -Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ #include #include -#include "libmarklin/locomotive.h" +#include "libmarklin/locotype.h" #include "engineer.h" #include "routeselect.h" #include "trainpanel.h" @@ -25,7 +25,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): { set_size(200, 170); - add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_locomotive().get_address())))); + add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_address())))); lbl_addr->set_style("digital"); lbl_addr->set_geometry(GLtk::Geometry(10, geom.h-34, 35, 24)); @@ -34,7 +34,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): lbl_name->set_geometry(GLtk::Geometry(45, geom.h-34, geom.w-55, 24)); train.signal_name_changed.connect(sigc::mem_fun(lbl_name, &GLtk::Label::set_text)); - add(*(lbl_speed=new GLtk::Label(res, format("%2d", train.get_locomotive().get_speed())))); + add(*(lbl_speed=new GLtk::Label(res, format("%2d", train.get_speed())))); lbl_speed->set_style("digital"); lbl_speed->set_geometry(GLtk::Geometry(10, geom.h-58, 35, 24)); train.signal_target_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::train_speed_changed)); @@ -48,11 +48,12 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): add(*(tgl_forward=new GLtk::Toggle(res))); tgl_forward->set_text("Fwd"); tgl_forward->set_geometry(GLtk::Geometry(geom.w-30, geom.h-59, 20, 27)); - tgl_forward->set_value(!train.get_locomotive().get_reverse()); + tgl_forward->set_value(!train.get_reverse()); tgl_forward->signal_toggled.connect(sigc::mem_fun(this, &TrainPanel::forward_toggled)); - train.get_locomotive().signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::train_reverse_changed)); + train.signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::train_reverse_changed)); - add(*(lbl_route=new GLtk::Label(res, "Free run"))); + const Route *route = train.get_route(); + add(*(lbl_route=new GLtk::Label(res, (route ? route->get_name() : "Free run")))); lbl_route->set_style("digital"); lbl_route->set_geometry(GLtk::Geometry(10, 58, geom.w-20, 24)); train.signal_route_changed.connect(sigc::mem_fun(this, &TrainPanel::train_route_changed)); @@ -62,7 +63,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): lbl_status->set_geometry(GLtk::Geometry(10, 34, geom.w-20, 24)); train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed)); - const map &funcs = train.get_locomotive().get_type().get_functions(); + const map &funcs = train.get_locomotive_type().get_functions(); unsigned x = 10; for(map::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=36) { @@ -72,12 +73,12 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): add(*(tgl=new GLtk::Toggle(res))); tgl->set_text(fname); tgl->set_geometry(GLtk::Geometry(x, geom.h-85, 36, 27)); - tgl->set_value(train.get_locomotive().get_function(i->first)); + tgl->set_value(train.get_function(i->first)); tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::func_toggled), i->first)); tgl_funcs[i->first] = tgl; } - train.get_locomotive().signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_function_changed)); + train.signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::train_function_changed)); GLtk::Button *btn; @@ -91,6 +92,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): add(*(btn=new GLtk::Button(res, "GoTo"))); btn->set_geometry(GLtk::Geometry(geom.w-130, 10, 40, 24)); + btn->signal_clicked.connect(sigc::mem_fun(this, &TrainPanel::goto_clicked)); add(*(btn=new GLtk::Button(res, "Route"))); btn->set_geometry(GLtk::Geometry(geom.w-170, 10, 40, 24)); @@ -113,7 +115,7 @@ void TrainPanel::train_reverse_changed(bool reverse) tgl_forward->set_value(!reverse); } -void TrainPanel::loco_function_changed(unsigned func, bool value) +void TrainPanel::train_function_changed(unsigned func, bool value) { map::iterator i = tgl_funcs.find(func); if(i!=tgl_funcs.end()) @@ -135,7 +137,8 @@ void TrainPanel::train_status_changed(const string &s) void TrainPanel::place_clicked() { - engineer.place_train(train); + engineer.pick(true); + pick_conn = engineer.signal_pick_done.connect(sigc::mem_fun(this, &TrainPanel::place)); } void TrainPanel::edit_clicked() @@ -154,6 +157,12 @@ void TrainPanel::route_clicked() dialog->set_visible(true); } +void TrainPanel::goto_clicked() +{ + engineer.pick(false); + pick_conn = engineer.signal_pick_done.connect(sigc::mem_fun(this, &TrainPanel::go_to)); +} + void TrainPanel::forward_toggled(bool value) { train.set_reverse(!value); @@ -161,5 +170,49 @@ void TrainPanel::forward_toggled(bool value) void TrainPanel::func_toggled(bool value, unsigned func) { - train.get_locomotive().set_function(func, value); + train.set_function(func, value); +} + +void TrainPanel::place(Track *track, unsigned ep) +{ + pick_conn.disconnect(); + + Block &block = engineer.get_layout().get_block_by_track(*track); + + while(1) + { + const vector &eps = block.get_endpoints(); + bool ok = false; + for(unsigned i=0; (!ok && iget_links()[ep]; + ep = next->traverse(next->get_endpoint_by_link(*track), 0); + track = next; + if(!block.get_tracks().count(track)) + break; + } + } +} + +void TrainPanel::go_to(Track *track, unsigned) +{ + pick_conn.disconnect(); + + try + { + train.go_to(*track); + } + catch(const Exception &e) + { + engineer.set_status(e.what()); + } }