layout.add_track(*this);
layout.get_scene().add(*this);
- const vector<Endpoint> &type_eps = track.get_type().get_endpoints();
+ const vector<TrackType::Endpoint> &type_eps = track.get_type().get_endpoints();
for(unsigned i=0; i<type_eps.size(); ++i)
endpoints.push_back(new Endpoint3D(*this, i));
}
{
visited.insert(&track);
- const vector<Marklin::Endpoint> &eps = track.get_type().get_endpoints();
+ const vector<TrackType::Endpoint> &eps = track.get_type().get_endpoints();
for(unsigned i=0; i<eps.size(); ++i)
{
if(i==track_ep) continue;
+++ /dev/null
-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
-#ifndef MARKLIN_ENDPOINT_H_
-#define MARKLIN_ENDPOINT_H_
-
-#include "geometry.h"
-
-namespace Marklin {
-
-struct Endpoint
-{
- Point pos;
- float dir; // Direction outwards from the endpoint
- unsigned paths;
-
- Endpoint(): dir(0), paths(0) { }
- Endpoint(float x, float y, float d, unsigned p): pos(x, y), dir(d), paths(p) { }
-};
-
-} // namespace Marklin
-
-#endif
}
const TrackType &type = lowest.track->get_type();
- const vector<Endpoint> &eps = type.get_endpoints();
+ const vector<TrackType::Endpoint> &eps = type.get_endpoints();
const vector<Track *> &links = lowest.track->get_links();
for(unsigned i=0; i<eps.size(); ++i)
{
{
found.insert(tid);
- const vector<Endpoint> &endpoints = (*i)->get_type().get_endpoints();
+ const vector<TrackType::Endpoint> &endpoints = (*i)->get_type().get_endpoints();
const vector<Track *> &links = (*i)->get_links();
// Build a combined path mask from linked endpoints
if(unsigned tid2 = links[j]->get_turnout_id())
{
- const Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)];
+ const TrackType::Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)];
int p = get_turnout(tid2);
if(p>=0 && !(ep.paths&(1<<p)))
{
{
// Linked to an existing track - good
result |= 1;
- const vector<Endpoint> &endpoints = (*i)->get_type().get_endpoints();
+ const vector<TrackType::Endpoint> &endpoints = (*i)->get_type().get_endpoints();
if(unsigned tid=(*i)->get_turnout_id())
{
int r = get_turnout(tid);
continue;
unsigned path_mask = 1<<j->second;
- const vector<Endpoint> &eps = (*i)->get_type().get_endpoints();
+ const vector<TrackType::Endpoint> &eps = (*i)->get_type().get_endpoints();
for(unsigned k=0; k<eps.size(); ++k)
if(eps[k].paths&path_mask)
{
Point Track::get_endpoint_position(unsigned epi) const
{
- const vector<Endpoint> &eps = type.get_endpoints();
+ const vector<TrackType::Endpoint> &eps = type.get_endpoints();
if(epi>=eps.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw InvalidParameterValue("TrackType::Endpoint index out of range");
- const Endpoint &ep = eps[epi];
+ const TrackType::Endpoint &ep = eps[epi];
float c = cos(rot);
float s = sin(rot);
float Track::get_endpoint_direction(unsigned epi) const
{
- const vector<Endpoint> &eps = type.get_endpoints();
+ const vector<TrackType::Endpoint> &eps = type.get_endpoints();
if(epi>=eps.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw InvalidParameterValue("TrackType::Endpoint index out of range");
- const Endpoint &ep = eps[epi];
+ const TrackType::Endpoint &ep = eps[epi];
return rot+ep.dir;
}
bool Track::snap_to(Track &other, bool link)
{
float limit = (link && !flex && !other.get_flex()) ? 1e-6 : 1e-4;
- const vector<Endpoint> &eps = type.get_endpoints();
- const vector<Endpoint> &other_eps = other.get_type().get_endpoints();
+ const vector<TrackType::Endpoint> &eps = type.get_endpoints();
+ const vector<TrackType::Endpoint> &other_eps = other.get_type().get_endpoints();
for(unsigned i=0; i<eps.size(); ++i)
{
bool Track::snap(Point &pt, float &d) const
{
- const vector<Endpoint> &eps = type.get_endpoints();
+ const vector<TrackType::Endpoint> &eps = type.get_endpoints();
for(unsigned i=0; i<eps.size(); ++i)
{
int TrackIter::get_exit(unsigned path) const
{
- const vector<Endpoint> &eps = _track->get_type().get_endpoints();
+ const vector<TrackType::Endpoint> &eps = _track->get_type().get_endpoints();
// Find an endpoint that's connected to the entry and has the requested path
for(unsigned i=0; i<eps.size(); ++i)
#define MARKLIN_TRACKPART_H_
#include <msp/datafile/loader.h>
-#include "endpoint.h"
#include "geometry.h"
namespace Marklin {
}
}
+TrackType::Endpoint::Endpoint(float x, float y, float d, unsigned p):
+ pos(x, y),
+ dir(d),
+ paths(p)
+{ }
+
TrackType::Loader::Loader(TrackType &t):
Msp::DataFile::BasicLoader<TrackType>(t)
#define LIBMARKLIN_TRACKTYPE_H_
#include <msp/datafile/loader.h>
-#include "endpoint.h"
+#include "geometry.h"
#include "trackpart.h"
namespace Marklin {
class TrackType
{
public:
+ struct Endpoint
+ {
+ Point pos;
+ float dir; // Direction outwards from the endpoint
+ unsigned paths;
+
+ Endpoint(float, float, float, unsigned);
+ };
+
class Loader: public Msp::DataFile::BasicLoader<TrackType>
{
public:
if(block->get_turnout_id())
{
- const Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
+ const TrackType::Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
bool multiple_paths = (track_ep.paths&(track_ep.paths-1));
if(multiple_paths || !last->get_turnout_id())