1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #ifndef SVTK_VIEWWINDOW_H
23 #define SVTK_VIEWWINDOW_H
26 #pragma warning( disable:4251 )
30 #include "SVTK_Selection.h"
31 #include "SUIT_ViewWindow.h"
33 #include "SALOME_InteractiveObject.hxx"
36 #include <vtkSmartPointer.h>
39 class SUIT_ResourceMgr;
41 class VTKViewer_Actor;
42 class VTKViewer_Trihedron;
44 class SVTK_ViewModelBase;
45 //class SVTK_MainWindow;
49 class SVTK_CubeAxesActor2D;
52 class vtkRenderWindow;
53 class vtkRenderWindowInteractor;
54 class vtkInteractorStyle;
55 class SVTK_RenderWindowInteractor;
57 class SVTK_NonIsometricDlg;
58 class SVTK_UpdateRateDlg;
59 class SVTK_CubeAxesDlg;
60 class SVTK_SetRotationPointDlg;
61 class SVTK_KeyFreeInteractorStyle;
62 class SVTK_ViewParameterDlg;
71 int convertAction( const int );
74 //! Define a container for SALOME VTK view window
75 class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
80 //! To construct #SVTK_ViewWindow instance
81 SVTK_ViewWindow(SUIT_Desktop* theDesktop);
83 virtual ~SVTK_ViewWindow();
85 virtual QImage dumpView();
87 //! To initialize #SVTK_ViewWindow instance
88 virtual void Initialize(SVTK_ViewModelBase* theModel);
93 //! Get #SVTK_MainWindow
94 //SVTK_MainWindow* getMainWindow();
96 //! Redirect the request to #SVTK_MainWindow::getRenderWindow
97 vtkRenderWindow* getRenderWindow();
99 //! Redirect the request to #SVTK_MainWindow::getInteractor
100 vtkRenderWindowInteractor* getInteractor() const;
102 //! Redirect the request to #SVTK_MainWindow::getInteractor
103 SVTK_RenderWindowInteractor* GetInteractor() const;
105 vtkInteractorStyle* GetInteractorStyle() const;
107 //! Redirect the request to #SVTK_RenderWindowInteractor::PushInteractorStyle
108 void PushInteractorStyle(vtkInteractorStyle* theStyle);
110 //! Redirect the request to #SVTK_RenderWindowInteractor::PopInteractorStyle
111 void PopInteractorStyle();
113 //! Redirect the request to #SVTK_MainWindow::getRenderer
114 vtkRenderer* getRenderer() const;
116 SVTK_Renderer* GetRenderer() const;
118 //! Redirect the request to #SVTK_MainWindow::GetSelector
119 SVTK_Selector* GetSelector() const;
121 //! Redirect the request to #SVTK_Selector::SelectionMode
122 Selection_Mode SelectionMode() const;
124 //! Change selection mode
125 virtual void SetSelectionMode(Selection_Mode theMode);
127 //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor
128 virtual void setBackgroundColor( const QColor& );
130 //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor
131 QColor backgroundColor() const;
133 //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
134 bool isTrihedronDisplayed();
136 //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
137 bool isCubeAxesDisplayed();
139 /* interactive object management */
140 //! Redirect the request to #SVTK_View::highlight (to support old code)
141 virtual void highlight(const Handle(SALOME_InteractiveObject)& theIO,
142 bool theIsHighlight = true,
143 bool theIsUpdate = true);
145 //! Redirect the request to #SVTK_View::unHighlightAll (to support old code)
146 virtual void unHighlightAll();
148 //! Redirect the request to #SVTK_View::isInViewer (to support old code)
149 bool isInViewer(const Handle(SALOME_InteractiveObject)& theIObject);
151 //! Redirect the request to #SVTK_View::isVisible (to support old code)
152 bool isVisible(const Handle(SALOME_InteractiveObject)& theIObject);
154 //! Redirect the request to #SVTK_View::FindIObject (to support old code)
155 //----------------------------------------------------------------------------
156 Handle(SALOME_InteractiveObject) FindIObject(const char* theEntry);
159 //----------------------------------------------------------------------------
160 //! Redirect the request to #SVTK_View::Display (to support old code)
161 virtual void Display(const Handle(SALOME_InteractiveObject)& theIObject,
162 bool theImmediatly = true);
164 //! Redirect the request to #SVTK_View::DisplayOnly (to support old code)
165 virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject);
167 //! Redirect the request to #SVTK_View::Erase (to support old code)
168 virtual void Erase(const Handle(SALOME_InteractiveObject)& theIObject,
169 bool theImmediatly = true);
171 //! Redirect the request to #SVTK_View::DisplayAll (to support old code)
172 virtual void DisplayAll();
174 //! Redirect the request to #SVTK_View::EraseAll (to support old code)
175 virtual void EraseAll();
177 //! To repaint the viewer
178 virtual void Repaint(bool theUpdateTrihedron = true);
180 //----------------------------------------------------------------------------
181 //! Redirect the request to #SVTK_Renderer::SetScale
182 virtual void SetScale( double theScale[3] );
184 //! Redirect the request to #SVTK_Renderer::GetScale
185 virtual void GetScale( double theScale[3] );
187 //! Redirect the request to #SVTK_Renderer::AddActor
188 virtual void AddActor(VTKViewer_Actor* theActor,
189 bool theIsUpdate = false);
191 //! Redirect the request to #SVTK_Renderer::RemoveActor
192 virtual void RemoveActor(VTKViewer_Actor* theActor,
193 bool theIsUpdate = false);
195 //----------------------------------------------------------------------------
196 //! Redirect the request to #SVTK_Renderer::AdjustActors
197 virtual void AdjustTrihedrons(const bool theIsForced);
199 //! Redirect the request to #SVTK_Renderer::GetTrihedron
200 VTKViewer_Trihedron* GetTrihedron();
202 //! Redirect the request to #SVTK_Renderer::GetCubeAxes
203 SVTK_CubeAxesActor2D* GetCubeAxes();
205 //! Redirect the request to #SVTK_Renderer::GetTrihedronSize
206 vtkFloatingPointType GetTrihedronSize() const;
208 //! Redirect the request to #SVTK_Renderer::SetTrihedronSize
209 virtual void SetTrihedronSize( const vtkFloatingPointType, const bool = true );
211 //! Redirect the request to #SVTK_MainWindow::SetIncrementalSpeed
212 virtual void SetIncrementalSpeed( const int, const int = 0 );
214 //! Redirect the request to #SVTK_MainWindow::SetProjectionMode
215 virtual void SetProjectionMode( const int );
217 //! Redirect the request to #SVTK_MainWindow::SetInteractionStyle
218 virtual void SetInteractionStyle( const int );
220 //! Redirect the request to #SVTK_MainWindow::SetSpacemouseButtons
221 virtual void SetSpacemouseButtons( const int, const int, const int );
223 //! Redirect the request to #SVTK_Renderer::SetSelectionProp
224 virtual void SetSelectionProp(const double& theRed = 1,
225 const double& theGreen = 1,
226 const double& theBlue = 0,
227 const int& theWidth = 5);
229 //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
230 virtual void SetPreselectionProp(const double& theRed = 0,
231 const double& theGreen = 1,
232 const double& theBlue = 1,
233 const int& theWidth = 5);
235 //! Redirect the request to #SVTK_Renderer::SetSelectionTolerance
236 virtual void SetSelectionTolerance(const double& theTolNodes = 0.025,
237 const double& theTolCell = 0.001,
238 const double& theTolObjects = 0.025);
240 //! Methods to save/restore visual parameters of a view (pan, zoom, etc.)
241 virtual QString getVisualParameters();
243 virtual void setVisualParameters( const QString& parameters );
245 virtual bool eventFilter( QObject*, QEvent* );
247 virtual void RefreshDumpImage();
249 //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance
250 void InvokeEvent(unsigned long theEvent, void* theCallData);
253 void Show( QShowEvent * );
254 void Hide( QHideEvent * );
257 virtual void showEvent( QShowEvent * );
258 virtual void hideEvent( QHideEvent * );
259 virtual void onSelectionChanged();
261 void onChangeRotationPoint(bool theIsActivate);
263 void activateSetRotationGravity();
264 void activateSetRotationSelected(void* theData);
265 void activateStartPointSelection();
267 void onUpdateRate(bool theIsActivate);
268 void onNonIsometric(bool theIsActivate);
269 void onGraduatedAxes(bool theIsActivate);
272 void activateWindowFit();
273 void activateRotation();
274 void activatePanning();
275 void activateGlobalPanning();
277 void onPerspectiveMode();
279 void activateProjectionMode(int);
281 void activateSetFocalPointGravity();
282 void activateSetFocalPointSelected();
283 void activateStartFocalPointSelection();
285 void onViewParameters(bool theIsActivate);
287 void onSwitchInteractionStyle(bool theOn);
289 void onStartRecording();
290 void onPlayRecording();
291 void onPauseRecording();
292 void onStopRecording();
295 void selectionChanged();
296 void actorAdded(VTKViewer_Actor*);
297 void actorRemoved(VTKViewer_Actor*);
300 //! Redirect the request to #SVTK_Renderer::OnFrontView
301 virtual void onFrontView();
303 //! Redirect the request to #SVTK_Renderer::OnBackView
304 virtual void onBackView();
306 //! Redirect the request to #SVTK_Renderer::OnTopView
307 virtual void onTopView();
309 //! Redirect the request to #SVTK_Renderer::OnBottomView
310 virtual void onBottomView();
312 //! Redirect the request to #SVTK_Renderer::OnRightView
313 virtual void onRightView();
315 //! Redirect the request to #SVTK_Renderer::OnLeftView
316 virtual void onLeftView();
318 //! Redirect the request to #SVTK_Renderer::OnResetView
319 virtual void onResetView();
321 //! Redirect the request to #SVTK_Renderer::OnFitAll
322 virtual void onFitAll();
324 //! Redirect the request to #SVTK_Renderer::OnViewTrihedron
325 virtual void onViewTrihedron();
327 //! Redirect the request to #SVTK_Renderer::OnViewCubeAxes
328 virtual void onViewCubeAxes();
330 //! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
331 virtual void onAdjustTrihedron();
333 //! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
334 virtual void onAdjustCubeAxes();
337 void onKeyPressed(QKeyEvent* event);
338 void onKeyReleased(QKeyEvent* event);
339 void onMousePressed(QMouseEvent* event);
340 void onMouseDoubleClicked(QMouseEvent* event);
341 void onMouseReleased(QMouseEvent* event);
342 void onMouseMoving(QMouseEvent* event);
345 virtual void Initialize(SVTK_View* theView,
346 SVTK_ViewModelBase* theModel);
348 void doSetVisualParameters( const QString& );
349 void SetEventDispatcher(vtkObject* theDispatcher);
351 QImage dumpViewContent();
353 virtual QString filter() const;
354 virtual bool dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format );
356 virtual bool action( const int );
358 QtxAction* getAction( int ) const;
359 void createToolBar();
360 void createActions(SUIT_ResourceMgr* theResourceMgr);
362 enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId,
363 ChangeRotationPointId, RotationId,
364 FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId,
365 ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate,
366 ParallelModeId, ProjectionModeId, ViewParametersId, SwitchInteractionStyleId,
367 StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId };
371 //SVTK_MainWindow* myMainWindow;
372 SVTK_ViewModelBase* myModel;
374 SVTK_RenderWindowInteractor* myInteractor;
375 vtkSmartPointer<SVTK_KeyFreeInteractorStyle> myKeyFreeInteractorStyle;
377 QString myVisualParams; // used for delayed setting of view parameters
379 vtkSmartPointer<vtkObject> myEventDispatcher;
381 SVTK_NonIsometricDlg* myNonIsometricDlg;
382 SVTK_UpdateRateDlg* myUpdateRateDlg;
383 SVTK_CubeAxesDlg* myCubeAxesDlg;
384 SVTK_SetRotationPointDlg* mySetRotationPointDlg;
385 SVTK_ViewParameterDlg* myViewParameterDlg;
387 QSize myPreRecordingMinSize;
388 QSize myPreRecordingMaxSize;
390 SVTK_Recorder* myRecorder;
391 QtxAction* myStartAction;
392 QtxAction* myPlayAction;
393 QtxAction* myPauseAction;
394 QtxAction* myStopAction;
397 int myRecordingToolBar;
404 #pragma warning( default:4251 )