Salome HOME
6f54053ccfdbd1d2c715a54c38fca958b70a2bf8
[modules/visu.git] / src / VISU_I / VISU_Prs3d_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_PrsObject_i.hxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26 //
27 #ifndef VISU_Prs3d_i_HeaderFile
28 #define VISU_Prs3d_i_HeaderFile
29
30 #include "VISU_PrsObject_i.hh"
31
32 #include "VISU_ActorFactory.h"
33 #include "VISU_ConvertorDef.hxx"
34
35 #include "SALOME_GenericObj_i.hh"
36 #include "SALOME_GenericObjPointer.hh"
37 #include "SALOME_InteractiveObject.hxx"
38
39 #include "VTKViewer.h"
40
41 #include <vtkSmartPointer.h>
42 #include <vtkTimeStamp.h>
43
44 class VISU_PipeLine;
45 class VISU_ActorBase;
46 class VISU_Actor;
47
48 class vtkPlane;
49 class vtkActorCollection;
50 class vtkDataSet;
51
52 namespace VISU
53 {
54   //----------------------------------------------------------------------------
55   class Result_i;
56
57
58   //----------------------------------------------------------------------------
59   struct TResultObserver: public virtual boost::signalslib::trackable
60   {
61     virtual
62     void
63     UpdateFromResult(Result_i* theResult) = 0;
64   };
65
66
67   //----------------------------------------------------------------------------
68   //! Base class for all VTK 3D presentations.
69   /*!
70     It is a root class for a middle level of VISU functionality.
71     Almost all functionality of the the class implemented through redirection 
72     external requestes to its VISU_PipeLine.
73     It define an interface and implement the following topics:
74     - provide persistent mechanism;
75     - implement basic actor management (CreateActor, UpdateActor, UpdateActors, RemoveActor and RemoveActors);
76     - implement common 3D functionality like "clipping planes" and offset.
77   */
78   class VISU_I_EXPORT Prs3d_i : public virtual POA_VISU::Prs3d,
79                                 public virtual SALOME::GenericObj_i,
80                                 public virtual TActorFactory,
81                                 public virtual PrsObject_i
82
83   {
84     Prs3d_i(const Prs3d_i&);
85
86   public:
87     //----------------------------------------------------------------------------
88     typedef PrsObject_i TSuperClass;
89     typedef VISU::Prs3d TInterface;
90
91     //----------------------------------------------------------------------------
92     //! A constructor to create a fresh instance of the class
93     Prs3d_i();
94
95     //! To create a deep copy from another instance of the class
96     virtual
97     void
98     SameAs(const Prs3d_i* theOrigin);
99
100     virtual
101     ~Prs3d_i();
102
103     //----------------------------------------------------------------------------
104     virtual
105     CORBA::Boolean 
106     Apply(bool theReInit);
107
108     //----------------------------------------------------------------------------
109     void 
110     SetCResult(Result_i* theResult);
111
112     Result_i* 
113     GetCResult() const;
114
115     virtual
116     void 
117     SetResultObject(VISU::Result_ptr theResult);
118
119     virtual
120     VISU::Result_ptr
121     GetResultObject();
122
123     //----------------------------------------------------------------------------
124     virtual
125     void 
126     SetMeshName(const char* theMeshName);
127
128     virtual
129     char*
130     GetMeshName();
131
132     std::string
133     GetCMeshName() const;
134
135     //----------------------------------------------------------------------------
136     //! To generate an unique type name for the class (used into persistent functionality)
137     virtual
138     const char* 
139     GetComment() const = 0;
140
141     //! To generate an unique name for the instance of the class
142     virtual
143     QString
144     GenerateName() = 0;
145
146     //! To save paramters of the instance to std::ostringstream
147     virtual
148     void
149     ToStream(std::ostringstream& theStr);
150
151     //! To restore paramters of the instance from Storable::TRestoringMap
152     virtual
153     Storable* 
154     Restore(SALOMEDS::SObject_ptr theSObject,
155             const Storable::TRestoringMap& theMap);
156
157     //----------------------------------------------------------------------------
158     //! Get corresponding SALOMEDS::SObject
159     virtual
160     SALOMEDS::SObject_var 
161     GetSObject();
162
163     //----------------------------------------------------------------------------
164     //! To update is internal state
165     virtual 
166     void
167     Update();
168
169     //! To remove the instance from study
170     virtual
171     void
172     RemoveFromStudy();
173
174     //----------------------------------------------------------------------------
175     //! Get corresponding VISU_PipeLine
176     VISU_PipeLine* 
177     GetPipeLine() const;
178
179     bool
180     IsPipeLineExists();
181
182     //! Get input of the VISU_PipeLine
183     vtkDataSet* 
184     GetInput();
185
186     //----------------------------------------------------------------------------
187     //! To define a way to create VTK representation of the instance
188     virtual 
189     VISU_Actor* 
190     CreateActor() = 0;
191
192     //! To unregister the pointed actor
193     virtual 
194     void
195     RemoveActor(VISU_ActorBase* theActor);
196
197     //! To unregister all actors of the instance
198     virtual 
199     void
200     RemoveActors();
201
202     //! To update the pointed actor
203     virtual 
204     void
205     UpdateActor(VISU_ActorBase* theActor);
206
207     //! To update all actors of the instance
208     virtual 
209     void
210     UpdateActors();
211
212     //----------------------------------------------------------------------------
213     // Clipping planes
214     void
215     RemoveAllClippingPlanes();
216
217     bool
218     AddClippingPlane(vtkPlane* thePlane);
219
220     vtkIdType
221     GetNumberOfClippingPlanes() const;
222
223     vtkPlane* 
224     GetClippingPlane(vtkIdType theID) const;
225
226     void RemoveClippingPlane(vtkIdType theID);
227
228     void
229     SetPlaneParam(vtkFloatingPointType theDir[3], 
230                   vtkFloatingPointType theDist, 
231                   vtkPlane* thePlane);
232
233     //----------------------------------------------------------------------------
234     void
235     GetBounds(vtkFloatingPointType aBounds[6]);
236
237     int
238     GetNumberOfActors();
239
240     bool
241     HasVisibleActors();
242
243     //! Move the 3D presentation according to the given offset parameters
244     void
245     SetOffset(const CORBA::Float* theOffsets);
246
247     //! Move the 3D presentation according to the given offset parameters
248     virtual
249     void
250     SetOffset(CORBA::Float theDx, 
251               CORBA::Float theDy, 
252               CORBA::Float theDz);
253
254     //! Gets offset parameters for the 3D presentation
255     void
256     GetOffset(CORBA::Float* theOffsets);
257
258     //! Gets offset parameters for the 3D presentation
259     virtual
260     void
261     GetOffset(CORBA::Float& theDx, 
262               CORBA::Float& theDy, 
263               CORBA::Float& theDz);
264
265     //----------------------------------------------------------------------------
266     //! Gets memory size actually used by the presentation (Mb).
267     virtual
268     CORBA::Float
269     GetMemorySize();
270
271     //----------------------------------------------------------------------------
272     //! Gets know whether the factory instance can be used for actor management or not
273     virtual
274     bool 
275     GetActiveState();
276
277     //----------------------------------------------------------------------------
278     //! Return modified time of the presentation
279     virtual
280     unsigned long int 
281     GetMTime();
282
283     //----------------------------------------------------------------------------
284     //! Create and return the interactive object
285     virtual
286     Handle(SALOME_InteractiveObject)
287     GetIO();
288
289     //! Used in derived classes to initilize the IO for actors
290     virtual
291     std::string
292     GetActorEntry();
293
294     //----------------------------------------------------------------------------
295     //! Managing "forced hidden" flag
296     bool
297     IsForcedHidden() const;
298
299     void
300     SetForcedHidden( bool );
301
302   protected:
303     /*! 
304       Used in Apply method to get know whether it is possible to create presentation
305       with the input parameters or not. The derived classes can use this method 
306       to customize Apply behaviour.
307     */
308     virtual 
309     bool 
310     SetInput(bool theReInit);
311
312     //! Restore input parameters if Apply function fails
313     virtual 
314     void 
315     OnRestoreInput();
316
317     //! Used in derived classes to initilize the myPipeLine member
318     void
319     SetPipeLine(VISU_PipeLine* thePipeLine);
320
321     //! Used in derived classes to initilize the myPipeLine member
322     void
323     CreateActor(VISU_Actor* theActor);
324
325     //! Gets or creates VISU_PipeLine instance for actor initilization
326     virtual 
327     VISU_PipeLine* 
328     GetActorPipeLine();
329
330     //! To check dataset validity, throws std::exception if not valid
331     virtual
332     void
333     CheckDataSet();
334
335   protected:
336     vtkTimeStamp myUpdateTime;
337     vtkTimeStamp myParamsTime;
338
339   private:
340     void
341     SetResultEntry(const std::string& theResultEntry);
342
343     std::string
344     GetResultEntry();
345
346     typedef SALOME::GenericObjPtr<VISU::Result_i> TResultPtr;
347     TResultPtr myResult;
348     TResultPtr myPreviousResult;
349
350     std::string myMeshName;
351     std::string myPreviousMeshName;
352
353     CORBA::Float myOffset[3];
354
355     boost::signal0<void> myUpdateActorsSignal;
356     boost::signal0<void> myRemoveActorsFromRendererSignal;
357     vtkSmartPointer<vtkActorCollection> myActorCollection;
358
359     vtkSmartPointer<VISU_PipeLine> myPipeLine;
360
361     Handle(SALOME_InteractiveObject) myIO;
362
363   private:
364     friend class ColoredPrs3dCache_i;
365
366     //! Sets activity flag for the factory instance
367     void
368     SetActiveState(bool theState);
369     
370     bool myIsActiveSatate;
371
372     bool myIsForcedHidden;
373   };
374
375   //----------------------------------------------------------------------------
376 }
377
378 #endif