X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Fcatalogue.cpp;h=7169c60c3272be579162ec093fdbd1c5672a764e;hb=621c5c938d70ba0d155e0eda91a708db0a52c0dc;hp=2f4fc04ded6ee6923322691354ebcba03c595334;hpb=e392d397f6b86a49a05e9738357ccbfc2a922f01;p=r2c2.git diff --git a/source/3d/catalogue.cpp b/source/3d/catalogue.cpp index 2f4fc04..7169c60 100644 --- a/source/3d/catalogue.cpp +++ b/source/3d/catalogue.cpp @@ -1,11 +1,8 @@ -/* $Id$ - -This file is part of the MSP Märklin suite -Copyright © 2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - +#include #include +#include +#include +#include #include "catalogue.h" #include "tracktype.h" #include "vehicletype.h" @@ -13,12 +10,18 @@ Distributed under the GPL using namespace std; using namespace Msp; -namespace Marklin { +namespace R2C2 { Catalogue3D::Catalogue3D(Catalogue &c): catalogue(c), endpoint_mesh((GL::NORMAL3, GL::VERTEX3)) { + add_creator(&Catalogue3D::create); + add_creator(&Catalogue3D::create); + add_creator(&Catalogue3D::create2); + add_creator(&Catalogue3D::create); + add_creator(&Catalogue3D::create2); + catalogue.signal_track_added.connect(sigc::mem_fun(this, &Catalogue3D::track_added)); catalogue.signal_vehicle_added.connect(sigc::mem_fun(this, &Catalogue3D::vehicle_added)); @@ -26,9 +29,6 @@ Catalogue3D::Catalogue3D(Catalogue &c): for(Catalogue::TrackMap::const_iterator i=trks.begin(); i!=trks.end(); ++i) track_added(*i->second); - ballast_material.set_diffuse(GL::Color(0.25, 0.25, 0.25)); - rail_material.set_diffuse(GL::Color(0.85, 0.85, 0.85)); - build_endpoint_mesh(); } @@ -42,20 +42,12 @@ Catalogue3D::~Catalogue3D() const TrackType3D &Catalogue3D::get_track(const TrackType &tt) const { - map::const_iterator i = tracks.find(&tt); - if(i==tracks.end()) - throw KeyError("Unknown track type"); - - return *i->second; + return *get_item(tracks, &tt); } const VehicleType3D &Catalogue3D::get_vehicle(const VehicleType &vt) const { - map::const_iterator i = vehicles.find(&vt); - if(i==vehicles.end()) - throw KeyError("Unknown vehicle type"); - - return *i->second; + return *get_item(vehicles, &vt); } void Catalogue3D::track_added(const TrackType &track) @@ -71,12 +63,12 @@ void Catalogue3D::vehicle_added(const VehicleType &veh) void Catalogue3D::build_endpoint_mesh() { const Profile &ballast_profile = catalogue.get_ballast_profile(); - const Point &ballast_min = ballast_profile.get_min_coords(); - const Point &ballast_max = ballast_profile.get_max_coords(); + const Vector &ballast_min = ballast_profile.get_min_coords(); + const Vector &ballast_max = ballast_profile.get_max_coords(); const Profile &rail_profile = catalogue.get_rail_profile(); - const Point &rail_min = rail_profile.get_min_coords(); - const Point &rail_max = rail_profile.get_max_coords(); + const Vector &rail_min = rail_profile.get_min_coords(); + const Vector &rail_max = rail_profile.get_max_coords(); float gauge = catalogue.get_gauge(); @@ -93,4 +85,32 @@ void Catalogue3D::build_endpoint_mesh() bld.end(); } -} // namespace Marklin +FS::Path Catalogue3D::locate_file(const string &name) +{ + if(FS::exists(name)) + return name; + + FS::Path path = FS::Path("data")/name; + if(FS::exists(path)) + return path; + + throw runtime_error("Can't locate "+name); +} + +template +T *Catalogue3D::create(const string &name) +{ + RefPtr obj = new T; + DataFile::load(*obj, locate_file(name).str()); + return obj.release(); +} + +template +T *Catalogue3D::create2(const string &name) +{ + RefPtr obj = new T; + DataFile::load(*obj, locate_file(name).str(), *this); + return obj.release(); +} + +} // namespace R2C2