]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/track.cpp
Don't reset router to free run mode until allocator has deactivated
[r2c2.git] / source / libr2c2 / track.cpp
index 697e67843080ec68fba6898e3ad3eae81d3d60d4..26fb59e0fa7e756b619ad718d090dec6b6f05314 100644 (file)
@@ -1,4 +1,5 @@
 #include <cmath>
+#include <msp/core/maputils.h>
 #include "block.h"
 #include "catalogue.h"
 #include "driver.h"
@@ -69,12 +70,14 @@ Block &Track::get_block() const
 void Track::set_position(const Vector &p)
 {
        position = p;
+       signal_moved.emit();
        propagate_slope();
 }
 
 void Track::set_rotation(const Angle &r)
 {
        rotation = wrap_positive(r);
+       signal_moved.emit();
 }
 
 void Track::set_tilt(const Angle &t)
@@ -84,6 +87,7 @@ void Track::set_tilt(const Angle &t)
 
        tilt = t;
        slope = tan(tilt)*type.get_path_length(0);
+       signal_moved.emit();
        propagate_slope();
 }
 
@@ -125,6 +129,8 @@ void Track::check_slope()
                        position.z = epp.z-slope;
                }
        }
+
+       signal_moved.emit();
 }
 
 void Track::set_turnout_id(unsigned i)
@@ -326,6 +332,21 @@ bool Track::break_link(unsigned i)
        return true;
 }
 
+void Track::add_attachment(TrackAttachment &a)
+{
+       if(find(attachments.begin(), attachments.end(), &a)!=attachments.end())
+               throw key_error(&a);
+       attachments.push_back(&a);
+}
+
+void Track::remove_attachment(TrackAttachment &a)
+{
+       AttachmentList::iterator i = find(attachments.begin(), attachments.end(), &a);
+       if(i==attachments.end())
+               throw key_error(&a);
+       attachments.erase(i);
+}
+
 void Track::save(list<DataFile::Statement> &st) const
 {
        st.push_back((DataFile::Statement("position"), position.x, position.y, position.z));
@@ -369,12 +390,12 @@ Track::Loader::Loader(Track &t):
 
 void Track::Loader::position(float x, float y, float z)
 {
-       obj.position = Vector(x, y, z);
+       obj.set_position(Vector(x, y, z));
 }
 
 void Track::Loader::rotation(float r)
 {
-       obj.rotation = Angle::from_radians(r);
+       obj.set_rotation(Angle::from_radians(r));
 }
 
 void Track::Loader::sensor_id(unsigned id)
@@ -384,16 +405,12 @@ void Track::Loader::sensor_id(unsigned id)
 
 void Track::Loader::slope(float s)
 {
-       tilt(atan(s/obj.type.get_path_length(0)));
+       obj.set_tilt(Geometry::atan(s/obj.type.get_path_length(0)));
 }
 
 void Track::Loader::tilt(float t)
 {
-       if(obj.links.size()!=2)
-               return;
-
-       obj.tilt = Angle::from_radians(t);
-       obj.slope = tan(t)*obj.type.get_path_length(0);
+       obj.set_tilt(Angle::from_radians(t));
 }
 
 void Track::Loader::turnout_id(unsigned id)