From: Mikko Rasa Date: Fri, 12 Nov 2010 21:45:26 +0000 (+0000) Subject: Fix and improve Route::check_validity X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=4513d00658c453b49d49bdfa97ec0ce67f576475;p=r2c2.git Fix and improve Route::check_validity --- diff --git a/source/libmarklin/route.cpp b/source/libmarklin/route.cpp index befaa6d..79886d2 100644 --- a/source/libmarklin/route.cpp +++ b/source/libmarklin/route.cpp @@ -180,7 +180,7 @@ void Route::update_turnouts() const vector &links = (*i)->get_links(); // Build a combined path mask from linked endpoints - unsigned mask = 15; + unsigned mask = (*i)->get_type().get_paths(); for(unsigned j=0; j &st) const unsigned Route::check_validity(Track &trk) const { unsigned result = 4; - for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + const vector &links = trk.get_links(); + for(vector::const_iterator i=links.begin(); i!=links.end(); ++i) { - int epi=(*i)->get_endpoint_by_link(trk); - if(epi>=0) + if(!*i) + continue; + if(!tracks.count(*i)) + continue; + + // Linked to an existing track - good + result |= 1; + + if(unsigned tid = (*i)->get_turnout_id()) { - // Linked to an existing track - good - result |= 1; - const vector &endpoints = (*i)->get_type().get_endpoints(); - if(unsigned tid=(*i)->get_turnout_id()) + const TrackType::Endpoint &ep = (*i)->get_type().get_endpoint((*i)->get_endpoint_by_link(trk)); + int path = get_turnout(tid); + if(path>=0) { - int r = get_turnout(tid); - if(r>=0) - { - // Linking to a turnout with path set is only good if we're continuing that path - if(endpoints[epi].paths&(1< &links = (*i)->get_links(); - int epj = -1; - for(unsigned k=0; k &tlinks = (*i)->get_links(); + unsigned count = 0; + for(unsigned j=0; jget_turnout_id(); + if(tid2) { - ++count; - epj = k; + const TrackType::Endpoint &ep2 = tlinks[j]->get_type().get_endpoint(tlinks[j]->get_endpoint_by_link(**i)); + path = get_turnout(tid2); + // Ignore a linked turnout with some other path set + if(path>0 && !(ep2.paths&(1<=0 && !(endpoints[epi].paths&endpoints[epj].paths)) + ++count; + + const TrackType::Endpoint &ep2 = (*i)->get_type().get_endpoint(j); + if(!(ep.paths&ep2.paths)) // Impossible path through the turnout - not good result &= 3; } - } + + // Only good if at most one other track is linked to the turnout + if(count<=1) + result |= 2; } - else - // Linked to something linear - good - result |= 2; } + else + // Linked to something linear - good + result |= 2; } return result;