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