SauvaudNode.hh 3.7 KB
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   SauvaudNode.hh
 * Author: hacene
 *
 * Created on January 3, 2022, 10:51 AM
 */

#ifndef SAUVAUDNODE_HH
#define SAUVAUDNODE_HH

namespace plot
{
	/**
 * Class that handle a <spectro> xml node.
 * Template class that should be instanciated for each subclass of PanelOutputPanel.
 */

	template <class PlotType>
	class SauvaudNode : public plot::DrawingPropertiesNode<PlotType>
	{
	public:
		SauvaudNode() : DrawingPropertiesNode<PlotType>()
		{
		}
		virtual ~SauvaudNode()
		{
		}

		void proceed(xmlNodePtr pNode_, const AMDA::Parameters::CfgContext &pContext_)
		{
			LOG4CXX_DEBUG(gLogger, "SauvaudNode::proceed");
			PlotType *plotOutput = pContext_.get<PlotType *>();
			xmlChar *name = pContext_.get<xmlChar *>();

			// initialize spectro with default properties
			DrawingProperties defaultProps = plotOutput->getParameter(
														   (const char *)name)
												 .getDefaultProperties();

			// read parent attributes
			DrawingPropertiesNode<PlotType>::parseAttributes(pNode_, defaultProps);

			// spectro properties
			std::shared_ptr<SauvaudProperties> sauvaudPropsPtr =
				std::shared_ptr<SauvaudProperties>(new SauvaudProperties(defaultProps));

			xmlChar *value = NULL;

			// -- parameter resolution
			value = xmlGetProp(pNode_, (const xmlChar *)"resolution");
			if (value)
			{
				sauvaudPropsPtr->setMaxResolution(atoi((const char *)value));
				xmlFree(value);
			}

			// read index definition
			value = xmlGetProp(pNode_, (const xmlChar *)"index");
			if (value)
			{
				sauvaudPropsPtr->setIndexDef((const char *)value);
				xmlFree(value);
			}

			//set related dim
			sauvaudPropsPtr->setRelatedDim(AMDA::Common::ParameterIndexesTool::getRelatedDimForTab2D(sauvaudPropsPtr->getIndexDef()));

			// read uselog0asmin
			value = xmlGetProp(pNode_, (const xmlChar *)"uselog0asmin");
			if (value)
			{
				std::string strValue((const char *)value);
				std::transform(strValue.begin(), strValue.end(), strValue.begin(),
							   ::tolower);
				std::istringstream is(strValue);
				bool uselog0asmin;
				is >> std::boolalpha >> uselog0asmin;
				sauvaudPropsPtr->setUseLog0AsMin(uselog0asmin);
				xmlFree(value);
			}

			// normalization
			value = xmlGetProp(pNode_, (const xmlChar *)"normalization");
			if (value)
			{
				sauvaudPropsPtr->setNormalization((const char *)value);
				xmlFree(value);
			}

			value = xmlGetProp(pNode_, (const xmlChar *)BACKGROUND_SUB_TYPE);
			if (value)
			{
				const char *valueString = (const char *)value;

				if (strcmp(valueString, BACKGROUND_SUB_TYPE_BY_CHANNEL) == 0)
				{
					sauvaudPropsPtr->setBackgroundSubType(SauvaudProperties::BackgroundSubType::BYCHANNEL);
				}
				else if (strcmp(valueString, BACKGROUND_SUB_TYPE_BY_FIXED_VALUE) == 0)
				{
					sauvaudPropsPtr->setBackgroundSubType(SauvaudProperties::BackgroundSubType::FIXEDVALUE);
				}

				xmlFree(value);
			}

			value = xmlGetProp(pNode_, (const xmlChar *)BACKGROUND_SUB_VALUE);
			if (value)
			{
				char *newValueBrut = (char *)value;
				double newValue = std::stod(newValueBrut);
				sauvaudPropsPtr->setBackgroundSubValue(newValue);
				xmlFree(value);
			}
			//setRelatedDim
			value = xmlGetProp(pNode_, (const xmlChar *)BACKGROUND_SUB_DIM);
			if (value)
			{
				char *newValueBrut = (char *)value;
				int newValue = std::stoi(newValueBrut);
				sauvaudPropsPtr->setBackgroundSubDim(newValue);
				xmlFree(value);
			}
			// add spectro definition to parameter
			plotOutput->getParameter((const char *)name).addSauvaudProperties(sauvaudPropsPtr);
		}
	};

}
/* namespace plot */

#endif /* SAUVAUDNODE_HH */