]> git.tdb.fi Git - r2c2.git/commitdiff
Add accessors adding things to a Catalogue from the outside
authorMikko Rasa <tdb@tdb.fi>
Mon, 1 Mar 2010 20:35:46 +0000 (20:35 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 1 Mar 2010 20:35:46 +0000 (20:35 +0000)
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

source/3d/catalogue.cpp
source/3d/catalogue.h
source/3d/layout.cpp
source/3d/layout.h
source/3d/track.h
source/libmarklin/catalogue.cpp
source/libmarklin/catalogue.h
source/libmarklin/layout.cpp
source/libmarklin/layout.h

index a5c584be58e4dd0e41f41ff35dbab3bc0fa81deb..54341c10c0432e7344d30d35cda86cf3724b2596 100644 (file)
@@ -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<unsigned, TrackType *> &trks = catalogue.get_tracks();
        for(map<unsigned, TrackType *>::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();
index ccbf5887c454c7e2c46701a9947d1fbd3cfa285d..6cc5bede4fcdc27f2faa845c1e96d723888f9eb0 100644 (file)
@@ -19,14 +19,14 @@ class TrackType3D;
 class Catalogue3D
 {
 private:
-       const Catalogue &catalogue;
+       Catalogue &catalogue;
        std::map<const TrackType *, TrackType3D *> 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();
 };
 
index b95d4e59c835798d2df81530d060e6e7303bff7d..a8fbc1ea0706ea61e08ecb1f2550d3d168e0e3f3 100644 (file)
@@ -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);
index a7fbdb98b9dbc7b7751ce2e26470403dd647c85d..9120af6356b2320018e05b7dadfaf3d1da5fedcd 100644 (file)
@@ -23,14 +23,12 @@ private:
        std::list<Track3D *> 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 &);
index fb662bf890cfd8fb1f90923bfdcdcda06869fe66..9928e11449345d2c0f453e8889913dc12058696d 100644 (file)
@@ -9,7 +9,6 @@ Distributed under the GPL
 #define MARKLIN3D_TRACK_H_
 
 #include <list>
-#include <msp/gl/color.h>
 #include <msp/gl/renderable.h>
 #include <msp/gl/vertexarray.h>
 #include <msp/gl/vertexarraybuilder.h>
@@ -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;
index cce5ef04ee564d3b2bd7f8b78278e89a0ccab3ff..bb724bc823868bc8beb12b8ec968258ae80ad324 100644 (file)
@@ -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<unsigned, TrackType *>::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<unsigned, LocoType *>::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<LocoType> 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<TrackType> trk = new TrackType(art_nr);
        load_sub(*trk);
-       obj.tracks[art_nr] = trk.release();
+       obj.add_track(*trk);
+       trk.release();
 }
 
 } // namespace Marklin
index e531941b40fb6e1c072491f90094b2ae8164ce1a..641b6f8b13c3ea15275a987cdd76a8eff71035f5 100644 (file)
@@ -35,6 +35,9 @@ public:
                void track(unsigned);
        };
 
+       sigc::signal<void, const TrackType &> signal_track_added;
+       sigc::signal<void, const LocoType &> 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<unsigned, TrackType *> &get_tracks() const { return tracks; }
-       LocoType &get_locomotive(unsigned) const;
+
+       void add_locomotive(LocoType &);
+       const LocoType &get_locomotive(unsigned) const;
        const std::map<unsigned, LocoType *> &get_locomotives() const { return locos; }
+
        Layout &get_layout() { return layout; }
 };
 
index 4e6620b2e1bcbb6704446efef85aabf5015c3b90..b61522ba4d59bfdc2d45344f3487aa912d7d694b 100644 (file)
@@ -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<Track> trk = new Track(type);
        load_sub(*trk);
index 4ec4277fcd60d909851f3937b457e40e40c27a01..86836b87f16e01fe7cbcba495fd08ab514ae553d 100644 (file)
@@ -37,16 +37,16 @@ public:
        sigc::signal<void, Route &> signal_route_removed;
 
 private:
-       const Catalogue &catalogue;
+       Catalogue &catalogue;
        std::string base;
        std::set<Track *> tracks;
        std::map<std::string, Route *> 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<Track *> &get_tracks() const { return tracks; }
        void add_track(Track &);