Blame view

src/ParamOutputImpl/Plot/AxesNode.hh 12.2 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
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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*
 * AxesNode.hh
 *
 *  Created on: 21 nov. 2013
 *      Author: CS
 */

#ifndef AXESNODE_HH_
#define AXESNODE_HH_

#include "NodeCfg.hh"
#include "PlotLogger.hh"
#include "CommonNode.hh"
#include "TimeAxis.hh"
#include "DigitalAxis.hh"
#include "ColorAxis.hh"
#include "EpochAxis.hh"
#include "Panel.hh"

namespace plot {

template<class AxisType>
class RangeNode: public AMDA::XMLConfigurator::NodeCfg {
public:
	RangeNode() :
			AMDA::XMLConfigurator::NodeCfg() {
	}
	virtual ~RangeNode() {
	}

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

		xmlChar* value = NULL;
		// -- min
		value = xmlGetProp(pNode, (const xmlChar *) "min");
		double min = nan("");
		if (value) {
			std::string text((const char*) value);
			std::string::size_type sz;
			min = std::stod(text, &sz);
			xmlFree(value);
		}
		// -- max
		value = xmlGetProp(pNode, (const xmlChar *) "max");
		double max = nan("");
		if (value) {
			std::string text((const char*) value);
			std::string::size_type sz;
			max = std::stod(text, &sz);
			xmlFree(value);
		}
		axis->setRequestedRange(min, max);

		// -- extend
		value = xmlGetProp(pNode, (const xmlChar *) "extend");
		if (value) {
			std::string strValue((const char*) value);
			std::transform(strValue.begin(), strValue.end(), strValue.begin(),
					::tolower);
			std::istringstream is(strValue);
			bool extend;
			is >> std::boolalpha >> extend;
			axis->setExtended(extend);
			xmlFree(value);
		}
	}
};

template<class AxisType>
class TickNode: public AMDA::XMLConfigurator::NodeCfg {
public:
	TickNode() :
			AMDA::XMLConfigurator::NodeCfg() {
	}
	virtual ~TickNode() {
	}

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

		xmlChar* value = NULL;
		std::string valueStr;
		// -- major
		// search for attribute majorNumber or majorSpace
		value = xmlGetProp(pNode, (const xmlChar *) "majorNumber");
		if (value) {
			valueStr = (const char*) value;
			axis->_tick.setMajorNumber(std::stod(valueStr, nullptr));
			xmlFree(value);
		} else {
			value = xmlGetProp(pNode, (const xmlChar *) "majorSpace");
			if (value) {
				valueStr = (const char*) value;
				axis->_tick.setMajorSpace(std::stod(valueStr, nullptr));
				xmlFree(value);
			}
		}

		// -- minor
		// search for attribute minorNumber or minorSpace
		value = xmlGetProp(pNode, (const xmlChar *) "minorNumber");
		if (value) {
			valueStr = (const char*) value;
			axis->_tick.setMinorNumber(std::stod(valueStr, nullptr));
			xmlFree(value);
		} else {
			value = xmlGetProp(pNode, (const xmlChar *) "minorSpace");
			if (value) {
				valueStr = (const char*) value;
				axis->_tick.setMinorSpace(std::stod(valueStr, nullptr));
				xmlFree(value);
			}
		}

		// -- axis grid (for minor ticks)
		value = xmlGetProp(pNode, (const xmlChar *) "minorGrid");
		if (value) {
			std::string strValue((const char*) value);
			std::transform(strValue.begin(), strValue.end(), strValue.begin(),
					::tolower);
			std::istringstream is(strValue);
			bool isVisible;
			is >> std::boolalpha >> isVisible;
			axis->_tick._isMinorGridVisible = isVisible;
			xmlFree(value);
		}

		// -- axis grid (for major ticks)
		value = xmlGetProp(pNode, (const xmlChar *) "majorGrid");
		if (value) {
			std::string strValue((const char*) value);
			std::transform(strValue.begin(), strValue.end(), strValue.begin(),
					::tolower);
			std::istringstream is(strValue);
			bool isVisible;
			is >> std::boolalpha >> isVisible;
			axis->_tick._isMajorGridVisible = isVisible;
			xmlFree(value);
		}

		// -- tick position
		value = xmlGetProp(pNode, (const xmlChar *) "position");
		if (value) {
			axis->_tick._position = Tick::getTickPosition((const char*) value);
			xmlFree(value);
		}

		// -- tick length factor
		value = xmlGetProp(pNode, (const xmlChar *) "lengthFactor");
		if (value) {
			valueStr = (const char*) value;
			axis->_tick._lengthFactor = std::stod(valueStr, nullptr);
			xmlFree(value);
		}
	}
};

template<class AxisType>
class LegendNode: public LabelNode {
public:
	LegendNode() :
			LabelNode() {
	}
	virtual ~LegendNode() {
	}

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

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

		AMDA::Parameters::CfgContext context;
		context.push<Label*>(&axis->_legend);

		LabelNode::proceed(pNode, context);
	}
};

template<class AxisType>
class ConstantLineNode: public AMDA::XMLConfigurator::NodeCfg {
public:
	ConstantLineNode() :
			AMDA::XMLConfigurator::NodeCfg() {
	}
	virtual ~ConstantLineNode() {
	}

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

		xmlChar* value = NULL;

		boost::shared_ptr<ConstantLine> constantLine (new ConstantLine ());

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

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

		// -- color attributes
		updateColor (constantLine->getColor(), pNode, (const xmlChar *)"color", (const xmlChar *)"colorMapIndex");

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

		// -- id
		value = xmlGetProp(pNode, (const xmlChar *)"id");
		if( value ){
			constantLine->setId (atoi((const char*)value));
			xmlFree(value);
		}


