]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/track.h
Enable Renderer for Endpoint3D and Path3D
[r2c2.git] / source / libr2c2 / track.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBR2C2_TRACK_H_
9 #define LIBR2C2_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 R2C2 {
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         sigc::signal<void, unsigned, Track *> signal_link_changed;
37         sigc::signal<void, unsigned> signal_path_changed;
38
39 private:
40         Layout &layout;
41         const TrackType &type;
42         Block *block;
43         Point pos;
44         float rot;
45         float slope;
46         bool flex;
47         unsigned turnout_id;
48         unsigned sensor_id;
49         std::vector<Track *> links;
50         unsigned active_path;
51
52         Track(const Track &);
53         Track &operator=(const Track &);
54 public:
55         Track(Layout &, const TrackType &);
56         ~Track();
57
58         Layout &get_layout() const { return layout; }
59         const TrackType &get_type() const { return type; }
60
61         void set_block(Block *);
62         Block &get_block() const;
63         void set_position(const Point &);
64         void set_rotation(float);
65         void set_slope(float);
66         void set_flex(bool);
67         const Point &get_position() const { return pos; }
68         float get_rotation() const { return rot; }
69         float get_slope() const { return slope; }
70         bool get_flex() const { return flex; }
71         void check_slope();
72
73         void set_turnout_id(unsigned);
74         void set_sensor_id(unsigned);
75         unsigned get_turnout_id() const { return turnout_id; }
76         unsigned get_sensor_id() const { return sensor_id; }
77         void set_active_path(unsigned);
78         unsigned get_active_path() const { return active_path; }
79
80         int get_endpoint_by_link(Track &) const;
81         Point get_endpoint_position(unsigned) const;
82         float get_endpoint_direction(unsigned) const;
83         bool snap_to(Track &, bool, float = 0);
84         bool snap(Point &, float &) const;
85         void break_link(Track &);
86         void break_links();
87         const std::vector<Track *> &get_links() const { return links; }
88         Track *get_link(unsigned) const;
89         TrackPoint get_point(unsigned, unsigned, float) const;
90         TrackPoint get_point(unsigned, float) const;
91
92         void save(std::list<Msp::DataFile::Statement> &) const;
93 private:
94         void turnout_event(unsigned, unsigned);
95 };
96
97 } // namespace R2C2
98
99 #endif