Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_I / VISU_Result_i.hh
1 // Copyright (C) 2007-2012  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_Result_i.hh
25 //  Author : Alexey PETROV
26 //  Module : VISU
27 //
28 #ifndef __VISU_RESULT_I_H__
29 #define __VISU_RESULT_I_H__
30
31 #include "VISU_PrsObject_i.hh"
32 #include "VISU_BoostSignals.h"
33 #include "SALOME_GenericObj_i.hh"
34
35 #include "SALOME_Event.h"
36 #include "VTKViewer.h"
37
38 #include <boost/shared_ptr.hpp>
39 #include <gp_Dir.hxx>
40 #include <vector>
41 #include <map>
42
43 class VISU_Convertor;
44
45 namespace VISU
46 {
47   //----------------------------------------------------------------------------
48   class TResultObserver;
49
50
51   //----------------------------------------------------------------------------
52   class VISU_I_EXPORT Result_i : public virtual POA_VISU::Result,
53                                  public virtual RemovableObject_i,
54                                  public virtual SALOME::GenericObj_i
55   {
56     Result_i(const Result_i &);
57
58   public:
59     enum ESourceId {
60       eRestoredComponent = -2, 
61       eRestoredFile = -1,  
62       eSavedFile = 0, 
63       eFile = 1, 
64       eComponent = 2
65     };
66
67     enum ECreationId {
68       eImportFile, 
69       eCopyAndImportFile, 
70       eImportMed, 
71       eImportMedField
72     };
73
74     static
75     Result_i*
76     New(SALOMEDS::Study_ptr theStudy,
77         const ESourceId& theSourceId,
78         const ECreationId& theCreationId,
79         CORBA::Boolean theIsBuildImmediately,
80         CORBA::Boolean theIsBuildFields,
81         CORBA::Boolean theIsBuildMinMax,
82         CORBA::Boolean theIsBuildGroups);
83     
84     virtual
85     void
86     RemoveFromStudy();
87
88     virtual
89     VISU::VISUType 
90     GetType() 
91     {
92       return VISU::TRESULT;
93     }
94
95     virtual
96     CORBA::Boolean
97     BuildAll();
98
99     virtual
100     CORBA::Boolean 
101     Build(CORBA::Boolean theIsBuildAll,
102           CORBA::Boolean theIsAtOnce);
103
104     virtual
105     CORBA::Boolean
106     ExportMED(const char* theFileName);
107
108     virtual
109     CORBA::Boolean
110     IsDone();
111
112     virtual
113     CORBA::Boolean
114     IsEntitiesDone();
115
116     virtual
117     void
118     SetBuildFields(CORBA::Boolean theIsBuildFields, 
119                    CORBA::Boolean theIsCalculateMinMax);
120
121     virtual
122     CORBA::Boolean
123     IsFieldsDone();
124
125     virtual
126     void 
127     SetBuildGroups(CORBA::Boolean theIsBuildGroups);
128
129     virtual
130     CORBA::Boolean
131     IsGroupsDone();
132
133     virtual
134     CORBA::Boolean
135     IsMinMaxDone();
136
137     virtual
138     CORBA::Boolean 
139     IsPartsDone();
140
141     virtual
142     VISU::Result::EntityNames* 
143     GetMeshNames();
144
145     virtual
146     VISU::Result::Entities* 
147     GetEntities(const char* theMeshName);
148
149     virtual
150     VISU::Result::EntityNames* 
151     GetFamilies(const char* theMeshName, 
152                 Entity theEntity);
153
154     virtual
155     VISU::Result::EntityNames* 
156     GetGroups(const char* theMeshName);
157
158     virtual
159     VISU::Result::EntityNames*
160     GetFields(const char* theMeshName, 
161               Entity theEntity);
162
163     virtual
164     VISU::Result::TimeStampNumbers* 
165     GetTimeStampNumbers(const char* theMeshName, 
166                         Entity theEntity, 
167                         const char* theFieldName);
168
169     virtual
170     VISU::double_array* 
171     GetTimeStampValues(const char* theMeshName, 
172                        Entity theEntity, 
173                        const char* theFieldName);
174
175     virtual
176     CORBA::Long 
177     GetNumberOfComponents(const char* theMeshName, 
178                           Entity theEntity, 
179                           const char* theFieldName);
180
181     virtual
182     VISU::Result::EntityNames* 
183     GetPartNames(const char* theMeshName);
184
185     virtual
186     VISU::Result::Resolutions* 
187     GetResolutions(const char* theMeshName, 
188                    const char* thePartName);
189
190     virtual
191     VISU::Result::Resolution
192     GetResolution(const char* theMeshName, 
193                   const char* thePartName);
194
195     virtual
196     void 
197     SetResolution(const char* theMeshName, 
198                   const char* thePartName, 
199                   VISU::Result::Resolution theResolution);
200
201     virtual 
202     void
203     UpdateObservers();
204
205     virtual 
206     void
207     ConnectObserver(TResultObserver* theObserver,
208                     boost::signalslib::connection& theConnection);
209
210     virtual
211     SALOME_MED::MedFileInfo*
212     GetMEDFileInfo();
213     
214     typedef boost::signal0<void> TUpdateObserverSignal;
215
216     typedef VISU_Convertor TInput;
217     typedef boost::shared_ptr<TInput> PInput;
218
219   private:
220     ESourceId mySourceId;
221     ECreationId myCreationId;
222
223     PInput myInput;
224     std::string myFileName;
225     QFileInfo myFileInfo;
226     std::string myInitFileName;
227
228   protected:
229     Result_i(SALOMEDS::Study_ptr theStudy,
230              const ESourceId& theSourceId,
231              const ECreationId& theCreationId,
232              CORBA::Boolean theIsBuildImmediately,
233              CORBA::Boolean theIsBuildFields,
234              CORBA::Boolean theIsBuildMinMax,
235              CORBA::Boolean theIsBuildGroups);
236
237     Result_i();
238
239     virtual
240     ~Result_i();
241
242     virtual
243     Storable* 
244     Build(SALOMEDS::SObject_ptr theSObject,
245           CORBA::Boolean theIsAtOnce = true) ;
246
247     virtual
248     void
249     BuildDataTree(const std::string& theResultEntry);
250
251     virtual
252     Storable* 
253     BuildAll(SALOMEDS::SObject_ptr theSObject) ;
254
255     ESourceId
256     GetSourceId() const;
257         
258     _PTR(Study) myStudy;
259     CORBA::Boolean myIsBuildImmediately;
260
261     CORBA::Boolean myIsEntitiesDone;
262
263     CORBA::Boolean myIsFieldsDone;
264     CORBA::Boolean myIsBuildFields;
265
266     CORBA::Boolean myIsGroupsDone;
267     CORBA::Boolean myIsBuildGroups;
268
269     CORBA::Boolean myIsPartsDone;
270     CORBA::Boolean myIsBuildParts;
271
272     CORBA::Boolean myIsMinMaxDone;
273     CORBA::Boolean myIsBuildMinMax;
274     TUpdateObserverSignal myUpdateObserverSignal;
275
276     CORBA::Boolean myIsAllDone;
277
278   public:
279     virtual
280     size_t
281     IsPossible();
282
283     virtual
284     Storable* 
285     Create(const char* theFileName);
286
287     virtual
288     Storable* 
289     Create(SALOMEDS::SObject_ptr theMedSObject);
290
291     virtual
292     Storable* 
293     Create(SALOME_MED::FIELD_ptr theField);
294
295     virtual
296     Storable* 
297     Restore(SALOMEDS::SObject_ptr theSObject,
298             const Storable::TRestoringMap& theMap,
299             const std::string& thePrefix,
300             CORBA::Boolean theIsMultiFile);
301
302     static 
303     Storable* 
304     StorableEngine(SALOMEDS::SObject_ptr theSObject,
305                    const Storable::TRestoringMap& theMap,
306                    const std::string& thePrefix,
307                    CORBA::Boolean theIsMultiFile);
308
309     virtual 
310     void
311     ToStream(std::ostringstream& theStr);
312
313     //---------------------------------------------------------------
314     typedef std::string TFileName;
315     typedef std::vector<TFileName> TFileNames;
316
317     virtual 
318     bool
319     Save(SALOMEDS::SComponent_ptr theComponent,
320          const std::string& theURL,
321          bool theIsMultiFile,
322          bool theIsASCII,
323          TFileNames& theFileNames,
324          TFileNames& theFiles);
325
326     //---------------------------------------------------------------
327     virtual 
328     CORBA::Boolean 
329     CanCopy(SALOMEDS::SObject_ptr theObject);
330
331     virtual 
332     bool 
333     CopyFrom(SALOMEDS::SObject_ptr theObject, 
334              CORBA::Long& theObjectID,
335              const std::string& theTmpDir,
336              TFileNames& theFileNames);
337
338     //---------------------------------------------------------------
339     virtual
340     const char* 
341     GetComment() const;
342
343     static const std::string myComment;
344
345     virtual
346     PInput 
347     GetInput(const std::string& theMeshName = "",
348              VISU::Entity theEntity = VISU::NONE,
349              const std::string& theFieldName = "", 
350              CORBA::Long theTimeStampNumber = -1);
351
352     virtual
353     std::string
354     GetInitFileName() const;
355
356     virtual
357     void 
358     SetInitFileName(const std::string& theFileName);
359
360     virtual
361     std::string
362     GetFileName() const;
363
364     QFileInfo
365     GetFileInfo() const;
366
367     ECreationId
368     GetCreationId() const;
369         
370   private:
371     SALOMEDS::SObject_var mySObject;
372     SALOMEDS::Study_var myStudyDocument;
373     SALOMEDS::SComponent_var mySComponent;
374
375   public:
376     std::string
377     GetEntry();
378
379     SALOMEDS::SObject_var
380     GetSObject() const;
381
382     SALOMEDS::Study_var
383     GetStudyDocument() const;
384
385     _PTR(Study) 
386     GetStudy() const;
387
388     SALOMEDS::SComponent_var
389     GetSComponent() const;
390
391     std::string
392     GetEntry(const Storable::TRestoringMap& theRestoringMap);
393
394     // Info on structured mesh contained in TInput
395   public:
396     typedef enum { AXIS_X = 0, AXIS_Y, AXIS_Z } TAxis;
397     typedef std::vector< vtkFloatingPointType > TAxisInfo;
398     const TAxisInfo* GetAxisInfo(const std::string& theMeshName,
399                                  TAxis              theAxis,
400                                  gp_Dir&            thePlaneNormal);
401     // Return i,j or k values and cutting plane normal for theAxis.
402     // In the case of any problems, return NULL pointer
403   private:
404     struct TGridInfo {
405       TAxisInfo myComponets[ 3 ];
406       gp_Dir    myAxis     [ 3 ];
407     };
408     std::map< std::string, TGridInfo > myMeshName2GridInfoMap;
409   };
410
411   //! To find Result object as published on father of the given SObject
412   VISU_I_EXPORT
413   Result_var 
414   FindResult(SALOMEDS::SObject_ptr theSObject);
415
416   //! To get VISU::Result object published on the given SALOMEDS::SObject
417   Result_i* 
418   GetResult(SALOMEDS::Study_ptr theStudy,
419             const std::string& theResultEntry);
420 }
421
422 #endif