]> git.tdb.fi Git - r2c2.git/blob - source/3d/allocation.cpp
New approach for displaying track state
[r2c2.git] / source / 3d / allocation.cpp
1 #include "libr2c2/block.h"
2 #include "allocation.h"
3 #include "layout.h"
4 #include "path.h"
5 #include "track.h"
6
7 using namespace Msp;
8
9 namespace R2C2 {
10
11 Allocation3D::Allocation3D(Layout3D &l, Train &t):
12         Utility3D(l),
13         train(t)
14 {
15         layout.get_layout().signal_block_reserved.connect(sigc::mem_fun(this, &Allocation3D::block_reserved));
16         train.signal_advanced.connect(sigc::mem_fun(this, &Allocation3D::train_advanced));
17 }
18
19 void Allocation3D::set_color(const GL::Color &c)
20 {
21         color = c;
22         for(PathMap::const_iterator i=paths.begin(); i!=paths.end(); ++i)
23         {
24                 float intensity = 0.5+train.get_block_allocator().is_block_current(*i->first)*0.5;
25                 for(PathList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
26                         (*j)->set_color(color*intensity);
27         }
28 }
29
30 void Allocation3D::block_reserved(Block &block, Train *t)
31 {
32         if(t && t!=&train)
33                 return;
34
35         if(t)
36         {
37                 if(paths.count(&block))
38                         return;
39
40                 PathList &bpaths = paths[&block];
41                 const Block::TrackSet &tracks = block.get_tracks();
42                 for(Block::TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
43                 {
44                         Path3D *path = new Path3D(layout.get<Track3D>(**i));
45                         bpaths.push_back(path);
46                         path->set_layer(1);
47                         float intensity = 0.5+train.get_block_allocator().is_block_current(block)*0.5;
48                         path->set_color(color*intensity);
49                         path->set_automatic();
50                 }
51         }
52         else
53         {
54                 PathMap::iterator i = paths.find(&block);
55                 if(i==paths.end())
56                         return;
57
58                 for(PathList::iterator j=i->second.begin(); j!=i->second.end(); ++j)
59                         delete *j;
60                 paths.erase(i);
61         }
62 }
63
64 void Allocation3D::train_advanced(Block &block)
65 {
66         PathMap::iterator i = paths.find(&block);
67         if(i==paths.end())
68                 return;
69
70         for(PathList::iterator j=i->second.begin(); j!=i->second.end(); ++j)
71                 (*j)->set_color(color);
72 }
73
74 } // namespace R2C2