tracks.erase(i);
}
-Track3D &Layout3D::get_track(const Track &t) const
+Track3D &Layout3D::get_track(Track &t) const
{
for(list<Track3D *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
if(&(*i)->get_track()==&t)
void add_track(Track3D &);
void remove_track(Track3D &);
const std::list<Track3D *> &get_tracks() const { return tracks; }
- Track3D &get_track(const Track &) const;
+ Track3D &get_track(Track &) const;
Track3D *pick_track(float, float, float) const;
void add_vehicle(Vehicle3D &);
try
{
- const set<Track *> &stracks = selection.get_tracks();
- set<const Track *> tracks(stracks.begin(), stracks.end());
- cur_route->add_tracks(tracks);
+ cur_route->add_tracks(selection.get_tracks());
}
catch(const Exception &e)
{
layout.remove_block(*this);
}
-int Block::get_endpoint_by_link(const Block &other) const
+int Block::get_endpoint_by_link(Block &other) const
{
for(unsigned i=0; i<endpoints.size(); ++i)
if(endpoints[i].link==&other)
unsigned get_turnout_id() const { return turnout_id; }
const std::set<Track *> &get_tracks() const { return tracks; }
const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
- int get_endpoint_by_link(const Block &) const;
+ int get_endpoint_by_link(Block &) const;
unsigned traverse(unsigned, float * =0) const;
unsigned traverse(unsigned, const Route *, float * =0) const;
void check_link(Block &);
throw KeyError("Unknown block", lexical_cast(id));
}
-Block &Layout::get_block_by_track(const Track &t) const
+Block &Layout::get_block_by_track(Track &t) const
{
for(set<Block *>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
- if((*i)->get_tracks().count(const_cast<Track *>(&t)))
+ if((*i)->get_tracks().count(&t))
return **i;
throw InvalidParameterValue("No block found for track");
(*i)->check_link(**j);
}
-void Layout::create_blocks(const Track &track)
+void Layout::create_blocks(Track &track)
{
const vector<Track *> &links = track.get_links();
for(set<Block *>::iterator i=blocks.begin(); i!=blocks.end();)
{
- bool del = (*i)->get_tracks().count(const_cast<Track *>(&track));
+ bool del = (*i)->get_tracks().count(&track);
for(vector<Track *>::const_iterator j=links.begin(); (!del && j!=links.end()); ++j)
del = (*i)->get_tracks().count(*j);
void add_block(Block &);
Block &get_block(unsigned) const;
- Block &get_block_by_track(const Track &) const;
+ Block &get_block_by_track(Track &) const;
const std::set<Block *> &get_blocks() const { return blocks; }
void create_blocks();
- void create_blocks(const Track &);
+ void create_blocks(Track &);
void remove_block(Block &);
void add_route(Route &);
using namespace Marklin;
-typedef std::pair<const Track *, unsigned> Key;
+typedef std::pair<Track *, unsigned> Key;
struct Node
{
- const Track *track;
+ Track *track;
unsigned ep;
Node *prev;
float dist;
track(0), ep(0), prev(0), dist(0)
{ }
- Node(const Track &t, unsigned e):
+ Node(Track &t, unsigned e):
track(&t), ep(e), prev(0), dist(0)
{ }
- Node(const Track &t, unsigned e, Node &r, float d):
+ Node(Track &t, unsigned e, Node &r, float d):
track(&t), ep(e), prev(&r), dist(prev->dist+d)
{ }
struct TrackMatch
{
- const Track &track;
+ Track &track;
- TrackMatch(const Track &t): track(t) { }
+ TrackMatch(Track &t): track(t) { }
- bool operator()(const Track &t) const { return &t==&track; }
+ bool operator()(Track &t) const { return &t==&track; }
};
struct TrackInSet
{
- const set<const Track *> &tracks;
+ const set<Track *> &tracks;
- TrackInSet(const set<const Track *> &t): tracks(t) { }
+ TrackInSet(const set<Track *> &t): tracks(t) { }
- bool operator()(const Track &t) const { return tracks.count(&t); }
+ bool operator()(Track &t) const { return tracks.count(&t); }
};
template<typename Pred>
-list<const Track *> dijkstra(const Track &from, unsigned ep, const Pred &goal)
+list<Track *> dijkstra(Track &from, unsigned ep, const Pred &goal)
{
map<Key, Node> track_nodes;
priority_queue<Node> nodes;
if(!final)
throw InvalidParameterValue("Could not find a route");
- list<const Track *> result;
+ list<Track *> result;
for(Node *node=final; node; node=node->prev)
result.push_front(node->track);
}
template<typename Pred>
-Route *create_route(const Track &from, unsigned ep, const Pred &goal)
+Route *create_route(Track &from, unsigned ep, const Pred &goal)
{
- list<const Track *> tracks = dijkstra(from, ep, goal);
+ list<Track *> tracks = dijkstra(from, ep, goal);
Route *route = new Route(from.get_layout());
- for(list<const Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ for(list<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
route->add_track(**i);
route->set_name("Pathfinder");
void Route::update_turnouts()
{
set<unsigned> found;
- for(set<const Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
if(unsigned tid = (*i)->get_turnout_id())
{
found.insert(tid);
return -1;
}
-void Route::add_track(const Track &trk)
+void Route::add_track(Track &trk)
{
if(tracks.count(&trk))
return;
update_turnouts();
}
-void Route::add_tracks(const set<const Track *> &trks)
+void Route::add_tracks(const set<Track *> &trks)
{
- set<const Track *> pending;
- for(set<const Track *>::const_iterator i=trks.begin(); i!=trks.end(); ++i)
+ set<Track *> pending;
+ for(set<Track *>::const_iterator i=trks.begin(); i!=trks.end(); ++i)
if(!tracks.count(*i))
pending.insert(*i);
while(!pending.empty())
{
bool found = false;
- for(set<const Track *>::const_iterator i=pending.begin(); i!=pending.end(); ++i)
+ for(set<Track *>::const_iterator i=pending.begin(); i!=pending.end(); ++i)
if(tracks.empty() || check_validity(**i)==7)
{
tracks.insert(*i);
update_turnouts();
}
-void Route::add_track_chain(const Track &start, unsigned ep, const TurnoutMap &trnts)
+void Route::add_track_chain(Track &start, unsigned ep, const TurnoutMap &trnts)
{
- const Track *track = &start;
+ Track *track = &start;
while(1)
{
if(track->get_type().is_dead_end())
st.push_back((DataFile::Statement("turnout"), i->first, i->second));
}
-unsigned Route::check_validity(const Track &trk) const
+unsigned Route::check_validity(Track &trk) const
{
unsigned result = 4;
- for(set<const Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
{
int epi=(*i)->get_endpoint_by_link(trk);
if(epi>=0)
tracks.erase(&t);
}
-Route *Route::find(const Track &from, unsigned ep, const Track &to)
+Route *Route::find(Track &from, unsigned ep, Track &to)
{
return create_route(from, ep, TrackMatch(to));
}
-Route *Route::find(const Track &from, unsigned ep, const Route &to)
+Route *Route::find(Track &from, unsigned ep, const Route &to)
{
return create_route(from, ep, TrackInSet(to.get_tracks()));
}
-Route *Route::find(const Track &from, unsigned ep, const set<const Track *> &to)
+Route *Route::find(Track &from, unsigned ep, const set<Track *> &to)
{
return create_route(from, ep, TrackInSet(to));
}
Layout &layout;
std::string name;
bool temporary;
- std::set<const Track *> tracks;
+ std::set<Track *> tracks;
TurnoutMap turnouts;
public:
void update_turnouts();
int get_turnout(unsigned) const;
const std::map<unsigned, int> &get_turnouts() const { return turnouts; }
- void add_track(const Track &);
- void add_tracks(const std::set<const Track *> &);
- void add_track_chain(const Track &, unsigned, const TurnoutMap &);
- const std::set<const Track *> &get_tracks() const { return tracks; }
+ void add_track(Track &);
+ void add_tracks(const std::set<Track *> &);
+ void add_track_chain(Track &, unsigned, const TurnoutMap &);
+ const std::set<Track *> &get_tracks() const { return tracks; }
void save(std::list<Msp::DataFile::Statement> &) const;
private:
- unsigned check_validity(const Track &) const;
+ unsigned check_validity(Track &) const;
void track_removed(Track &);
public:
- static Route *find(const Track &, unsigned, const Track &);
- static Route *find(const Track &, unsigned, const Route &);
- static Route *find(const Track &, unsigned, const std::set<const Track *> &);
+ static Route *find(Track &, unsigned, Track &);
+ static Route *find(Track &, unsigned, const Route &);
+ static Route *find(Track &, unsigned, const std::set<Track *> &);
};
} // namespace Marklin
active_path = (active_path&1) | (p&2);
}
-int Track::get_endpoint_by_link(const Track &other) const
+int Track::get_endpoint_by_link(Track &other) const
{
for(unsigned i=0; i<links.size(); ++i)
if(links[i]==&other)
void set_active_path(unsigned);
unsigned get_active_path() const { return active_path; }
- int get_endpoint_by_link(const Track &) const;
+ int get_endpoint_by_link(Track &) const;
Point get_endpoint_position(unsigned) const;
float get_endpoint_direction(unsigned) const;
bool snap_to(Track &, bool);
signal_route_changed.emit(get_route());
}
-void Train::go_to(const Track &to)
+void Train::go_to(Track &to)
{
for(list<BlockRef>::const_iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
- if(i->block->get_tracks().count(const_cast<Track *>(&to)))
+ if(i->block->get_tracks().count(&to))
{
signal_arrived.emit();
set_route(0);
unsigned ep = track->get_endpoint_by_link(from);
- set<const Track *> tracks;
+ set<Track *> tracks;
for(list<RouteRef>::iterator i=routes.begin(); i!=routes.end(); ++i)
tracks.insert(i->route->get_tracks().begin(), i->route->get_tracks().end());
Route *diversion = 0;
// Check if we've reached the next route
if(routes.size()>1)
{
- const set<const Track *> &rtracks = (++routes.begin())->route->get_tracks();
+ const set<Track *> &rtracks = (++routes.begin())->route->get_tracks();
for(list<BlockRef>::iterator j=rsv_blocks.begin(); j!=i; ++j)
if(rtracks.count(j->block->get_endpoints()[j->entry].track))
{
i->entry = i->block->traverse(i->entry);
}
-bool Train::advance_route(list<RouteRef>::iterator &iter, const Track &track)
+bool Train::advance_route(list<RouteRef>::iterator &iter, Track &track)
{
while(iter!=routes.end() && !iter->route->get_tracks().count(&track))
++iter;
lead->set_temporary(true);
}
- set<const Track *> tracks;
+ set<Track *> tracks;
for(list<BlockRef>::iterator i=cur_blocks.begin(); i!=rsv_blocks.end(); )
{
const set<Track *> &btracks = i->block->get_tracks();
return lead;
}
-bool Train::is_valid_diversion(const Route &diversion, const Track &from, unsigned from_ep)
+bool Train::is_valid_diversion(const Route &diversion, Track &from, unsigned from_ep)
{
float diversion_len = 0;
- const Track *track = &from;
+ Track *track = &from;
unsigned ep = from_ep;
while(diversion.get_tracks().count(track))
{
path = diversion.get_turnout(track->get_turnout_id());
diversion_len += track->get_type().get_path_length(path);
- const Track *next = track->get_link(track->traverse(ep, path));
+ Track *next = track->get_link(track->traverse(ep, path));
ep = next->get_endpoint_by_link(*track);
track = next;
if(!advance_route(route, from))
return false;
- set<const Track *> visited;
+ set<Track *> visited;
float route_len = 0;
track = &from;
ep = from_ep;
return false;
visited.insert(track);
- const Track *next = track->get_link(track->traverse(ep, path));
+ Track *next = track->get_link(track->traverse(ep, path));
ep = next->get_endpoint_by_link(*track);
track = next;
Timetable *get_timetable() { return timetable; }
void set_route(const Route *);
- void go_to(const Track &);
+ void go_to(Track &);
bool divert(Track &);
const Route *get_route() const;
void place(Block &, unsigned);
void release_blocks(std::list<BlockRef> &);
void release_blocks(std::list<BlockRef> &, std::list<BlockRef>::iterator, std::list<BlockRef>::iterator);
void reverse_blocks(std::list<BlockRef> &) const;
- bool advance_route(std::list<RouteRef>::iterator &, const Track &);
+ bool advance_route(std::list<RouteRef>::iterator &, Track &);
Route *create_lead_route(Route *, const Route *);
- bool is_valid_diversion(const Route &, const Track &, unsigned);
+ bool is_valid_diversion(const Route &, Track &, unsigned);
};
} // namespace Marklin