#ifndef PLOTFUNCTION_HH_ #define PLOTFUNCTION_HH_ // includes boost #include #include #include #include "NodeCfg.hh" #include "PanelPlotOutput.hh" #include "PlPlotUtil.hh" #include "PlotFunctionNode.hh" #include "plotFunctionElements/Abscisse.hh" #include #include "DefaultTimeAxisDecorator.hh" #include "TimeAxisDecorator.hh" #include "plplot/plplot.h" #include "plplot/plplotP.h" #include "plplot/plstream.h" #include #include "plplot/plstream.h" extern "C" { #include } /** * @brief Id pour l'axe X qui sera crée * */ #define X_AXIS_ID "xaxis_id" #define X_AXIS_ID1 "xaxis_id1" /** * @brief Id pour l'axe Y qui sera crée * */ #define Y_AXIS_ID "y-left" namespace plot { class PlotFunction : public PanelPlotOutput { public: /** * @brief enum to represent the type of fucntion to apply for plotfunction feature * */ enum Function { NONE, AVG, FFT, DFT, SUM }; PlotFunction(AMDA::Parameters::ParameterManager &manager, boost::shared_ptr panel, TimeAxisDecorator *timeAxisDecorator = new DefaultTimeAxisDecorator()); virtual ~PlotFunction(); /** * @overload plot::PanelPlotOutput */ virtual const std::string typeName() { return PlotFunction_NODENAME; } /** * @overload plot::PanelPlotOutput */ virtual const std::string subTypeName() { return PlotFunction_NODENAME; } void setAbscisse(Abscisse abscisse_) { abscisse = abscisse_; }; Abscisse getAbscisse() { return abscisse; }; Function getFunction() { return function; }; void setFunction(Function function_) { function = function_; }; void setAbscisseScale(Axis::Scale scale) { abscisseScale = scale; }; Axis::Scale getAbscisseScale() { return abscisseScale; }; Axis::Scale getOrdonneeScale() { return ordonneeScale; }; void setOrdonneeScale(Axis::Scale scale) { ordonneeScale = scale; }; static QSASConfig *qsasconfig; void setTimeAxisDecorator(std::shared_ptr pDecorator_) { _xdecoratorPtr = pDecorator_; } std::shared_ptr getTimeAxisDecorator() { return _xdecoratorPtr; } bool isFourier() { return function == PlotFunction::Function::FFT || function == PlotFunction::Function::DFT; } std::string functionStr() { switch (function) { case PlotFunction::Function::AVG: return "AVERAGE"; case PlotFunction::Function::SUM: return "SUM"; case PlotFunction::Function::FFT: return "FFT"; default: return "NONE"; } } /** * @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; } protected: /** *@brief Draw the serie of a parameter component on plot. */ virtual void drawSeries(double startDate, double stopDate, int intervalIndex, std::string pParamId, SeriesProperties &pSerie, AMDA::Common::ParameterIndexComponent pParamIndex, ParameterAxes ¶m, bool moreThanOneSerieForAxis); virtual void writeDataFile(double startTime, double stopTime); virtual void preparePlotArea(double startTime, double stopTime, int intervalIndex); /** * @brief Get original id of the concerned parameter (for the plot) then add it to the usedParametersId_ and store it in originalParamId * * @param usedParametersId_ */ virtual void createParameters(std::list &usedParametersId_); /** * @brief draw the plot for the current time interval */ virtual bool draw(double startTime, double stopTime, int intervalIndex, bool isFirstInterval, bool isLastInterval); virtual void writeContext(ContextFileWriter &writer, AMDA::Parameters::TimeIntervalList::iterator currentTimeInterval); private: /** * @brief Format a time to given format * * @param time given time * @param format given format * @return std::string */ std::string formatTime(double time, std::string format) { long int lTime = static_cast(time); tm *lTimeTm = gmtime(&lTime); char lTimeChr[80]; // Format date. strftime(lTimeChr, 80, format.c_str(), lTimeTm); std::string lTimeStr = lTimeChr; return lTimeStr; } /** * @brief Add a title to panel * * @param startTime add startime * @param stopTime add stoptime */ void addTitleToPanel(double startTime, double stopTime); /** * @brief draw Series for compued data for given spectro * * @param startDate * @param stopDate * @param intervalIndex */ void drawSeriesForSpectro(double startDate, double stopDate, int intervalIndex); /** * @brief Apply a function either for Series or Spectro * */ void applyFunction(); /** * @brief Configure axis ranges * */ void setAxisRange(); /** * @brief Configure axis legend * */ void configureAxisLegend(); /** * @brief Afficher sur le plot the starting date * * @param _timeFormat le format * @param startTime le start time envoyé depuis le l'ihm * @param stopTime le stop time envoyé depuis le l'ihm */ void drawStartDate(std::string _timeFormat, double startTime, double stopTime); /** * @brief Apply log scaling on given data * * @param vect vector of data */ void applyScale(std::vector &vectX, std::vector &vectY); /** * @brief Get the Min Max de xValuesMap et yValuesMap * * @param minToFill la variable qui store la valeur minimale * @param maxToFill la variable qui store la valeur maximale */ void getMinMax(std::map>, double *minToFill, double *maxToFill); /** * @brief Compute function * * @param pParamIndex index of Series or (-1,-1) if it is spectro * @param ParameterData parameter data * @param pSerie pointer to series * @param pSpectro pointer to spectro * @param paramOriginID origin param ID */ void compute(AMDA::Common::ParameterIndexComponent pParamIndex, plot::ParameterData &data, SeriesProperties *pSerie, SpectroProperties *pSpectro, std::string paramOriginID); /** * @brief Une map pour stocker les valeurs calculées de l'axe X associés aux pseudo paramètres crées localement * */ std::map> xValuesMap; /** * @brief Une map pour stocker les valeurs calculées de l'axe Y associés aux pseudo paramètres crées localement * */ std::map> yValuesMap; /** * @brief function type to be applied * @see Function */ Function function; /** * @brief Abscisse type for Fourier * @see Abscisse * */ Abscisse abscisse; /** * @brief Scale of x-axis * */ Axis::Scale abscisseScale; /** * @brief Scale for y-axis * */ Axis::Scale ordonneeScale; std::shared_ptr _xdecoratorPtr; /** * @brief Flag to store if is spectro * */ bool isSpectro = false; }; } #endif