X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2F3d%2Fallocation.cpp;fp=source%2F3d%2Fallocation.cpp;h=4bafb111c7e60e02cd018960d599d9c24796a216;hb=5116fff210cdc3f0fbdae13046cc60450aad5e8f;hp=0000000000000000000000000000000000000000;hpb=7fac28fcb5afb17eff7c459474e4cf884a02719c;p=r2c2.git diff --git a/source/3d/allocation.cpp b/source/3d/allocation.cpp new file mode 100644 index 0000000..4bafb11 --- /dev/null +++ b/source/3d/allocation.cpp @@ -0,0 +1,74 @@ +#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(**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