Salome HOME
41152cfcf319fd49084f7e95e8455c8b08a7daeb
[modules/visu.git] / src / OBJECT / VISU_Actor.h
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   : 
24 //  Author : 
25 //  Module : VISU
26
27 #ifndef VISU_ACTOR_H
28 #define VISU_ACTOR_H
29
30 #include "VISU_OBJECT.h"
31
32 #include "SALOME_Actor.h"
33 #include "VISU_ActorBase.h"
34 #include "VISU_BoostSignals.h"
35 #include "SVTK_DeviceActor.h"
36
37 #include <string>
38 #include <vtkTimeStamp.h>
39 #include <vtkSmartPointer.h>
40
41 class vtkProp;
42 class vtkProperty;
43 class vtkTextMapper;
44 class vtkTextActor;
45 class vtkInteractorStyle;
46 class vtkCallbackCommand;
47 class VTKViewer_ShrinkFilter;
48 class VISU_PipeLine;
49 class vtkPlane;
50 class vtkImplicitFunctionCollection;
51 class vtkFeatureEdges;
52 class vtkTextProperty;
53 class vtkCellCenters;
54 class vtkLabeledDataMapper;
55 class vtkMaskPoints;
56 class vtkActor2D;
57
58 class VTKViewer_FramedTextActor;
59
60 class VISU_SelectVisiblePoints;
61
62 #if !defined(VTK_XVERSION)
63 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
64 #endif
65
66 namespace SVTK
67 {
68   namespace Representation
69   {
70     const Type Surfaceframe = Insideframe + 1;
71     const Type FeatureEdges = Insideframe + 2;
72   }
73 }
74
75 namespace VISU 
76 {
77   class Prs3d_i;
78 }
79
80 //----------------------------------------------------------------------------
81 class VISU_OBJECT_EXPORT VISU_Actor : public VISU_ActorBase
82 {
83  public:
84   vtkTypeMacro(VISU_Actor, VISU_ActorBase);
85
86   //static 
87   //VISU_Actor* 
88   //New();
89
90   //! Copies all properties from the given actor
91   virtual
92   void
93   DeepCopy(VISU_Actor *theActor);
94
95   virtual
96   void
97   ShallowCopyPL(VISU_PipeLine* thePipeLine);
98
99   //----------------------------------------------------------------------------
100   virtual
101   void
102   setIO(const Handle(SALOME_InteractiveObject)& theIO);
103
104   //----------------------------------------------------------------------------
105   VISU::Prs3d_i* 
106   GetPrs3d();
107
108   virtual
109   void
110   SetPrs3d(VISU::Prs3d_i* thePrs3d);
111
112   virtual
113   void
114   SetVisibility(int theMode);
115
116   bool
117   ShouldBeDisplayed();
118
119   virtual
120   void
121   SetPosition( double thePosition[3] );
122
123   virtual
124   void
125   SetPosition( double theX, double theY, double theZ );
126
127   //----------------------------------------------------------------------------
128   virtual
129   VISU_PipeLine* 
130   GetPipeLine();
131
132   virtual 
133   void
134   SetPipeLine(VISU_PipeLine* thePipeLine);
135
136   //----------------------------------------------------------------------------
137   virtual
138   void
139   SetRepresentation(int theMode);
140
141   //----------------------------------------------------------------------------
142   virtual
143   bool
144   IsShrunkable();
145
146   virtual
147   bool
148   IsShrunk();
149
150   virtual
151   void
152   SetShrink();
153
154   virtual
155   void
156   UnShrink(); 
157
158   virtual
159   void
160   SetShrinkable(bool theIsShrinkable);
161
162   virtual
163   void
164   SetShrinkFactor(vtkFloatingPointType theFactor = 0.8); 
165
166   virtual
167   vtkFloatingPointType
168   GetShrinkFactor();
169
170   //----------------------------------------------------------------------------
171   virtual
172   bool
173   IsFeatureEdgesAllowed();
174
175   virtual
176   void
177   SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed);
178
179   virtual
180   bool
181   IsFeatureEdgesEnabled();
182
183   virtual
184   void
185   SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled);
186
187   virtual
188   vtkFloatingPointType
189   GetFeatureEdgesAngle();
190
191   virtual
192   void
193   SetFeatureEdgesAngle(vtkFloatingPointType theAngle = 30.0); 
194
195   virtual
196   void
197   GetFeatureEdgesFlags(bool& theIsFeatureEdges,
198                        bool& theIsBoundaryEdges,
199                        bool& theIsManifoldEdges,
200                        bool& theIsNonManifoldEdges);
201
202   virtual
203   void
204   SetFeatureEdgesFlags(bool theIsFeatureEdges,
205                        bool theIsBoundaryEdges,
206                        bool theIsManifoldEdges,
207                        bool theIsNonManifoldEdges);
208
209   virtual
210   bool
211   GetFeatureEdgesColoring();
212
213   virtual
214   void
215   SetFeatureEdgesColoring(bool theIsColoring);
216
217   //----------------------------------------------------------------------------
218   virtual
219   void
220   SetOpacity(vtkFloatingPointType theValue);
221
222   virtual
223   vtkFloatingPointType
224   GetOpacity();
225
226   virtual
227   void
228   SetLineWidth(vtkFloatingPointType theLineWidth);
229
230   virtual
231   vtkFloatingPointType
232   GetLineWidth();
233  
234   //----------------------------------------------------------------------------
235   virtual
236   void
237   AddToRender( vtkRenderer* ); 
238
239   virtual
240   void
241   RemoveFromRender( vtkRenderer* );
242
243   //----------------------------------------------------------------------------
244   //! Just to update visibility of the highlight devices
245   virtual
246   void
247   highlight(bool theHighlight);  
248
249   //! To process prehighlight (called from #SVTK_InteractorStyle)
250   virtual
251   bool
252   PreHighlight(vtkInteractorStyle* theInteractorStyle, 
253                SVTK_SelectionEvent* theSelectionEvent,
254                bool theIsHighlight);
255
256   //! To process highlight (called from #SVTK_InteractorStyle)
257   virtual
258   bool
259   Highlight(vtkInteractorStyle* theInteractorStyle, 
260             SVTK_SelectionEvent* theSelectionEvent,
261             bool theIsHighlight);
262
263   //! Internal highlight.
264   virtual
265   void
266   Highlight(bool theIsHighlight);
267
268   virtual
269   void 
270   SetVTKMapping(bool theIsVTKMapping); 
271
272   virtual
273   bool 
274   IsVTKMapping() const;
275
276   virtual
277   vtkDataSet* 
278   GetInput(); 
279
280   //! Gets memory size used by the instance (bytes).
281   virtual
282   unsigned long int
283   GetMemorySize();
284  
285   //----------------------------------------------------------------------------
286   virtual
287   vtkIdType
288   GetNodeObjId(vtkIdType theID);
289
290   virtual
291   vtkIdType
292   GetNodeVTKID(vtkIdType theID);
293
294   virtual
295   vtkFloatingPointType* 
296   GetNodeCoord(vtkIdType theObjID);
297
298   virtual
299   vtkIdType
300   GetElemObjId(vtkIdType theID);
301
302   virtual
303   vtkIdType
304   GetElemVTKID(vtkIdType theID);
305
306   virtual
307   vtkCell* 
308   GetElemCell(vtkIdType theObjID);
309
310   //----------------------------------------------------------------------------
311   virtual void RemoveAllClippingPlanes();
312
313   virtual vtkIdType GetNumberOfClippingPlanes();
314
315   virtual bool AddClippingPlane(vtkPlane* thePlane);
316
317   virtual vtkPlane* GetClippingPlane(vtkIdType theID);
318
319   virtual vtkImplicitFunctionCollection* GetClippingPlanes();
320
321   //----------------------------------------------------------------------------
322   //! Apply the picking settings on the actor.
323   void
324   UpdatePickingSettings();
325
326   //----------------------------------------------------------------------------
327   //! Methods for values labeling
328   virtual 
329   void 
330   SetValuesLabeled( const bool theIsValLabeled );
331
332   virtual 
333   bool 
334   GetValuesLabeled() const;
335
336   virtual
337   vtkDataSet*
338   GetValLabelsInput();
339
340   vtkTextProperty* 
341   GetsValLabelsProps() const;
342
343   enum EQuadratic2DRepresentation { eLines = 0, eArcs };
344
345   virtual
346     EQuadratic2DRepresentation GetQuadratic2DRepresentation() const;
347   
348   virtual void 
349     SetQuadratic2DRepresentation( EQuadratic2DRepresentation theMode );
350   
351   
352  protected:
353   VISU_Actor();
354
355   virtual
356   ~VISU_Actor();
357  
358   virtual 
359   void
360   SetMapperInput(vtkDataSet* theDataSet) = 0;
361
362   virtual
363   VISU_PipeLine* 
364   GetCurrentPL();
365
366   //----------------------------------------------------------------------------
367   bool
368   isSubElementsHighlighted();
369
370   //----------------------------------------------------------------------------
371   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
372
373   //! Main process VTK event method
374   static
375   void
376   ProcessEvents(vtkObject* theObject, 
377                 unsigned long theEvent,
378                 void* theClientData, 
379                 void* theCallData);
380
381   //----------------------------------------------------------------------------
382  private:
383   void
384   ResetTextActor();
385
386   //----------------------------------------------------------------------------
387  protected:
388   vtkFloatingPointType myPriority;
389   bool myIsVTKMapping;
390   VISU::Prs3d_i* myPrs3d;
391   vtkSmartPointer<VISU_PipeLine> myPipeLine;
392
393   vtkSmartPointer<VTKViewer_ShrinkFilter> myShrinkFilter;
394   bool myIsShrinkable;
395   bool myIsShrunk;
396
397   vtkSmartPointer<vtkTextMapper> myAnnotationMapper;
398 #if (VTK_XVERSION < 0x050100)
399   vtkSmartPointer<vtkTextActor>  myAnnotationActor;
400 #else
401   vtkSmartPointer<vtkActor2D>  myAnnotationActor;
402 #endif
403
404   vtkSmartPointer<VTKViewer_FramedTextActor> myTextActor;
405
406   vtkSmartPointer<vtkFeatureEdges> myFeatureEdges;
407   bool myIsFeatureEdgesAllowed;
408   bool myIsFeatureEdgesEnabled;
409
410   Selection_Mode myLastSelectionMode;
411   bool myIsSubElementsHighlighted;
412   
413   // fields for values labeling
414   bool                    myIsValLabeled;
415   vtkDataSet*             myValLblDataSet;
416   vtkActor2D*             myValLabels;
417   vtkMaskPoints*          myValMaskPoints;
418   vtkCellCenters*         myValCellCenters;
419   vtkLabeledDataMapper*   myValLabeledDataMapper;
420   VISU_SelectVisiblePoints* myValSelectVisiblePoints;
421 };
422
423 #endif //VISU_ACTOR_H