1 #include "vehicletype.h"
8 VehicleType::VehicleType(const ArticleNumber &an):
11 swap_direction(false),
17 unsigned VehicleType::get_max_function() const
21 return (--functions.end())->first;
24 const VehicleType::Axle &VehicleType::get_fixed_axle(unsigned i) const
27 throw InvalidParameterValue("Axle index out of range");
31 const VehicleType::Bogie &VehicleType::get_bogie(unsigned i) const
34 throw InvalidParameterValue("Axle index out of range");
38 const VehicleType::Axle &VehicleType::get_bogie_axle(unsigned i, unsigned j) const
41 throw InvalidParameterValue("Axle index out of range");
42 if(j>=bogies[i].axles.size())
43 throw InvalidParameterValue("Axle index out of range");
44 return bogies[i].axles[j];
47 const VehicleType::Rod &VehicleType::get_rod(unsigned i) const
50 throw InvalidParameterValue("Rod index out of range");
54 float VehicleType::get_front_axle_offset() const
56 float front = length/2;
58 front = axles.front().position;
61 const Bogie &bogie = bogies.front();
62 front = max(front, bogie.position+bogie.axles.front().position);
67 float VehicleType::get_back_axle_offset() const
69 float back = -length/2;
71 back = axles.back().position;
74 const Bogie &bogie = bogies.back();
75 back = min(back, bogie.position+bogie.axles.back().position);
81 VehicleType::Axle::Axle():
88 VehicleType::Bogie::Bogie():
94 VehicleType::Rod::Rod():
104 VehicleType::Loader::Loader(VehicleType &vt):
105 DataFile::ObjectLoader<VehicleType>(vt)
107 add("axle", &Loader::axle);
108 add("bogie", &Loader::bogie);
109 add("function", &Loader::function);
110 add("height", &Loader::height);
111 add("length", &Loader::length);
112 add("locomotive", &VehicleType::locomotive);
113 add("name", &VehicleType::name);
114 add("object", &VehicleType::object);
115 add("rod", &Loader::rod);
116 add("swap_direction", &VehicleType::swap_direction);
117 add("width", &Loader::width);
120 void VehicleType::Loader::axle()
124 obj.axles.push_back(axl);
127 void VehicleType::Loader::bogie()
131 obj.bogies.push_back(bog);
134 void VehicleType::Loader::function(unsigned i, const string &f)
136 obj.functions[i] = f;
139 void VehicleType::Loader::height(float h)
144 void VehicleType::Loader::length(float l)
149 void VehicleType::Loader::rod()
152 Rod::Loader ldr(rd, rod_tags);
154 obj.rods.push_back(rd);
155 if(!ldr.get_tag().empty())
156 rod_tags[ldr.get_tag()] = obj.rods.size()-1;
157 rod_tags["previous"] = obj.rods.size()-1;
160 void VehicleType::Loader::width(float w)
166 VehicleType::Axle::Loader::Loader(Axle &a):
167 DataFile::ObjectLoader<Axle>(a)
169 add("object", &Axle::object);
170 add("position", &Loader::position);
171 add("powered", &Axle::powered);
172 add("wheel_diameter", &Loader::wheel_diameter);
175 void VehicleType::Axle::Loader::position(float p)
177 obj.position = p/1000;
180 void VehicleType::Axle::Loader::wheel_diameter(float d)
182 obj.wheel_dia = d/1000;
186 VehicleType::Bogie::Loader::Loader(Bogie &b):
187 DataFile::ObjectLoader<Bogie>(b)
189 add("axle", &Loader::axle);
190 add("object", &Bogie::object);
191 add("position", &Loader::position);
192 add("rotate_object", &Bogie::rotate_object);
195 void VehicleType::Bogie::Loader::axle()
199 obj.axles.push_back(axl);
202 void VehicleType::Bogie::Loader::position(float p)
204 obj.position = p/1000;
208 VehicleType::Rod::Loader::Loader(Rod &r, const map<string, unsigned> &t):
209 DataFile::ObjectLoader<Rod>(r),
212 add("connect", &Loader::connect);
213 add("limit", &Rod::limit);
214 add("mirror_object", &Rod::mirror_object);
215 add("object", &Rod::object);
216 add("pivot_body", &Loader::pivot_body);
217 add("pivot_axle", &Loader::pivot_axle);
218 add("pivot_axle", &Loader::pivot_bogie_axle);
219 add("pivot_rod", &Loader::pivot_rod);
220 add("position", &Loader::position);
221 add("tag", &Loader::set_tag);
224 void VehicleType::Rod::Loader::connect(const string &t, float px, float pz, float ox, float oz)
226 map<string, unsigned>::const_iterator i = tags.find(t);
228 throw KeyError("Unknown rod tag", t);
229 obj.connect_index = i->second;
230 obj.connect_point = Vector(px/1000, 0, pz/1000);
231 obj.connect_offset = Vector(ox/1000, 0, oz/1000);
234 void VehicleType::Rod::Loader::pivot_body()
239 void VehicleType::Rod::Loader::pivot_axle(unsigned i)
245 void VehicleType::Rod::Loader::pivot_bogie_axle(unsigned i, unsigned j)
247 obj.pivot = BOGIE_AXLE;
249 obj.pivot_index2 = j;
252 void VehicleType::Rod::Loader::pivot_rod(const string &t)
254 map<string, unsigned>::const_iterator i = tags.find(t);
256 throw KeyError("Unknown rod tag", t);
258 obj.pivot_index = i->second;
261 void VehicleType::Rod::Loader::position(float x, float y, float z)
263 obj.pivot_point = Vector(x/1000, y/1000, z/1000);
266 void VehicleType::Rod::Loader::set_tag(const string &t)
272 void operator>>(const LexicalConverter &c, VehicleType::Rod::Limit &l)
274 const string &s = c.get();
276 l = VehicleType::Rod::FIXED;
278 l = VehicleType::Rod::ROTATE;
279 else if(s=="SLIDE_X")
280 l = VehicleType::Rod::SLIDE_X;
282 throw LexicalError("Invalid value for Rod::Limit");