]> git.tdb.fi Git - r2c2.git/commitdiff
Add a utility class to display a TrackChain as a path
authorMikko Rasa <tdb@tdb.fi>
Fri, 9 Aug 2013 16:39:05 +0000 (19:39 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 11 Aug 2013 12:25:52 +0000 (15:25 +0300)
source/3d/trackchain.cpp [new file with mode: 0644]
source/3d/trackchain.h [new file with mode: 0644]

diff --git a/source/3d/trackchain.cpp b/source/3d/trackchain.cpp
new file mode 100644 (file)
index 0000000..3d972d1
--- /dev/null
@@ -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<Track3D>(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 (file)
index 0000000..1610c7d
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef R2C2_3D_TRACKCHAIN_H_
+#define R2C2_3D_TRACKCHAIN_H_
+
+#include <msp/gl/color.h>
+#include "libr2c2/trackchain.h"
+
+namespace R2C2 {
+
+class Layout3D;
+class Path3D;
+
+class TrackChain3D: public sigc::trackable
+{
+protected:
+       typedef std::map<Track *, Path3D *> 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