]> git.tdb.fi Git - r2c2.git/blobdiff - source/3d/catalogue.cpp
Add vehicles
[r2c2.git] / source / 3d / catalogue.cpp
index 54341c10c0432e7344d30d35cda86cf3724b2596..1068feafdfa87a1933c538e06d5921049107a9b5 100644 (file)
@@ -6,8 +6,10 @@ Distributed under the GPL
 */
 
 #include <msp/gl/meshbuilder.h>
+#include "libmarklin/locotype.h"
 #include "catalogue.h"
 #include "tracktype.h"
+#include "vehicletype.h"
 
 using namespace std;
 using namespace Msp;
@@ -19,6 +21,7 @@ Catalogue3D::Catalogue3D(Catalogue &c):
        endpoint_mesh((GL::NORMAL3, GL::VERTEX3))
 {
        catalogue.signal_track_added.connect(sigc::mem_fun(this, &Catalogue3D::track_added));
+       catalogue.signal_loco_added.connect(sigc::mem_fun(this, &Catalogue3D::loco_added));
 
        const map<unsigned, TrackType *> &trks = catalogue.get_tracks();
        for(map<unsigned, TrackType *>::const_iterator i=trks.begin(); i!=trks.end(); ++i)
@@ -45,11 +48,25 @@ const TrackType3D &Catalogue3D::get_track(const TrackType &tt) const
        return *i->second;
 }
 
+const VehicleType3D &Catalogue3D::get_vehicle(const VehicleType &vt) const
+{
+       map<const VehicleType *, VehicleType3D *>::const_iterator i = vehicles.find(&vt);
+       if(i==vehicles.end())
+               throw KeyError("Unknown vehicle type");
+
+       return *i->second;
+}
+
 void Catalogue3D::track_added(const TrackType &track)
 {
        tracks[&track] = new TrackType3D(*this, track);
 }
 
+void Catalogue3D::loco_added(const LocoType &loco)
+{
+       vehicles[&loco] = new VehicleType3D(*this, loco);
+}
+
 void Catalogue3D::build_endpoint_mesh()
 {
        const Profile &ballast_profile = catalogue.get_ballast_profile();