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