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