]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/catalogue.cpp
Make vehicles aware of which train they are in
[r2c2.git] / source / libr2c2 / catalogue.cpp
index 847045634a1927ea142020a1a54c9a2d43360d72..0d62d72a85c6076eabc85cf4c0a4c5708596848c 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/core/refptr.h>
 #include <msp/datafile/parser.h>
 #include "catalogue.h"
+#include "signaltype.h"
 #include "tracktype.h"
 #include "vehicletype.h"
 
@@ -20,6 +21,8 @@ Catalogue::~Catalogue()
 {
        for(TrackMap::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                delete i->second;
+       for(SignalMap::iterator i=signals.begin(); i!=signals.end(); ++i)
+               delete i->second;
        for(VehicleMap::iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
                delete i->second;
 }
@@ -51,15 +54,27 @@ const VehicleType &Catalogue::get_vehicle(const ArticleNumber &art_nr) const
        return *get_item(vehicles, art_nr);
 }
 
+void Catalogue::add_signal(SignalType &sig)
+{
+       insert_unique(signals, sig.get_article_number(), &sig);
+       signal_signal_added.emit(sig);
+}
+
+const SignalType &Catalogue::get_signal(const ArticleNumber &art_nr) const
+{
+       return *get_item(signals, art_nr);
+}
+
 
 Catalogue::Loader::Loader(Catalogue &c):
-       DataFile::BasicLoader<Catalogue>(c)
+       DataFile::ObjectLoader<Catalogue>(c)
 {
        add("ballast_profile", &Loader::ballast_profile);
        add("gauge", &Loader::gauge);
        add("layout", &Loader::layout);
        add("rail_profile", &Loader::rail_profile);
        add("scale", &Loader::scale);
+       add("signal", &Loader::signal);
        add("track", static_cast<void (Loader::*)(unsigned)>(&Loader::track));
        add("track", static_cast<void (Loader::*)(ArticleNumber)>(&Loader::track));
        add("track_technique", &Catalogue::track_technique);
@@ -76,8 +91,8 @@ void Catalogue::Loader::gauge(float g)
 {
        obj.gauge = g/1000;
        obj.path_profile = Profile();
-       obj.path_profile.append_vertex(Vector(0.1*obj.gauge, 0), false);
-       obj.path_profile.append_vertex(Vector(-0.1*obj.gauge, 0), false);
+       obj.path_profile.append_vertex(Vector(0.1*obj.gauge, 0, 0), false);
+       obj.path_profile.append_vertex(Vector(-0.1*obj.gauge, 0, 0), false);
 }
 
 void Catalogue::Loader::layout()
@@ -95,6 +110,16 @@ void Catalogue::Loader::scale(float n, float d)
        obj.scale = n/d;
 }
 
+void Catalogue::Loader::signal(ArticleNumber art_nr)
+{
+       if(obj.signals.count(art_nr))
+               throw key_error(art_nr);
+
+       RefPtr<SignalType> sig = new SignalType(art_nr);
+       load_sub(*sig);
+       obj.add_signal(*sig.release());
+}
+
 void Catalogue::Loader::track(unsigned art_nr)
 {
        track(ArticleNumber(art_nr));