-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#ifndef LIBR2C2_TRACK_H_
#define LIBR2C2_TRACK_H_
#include <list>
#include <set>
#include <sigc++/trackable.h>
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
#include "geometry.h"
+#include "object.h"
+#include "tracktype.h"
namespace R2C2 {
class Block;
class Layout;
-class TrackType;
-class Track: public sigc::trackable
+class Track: public Object, public sigc::trackable
{
public:
- class Loader: public Msp::DataFile::BasicLoader<Track>
+ class Loader: public Msp::DataFile::ObjectLoader<Track>
{
public:
Loader(Track &);
private:
void position(float, float, float);
+ void rotation(float);
void sensor_id(unsigned);
void turnout_id(unsigned);
};
sigc::signal<void, unsigned> signal_path_changed;
private:
- Layout &layout;
const TrackType &type;
Block *block;
- Vector pos;
- float rot;
float slope;
bool flex;
unsigned turnout_id;
unsigned sensor_id;
std::vector<Track *> links;
unsigned active_path;
+ bool path_changing;
Track(const Track &);
Track &operator=(const Track &);
Track(Layout &, const TrackType &);
~Track();
- Layout &get_layout() const { return layout; }
- const TrackType &get_type() const { return type; }
+ virtual Track *clone(Layout * = 0) const;
+ virtual const TrackType &get_type() const { return type; }
void set_block(Block *);
Block &get_block() const;
- void set_position(const Vector &);
- void set_rotation(float);
+ virtual void set_position(const Vector &);
+ virtual void set_rotation(const Angle &);
void set_slope(float);
void set_flex(bool);
- const Vector &get_position() const { return pos; }
- float get_rotation() const { return rot; }
float get_slope() const { return slope; }
bool get_flex() const { return flex; }
+private:
void check_slope();
+public:
void set_turnout_id(unsigned);
void set_sensor_id(unsigned);
unsigned get_turnout_id() const { return turnout_id; }
unsigned get_sensor_id() const { return sensor_id; }
void set_active_path(unsigned);
unsigned get_active_path() const { return active_path; }
+ bool is_path_changing() const { return path_changing; }
- int get_endpoint_by_link(Track &) const;
- Vector get_endpoint_position(unsigned) const;
- float get_endpoint_direction(unsigned) const;
- bool snap_to(Track &, bool, float = 0);
- bool snap(Vector &, float &) const;
- void break_link(Track &);
- void break_links();
- const std::vector<Track *> &get_links() const { return links; }
- Track *get_link(unsigned) const;
TrackPoint get_point(unsigned, unsigned, float) const;
TrackPoint get_point(unsigned, float) const;
- bool collide_ray(const Vector &, const Vector &);
+ virtual unsigned get_n_snap_nodes() const;
+ virtual Snap get_snap_node(unsigned) const;
+ virtual bool snap(Snap &, float, SnapType = SNAP_DEFAULT) const;
+private:
+ virtual SnapType get_default_snap_type_to(const Object &) const;
+
+public:
+ virtual unsigned get_n_link_slots() const;
+ virtual Track *get_link(unsigned) const;
+ const std::vector<Track *> &get_links() const { return links; }
+ virtual int get_link_slot(const Object &) const;
+ virtual bool link_to(Object &);
+ using Object::break_link;
+ virtual bool break_link(unsigned);
void save(std::list<Msp::DataFile::Statement> &) const;
private: