]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/block.cpp
Ignore the click that causes manipulator to finish
[r2c2.git] / source / libmarklin / block.cpp
index b9b65ad710dca9dd833177ee993b31562c3c4b5b..e8e367f7255715dc3c7ac2343763ae7da11021bf 100644 (file)
@@ -84,6 +84,14 @@ bool Block::has_track(Track &t) const
        return tracks.count(&t);
 }
 
+const Block::Endpoint &Block::get_endpoint(unsigned i) const
+{
+       if(i>=endpoints.size())
+               throw InvalidParameterValue("Endpoint index out of range");
+
+       return endpoints[i];
+}
+
 int Block::get_endpoint_by_link(Block &other) const
 {
        for(unsigned i=0; i<endpoints.size(); ++i)
@@ -103,12 +111,7 @@ float Block::get_path_length(unsigned entry, const Route *route) const
        float result = 0;
        while(t_iter && has_track(*t_iter))
        {
-               int path = -1;
-               if(t_iter->get_turnout_id() && route)
-                       path = route->get_turnout(t_iter->get_turnout_id());
-               if(path==-1)
-                       path = t_iter->get_active_path();
-
+               unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path());
                result += t_iter->get_type().get_path_length(path);
 
                t_iter = t_iter.next(path);
@@ -168,7 +171,7 @@ bool Block::reserve(Train *t)
 
 void Block::find_paths(TrackIter track, unsigned path)
 {
-       unsigned mask = track->get_type().get_endpoints()[track.entry()].paths;
+       unsigned mask = track.endpoint().paths;
        for(unsigned i=0; mask>>i; ++i)
                if(mask&(1<<i))
                {