+#include "libr2c2/block.h"
+#include "allocation.h"
+#include "layout.h"
+#include "path.h"
+#include "track.h"
+
+using namespace Msp;
+
+namespace R2C2 {
+
+Allocation3D::Allocation3D(Layout3D &l, Train &t):
+ Utility3D(l),
+ train(t)
+{
+ layout.get_layout().signal_block_reserved.connect(sigc::mem_fun(this, &Allocation3D::block_reserved));
+ train.signal_advanced.connect(sigc::mem_fun(this, &Allocation3D::train_advanced));
+}
+
+void Allocation3D::set_color(const GL::Color &c)
+{
+ color = c;
+ for(PathMap::const_iterator i=paths.begin(); i!=paths.end(); ++i)
+ {
+ float intensity = 0.5+train.get_block_allocator().is_block_current(*i->first)*0.5;
+ for(PathList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
+ (*j)->set_color(color*intensity);
+ }
+}
+
+void Allocation3D::block_reserved(Block &block, Train *t)
+{
+ if(t && t!=&train)
+ return;
+
+ if(t)
+ {
+ if(paths.count(&block))
+ return;
+
+ PathList &bpaths = paths[&block];
+ 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));
+ bpaths.push_back(path);
+ path->set_layer(1);
+ float intensity = 0.5+train.get_block_allocator().is_block_current(block)*0.5;
+ path->set_color(color*intensity);
+ path->set_automatic();
+ }
+ }
+ else
+ {
+ PathMap::iterator i = paths.find(&block);
+ if(i==paths.end())
+ return;
+
+ for(PathList::iterator j=i->second.begin(); j!=i->second.end(); ++j)
+ delete *j;
+ paths.erase(i);
+ }
+}
+
+void Allocation3D::train_advanced(Block &block)
+{
+ PathMap::iterator i = paths.find(&block);
+ if(i==paths.end())
+ return;
+
+ for(PathList::iterator j=i->second.begin(); j!=i->second.end(); ++j)
+ (*j)->set_color(color);
+}
+
+} // namespace R2C2