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