]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/block.cpp
Add Block::has_track and Route::has_track methods
[r2c2.git] / source / libmarklin / block.cpp
index aa16fffc6ba5b6e3f04879f0e3d5fdb206b809c3..780ee1bbd293e75a9e442f6a83a80c8a38a28f26 100644 (file)
@@ -8,6 +8,7 @@ Distributed under the GPL
 #include <algorithm>
 #include "block.h"
 #include "layout.h"
+#include "route.h"
 #include "tracktype.h"
 
 using namespace std;
@@ -71,7 +72,12 @@ Block::~Block()
        layout.remove_block(*this);
 }
 
-int Block::get_endpoint_by_link(const Block &other) const
+bool Block::has_track(Track &t) const
+{
+       return tracks.count(&t);
+}
+
+int Block::get_endpoint_by_link(Block &other) const
 {
        for(unsigned i=0; i<endpoints.size(); ++i)
                if(endpoints[i].link==&other)
@@ -81,6 +87,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 +105,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);