- {
- if(router->metrics_stale)
- {
- router->create_metrics();
- router->metrics_stale = false;
- }
- router->planner = planner;
- }
+ if(!planner || router->planner.get()==planner)
+ routers.push_back(router);
+}
+
+void TrainRouter::start_planning(Layout &layout)
+{
+ vector<TrainRouter *> routers;
+ get_routers(layout, routers);
+
+ for(vector<TrainRouter *>::const_iterator i=routers.begin(); i!=routers.end(); ++i)
+ if((*i)->metrics_stale)
+ (*i)->create_metrics();
+
+ RefPtr<TrainRoutePlanner> planner = new TrainRoutePlanner(layout);
+ for(vector<TrainRouter *>::const_iterator i=routers.begin(); i!=routers.end(); ++i)
+ {
+ (*i)->waypoints_changed = false;
+ (*i)->planner = planner;
+ }
+
+ planner->plan_async();
+}
+
+void TrainRouter::apply_plan(Layout &layout, TrainRoutePlanner &planner)
+{
+ if(planner.get_result()==TrainRoutePlanner::FAILED)
+ layout.emergency(0, "Route planning failed");