]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/track.h
Emit a signal before changing the path of a turnout
[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
17 class Track: public Object, public sigc::trackable
18 {
19 public:
20         class Loader: public Msp::DataFile::ObjectLoader<Track>
21         {
22         public:
23                 Loader(Track &);
24         private:
25                 void position(float, float, float);
26                 void rotation(float);
27                 void sensor_id(unsigned);
28                 void turnout_id(unsigned);
29         };
30
31         sigc::signal<void, unsigned, Track *> signal_link_changed;
32         sigc::signal<void, unsigned> signal_path_changing;
33         sigc::signal<void, unsigned> signal_path_changed;
34
35 private:
36         const TrackType &type;
37         Block *block;
38         float slope;
39         bool flex;
40         unsigned turnout_id;
41         unsigned sensor_id;
42         std::vector<Track *> links;
43         unsigned active_path;
44         bool path_changing;
45
46         Track(const Track &);
47         Track &operator=(const Track &);
48 public:
49         Track(Layout &, const TrackType &);
50         ~Track();
51
52         virtual Track *clone(Layout * = 0) const;
53         virtual const TrackType &get_type() const { return type; }
54
55         void set_block(Block *);
56         Block &get_block() const;
57         virtual void set_position(const Vector &);
58         virtual void set_rotation(const Angle &);
59         void set_slope(float);
60         void set_flex(bool);
61         float get_slope() const { return slope; }
62         bool get_flex() const { return flex; }
63 private:
64         void check_slope();
65
66 public:
67         void set_turnout_id(unsigned);
68         void set_sensor_id(unsigned);
69         unsigned get_turnout_id() const { return turnout_id; }
70         unsigned get_sensor_id() const { return sensor_id; }
71         void set_active_path(unsigned);
72         unsigned get_active_path() const { return active_path; }
73         bool is_path_changing() const { return path_changing; }
74
75         TrackPoint get_point(unsigned, unsigned, float) const;
76         TrackPoint get_point(unsigned, float) const;
77
78         virtual unsigned get_n_snap_nodes() const;
79         virtual Snap get_snap_node(unsigned) const;
80         virtual bool snap(Snap &, float, SnapType = SNAP_DEFAULT) const;
81 private:
82         virtual SnapType get_default_snap_type_to(const Object &) const;
83
84 public:
85         virtual unsigned get_n_link_slots() const;
86         virtual Track *get_link(unsigned) const;
87         const std::vector<Track *> &get_links() const { return links; }
88         virtual int get_link_slot(const Object &) const;
89         virtual bool link_to(Object &);
90         using Object::break_link;
91         virtual bool break_link(unsigned);
92
93         void save(std::list<Msp::DataFile::Statement> &) const;
94 private:
95         void turnout_event(unsigned, unsigned);
96 };
97
98 } // namespace R2C2
99
100 #endif