]> git.tdb.fi Git - r2c2.git/commitdiff
Emit signal for control changes initiated by the control model itself
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Apr 2010 19:42:44 +0000 (19:42 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Apr 2010 19:42:44 +0000 (19:42 +0000)
Fix the speed display format in train panel

source/engineer/trainpanel.cpp
source/libmarklin/aicontrol.cpp
source/libmarklin/aicontrol.h
source/libmarklin/controlmodel.h
source/libmarklin/simplephysics.cpp
source/libmarklin/train.cpp

index 1fd4abe527084209f68df5cf19db6c15cabfe868..6685727663276642de5a1c0c3f56b920ca431906 100644 (file)
@@ -114,7 +114,7 @@ void TrainPanel::train_control_changed(const string &control, float value)
        {
                float speed = abs(value)/engineer.get_layout().get_catalogue().get_scale()*3.6;
                sld_speed->set_value(speed);
-               lbl_speed->set_text(format("%03.0f", speed));
+               lbl_speed->set_text(format("%3.0f", speed));
                if(value)
                        tgl_forward->set_value(value>0);
        }
index ae47d412b7ffb38f619dd0981aba324e5ef0f196..b97b0374add45037a986ca047d7e9354c0d4a528 100644 (file)
@@ -41,6 +41,8 @@ void AIControl::set_control(const string &n, float v)
                target_speed.set(v);
                if(!blocked)
                        next_model->set_control("speed", target_speed.value);
+
+               signal_control_changed.emit(n, target_speed.value);
        }
        else
                next_model->set_control(n, v);
@@ -86,6 +88,12 @@ void AIControl::tick(const Time::TimeDelta &dt)
                train.set_active(false);
 }
 
+void AIControl::control_changed(const string &n, float v)
+{
+       if(n!="speed")
+               signal_control_changed.emit(n, v);
+}
+
 void AIControl::arrived()
 {
        set_control("speed", 0);
index 7c5bf5d27376c9b045c72c5aff29c11337729cc6..d02011f60a55186627ecca7c500cbab9144bacd5 100644 (file)
@@ -37,6 +37,7 @@ public:
        virtual void tick(const Msp::Time::TimeDelta &);
 
 private:
+       void control_changed(const std::string &, float);
        void arrived();
 };
 
index d37ef634eee03aa5fa9619d1d7fbce4f58dfeaaf..a45a30e74e11c69b45f691fe91c0fe9f46e7d821 100644 (file)
@@ -9,6 +9,7 @@ Distributed under the GPL
 #define LIBMARKLIN_CONTROLMODEL_H_
 
 #include <string>
+#include <sigc++/signal.h>
 #include <msp/time/timedelta.h>
 
 namespace Marklin {
@@ -17,6 +18,9 @@ class TrainControl;
 
 class ControlModel
 {
+public:
+       sigc::signal<void, const std::string &, float> signal_control_changed;
+
 protected:
        ControlModel() { }
 public:
index 3dc8e2ef93c2b61ee3c806252b81029aa78f5701..284e5271b6ae9a06448857a663dbab146e2e2c73 100644 (file)
@@ -25,7 +25,10 @@ SimplePhysics::SimplePhysics():
 void SimplePhysics::set_control(const string &name, float v)
 {
        if(name=="speed")
+       {
                target_speed.set(v);
+               signal_control_changed.emit(name, target_speed.value);
+       }
 }
 
 const TrainControl &SimplePhysics::get_control(const string &name) const
index 24ccfa2448bf1abf814afc4d728da7c935a9908b..307b1b7da0f2903cc526b348fcdc291af3970815 100644 (file)
@@ -57,6 +57,8 @@ Train::Train(Layout &l, const LocoType &t, unsigned a):
        layout.signal_block_reserved.connect(sigc::mem_fun(this, &Train::block_reserved));
        layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Train::sensor_event));
        layout.get_driver().signal_turnout.connect(sigc::mem_fun(this, &Train::turnout_event));
+
+       control->signal_control_changed.connect(signal_control_changed);
 }
 
 Train::~Train()
@@ -90,7 +92,6 @@ const Vehicle &Train::get_vehicle(unsigned i) const
 void Train::set_control(const string &n, float v)
 {
        control->set_control(n, v);
-       signal_control_changed.emit(n, control->get_control(n).value);
 }
 
 void Train::set_active(bool a)