]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/vehicletype.cpp
Make LCD output selectable at runtime through an extra I/O pin
[r2c2.git] / source / libmarklin / vehicletype.cpp
index 0c057e26203b79075eb1207f2c4b6c4b7bbda2f3..5c14cbada6b5dc43905d6b064b087533bd87d066 100644 (file)
@@ -7,17 +7,52 @@ Distributed under the GPL
 
 #include "vehicletype.h"
 
+using namespace std;
 using namespace Msp;
 
 namespace Marklin {
 
-VehicleType::VehicleType(unsigned n):
-       art_nr(n),
+VehicleType::VehicleType(const ArticleNumber &an):
+       art_nr(an),
+       locomotive(false),
        length(0),
        width(0),
        height(0)
 { }
 
+unsigned VehicleType::get_max_function() const
+{
+       if(functions.empty())
+               return 0;
+       return (--functions.end())->first;
+}
+
+float VehicleType::get_front_axle_offset() const
+{
+       float front = length/2;
+       if(!axles.empty())
+               front = axles.front().position;
+       if(!bogies.empty())
+       {
+               const Bogie &bogie = bogies.front();
+               front = max(front, bogie.position+bogie.axles.front().position);
+       }
+       return front;
+}
+
+float VehicleType::get_back_axle_offset() const
+{
+       float back = -length/2;
+       if(!axles.empty())
+               back = axles.back().position;
+       if(!bogies.empty())
+       {
+               const Bogie &bogie = bogies.back();
+               back = min(back, bogie.position+bogie.axles.back().position);
+       }
+       return back;
+}
+
 
 VehicleType::Axle::Axle():
        position(0),
@@ -35,13 +70,15 @@ VehicleType::Bogie::Bogie():
 VehicleType::Loader::Loader(VehicleType &vt):
        DataFile::ObjectLoader<VehicleType>(vt)
 {
-       add("axle",   &Loader::axle);
-       add("bogie",  &Loader::bogie);
-       add("height", &Loader::height);
-       add("length", &Loader::length);
-       add("object", &VehicleType::object);
-       add("name",   &VehicleType::name);
-       add("width",  &Loader::width);
+       add("axle",       &Loader::axle);
+       add("bogie",      &Loader::bogie);
+       add("function",   &Loader::function);
+       add("height",     &Loader::height);
+       add("length",     &Loader::length);
+       add("locomotive", &VehicleType::locomotive);
+       add("object",     &VehicleType::object);
+       add("name",       &VehicleType::name);
+       add("width",      &Loader::width);
 }
 
 void VehicleType::Loader::axle()
@@ -58,6 +95,11 @@ void VehicleType::Loader::bogie()
        obj.bogies.push_back(bog);
 }
 
+void VehicleType::Loader::function(unsigned i, const string &f)
+{
+       obj.functions[i] = f;
+}
+
 void VehicleType::Loader::height(float h)
 {
        obj.height = h/1000;
@@ -77,6 +119,7 @@ void VehicleType::Loader::width(float w)
 VehicleType::Axle::Loader::Loader(Axle &a):
        DataFile::ObjectLoader<Axle>(a)
 {
+       add("object",         &Axle::object);
        add("position",       &Loader::position);
        add("powered",        &Axle::powered);
        add("wheel_diameter", &Loader::wheel_diameter);