X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrack.cpp;h=aeccaa697e4bc29a3e8b341737401200bd5bd82e;hb=9a2fd67cec715e371e293be638b126e0d1b2148d;hp=7b6bef1de2d7e914846f67ec1b8c5f8b4eadfd64;hpb=2875ea548e0567ad2ce1b8f9bda58e6452813204;p=r2c2.git diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 7b6bef1..aeccaa6 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -38,7 +38,8 @@ Track::Track(Layout &l, const TrackType &t): sensor_addr(0), links(type.get_endpoints().size()), active_path(0), - path_changing(false) + path_changing(false), + preferred_exit(-1) { if(type.is_turnout()) { @@ -55,7 +56,6 @@ Track::Track(Layout &l, const TrackType &t): layout.add(*this); - for(unsigned paths = type.get_paths(); !(paths&1); ++active_path, paths>>=1) ; } @@ -188,6 +188,11 @@ void Track::set_sensor_address(unsigned a) layout.create_blocks(*this); } +void Track::set_preferred_exit(int e) +{ + preferred_exit = e; +} + void Track::set_active_path(unsigned p) { if(!type.is_turnout()) @@ -320,6 +325,10 @@ bool Track::link_to(Object &other) if(!otrack) return false; + float gauge_ratio = otrack->get_type().get_gauge()/type.get_gauge(); + if(gauge_ratio<0.99 || gauge_ratio>1.01) + return false; + float limit = type.get_gauge(); if(!flex && !otrack->get_flex()) limit /= 10; @@ -413,6 +422,12 @@ void Track::save(list &st) const st.push_back((DataFile::Statement("flex"), true)); } +void Track::save_dynamic(list &st) const +{ + if(turnout_addr) + st.push_back((DataFile::Statement("path"), active_path)); +} + void Track::turnout_event(unsigned id, unsigned state) { if(id==turnout_id) @@ -436,6 +451,7 @@ void Track::turnout_failed(unsigned id) Track::Loader::Loader(Track &t): DataFile::ObjectLoader(t) { + add("path", &Loader::path); add("position", &Loader::position); add("rotation", &Loader::rotation); add("tilt", &Loader::tilt); @@ -449,6 +465,16 @@ Track::Loader::Loader(Track &t): add("slope", &Loader::slope); } +void Track::Loader::path(unsigned p) +{ + obj.set_active_path(p); + if(obj.path_changing) + { + obj.active_path = p; + obj.signal_path_changed.emit(p); + } +} + void Track::Loader::position(float x, float y, float z) { obj.set_position(Vector(x, y, z));