		// Add constantLine to _constantLines list
		axis->_constantLines.push_back (constantLine);
	}
};

template<class AxisType>
class AnyAxisNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	AnyAxisNode() :
			AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["range"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new RangeNode<AxisType>());
		getChildList()["tick"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new TickNode<AxisType>());
		getChildList()["legend"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new LegendNode<AxisType>());
		getChildList()["constantLine"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new ConstantLineNode<AxisType>());

	}
	virtual ~AnyAxisNode() {
	}

	virtual void proceed(xmlNodePtr pNode,
			const AMDA::Parameters::CfgContext& pContext) {
		LOG4CXX_DEBUG(gLogger, "AnyAxisNode::proceed");
		AxisType* axis = pContext.get<AxisType*>();

		xmlChar* value = NULL;

		// -- axis origin
		value = xmlGetProp(pNode, (const xmlChar *) "origin");
		if (value) {
			std::string valueStr((const char*) value);
			axis->_origin = std::stod(valueStr, nullptr); // must be 0.0
			if (axis->_origin != 0) {
				LOG4CXX_WARN(gLogger,
						"Axis origin must be 0.0, origin is set to min value");
			}
			xmlFree(value);
		}

		// -- axis position
		value = xmlGetProp(pNode, (const xmlChar *) "position");
		if (value) {
			PlotCommon::setPosition((const char*) value, axis->_position);
			xmlFree(value);
		}

		// -- axis thickness
		value = xmlGetProp(pNode, (const xmlChar *) "thickness");
		if (value) {
			std::string valueStr((const char*) value);
			axis->_thickness = std::stod(valueStr, nullptr);
			xmlFree(value);
		}

		// -- axis color
		value = xmlGetProp(pNode, (const xmlChar *) "color");
		if (value) {
			std::string strValue((const char*) value);
			try {
				createColor(axis->_color, strValue);
			} catch (std::exception& e) {
				LOG4CXX_WARN(gLogger, "Axis color : " << e.what());
			}
			xmlFree(value);
		}

		// -- axis color map index
		value = xmlGetProp(pNode, (const xmlChar *) "colorMapIndex");
		if (value) {
			axis->_color._colorMapIndex = atoi((const char*) value);
			xmlFree(value);
		} else if (axis->_color._colorIndex != -1
				&& axis->_color._colorMapIndex == -1) {
			LOG4CXX_WARN(gLogger,
					"No default color map is defined, color map 0 will be used");
			axis->_color._colorMapIndex = 0;
		}

		// -- axis reverse mode
		value = xmlGetProp(pNode, (const xmlChar *) "reverse");
		if (value) {
			std::string strValue((const char*) value);
			std::transform(strValue.begin(), strValue.end(), strValue.begin(),
					::tolower);
			std::istringstream is(strValue);
			bool isReverse;
			is >> std::boolalpha >> isReverse;
			axis->_reverse = isReverse;
			xmlFree(value);
		}

		// -- axis visibility
		value = xmlGetProp(pNode, (const xmlChar *) "visible");
		if (value) {
			std::string strValue((const char*) value);
			std::transform(strValue.begin(), strValue.end(), strValue.begin(),
					::tolower);
			std::istringstream is(strValue);
			bool isVisible;
			is >> std::boolalpha >> isVisible;
			axis->_visible = isVisible;
			xmlFree(value);
		}

		// -- scale type
		value = xmlGetProp(pNode, (const xmlChar *) "scale");
		if (value) {
			axis->setScale((const char*) value);
			xmlFree(value);
		}

		// -- showLegend
		value = xmlGetProp(pNode, (const xmlChar *) "showLegend");
		if (value) {
			axis->setShowLegend(strcasecmp ((const char*)value, "true") == 0);
			xmlFree(value);
		}

		// -- showTickMark
		value = xmlGetProp(pNode, (const xmlChar *) "showTickMark");
		if (value) {
			axis->setShowTickMark(strcasecmp ((const char*)value, "true") == 0);
			xmlFree(value);
		}

		NodeGrpCfg::proceed(pNode, pContext);
	}
};

class TimeAxisNode: public AnyAxisNode<TimeAxis> {
public:
	TimeAxisNode() :
			AnyAxisNode<TimeAxis>() {
	}
	virtual ~TimeAxisNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx);
};

class EpochAxisNode: public AnyAxisNode<EpochAxis> {
public:
	EpochAxisNode() :
			AnyAxisNode<EpochAxis>() {
	}
	virtual ~EpochAxisNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx);
};

class DigitalAxisNode: public AnyAxisNode<DigitalAxis> {
public:
	DigitalAxisNode() :
			AnyAxisNode<DigitalAxis>() {
	}
	virtual ~DigitalAxisNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx);
};

class ColorAxisNode: public AnyAxisNode<ColorAxis> {
public:
	ColorAxisNode() :
			AnyAxisNode<ColorAxis>() {
	}
	virtual ~ColorAxisNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx);
};

class XAxisNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	XAxisNode() :
			AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["timeAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new TimeAxisNode());
		getChildList()["epochAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new EpochAxisNode());
		getChildList()["digitalAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new DigitalAxisNode());
	}
	virtual ~XAxisNode() {

	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx);

};

class YAxisNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	YAxisNode() :
			AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["digitalAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new DigitalAxisNode());
	}
	virtual ~YAxisNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx);
};

class ZAxisNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	ZAxisNode() :
			AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["colorAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new ColorAxisNode());
	}
	virtual ~ZAxisNode() {
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx);
};

class AxesNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	AxesNode() :
			AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["xAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new XAxisNode());
		getChildList()["yAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new YAxisNode());
		getChildList()["zAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr(
						new ZAxisNode());
	}
	virtual ~AxesNode() {
	}

};

} /* namespace plot */
#endif /* AXESNODE_HH_ */