TimePlot.hh 6.98 KB
/*
 * TimePlot.hh
 *
 *  Created on: 22 nov. 2013
 *      Author: CS
 */

#ifndef TIMEPLOT_HH_
#define TIMEPLOT_HH_

#include "NodeCfg.hh"
#include "PanelPlotOutput.hh"

#include <algorithm>
#include <map>
#include <memory>

#include "DefaultTimeAxisDecorator.hh"

#include "TimeAxisDecorator.hh"

#include "ParamData.hh"

#include "TimePlotNode.hh"

#include "ParamInfo.hh"

extern "C"
{
#include <plplot/qsastime.h>
}

namespace plot
{

	class TimeAxis;

	/**
 * Plot that draws f(t)
 */
	class TimePlot : public PanelPlotOutput
	{
	public:
		TimePlot(AMDA::Parameters::ParameterManager &manager,
				 boost::shared_ptr<Panel> panel, TimeAxisDecorator *timeAxisDecorator = new DefaultTimeAxisDecorator(), bool isStandalone = true);
		virtual ~TimePlot();
		/**
	 * @overload plot::PanelPlotOutput
	 */
		virtual const std::string typeName()
		{
			return TIMEPLOT_NODENAME;
		}

		/**
	 * @brief overloads ParamOutput::preparePlotArea
	 */
		virtual void preparePlotArea(double startTime, double stopTime, int intervalIndex);

		/**
	 * @brief overloads ParamOutput::draw()
	 */
		virtual bool draw(double startTime, double stopTime, int intervalIndex,
						  bool isFirstInterval, bool isLastInterval);

		TimeAxis *getTimeAxis();

		void setTimeAxisDecorator(std::shared_ptr<TimeAxisDecorator> pDecorator_)
		{
			_xdecoratorPtr = pDecorator_;
		}

		std::shared_ptr<TimeAxisDecorator> getTimeAxisDecorator()
		{
			return _xdecoratorPtr;
		}

		void normalize(MatrixGrid &matrixGrid, std::string normalizationType);

		/**
		 * @brief Apply a background subtraction for the given spectro
		 * 
		 * @param matrixGrid matrix for each index of the sepctro
		 * @param pSpectro spectro's properties
		 * @param data data of the parameter associated with the spectro
		 */
		void applyBackgroundSubtraction(MatrixGrid &matrixGrid, SpectroProperties &pSpectro, ParameterData &data);

		/**
	 * @brief QSAS time configuration for time formatting
	 */
		static QSASConfig *qsasconfig;

	protected:
		/**
	 * @overload PanelPlotOutput::calculatePlotArea(Bounds const& pPanelBounds, bool pKeepRatio)
	 * @brief Calculate and draw plot area.
	 */
		virtual void calculatePlotArea(const Bounds &panelBounds_, Bounds &bounds_);

		/**
	 * @overload PanelPlotOutput::drawFills(double startDate, double stopDate)
	 * @brief Draw fill area between parameter and constant or between parameters
	 */
		virtual void drawFills(double startDate, double stopDate);

		/**
	 * @overload PanelPlotOutput::drawSeries(double startDate, double stopDate, std::string pParamId, SeriesProperties const& pSerie)
	 * @brief Draw series of parameter on plot.
	 */
		virtual void drawSeries(double startDate, double stopDate, int intervalIndex, std::string pParamId,
								SeriesProperties &pSeries,
								AMDA::Common::ParameterIndexComponent pParamIndex,
								ParameterAxes &param, bool moreThanOneSerieForAxis);

		/**
	 * @overload PanelPlotOutput::drawSpectro(double startDate, double stopDate, std::string pParamId, SpectroProperties& pSpectro)
	 * @brief Draw spectro of parameter on plot.
	 */
		virtual void drawSpectro(double startDate, double stopDate, std::string pParamId,
								 SpectroProperties &pSpectro);
                
                		virtual void drawSauvaud(double startDate, double stopDate, std::string pParamId,
								 SauvaudProperties &pSauvaud,int subInde, int subsNumber);


