]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/track.h
13a98bf51b268d4772dff9d1c7111df54fbea967
[r2c2.git] / source / libmarklin / track.h
1 #ifndef LIBMARKLIN_TRACK_H_
2 #define LIBMARKLIN_TRACK_H_
3
4 #include <list>
5 #include <set>
6 #include <msp/datafile/loader.h>
7 #include "geometry.h"
8
9 namespace Marklin {
10
11 class TrackType;
12
13 class Track
14 {
15 public:
16         class Loader: public Msp::DataFile::Loader
17         {
18         private:
19                 Track &track;
20
21         public:
22                 Loader(Track &);
23                 Track &get_object() { return track; }
24         private:
25                 void position(float, float, float);
26         };
27
28 private:
29         const TrackType &type;
30         Point        pos;
31         float        rot;
32         float        slope;
33         bool         flex;
34         unsigned     turnout_id;
35         unsigned     sensor_id;
36         std::vector<Track *> links;
37
38 public:
39         Track(const TrackType &);
40         ~Track();
41
42         const TrackType &get_type() const { return type; }
43         void            set_position(const Point &);
44         const Point     &get_position() const      { return pos; }
45         void            set_rotation(float);
46         float           get_rotation() const       { return rot; }
47         void            set_slope(float);
48         float           get_slope() const          { return slope; }
49         void            set_flex(bool);
50         bool            get_flex() const           { return flex; }
51         void            set_turnout_id(unsigned);
52         unsigned        get_turnout_id() const     { return turnout_id; }
53         void            set_sensor_id(unsigned);
54         unsigned        get_sensor_id() const      { return sensor_id; }
55         int             get_endpoint_by_link(const Track &) const;
56         Point           get_endpoint_position(unsigned) const;
57         float           get_endpoint_direction(unsigned) const;
58         bool            snap_to(Track &, bool);
59         bool            snap(Point &, float &) const;
60         void            break_link(Track &);
61         void            break_links();
62         const std::vector<Track *> &get_links() const { return links; }
63         Track           *get_link(unsigned) const;
64         void            check_slope();
65         int             traverse(unsigned, unsigned) const;
66
67         /**
68         Creates a copy of the track.  The new track will be almost identical, but
69         won't have any links to other tracks, nor a turnout or sensor id.
70         */
71         Track *copy() const;
72 private:
73
74         // Direct copying not allowed due to links.  See the copy() function.
75         Track(const Track &);
76         Track &operator=(const Track &);
77 };
78
79 } // namespace Marklin
80
81 #endif