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