3 This file is part of the MSP Märklin suite
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gl/meshbuilder.h>
9 #include <msp/gl/vector.h>
10 #include "catalogue.h"
11 #include "vehicletype.h"
18 VehicleType3D::VehicleType3D(Catalogue3D &, const VehicleType &vt):
22 body_object = get_object(vt.get_object());
24 const vector<VehicleType::Axle> &axles = vt.get_axles();
25 for(vector<VehicleType::Axle>::const_iterator i=axles.begin(); i!=axles.end(); ++i)
26 axle_objects[0].push_back(get_object(i->object));
28 const vector<VehicleType::Bogie> &bogies = vt.get_bogies();
29 for(vector<VehicleType::Bogie>::const_iterator i=bogies.begin(); i!=bogies.end(); ++i)
31 bogie_objects.push_back(get_object(i->object));
32 axle_objects.push_back(vector<GL::Object *>());
33 for(vector<VehicleType::Axle>::const_iterator j=i->axles.begin(); j!=i->axles.end(); ++j)
34 axle_objects.back().push_back(get_object(j->object));
38 VehicleType3D::~VehicleType3D()
40 for(map<string, GL::Object *>::iterator i=objects.begin(); i!=objects.end(); ++i)
44 const GL::Object *VehicleType3D::get_axle_object(unsigned i) const
46 if(i>=axle_objects[0].size())
47 throw InvalidParameterValue("Axle index out of range");
48 return axle_objects[0][i];
51 const GL::Object *VehicleType3D::get_bogie_object(unsigned i) const
53 if(i>=bogie_objects.size())
54 throw InvalidParameterValue("Bogie index out of range");
55 return bogie_objects[i];
58 const GL::Object *VehicleType3D::get_bogie_axle_object(unsigned i, unsigned j) const
60 if(i>=bogie_objects.size())
61 throw InvalidParameterValue("Bogie index out of range");
62 if(j>=axle_objects[i+1].size())
63 throw InvalidParameterValue("Axle index out of range");
64 return axle_objects[i+1][j];
67 GL::Object *VehicleType3D::get_object(const string &name)
72 GL::Object *&ptr = objects[name];
76 DataFile::load(*ptr, name);
81 } // namespace Marklin