drp_route->set_selected_index(0);
const map<string, Route *> &routes = engineer.get_layout().get_routes();
unsigned n = 1;
- for(map<string, Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n)
- {
- drp_route->append(i->second->get_name());
- if(i->second==train.get_route())
- drp_route->set_selected_index(n);
- }
+ for(map<string, Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
+ if(!i->second->is_temporary())
+ {
+ drp_route->append(i->second->get_name());
+ if(i->second==train.get_route())
+ drp_route->set_selected_index(n);
+ ++n;
+ }
}
void RouteSelect::on_ok_clicked()
{
const map<string, Route *> &routes = engineer.get_layout().get_routes();
map<string, Route *>::const_iterator i = routes.begin();
- advance(i, drp_route->get_selected_index()-1);
+ unsigned n = drp_route->get_selected_index()-1;
+ while(i!=routes.end())
+ {
+ if(!i->second->is_temporary())
+ {
+ if(!n)
+ break;
+ --n;
+ }
+ ++i;
+ }
train.set_route(i->second);
}
for(map<string, Route *>::iterator i=routes.begin(); i!=routes.end(); ++i)
{
+ if(i->second->is_temporary())
+ continue;
+
DataFile::Statement st("route");
st.append(i->first);
i->second->save(st.sub);
{
for(map<string, Route *>::iterator i=routes.begin(); i!=routes.end(); ++i)
{
+ if(i->second->is_temporary())
+ continue;
+
/* We must copy the turnout map, since adding tracks to the route will
(temporarily) mess it up */
const map<unsigned, int> turnouts = i->second->get_turnouts();
while(1)
{
// Traverse the track and get the next one
+ if(track->get_type().get_endpoints().size()<2)
+ break;
unsigned out_ep = track->traverse(ep, trk_path);
Track *next = track->get_links()[out_ep];
if(!next || next == start)
for(list<const Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
route->add_track(**i);
+ route->set_temporary(true);
+
return route;
}
Route::Route(Layout &l, const string &n):
layout(l),
- name(n)
+ name(n),
+ temporary(false)
{
layout.add_route(*this);
layout.signal_track_removed.connect(sigc::mem_fun(this, &Route::track_removed));
layout.remove_route(*this);
}
+void Route::set_temporary(bool t)
+{
+ temporary = t;
+}
+
int Route::get_turnout(unsigned id) const
{
map<unsigned, int>::const_iterator i = turnouts.find(id);
private:
Layout &layout;
std::string name;
+ bool temporary;
std::set<const Track *> tracks;
std::map<unsigned, int> turnouts;
~Route();
const std::string &get_name() const { return name; }
+ void set_temporary(bool);
+ bool is_temporary() const { return temporary; }
int get_turnout(unsigned) const;
const std::map<unsigned, int> &get_turnouts() const { return turnouts; }
void add_track(const Track &);
const VehicleType &vtype = veh.get_type();
Track *track = veh.get_track();
+ if(!track)
+ return 0;
unsigned entry = veh.get_entry();
float result = -vtype.get_length()/2;
result += track->get_type().get_path_length(track->get_active_path());
first = false;
+ if(track->get_type().get_endpoints().size()<2)
+ return result;
+
unsigned exit = track->traverse(entry);
Track *next = track->get_link(exit);
}
if(route)
- st.push_back((DataFile::Statement("route"), route->get_name()));
+ {
+ if(!route->is_temporary())
+ st.push_back((DataFile::Statement("route"), route->get_name()));
+ else if(next_route && !next_route->is_temporary())
+ st.push_back((DataFile::Statement("route"), next_route->get_name()));
+ }
if(timetable)
{
unsigned good_sens = nsens;
while(good_sens<3)
{
+ if(last->block->get_endpoints().size()<2)
+ {
+ good = last;
+ good_sens = nsens;
+ break;
+ }
+
// Traverse to the next block
unsigned exit = last->block->traverse(last->entry);
Block *link = last->block->get_link(exit);