Blame view

src/ParamOutputImpl/Plot/AdditionalObjectsNode.hh 8.16 KB
fbe3c2bb   Benjamin Renard   First commit
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
/*
 * AdditionalObjectsNode.hh
 *
 *  Created on: 1/07/2014
 *      Author: AKKA
 */

#ifndef ADDITIONALOBJECTSNODE_HH_
#define ADDITIONALOBJECTSNODE_HH_

#include <cstdlib>

#include "NodeCfg.hh"
#include "Constant.hh"
#include "PlotLogger.hh"
#include "CommonNode.hh"
#include "TextPlot.hh"
#include "CurvePlot.hh"
#include "CurveFunction/CurveFunctionWriter.hh"

namespace plot {

/*
 * @brief Text plot node
 */
class TextPlotNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	TextPlotNode() :
			AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["font"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new FontNode<TextPlot>());
	}

	virtual ~TextPlotNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx) {
		LOG4CXX_DEBUG(gLogger, "TextPlotNode::proceed");

		Panel* panel = pCtx.get<Panel*>();

		boost::shared_ptr<TextPlot> textPlot (new TextPlot());

		xmlChar* value = NULL;

		// -- text
		if ((value = xmlGetProp(pNode, (const xmlChar *) "text"))) {
			textPlot->_text = (const char *) value;
			xmlFree(value);
		}

078ec265   Benjamin Renard   Give the possibil...
52
53
54
55
56
57
58
59
60
61
62
63
		// -- xAxis
		if ((value = xmlGetProp(pNode, (const xmlChar *) "xAxis"))) {
			textPlot->_xAxisId = (const char *) value;
			xmlFree(value);
		}

		// -- yAxis
		if ((value = xmlGetProp(pNode, (const xmlChar *) "yAxis"))) {
			textPlot->_yAxisId = (const char *) value;
			xmlFree(value);
		}

fbe3c2bb   Benjamin Renard   First commit
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
		// -- x
		if ((value = xmlGetProp(pNode, (const xmlChar *) "x"))) {
			textPlot->_x = (const char *) value;
			xmlFree(value);
		}

		// -- y
		if ((value = xmlGetProp(pNode, (const xmlChar *) "y"))) {
			textPlot->_y = (const char *) value;
			xmlFree(value);
		}

		// -- angle
		if ((value = xmlGetProp(pNode, (const xmlChar *) "angle"))) {
			textPlot->_angle = std::stod((const char *) value);
			xmlFree(value);
		}

		// -- align
		if ((value = xmlGetProp(pNode, (const xmlChar *) "align"))) {
			if (strcmp ((const char *) value, "left") == 0)
				textPlot->_align = 0;
			else if (strcmp ((const char *) value, "center") == 0)
				textPlot->_align = 0.5;
			else
				textPlot->_align = 1.0;
			xmlFree(value);
		}

		// -- color
		Color color;
		value = xmlGetProp(pNode, (const xmlChar *) "color");
		if (value) {
			try {
				std::string strValue((const char*) value);
				createColor(color, strValue);
			} catch (std::logic_error& e) {
				LOG4CXX_WARN(gLogger, "TextPlot Color : " << e.what());
				color =
						DefaultPlotConfiguration::getInstance()._defaultPanel._backgroundColor;
			}
			xmlFree(value);
		} else {
			color =
					DefaultPlotConfiguration::getInstance()._defaultPanel._backgroundColor;
		}
		textPlot->_color = color;

		panel->_textPlots.push_back(textPlot);

		AMDA::Parameters::CfgContext context;
		context.push<TextPlot *> (textPlot.get());
		AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode, context);
	}


};

/*
 * @brief Curve function attribute node
 */
class CurveFunctionAttributeNode: public AMDA::XMLConfigurator::NodeCfg {
public:
	CurveFunctionAttributeNode() :
			NodeCfg() {
	}
	virtual ~CurveFunctionAttributeNode() {
	}

	void proceed(xmlNodePtr pNode,
			const AMDA::Parameters::CfgContext& pContext) {
		LOG4CXX_DEBUG(gLogger, "CurveFunctionAttributeNode::proceed");
		CurveFunctionWriter* curveFunction = pContext.get<CurveFunctionWriter*>();

		xmlChar* value = NULL;
		// -- name
		std::string attName = "";
		if ((value = xmlGetProp(pNode, (const xmlChar *) "name"))) {
			attName = (const char*) value;
			xmlFree(value);
		}

		if (attName.empty())
		{
			LOG4CXX_DEBUG(gLogger, "CurveFunctionAttributeNode::proceed - Attribute don't have a name => skip");
			return;
		}

		// -- value
		double attValue = 0.;
		if ((value = xmlGetProp(pNode, (const xmlChar *) "value"))) {
			attValue = std::atof((const char*)value);
			xmlFree(value);
		}
		else
		{
			LOG4CXX_DEBUG(gLogger, "CurveFunctionAttributeNode::proceed - Attribute " << attName << "don't have a value => set to 0.");
		}

		curveFunction->addAttribute(attName,attValue);
	}
};

