]> git.tdb.fi Git - r2c2.git/blob - source/3d/allocation.cpp
Make some internal colors darker to match linear color space
[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                 GL::Color block_color = get_color_for_block(*i->first);
25                 for(PathList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
26                         (*j)->set_color(block_color);
27         }
28 }
29
30 GL::Color Allocation3D::get_color_for_block(const Block &block) const
31 {
32         float intensity = 0.25+train.get_block_allocator().is_block_current(block)*0.75;
33         return color*intensity;
34 }
35
36 void Allocation3D::block_reserved(Block &block, Train *t)
37 {
38         if(t==&train)
39         {
40                 if(paths.count(&block))
41                         return;
42
43                 PathList &bpaths = paths[&block];
44                 GL::Color block_color = get_color_for_block(block);
45                 const Block::TrackSet &tracks = block.get_tracks();
46                 for(Block::TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
47                 {
48                         Path3D *path = new Path3D(layout.get_3d(**i));
49                         bpaths.push_back(path);
50                         path->set_layer(1);
51                         path->set_color(block_color);
52                         path->set_automatic();
53                 }
54         }
55         else
56         {
57                 PathMap::iterator i = paths.find(&block);
58                 if(i==paths.end())
59                         return;
60
61                 for(PathList::iterator j=i->second.begin(); j!=i->second.end(); ++j)
62                         delete *j;
63                 paths.erase(i);
64         }
65 }
66
67 void Allocation3D::train_advanced(Block &block)
68 {
69         PathMap::iterator i = paths.find(&block);
70         if(i==paths.end())
71                 return;
72
73         for(PathList::iterator j=i->second.begin(); j!=i->second.end(); ++j)
74                 (*j)->set_color(color);
75 }
76
77 } // namespace R2C2