]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/track.h
Make Route hold non-const Tracks to match Block
[r2c2.git] / source / libmarklin / track.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_TRACK_H_
9 #define LIBMARKLIN_TRACK_H_
10
11 #include <list>
12 #include <set>
13 #include <sigc++/trackable.h>
14 #include <msp/datafile/loader.h>
15 #include "geometry.h"
16
17 namespace Marklin {
18
19 class Layout;
20 class TrackType;
21
22 class Track: public sigc::trackable
23 {
24 public:
25         class Loader: public Msp::DataFile::BasicLoader<Track>
26         {
27         public:
28                 Loader(Track &);
29         private:
30                 void position(float, float, float);
31                 void sensor_id(unsigned);
32                 void turnout_id(unsigned);
33         };
34
35 private:
36         Layout &layout;
37         const TrackType &type;
38         Point pos;
39         float rot;
40         float slope;
41         bool flex;
42         unsigned turnout_id;
43         unsigned sensor_id;
44         std::vector<Track *> links;
45         unsigned active_path;
46
47         Track(const Track &);
48         Track &operator=(const Track &);
49 public:
50         Track(Layout &, const TrackType &);
51         ~Track();
52
53         Layout &get_layout() const { return layout; }
54         const TrackType &get_type() const { return type; }
55
56         void set_position(const Point &);
57         void set_rotation(float);
58         void set_slope(float);
59         void set_flex(bool);
60         const Point &get_position() const { return pos; }
61         float get_rotation() const { return rot; }
62         float get_slope() const { return slope; }
63         bool get_flex() const { return flex; }
64         void check_slope();
65
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
73         int get_endpoint_by_link(Track &) const;
74         Point get_endpoint_position(unsigned) const;
75         float get_endpoint_direction(unsigned) const;
76         bool snap_to(Track &, bool);
77         bool snap(Point &, float &) const;
78         void break_link(Track &);
79         void break_links();
80         const std::vector<Track *> &get_links() const { return links; }
81         Track *get_link(unsigned) const;
82         unsigned traverse(unsigned, unsigned) const;
83         unsigned traverse(unsigned) const;
84         TrackPoint get_point(unsigned, unsigned, float) const;
85         TrackPoint get_point(unsigned, float) const;
86
87         void save(std::list<Msp::DataFile::Statement> &) const;
88 private:
89         void turnout_event(unsigned, bool);
90 };
91
92 } // namespace Marklin
93
94 #endif