Salome HOME
d8e753cd7ebe917175867c5314e4b7139dee93af
[modules/visu.git] / src / VISU_I / VISU_Table_i.hh
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_Table_i.hh
25 //  Author : Vadim SANDLER
26 //  Module : VISU
27 //
28 #ifndef VISU_Table_i_HeaderFile
29 #define VISU_Table_i_HeaderFile
30
31 #include "VISU_PrsObject_i.hh"
32
33 #include <QStringList>
34 #include <QSet>
35 #include <QMap>
36
37 class SPlot2d_Curve;
38
39 namespace VISU {
40   typedef enum {NoneDvtn = 0, 
41                 AbsoluteDvtn,               // min, max
42                 PercentageDvtn,             // min%, max%
43                 ErrorDvtn,                  // errmin, errmax
44                 ErrorPercentageDvtn,        // errmin%, errmax%
45                 SimpleErrorDvtn,            // error
46                 SimpleErrorPercentageDvtn   // error%
47                } DeviationType;
48
49   class VISU_I_EXPORT DeviationData {
50   public:
51     DeviationData(){
52       _minRow = -1;_maxRow = -1;
53       _minType = NoneDvtn;_maxType = NoneDvtn;
54     }
55     DeviationData(const int minC, const int maxC, 
56                   const DeviationType minT, const DeviationType maxT) {
57            _minRow = minC; _maxRow = maxC;
58            _minType = minT ; _maxType = maxT;
59     }
60     int minRow() const {return _minRow;}
61     int maxRow() const {return _maxRow;}
62     DeviationType minDeviation() const {return _minType;}
63     DeviationType maxDeviation() const {return _maxType;}
64
65   private:
66     int _minRow;
67     int _maxRow;
68     DeviationType _minType;
69     DeviationType _maxType;
70   };
71
72   typedef QMap<int, DeviationData> DeviationMap;
73
74   //==============================================================================
75   class VISU_I_EXPORT Table_i : public virtual POA_VISU::Table,
76                   public virtual PrsObject_i
77   {
78     static int myNbPresent;
79     Table_i( const Table_i& );
80   public:
81     Table_i( SALOMEDS::Study_ptr theStudy, const char* theObject );
82     virtual ~Table_i();
83     virtual VISU::VISUType GetType() { return VISU::TTABLE;};
84
85     virtual void SetTitle( const char* theTitle );
86     virtual char* GetTitle();
87
88     virtual void SetOrientation( VISU::Table::Orientation theOrientation );
89     virtual VISU::Table::Orientation GetOrientation();
90
91     virtual CORBA::Long GetNbRows();
92     virtual CORBA::Long GetNbColumns();
93
94     virtual void SortRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy);
95     virtual void SortColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy);
96     virtual void SortByRow(CORBA::Long theRow, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy);
97     virtual void SortByColumn(CORBA::Long theColumn, VISU::SortOrder theSortOrder, VISU::SortPolicy theSortPolicy);
98
99     virtual bool            hasDeviationData(const int);
100     virtual bool            isDeviationRow(const int);
101     virtual DeviationData*  getDeviationInfo(const int);
102     virtual void RemoveFromStudy();
103
104   protected:
105     Storable* Build(int theRestoring);
106     void      UpdateCurves(std::map<int, int> theMixData);
107     void      BuildDeviationMap();
108
109   protected:
110     VISU::Table::Orientation myOrientation;
111     std::string myTitle;
112     SALOMEDS::SObject_var mySObj;
113     DeviationMap          myDeviationMap;
114
115   public:
116     virtual Storable* Create();
117     SALOMEDS::SObject_var GetSObject() const;
118
119     virtual Storable* Restore( const Storable::TRestoringMap& theMap,
120                                SALOMEDS::SObject_ptr SO);
121
122     static Storable* StorableEngine(SALOMEDS::SObject_ptr theSObject,
123                                     const Storable::TRestoringMap& theMap,
124                                     const std::string& thePrefix,
125                                     CORBA::Boolean theIsMultiFile);
126
127     static bool parseTitle(const QString theTitle, 
128                            QString& theOutTitle,
129                            DeviationType& theType, 
130                            bool& isMin);
131
132     static double calculateDeviation(DeviationType theType, double value,double deviationValue, bool isMin);
133
134     static QString deviationLabel(DeviationData* );
135
136     virtual void ToStream( std::ostringstream& theStr );
137     static const std::string myComment;
138     virtual const char* GetComment() const;
139     virtual QString GenerateName();
140     virtual QString GetTableTitle();
141
142     virtual std::string GetObjectEntry();
143   };
144   SALOMEDS::SObject_var ImportTables(const char* theFileName, SALOMEDS::Study_ptr theStudy,
145                                      bool theFirstStrAsTitle = false);
146   bool ExportTableToFile(SALOMEDS::SObject_ptr theTable, const char* theFileName);
147   //==============================================================================
148
149   typedef QSet<QString> ContainerSet;
150
151   class VISU_I_EXPORT Curve_i : public virtual POA_VISU::Curve,
152                   public virtual PrsObject_i
153   {
154     static int myNbPresent;
155     Curve_i();
156     Curve_i( const Curve_i& );
157   public:
158     Curve_i( SALOMEDS::Study_ptr theStudy, Table_i* theTable,
159              CORBA::Long theHRow, CORBA::Long theVRow, CORBA::Long theZRow,
160              CORBA::Boolean theIsV2 );
161     virtual ~Curve_i();
162     virtual VISU::VISUType GetType() { return VISU::TCURVE;};
163
164     virtual void SetTitle( const char* theTitle );
165     virtual char* GetTitle();
166
167     virtual void SetColor( const SALOMEDS::Color& theColor );
168     virtual SALOMEDS::Color GetColor();
169
170     virtual void SetMarker( VISU::Curve::MarkerType theType );
171     virtual VISU::Curve::MarkerType GetMarker();
172
173     virtual void SetLine( VISU::Curve::LineType theType, CORBA::Long theWidth );
174     virtual VISU::Curve::LineType GetLine();
175     virtual CORBA::Long GetLineWidth();
176
177     virtual void SetScale( CORBA::Double theCoef );
178     virtual CORBA::Double GetScale();
179     virtual void RemoveScale();
180
181     virtual void addContainer(const QString& id);
182     virtual void removeContainer(const QString& id);
183     virtual ContainerSet getContainers() const;
184
185     virtual void RemoveFromStudy();
186
187     virtual SALOMEDS::SObject_var GetSObject();
188
189     virtual void ShowDeviation(CORBA::Boolean);
190     virtual bool isDeviationShown();
191     virtual bool hasDeviation();
192
193   protected:
194     Storable* Build(int theRestoring);
195
196   protected:
197     Table_i*                myTable;
198     int                     myHRow;
199     int                     myVRow;
200     int                     myZRow;
201     bool                    myIsV2;
202     double                  myScale;
203     struct SALOMEDS::Color  myColor;
204     VISU::Curve::MarkerType myMarker;
205     VISU::Curve::LineType   myLine;
206     int                     myLineWidth;
207     std::string             myTitle;
208     bool                    myAuto;
209     SALOMEDS::SObject_var   mySObj;
210     ContainerSet            myContainers;
211     bool                    myDeviationEnabled;
212
213   public:
214     virtual Storable* Create();
215     
216     Table_i* getTable() const {return myTable;}
217
218     int  GetHRow() const { return myHRow; }
219     void SetHRow( const int theHRow ) { myHRow = theHRow; }
220
221     int  GetVRow() const { return myVRow; }
222     void SetVRow( const int theVRow ) { myVRow = theVRow; }
223
224     int  GetZRow() const { return myZRow; }
225     void SetZRow( const int theZRow ) { myZRow = theZRow; }
226
227     int  GetIsV2() const { return myIsV2; }
228     void SetIsV2( const int theIsV2 ) { myIsV2 = theIsV2; }
229
230     virtual Storable* Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr theSO);
231
232     static Storable* StorableEngine(SALOMEDS::SObject_ptr theSObject,
233                                     const Storable::TRestoringMap& theMap,
234                                     const std::string& thePrefix,
235                                     CORBA::Boolean theIsMultiFile);
236
237     virtual void ToStream( std::ostringstream& theStr );
238     static const std::string myComment;
239     virtual const char* GetComment() const;
240     virtual QString GenerateName();
241     virtual std::string GetTableID();
242
243     virtual CORBA::Boolean IsAuto() { return myAuto; }
244     virtual CORBA::Boolean IsValid();
245     virtual std::string GetHorTitle();
246     virtual std::string GetVerTitle();
247     virtual std::string GetHorUnits();
248     virtual std::string GetVerUnits();
249     virtual int GetData( double*& theHorList, double*& theVerList, QStringList& );
250     virtual int GetDeviationData( double*& theMin, double*& theMax, QList<int>& );
251
252     virtual SPlot2d_Curve* CreatePresentation();
253   };
254
255   //==============================================================================
256   class VISU_I_EXPORT Container_i : public virtual POA_VISU::Container,
257                       public virtual PrsObject_i
258   {
259     static int myNbPresent;
260     Container_i();
261     Container_i( const Container_i& );
262   public:
263     Container_i(SALOMEDS::Study_ptr theStudy);
264     virtual ~Container_i();
265     virtual VISU::VISUType GetType() { return VISU::TCONTAINER;};
266
267     virtual void AddCurve( Curve_ptr theCurve );
268     virtual void RemoveCurve( Curve_ptr theCurve );
269
270     virtual CORBA::Long GetNbCurves();
271     virtual void Clear();
272
273     virtual void RemoveFromStudy();
274
275     virtual SALOMEDS::SObject_var GetSObject();
276
277   protected:
278     Storable* Build(int theRestoring);
279
280   protected:
281     QStringList myCurves;
282     SALOMEDS::SObject_var mySObj;
283
284   public:
285     virtual Storable* Create();
286     virtual Storable* Restore( const Storable::TRestoringMap& theMap, SALOMEDS::SObject_ptr SO );
287
288     static Storable* StorableEngine(SALOMEDS::SObject_ptr theSObject,
289                                     const Storable::TRestoringMap& theMap,
290                                     const std::string& thePrefix,
291                                     CORBA::Boolean theIsMultiFile);
292
293     virtual void ToStream( std::ostringstream& theStr );
294     static const std::string myComment;
295     virtual const char* GetComment() const;
296     virtual QString GenerateName();
297
298     void Update();
299     VISU::Curve_i* GetCurve( CORBA::Long theIndex );
300
301   };
302 }
303
304 #endif