Blame view

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

#include "PageNode.hh"
#include "PanelNode.hh"
#include "PlotLogger.hh"
#include "Page.hh"
#include "PlotOutput.hh"
#include "Constant.hh"
#include "CommonNode.hh"
#include "LayoutNode.hh"
#include "PlotOutput.hh"
#include "DefaultPlotConfiguration.hh"

namespace plot {

PageNode::PageNode() :
		NodeGrpCfg() {
	getChildList()["title"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new TitleNode<Page>());
	getChildList()["margin"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new MarginNode());
	getChildList()["font"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new FontNode<Page>());
	getChildList()["layout"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new LayoutNode());
	getChildList()["panelDefaults"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new PanelDefaultNode());
	getChildList()["panel"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new PanelNode());
}

PageNode::~PageNode() {
}

void PageNode::proceed(xmlNodePtr pNode,
		const AMDA::Parameters::CfgContext& pContext) {
	LOG4CXX_DEBUG(gLogger, "PageNode::proceed");
	boost::shared_ptr<Page> page(
			new Page(DefaultPlotConfiguration::getInstance()));

	xmlChar* value = NULL;

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

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

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

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

	// -- defaultTimePlotWidth
	value = xmlGetProp(pNode, (const xmlChar *) "defaultTimePlotWidth");
	if (value) {
		page->_defaultTimePlotWidth = std::stod((const char*) value);
		xmlFree(value);
	}

	// -- defaultTimePlotHeight
	value = xmlGetProp(pNode, (const xmlChar *) "defaultTimePlotHeight");
	if (value) {
		page->_defaultTimePlotHeight = std::stod((const char*) value);
		xmlFree(value);
	}

	// -- defaultTimePlotXMargin
	value = xmlGetProp(pNode, (const xmlChar *) "defaultTimePlotXMargin");
	if (value) {
		int margin1, margin2;
		extractMargins ((const char*) value, &margin1, &margin2);
		page->_defaultTimePlotLeftMargin = margin1;
		page->_defaultTimePlotRightMargin = margin2;
		xmlFree(value);
	}

	// -- defaultTimePlotYMargin
	value = xmlGetProp(pNode, (const xmlChar *) "defaultTimePlotYMargin");
	if (value) {
		int margin1, margin2;
		extractMargins ((const char*) value, &margin1, &margin2);
		page->_defaultTimePlotTopMargin = margin1;
		page->_defaultTimePlotBottomMargin = margin2;
		xmlFree(value);
	}

	// -- defaultXYPlotWidth
	value = xmlGetProp(pNode, (const xmlChar *) "defaultXYPlotWidth");
	if (value) {
		page->_defaultXYPlotWidth = std::stod((const char*) value);
		xmlFree(value);
	}

	// -- defaultXYPlotHeight
	value = xmlGetProp(pNode, (const xmlChar *) "defaultXYPlotHeight");
	if (value) {
		page->_defaultXYPlotHeight = std::stod((const char*) value);
		xmlFree(value);
	}

	// -- defaultXYPlotXMargin
	value = xmlGetProp(pNode, (const xmlChar *) "defaultXYPlotXMargin");
	if (value) {
		int margin1, margin2;
		extractMargins ((const char*) value, &margin1, &margin2);
		page->_defaultXYPlotLeftMargin = margin1;
		page->_defaultXYPlotRightMargin = margin2;
		xmlFree(value);
	}

	// -- defaultXYPlotYMargin
	value = xmlGetProp(pNode, (const xmlChar *) "defaultXYPlotYMargin");
	if (value) {
		int margin1, margin2;
		extractMargins ((const char*) value, &margin1, &margin2);
		page->_defaultXYPlotTopMargin = margin1;
		page->_defaultXYPlotBottomMargin = margin2;
		xmlFree(value);
	}

	// -- superposeMode
	value = xmlGetProp(pNode, (const xmlChar *) "superposeMode");
	if (value) {
		page->_superposeMode = (strcasecmp ((const char*)value, "true") == 0);
		xmlFree(value);
	}

	AMDA::Parameters::CfgContext context;
	PlotOutput* plotOutput = pContext.get<PlotOutput*>();
	plotOutput->setPage(boost::shared_ptr<Page>(page));
	context.push<Page*>(page.get());
	context.push<PlotOutput*>(pContext.get<PlotOutput*>());
	context.push<AMDA::Parameters::ParameterManager*>(
			pContext.get<AMDA::Parameters::ParameterManager*>());

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

PanelDefaultNode::PanelDefaultNode() :
		NodeGrpCfg() {
	getChildList()["font"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new FontNode<Panel>());
}

PanelDefaultNode::~PanelDefaultNode() {
}

void PanelDefaultNode::proceed(xmlNodePtr pNode,
		const AMDA::Parameters::CfgContext& /*pContext*/) {
	LOG4CXX_DEBUG(gLogger, "PanelDefaultNode::proceed");

	xmlChar* value = NULL;

	// -- resolution
	if ((value = xmlGetProp(pNode, (const xmlChar *) "resolution"))) {
		DefaultPlotConfiguration::getInstance()._defaultPanel._resolution =
				atoi((const char*) value);
		xmlFree(value);
	}

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

	// -- color map index
	value = xmlGetProp(pNode, (const xmlChar *) "colorMapIndex");
	if (value) {
		DefaultPlotConfiguration::getInstance()._defaultPanel._backgroundColor._colorMapIndex =
				atoi((const char*) value);
		xmlFree(value);
	}

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

} /* namespace plot */