From: Mikko Rasa Date: Fri, 9 Aug 2013 16:39:05 +0000 (+0300) Subject: Add a utility class to display a TrackChain as a path X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5076c0631dda658fd032410b2e009520eb08b31c;p=r2c2.git Add a utility class to display a TrackChain as a path --- diff --git a/source/3d/trackchain.cpp b/source/3d/trackchain.cpp new file mode 100644 index 0000000..3d972d1 --- /dev/null +++ b/source/3d/trackchain.cpp @@ -0,0 +1,62 @@ +#include "layout.h" +#include "path.h" +#include "trackchain.h" +#include "track.h" + +using namespace Msp; + +namespace R2C2 { + +TrackChain3D::TrackChain3D(Layout3D &l, TrackChain &r): + layout(l), + chain(r), + layer(0) +{ + chain.signal_track_added.connect(sigc::mem_fun(this, &TrackChain3D::track_added)); + chain.signal_track_removed.connect(sigc::mem_fun(this, &TrackChain3D::track_removed)); + + const TrackChain::TrackSet &tracks = chain.get_tracks(); + for(TrackChain::TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) + track_added(**i); +} + +TrackChain3D::~TrackChain3D() +{ + for(PathMap::iterator i=paths.begin(); i!=paths.end(); ++i) + delete i->second; +} + +void TrackChain3D::set_color(const GL::Color &c) +{ + color = c; + for(PathMap::iterator i=paths.begin(); i!=paths.end(); ++i) + i->second->set_color(color); +} + +void TrackChain3D::set_layer(float l) +{ + layer = l; + for(PathMap::iterator i=paths.begin(); i!=paths.end(); ++i) + i->second->set_layer(layer); +} + +void TrackChain3D::track_added(Track &track) +{ + Track3D &track_3d = layout.get(track); + Path3D *path = new Path3D(track_3d); + paths.insert(PathMap::value_type(&track, path)); + path->set_color(color); + path->set_layer(layer); +} + +void TrackChain3D::track_removed(Track &track) +{ + PathMap::iterator i = paths.find(&track); + if(i!=paths.end()) + { + delete i->second; + paths.erase(i); + } +} + +} // namespace R2C2 diff --git a/source/3d/trackchain.h b/source/3d/trackchain.h new file mode 100644 index 0000000..1610c7d --- /dev/null +++ b/source/3d/trackchain.h @@ -0,0 +1,37 @@ +#ifndef R2C2_3D_TRACKCHAIN_H_ +#define R2C2_3D_TRACKCHAIN_H_ + +#include +#include "libr2c2/trackchain.h" + +namespace R2C2 { + +class Layout3D; +class Path3D; + +class TrackChain3D: public sigc::trackable +{ +protected: + typedef std::map PathMap; + + Layout3D &layout; + TrackChain &chain; + PathMap paths; + Msp::GL::Color color; + float layer; + +public: + TrackChain3D(Layout3D &, TrackChain &); + ~TrackChain3D(); + + void set_color(const Msp::GL::Color &); + void set_layer(float); + +protected: + void track_added(Track &); + void track_removed(Track &); +}; + +} // namespace R2C2 + +#endif