AxesNode.cc 4.77 KB
/*
 * AxesNode.cc
 *
 *  Created on: 26 nov. 2013
 *      Author: CS
 */

#include "AxesNode.hh"
#include "Panel.hh"
#include "DefaultPlotConfiguration.hh"

namespace plot {

void TimeAxisNode::proceed(xmlNodePtr pNode,
		const AMDA::Parameters::CfgContext& pCtx) {
	Panel* panel = pCtx.get<Panel*>();
	TimeAxis* axis = new TimeAxis(
			*DefaultPlotConfiguration::getInstance().getDefaultTimeAxis());

	// read dedicated attributes
	xmlChar* value = NULL;
	// -- axis id
	value = xmlGetProp(pNode, (const xmlChar *) "id");
	if (value && std::string((const char*)value).size() != 0) {
		axis->_id = (const char*) value;
		xmlFree(value);
	}
// Let default configuration of TimeAxis
// else {
//		axis->_id = DefaultPlotConfiguration::TIME_DEFAULT_ID;
//	}
	panel->addAxis(axis->_id, boost::shared_ptr<Axis>(axis));

	// -- time format type
	value = xmlGetProp(pNode, (const xmlChar *) "format");
	if (value) {
		axis->_timeFormat = (const char*) value;
		xmlFree(value);
	}

	AMDA::Parameters::CfgContext context;
	context.push<TimeAxis*>(axis);
	context.push<Panel*>(panel);

	AnyAxisNode<TimeAxis>::proceed(pNode, context);
}

void EpochAxisNode::proceed(xmlNodePtr pNode,
		const AMDA::Parameters::CfgContext& pCtx) {
	Panel* panel = pCtx.get<Panel*>();
	EpochAxis* axis = new EpochAxis(
			*DefaultPlotConfiguration::getInstance().getDefaultEpochAxis());

	// read dedicated attributes
	xmlChar* value = NULL;
	// -- axis id
	value = xmlGetProp(pNode, (const xmlChar *) "id");
	if (value && std::string((const char*)value).size() != 0) {
		axis->_id = (const char*) value;
	}
	if (value != NULL)
		xmlFree(value);

	// -- normalized
	value = xmlGetProp(pNode, (const xmlChar *) "normalized");
	if (value != NULL)
	{
		axis->setNormalized(strcmp((char*)value,"true") == 0);
		xmlFree(value);
	}

	panel->addAxis(axis->_id, boost::shared_ptr<Axis>(axis));

	AMDA::Parameters::CfgContext context;
	context.push<EpochAxis*>(axis);
	context.push<Panel*>(panel);

	AnyAxisNode<EpochAxis>::proceed(pNode, context);
}

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

	DigitalAxis* axis = new DigitalAxis(
			strcmp((const char *)tagName, (const char *)"xAxis") == 0 ?
					*DefaultPlotConfiguration::getInstance().getDefaultXAxis() :
					*DefaultPlotConfiguration::getInstance().getDefaultYAxis());
	// read dedicated attributes
	xmlChar* value = NULL;

	// -- axis id
	value = xmlGetProp(pNode, (const xmlChar *) "id");
	if (value) {
		axis->_id = (const char*) value;
		xmlFree(value);
	}
	panel->addAxis(axis->_id, boost::shared_ptr<Axis>(axis));

	AMDA::Parameters::CfgContext context;
	context.push<DigitalAxis*>(axis);
	context.push<Panel*>(panel);
	AnyAxisNode<DigitalAxis>::proceed(pNode, context);
}

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

	ColorAxis* axis = new ColorAxis(
			*DefaultPlotConfiguration::getInstance().getDefaultColorAxis());

	xmlChar * value = NULL;
	Color color;
	std::string colorStr;

	// -- minValColor - all value lower than this value will be draw with this color
	value = xmlGetProp(pNode, (const xmlChar *) "minValColor");
	if( value ) {
		colorStr = (const char*)value;
		createColor(color, colorStr);
		axis->setMinValColor(color);
		xmlFree(value);
	}

	// -- maxValColor - all value greater than this value will be draw with this color
	value = xmlGetProp(pNode, (const xmlChar *) "maxValColor");
	if( value ) {
		colorStr = (const char*)value;
		createColor(color, colorStr);
		axis->setMaxValColor(color);
		xmlFree(value);
	}

	panel->addColorAxis(axis->_id, boost::shared_ptr<ColorAxis>(axis));

	AMDA::Parameters::CfgContext context;
	context.push<ColorAxis*>(axis);
	context.push<Panel*>(panel);
	AnyAxisNode<ColorAxis>::proceed(pNode, context);
}

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

	AMDA::Parameters::CfgContext context;
	context.push<Panel*>(panel);
	context.push<const xmlChar*>(pNode->name);
	NodeGrpCfg::proceed(pNode, context);
}

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

	AMDA::Parameters::CfgContext context;
	context.push<Panel*>(panel);
	context.push<const xmlChar*>(pNode->name);
	NodeGrpCfg::proceed(pNode, context);
}

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

	AMDA::Parameters::CfgContext context;
	context.push<Panel*>(panel);
	context.push<const xmlChar*>(pNode->name);
	NodeGrpCfg::proceed(pNode, context);
}

}