		/**
	 * @overload PanelPlotOutput::drawIntervals(double startDate, double stopDate, std::string pParamId, IntervalsProperties& pIntervals)
	 * @brief Draw intervals defined by a parameter
	 */
		virtual void drawIntervals(double startDate, double stopDate, std::string pParamId,
								   IntervalsProperties &pIntervals);

		void drawXAxis(boost::shared_ptr<Axis> pXAxis, PlWindow &pPlWindow, Bounds &pPlotAreaSize, TickConf &pTickConf);

		/**
//	 * @overload convertXAxisValue(const std::string &value)
//	 * @brief Convert an X axis string value to a double X value
	 * Subclasses may override it to take into account specific value meaning.
	 * @param value string value to convert.
	 */
		virtual double convertXAxisValue(const std::string &value);

		/**
	 * @brief Identify if other side of the plot area need to be drawn or not.
	 * @note A plot area side need to be drawn when there is no axis associated to it.
	 */
		std::string drawOppositeSide(boost::shared_ptr<Axis> pAxis);

		/**
	 * @overload PanelPlotOutput::resetPlot - reset plot
	 */
		virtual void resetPlot()
		{
			_startDateDrawn = false;
			PanelPlotOutput::resetPlot();
		}
		/*
	 *
	 */

	private:
		void drawStartDate(TimeAxis *pXAxis, double startTime, double stopTime);

		const std::string getXAxisId() const;

		/**
	 * @brief Configure series color (symbols and line) and range of axis (depending of parameters series to draw).
	 */
		void configureSeriesAxis();

		/**
	 * @brief Configure axis legend with paramInfo.
	 */
		void configureAxisLegend();

		/**
	* @brief Configure spectro.
	*/
		void configureSpectroAxis();
                    /**
                	* @brief Configure spectro.
	*/
		void configureSauvaudAxis();

		/**
	* @brief Retrieve ConstantLine informations for a given serieId and constantId.
	*/
		ConstantLine *getConstantLineFromId(int serieId, int constantId, boost::shared_ptr<Axis> &yAxis);

		/**
	* @brief Retrieve serie properties by serie Id.
	*/
		bool getSeriePropertiesById(int serieId, SeriesProperties &rSerieProperties);

		/**
	* @brief Merge, sort and remove duplicate from 2 arrays in a vector
	*/
		void mergeAndSortTime(double *values1Time, int values1Nb,
							  double *values2Time, int values2Nb,
							  std::vector<double> &values);

		/**
	* @brief Return or compute an interpolated value
	*/
		double getInterpolatedValue(double *values, double *valuesTime, int valuesNb, double atTime);

		/**
	* @brief Compute if two ligne segments intersects
	*/
		bool intersect(double xi, double y1i, double y2i,
					   double xj, double y1j, double y2j,
					   double *xInter);

		/**
	* @brief Compute and add intersections time to the vector if intersections exist
	*/
		void addIntersectionTime(double *values1, double *values1Time, int values1Nb,
								 double *values2, double *values2Time, int values2Nb,
								 std::vector<double> &valuesTime);

		/**
	* @brief Draw Fill Area for the given arrays and the valueTime timeline
	*/
		void drawFillArea(double *values1, double *values1Time, int values1Nb,
						  double *values2, double *values2Time, int values2Nb,
						  std::vector<double> &valuesTime,
						  bool colorGreaterSpecified, Color &colorGreater,
						  bool colorLessSpecified, Color &colorLess,
						  SeriesProperties &rSeriesProperties);

		Color getStatusColor(AMDA::Info::ParamInfoSPtr &paramInfo, double value);

		void drawOneInterval(double tmin, double tmax, Color color);

		std::shared_ptr<TimeAxisDecorator> _xdecoratorPtr;

		bool _startDateDrawn;
	};

	/**
 * @brief Custom generator for time label, just not display min time.
 */
	void generateTimeLabel(PLINT axis, PLFLT value, char *label, PLINT length,
						   PLPointer data);

} /* namespace plot */
#endif /* TIMEPLOT_HH_ */