a84d4591d125c40c0841a7d8216f0f666b0f50e5
[mussa.git] / alg / annotation_colors.cpp
1 #include "annotation_colors.hpp"
2
3 using namespace std;
4
5 DefaultColorMap::DefaultColorMap()
6   : defaultColor(Color(0.0, 0.0, 0.0)) // set default color to black
7 {
8 }
9
10 DefaultColorMap::DefaultColorMap(const Color &c) 
11   : defaultColor(c)
12 {
13 }
14
15 DefaultColorMap::DefaultColorMap(const DefaultColorMap &dcm)
16   : defaultColor(dcm.defaultColor),
17     cm(dcm.cm)
18 {
19 }
20
21 AnnotationColors::AnnotationColors()
22 {
23 }
24
25 AnnotationColors::AnnotationColors(const AnnotationColors &ac)
26   : root_map(ac.root_map)
27 {
28 }
29
30 void AnnotationColors::clear()
31 {
32   root_map.cm.clear();
33   root_map.defaultColor = Color(0.0, 0.0, 0.0);
34 }
35
36 void AnnotationColors::setColor(Color &c)
37 {
38   root_map.defaultColor = c;
39 }
40
41 Color AnnotationColors::color() 
42 {
43   return root_map.defaultColor;
44 }
45
46 void AnnotationColors::appendTypeColor(const string &type, const Color &c)
47 {
48   root_map.cm[type].defaultColor = c;
49 }
50
51 Color AnnotationColors::typeColor(const string &type)
52 {
53   return root_map.cm[type].defaultColor;
54 }
55
56 void AnnotationColors::erase(const string &type)
57 {
58   root_map.cm.erase(type);
59 }
60
61 void AnnotationColors::appendInstanceColor(const string &type, 
62                                            const string &instance,
63                                            const Color &c)
64 {
65   root_map.cm[type].cm[instance].defaultColor = c;
66 }
67
68 Color AnnotationColors::instanceColor(const string &type,
69                                       const string &instance) 
70 {
71   return root_map.cm[type].cm[instance].defaultColor;
72 }
73
74 void AnnotationColors::erase(const string &type, 
75                              const string& instance)
76 {
77   root_map.cm[type].cm.erase(instance);
78 }
79
80 Color AnnotationColors::lookup(const annot &a) const
81 {
82   return lookup(a.type, a.name);
83 }
84
85 Color AnnotationColors::lookup(const string &type, const string &instance) const
86 {
87   // Yeah, there's probably a nicer looking recursive solution
88   // to this problem.
89   DefaultColorMap::const_iterator type_map = root_map.cm.find(type);
90   if (type_map != root_map.cm.end() ) {
91     // found lookup instance
92     DefaultColorMap::const_iterator instance_map = type_map->second.cm.find(instance);
93     if (instance_map != type_map->second.cm.end() ) {
94       return instance_map->second.defaultColor;
95     } else {
96       return type_map->second.defaultColor;
97     }
98   } else {
99     // not found
100     return root_map.defaultColor;
101   }
102 }
103