]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/track.h
Maintain a Block pointer in Track
[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 Block;
20 class Layout;
21 class TrackType;
22
23 class Track: public sigc::trackable
24 {
25 public:
26         class Loader: public Msp::DataFile::BasicLoader<Track>
27         {
28         public:
29                 Loader(Track &);
30         private:
31                 void position(float, float, float);
32                 void sensor_id(unsigned);
33                 void turnout_id(unsigned);
34         };
35
36 private:
37         Layout &layout;
38         const TrackType &type;
39         Block *block;
40         Point pos;
41         float rot;
42         float slope;
43         bool flex;
44         unsigned turnout_id;
45         unsigned sensor_id;
46         std::vector<Track *> links;
47         unsigned active_path;
48
49         Track(const Track &);
50         Track &operator=(const Track &);
51 public:
52         Track(Layout &, const TrackType &);
53         ~Track();
54
55         Layout &get_layout() const { return layout; }
56         const TrackType &get_type() const { return type; }
57
58         void set_block(Block *);
59         Block &get_block() const;
60         void set_position(const Point &);
61         void set_rotation(float);
62         void set_slope(float);
63         void set_flex(bool);
64         const Point &get_position() const { return pos; }
65         float get_rotation() const { return rot; }
66         float get_slope() const { return slope; }
67         bool get_flex() const { return flex; }
68         void check_slope();
69
70         void set_turnout_id(unsigned);
71         void set_sensor_id(unsigned);
72         unsigned get_turnout_id() const { return turnout_id; }
73         unsigned get_sensor_id() const { return sensor_id; }
74         void set_active_path(unsigned);
75         unsigned get_active_path() const { return active_path; }
76
77         int get_endpoint_by_link(Track &) const;
78         Point get_endpoint_position(unsigned) const;
79         float get_endpoint_direction(unsigned) const;
80         bool snap_to(Track &, bool);
81         bool snap(Point &, float &) const;
82         void break_link(Track &);
83         void break_links();
84         const std::vector<Track *> &get_links() const { return links; }
85         Track *get_link(unsigned) const;
86         unsigned traverse(unsigned, unsigned) const;
87         unsigned traverse(unsigned) const;
88         TrackPoint get_point(unsigned, unsigned, float) const;
89         TrackPoint get_point(unsigned, float) const;
90
91         void save(std::list<Msp::DataFile::Statement> &) const;
92 private:
93         void turnout_event(unsigned, bool);
94 };
95
96 } // namespace Marklin
97
98 #endif