]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/track.h
Further improve lead route generation
[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 position(float, float, float);
27                 void rotation(float);
28                 void sensor_address(unsigned);
29                 void slope(float);
30                 void tilt(float);
31                 void turnout_address(unsigned);
32         };
33
34         typedef std::list<TrackAttachment *> AttachmentList;
35
36         sigc::signal<void, unsigned, Track *> signal_link_changed;
37         sigc::signal<void, unsigned> signal_path_changing;
38         sigc::signal<void, unsigned> signal_path_changed;
39
40 private:
41         const TrackType &type;
42         Block *block;
43         float slope;
44         bool flex;
45         unsigned turnout_addr;
46         unsigned turnout_id;
47         unsigned sensor_addr;
48         std::vector<Track *> links;
49         unsigned active_path;
50         bool path_changing;
51         AttachmentList attachments;
52
53         Track(const Track &);
54         Track &operator=(const Track &);
55 public:
56         Track(Layout &, const TrackType &);
57         ~Track();
58
59         virtual Track *clone(Layout * = 0) const;
60         virtual const TrackType &get_type() const { return type; }
61
62         void set_block(Block *);
63         Block &get_block() const;
64         virtual void set_position(const Vector &);
65         virtual void set_rotation(const Angle &);
66         virtual void set_tilt(const Angle &);
67         void set_flex(bool);
68         bool get_flex() const { return flex; }
69 private:
70         void propagate_slope();
71         void check_slope();
72
73 public:
74         void set_turnout_address(unsigned);
75         void set_sensor_address(unsigned);
76         unsigned get_turnout_address() const { return turnout_addr; }
77         unsigned get_sensor_address() const { return sensor_addr; }
78         void set_active_path(unsigned);
79         unsigned get_active_path() const { return active_path; }
80         bool is_path_changing() const { return path_changing; }
81         float get_path_length(int = -1) const;
82
83         OrientedPoint get_point(unsigned, unsigned, float) const;
84         OrientedPoint get_point(unsigned, float) const;
85
86         virtual unsigned get_n_snap_nodes() const;
87         virtual Snap get_snap_node(unsigned) const;
88         virtual bool snap(Snap &, float, SnapType = SNAP_DEFAULT) const;
89 private:
90         virtual SnapType get_default_snap_type_to(const Object &) const;
91
92 public:
93         virtual unsigned get_n_link_slots() const;
94         virtual Track *get_link(unsigned) const;
95         const std::vector<Track *> &get_links() const { return links; }
96         virtual int get_link_slot(const Object &) const;
97         virtual bool link_to(Object &);
98         using Object::break_link;
99         virtual bool break_link(unsigned);
100
101         void add_attachment(TrackAttachment &);
102         void remove_attachment(TrackAttachment &);
103         const AttachmentList &get_attachments() const { return attachments; }
104         AttachmentList get_attachments_ordered(unsigned) const;
105
106         void save(std::list<Msp::DataFile::Statement> &) const;
107 private:
108         void turnout_event(unsigned, unsigned);
109         void turnout_failed(unsigned);
110 };
111
112 } // namespace R2C2
113
114 #endif