From: Mikko Rasa Date: Mon, 1 Mar 2010 20:35:46 +0000 (+0000) Subject: Add accessors adding things to a Catalogue from the outside X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=48dff17ed3144d944965e7cb534e1f8fb92bd620;p=r2c2.git Add accessors adding things to a Catalogue from the outside Emit signals from Catalogue as things are added Make Catalogue3D listen to the signals and create appropriate things Remove the track color and quality interfaces --- diff --git a/source/3d/catalogue.cpp b/source/3d/catalogue.cpp index a5c584b..54341c1 100644 --- a/source/3d/catalogue.cpp +++ b/source/3d/catalogue.cpp @@ -14,13 +14,15 @@ using namespace Msp; namespace Marklin { -Catalogue3D::Catalogue3D(const Catalogue &c): +Catalogue3D::Catalogue3D(Catalogue &c): catalogue(c), endpoint_mesh((GL::NORMAL3, GL::VERTEX3)) { + catalogue.signal_track_added.connect(sigc::mem_fun(this, &Catalogue3D::track_added)); + const map &trks = catalogue.get_tracks(); for(map::const_iterator i=trks.begin(); i!=trks.end(); ++i) - tracks[i->second] = new TrackType3D(*this, *i->second); + 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)); @@ -43,6 +45,11 @@ const TrackType3D &Catalogue3D::get_track(const TrackType &tt) const return *i->second; } +void Catalogue3D::track_added(const TrackType &track) +{ + tracks[&track] = new TrackType3D(*this, track); +} + void Catalogue3D::build_endpoint_mesh() { const Profile &ballast_profile = catalogue.get_ballast_profile(); diff --git a/source/3d/catalogue.h b/source/3d/catalogue.h index ccbf588..6cc5bed 100644 --- a/source/3d/catalogue.h +++ b/source/3d/catalogue.h @@ -19,14 +19,14 @@ class TrackType3D; class Catalogue3D { private: - const Catalogue &catalogue; + Catalogue &catalogue; std::map tracks; Msp::GL::Material ballast_material; Msp::GL::Material rail_material; Msp::GL::Mesh endpoint_mesh; public: - Catalogue3D(const Catalogue &); + Catalogue3D(Catalogue &); ~Catalogue3D(); const Catalogue &get_catalogue() const { return catalogue; } @@ -35,6 +35,7 @@ public: const Msp::GL::Material &get_rail_material() const { return rail_material; } const Msp::GL::Mesh &get_endpoint_mesh() const { return endpoint_mesh; } private: + void track_added(const TrackType &); void build_endpoint_mesh(); }; diff --git a/source/3d/layout.cpp b/source/3d/layout.cpp index b95d4e5..a8fbc1e 100644 --- a/source/3d/layout.cpp +++ b/source/3d/layout.cpp @@ -22,8 +22,7 @@ namespace Marklin { Layout3D::Layout3D(Layout &l): layout(l), - catalogue(layout.get_catalogue()), - quality(4) + catalogue(layout.get_catalogue()) { layout.signal_track_added.connect(sigc::mem_fun(this, &Layout3D::track_added)); layout.signal_track_removed.connect(sigc::mem_fun(this, &Layout3D::track_removed)); @@ -39,11 +38,6 @@ Layout3D::~Layout3D() delete tracks.front(); } -void Layout3D::set_quality(unsigned q) -{ - quality = q; -} - void Layout3D::add_track(Track3D &t) { tracks.push_back(&t); diff --git a/source/3d/layout.h b/source/3d/layout.h index a7fbdb9..9120af6 100644 --- a/source/3d/layout.h +++ b/source/3d/layout.h @@ -23,14 +23,12 @@ private: std::list tracks; Msp::GL::Scene scene; Msp::GL::Scene ep_scene; - unsigned quality; public: Layout3D(Layout &); ~Layout3D(); const Catalogue3D &get_catalogue() const { return catalogue; } - void set_quality(unsigned); void add_track(Track3D &); void remove_track(Track3D &); diff --git a/source/3d/track.h b/source/3d/track.h index fb662bf..9928e11 100644 --- a/source/3d/track.h +++ b/source/3d/track.h @@ -9,7 +9,6 @@ Distributed under the GPL #define MARKLIN3D_TRACK_H_ #include -#include #include #include #include @@ -37,7 +36,6 @@ public: Layout3D &get_layout() const { return layout; } Track &get_track() const { return track; } const TrackType3D &get_type() const { return type; } - void set_color(const Msp::GL::Color &) { } void get_bounds(float, Point &, Point &) const; virtual void render(const Msp::GL::Tag &) const; diff --git a/source/libmarklin/catalogue.cpp b/source/libmarklin/catalogue.cpp index cce5ef0..bb724bc 100644 --- a/source/libmarklin/catalogue.cpp +++ b/source/libmarklin/catalogue.cpp @@ -30,7 +30,25 @@ Catalogue::~Catalogue() delete i->second; } -TrackType &Catalogue::get_track(unsigned art_nr) const +void Catalogue::add_track(TrackType &track) +{ + if(tracks.count(track.get_article_number())) + throw Exception("Duplicate track type"); + + tracks[track.get_article_number()] = &track; + signal_track_added.emit(track); +} + +void Catalogue::add_locomotive(LocoType &loco) +{ + if(locos.count(loco.get_article_number())) + throw Exception("Duplicate track type"); + + locos[loco.get_article_number()] = &loco; + signal_loco_added.emit(loco); +} + +const TrackType &Catalogue::get_track(unsigned art_nr) const { map::const_iterator i=tracks.find(art_nr); if(i==tracks.end()) @@ -39,7 +57,7 @@ TrackType &Catalogue::get_track(unsigned art_nr) const return *i->second; } -LocoType &Catalogue::get_locomotive(unsigned art_nr) const +const LocoType &Catalogue::get_locomotive(unsigned art_nr) const { map::const_iterator i=locos.find(art_nr); if(i==locos.end()) @@ -78,12 +96,10 @@ void Catalogue::Loader::layout() void Catalogue::Loader::locomotive(unsigned art_nr) { - if(obj.locos.count(art_nr)) - throw Exception("Duplicate locomotive number"); - RefPtr loco = new LocoType(art_nr); load_sub(*loco); - obj.locos[art_nr] = loco.release(); + obj.add_locomotive(*loco); + loco.release(); } void Catalogue::Loader::rail_profile() @@ -98,12 +114,10 @@ void Catalogue::Loader::scale(float n, float d) void Catalogue::Loader::track(unsigned art_nr) { - if(obj.tracks.count(art_nr)) - throw Exception("Duplicate track number"); - RefPtr trk = new TrackType(art_nr); load_sub(*trk); - obj.tracks[art_nr] = trk.release(); + obj.add_track(*trk); + trk.release(); } } // namespace Marklin diff --git a/source/libmarklin/catalogue.h b/source/libmarklin/catalogue.h index e531941..641b6f8 100644 --- a/source/libmarklin/catalogue.h +++ b/source/libmarklin/catalogue.h @@ -35,6 +35,9 @@ public: void track(unsigned); }; + sigc::signal signal_track_added; + sigc::signal signal_loco_added; + private: float scale; float gauge; @@ -52,10 +55,15 @@ public: float get_gauge() const { return gauge; } const Profile &get_rail_profile() const { return rail_profile; } const Profile &get_ballast_profile() const { return ballast_profile; } - TrackType &get_track(unsigned) const; + + void add_track(TrackType &); + const TrackType &get_track(unsigned) const; const std::map &get_tracks() const { return tracks; } - LocoType &get_locomotive(unsigned) const; + + void add_locomotive(LocoType &); + const LocoType &get_locomotive(unsigned) const; const std::map &get_locomotives() const { return locos; } + Layout &get_layout() { return layout; } }; diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index 4e6620b..b61522b 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -17,7 +17,7 @@ using namespace Msp; namespace Marklin { -Layout::Layout(const Catalogue &c): +Layout::Layout(Catalogue &c): catalogue(c) { } @@ -210,7 +210,7 @@ void Layout::Loader::route(const string &n) void Layout::Loader::track(unsigned art_nr) { - TrackType &type = obj.catalogue.get_track(art_nr); + const TrackType &type = obj.catalogue.get_track(art_nr); RefPtr trk = new Track(type); load_sub(*trk); diff --git a/source/libmarklin/layout.h b/source/libmarklin/layout.h index 4ec4277..86836b8 100644 --- a/source/libmarklin/layout.h +++ b/source/libmarklin/layout.h @@ -37,16 +37,16 @@ public: sigc::signal signal_route_removed; private: - const Catalogue &catalogue; + Catalogue &catalogue; std::string base; std::set tracks; std::map routes; public: - Layout(const Catalogue &); + Layout(Catalogue &); ~Layout(); - const Catalogue &get_catalogue() const { return catalogue; } + Catalogue &get_catalogue() const { return catalogue; } const std::string &get_base() const { return base; } const std::set &get_tracks() const { return tracks; } void add_track(Track &);