X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrack.cpp;h=5da34f692b370c9f5711536e2d0838da78e9f8cb;hb=26a8dbeae14c685c6aef1aad3aa75c6f1a75e458;hp=8ecb9b9bac00833eaa70190982fcb1933b43e9ae;hpb=64d23de66c33d0f77454c3db2e40cccc18f7851b;p=r2c2.git diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 8ecb9b9..5da34f6 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -53,6 +53,8 @@ Track::Track(Layout &l, const TrackType &t): Track::~Track() { break_links(); + if(layout.has_driver() && turnout_id) + layout.get_driver().remove_turnout(turnout_id); layout.remove(*this); } @@ -155,11 +157,15 @@ void Track::set_turnout_id(unsigned i) if(!i) throw invalid_argument("Track::set_turnout_id"); + Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0); + + if(driver && turnout_id) + driver->remove_turnout(turnout_id); turnout_id = i; layout.create_blocks(*this); layout.update_routes(); - if(layout.has_driver() && turnout_id) - layout.get_driver().add_turnout(turnout_id, type); + if(driver && turnout_id) + driver->add_turnout(turnout_id, type); } void Track::set_sensor_id(unsigned i) @@ -183,6 +189,13 @@ void Track::set_active_path(unsigned p) layout.get_driver().set_turnout(turnout_id, p); } +float Track::get_path_length(int p) const +{ + if(p<0) + p = active_path; + return type.get_path_length(p); +} + OrientedPoint Track::get_point(unsigned epi, unsigned path, float d) const { OrientedPoint p = type.get_point(epi, path, d); @@ -337,9 +350,14 @@ bool Track::break_link(unsigned i) return false; links[i] = 0; - other->break_link(*this); - // XXX Creates the blocks twice, because the other track calls this too - layout.create_blocks(*this); + if(!other->break_link(*this)) + { + /* If the call doesn't succeed, it means that the other track already + broke the link and is calling us right now. Recreate blocks in the inner + call so it occurs before any signals are emitted. */ + layout.create_blocks(*this); + } + signal_link_changed.emit(i, 0); return true;