X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fremote%2Ftrainpanel.cpp;h=cfe0c10fea9f609e8969acc9c8137dcedce3f655;hb=90f9efba8d88f41c7a180734b7bcbdd1501d995e;hp=ce46fa19dffaa86634df6553609c8a28f086878e;hpb=2fe7cbcb761487bc7409b93b372da6f8ab3c581e;p=r2c2.git diff --git a/source/remote/trainpanel.cpp b/source/remote/trainpanel.cpp index ce46fa1..cfe0c10 100644 --- a/source/remote/trainpanel.cpp +++ b/source/remote/trainpanel.cpp @@ -1,24 +1,24 @@ /* $Id$ -This file is part of the MSP Märklin suite -Copyright © 2009 Mikkosoft Productions, Mikko Rasa +This file is part of R²C² +Copyright © 2009-2010 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ #include #include -#include "libmarklin/locotype.h" +#include "remote.h" #include "trainpanel.h" using namespace std; -TrainPanel::TrainPanel(Marklin::Client &c, Marklin::NetTrain &t): +TrainPanel::TrainPanel(Remote &r, R2C2::Client &c, R2C2::NetTrain &t): + remote(r), client(c), train(t) { train.signal_name_changed.connect(sigc::mem_fun(this, &TrainPanel::name_changed)); - train.signal_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::speed_changed)); - train.signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::reverse_changed)); + train.signal_control_changed.connect(sigc::mem_fun(this, &TrainPanel::control_changed)); train.signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::function_changed)); train.signal_route_changed.connect(sigc::mem_fun(this, &TrainPanel::route_changed)); train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::status_changed)); @@ -34,8 +34,8 @@ TrainPanel::TrainPanel(Marklin::Client &c, Marklin::NetTrain &t): hbox->add(*manage(scl_speed = new Gtk::HScale)); scl_speed->set_digits(0); - scl_speed->set_range(0, 14); - scl_speed->set_increments(1, 1); + scl_speed->set_range(0, 200); + scl_speed->set_increments(5, 5); scl_speed->set_size_request(210, -1); scl_speed->signal_value_changed().connect(sigc::mem_fun(this, &TrainPanel::ui_speed_changed)); @@ -80,14 +80,15 @@ void TrainPanel::status_changed(const string &status) lbl_status->set_text(status); } -void TrainPanel::speed_changed(unsigned speed) +void TrainPanel::control_changed(const string &control, float value) { - scl_speed->set_value(speed); -} - -void TrainPanel::reverse_changed(bool rev) -{ - chk_reverse->set_active(rev); + if(control=="speed") + { + // XXX It would be better to make the VehicleType give us the catalogue + scl_speed->set_value(value*3.6/remote.get_catalogue().get_scale()); + } + else if(control=="reverse") + chk_reverse->set_active(value); } void TrainPanel::function_changed(unsigned func, bool set) @@ -110,12 +111,19 @@ void TrainPanel::route_changed(const string &route) void TrainPanel::ui_speed_changed() { - train.set_speed(static_cast(scl_speed->get_value())); + float speed = scl_speed->get_value()/3.6*remote.get_catalogue().get_scale(); + train.set_control("speed", speed); } void TrainPanel::ui_reverse_changed() { - train.set_reverse(chk_reverse->get_active()); + if(train.get_control("speed")) + { + train.set_control("speed", 0); + chk_reverse->set_active(train.get_control("reverse")); + } + else + train.set_control("reverse", chk_reverse->get_active()); } void TrainPanel::ui_function_changed(unsigned func)