XYPlotNode.cc 2.52 KB
/*
 * XYPlotNode.cc
 *
 *  Created on: Dec 6, 2013
 *      Author: amdadev
 */

#include "XYPlotNode.hh"
#include "PlotLogger.hh"
#include "PanelPlotNodeRegistry.hh"
#include "XYPlot.hh"
#include "AxesNode.hh"
#include "AdditionalObjectsNode.hh"
#include "PlotLegendNode.hh"

namespace plot {

const std::string XYPlotNode::NODENAME = XYPLOT_NODENAME;

std::string XYPlotNode::_key = PanelPlotNodeRegistry::getInstance().addElement(
		NODENAME, boost::shared_ptr<XYPlotNode>(new XYPlotNode()));

XYPlotNode::XYPlotNode() :
		AbstractPanelPlotNode() {
	getChildList()["legends"] = AMDA::XMLConfigurator::NodeCfgSPtr(
				new PlotLegendNode());
	getChildList()["params"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new XYPlotParamsNode<XYPlot>());
	getChildList()["axes"] = AMDA::XMLConfigurator::NodeCfgSPtr(new AxesNode());
	getChildList()["additionalObjects"] = AMDA::XMLConfigurator::NodeCfgSPtr(new AdditionalObjectsNode());
}

XYPlotNode::~XYPlotNode() {
}

boost::shared_ptr<PanelPlotOutput> XYPlotNode::proceed(xmlNodePtr pNode_,
		PlotOutput* plotManager_, Panel* panel_) {

	LOG4CXX_DEBUG(gLogger, "XYPlotNode::proceed");
	boost::shared_ptr<XYPlot> plot(
			new XYPlot(plotManager_->getParameterManager(),
					boost::shared_ptr<Panel>(panel_)));

	// Copy default pages values for the panel if not already specified
	if (panel_->_leftMargin == -1)
		panel_->_leftMargin = panel_->_page->_defaultXYPlotLeftMargin;
	if (panel_->_rightMargin == -1)
		panel_->_rightMargin = panel_->_page->_defaultXYPlotRightMargin;
	if (panel_->_topMargin == -1)
		panel_->_topMargin = panel_->_page->_defaultXYPlotTopMargin;
	if (panel_->_bottomMargin == -1)
		panel_->_bottomMargin = panel_->_page->_defaultXYPlotBottomMargin;

	if (panel_->_preferedWidth == -1)
		panel_->_preferedWidth = panel_->_page->_defaultXYPlotWidth;
	if (panel_->_preferedHeight == -1)
		panel_->_preferedHeight = panel_->_page->_defaultXYPlotHeight;

	// -- read isotropic attribute
	xmlChar* value;

	value = xmlGetProp(pNode_, (const xmlChar *) "isotropic");
	if (value) {
		std::string strValue((const char*) value);
		std::transform(strValue.begin(), strValue.end(), strValue.begin(),
				::tolower);
		std::istringstream is(strValue);
		bool isIsotropic;
		is >> std::boolalpha >> isIsotropic;
		plot->_isIsotropic = isIsotropic;
		xmlFree(value);
	}

	AMDA::Parameters::CfgContext context;
	context.push<PanelPlotOutput*>(plot.get());
	context.push<XYPlot*>(plot.get());
	context.push<Panel*>(panel_);
	AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode_, context);

	return plot;
}

} /* namespace plot */