X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrack.cpp;h=aeccaa697e4bc29a3e8b341737401200bd5bd82e;hb=9a2fd67cec715e371e293be638b126e0d1b2148d;hp=26886344b0a1312a9bb8023c065ed6220fdcb70c;hpb=73e4a36bbf828e07b83a779b696875e1f80045cc;p=r2c2.git diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 2688634..aeccaa6 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "block.h" #include "catalogue.h" #include "driver.h" @@ -37,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()) { @@ -48,12 +50,12 @@ Track::Track(Layout &l, const TrackType &t): Driver &driver = layout.get_driver(); turnout_id = driver.add_turnout(turnout_addr, type); driver.signal_turnout.connect(sigc::mem_fun(this, &Track::turnout_event)); + driver.signal_turnout_failed.connect(sigc::mem_fun(this, &Track::turnout_failed)); } } layout.add(*this); - for(unsigned paths = type.get_paths(); !(paths&1); ++active_path, paths>>=1) ; } @@ -186,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()) @@ -193,6 +200,9 @@ void Track::set_active_path(unsigned p) if(!(type.get_paths()&(1<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; limit *= limit; @@ -408,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) @@ -418,10 +438,20 @@ void Track::turnout_event(unsigned id, unsigned state) } } +void Track::turnout_failed(unsigned id) +{ + if(id==turnout_id) + { + path_changing = false; + layout.emergency(block, "Turnout failed"); + } +} + Track::Loader::Loader(Track &t): DataFile::ObjectLoader(t) { + add("path", &Loader::path); add("position", &Loader::position); add("rotation", &Loader::rotation); add("tilt", &Loader::tilt); @@ -435,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));