PlotFunction.hh 4.55 KB

#ifndef PLOTFUNCTION_HH_
#define PLOTFUNCTION_HH_

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

#include "NodeCfg.hh"
#include "PanelPlotOutput.hh"
#include "PlPlotUtil.hh"
#include "PlotFunctionNode.hh"
#include "plotFunctionElements/Abscisse.hh"
#include <climits>

#include "DefaultTimeAxisDecorator.hh"

#include "TimeAxisDecorator.hh"

#include "plplot/plplot.h"
#include "plplot/plplotP.h"
#include "plplot/plstream.h"
#include <map>

#include "plplot/plstream.h"

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

#define X_AXIS_ID "x_axis_id"
#define Y_AXIS_ID ""

namespace plot
{

    class PlotFunction : public PanelPlotOutput
    {
    public:
        enum Function
        {
            NONE,
            FFT,
            SUM
        };

        PlotFunction(AMDA::Parameters::ParameterManager &manager,
                     boost::shared_ptr<Panel> panel, TimeAxisDecorator *timeAxisDecorator = new DefaultTimeAxisDecorator());
        virtual ~PlotFunction();

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

        void setOriginalParamId(std::string originalParamId_)
        {
            originalParamId = originalParamId_;
        };

        void setAbscisse(Abscisse abscisse_)
        {
            abscisse = abscisse_;
        };

        Abscisse getAbscisse()
        {
            return abscisse;
        };

        Function getFunction()
        {
            return function;
        };

        void setFunction(Function function_)
        {
            function = function_;
        };

        void setParamsNbPoints(std::vector<std::string> paramsNbPoints_)
        {
            paramsNbPoints = paramsNbPoints_;
        };

        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<TimeAxisDecorator> pDecorator_)
        {
            _xdecoratorPtr = pDecorator_;
        }

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

    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 &param, bool moreThanOneSerieForAxis);

        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<std::string> &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 drawFills(double startDate, double stopDate);

    private:
        void configureSeriesAxis();
        void configureAxisLegend();
        void drawStartDate(std::string _timeFormat, double startTime, double stopTime);
        void createYAxis();
        void createXAxis();
        void getMinMax(std::map<std::string, std::vector<double>>, double *minToFill, double *maxToFill);

        void compute(AMDA::Common::ParameterIndexComponent pParamIndex, plot::ParameterData data, std::string id);
        std::map<std::string, std::vector<double>> xValuesMap;
        std::map<std::string, std::vector<double>> yValuesMap;
        Function function;
        std::vector<std::string> paramsNbPoints;
        Abscisse abscisse;
        Axis::Scale abscisseScale;
        Axis::Scale ordonneeScale;
        std::shared_ptr<TimeAxisDecorator> _xdecoratorPtr;

        /**
         * @brief original param Id.
         */
        std::string originalParamId;
        std::list<std::string> listParamsId;
        // std::vector<double> xValues;
        // std::vector<double> yValues;
    };
}
#endif