const Block::TrackSet &tracks = block.get_tracks();
for(Block::TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
{
- Path3D *path = new Path3D(layout.get<Track3D>(**i));
+ Path3D *path = new Path3D(layout.get_3d(**i));
bpaths.push_back(path);
path->set_layer(1);
float intensity = 0.5+train.get_block_allocator().is_block_current(block)*0.5;
insert_unique(objects, &o.get_object(), &o);
}
-Object3D &Layout3D::get(Object &o) const
+Object3D &Layout3D::get_3d(Object &o) const
{
return *get_item(objects, &o);
}
#include <msp/gl/simplescene.h>
#include "libr2c2/layout.h"
#include "catalogue.h"
+#include "typemap.h"
namespace R2C2 {
void get_bounds(Vector &, Vector &) const;
void add(Object3D &);
- Object3D &get(Object &) const;
+ Object3D &get_3d(Object &) const;
const ObjectMap &get_all() const { return objects; }
void remove(Object3D &);
template<typename T>
- T &get(Object &o) const
- { return dynamic_cast<T &>(get(o)); }
+ typename TypeMap3D<T>::Type3D &get_3d(T &o) const
+ { return dynamic_cast<typename TypeMap3D<T>::Type3D &>(get_3d(static_cast<Object &>(o))); }
void add(Utility3D &);
void remove(Utility3D &);
void TrackChain3D::track_added(Track &track)
{
- Track3D &track_3d = layout.get<Track3D>(track);
+ Track3D &track_3d = layout.get_3d(track);
Path3D *path = new Path3D(track_3d);
paths.insert(PathMap::value_type(&track, path));
path->set_color(color);
TrackIter iter = BlockIter(block, 0).track_iter();
for(; (iter && &iter->get_block()==block); iter=iter.next())
{
- Path3D *path = new Path3D(layout.get<Track3D>(*iter));
+ Path3D *path = new Path3D(layout.get_3d(*iter));
paths.push_back(path);
path->set_side(iter.entry()*2-1);
}
--- /dev/null
+#ifndef R2C2_3D_TYPEMAP_H_
+#define R2C2_3D_TYPEMAP_H_
+
+#include <msp/core/meta.h>
+#include "signal.h"
+#include "track.h"
+#include "vehicle.h"
+
+namespace R2C2 {
+
+template<typename T>
+struct TypeMap3D;
+
+template<typename T>
+struct TypeMap3D<const T>: TypeMap3D<T>
+{ };
+
+template<> struct TypeMap3D<Signal> { typedef Signal3D Type3D; };
+template<> struct TypeMap3D<Track> { typedef Track3D Type3D; };
+template<> struct TypeMap3D<Vehicle> { typedef Vehicle3D Type3D; };
+
+} // namespace R2C2
+
+#endif
const set<Track *> &tracks = layout->get_all<Track>();
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
- update_track_icon(layout_3d->get<Track3D>(**i));
+ update_track_icon(layout_3d->get_3d(**i));
}
Designer::~Designer()
selection.clear();
for(set<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
{
- overlay->clear(layout_3d->get<Track3D>(**i));
+ overlay->clear(layout_3d->get_3d(**i));
delete *i;
}
}
if(*j!=*i)
(*i)->snap_to(**j, true);
- update_track_icon(layout_3d->get<Track3D>(**i));
+ update_track_icon(layout_3d->get_3d(**i));
}
}
else if(key==Msp::Input::KEY_F)
{
const set<Track *> &tracks = selection.get_objects<Track>();
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
- update_track_icon(layout_3d->get<Track3D>(**i));
+ update_track_icon(layout_3d->get_3d(**i));
}
void Designer::route_name_accept(const string &text)
const set<Track *> &rtracks = route.get_tracks();
for(set<Track *>::iterator i=rtracks.begin(); i!=rtracks.end(); ++i)
{
- Track3D &t3d = layout_3d->get<Track3D>(**i);
+ Track3D &t3d = layout_3d->get_3d(**i);
Path3D *path = new Path3D(t3d);
path->set_color(GL::Color(0.5, 0.8, 1.0));
if(unsigned tid = (*i)->get_turnout_id())
const Zone::TrackSet &ztracks = zone.get_tracks();
for(Zone::TrackSet::const_iterator i=ztracks.begin(); i!=ztracks.end(); ++i)
{
- Track3D &t3d = layout_3d->get<Track3D>(**i);
+ Track3D &t3d = layout_3d->get_3d(**i);
Path3D *path = new Path3D(t3d);
path->set_color(GL::Color(0.8, 1.0, 0.5));
}
const set<Track *> &tracks = layout.get_all<Track>();
for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
if((*i)->get_type().is_turnout())
- new Path3D(layout_3d.get<Track3D>(**i));
+ new Path3D(layout_3d.get_3d(**i));
if(FS::exists(options.state_fn))
DataFile::load(layout, options.state_fn);
void Engineer::process_new_train(Train &train)
{
- Vehicle3D &loco3d = layout_3d.get<Vehicle3D>(train.get_vehicle(0));
+ Vehicle3D &loco3d = layout_3d.get_3d(train.get_vehicle(0));
overlay->set_label(loco3d, train.get_name());
train.signal_name_changed.connect(sigc::bind<0>(sigc::mem_fun(overlay, &Overlay3D::set_label), sigc::ref(loco3d)));
}