X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibr2c2%2Ftrack.cpp;h=b2d3e63af703031446d86e5fe5986b1f7e8664fd;hb=2d44923e135a119fde31a7a50e5fcd3e400e4f41;hp=0592731c6bb24aab7cae2b44cbca29437328502f;hpb=1ff06c5bc46a677fa389ef86c6b26664368f1653;p=r2c2.git diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 0592731..b2d3e63 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of R²C² -Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -25,11 +25,14 @@ Track::Track(Layout &l, const TrackType &t): rot(0), slope(0), flex(false), - turnout_id(type.is_turnout() ? layout.allocate_turnout_id(type.is_double_address()) : 0), + turnout_id(0), sensor_id(0), links(type.get_endpoints().size()), active_path(0) { + if(type.is_turnout()) + turnout_id = layout.allocate_turnout_id(); + layout.add_track(*this); if(layout.has_driver()) @@ -62,7 +65,7 @@ Block &Track::get_block() const return *block; } -void Track::set_position(const Point &p) +void Track::set_position(const Vector &p) { pos = p; } @@ -96,8 +99,8 @@ void Track::check_slope() if(links[0] && links[1]) { - Point epp0 = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this)); - Point epp1 = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this)); + Vector epp0 = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this)); + Vector epp1 = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this)); pos.z = epp0.z; slope = epp1.z-pos.z; } @@ -106,12 +109,12 @@ void Track::check_slope() slope = 0; if(links[0]) { - Point epp = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this)); + Vector epp = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this)); pos.z = epp.z; } else if(links[1]) { - Point epp = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this)); + Vector epp = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this)); pos.z = epp.z; } } @@ -126,11 +129,7 @@ void Track::set_turnout_id(unsigned i) layout.create_blocks(*this); layout.update_routes(); if(layout.has_driver() && turnout_id) - { - layout.get_driver().add_turnout(turnout_id); - if(type.is_double_address()) - layout.get_driver().add_turnout(turnout_id+1); - } + layout.get_driver().add_turnout(turnout_id, type); } void Track::set_sensor_id(unsigned i) @@ -151,11 +150,7 @@ void Track::set_active_path(unsigned p) if(!(type.get_paths()&(1<2) - active_path = (active_path&1) | (p&2); + layout.get_driver().set_turnout(turnout_id, p); } int Track::get_endpoint_by_link(Track &other) const @@ -167,7 +162,7 @@ int Track::get_endpoint_by_link(Track &other) const return -1; } -Point Track::get_endpoint_position(unsigned epi) const +Vector Track::get_endpoint_position(unsigned epi) const { const vector &eps = type.get_endpoints(); if(epi>=eps.size()) @@ -178,7 +173,7 @@ Point Track::get_endpoint_position(unsigned epi) const float c = cos(rot); float s = sin(rot); - Point p(pos.x+c*ep.pos.x-s*ep.pos.y, pos.y+s*ep.pos.x+c*ep.pos.y, pos.z); + Vector p(pos.x+c*ep.pos.x-s*ep.pos.y, pos.y+s*ep.pos.x+c*ep.pos.y, pos.z); if(eps.size()==2 && epi==1) p.z += slope; return p; @@ -210,14 +205,14 @@ bool Track::snap_to(Track &other, bool link, float limit) for(unsigned i=0; i &eps = type.get_endpoints(); for(unsigned i=0; i &st) const { st.push_back((DataFile::Statement("position"), pos.x, pos.y, pos.z)); @@ -347,19 +359,16 @@ void Track::save(list &st) const st.push_back((DataFile::Statement("flex"), true)); } -void Track::turnout_event(unsigned addr, bool state) +void Track::turnout_event(unsigned addr, unsigned state) { if(!turnout_id) return; if(addr==turnout_id) - active_path = (active_path&2) | (state ? 1 : 0); - else if(type.is_double_address() && addr==turnout_id+1) - active_path = (active_path&1) | (state ? 2 : 0); - else - return; - - signal_path_changed.emit(active_path); + { + active_path = state; + signal_path_changed.emit(active_path); + } } @@ -376,7 +385,7 @@ Track::Loader::Loader(Track &t): void Track::Loader::position(float x, float y, float z) { - obj.pos = Point(x, y, z); + obj.pos = Vector(x, y, z); } void Track::Loader::sensor_id(unsigned id)