Salome HOME
Integration of CurvePlot tool in GUI.
[modules/gui.git] / tools / CurvePlot / src / cpp / CurvePlot.hxx
1 // Copyright (C) 2010-2015  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 #include <string>
26 #include <vector>
27
28 namespace CURVEPLOT
29 {
30   typedef int PlotID;
31
32   /**
33    * This function should be called before doing anything in the CURVEPLOT namespace.
34    */
35   void InitializeCurvePlot();
36
37   class ColumnVector
38   {
39   public:
40     friend class CurvePlot;
41
42     virtual ~ColumnVector();
43
44     /**
45      * Build a ColumnVector from a std::vector() of double. The memory is copied for now (TODO: optimize this).
46      */
47     static ColumnVector BuildFromStdVector(const std::vector<double> & vec);
48
49     /**
50      * Build a ColumnVector from a block of memory which was malloc'ed.
51      * The memory is not copied, and the array thus created becomes responsible of the block.
52      * So do NOT free the memory that you pass.
53      */
54     static ColumnVector BuildFromCMemory(double * data, int size);
55
56     /**
57      * Get the current size of the vector.
58      */
59     int size() const;
60
61     /** Get a string representation */
62     std::string toStdString() const;
63
64   private:
65     class Internal;
66     ColumnVector();
67
68     void createPythonVar(std::string varName) const;
69     void cleanPythonVar(std::string varName) const;
70
71     Internal * _impl;
72   };
73
74
75   /**
76    * C++ wrapping of the public API exposed in the Python package curveplot. See doc there.
77    */
78   class CurvePlot
79   {
80   public:
81     static PlotID AddCurve(const ColumnVector & x, const ColumnVector & y,
82                            PlotID & plot_set_id,
83                            std::string curve_label="", std::string x_label="", std::string y_label="",
84                            bool append=true);
85
86     static PlotID AddPlotSet(std::string title="");
87
88     static PlotID DeleteCurve(PlotID curve_id=-1);
89
90     static PlotID DeletePlotSet(PlotID plot_set_id=-1);
91
92     static PlotID ClearPlotSet(PlotID plot_set_id=-1);
93
94     static bool SetXLabel(std::string x_label, PlotID plot_set_id=-1);
95
96     static bool SetYLabel(std::string y_label, PlotID plot_set_id=-1);
97
98     static bool SetPlotSetTitle(std::string title, PlotID plot_set_id=-1);
99
100     static PlotID GetPlotSetID(PlotID curve_id);
101
102     static PlotID GetPlotSetIDByName(std::string name);
103
104     static PlotID GetCurrentCurveID();
105
106     static PlotID GetCurrentPlotSetID();
107
108     static void ToggleCurveBrowser(bool with_curve_browser);
109
110     static bool IsValidPlotSetID(PlotID plot_set_id=-1);
111
112     static int GetSalomeViewID(PlotID plot_set_id);
113
114     static CurvePlot * GetInstance(bool test_mode=false);
115
116     /**! Temporary ... */
117     static void OnSalomeViewTryClose(int salome_view_id);
118
119   protected:
120
121   private:
122     class Internal;
123
124     static CurvePlot * _instance;
125
126     CurvePlot(bool testMode);
127     virtual ~CurvePlot();
128
129     Internal * _impl;
130   };
131 }
132
133 #endif /* SRC_CPP_CURVEPLOT_HXX_ */