AbstractPlotConfigNode.hh 2.84 KB
/*
 * AbstractPlotConfigNode.hh
 *
 *  Created on: Dec 10, 2013
 *      Author: amdadev
 */

#ifndef ABSTRACTPLOTCONFIGNODE_HH_
#define ABSTRACTPLOTCONFIGNODE_HH_

#include <libxml/tree.h>
#include <iosfwd>


#include "DefaultPlotConfiguration.hh"
#include "DrawingPropertiesNode.hh"
#include "FileConfigurator.hh"
#include "DrawingProperties.hh"
#include "LineNode.hh"
#include "NodeCfg.hh"
#include "SerieSymbolNode.hh"
#include "TimeTickNode.hh"
#include "IntervalTickNode.hh"
#include "ResamplingNode.hh"
#include "ErrorBarNode.hh"

namespace plot {
/**
 * base class that manage default configuration nodes for any type of plot.
 */
class AbstractPlotConfigNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	AbstractPlotConfigNode() : NodeGrpCfg(){
		getChildList()["line"] = AMDA::XMLConfigurator::NodeCfgSPtr(
							new LineNode<DrawingProperties>()	);
		getChildList()["symbol"] = AMDA::XMLConfigurator::NodeCfgSPtr(
						new SerieSymbolNode() );
		getChildList()["timeTick"] = AMDA::XMLConfigurator::NodeCfgSPtr(
						new TimeTickNode() );
		getChildList()["intervalTick"] = AMDA::XMLConfigurator::NodeCfgSPtr(
								new IntervalTickNode() );
		getChildList()["resampling"] = AMDA::XMLConfigurator::NodeCfgSPtr(
								new ResamplingNode() );
		getChildList()["errorBar"] = AMDA::XMLConfigurator::NodeCfgSPtr(
								new ErrorBarNode() );
	}
	virtual ~AbstractPlotConfigNode(){
	}

	void proceed(xmlNodePtr pNode_,const AMDA::Parameters::CfgContext& ctx_){
		LOG4CXX_DEBUG(gLogger, "AbstractPlotConfigNode::proceed");
		DefaultPlotConfiguration* pConfig = ctx_.get<DefaultPlotConfiguration*>();
		// initialize drawing properties object:
		DrawingProperties props;

		// parse node attributes
		parseAttributes(pNode_, props);

		// proceed children
		AMDA::Parameters::CfgContext childContext;
		childContext.push<DrawingProperties*>( &props );
		AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode_, childContext);

		pConfig->_defaultDrawingProperties[getNodeName()]=props;

	}

protected:
	virtual const std::string& getNodeName()=0;

	virtual void parseAttributes(xmlNodePtr pNode_, DrawingProperties& props_){

		// attribute
		xmlChar* value = NULL;
		// -- xAxis information
		value = xmlGetProp(pNode_, (const xmlChar *) "xAxis");
		if( value ){
			props_.setXAxisId(std::string((const char*)value));
			xmlFree(value);
		}
		// -- yAxis information
		value = xmlGetProp(pNode_, (const xmlChar *) "yAxis");
		if( value ){
			props_.setYAxisId(std::string((const char*)value));
			xmlFree(value);
		}
		// -- yAxis information
		value = xmlGetProp(pNode_, (const xmlChar *) "zAxis");
		if( value ){
				props_.setZAxisId(std::string((const char*)value));
				xmlFree(value);
		}
		// -- default color
		updateColor(props_.getColor(), pNode_, (const xmlChar *)"color", (const xmlChar *)"colorMapIndex");
	}

};


} /* namespace plot */

#endif /* ABSTRACTPLOTCONFIGNODE_HH_ */