]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/vehicletype.cpp
Full vehicle unification
[r2c2.git] / source / libmarklin / vehicletype.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include "vehicletype.h"
9
10 using namespace std;
11 using namespace Msp;
12
13 namespace Marklin {
14
15 VehicleType::VehicleType(unsigned n):
16         art_nr(n),
17         length(0),
18         width(0),
19         height(0)
20 { }
21
22 unsigned VehicleType::get_max_function() const
23 {
24         if(functions.empty())
25                 return 0;
26         return (--functions.end())->first;
27 }
28
29
30 VehicleType::Axle::Axle():
31         position(0),
32         wheel_dia(0),
33         powered(false)
34 { }
35
36
37 VehicleType::Bogie::Bogie():
38         position(0),
39         rotate_object(false)
40 { }
41
42
43 VehicleType::Loader::Loader(VehicleType &vt):
44         DataFile::ObjectLoader<VehicleType>(vt)
45 {
46         add("axle",       &Loader::axle);
47         add("bogie",      &Loader::bogie);
48         add("function",   &Loader::function);
49         add("height",     &Loader::height);
50         add("length",     &Loader::length);
51         add("locomotive", &VehicleType::locomotive);
52         add("object",     &VehicleType::object);
53         add("name",       &VehicleType::name);
54         add("width",      &Loader::width);
55 }
56
57 void VehicleType::Loader::axle()
58 {
59         Axle axl;
60         load_sub(axl);
61         obj.axles.push_back(axl);
62 }
63
64 void VehicleType::Loader::bogie()
65 {
66         Bogie bog;
67         load_sub(bog);
68         obj.bogies.push_back(bog);
69 }
70
71 void VehicleType::Loader::function(unsigned i, const string &f)
72 {
73         obj.functions[i] = f;
74 }
75
76 void VehicleType::Loader::height(float h)
77 {
78         obj.height = h/1000;
79 }
80
81 void VehicleType::Loader::length(float l)
82 {
83         obj.length = l/1000;
84 }
85
86 void VehicleType::Loader::width(float w)
87 {
88         obj.width = w/1000;
89 }
90
91
92 VehicleType::Axle::Loader::Loader(Axle &a):
93         DataFile::ObjectLoader<Axle>(a)
94 {
95         add("position",       &Loader::position);
96         add("powered",        &Axle::powered);
97         add("wheel_diameter", &Loader::wheel_diameter);
98 }
99
100 void VehicleType::Axle::Loader::position(float p)
101 {
102         obj.position = p/1000;
103 }
104
105 void VehicleType::Axle::Loader::wheel_diameter(float d)
106 {
107         obj.wheel_dia = d/1000;
108 }
109
110
111 VehicleType::Bogie::Loader::Loader(Bogie &b):
112         DataFile::ObjectLoader<Bogie>(b)
113 {
114         add("axle",          &Loader::axle);
115         add("object",        &Bogie::object);
116         add("position",      &Loader::position);
117         add("rotate_object", &Bogie::rotate_object);
118 }
119
120 void VehicleType::Bogie::Loader::axle()
121 {
122         Axle axl;
123         load_sub(axl);
124         obj.axles.push_back(axl);
125 }
126
127 void VehicleType::Bogie::Loader::position(float p)
128 {
129         obj.position = p/1000;
130 }
131
132 } // namespace Marklin