]> git.tdb.fi Git - r2c2.git/blob - source/3d/allocation.cpp
Provide some telemetry values from ArduControl
[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==&train)
33         {
34                 if(paths.count(&block))
35                         return;
36
37                 PathList &bpaths = paths[&block];
38                 const Block::TrackSet &tracks = block.get_tracks();
39                 for(Block::TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
40                 {
41                         Path3D *path = new Path3D(layout.get_3d(**i));
42                         bpaths.push_back(path);
43                         path->set_layer(1);
44                         float intensity = 0.5+train.get_block_allocator().is_block_current(block)*0.5;
45                         path->set_color(color*intensity);
46                         path->set_automatic();
47                 }
48         }
49         else
50         {
51                 PathMap::iterator i = paths.find(&block);
52                 if(i==paths.end())
53                         return;
54
55                 for(PathList::iterator j=i->second.begin(); j!=i->second.end(); ++j)
56                         delete *j;
57                 paths.erase(i);
58         }
59 }
60
61 void Allocation3D::train_advanced(Block &block)
62 {
63         PathMap::iterator i = paths.find(&block);
64         if(i==paths.end())
65                 return;
66
67         for(PathList::iterator j=i->second.begin(); j!=i->second.end(); ++j)
68                 (*j)->set_color(color);
69 }
70
71 } // namespace R2C2