]> git.tdb.fi Git - r2c2.git/blobdiff - source/remote/trainpanel.cpp
Foundations of using physics simulation for trains
[r2c2.git] / source / remote / trainpanel.cpp
index ce46fa19dffaa86634df6553609c8a28f086878e..37d75afba7273e36c8bb496f5e688cc1bfffb65e 100644 (file)
@@ -1,24 +1,25 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright © 2009  Mikkosoft Productions, Mikko Rasa
+Copyright © 2009-2010  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
 #include <gtkmm/box.h>
 #include <gtkmm/liststore.h>
 #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, Marklin::Client &c, Marklin::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 +35,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 +81,14 @@ 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 LocoType give us the catalogue
+               scl_speed->set_value(abs(value)*3.6/remote.get_catalogue().get_scale());
+               chk_reverse->set_active(value<0);
+       }
 }
 
 void TrainPanel::function_changed(unsigned func, bool set)
@@ -110,12 +111,15 @@ void TrainPanel::route_changed(const string &route)
 
 void TrainPanel::ui_speed_changed()
 {
-       train.set_speed(static_cast<unsigned>(scl_speed->get_value()));
+       float speed = scl_speed->get_value()/3.6*remote.get_catalogue().get_scale();
+       if(chk_reverse->get_active())
+               speed = -speed;
+       train.set_control("speed", speed);
 }
 
 void TrainPanel::ui_reverse_changed()
 {
-       train.set_reverse(chk_reverse->get_active());
+       train.set_control("speed", 0);
 }
 
 void TrainPanel::ui_function_changed(unsigned func)