Salome HOME
a8c9ac999134dd011d9694ad704b4e8de281cfac
[modules/gui.git] / src / SVTK / SALOME_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 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
23 //  File   : SALOME_Actor.h
24 //  Author : Nicolas REJNERI
25 //  Module : SALOME
26 //  $Header$
27 //
28 #ifndef SALOME_ACTOR_H
29 #define SALOME_ACTOR_H
30
31 #include "SVTK_SelectionEvent.h"
32 #include "SVTK_Selector.h"
33 #include "SVTK.h"
34
35 class Handle(SALOME_InteractiveObject);
36
37 // undefining min and max because CASCADE's defines them and
38 // it clashes with std::min(), std::max()
39 #undef min
40 #undef max
41
42 #include "VTKViewer_Actor.h"
43
44 #include <vtkSmartPointer.h>
45
46 class vtkPointPicker;
47 class vtkCellPicker;
48 class vtkOutlineSource;
49 class vtkInteractorStyle;
50 class vtkRenderWindowInteractor;
51
52 class SVTK_Actor;
53 class SVTK_RectPicker;
54 class SVTK_InteractorStyle;
55
56 SVTK_EXPORT extern int SALOME_POINT_SIZE;
57 SVTK_EXPORT extern int SALOME_LINE_WIDTH;
58
59 #ifdef WIN32
60 #pragma warning ( disable:4251 )
61 #endif
62
63 //! The class is a basic one for all SALOME VTK presentation.
64 /*!
65   It provide highlight and prehighlight capabilites,
66   common way to publish and remove VTK presentation, 
67   mapping of VTK and object IDs and so on.
68  */
69 class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor 
70 {
71  public:
72   static SALOME_Actor* New();
73   
74   vtkTypeMacro(SALOME_Actor,VTKViewer_Actor);
75
76   //----------------------------------------------------------------------------
77   //! To check, if the #SALOME_Actor has a reference to #SALOME_InteractiveObject
78   virtual
79   Standard_Boolean 
80   hasIO();
81
82   //! Get correspoinding reference to #SALOME_InteractiveObject
83   virtual 
84   const Handle(SALOME_InteractiveObject)& 
85   getIO(); 
86
87   //! Set reference to #SALOME_InteractiveObject
88   virtual
89   void
90   setIO(const Handle(SALOME_InteractiveObject)& theIO);
91
92   //! Name the #SALOME_Actor
93   virtual
94   void
95   setName(const char* theName);
96
97   //----------------------------------------------------------------------------
98   //! Apply view transformation
99   virtual
100   void
101   SetTransform(VTKViewer_Transform* theTransform); 
102
103   //! Apply additional position
104   virtual
105   void
106   SetPosition(vtkFloatingPointType _arg1, 
107               vtkFloatingPointType _arg2, 
108               vtkFloatingPointType _arg3);
109
110   //! Apply additional position
111   virtual
112   void
113   SetPosition(vtkFloatingPointType _arg[3]);
114
115   //----------------------------------------------------------------------------
116   //! Visibility management
117   virtual
118   void
119   SetVisibility( int );
120
121   //----------------------------------------------------------------------------
122   //! To publish the actor an all its internal devices
123   virtual
124   void
125   AddToRender(vtkRenderer* theRendere); 
126
127   //! To remove the actor an all its internal devices
128   virtual
129   void
130   RemoveFromRender(vtkRenderer* theRendere);
131
132   //! Get reference on renderer where it is published
133   vtkRenderer*
134   GetRenderer();
135
136   //----------------------------------------------------------------------------
137   //! To set interactor in order to use #vtkInteractorObserver devices
138   virtual
139   void
140   SetInteractor(vtkRenderWindowInteractor* theInteractor);
141
142   //! Put a request to redraw the view 
143   virtual
144   void
145   Update();
146
147   //----------------------------------------------------------------------------
148   //! Set selector in order to the actor at any time can restore current selection
149   virtual
150   void
151   SetSelector(SVTK_Selector* theSelector);
152
153   //! Just to update visibility of the highlight devices
154   virtual
155   void
156   highlight(bool theHighlight);  
157
158   //! To map current selection to VTK representation
159   virtual
160   void
161   Highlight(bool theHighlight);  
162
163   //----------------------------------------------------------------------------
164   //! To process prehighlight (called from #SVTK_InteractorStyle)
165   virtual
166   bool
167   PreHighlight(vtkInteractorStyle* theInteractorStyle, 
168                SVTK_SelectionEvent* theSelectionEvent,
169                bool theIsHighlight);
170
171   //! To process highlight (called from #SVTK_InteractorStyle)
172   virtual 
173   bool
174   Highlight(vtkInteractorStyle* theInteractorStyle, 
175             SVTK_SelectionEvent* theSelectionEvent,
176             bool theIsHighlight);
177
178   //----------------------------------------------------------------------------
179   //! To set up a picker for nodal selection (initialized by #SVTK_Renderer::AddActor)
180   void
181   SetPointPicker(vtkPointPicker* thePointPicker); 
182
183   //! To set up a picker for cell selection (initialized by #SVTK_Renderer::AddActor)
184   void
185   SetCellPicker(vtkCellPicker* theCellPicker); 
186
187   //! To set up a picker for point rectangle selection (initialized by #SVTK_Renderer::AddActor)
188   void
189   SetPointRectPicker(SVTK_RectPicker* theRectPicker);
190
191   //! To set up a picker for cell rectangle selection (initialized by #SVTK_Renderer::AddActor)
192   void
193   SetCellRectPicker(SVTK_RectPicker* theRectPicker);
194
195   //----------------------------------------------------------------------------
196   //! To set up a prehighlight property (initialized by #SVTK_Renderer::AddActor)
197   void
198   SetPreHighlightProperty(vtkProperty* theProperty);
199
200   //! To set up a highlight property (initialized by #SVTK_Renderer::AddActor)
201   void
202   SetHighlightProperty(vtkProperty* theProperty);
203
204  protected:
205   //----------------------------------------------------------------------------
206   vtkRenderWindowInteractor* myInteractor;
207   vtkRenderer* myRenderer;
208
209   Handle(SALOME_InteractiveObject) myIO;
210
211   SALOME_Actor();
212   ~SALOME_Actor();
213
214  protected:
215   Selection_Mode mySelectionMode;
216   vtkSmartPointer<SVTK_Selector> mySelector;
217
218   //----------------------------------------------------------------------------
219   // Highlight/ Prehighlight devices
220   vtkSmartPointer<vtkPointPicker> myPointPicker;
221   vtkSmartPointer<vtkCellPicker> myCellPicker;
222
223   vtkSmartPointer<SVTK_RectPicker> myPointRectPicker;
224   vtkSmartPointer<SVTK_RectPicker> myCellRectPicker;
225
226   vtkSmartPointer<SVTK_Actor> myPreHighlightActor;
227   vtkSmartPointer<SVTK_Actor> myHighlightActor;
228
229   vtkSmartPointer<VTKViewer_Actor> myOutlineActor;
230   vtkSmartPointer<vtkOutlineSource> myOutline;
231 };
232
233 #ifdef WIN32
234 #pragma warning ( default:4251 )
235 #endif
236
237 #endif // SALOME_ACTOR_H