3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/core/refptr.h>
9 #include <msp/datafile/parser.h>
10 #include "catalogue.h"
11 #include "tracktype.h"
12 #include "vehicletype.h"
19 Catalogue::Catalogue():
25 Catalogue::~Catalogue()
27 for(map<unsigned, TrackType *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
29 for(map<unsigned, VehicleType *>::iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
33 float Catalogue::get_rail_elevation() const
35 return ballast_profile.get_height()+rail_profile.get_height();
38 void Catalogue::add_track(TrackType &track)
40 if(tracks.count(track.get_article_number()))
41 throw Exception("Duplicate track type");
43 tracks[track.get_article_number()] = &track;
44 signal_track_added.emit(track);
47 const TrackType &Catalogue::get_track(unsigned art_nr) const
49 map<unsigned, TrackType *>::const_iterator i=tracks.find(art_nr);
51 throw KeyError("Unknown track type");
56 void Catalogue::add_vehicle(VehicleType &veh)
58 if(vehicles.count(veh.get_article_number()))
59 throw Exception("Duplicate vehicle type");
61 vehicles[veh.get_article_number()] = &veh;
62 signal_vehicle_added.emit(veh);
65 const VehicleType &Catalogue::get_vehicle(unsigned art_nr) const
67 map<unsigned, VehicleType *>::const_iterator i = vehicles.find(art_nr);
69 throw KeyError("Unknown vehicle type");
75 Catalogue::Loader::Loader(Catalogue &c):
76 DataFile::BasicLoader<Catalogue>(c)
78 add("ballast_profile", &Loader::ballast_profile);
79 add("gauge", &Loader::gauge);
80 add("layout", &Loader::layout);
81 add("rail_profile", &Loader::rail_profile);
82 add("scale", &Loader::scale);
83 add("track", &Loader::track);
84 add("vehicle", &Loader::vehicle);
87 void Catalogue::Loader::ballast_profile()
89 load_sub(obj.ballast_profile);
92 void Catalogue::Loader::gauge(float g)
95 obj.path_profile = Profile();
96 obj.path_profile.append_point(Point(0.1*obj.gauge, 0));
97 obj.path_profile.append_point(Point(-0.1*obj.gauge, 0));
100 void Catalogue::Loader::layout()
102 load_sub(obj.layout);
105 void Catalogue::Loader::rail_profile()
107 load_sub(obj.rail_profile);
110 void Catalogue::Loader::scale(float n, float d)
115 void Catalogue::Loader::track(unsigned art_nr)
117 RefPtr<TrackType> trk = new TrackType(art_nr);
123 void Catalogue::Loader::vehicle(unsigned art_nr)
125 RefPtr<VehicleType> veh = new VehicleType(art_nr);
127 obj.add_vehicle(*veh);
131 } // namespace Marklin