aab22d1b9b2d85258a36cf7da577922b78c88b92
[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(AnnotationColors &ac)
26   : root_map(ac.root_map)
27 {
28 }
29
30 void AnnotationColors::setColor(Color &c)
31 {
32   root_map.defaultColor = c;
33 }
34
35 Color AnnotationColors::color() 
36 {
37   return root_map.defaultColor;
38 }
39
40 void AnnotationColors::appendTypeColor(const string &type, const Color &c)
41 {
42   root_map.cm[type].defaultColor = c;
43 }
44
45 Color AnnotationColors::typeColor(const string &type)
46 {
47   return root_map.cm[type].defaultColor;
48 }
49
50 void AnnotationColors::erase(const string &type)
51 {
52   root_map.cm.erase(type);
53 }
54
55 void AnnotationColors::appendInstanceColor(const string &type, 
56                                            const string &instance,
57                                            const Color &c)
58 {
59   root_map.cm[type].cm[instance].defaultColor = c;
60 }
61
62 Color AnnotationColors::instanceColor(const string &type,
63                                       const string &instance) 
64 {
65   return root_map.cm[type].cm[instance].defaultColor;
66 }
67
68 void AnnotationColors::erase(const string &type, 
69                              const string& instance)
70 {
71   root_map.cm[type].cm.erase(instance);
72 }
73
74 Color AnnotationColors::lookup(const annot &a)
75 {
76   return lookup(a.type, a.name);
77 }
78
79 Color AnnotationColors::lookup(const string &type, const string &instance)
80 {
81   // Yeah, there's probably a nicer looking recursive solution
82   // to this problem.
83   DefaultColorMap::iterator type_map = root_map.cm.find(type);
84   if (type_map != root_map.cm.end() ) {
85     // found lookup instance
86     DefaultColorMap::iterator instance_map = type_map->second.cm.find(instance);
87     if (instance_map != type_map->second.cm.end() ) {
88       return instance_map->second.defaultColor;
89     } else {
90       return type_map->second.defaultColor;
91     }
92   } else {
93     // not found
94     return root_map.defaultColor;
95   }
96 }
97