Blame view

src/ParamOutputImpl/Plot/PanelNode.cc 4.47 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
/*
 * PanelNode.cc
 *
 *  Created on: 29 oct. 2013
 *      Author: CS
 */

#include "PanelNode.hh"
#include "PlotLogger.hh"
#include "Panel.hh"
#include "Page.hh"
#include "DefaultPlotConfiguration.hh"
#include "CommonNode.hh"
#include "PanelPlotNodeRegistry.hh"
#include "ParamPlotNode.hh"

#include <stdlib.h>
#include <iosfwd>

namespace plot {

PanelNode::PanelNode() :
		NodeGrpCfg() {
	getChildList()["bounds"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new BoundsNode());
	getChildList()["font"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new FontNode<Panel>());
	getChildList()["title"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new TitleNode<Panel>());

	for( auto child : PanelPlotNodeRegistry::getInstance().getAllElements() ){
		getChildList()[child.first] = child.second;
	}

	// paramPlot node specify a plot node where plot type is set
	// in parameter id description (as a paramPlot node attribute)
	getChildList()["paramPlot"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new ParamPlotNode());

}

PanelNode::~PanelNode() {
}

void PanelNode::proceed(xmlNodePtr pNode,
		const AMDA::Parameters::CfgContext& pContext) {
	LOG4CXX_DEBUG(gLogger, "PanelNode::proceed");
	Page* page = pContext.get<Page*>();
	Panel* panel = new Panel(page);

	xmlChar* value = NULL;

85bb5117   Benjamin Renard   Give the possibil...
53
54
55
56
57
58
	// -- id
	if ((value = xmlGetProp(pNode, (const xmlChar *) "id"))) {
		panel->_id = atoi((const char*) value);
		xmlFree(value);
	}

fbe3c2bb   Benjamin Renard   First commit
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
	// -- resolution
	if ((value = xmlGetProp(pNode, (const xmlChar *) "resolution"))) {
		panel->_resolution = atoi((const char*) value);
		xmlFree(value);
	}

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

	// -- color map index
	value = xmlGetProp(pNode, (const xmlChar *) "colorMapIndex");
	if (value) {
		bgcolor._colorMapIndex = atoi((const char*) value);
		xmlFree(value);
	}
	panel->_backgroundColor = bgcolor;

	// -- Prefered panel width
	value = xmlGetProp(pNode, (const xmlChar *) "preferedWidth");
	if (value) {
		panel->_preferedWidth = std::stod((const char*) value);
		xmlFree(value);
	} else {
		panel->_preferedWidth = DefaultPlotConfiguration::getInstance()._defaultPanel._preferedWidth;
	}

	// -- Prefered panel height
	value = xmlGetProp(pNode, (const xmlChar *) "preferedHeight");
	if (value) {
		panel->_preferedHeight = std::stod((const char*) value);
		xmlFree(value);
	} else {
		panel->_preferedHeight = DefaultPlotConfiguration::getInstance()._defaultPanel._preferedHeight;
	}

	// -- xMargin
	value = xmlGetProp(pNode, (const xmlChar *) "xMargin");
	if (value) {
		int margin1, margin2;
		extractMargins ((const char*) value, &margin1, &margin2);
		panel->_leftMargin = margin1;
		panel->_rightMargin = margin2;
		xmlFree(value);
	}

	// -- yMargin
	value = xmlGetProp(pNode, (const xmlChar *) "yMargin");
	if (value) {
		int margin1, margin2;
		extractMargins ((const char*) value, &margin1, &margin2);
		panel->_topMargin = margin1;
		panel->_bottomMargin = margin2;
		xmlFree(value);
	}


	AMDA::Parameters::CfgContext context;
	//page->addPanel(panel);
	context.push<Panel*>(panel);
	context.push<PlotOutput*>(pContext.get<PlotOutput*>());
	context.push<AMDA::Parameters::ParameterManager*>(
			pContext.get<AMDA::Parameters::ParameterManager*>());

	AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode, context);
}

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

	xmlChar* value = NULL;

	Bounds bounds;

	// -- x position
	value = xmlGetProp(pNode, (const xmlChar *) "x");
	if (value) {
		bounds._x = atof((const char*) value);
		xmlFree(value);
	}

	// -- y position
	value = xmlGetProp(pNode, (const xmlChar *) "y");
	if (value) {
		bounds._y = atof((const char*) value);
		xmlFree(value);
	}

	// -- width
	value = xmlGetProp(pNode, (const xmlChar *) "width");
	if (value) {
		bounds._width = atof((const char*) value);
		xmlFree(value);
	}

	// -- height
	value = xmlGetProp(pNode, (const xmlChar *) "height");
	if (value) {
		bounds._height = atof((const char*) value);
		xmlFree(value);
	}

	panel->_bounds = bounds;
}

} /* namespace plot */