CommonNode.hh
5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
* CommonNode.hh
*
* Created on: 30 oct. 2013
* Author: CS
*/
#ifndef COMMONNODE_HH_
#define COMMONNODE_HH_
#include "NodeCfg.hh"
#include "PlotLogger.hh"
#include "PlotCommon.hh"
#include "Font.hh"
#include "Color.hh"
#include "Label.hh"
namespace plot {
/**
* Exception to raise when plot xml parsing fails.
*/
struct PlotNodeException: AMDA::AMDA_exception {
};
class LabelNode: public AMDA::XMLConfigurator::NodeCfg {
public:
LabelNode() :
AMDA::XMLConfigurator::NodeCfg() {
}
virtual ~LabelNode() {
}
void proceed(xmlNodePtr pNode,
const AMDA::Parameters::CfgContext& pContext);
};
template<class T>
class TitleNode: public LabelNode {
public:
TitleNode() :
LabelNode() {
}
virtual ~TitleNode() {
}
void proceed(xmlNodePtr pNode,
const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "TitleNode::proceed");
T* element = pContext.get<T*>();
xmlChar* value = NULL;
// -- horizontal margin
value = xmlGetProp(pNode, (const xmlChar *) "position");
if (value) {
PlotCommon::setPosition((const char*) value,
element->_titlePosition);
xmlFree(value);
}
// -- vertical margin
value = xmlGetProp(pNode, (const xmlChar *) "align");
if (value) {
PlotCommon::setTitleAlign((const char*) value,
element->_titleAlign);
xmlFree(value);
}
if (pNode->children) {
element->setTitleText((const char*) pNode->children->content);
}
AMDA::Parameters::CfgContext context;
context.push<Label*>(element->getTitle());
LabelNode::proceed(pNode, context);
}
};
/*
template<class T>
class ColorNode: public AMDA::XMLConfigurator::NodeCfg {
public:
ColorNode() :
NodeCfg() {
}
virtual ~ColorNode() {
}
void getColor(xmlNodePtr pNode, Color& color) {
xmlChar* value = NULL;
// -- color map index
value = xmlGetProp(pNode, (const xmlChar *) "colorMapIndex");
if (value) {
color._colorMapIndex = atoi((const char*) value);
} else {
color._colorMapIndex = -1;
}
// -- color Index
value = xmlGetProp(pNode, (const xmlChar *) "colorIndex");
if (value) {
color._colorIndex = atoi((const char*) value);
} else {
color._colorIndex = -1;
}
// -- red
value = xmlGetProp(pNode, (const xmlChar *) "red");
if (value) {
color._red = atoi((const char*) value);
} else {
color._red = -1;
}
// -- green
value = xmlGetProp(pNode, (const xmlChar *) "green");
if (value) {
color._green = atoi((const char*) value);
} else {
color._green = -1;
}
// -- blue
value = xmlGetProp(pNode, (const xmlChar *) "blue");
if (value) {
color._blue = atoi((const char*) value);
} else {
color._blue = -1;
}
if (value) {
xmlFree(value);
}
}
};*/
/*template<class T>
class BackgroundColorNode: public ColorNode<T> {
public:
BackgroundColorNode() :
ColorNode<T>() {
}
virtual ~BackgroundColorNode() {
}
void proceed(xmlNodePtr pNode,
const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "ColorNode::proceed");
T* element = pContext.get<T*>();
this->getColor(pNode, element->_backgroundColor);
}
};*/
template<class T>
class FontNode: public AMDA::XMLConfigurator::NodeCfg {
public:
FontNode() :
NodeCfg() {
}
virtual ~FontNode() {
}
void proceed(xmlNodePtr pNode,
const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "FontNode::proceed");
T* element = pContext.get<T*>();
xmlChar* value = NULL;
Font elementFont(element->getFont());
// -- name
value = xmlGetProp(pNode, (const xmlChar *) "name");
if (value) {
elementFont.setName((const char*) value);
xmlFree(value);
}
// -- size
value = xmlGetProp(pNode, (const xmlChar *) "size");
if (value) {
elementFont.setSize(atoi((const char*) value));
xmlFree(value);
}
// -- style
value = xmlGetProp(pNode, (const xmlChar *) "style");
if (value) {
elementFont.setStyle(Font::getStyleByStr((const char*) value));
xmlFree(value);
}
// -- weight
value = xmlGetProp(pNode, (const xmlChar *) "weight");
if (value) {
elementFont.setWeight(Font::getWeightByStr((const char*) value));
xmlFree(value);
}
element->setFont(elementFont);
}
};
class MarginNode: public AMDA::XMLConfigurator::NodeCfg {
public:
MarginNode() :
NodeCfg() {
}
virtual ~MarginNode() {
}
void proceed(xmlNodePtr pNode,
const AMDA::Parameters::CfgContext& pContext);
};
//const Color parseColorAttributes(const xmlNodePtr pNode_, const xmlChar* colorAttributeName_, const xmlChar* colormapAttributName_);
/**
* update Color object, according to attributes of the given xml node.
* Method handles two different format for color attribute : [r,g,b] or index value in a color map.
* It also handles an attribute for identifying the color map to use (its an index pointing to the
* list of available color maps).
* The two format are mutually exclusive : updating a color with [r,g,b] format will automatically
* set color index to -1; respectively, setting a zero or positive number for color
* index will imply setting -1 for r,g,b part of the color object.
* Color map index should be a zero or positive integer, but no control is done in this method.
* @param color_ the color to update.
* @param pNode_ xml node containing color informations.
* @param colorTag_ color attribute. Can be either a [r,g,b] format or an int format (indicating an index into a color map).
* @param colorMapTag_ color map index. Index of the color map to use.
*/
void updateColor(Color& color_, const xmlNodePtr pNode_, const xmlChar* colorTag_, const xmlChar* colorMapTag_);
void createColor(Color& color, std::string& value);
std::vector<std::string> &split(const std::string &s, char delim,
std::vector<std::string> &elems);
std::vector<std::string> split(const std::string &s, char delim);
void extractMargins (const char *margins, int *margin1, int *margin2);
} /* namespace plot */
#endif /* COMMONNODE_HH_ */