]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/vehicletype.h
Allow rotating the body object of a vehicle
[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 "articlenumber.h"
6 #include "geometry.h"
7
8 namespace R2C2 {
9
10 class VehicleType
11 {
12 public:
13         class Loader: public Msp::DataFile::ObjectLoader<VehicleType>
14         {
15         private:
16                 std::map<std::string, unsigned> rod_tags;
17
18         public:
19                 Loader(VehicleType &);
20         private:
21                 void axle();
22                 void bogie();
23                 void function(unsigned, const std::string &);
24                 void height(float);
25                 void length(float);
26                 void rod();
27                 void width(float);
28         };
29
30         struct Axle
31         {
32                 class Loader: public Msp::DataFile::ObjectLoader<Axle>
33                 {
34                 public:
35                         Loader(Axle &);
36                 private:
37                         void position(float);
38                         void wheel_diameter(float);
39                 };
40
41                 float position;
42                 float wheel_dia;
43                 bool powered;
44                 std::string object;
45
46                 Axle();
47         };
48
49         typedef std::vector<Axle> AxleArray;
50
51         struct Bogie
52         {
53                 class Loader: public Msp::DataFile::ObjectLoader<Bogie>
54                 {
55                 public:
56                         Loader(Bogie &);
57                 private:
58                         void axle();
59                         void position(float);
60                 };
61
62                 float position;
63                 AxleArray axles;
64                 std::string object;
65                 bool rotate_object;
66
67                 Bogie();
68         };
69
70         typedef std::vector<Bogie> BogieArray;
71
72         struct Rod
73         {
74                 enum Anchor
75                 {
76                         BODY,
77                         AXLE,
78                         BOGIE_AXLE,
79                         ROD
80                 };
81
82                 enum Limit
83                 {
84                         FIXED,
85                         ROTATE,
86                         SLIDE_X
87                 };
88
89                 class Loader: public Msp::DataFile::ObjectLoader<Rod>
90                 {
91                 private:
92                         const std::map<std::string, unsigned> &tags;
93                         std::string tag;
94
95                 public:
96                         Loader(Rod &, const std::map<std::string, unsigned> &);
97                         const std::string &get_tag() const { return tag; }
98                 private:
99                         void connect(const std::string &, float, float, float, float);
100                         void limit(Limit);
101                         void pivot_body();
102                         void pivot_axle(unsigned);
103                         void pivot_bogie_axle(unsigned, unsigned);
104                         void pivot_rod(const std::string &);
105                         void position(float, float, float);
106                         void set_tag(const std::string &);
107                 };
108
109                 Anchor pivot;
110                 unsigned pivot_index;
111                 unsigned pivot_index2;
112                 Vector pivot_point;
113                 Limit limit;
114                 int connect_index;
115                 Vector connect_point;
116                 Vector connect_offset;
117                 std::string object;
118                 bool mirror_object;
119
120                 Rod();
121         };
122
123         typedef std::vector<Rod> RodArray;
124
125         typedef std::map<unsigned, std::string> FunctionMap;
126
127 private:
128         ArticleNumber art_nr;
129         std::string name;
130         bool locomotive;
131         FunctionMap functions;
132         bool swap_direction;
133         float length;
134         float width;
135         float height;
136         AxleArray axles;
137         BogieArray bogies;
138         RodArray rods;
139         std::string object;
140         bool rotate_object;
141
142 public:
143         VehicleType(const ArticleNumber &);
144
145         const ArticleNumber &get_article_number() const { return art_nr; }
146         const std::string &get_name() const { return name; }
147         bool is_locomotive() const { return locomotive; }
148         unsigned get_max_function() const;
149         const FunctionMap &get_functions() const { return functions; }
150         bool get_swap_direction() const { return swap_direction; }
151         float get_length() const { return length; }
152         float get_width() const { return width; }
153         float get_height() const { return height; }
154         const AxleArray &get_fixed_axles() const { return axles; }
155         const Axle &get_fixed_axle(unsigned) const;
156         const BogieArray &get_bogies() const { return bogies; }
157         const Bogie &get_bogie(unsigned) const;
158         const Axle &get_bogie_axle(unsigned, unsigned) const;
159         const RodArray &get_rods() const { return rods; }
160         const Rod &get_rod(unsigned) const;
161         float get_front_axle_offset() const;
162         float get_back_axle_offset() const;
163         const std::string &get_object() const { return object; }
164         bool get_rotate_object() const { return rotate_object; }
165 };
166
167 } // namespace R2C2
168
169 #endif