]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/track.h
Give zones a preferred running direction
[r2c2.git] / source / libr2c2 / track.h
1 #ifndef LIBR2C2_TRACK_H_
2 #define LIBR2C2_TRACK_H_
3
4 #include <list>
5 #include <set>
6 #include <sigc++/trackable.h>
7 #include <msp/datafile/objectloader.h>
8 #include "geometry.h"
9 #include "object.h"
10 #include "tracktype.h"
11
12 namespace R2C2 {
13
14 class Block;
15 class Layout;
16 class TrackAttachment;
17
18 class Track: public Object, public sigc::trackable
19 {
20 public:
21         class Loader: public Msp::DataFile::ObjectLoader<Track>
22         {
23         public:
24                 Loader(Track &);
25         private:
26                 void path(unsigned);
27                 void position(float, float, float);
28                 void rotation(float);
29                 void sensor_address(unsigned);
30                 void slope(float);
31                 void tilt(float);
32                 void turnout_address(unsigned);
33         };
34
35         typedef std::list<TrackAttachment *> AttachmentList;
36
37         sigc::signal<void, unsigned, Track *> signal_link_changed;
38         sigc::signal<void, unsigned> signal_path_changing;
39         sigc::signal<void, unsigned> signal_path_changed;
40
41 private:
42         const TrackType &type;
43         Block *block;
44         float slope;
45         bool flex;
46         unsigned turnout_addr;
47         unsigned turnout_id;
48         unsigned sensor_addr;
49         std::vector<Track *> links;
50         unsigned active_path;
51         bool path_changing;
52         AttachmentList attachments;
53         int preferred_exit;
54
55         Track(const Track &);
56         Track &operator=(const Track &);
57 public:
58         Track(Layout &, const TrackType &);
59         ~Track();
60
61         virtual Track *clone(Layout * = 0) const;
62         virtual const TrackType &get_type() const { return type; }
63
64         void set_block(Block *);
65         Block &get_block() const;
66         virtual void set_position(const Vector &);
67         virtual void set_rotation(const Angle &);
68         virtual void set_tilt(const Angle &);
69         void set_flex(bool);
70         bool get_flex() const { return flex; }
71 private:
72         void propagate_slope();
73         void check_slope();
74
75 public:
76         void set_turnout_address(unsigned);
77         void set_sensor_address(unsigned);
78         unsigned get_turnout_address() const { return turnout_addr; }
79         unsigned get_sensor_address() const { return sensor_addr; }
80         void set_preferred_exit(int);
81         int get_preferred_exit() const { return preferred_exit; }
82         void set_active_path(unsigned);
83         unsigned get_active_path() const { return active_path; }
84         bool is_path_changing() const { return path_changing; }
85         float get_path_length(int = -1) const;
86
87         OrientedPoint get_point(unsigned, unsigned, float) const;
88         OrientedPoint get_point(unsigned, float) const;
89
90         virtual unsigned get_n_snap_nodes() const;
91         virtual Snap get_snap_node(unsigned) const;
92         virtual bool snap(Snap &, float, SnapType = SNAP_DEFAULT) const;
93 private:
94         virtual SnapType get_default_snap_type_to(const Object &) const;
95
96 public:
97         virtual unsigned get_n_link_slots() const;
98         virtual Track *get_link(unsigned) const;
99         const std::vector<Track *> &get_links() const { return links; }
100         virtual int get_link_slot(const Object &) const;
101         virtual bool link_to(Object &);
102         using Object::break_link;
103         virtual bool break_link(unsigned);
104
105         void add_attachment(TrackAttachment &);
106         void remove_attachment(TrackAttachment &);
107         const AttachmentList &get_attachments() const { return attachments; }
108         AttachmentList get_attachments_ordered(unsigned) const;
109
110         void save(std::list<Msp::DataFile::Statement> &) const;
111         void save_dynamic(std::list<Msp::DataFile::Statement> &) const;
112 private:
113         void turnout_event(unsigned, unsigned);
114         void turnout_failed(unsigned);
115 };
116
117 } // namespace R2C2
118
119 #endif