X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrack.cpp;h=7b9a4a2d70b30febaf96ebf917cb284153ba44ac;hb=0b75458245997b9df6da47cc4534341c8426084b;hp=e4d7badfb9f9e053d2dc7fa7650b039bf890cf90;hpb=b88d3630a0e3fdd763db018bbe5dbfe3180a95f2;p=r2c2.git diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index e4d7bad..7b9a4a2 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -100,8 +100,8 @@ void Track::check_slope() if(links[0] && links[1]) { - Vector epp0 = links[0]->get_snap_node(links[0]->get_endpoint_by_link(*this)).position; - Vector epp1 = links[1]->get_snap_node(links[1]->get_endpoint_by_link(*this)).position; + Vector epp0 = links[0]->get_snap_node(links[0]->get_link_slot(*this)).position; + Vector epp1 = links[1]->get_snap_node(links[1]->get_link_slot(*this)).position; position.z = epp0.z; slope = epp1.z-position.z; } @@ -110,12 +110,12 @@ void Track::check_slope() slope = 0; if(links[0]) { - Vector epp = links[0]->get_snap_node(links[0]->get_endpoint_by_link(*this)).position; + Vector epp = links[0]->get_snap_node(links[0]->get_link_slot(*this)).position; position.z = epp.z; } else if(links[1]) { - Vector epp = links[1]->get_snap_node(links[1]->get_endpoint_by_link(*this)).position; + Vector epp = links[1]->get_snap_node(links[1]->get_link_slot(*this)).position; position.z = epp.z; } } @@ -155,106 +155,6 @@ void Track::set_active_path(unsigned p) layout.get_driver().set_turnout(turnout_id, p); } -int Track::get_endpoint_by_link(Track &other) const -{ - for(unsigned i=0; i &eps = type.get_endpoints(); - const vector &other_eps = other.get_type().get_endpoints(); - - for(unsigned i=0; i::iterator i=links.begin(); i!=links.end(); ++i) - if(*i==&trk) - { - *i = 0; - trk.break_link(*this); - // XXX Creates the blocks twice - layout.create_blocks(*this); - signal_link_changed.emit(i-links.begin(), 0); - return; - } -} - -void Track::break_links() -{ - for(vector::iterator i=links.begin(); i!=links.end(); ++i) - if(Track *trk=*i) - { - *i = 0; - trk->break_link(*this); - } -} - -Track *Track::get_link(unsigned i) const -{ - if(i>=links.size()) - throw out_of_range("Track::get_link"); - - return links[i]; -} - TrackPoint Track::get_point(unsigned epi, unsigned path, float d) const { TrackPoint p = type.get_point(epi, path, d); @@ -346,6 +246,89 @@ SnapType Track::get_default_snap_type_to(const Object &other) const return NO_SNAP; } +unsigned Track::get_n_link_slots() const +{ + return links.size(); +} + +Track *Track::get_link(unsigned i) const +{ + if(i>=links.size()) + throw out_of_range("Track::get_link"); + + return links[i]; +} + +int Track::get_link_slot(const Object &other) const +{ + for(unsigned i=0; i(&other); + if(!otrack) + return false; + + float limit = layout.get_catalogue().get_gauge(); + if(!flex && !otrack->get_flex()) + limit /= 10; + limit *= limit; + + unsigned nsn = get_n_snap_nodes(); + unsigned other_nsn = other.get_n_snap_nodes(); + for(unsigned i=0; iM_PI) + da -= M_PI*2; + + if(d.x*d.x+d.y*d.y-0.01 && da<0.01) + { + break_link(i); + links[i] = otrack; + otrack->links[j] = this; + layout.create_blocks(*this); + + signal_link_changed.emit(i, otrack); + otrack->signal_link_changed.emit(j, this); + return true; + } + } + } + + return false; +} + +bool Track::break_link(unsigned i) +{ + if(i>=links.size()) + throw out_of_range("Track::break_link"); + + Track *other = links[i]; + if(!other) + 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); + signal_link_changed.emit(i, 0); + + return true; +} + bool Track::collide_ray(const Vector &start, const Vector &ray) const { Vector local_start(start.x-position.x, start.y-position.y, start.z-position.z);