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 void Catalogue::add_track(TrackType &track)
35 if(tracks.count(track.get_article_number()))
36 throw Exception("Duplicate track type");
38 tracks[track.get_article_number()] = &track;
39 signal_track_added.emit(track);
42 const TrackType &Catalogue::get_track(unsigned art_nr) const
44 map<unsigned, TrackType *>::const_iterator i=tracks.find(art_nr);
46 throw KeyError("Unknown track type");
51 void Catalogue::add_vehicle(VehicleType &veh)
53 if(vehicles.count(veh.get_article_number()))
54 throw Exception("Duplicate vehicle type");
56 vehicles[veh.get_article_number()] = &veh;
57 signal_vehicle_added.emit(veh);
60 const VehicleType &Catalogue::get_vehicle(unsigned art_nr) const
62 map<unsigned, VehicleType *>::const_iterator i = vehicles.find(art_nr);
64 throw KeyError("Unknown vehicle type");
70 Catalogue::Loader::Loader(Catalogue &c):
71 DataFile::BasicLoader<Catalogue>(c)
73 add("ballast_profile", &Loader::ballast_profile);
74 add("gauge", &Loader::gauge);
75 add("layout", &Loader::layout);
76 add("rail_profile", &Loader::rail_profile);
77 add("scale", &Loader::scale);
78 add("track", &Loader::track);
79 add("vehicle", &Loader::vehicle);
82 void Catalogue::Loader::ballast_profile()
84 load_sub(obj.ballast_profile);
87 void Catalogue::Loader::gauge(float g)
90 obj.path_profile = Profile();
91 obj.path_profile.append_point(Point(0.1*obj.gauge, 0));
92 obj.path_profile.append_point(Point(-0.1*obj.gauge, 0));
95 void Catalogue::Loader::layout()
100 void Catalogue::Loader::rail_profile()
102 load_sub(obj.rail_profile);
105 void Catalogue::Loader::scale(float n, float d)
110 void Catalogue::Loader::track(unsigned art_nr)
112 RefPtr<TrackType> trk = new TrackType(art_nr);
118 void Catalogue::Loader::vehicle(unsigned art_nr)
120 RefPtr<VehicleType> veh = new VehicleType(art_nr);
122 obj.add_vehicle(*veh);
126 } // namespace Marklin