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