1 #include <msp/core/maputils.h>
2 #include <msp/core/refptr.h>
3 #include <msp/datafile/parser.h>
6 #include "vehicletype.h"
13 Catalogue::Catalogue():
19 Catalogue::~Catalogue()
21 for(TrackMap::iterator i=tracks.begin(); i!=tracks.end(); ++i)
23 for(VehicleMap::iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
27 float Catalogue::get_rail_elevation() const
29 return ballast_profile.get_height()+rail_profile.get_height();
32 void Catalogue::add_track(TrackType &track)
34 insert_unique(tracks, track.get_article_number(), &track);
35 signal_track_added.emit(track);
38 const TrackType &Catalogue::get_track(const ArticleNumber &art_nr) const
40 return *get_item(tracks, art_nr);
43 void Catalogue::add_vehicle(VehicleType &veh)
45 insert_unique(vehicles, veh.get_article_number(), &veh);
46 signal_vehicle_added.emit(veh);
49 const VehicleType &Catalogue::get_vehicle(const ArticleNumber &art_nr) const
51 return *get_item(vehicles, art_nr);
55 Catalogue::Loader::Loader(Catalogue &c):
56 DataFile::BasicLoader<Catalogue>(c)
58 add("ballast_profile", &Loader::ballast_profile);
59 add("gauge", &Loader::gauge);
60 add("layout", &Loader::layout);
61 add("rail_profile", &Loader::rail_profile);
62 add("scale", &Loader::scale);
63 add("track", static_cast<void (Loader::*)(unsigned)>(&Loader::track));
64 add("track", static_cast<void (Loader::*)(ArticleNumber)>(&Loader::track));
65 add("track_technique", &Catalogue::track_technique);
66 add("vehicle", static_cast<void (Loader::*)(unsigned)>(&Loader::vehicle));
67 add("vehicle", static_cast<void (Loader::*)(ArticleNumber)>(&Loader::vehicle));
70 void Catalogue::Loader::ballast_profile()
72 load_sub(obj.ballast_profile);
75 void Catalogue::Loader::gauge(float g)
78 obj.path_profile = Profile();
79 obj.path_profile.append_vertex(Vector(0.1*obj.gauge, 0), false);
80 obj.path_profile.append_vertex(Vector(-0.1*obj.gauge, 0), false);
83 void Catalogue::Loader::layout()
88 void Catalogue::Loader::rail_profile()
90 load_sub(obj.rail_profile);
93 void Catalogue::Loader::scale(float n, float d)
98 void Catalogue::Loader::track(unsigned art_nr)
100 track(ArticleNumber(art_nr));
103 void Catalogue::Loader::track(ArticleNumber art_nr)
105 if(obj.tracks.count(art_nr))
106 throw key_error(art_nr);
108 RefPtr<TrackType> trk = new TrackType(art_nr);
110 obj.add_track(*trk.release());
113 void Catalogue::Loader::vehicle(unsigned art_nr)
115 vehicle(ArticleNumber(art_nr));
118 void Catalogue::Loader::vehicle(ArticleNumber art_nr)
120 if(obj.vehicles.count(art_nr))
121 throw key_error(art_nr);
123 RefPtr<VehicleType> veh = new VehicleType(art_nr);
125 obj.add_vehicle(*veh.release());