X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fblock.cpp;h=db1942bb5b613fde7ff1b71272383455740bc875;hb=97443d96ff3ce51388d2edd1e0dca8f2cd231346;hp=51f8ddb0dfe45dbd954f994ba75b1c82f759e290;hpb=651698847d5293cfb15b6fb23a394701388c0151;p=r2c2.git diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index 51f8ddb..db1942b 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -8,6 +8,7 @@ Distributed under the GPL #include #include "block.h" #include "layout.h" +#include "route.h" #include "tracktype.h" using namespace std; @@ -81,6 +82,11 @@ int Block::get_endpoint_by_link(const Block &other) const } unsigned Block::traverse(unsigned epi, float *len) const +{ + return traverse(epi, 0, len); +} + +unsigned Block::traverse(unsigned epi, const Route *route, float *len) const { if(epi>=endpoints.size()) throw InvalidParameterValue("Endpoint index out of range"); @@ -94,7 +100,11 @@ unsigned Block::traverse(unsigned epi, float *len) const while(1) { - unsigned cur_path = track->get_active_path(); + int cur_path = -1; + if(track->get_turnout_id() && route) + cur_path = route->get_turnout(track->get_turnout_id()); + if(cur_path==-1) + cur_path = track->get_active_path(); if(len) *len += track->get_type().get_path_length(cur_path); @@ -199,6 +209,11 @@ void Block::determine_id() swap(id1, id2); id = (id1<<16)|id2; } + else if(endpoints.size()==1) + { + unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1; + id = 0x10000 | id1; + } }