Blame view

src/ParamOutputImpl/Plot/LineNode.hh 2.19 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
/**
 * LineNode.hh
 *
 *  Created on: Dec 2, 2013
 *      Author: amdadev
 */

#ifndef LINENODE_HH_
#define LINENODE_HH_

#include <libxml/tree.h>
#include <iosfwd>

#include "NodeCfg.hh"
#include "PlotLogger.hh"
#include "SeriesProperties.hh"
#include "CommonNode.hh"



namespace plot {


/**
 * Read a 'line' tag from xml request and populate related plot::SerieProperties
 * object (which is object holding drawing properties for that parameter's serie).
 * structure of xml node to read is defined in the plot.xsd schemas.
 */
template<class LineType>
class LineNode: public AMDA::XMLConfigurator::NodeCfg {
public:

	LineNode() : AMDA::XMLConfigurator::NodeCfg(){};

	virtual ~LineNode(){};

	void proceed(xmlNodePtr pNode_,const AMDA::Parameters::CfgContext& pContext_){
		LOG4CXX_DEBUG(gLogger, "LineNode::proceed");

		LineType* props = pContext_.get<LineType*>();
		// read attributes :
		xmlChar* value = NULL;

		// TODO see if we have some default config values to retrieve...

		// overwrites default values if any...
		// type
		value = xmlGetProp(pNode_, (const xmlChar *)"type");
		if( value ){
			try{
				props->getLineProperties().setType( stoLineType.at(std::string((const char*)value)) );
			}
			catch( std::out_of_range& err ){
				std::ostringstream msg {};
				msg << "LineNode::proceed invalid LineType value:" << value <<". Using default value.";
				LOG4CXX_DEBUG(gLogger, msg.str());
			}
			xmlFree(value);
		}

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

		// width
		value = xmlGetProp(pNode_, (const xmlChar *)"width");
		if( value ){
			props->getLineProperties().setWidth( atoi((const char*)value) );
			xmlFree(value);
		}

		// color attributes :
		updateColor(props->getLineProperties().getColor(), pNode_, (const xmlChar *)"color", (const xmlChar *)"colorMapIndex");
	}

};

} /* namespace plot */

#endif /* LINENODE_HH_ */