]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/vehicletype.h
e49a48fb19ea3c0b9fad7361ca8b39fa0b08b2cf
[r2c2.git] / source / libr2c2 / vehicletype.h
1 #ifndef LIBR2C2_VEHICLETYPE_H_
2 #define LIBR2C2_VEHICLETYPE_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "geometry.h"
6 #include "objecttype.h"
7
8 namespace R2C2 {
9
10 class VehicleType: public ObjectType
11 {
12 private:
13         typedef std::map<std::string, unsigned> TagMap;
14
15 public:
16         class Loader: public Msp::DataFile::DerivedObjectLoader<VehicleType, ObjectType::Loader>
17         {
18         private:
19                 TagMap rod_tags;
20
21         public:
22                 Loader(VehicleType &);
23         private:
24                 virtual void finish();
25                 void axle();
26                 void bogie();
27                 void function(unsigned, const std::string &);
28                 void height(float);
29                 void length(float);
30                 void mirror_rods();
31                 void rod(const std::string &);
32                 void width(float);
33         };
34
35         struct Bogie;
36
37         struct Axle
38         {
39                 class Loader: public Msp::DataFile::ObjectLoader<Axle>
40                 {
41                 public:
42                         Loader(Axle &);
43                 private:
44                         void position(float);
45                         void wheel_diameter(float);
46                 };
47
48                 unsigned index;
49                 Bogie *bogie;
50                 float local_position;
51                 float position;
52                 float wheel_dia;
53                 bool powered;
54                 std::string object;
55
56                 Axle();
57         };
58
59         struct Bogie
60         {
61                 class Loader: public Msp::DataFile::ObjectLoader<Bogie>
62                 {
63                 private:
64                         VehicleType &parent;
65
66                 public:
67                         Loader(VehicleType &, Bogie &);
68                 private:
69                         void axle();
70                         void position(float);
71                 };
72
73                 unsigned index;
74                 float position;
75                 unsigned first_axle;
76                 std::vector<Axle *> axles;
77                 std::string object;
78                 bool rotate_object;
79
80                 Bogie();
81         };
82
83         struct RodConstraint
84         {
85                 enum Type
86                 {
87                         MOVE,
88                         SLIDE,
89                         ROTATE
90                 };
91
92                 enum Target
93                 {
94                         BODY,
95                         BOGIE,
96                         AXLE,
97                         ROD
98                 };
99
100                 class Loader: public Msp::DataFile::ObjectLoader<RodConstraint>
101                 {
102                 private:
103                         TagMap &tags;
104
105                 public:
106                         Loader(RodConstraint &, TagMap &);
107                 private:
108                         void axis(float, float, float);
109                         void local_position(float, float, float);
110                         void target_axle(unsigned);
111                         void target_position(float, float, float);
112                         void target_rod(const std::string &);
113                 };
114
115                 Type type;
116                 Target target;
117                 unsigned target_index;
118                 Vector target_position;
119                 Vector local_position;
120                 Vector axis;
121
122                 RodConstraint();
123         };
124
125         struct Rod
126         {
127                 class Loader: public Msp::DataFile::ObjectLoader<Rod>
128                 {
129                 private:
130                         TagMap &tags;
131
132                 public:
133                         Loader(Rod &, TagMap &);
134                 private:
135                         template<RodConstraint::Type>
136                         void constraint();
137                         void initial_position(float, float, float);
138                 };
139
140                 Vector initial_position;
141                 std::vector<RodConstraint> constraints;
142                 std::string object;
143                 bool mirror_object;
144
145                 Rod();
146         };
147
148         class MirrorParametersLoader: public Msp::DataFile::Loader
149         {
150         public:
151                 std::string filter;
152                 Angle phase_offset;
153
154                 MirrorParametersLoader();
155         private:
156                 void filt(const std::string &);
157                 void phase_offs(float);
158         };
159
160         typedef std::vector<Axle> AxleArray;
161         typedef std::vector<Bogie> BogieArray;
162         typedef std::vector<Rod> RodArray;
163         typedef std::map<unsigned, std::string> FunctionMap;
164
165 private:
166         bool locomotive;
167         FunctionMap functions;
168         bool swap_direction;
169         float length;
170         float width;
171         float height;
172         AxleArray axles;
173         std::vector<Axle *> fixed_axles;
174         BogieArray bogies;
175         RodArray rods;
176         std::string object;
177         bool rotate_object;
178         float max_speed;
179
180 public:
181         VehicleType(const ArticleNumber &);
182
183         bool is_locomotive() const { return locomotive; }
184         unsigned get_max_function() const;
185         const FunctionMap &get_functions() const { return functions; }
186         bool get_swap_direction() const { return swap_direction; }
187         float get_length() const { return length; }
188         float get_width() const { return width; }
189         float get_height() const { return height; }
190         const AxleArray &get_axles() const { return axles; }
191         const Axle &get_axle(unsigned) const;
192         const Axle &get_fixed_axle(unsigned) const;
193         const BogieArray &get_bogies() const { return bogies; }
194         const Bogie &get_bogie(unsigned) const;
195         const Axle &get_bogie_axle(unsigned, unsigned) const;
196         const RodArray &get_rods() const { return rods; }
197         const Rod &get_rod(unsigned) const;
198         float get_front_axle_offset() const;
199         float get_back_axle_offset() const;
200         const std::string &get_object() const { return object; }
201         bool get_rotate_object() const { return rotate_object; }
202         float get_maximum_speed() const { return max_speed; }
203 };
204
205 } // namespace R2C2
206
207 #endif