Salome HOME
Copyright update 2020
[modules/gui.git] / tools / CurvePlot / src / cpp / CurvePlot.hxx
1 // Copyright (C) 2010-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Adrien BRUNETON
20 //
21
22 #ifndef SRC_CPP_CURVEPLOT_HXX_
23 #define SRC_CPP_CURVEPLOT_HXX_
24
25 #ifdef WIN32
26 #  if defined CURVEPLOT_EXPORTS || defined CurvePlot_EXPORTS
27 #    define CURVEPLOT_EXPORT __declspec(dllexport)
28 #  else
29 #    define CURVEPLOT_EXPORT __declspec(dllimport)
30 #  endif
31 #else   // WIN32
32 #  define CURVEPLOT_EXPORT
33 #endif  // WIN32
34
35
36 #include <string>
37 #include <vector>
38
39 namespace CURVEPLOT
40 {
41   typedef int PlotID;
42
43   /**
44    * This function should be called before doing anything in the CURVEPLOT namespace.
45    */
46   CURVEPLOT_EXPORT void* InitializeCurvePlot();
47
48   class CURVEPLOT_EXPORT ColumnVector
49   {
50   public:
51     friend class CurvePlot;
52
53     virtual ~ColumnVector();
54
55     /**
56      * Build a ColumnVector from a std::vector() of double. The memory is copied for now (TODO: optimize this).
57      */
58     static ColumnVector BuildFromStdVector(const std::vector<double> & vec);
59
60     /**
61      * Build a ColumnVector from a block of memory which was malloc'ed.
62      * The memory is not copied, and the array thus created becomes responsible of the block.
63      * So do NOT free the memory that you pass.
64      */
65     static ColumnVector BuildFromCMemory(double * data, int size);
66
67     /**
68      * Get the current size of the vector.
69      */
70     int size() const;
71
72     /** Get a string representation */
73     std::string toStdString() const;
74
75   private:
76     class Internal;
77     ColumnVector();
78
79     void createPythonVar(std::string varName) const;
80     void cleanPythonVar(std::string varName) const;
81
82     Internal * _impl;
83   };
84
85
86   /**
87    * C++ wrapping of the public API exposed in the Python package curveplot. See doc there.
88    */
89   class CURVEPLOT_EXPORT CurvePlot
90   {
91   public:
92     static PlotID AddCurve(const ColumnVector & x, const ColumnVector & y,
93                            PlotID & plot_set_id,
94                            std::string curve_label="", std::string x_label="", std::string y_label="",
95                            bool append=true);
96
97     static PlotID AddPlotSet(std::string title="");
98
99     static PlotID DeleteCurve(PlotID curve_id=-1);
100
101     static PlotID DeletePlotSet(PlotID plot_set_id=-1);
102
103     static PlotID ClearPlotSet(PlotID plot_set_id=-1);
104
105     static bool SetXLabel(std::string x_label, PlotID plot_set_id=-1);
106
107     static bool SetYLabel(std::string y_label, PlotID plot_set_id=-1);
108
109     static bool SetPlotSetTitle(std::string title, PlotID plot_set_id=-1);
110
111     static PlotID GetPlotSetID(PlotID curve_id);
112
113     static PlotID GetPlotSetIDByName(std::string name);
114
115     static PlotID GetCurrentCurveID();
116
117     static PlotID GetCurrentPlotSetID();
118
119     static void ToggleCurveBrowser(bool with_curve_browser);
120
121     static bool IsValidPlotSetID(PlotID plot_set_id=-1);
122
123     static int GetSalomeViewID(PlotID plot_set_id);
124
125     static CurvePlot * GetInstance(bool test_mode=false);
126
127     /**! Temporary ... */
128     static void OnSalomeViewTryClose(int salome_view_id);
129
130   protected:
131
132   private:
133     class Internal;
134
135     static CurvePlot * _instance;
136
137     CurvePlot(bool testMode);
138     virtual ~CurvePlot();
139
140     Internal * _impl;
141   };
142 }
143
144 #endif /* SRC_CPP_CURVEPLOT_HXX_ */