/*
 * @brief Curve function attributes (ie list of attribute) node
 */
class CurveFunctionAttributesNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	CurveFunctionAttributesNode() :
		NodeGrpCfg() {
		getChildList()["attribute"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new CurveFunctionAttributeNode());
	}

	virtual ~CurveFunctionAttributesNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
		LOG4CXX_DEBUG(gLogger, "CurveFunctionAttributesNode::proceed");
		CurveFunctionWriter* curveFunction = pContext.get<CurveFunctionWriter*>();

		AMDA::Parameters::CfgContext context;
		context.push<CurveFunctionWriter *> (curveFunction);
		AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode, context);
	}
};

/*
 * @brief Curve function node
 */
class CurveFunctionNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	CurveFunctionNode() :
		NodeGrpCfg() {
		getChildList()["attributes"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new CurveFunctionAttributesNode());
	}

	virtual ~CurveFunctionNode() {
	}

	void proceed(xmlNodePtr pNode,
			const AMDA::Parameters::CfgContext& pContext) {
		LOG4CXX_DEBUG(gLogger, "CurveFunctionNode::proceed");
		CurvePlot* curvePlot = pContext.get<CurvePlot*>();
		xmlChar* value = NULL;

		// -- name
		std::string functionName;
		if ((value = xmlGetProp(pNode, (const xmlChar *) "name"))) {
			functionName = (const char*) value;
			xmlFree(value);
		}
		else
		{
			ERROR_EXCEPTION(
				AMDA::XMLConfigurator::ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@name")
		}

		std::shared_ptr<CurveFunctionWriter> curveFunction (new CurveFunctionWriter());
		curveFunction->setFunctionName(functionName);

		curvePlot->_curveFunction = curveFunction;

		AMDA::Parameters::CfgContext context;
		context.push<CurveFunctionWriter *> (curveFunction.get());
		AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode, context);
	}
};

/*
 * @brief Curve plot node
 */
class CurvePlotNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	CurvePlotNode() :
			AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["function"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new CurveFunctionNode());
	}

	virtual ~CurvePlotNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx) {
		LOG4CXX_DEBUG(gLogger, "CurvePlotNode::proceed");
		Panel* panel = pCtx.get<Panel*>();

		boost::shared_ptr<CurvePlot> curvePlot (new CurvePlot());

		xmlChar* value = NULL;

		// -- serieId
		if ((value = xmlGetProp(pNode, (const xmlChar *) "serieId"))) {
			curvePlot->_serieId = atoi((const char*)value);
			LOG4CXX_DEBUG(gLogger, "CurvePlotNode::proceed - curvePlot->_serieId " << curvePlot->_serieId);
			xmlFree(value);
		}

		// -- style
		if((value = xmlGetProp(pNode, (const xmlChar *)"style"))) {
			try{
				curvePlot->_style = stoLineStyle.at(std::string((const char*)value));
			}
			catch( std::out_of_range& err ){
				std::ostringstream msg {};
				msg << "CurvePlotNode::proceed invalid LineStyle value:" << value <<". Using default value.";
				LOG4CXX_DEBUG(gLogger, msg.str());
			}
			xmlFree(value);
		}

		// -- width
		if((value = xmlGetProp(pNode, (const xmlChar *)"width"))) {
			curvePlot->_width = atoi((const char*)value);
			xmlFree(value);
		}

		// -- color attributes :
		updateColor(curvePlot->_color, pNode, (const xmlChar *)"color", (const xmlChar *)"colorMapIndex");

		panel->_curvePlots.push_back(curvePlot);

		AMDA::Parameters::CfgContext context;
		context.push<CurvePlot *> (curvePlot.get());
		AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode, context);
	}
};

/*
 * @brief Additional object node
 */
class AdditionalObjectsNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	AdditionalObjectsNode() :
			AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["textPlot"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new TextPlotNode());
		getChildList()["curvePlot"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new CurvePlotNode());
	}
	virtual ~AdditionalObjectsNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx) {
		LOG4CXX_DEBUG(gLogger, "AdditionalObjectsNode::proceed");
		Panel* panel = pCtx.get<Panel*>();

		AMDA::Parameters::CfgContext context;
		context.push<Panel *> (panel);
		AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode, context);
	}
};

} /* namespace plot */
#endif /* ADDITIONALOBJECTSNODE_HH_ */