InstantPlot.hh 6.94 KB
/*
 * InstantPlot.hh
 *
 *  Created on: 29 oct. 2013
 *      Author: CS
 */

#ifndef INSTANTPLOT_HH_
#define INSTANTPLOT_HH_

//includes boost
#include <boost/shared_ptr.hpp>

#include "PanelPlotOutput.hh"
#include "NodeCfg.hh"
#include "InstantPlotNode.hh"
#include "InstantSeriesProperties.hh"
#include "InstantSpectroProperties.hh"

namespace plot {

/**
 *  @brief Plot that draws f(x).
 */
class InstantPlot: public PanelPlotOutput {
public:
	InstantPlot(AMDA::Parameters::ParameterManager& manager,
			boost::shared_ptr<Panel> panel);
	virtual ~InstantPlot();

	/**
	 * @overload plot::PanelPlotOutput
	 */
	virtual const std::string typeName() {
		return INSTANTPLOT_NODENAME;
	}

	/**
	 * @overload plot::PanelPlotOutput
	 */
	virtual const std::string subTypeName() {
		return INSTANTPLOT_NODENAME;
	}

	/**
	 * @overload plot::PanelPlotOutput::preparePlotArea()
	 */
	virtual void preparePlotArea(double startTime, double stopTime, int intervalIndex);

	/**
	 * @overload plot::PanelPlotOutput::createParameters()
	 */
	virtual void createParameters(std::list<std::string>& usedParametersId_);

	/**
	 * Adds a parameter
	 */
	virtual void addParam(const std::string& name) {
		// There is only one parameter for instant plots
		_originalParamId = name;
	}

	/**
	 * @brief draw the plot for the current time interval
	 */
	virtual bool draw(double startTime, double stopTime, int intervalIndex,
			bool isFirstInterval, bool isLastInterval);

	/**
	 * @brief Override drawAdditionalObjects
	 * draw additional objects
	 */
	virtual void drawAdditionalObjects();

	/**
	 * @overload PanelPlotOutput::getLayoutConstraint (void)
	 * @brief Defines the layout constraint to be used for the panel when used within a layout
	 */
	virtual PanelConstraint getLayoutConstraint (void) {
		return PanelConstraint::Square;
	}

	double getTime() const {
		return _time;
	}

	void setTime(double time) {
		_time = time;
	}

	const boost::shared_ptr<InstantSeriesProperties>& getInstantSerieProperties() const {
		return _iSerieProperties;
	}

	void setInstantSerieProperties(
			const boost::shared_ptr<InstantSeriesProperties>& instantSerieProperties) {
		_iSerieProperties = instantSerieProperties;
	}

	const boost::shared_ptr<InstantSpectroProperties>& getInstantSpectroProperties() const {
		return _iSpectroProperties;
	}

	void setInstantSpectroProperties(
		const boost::shared_ptr<InstantSpectroProperties>& instantSpectroProperties) {
		_iSpectroProperties = instantSpectroProperties;
	}

	const std::string& getOriginalParamId() const {
		return _originalParamId;
	}

	void setOriginalParamId(const std::string& originalParamId) {
		_originalParamId = originalParamId;
	}

protected:

	/**
	 * @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);

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

	/**
	 * @brief Draw sprctro of parameter on plot.
	 */
	virtual void drawSpectro(double startDate, double stopDate, std::string pParamId, SpectroProperties& pSpectro, bool& noData);

	/*
	 * Dumps properties for test.
	 */
	virtual void dump(std::ostream& fileName_);

	virtual void writeContext(ContextFileWriter &writer, AMDA::Parameters::TimeIntervalList::iterator currentTimeInterval);

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

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

	/**
	 * @overload  PanelPlotOutput::getSerieParamsLegendString Get the instant serie legend
	 */
	std::string getSerieParamsLegendString(SeriesProperties &rSeriesProperties,
		AMDA::Common::ParameterIndexComponent& index, std::string originalParamId);

	/**
	 * @overload PanelPlotOutput::configureParamsLegend Configure params legend for an instant plot.
	 */
	virtual void configureParamsLegend(double startTime, double stopTime, int intervalIndex);

	/**
	 * @brief Configure table axis for the parameter
	 */
	void configureTableAxis (boost::shared_ptr<Axis> axisSPtr, bool isSpectro, int relatedDim);

	/**
	 * @brief Configure data axis for the parameter
	 */
	void configureDataAxis (boost::shared_ptr<Axis> axisSPtr, bool isSpectro);

	/**
	 * @brief Configure legend for table axis
	 */
	void configureTableAxisLegend(boost::shared_ptr<Axis> axisSPtr, int relatedDim);

	/**
	 * @brief Configure legend for data axis
	 */
	void configureDataAxisLegend(boost::shared_ptr<Axis> axisSPtr, bool isSpectro);

	/**
	 * @brief Configure spectro range of axis (depending of parameters spectro to draw).
	 */
	void configureSpectroAxis();

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

	/**
	* @brief Retrieve ConstantLine informations for a given serieId and constantId.
	*/
	ConstantLine * getConstantLineFromSerieId (int serieId, int constantId);

	/**
	* @brief Retrieve values for a given serieId.
	*/
	void getSerieParameterValues(int serieId, double **xValues, double **yValues, int *nbValues);

	/**
	* @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 addIntersectionTable (	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);

	/**
	 * @brief time used for instantPlot plotting.
	 */
	double	_time;
	double _prevTime;
	double _nextTime;

	/**
	 * @brief Intant pot param Id.
	 */
	std::string	_originalParamId;

	/**
	 * @brief Instant plot serie properties
	 */
	boost::shared_ptr<InstantSeriesProperties>	_iSerieProperties;

	/*
	 * @brief Instant plot spectro properties
	 */
	boost::shared_ptr<InstantSpectroProperties>	_iSpectroProperties;
};

} /* namespace plot */
#endif /* INSTANTPLOT_HH_ */