delete picking_path;
picking_path = new Path3D(*track);
if(picking_entry>=0)
- picking_path->set_mask(picking_track->get_type().get_endpoints()[picking_entry].paths);
+ picking_path->set_mask(picking_track->get_type().get_endpoint(picking_entry).paths);
else
picking_path->set_mask(picking_track->get_type().get_paths());
picking_path->set_color(GL::Color(0));
else if(btn==3 && picking_entry>=0)
{
picking_entry = (picking_entry+1)%picking_track->get_type().get_endpoints().size();
- picking_path->set_mask(picking_track->get_type().get_endpoints()[picking_entry].paths);
+ picking_path->set_mask(picking_track->get_type().get_endpoint(picking_entry).paths);
}
}
else
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)
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))
{
const std::set<Track *> &get_tracks() const { return tracks; }
bool has_track(Track &) const;
const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
+ const Endpoint &get_endpoint(unsigned) const;
int get_endpoint_by_link(Block &) const;
float get_path_length(unsigned, const Route * = 0) const;
void check_link(Block &);
if(!_block)
return TrackIter();
- const Block::Endpoint &ep = _block->get_endpoints()[_entry];
+ const Block::Endpoint &ep = _block->get_endpoint(_entry);
return TrackIter(ep.track, ep.track_ep);
}
+const Block::Endpoint &BlockIter::endpoint() const
+{
+ if(!_block)
+ throw InvalidState("BlockIter is null");
+
+ return _block->get_endpoint(_entry);
+}
+
int BlockIter::get_exit(const Route *route) const
{
const vector<Block::Endpoint> &eps = _block->get_endpoints();
Block *block() const { return _block; }
unsigned entry() const { return _entry; }
TrackIter track_iter() const;
+ const Block::Endpoint &endpoint() const;
private:
int get_exit(const Route *) const;
break;
}
- unsigned paths = lowest.track->get_type().get_endpoints()[lowest.track.entry()].paths;
+ unsigned paths = lowest.track.endpoint().paths;
for(unsigned i=0; paths>>i; ++i)
if(paths&(1<<i))
{
if(unsigned tid2 = links[j]->get_turnout_id())
{
- const TrackType::Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)];
+ const TrackType::Endpoint &ep = links[j]->get_type().get_endpoint(links[j]->get_endpoint_by_link(**i));
int p = get_turnout(tid2);
if(p>=0 && !(ep.paths&(1<<p)))
{
throw InvalidParameterValue("Endpoint index not valid for track");
}
+const TrackType::Endpoint &TrackIter::endpoint() const
+{
+ if(!_track)
+ throw InvalidState("TrackIter is null");
+
+ return _track->get_type().get_endpoint(_entry);
+}
+
int TrackIter::get_exit(unsigned path) const
{
const vector<TrackType::Endpoint> &eps = _track->get_type().get_endpoints();
#include <set>
#include <msp/core/refptr.h>
+#include "tracktype.h"
namespace Marklin {
Track *track() const { return _track; }
unsigned entry() const { return _entry; }
+ const TrackType::Endpoint &endpoint() const;
private:
int get_exit(unsigned) const;
return endpoints.size()<2;
}
+const TrackType::Endpoint &TrackType::get_endpoint(unsigned i) const
+{
+ if(i>=endpoints.size())
+ throw InvalidParameterValue("Endpoint index out of range");
+
+ return endpoints[i];
+}
+
TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
{
if(epi>=endpoints.size())
unsigned get_autofit_preference() const { return autofit_preference; }
const std::vector<TrackPart> &get_parts() const { return parts; }
const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
+ const Endpoint &get_endpoint(unsigned) const;
TrackPoint get_point(unsigned, unsigned, float) const;
private:
int route_path = route->route->get_turnout(from.get_turnout_id());
// Check that more than one path is available
- unsigned ep_paths = track->get_type().get_endpoints()[track.entry()].paths;
+ unsigned ep_paths = track.endpoint().paths;
if(!(ep_paths&(ep_paths-1)))
return false;
}
else
{
- const Block::Endpoint &bep = block.get_endpoints()[entry];
+ const Block::Endpoint &bep = block.get_endpoint(entry);
vehicles.back()->place(*bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
}
}
// Check if we've reached the next route
if(routes.size()>1)
{
- const set<Track *> &rtracks = (++routes.begin())->route->get_tracks();
+ const Route &route = *(++routes.begin())->route;
for(BlockList::iterator j=cur_blocks_end; j!=end; ++j)
- if(rtracks.count((*j)->get_endpoints()[j->entry()].track))
+ if(route.has_track(*j->track_iter()))
{
routes.pop_front();
// XXX Exceptions?
if(block->get_turnout_id())
{
- const TrackType::Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
+ const TrackType::Endpoint &track_ep = track.endpoint();
bool multiple_paths = (track_ep.paths&(track_ep.paths-1));
if(multiple_paths && cur_route!=routes.end() && cur_route->diversion!=block->get_turnout_id())
if((*i)->get_turnout_id())
{
TrackIter track = i->track_iter();
- const TrackType::Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
+ const TrackType::Endpoint &track_ep = track.endpoint();
unsigned path = 0;
list<BlockIter>::iterator j = i;
if(++j!=blocks.end())
{
TrackIter rev = j->track_iter().flip();
- unsigned mask = rev->get_type().get_endpoints()[rev.entry()].paths&track_ep.paths;
+ unsigned mask = rev.endpoint().paths&track_ep.paths;
for(path=0; mask>1; mask>>=1, ++path) ;
}
else