Salome HOME
3716f95018c7b0bac89d7e510170e7c13cc15baf
[modules/gui.git] / src / SVTK / SVTK_Renderer.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 VTKViewer : build VTK viewer into Salome desktop
24 //  File   : 
25 //  Author : 
26
27 #ifndef SVTK_Renderer_h
28 #define SVTK_Renderer_h
29
30 #include "SVTK.h"
31 #include "VTKViewer.h"
32 #include "SALOME_ListIO.hxx"
33
34 #include <vtkObject.h>
35 #include <vtkSmartPointer.h>
36
37 class vtkRenderer;
38 class vtkCallbackCommand;
39 class vtkRenderWindowInteractor;
40
41 class vtkPicker;
42 class vtkPointPicker;
43 class vtkCellPicker;
44 class vtkProperty;
45
46 class SVTK_AreaPicker;
47
48 class VTKViewer_Trihedron;
49 class VTKViewer_Transform;
50 class SVTK_CubeAxesActor2D;
51 class VTKViewer_Actor;
52 class SVTK_Selector;
53
54 #ifdef WIN32
55 #pragma warning ( disable:4251 )
56 #endif
57
58 /*! 
59   \class SVTK_Renderer
60   The class is a container for #vtkRenderer instance.
61   Main goal of the class is to apply common behaviour to all #SALOME_Actor, like
62   selection and preselection colors.
63   Also, the class is responsible for management of internal actors like trihedron an so on.
64  */
65 class SVTK_EXPORT SVTK_Renderer : public vtkObject
66 {
67  public:
68   vtkTypeMacro(SVTK_Renderer,vtkObject)
69   static SVTK_Renderer* New();
70
71   //----------------------------------------------------------------------------
72   //! Get its device
73   vtkRenderer* 
74   GetDevice();
75
76   //! Initialize the class
77   virtual
78   void 
79   Initialize(vtkRenderWindowInteractor* theInteractor,
80              SVTK_Selector* theSelector);
81
82   //----------------------------------------------------------------------------
83   //! Publishes pointed actor into the renderer
84   virtual
85   void 
86   AddActor(VTKViewer_Actor* theActor, bool theIsAdjustActors = true);
87
88   //! Removes pointed actor from the renderer
89   virtual
90   void 
91   RemoveActor(VTKViewer_Actor* theActor, bool theIsAdjustActors = true);
92
93   //! Get special container that keeps scaling of the scene 
94   VTKViewer_Transform* 
95   GetTransform();
96
97   //! Allows to apply a scale on the whole scene
98   virtual
99   void
100   SetScale( double theScale[3] );
101
102   //! Allows to get a scale that is applied on the whole scene
103   void
104   GetScale( double theScale[3] );
105
106   //----------------------------------------------------------------------------
107   //! Applies color and size (PointSize and LineWidth) of primitives in selection mode
108   void
109   SetSelectionProp(const double& theRed = 1, 
110                    const double& theGreen = 1,
111                    const double& theBlue = 0, 
112                    const int& theWidth = 5);
113
114   //! Applies color and size (PointSize and LineWidth) of primitives in preselection mode
115   void
116   SetPreselectionProp(const double& theRed = 0, 
117                       const double& theGreen = 1,
118                       const double& theBlue = 1, 
119                       const int& theWidth = 5);
120
121   //! Setup requested tolerance for the picking
122   void
123   SetSelectionTolerance(const double& theTolNodes = 0.025, 
124                         const double& theTolCell = 0.001,
125                         const double& theTolObjects = 0.025);
126
127   //----------------------------------------------------------------------------
128   //! Adjust all intenal actors (trihedron and graduated rules) to the scene
129   void
130   AdjustActors();
131
132   //! Set size of the trihedron in percents from bounding box of the scene
133   void
134   SetTrihedronSize(double theSize, const bool theRelative = true);
135  
136   //! Get size of the trihedron in percents from bounding box of the scene
137   double  
138   GetTrihedronSize() const;
139
140   //! Shows if the size of the trihedron is relative
141   bool  
142   IsTrihedronRelative() const;
143
144   //----------------------------------------------------------------------------
145   //! Get trihedron control
146   VTKViewer_Trihedron* 
147   GetTrihedron();
148
149   //! Is trihedron displayed
150   bool 
151   IsTrihedronDisplayed();
152
153   //! Toggle trihedron visibility
154   void 
155   OnViewTrihedron(); 
156
157   //! Set Toggle trihedron visibility
158
159   void
160   SetTrihedronVisibility( const bool );
161
162   //! Adjust size of the trihedron to the bounding box of the scene
163   void 
164   OnAdjustTrihedron();
165
166   //----------------------------------------------------------------------------
167   //! Get graduated rules control
168   SVTK_CubeAxesActor2D* 
169   GetCubeAxes();
170
171   //! Is graduated rules displayed
172   bool 
173   IsCubeAxesDisplayed();
174
175   //! Toggle graduated rules visibility
176   void 
177   OnViewCubeAxes();
178
179   //! Adjust size of the graduated rules to the bounding box of the scene
180   void 
181   OnAdjustCubeAxes();
182
183   //----------------------------------------------------------------------------
184   //! Fit all presentation in the scene into the window
185   void OnFitAll(); 
186
187   //----------------------------------------------------------------------------
188   //! Fit all selected presentation in the scene
189   void onFitSelection();
190
191   //! Fit given presentations in the scene
192   void OnFitIObjects(const SALOME_ListIO& objects);
193
194   //! Set camera into predefined state
195   void OnResetView(); 
196
197   //! Reset camera clipping range to adjust the range to the bounding box of the scene
198   void OnResetClippingRange(); 
199
200   //! To reset direction of the camera to front view
201   void OnFrontView(); 
202
203   //! To reset direction of the camera to back view
204   void OnBackView(); 
205
206   //! To reset direction of the camera to top view
207   void OnTopView();
208
209   //! To reset direction of the camera to bottom view
210   void OnBottomView();
211
212   //! To reset direction of the camera to right view
213   void OnRightView(); 
214
215   //! To reset direction of the camera to left view
216   void OnLeftView();     
217
218   //! To rotate view 90 degrees clockwise
219   void onClockWiseView();
220
221   //! To rotate view 90 degrees counterclockwise
222   void onAntiClockWiseView();
223
224 protected:
225   SVTK_Renderer();
226   ~SVTK_Renderer();
227
228   virtual
229   bool
230   OnAdjustActors();
231
232   //----------------------------------------------------------------------------
233   // Priority at which events are processed
234   double myPriority;
235
236   // Used to process events
237   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
238
239   // Description:
240   // Main process event method
241   static void ProcessEvents(vtkObject* object, 
242                             unsigned long event,
243                             void* clientdata, 
244                             void* calldata);
245   
246   vtkSmartPointer<vtkRenderer> myDevice;
247   vtkRenderWindowInteractor* myInteractor;
248   vtkSmartPointer<SVTK_Selector> mySelector;
249
250   //----------------------------------------------------------------------------
251   vtkSmartPointer<VTKViewer_Transform> myTransform;
252
253   //----------------------------------------------------------------------------
254   // Highlight/ Prehighlight devices
255   vtkSmartPointer<vtkPointPicker> myPointPicker;
256   vtkSmartPointer<vtkCellPicker> myCellPicker;
257
258   vtkSmartPointer<SVTK_AreaPicker> myPointAreaPicker;
259   vtkSmartPointer<SVTK_AreaPicker> myCellAreaPicker;
260
261   vtkSmartPointer<vtkProperty> myPreHighlightProperty;
262   vtkSmartPointer<vtkProperty> myHighlightProperty;
263
264   //----------------------------------------------------------------------------
265   vtkSmartPointer<SVTK_CubeAxesActor2D> myCubeAxes;
266   vtkSmartPointer<VTKViewer_Trihedron> myTrihedron;  
267   double myTrihedronSize;
268   bool myIsTrihedronRelative;
269   double myBndBox[6];
270 };
271
272 #ifdef WIN32
273 #pragma warning ( default:4251 )
274 #endif
275
276 #endif