/* * AxesNode.hh * * Created on: 21 nov. 2013 * Author: CS */ #ifndef AXESNODE_HH_ #define AXESNODE_HH_ #include "NodeCfg.hh" #include "PlotLogger.hh" #include "CommonNode.hh" #include "TimeAxis.hh" #include "DigitalAxis.hh" #include "ColorAxis.hh" #include "EpochAxis.hh" #include "Panel.hh" namespace plot { template class RangeNode: public AMDA::XMLConfigurator::NodeCfg { public: RangeNode() : AMDA::XMLConfigurator::NodeCfg() { } virtual ~RangeNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "RangeNode::proceed"); AxisType* axis = pContext.get(); xmlChar* value = NULL; // -- min value = xmlGetProp(pNode, (const xmlChar *) "min"); double min = nan(""); if (value) { std::string text((const char*) value); std::string::size_type sz; min = std::stod(text, &sz); xmlFree(value); } // -- max value = xmlGetProp(pNode, (const xmlChar *) "max"); double max = nan(""); if (value) { std::string text((const char*) value); std::string::size_type sz; max = std::stod(text, &sz); xmlFree(value); } axis->setRequestedRange(min, max); // -- extend value = xmlGetProp(pNode, (const xmlChar *) "extend"); if (value) { std::string strValue((const char*) value); std::transform(strValue.begin(), strValue.end(), strValue.begin(), ::tolower); std::istringstream is(strValue); bool extend; is >> std::boolalpha >> extend; axis->setExtended(extend); xmlFree(value); } } }; template class TickNode: public AMDA::XMLConfigurator::NodeCfg { public: TickNode() : AMDA::XMLConfigurator::NodeCfg() { } virtual ~TickNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "TickNode::proceed"); AxisType* axis = pContext.get(); xmlChar* value = NULL; std::string valueStr; // -- major // search for attribute majorNumber or majorSpace value = xmlGetProp(pNode, (const xmlChar *) "majorNumber"); if (value) { valueStr = (const char*) value; axis->_tick.setMajorNumber(std::stod(valueStr, nullptr)); xmlFree(value); } else { value = xmlGetProp(pNode, (const xmlChar *) "majorSpace"); if (value) { valueStr = (const char*) value; axis->_tick.setMajorSpace(std::stod(valueStr, nullptr)); xmlFree(value); } } // -- minor // search for attribute minorNumber or minorSpace value = xmlGetProp(pNode, (const xmlChar *) "minorNumber"); if (value) { valueStr = (const char*) value; axis->_tick.setMinorNumber(std::stod(valueStr, nullptr)); xmlFree(value); } else { value = xmlGetProp(pNode, (const xmlChar *) "minorSpace"); if (value) { valueStr = (const char*) value; axis->_tick.setMinorSpace(std::stod(valueStr, nullptr)); xmlFree(value); } } // -- axis grid (for minor ticks) value = xmlGetProp(pNode, (const xmlChar *) "minorGrid"); if (value) { std::string strValue((const char*) value); std::transform(strValue.begin(), strValue.end(), strValue.begin(), ::tolower); std::istringstream is(strValue); bool isVisible; is >> std::boolalpha >> isVisible; axis->_tick._isMinorGridVisible = isVisible; xmlFree(value); } // -- axis grid (for major ticks) value = xmlGetProp(pNode, (const xmlChar *) "majorGrid"); if (value) { std::string strValue((const char*) value); std::transform(strValue.begin(), strValue.end(), strValue.begin(), ::tolower); std::istringstream is(strValue); bool isVisible; is >> std::boolalpha >> isVisible; axis->_tick._isMajorGridVisible = isVisible; xmlFree(value); } // -- tick position value = xmlGetProp(pNode, (const xmlChar *) "position"); if (value) { axis->_tick._position = Tick::getTickPosition((const char*) value); xmlFree(value); } // -- tick length factor value = xmlGetProp(pNode, (const xmlChar *) "lengthFactor"); if (value) { valueStr = (const char*) value; axis->_tick._lengthFactor = std::stod(valueStr, nullptr); xmlFree(value); } } }; template class LegendNode: public LabelNode { public: LegendNode() : LabelNode() { } virtual ~LegendNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "LegendNode::proceed"); AxisType* axis = pContext.get(); xmlChar* value = NULL; // -- text value = xmlGetProp(pNode, (const xmlChar *) "text"); if (value) { axis->_legend._text = (const char*) value; xmlFree(value); } AMDA::Parameters::CfgContext context; context.push(&axis->_legend); LabelNode::proceed(pNode, context); } }; template class ConstantLineNode: public AMDA::XMLConfigurator::NodeCfg { public: ConstantLineNode() : AMDA::XMLConfigurator::NodeCfg() { } virtual ~ConstantLineNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "ConstantLineNode::proceed"); AxisType* axis = pContext.get(); xmlChar* value = NULL; boost::shared_ptr constantLine (new ConstantLine ()); // -- style value = xmlGetProp(pNode, (const xmlChar *)"style"); if( value ){ try{ constantLine->setStyle (stoLineStyle.at(std::string((const char*)value))); } catch( std::out_of_range& err ){ std::ostringstream msg {}; msg << "ConstantLineNode::proceed invalid LineStyle value:" << value <<". Using default value."; LOG4CXX_DEBUG(gLogger, msg.str()); } xmlFree(value); } // -- width value = xmlGetProp(pNode, (const xmlChar *)"width"); if( value ){ constantLine->setWidth (atoi((const char*)value)); xmlFree(value); } // -- color attributes updateColor (constantLine->getColor(), pNode, (const xmlChar *)"color", (const xmlChar *)"colorMapIndex"); // -- value value = xmlGetProp(pNode, (const xmlChar *)"value"); if( value ){ constantLine->setValue ((const char*)value); xmlFree(value); } // -- id value = xmlGetProp(pNode, (const xmlChar *)"id"); if( value ){ constantLine->setId (atoi((const char*)value)); xmlFree(value); } // Add constantLine to _constantLines list axis->_constantLines.push_back (constantLine); } }; template class AnyAxisNode: public AMDA::XMLConfigurator::NodeGrpCfg { public: AnyAxisNode() : AMDA::XMLConfigurator::NodeGrpCfg() { getChildList()["range"] = AMDA::XMLConfigurator::NodeCfgSPtr( new RangeNode()); getChildList()["tick"] = AMDA::XMLConfigurator::NodeCfgSPtr( new TickNode()); getChildList()["legend"] = AMDA::XMLConfigurator::NodeCfgSPtr( new LegendNode()); getChildList()["constantLine"] = AMDA::XMLConfigurator::NodeCfgSPtr( new ConstantLineNode()); } virtual ~AnyAxisNode() { } virtual void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) { LOG4CXX_DEBUG(gLogger, "AnyAxisNode::proceed"); AxisType* axis = pContext.get(); xmlChar* value = NULL; // -- axis origin value = xmlGetProp(pNode, (const xmlChar *) "origin"); if (value) { std::string valueStr((const char*) value); axis->_origin = std::stod(valueStr, nullptr); // must be 0.0 if (axis->_origin != 0) { LOG4CXX_WARN(gLogger, "Axis origin must be 0.0, origin is set to min value"); } xmlFree(value); } // -- axis position value = xmlGetProp(pNode, (const xmlChar *) "position"); if (value) { PlotCommon::setPosition((const char*) value, axis->_position); xmlFree(value); } // -- axis thickness value = xmlGetProp(pNode, (const xmlChar *) "thickness"); if (value) { std::string valueStr((const char*) value); axis->_thickness = std::stod(valueStr, nullptr); xmlFree(value); } // -- axis color value = xmlGetProp(pNode, (const xmlChar *) "color"); if (value) { std::string strValue((const char*) value); try { createColor(axis->_color, strValue); } catch (std::exception& e) { LOG4CXX_WARN(gLogger, "Axis color : " << e.what()); } xmlFree(value); } // -- axis color map index value = xmlGetProp(pNode, (const xmlChar *) "colorMapIndex"); if (value) { axis->_color._colorMapIndex = atoi((const char*) value); xmlFree(value); } else if (axis->_color._colorIndex != -1 && axis->_color._colorMapIndex == -1) { LOG4CXX_WARN(gLogger, "No default color map is defined, color map 0 will be used"); axis->_color._colorMapIndex = 0; } // -- axis reverse mode value = xmlGetProp(pNode, (const xmlChar *) "reverse"); if (value) { std::string strValue((const char*) value); std::transform(strValue.begin(), strValue.end(), strValue.begin(), ::tolower); std::istringstream is(strValue); bool isReverse; is >> std::boolalpha >> isReverse; axis->_reverse = isReverse; xmlFree(value); } // -- axis visibility value = xmlGetProp(pNode, (const xmlChar *) "visible"); if (value) { std::string strValue((const char*) value); std::transform(strValue.begin(), strValue.end(), strValue.begin(), ::tolower); std::istringstream is(strValue); bool isVisible; is >> std::boolalpha >> isVisible; axis->_visible = isVisible; xmlFree(value); } // -- scale type value = xmlGetProp(pNode, (const xmlChar *) "scale"); if (value) { axis->setScale((const char*) value); xmlFree(value); } // -- showLegend value = xmlGetProp(pNode, (const xmlChar *) "showLegend"); if (value) { axis->setShowLegend(strcasecmp ((const char*)value, "true") == 0); xmlFree(value); } // -- showTickMark value = xmlGetProp(pNode, (const xmlChar *) "showTickMark"); if (value) { axis->setShowTickMark(strcasecmp ((const char*)value, "true") == 0); xmlFree(value); } NodeGrpCfg::proceed(pNode, pContext); } }; class TimeAxisNode: public AnyAxisNode { public: TimeAxisNode() : AnyAxisNode() { } virtual ~TimeAxisNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx); }; class EpochAxisNode: public AnyAxisNode { public: EpochAxisNode() : AnyAxisNode() { } virtual ~EpochAxisNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx); }; class DigitalAxisNode: public AnyAxisNode { public: DigitalAxisNode() : AnyAxisNode() { } virtual ~DigitalAxisNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx); }; class ColorAxisNode: public AnyAxisNode { public: ColorAxisNode() : AnyAxisNode() { } virtual ~ColorAxisNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx); }; class XAxisNode: public AMDA::XMLConfigurator::NodeGrpCfg { public: XAxisNode() : AMDA::XMLConfigurator::NodeGrpCfg() { getChildList()["timeAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr( new TimeAxisNode()); getChildList()["epochAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr( new EpochAxisNode()); getChildList()["digitalAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr( new DigitalAxisNode()); } virtual ~XAxisNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx); }; class YAxisNode: public AMDA::XMLConfigurator::NodeGrpCfg { public: YAxisNode() : AMDA::XMLConfigurator::NodeGrpCfg() { getChildList()["digitalAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr( new DigitalAxisNode()); } virtual ~YAxisNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx); }; class ZAxisNode: public AMDA::XMLConfigurator::NodeGrpCfg { public: ZAxisNode() : AMDA::XMLConfigurator::NodeGrpCfg() { getChildList()["colorAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr( new ColorAxisNode()); } virtual ~ZAxisNode() { } void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pCtx); }; class AxesNode: public AMDA::XMLConfigurator::NodeGrpCfg { public: AxesNode() : AMDA::XMLConfigurator::NodeGrpCfg() { getChildList()["xAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr( new XAxisNode()); getChildList()["yAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr( new YAxisNode()); getChildList()["zAxis"] = AMDA::XMLConfigurator::NodeCfgSPtr( new ZAxisNode()); } virtual ~AxesNode() { } }; } /* namespace plot */ #endif /* AXESNODE_HH_ */