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