Salome HOME
updated copyright message
[modules/gui.git] / src / SVTK / SALOME_Actor.h
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
24 //  File   : SALOME_Actor.h
25 //  Author : Nicolas REJNERI
26
27 #ifndef SALOME_ACTOR_H
28 #define SALOME_ACTOR_H
29
30 #include "SVTK_SelectionEvent.h"
31 #include "SVTK_Selector.h"
32 #include "SVTK.h"
33
34 class SALOME_InteractiveObject;
35
36 // undefining min and max because CASCADE's defines them and
37 // it clashes with std::min(), std::max()
38 #undef min
39 #undef max
40
41 #include <VTKViewer_Actor.h>
42 #include <VTKViewer_MarkerDef.h>
43
44 #include <vtkSmartPointer.h>
45
46 class vtkAbstractPicker;
47 class vtkPointPicker;
48 class vtkCellPicker;
49 class vtkOutlineSource;
50 class vtkInteractorStyle;
51 class vtkRenderWindowInteractor;
52
53 class VTKViewer_FramedTextActor;
54
55 class SVTK_Actor;
56 class SVTK_AreaPicker;
57 class SVTK_InteractorStyle;
58
59 SVTK_EXPORT extern int SALOME_POINT_SIZE;
60 SVTK_EXPORT extern int SALOME_LINE_WIDTH;
61
62 #ifdef WIN32
63 #pragma warning ( disable:4251 )
64 #endif
65
66 //! The class is a basic one for all SALOME VTK presentation.
67 /*!
68   It provide highlight and prehighlight capabilites,
69   common way to publish and remove VTK presentation, 
70   mapping of VTK and object IDs and so on.
71  */
72 class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor 
73 {
74  public:
75   static SALOME_Actor* New();
76   
77   vtkTypeMacro(SALOME_Actor,VTKViewer_Actor)
78
79   //----------------------------------------------------------------------------
80   //! To check, if the #SALOME_Actor has a reference to #SALOME_InteractiveObject
81   virtual
82   Standard_Boolean 
83   hasIO();
84
85   //! Get correspoinding reference to #SALOME_InteractiveObject
86   virtual 
87   const Handle(SALOME_InteractiveObject)& 
88   getIO(); 
89
90   //! Set reference to #SALOME_InteractiveObject
91   virtual
92   void
93   setIO(const Handle(SALOME_InteractiveObject)& theIO);
94
95   //! Name the #SALOME_Actor
96   virtual
97   void
98   setName(const char* theName);
99
100   //----------------------------------------------------------------------------
101   //! Apply view transformation
102   virtual
103   void
104   SetTransform(VTKViewer_Transform* theTransform); 
105
106   //! Apply additional position
107   virtual
108   void
109   SetPosition(double _arg1, 
110               double _arg2, 
111               double _arg3);
112
113   //! Apply additional position
114   virtual
115   void
116   SetPosition(double _arg[3]);
117
118   //----------------------------------------------------------------------------
119   //! Visibility management
120   virtual
121   void
122   SetVisibility( int );
123
124   //! Gets know whether the actor should be displayed or not
125   virtual
126   bool
127   ShouldBeDisplayed();
128
129   //----------------------------------------------------------------------------
130   //! To publish the actor an all its internal devices
131   virtual
132   void
133   AddToRender(vtkRenderer* theRendere); 
134
135   //! To remove the actor an all its internal devices
136   virtual
137   void
138   RemoveFromRender(vtkRenderer* theRendere);
139
140   //! Get reference on renderer where it is published
141   vtkRenderer*
142   GetRenderer();
143
144   //----------------------------------------------------------------------------
145   //! To set interactor in order to use #vtkInteractorObserver devices
146   virtual
147   void
148   SetInteractor(vtkRenderWindowInteractor* theInteractor);
149
150   //! Put a request to redraw the view 
151   virtual
152   void
153   Update();
154
155   //----------------------------------------------------------------------------
156   //! Set selector in order to the actor at any time can restore current selection
157   virtual
158   void
159   SetSelector(SVTK_Selector* theSelector);
160
161   //! Just to update visibility of the highlight devices
162   virtual
163   void
164   highlight(bool theHighlight);  
165
166   //! To map current selection to VTK representation
167   virtual
168   void
169   Highlight(bool theHighlight);  
170
171   //----------------------------------------------------------------------------
172   //! To process prehighlight (called from #SVTK_InteractorStyle)
173   virtual
174   bool
175   PreHighlight(vtkInteractorStyle* theInteractorStyle, 
176                SVTK_SelectionEvent* theSelectionEvent,
177                bool theIsHighlight);
178
179   //! To process highlight (called from #SVTK_InteractorStyle)
180   virtual 
181   bool
182   Highlight(vtkInteractorStyle* theInteractorStyle, 
183             SVTK_SelectionEvent* theSelectionEvent,
184             bool theIsHighlight);
185
186   //----------------------------------------------------------------------------
187   //! To get flag of displaying of name actor
188   virtual
189   bool
190   IsDisplayNameActor() const;
191
192   //! To set flag of displaying of name actor
193   virtual
194   void
195   SetIsDisplayNameActor(bool theIsDisplayNameActor);
196
197   //! To set text of name actor
198   virtual
199   void
200   SetNameActorText(const char* theText);
201
202   //! To set offset of name actor
203   virtual
204   void
205   SetNameActorOffset(double theOffset[2]);
206
207   //! To get size of name actor
208   virtual
209   void
210   GetNameActorSize(vtkRenderer* theRenderer, double theSize[2]) const;
211
212   //! To update visibility of name actors
213   virtual
214   void
215   UpdateNameActors();
216
217   //----------------------------------------------------------------------------
218   //! Set standard point marker
219   virtual
220   void
221   SetMarkerStd( VTK::MarkerType, VTK::MarkerScale );
222
223   //! Set custom point marker
224   virtual
225   void
226   SetMarkerTexture( int, VTK::MarkerTexture );
227
228   //! Get type of the point marker
229   virtual
230   VTK::MarkerType
231   GetMarkerType();
232
233   //! Get scale of the point marker
234   virtual
235   VTK::MarkerScale
236   GetMarkerScale();
237
238   //! Get texture identifier of the point marker
239   virtual
240   int
241   GetMarkerTexture();
242
243   //----------------------------------------------------------------------------
244   //! To set up a picker for nodal selection (initialized by #SVTK_Renderer::AddActor)
245   void
246   SetPointPicker(vtkPointPicker* thePointPicker); 
247
248   //! To set up a picker for cell selection (initialized by #SVTK_Renderer::AddActor)
249   void
250   SetCellPicker(vtkCellPicker* theCellPicker); 
251
252   //! To set up a picker for point rectangle selection (initialized by #SVTK_Renderer::AddActor)
253   void
254   SetPointAreaPicker(SVTK_AreaPicker* theAreaPicker);
255
256   //! To set up a picker for cell rectangle selection (initialized by #SVTK_Renderer::AddActor)
257   void
258   SetCellAreaPicker(SVTK_AreaPicker* theAreaPicker);
259
260   //----------------------------------------------------------------------------
261   //! To find a gravity center of object
262   double* GetGravityCenter( int );
263
264   //----------------------------------------------------------------------------
265   //! To set up a prehighlight property (initialized by #SVTK_Renderer::AddActor)
266   void
267   SetPreHighlightProperty(vtkProperty* theProperty);
268
269   //! To set up a highlight property (initialized by #SVTK_Renderer::AddActor)
270   void
271   SetHighlightProperty(vtkProperty* theProperty);
272
273  protected:
274   //----------------------------------------------------------------------------
275   vtkRenderWindowInteractor* myInteractor;
276   vtkRenderer* myRenderer;
277
278   Handle(SALOME_InteractiveObject) myIO;
279
280   SALOME_Actor();
281   ~SALOME_Actor();
282
283  protected:
284   Selection_Mode mySelectionMode;
285   vtkSmartPointer<SVTK_Selector> mySelector;
286
287   //----------------------------------------------------------------------------
288   // Highlight/ Prehighlight devices
289   vtkSmartPointer<vtkPointPicker> myPointPicker;
290   vtkSmartPointer<vtkCellPicker> myCellPicker;
291
292   vtkSmartPointer<SVTK_AreaPicker> myPointAreaPicker;
293   vtkSmartPointer<SVTK_AreaPicker> myCellAreaPicker;
294
295   vtkSmartPointer<SVTK_Actor> myPreHighlightActor;
296   vtkSmartPointer<SVTK_Actor> myHighlightActor;
297
298   vtkSmartPointer<VTKViewer_Actor> myOutlineActor;
299   vtkSmartPointer<vtkOutlineSource> myOutline;
300
301   bool myIsDisplayNameActor;
302   vtkSmartPointer<VTKViewer_FramedTextActor> myNameActor;
303 };
304
305 namespace SVTK
306 {
307   class SVTK_EXPORT TPickLimiter
308   {
309     vtkAbstractPicker* myPicker;
310   public:
311     TPickLimiter(vtkAbstractPicker*, SALOME_Actor*);
312     ~TPickLimiter();
313   };
314 }
315
316 #ifdef WIN32
317 #pragma warning ( default:4251 )
318 #endif
319
320 #endif // SALOME_ACTOR_H