HistogramSeriesNode.hh
4.27 KB
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
/*
* HistogramSeriesNode.hh
*
* Created on: Jan 27, 2023
* Author: AKKODIS
*/
#ifndef HISTOGRAMSERIESNODE_HH_
#define HISTOGRAMSERIESNODE_HH_
#include <libxml/globals.h>
#include <libxml/tree.h>
#include <libxml/xmlstring.h>
#include <iosfwd>
#include "FileConfigurator.hh"
#include "DrawingPropertiesNode.hh"
#include "PlotLogger.hh"
#include "NodeCfg.hh"
#include "HistogramSeriesProperties.hh"
namespace plot {
/**
* Class that handle a <histogram1d> and <histogram2d> xml node.
* Template class that should be instanciated for each subclass of PanelOutputPanel.
*/
template<class PlotType>
class HistogramSeriesNode: public plot::DrawingPropertiesNode<PlotType> {
public:
HistogramSeriesNode(std::string histogramType) :
DrawingPropertiesNode<PlotType>(),
_histogramType(histogramType) {
DrawingPropertiesNode<PlotType>::getChildList()["bins"] = AMDA::XMLConfigurator::NodeCfgSPtr(new BinsNode(histogramType));
DrawingPropertiesNode<PlotType>::getChildList()["histotype"] = AMDA::XMLConfigurator::NodeCfgSPtr(new HistotypeNode(histogramType));
}
virtual ~HistogramSeriesNode() {
}
void proceed(xmlNodePtr pNode_,
const AMDA::Parameters::CfgContext& pContext_) {
LOG4CXX_DEBUG(gLogger, "HistogramSeriesNode::proceed - " );
PlotType* plotOutput = pContext_.get<PlotType*>();
xmlChar* name = pContext_.get<xmlChar*>();
// initialize series with default properties
DrawingProperties defaultProps = plotOutput->getParameter(
(const char*) name).getDefaultProperties();
std::shared_ptr<HistogramSeriesProperties> histogramPropsPtr =
std::shared_ptr<HistogramSeriesProperties>(new HistogramSeriesProperties(defaultProps,_histogramType));
// parse attributes...
parseAttributes(pNode_, *histogramPropsPtr.get());
// add series definition to parameter
histogramPropsPtr->setParamId((const char*)name);
plotOutput->getParameter((const char*) name).addHistogramSeriesProperties(histogramPropsPtr);
//parse children nodes
AMDA::Parameters::CfgContext context;
context.push<xmlChar*>(name);
context.push<HistogramSeriesProperties*>(histogramPropsPtr.get());
context.push<DrawingProperties*>(histogramPropsPtr.get());
AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode_, context);
}
protected:
void parseAttributes(xmlNodePtr pNode_, DrawingProperties& props_) {
// read parent attributes
DrawingPropertiesNode<PlotType>::parseAttributes(pNode_, props_);
// specific series node attributes :
xmlChar * value = NULL;
value = xmlGetProp(pNode_, (const xmlChar*) "index");
if (value) {
AMDA::Common::ParameterIndexComponentList indexList;
if (!AMDA::Common::ParameterIndexesTool::parse((const char*) value, -1, -1, indexList) || indexList.empty())
{
LOG4CXX_ERROR(gLogger, "HistogramSeriesNode::parseAttributes - Bad index definition " << (const char*) value);
xmlFree(value);
BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("Bad HistogramSerieNode index definition"));
}
((HistogramSeriesProperties&) props_).setIndex(indexList.front());
xmlFree(value);
} else {
((HistogramSeriesProperties&) props_).setIndex(AMDA::Common::ParameterIndexComponent(-1,-1)); // default case: if no index attribute, we use default index value -1 which means for all series.
}
value = xmlGetProp(pNode_, (const xmlChar*) "id");
if (value) {
((HistogramSeriesProperties&) props_).setId(atoi((const char*) value));
xmlFree(value);
}
// only available for 1D histo
if(_histogramType == "histogram1d"){
// -- color
Color color(0, 255, 0);
value = xmlGetProp(pNode_, (const xmlChar *)"color");
if (value)
{
try
{
std::string strValue((const char *)value);
createColor(color, strValue);
((HistogramSeriesProperties &)props_).setColor(color);
}
catch (std::logic_error &e)
{
LOG4CXX_WARN(gLogger, "Histogram1D Color : " << e.what());
}
xmlFree(value);
}
}
// only available for 2D histo
if(_histogramType == "histogram2d"){
// -- associated x serie id
value = xmlGetProp(pNode_, (const xmlChar*) "xId");
if (value) {
((HistogramSeriesProperties&) props_).setXId(atoi((const char*) value));
xmlFree(value);
}
}
}
std::string _histogramType;
};
/* namespace plot */
}
#endif /* HISTOGRAMSERIESNODE_HH_ */