X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fblock.cpp;h=a29469c4fd9b97e32751987e3c42ac6f903b078e;hb=80dcfa55c913037066e43fa115ae56fa51b974f2;hp=9a9164ea292770380548aea3a2c517ac4fbe327d;hpb=6dc18b0e518407bd2a86602bae1e9bbae05da7c8;p=r2c2.git diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index 9a9164e..a29469c 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -5,7 +5,7 @@ Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ -#include +#include #include "control.h" #include "block.h" #include "tracktype.h" @@ -17,11 +17,9 @@ using namespace Msp; namespace Marklin { -unsigned Block::next_id = 1; - Block::Block(TrafficManager &tm, Track &start): trfc_mgr(tm), - id(next_id++), + id(0), sensor_id(start.get_sensor_id()), turnout_id(start.get_turnout_id()), train(0) @@ -50,6 +48,11 @@ Block::Block(TrafficManager &tm, Track &start): } } + if(sensor_id) + id = 0x1000|sensor_id; + else if(turnout_id) + id = 0x2000|turnout_id; + for(unsigned i=0; i=endpoints.size()) throw InvalidParameterValue("Endpoint index out of range"); @@ -93,17 +96,14 @@ int Block::traverse(unsigned epi, float *len) const if(len) *len += track->get_type().get_path_length(cur_path); - int other_ep = track->traverse(track_ep, cur_path); - if(other_ep<0) - return -1; - + unsigned other_ep = track->traverse(track_ep, cur_path); for(unsigned i=0; i(other_ep)) return i; Track *next = track->get_link(other_ep); - if(tracks.count(next)==0) - return -1; + if(!tracks.count(next)) + throw LogicError("Block traversal strayed out of the block"); track_ep = next->get_endpoint_by_link(*track); track = next; } @@ -123,6 +123,15 @@ void Block::check_link(Block &other) j->link = this; } } + + if(!sensor_id && !turnout_id && endpoints.size()==2) + { + unsigned id1 = endpoints[0].link ? endpoints[0].link->get_id() : 1; + unsigned id2 = endpoints[1].link ? endpoints[1].link->get_id() : 1; + if(id2get_sensor_id()) - cout<<", sensor="<<(*tracks.begin())->get_sensor_id(); - cout<<'\n'; - for(vector::iterator i=endpoints.begin(); i!=endpoints.end(); ++i) - { - cout<<" Endpoint, link="; - if(i->link) - cout<link->id; - else - cout<<"none"; - cout<<", paths="<paths<<'\n'; - } -} - void Block::find_paths(Track &track, unsigned track_ep, unsigned path, set &visited) { visited.insert(&track);