PlotLegendNode.cc 6.36 KB
/*
 * PlotLegendNode.cc
 *
 *  Created on: Sep 22, 2014
 *      Author: AKKA
 */


#ifndef PLOTLEGENDNODE_CC_
#define PLOTLEGENDNODE_CC_

#include "PlotLegendNode.hh"

#include "PlotLogger.hh"
#include "NodeCfg.hh"
#include "Panel.hh"
#include "Page.hh"
#include "CommonNode.hh"

namespace plot {

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

ParamsLegendNode::~ParamsLegendNode()
{
}

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

	Panel* panel = pContext_.get<Panel *>();
	ParamsLegendProperties& paramsLegendProperties = panel->_paramsLegendProperties;

	paramsLegendProperties.setIsVisible(true);

	xmlChar* value;

	// -- type
	if ((value = xmlGetProp(pNode_, (const xmlChar *) "type")))
	{
		if (strcmp ((const char *) value, "text-line-symbol") == 0)
			paramsLegendProperties.setOnlyText(false);
		else if (strcmp ((const char *) value, "text-only") == 0)
			paramsLegendProperties.setOnlyText(true);
		else
		{
			LOG4CXX_DEBUG(gLogger, "ParamsLegendNode::proceed - type " << value << "not implemented => set to text-line-symbol mode");
			paramsLegendProperties.setOnlyText(false);
		}
		xmlFree(value);
	}

	// -- showParamInfo
	if ((value = xmlGetProp(pNode_, (const xmlChar *) "showParamInfo")))
	{
		paramsLegendProperties.setParamInfoVisible(strcmp ((const char *) value, "true") == 0);
		xmlFree(value);
	}
	else
		paramsLegendProperties.setParamInfoVisible(true);

	// -- showIntervalInfo
	if ((value = xmlGetProp(pNode_, (const xmlChar *) "showIntervalInfo")))
	{
		paramsLegendProperties.setIntervalInfoVisible(strcmp ((const char *) value, "true") == 0);
		xmlFree(value);
	}
	else
		paramsLegendProperties.setIntervalInfoVisible(panel->_page->_superposeMode);

	if (paramsLegendProperties.isIntervalInfoVisible())
	{
		// -- intervalInfoType
		if ((value = xmlGetProp(pNode_, (const xmlChar *) "intervalInfoType")))
		{
			if (strcmp ((const char *) value, "start-stop") == 0)
			{
				paramsLegendProperties.setIntervalInfoType(ParamsLegendProperties::IntervalInfoType::STARTSTOP);
			}
			else
				paramsLegendProperties.setIntervalInfoType(ParamsLegendProperties::IntervalInfoType::INDEX);
			xmlFree(value);
		}
	}

	// -- position
	if ((value = xmlGetProp(pNode_, (const xmlChar *) "position")))
	{
		if (strcmp ((const char *) value, "inside") == 0)
			paramsLegendProperties.setPosition(ParamsLegendPosition::POS_INSIDE);
		else if (strcmp ((const char *) value, "outside") == 0)
			paramsLegendProperties.setPosition(ParamsLegendPosition::POS_OUTSIDE);
		else
		{
			LOG4CXX_DEBUG(gLogger, "ParamsLegendNode::proceed - position " << value << "not implemented => set to inside");
			paramsLegendProperties.setPosition(ParamsLegendPosition::POS_INSIDE);
		}
		xmlFree(value);
	}

	// -- defaultTextColor
	Color textColor(0,0,0);
	updateColor(textColor, pNode_, (const xmlChar *)"defaultTextColor", (const xmlChar *)"defaultTextColorMapIndex");
	paramsLegendProperties.setDefaultTextColor(textColor);

	// -- borderVisible
	if ((value = xmlGetProp(pNode_, (const xmlChar *) "borderVisible")))
	{
		paramsLegendProperties.setIsBorderVisible(strcmp ((const char *) value, "true") == 0);
		xmlFree(value);
	}
	else
		paramsLegendProperties.setIsBorderVisible(false);

	// -- borderColor
	Color borderColor(0,0,0);
	updateColor(borderColor, pNode_, (const xmlChar *)"borderColor", (const xmlChar *)"borderColorMapIndex");
	paramsLegendProperties.setBorderColor(borderColor);

	//init with panel font
	paramsLegendProperties.setFont(panel->_font);

	AMDA::Parameters::CfgContext context;
	context.push<ParamsLegendProperties*>(&paramsLegendProperties);
	AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode_, context);
}

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

TextLegendNode::~TextLegendNode()
{
}

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

	Panel* panel = pContext_.get<Panel *>();

	boost::shared_ptr<TextLegendProperties> pTextLegendProperties (new TextLegendProperties());

	xmlChar* value;

	// -- text
	if ((value = xmlGetProp(pNode_, (const xmlChar *) "text")))
	{
		pTextLegendProperties->setText((const char *) value);
		xmlFree(value);
	}

	// -- position
	if ((value = xmlGetProp(pNode_, (const xmlChar *) "position")))
	{
		if (strcasecmp ((const char *) value, "left") == 0)
			pTextLegendProperties->setPosition(TextLegendPosition::POS_LEFT);
		else if (strcmp ((const char *) value, "right") == 0)
			pTextLegendProperties->setPosition(TextLegendPosition::POS_RIGHT);
		else if (strcmp ((const char *) value, "top") == 0)
			pTextLegendProperties->setPosition(TextLegendPosition::POS_TOP);
		else if (strcmp ((const char *) value, "bottom") == 0)
			pTextLegendProperties->setPosition(TextLegendPosition::POS_BOTTOM);
		else
		{
			LOG4CXX_DEBUG(gLogger, "TextLegendNode::proceed - position " << value << "not implemented => set to RIGHT");
			pTextLegendProperties->setPosition(TextLegendPosition::POS_RIGHT);
		}
		xmlFree(value);
	}

	// -- color
	updateColor(pTextLegendProperties->getColor(), pNode_, (const xmlChar *)"color", (const xmlChar *)"colorMapIndex");

	//init with panel font
	pTextLegendProperties->setFont(panel->_font);

	panel->_textLegendPropertiesList.push_back(pTextLegendProperties);

	AMDA::Parameters::CfgContext context;
	context.push<TextLegendProperties*>(pTextLegendProperties.get());

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

PlotLegendNode::PlotLegendNode() : AMDA::XMLConfigurator::NodeGrpCfg()
{
	getChildList()["paramsLegend"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new ParamsLegendNode());
	getChildList()["textLegend"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new TextLegendNode());
}

PlotLegendNode::~PlotLegendNode()
{
}

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

	AMDA::Parameters::CfgContext context;
	context.push<Panel*>(panel);
	AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode_, context);
}

} /* namespace plot */

#endif /* PARAMSLEGENDNODE_CC_ */