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