]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/track.h
Add framework for generating simple meshes for vehicles
[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         sigc::signal<void, unsigned> signal_path_changed;
37
38 private:
39         Layout &layout;
40         const TrackType &type;
41         Block *block;
42         Point pos;
43         float rot;
44         float slope;
45         bool flex;
46         unsigned turnout_id;
47         unsigned sensor_id;
48         std::vector<Track *> links;
49         unsigned active_path;
50
51         Track(const Track &);
52         Track &operator=(const Track &);
53 public:
54         Track(Layout &, const TrackType &);
55         ~Track();
56
57         Layout &get_layout() const { return layout; }
58         const TrackType &get_type() const { return type; }
59
60         void set_block(Block *);
61         Block &get_block() const;
62         void set_position(const Point &);
63         void set_rotation(float);
64         void set_slope(float);
65         void set_flex(bool);
66         const Point &get_position() const { return pos; }
67         float get_rotation() const { return rot; }
68         float get_slope() const { return slope; }
69         bool get_flex() const { return flex; }
70         void check_slope();
71
72         void set_turnout_id(unsigned);
73         void set_sensor_id(unsigned);
74         unsigned get_turnout_id() const { return turnout_id; }
75         unsigned get_sensor_id() const { return sensor_id; }
76         void set_active_path(unsigned);
77         unsigned get_active_path() const { return active_path; }
78
79         int get_endpoint_by_link(Track &) const;
80         Point get_endpoint_position(unsigned) const;
81         float get_endpoint_direction(unsigned) const;
82         bool snap_to(Track &, bool, float = 0);
83         bool snap(Point &, float &) const;
84         void break_link(Track &);
85         void break_links();
86         const std::vector<Track *> &get_links() const { return links; }
87         Track *get_link(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