IntervalsNode.hh 3.83 KB
/*
 * IntervalsNode.hh
 *
 *  Created on: Feb 4, 2019
 *      Author: AKKA
 */

#ifndef INTERVALSNODE_HH_
#define INTERVALSNODE_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 "IntervalsProperties.hh"

namespace plot {
/**
 * Class that handle a <intervals> xml node.
 * Template class that should be instanciated for each subclass of PanelOutputPanel.
 */

template<class PlotType>
class IntervalsNode: public plot::DrawingPropertiesNode<PlotType> {
public:
	IntervalsNode():
		DrawingPropertiesNode<PlotType>() {
	}
	virtual ~IntervalsNode() {
	}

	void proceed(xmlNodePtr pNode_,const AMDA::Parameters::CfgContext& pContext_) {
		LOG4CXX_DEBUG(gLogger, "IntervalsNode::proceed");
		PlotType* plotOutput = pContext_.get<PlotType*>();
		xmlChar* name = pContext_.get<xmlChar*>();

		// initialize intervals with default properties
		DrawingProperties defaultProps = plotOutput->getParameter(
				(const char*) name).getDefaultProperties();

		// read parent attributes
		DrawingPropertiesNode<PlotType>::parseAttributes(pNode_, defaultProps);

		// intervals properties
		std::shared_ptr<IntervalsProperties> intervalsPropsPtr =
				std::shared_ptr<IntervalsProperties>(new IntervalsProperties(defaultProps));

		// read index definition
		xmlChar * value = NULL;

		value = xmlGetProp(pNode_, (const xmlChar*) "index");
		if (value) {
			intervalsPropsPtr->setIndexDef((const char*) value);
			xmlFree(value);
		}
		// -- color
		Color color(255, 0, 0);
		value = xmlGetProp(pNode_, (const xmlChar *)"color");
		if (value)
		{
			try
			{
				std::string strValue((const char *)value);
				createColor(color, strValue);
			}
			catch (std::logic_error &e)
			{
				LOG4CXX_WARN(gLogger, "Intervals Color : " << e.what());
			}
			xmlFree(value);
		}
		intervalsPropsPtr->setColor(color);
		// add intervals definition to parameter
		plotOutput->getParameter((const char*)name).addIntervalsProperties(intervalsPropsPtr);

		// -- Position
		value = xmlGetProp(pNode_, (const xmlChar *)"position");
		if (value)
		{
			try
			{
				std::string strValue((const char *)value);
				if (strValue == "right")
				{
					intervalsPropsPtr->setPosition("POS_RIGHT");
				}
				else if (strValue == "left")
				{
					intervalsPropsPtr->setPosition("POS_RIGHT");
				}
				else if (strValue == "top")
				{
					intervalsPropsPtr->setPosition("POS_TOP");
				}
				else if (strValue == "bottom")
				{
					intervalsPropsPtr->setPosition("POS_BOTTOM");
				}
				else
					intervalsPropsPtr->setPosition("POS_RIGHT");
			}
			catch (std::logic_error &e)
			{
				LOG4CXX_WARN(gLogger, "Intervals Legend position : " << e.what());
			}
			xmlFree(value);
		}
		else
		{
			intervalsPropsPtr->setPosition("POS_RIGHT");
		}
		// -- text
		value = xmlGetProp(pNode_, (const xmlChar *)"text");
		if (value)
		{
			intervalsPropsPtr->setText((const char *)value);
			// label->_text = (const char *)value;
			xmlFree(value);
		}
		// -- font name
		Font labelFont("sans-serif", 10);
		value = xmlGetProp(pNode_, (const xmlChar *)"fontName");
		if (value)
		{
			labelFont.setName((const char *)value);
			xmlFree(value);
		}

		// -- font size
		value = xmlGetProp(pNode_, (const xmlChar *)"fontSize");
		if (value)
		{

			labelFont.setSize(atoi((const char *)value));
			xmlFree(value);
		}

		// -- font style
		value = xmlGetProp(pNode_, (const xmlChar *)"fontStyle");
		if (value)
		{
			labelFont.setStyle(Font::getStyleByStr((const char *)value));
			xmlFree(value);
		}

		// -- font weight
		value = xmlGetProp(pNode_, (const xmlChar *)"fontWeight");
		if (value)
		{
			labelFont.setWeight(Font::getWeightByStr((const char *)value));
			xmlFree(value);
		}

		intervalsPropsPtr->setFont(labelFont);
	}
};

}
/* namespace plot */

#endif /* INTERVALSNODE_HH_ */