EpochPlotNode.cc 2.58 KB
/*
 * EpochPlotNode.cc
 *
 *  Created on: Jan 16, 2015
 *      Author: AKKA
 */


#include "TimePlotNode.hh"
#include "PanelPlotNodeRegistry.hh"
#include "EpochPlot.hh"
#include "AxesNode.hh"
#include "PlotLogger.hh"
#include "ParamsNode.hh"
#include "PlotOutput.hh"
#include "PlotLegendNode.hh"
#include "NodeCfg.hh"

namespace plot {


const std::string EpochPlotNode::NODENAME = EPOCHPLOT_NODENAME;

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

/**
 * default constructor implementation.
 */

EpochPlotNode::EpochPlotNode() :
		AbstractPanelPlotNode() {
	getChildList()["legends"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new PlotLegendNode());
	getChildList()["params"] = AMDA::XMLConfigurator::NodeCfgSPtr(
			new ParamsNode<EpochPlot>());
	getChildList()["axes"] = AMDA::XMLConfigurator::NodeCfgSPtr(new AxesNode());
}

EpochPlotNode::~EpochPlotNode() {

}

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

	LOG4CXX_DEBUG(gLogger, "EpochPlotNode::proceed");

	boost::shared_ptr<EpochPlot> plot(
			new EpochPlot(plotManager_->getParameterManager(),
					boost::shared_ptr<Panel>(panel_)));

	// Get centerTimeId
	xmlChar* value = NULL;
	if ((value = xmlGetProp(pNode_, (const xmlChar *) "centerTimeId"))) {
		plot->setCenterTimeId(std::string((const char*) value));
		xmlFree(value);
	}
	else
	{
		LOG4CXX_ERROR(gLogger, "EpochPlotNode::proceed - centerTimeId not defined");
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("centerTimeId not defined for epochPlot"));
	}

	// Copy default pages values for the panel if not already specified
	if (panel_->_leftMargin == -1)
		panel_->_leftMargin = panel_->_page->_defaultTimePlotLeftMargin;
	if (panel_->_rightMargin == -1)
		panel_->_rightMargin = panel_->_page->_defaultTimePlotRightMargin;
	if (panel_->_topMargin == -1)
		panel_->_topMargin = panel_->_page->_defaultTimePlotTopMargin;
	if (panel_->_bottomMargin == -1)
		panel_->_bottomMargin = panel_->_page->_defaultTimePlotBottomMargin;

	if (panel_->_preferedWidth == -1)
		panel_->_preferedWidth = panel_->_page->_defaultTimePlotWidth;
	if (panel_->_preferedHeight == -1)
		panel_->_preferedHeight = panel_->_page->_defaultTimePlotHeight;

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

	return plot;
}

}  // namespace plot