]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/track.h
Major architecture rework
[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         const TrackType &get_type() const { return type; }
54
55         void set_position(const Point &);
56         void set_rotation(float);
57         void set_slope(float);
58         void set_flex(bool);
59         const Point &get_position() const { return pos; }
60         float get_rotation() const { return rot; }
61         float get_slope() const { return slope; }
62         bool get_flex() const { return flex; }
63         void check_slope();
64
65         void set_turnout_id(unsigned);
66         void set_sensor_id(unsigned);
67         unsigned get_turnout_id() const { return turnout_id; }
68         unsigned get_sensor_id() const { return sensor_id; }
69         void set_active_path(unsigned);
70         unsigned get_active_path() const { return active_path; }
71
72         int get_endpoint_by_link(const Track &) const;
73         Point get_endpoint_position(unsigned) const;
74         float get_endpoint_direction(unsigned) const;
75         bool snap_to(Track &, bool);
76         bool snap(Point &, float &) const;
77         void break_link(Track &);
78         void break_links();
79         const std::vector<Track *> &get_links() const { return links; }
80         Track *get_link(unsigned) const;
81         unsigned traverse(unsigned, unsigned) const;
82         Point get_point(unsigned, unsigned, float) const;
83
84         void save(std::list<Msp::DataFile::Statement> &) const;
85 private:
86         void turnout_event(unsigned, bool);
87 };
88
89 } // namespace Marklin
90
91 #endif