-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#ifndef LIBR2C2_TRACKTYPE_H_
#define LIBR2C2_TRACKTYPE_H_
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
#include "articlenumber.h"
#include "geometry.h"
+#include "objecttype.h"
#include "trackpart.h"
namespace R2C2 {
-class TrackType
+class TrackType: public ObjectType
{
public:
struct Endpoint
{
- Point pos;
- float dir; // Direction outwards from the endpoint
+ Vector pos;
+ Angle dir; // Direction outwards from the endpoint
unsigned paths;
- Endpoint(float, float, float, unsigned);
+ Endpoint(float, float, const Angle &, unsigned);
+
+ bool has_path(unsigned p) const { return paths&(1<<p); }
+ bool has_common_paths(const Endpoint &e) const { return paths&e.paths; }
};
- class Loader: public Msp::DataFile::BasicLoader<TrackType>
+ class Loader: public Msp::DataFile::DerivedObjectLoader<TrackType, ObjectType::Loader>
{
private:
bool state_bits_set;
};
private:
- ArticleNumber art_nr;
- std::string description;
std::vector<TrackPart> parts;
std::vector<Endpoint> endpoints;
unsigned state_bits;
unsigned autofit_preference;
+ std::string object;
public:
TrackType(const ArticleNumber &);
- const ArticleNumber &get_article_number() const { return art_nr; }
- const std::string &get_description() const { return description; }
float get_total_length() const;
float get_path_length(int) const;
unsigned get_paths() const;
bool is_turnout() const;
bool is_dead_end() const;
unsigned get_autofit_preference() const { return autofit_preference; }
+ const std::string &get_object() const { return object; }
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;
+ TrackPoint get_nearest_point(const Vector &) const;
private:
void collect_endpoints();