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));
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();
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; }
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();
};
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));
delete tracks.front();
}
-void Layout3D::set_quality(unsigned q)
-{
- quality = q;
-}
-
void Layout3D::add_track(Track3D &t)
{
tracks.push_back(&t);
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 &);
#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>
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;
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())
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())
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()
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
void track(unsigned);
};
+ sigc::signal<void, const TrackType &> signal_track_added;
+ sigc::signal<void, const LocoType &> signal_loco_added;
+
private:
float scale;
float gauge;
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; }
};
namespace Marklin {
-Layout::Layout(const Catalogue &c):
+Layout::Layout(Catalogue &c):
catalogue(c)
{ }
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);
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 &);