]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/vehicletype.cpp
Add some utility functions for interfacing with hardware
[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 Msp;
11
12 namespace Marklin {
13
14 VehicleType::VehicleType(unsigned n):
15         art_nr(n),
16         length(0),
17         width(0),
18         height(0)
19 { }
20
21
22 VehicleType::Axle::Axle():
23         position(0),
24         wheel_dia(0),
25         powered(false)
26 { }
27
28
29 VehicleType::Bogie::Bogie():
30         position(0),
31         rotate_object(false)
32 { }
33
34
35 VehicleType::Loader::Loader(VehicleType &vt):
36         DataFile::ObjectLoader<VehicleType>(vt)
37 {
38         add("axle",   &Loader::axle);
39         add("bogie",  &Loader::bogie);
40         add("height", &Loader::height);
41         add("length", &Loader::length);
42         add("object", &VehicleType::object);
43         add("name",   &VehicleType::name);
44         add("width",  &Loader::width);
45 }
46
47 void VehicleType::Loader::axle()
48 {
49         Axle axl;
50         load_sub(axl);
51         obj.axles.push_back(axl);
52 }
53
54 void VehicleType::Loader::bogie()
55 {
56         Bogie bog;
57         load_sub(bog);
58         obj.bogies.push_back(bog);
59 }
60
61 void VehicleType::Loader::height(float h)
62 {
63         obj.height = h/1000;
64 }
65
66 void VehicleType::Loader::length(float l)
67 {
68         obj.length = l/1000;
69 }
70
71 void VehicleType::Loader::width(float w)
72 {
73         obj.width = w/1000;
74 }
75
76
77 VehicleType::Axle::Loader::Loader(Axle &a):
78         DataFile::ObjectLoader<Axle>(a)
79 {
80         add("position",       &Loader::position);
81         add("powered",        &Axle::powered);
82         add("wheel_diameter", &Loader::wheel_diameter);
83 }
84
85 void VehicleType::Axle::Loader::position(float p)
86 {
87         obj.position = p/1000;
88 }
89
90 void VehicleType::Axle::Loader::wheel_diameter(float d)
91 {
92         obj.wheel_dia = d/1000;
93 }
94
95
96 VehicleType::Bogie::Loader::Loader(Bogie &b):
97         DataFile::ObjectLoader<Bogie>(b)
98 {
99         add("axle",          &Loader::axle);
100         add("object",        &Bogie::object);
101         add("position",      &Loader::position);
102         add("rotate_object", &Bogie::rotate_object);
103 }
104
105 void VehicleType::Bogie::Loader::axle()
106 {
107         Axle axl;
108         load_sub(axl);
109         obj.axles.push_back(axl);
110 }
111
112 void VehicleType::Bogie::Loader::position(float p)
113 {
114         obj.position = p/1000;
115 }
116
117 } // namespace Marklin