]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/trainpanel.cpp
Return null from Route::find if a route can't be found
[r2c2.git] / source / engineer / trainpanel.cpp
index 922e3741e272183abad52382f4255ce08c6fbfe3..cc53499050a419b7c647b76f36d908516b11ba14 100644 (file)
@@ -8,6 +8,7 @@ Distributed under the GPL
 #include <cmath>
 #include <msp/strings/formatter.h>
 #include "libmarklin/timetable.h"
+#include "libmarklin/trackiter.h"
 #include "libmarklin/vehicletype.h"
 #include "engineer.h"
 #include "routeselect.h"
@@ -262,14 +263,15 @@ void TrainPanel::place(Track *track, unsigned ep)
 {
        pick_conn.disconnect();
 
-       Block &block = engineer.get_layout().get_block_by_track(*track);
+       Block &block = track->get_block();
+       TrackIter iter(track, ep);
 
-       while(1)
+       while(block.has_track(*iter))
        {
                const vector<Block::Endpoint> &eps = block.get_endpoints();
                bool ok = false;
                for(unsigned i=0; (!ok && i<eps.size()); ++i)
-                       if(eps[i].track==track && eps[i].track_ep==ep)
+                       if(eps[i].track==iter.track() && eps[i].track_ep==iter.entry())
                        {
                                train.place(block, i);
                                ok = true;
@@ -277,14 +279,8 @@ void TrainPanel::place(Track *track, unsigned ep)
 
                if(ok)
                        break;
-               else
-               {
-                       Track *next = track->get_links()[ep];
-                       ep = next->traverse(next->get_endpoint_by_link(*track), 0);
-                       track = next;
-                       if(!block.get_tracks().count(track))
-                               break;
-               }
+
+               iter = iter.flip().reverse();
        }
 }
 
@@ -292,12 +288,6 @@ void TrainPanel::go_to(Track *track, unsigned)
 {
        pick_conn.disconnect();
 
-       try
-       {
-               train.go_to(*track);
-       }
-       catch(const Exception &e)
-       {
-               engineer.set_status(e.what());
-       }
+       if(!train.go_to(*track))
+               engineer.set_status("Could not set route");
 }