1 // Copyright (C) 2007-2012 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
23 #ifndef SVTK_VIEWWINDOW_H
24 #define SVTK_VIEWWINDOW_H
27 #pragma warning( disable:4251 )
31 #include "SVTK_Selection.h"
33 #include "SUIT_ViewWindow.h"
35 #include "SALOME_InteractiveObject.hxx"
38 #include <vtkSmartPointer.h>
41 class SUIT_ResourceMgr;
43 class VTKViewer_Actor;
44 class VTKViewer_Trihedron;
46 class SVTK_ViewModelBase;
50 class SVTK_CubeAxesActor2D;
53 class vtkRenderWindow;
54 class vtkRenderWindowInteractor;
55 class vtkInteractorStyle;
56 class vtkCallbackCommand;
58 class SVTK_RenderWindowInteractor;
60 class SVTK_NonIsometricDlg;
61 class SVTK_UpdateRateDlg;
62 class SVTK_CubeAxesDlg;
63 class SVTK_SetRotationPointDlg;
64 class SVTK_InteractorStyle;
65 class SVTK_KeyFreeInteractorStyle;
66 class SVTK_ViewParameterDlg;
69 class vtkPVAxesWidget;
77 int convertAction( const int );
80 //! Define a container for SALOME VTK view window
81 class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
86 //! To construct #SVTK_ViewWindow instance
87 SVTK_ViewWindow(SUIT_Desktop* theDesktop);
89 virtual ~SVTK_ViewWindow();
91 virtual QImage dumpView();
93 //! To initialize #SVTK_ViewWindow instance
94 virtual void Initialize(SVTK_ViewModelBase* theModel);
100 vtkRenderWindow* getRenderWindow();
103 vtkRenderWindowInteractor* getInteractor() const;
105 //! Get SVTK interactor
106 SVTK_RenderWindowInteractor* GetInteractor() const;
108 //! Get current interactor style
109 vtkInteractorStyle* GetInteractorStyle() const;
111 //! Add interactor style to the stack of styles
112 void PushInteractorStyle(vtkInteractorStyle* theStyle);
114 //! Remove last interactor style from the stack of styles
115 void PopInteractorStyle();
118 vtkRenderer* getRenderer() const;
120 //! Get SVTK renderer
121 SVTK_Renderer* GetRenderer() const;
124 SVTK_Selector* GetSelector() const;
126 //! Set selection mode
127 Selection_Mode SelectionMode() const;
129 //! Change selection mode
130 virtual void SetSelectionMode(Selection_Mode theMode);
132 //! Set background color [obsolete]
133 virtual void setBackgroundColor( const QColor& );
135 //! Get background color [obsolete]
136 QColor backgroundColor() const;
139 virtual void setBackground( const Qtx::BackgroundData& );
142 Qtx::BackgroundData background() const;
144 //! Return \c true if "display trihedron" flag is set
145 bool isTrihedronDisplayed();
147 //! Return \c true if "show graduated axes" flag is set
148 bool isCubeAxesDisplayed();
150 /* interactive object management */
151 //! Redirect the request to #SVTK_View::highlight (to support old code)
152 virtual void highlight(const Handle(SALOME_InteractiveObject)& theIO,
153 bool theIsHighlight = true,
154 bool theIsUpdate = true);
156 //! Redirect the request to #SVTK_View::unHighlightAll (to support old code)
157 virtual void unHighlightAll();
159 //! Redirect the request to #SVTK_View::isInViewer (to support old code)
160 bool isInViewer(const Handle(SALOME_InteractiveObject)& theIObject);
162 //! Redirect the request to #SVTK_View::isVisible (to support old code)
163 bool isVisible(const Handle(SALOME_InteractiveObject)& theIObject);
165 //! Redirect the request to #SVTK_View::FindIObject (to support old code)
166 //----------------------------------------------------------------------------
167 Handle(SALOME_InteractiveObject) FindIObject(const char* theEntry);
170 //----------------------------------------------------------------------------
171 //! Redirect the request to #SVTK_View::Display (to support old code)
172 virtual void Display(const Handle(SALOME_InteractiveObject)& theIObject,
173 bool theImmediatly = true);
175 //! Redirect the request to #SVTK_View::DisplayOnly (to support old code)
176 virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject);
178 //! Redirect the request to #SVTK_View::Erase (to support old code)
179 virtual void Erase(const Handle(SALOME_InteractiveObject)& theIObject,
180 bool theImmediatly = true);
182 //! Redirect the request to #SVTK_View::DisplayAll (to support old code)
183 virtual void DisplayAll();
185 //! Redirect the request to #SVTK_View::EraseAll (to support old code)
186 virtual void EraseAll();
188 //! To repaint the viewer
189 virtual void Repaint(bool theUpdateTrihedron = true);
191 //----------------------------------------------------------------------------
192 //! Redirect the request to #SVTK_Renderer::SetScale
193 virtual void SetScale( double theScale[3] );
195 //! Redirect the request to #SVTK_Renderer::GetScale
196 virtual void GetScale( double theScale[3] );
198 //! Redirect the request to #SVTK_Renderer::AddActor
199 virtual void AddActor(VTKViewer_Actor* theActor,
200 bool theIsUpdate = false,
201 bool theIsAdjustActors = true);
203 //! Redirect the request to #SVTK_Renderer::RemoveActor
204 virtual void RemoveActor(VTKViewer_Actor* theActor,
205 bool theIsUpdate = false,
206 bool theIsAdjustActors = true);
208 //----------------------------------------------------------------------------
209 //! Redirect the request to #SVTK_Renderer::AdjustActors
210 virtual void AdjustTrihedrons(const bool theIsForced);
212 //! Redirect the request to #SVTK_Renderer::GetTrihedron
213 VTKViewer_Trihedron* GetTrihedron();
215 //! Redirect the request to #SVTK_Renderer::GetCubeAxes
216 SVTK_CubeAxesActor2D* GetCubeAxes();
218 //! Redirect the request to #SVTK_Renderer::GetTrihedronSize
219 vtkFloatingPointType GetTrihedronSize() const;
221 //! Redirect the request to #SVTK_Renderer::SetTrihedronSize
222 virtual void SetTrihedronSize( const vtkFloatingPointType, const bool = true );
224 //! Set incremental speed
225 virtual void SetIncrementalSpeed( const int, const int = 0 );
227 //! Set current projection mode
228 virtual void SetProjectionMode( const int );
230 //! Set interactive style
231 virtual void SetInteractionStyle( const int );
233 //! Set zooming style
234 virtual void SetZoomingStyle( const int );
236 //! Set dynamic preselection on/off
237 virtual void SetDynamicPreSelection( bool );
239 //! Customize space mouse buttons
240 virtual void SetSpacemouseButtons( const int, const int, const int );
242 //! Set selection properties
243 virtual void SetSelectionProp(const double& theRed = 1,
244 const double& theGreen = 1,
245 const double& theBlue = 0,
246 const int& theWidth = 5);
248 //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
249 virtual void SetPreselectionProp(const double& theRed = 0,
250 const double& theGreen = 1,
251 const double& theBlue = 1,
252 const int& theWidth = 5);
254 //! Redirect the request to #SVTK_Renderer::SetSelectionTolerance
255 virtual void SetSelectionTolerance(const double& theTolNodes = 0.025,
256 const double& theTolCell = 0.001,
257 const double& theTolObjects = 0.025);
259 //! Get visibility status of the static trihedron
260 bool IsStaticTrihedronVisible() const;
262 //! Set visibility status of the static trihedron
263 virtual void SetStaticTrihedronVisible( const bool );
265 //! Methods to save/restore visual parameters of a view (pan, zoom, etc.)
266 virtual QString getVisualParameters();
268 virtual void setVisualParameters( const QString& parameters );
270 virtual bool eventFilter( QObject*, QEvent* );
272 virtual void RefreshDumpImage();
274 void emitTransformed();
276 //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance
277 void InvokeEvent(unsigned long theEvent, void* theCallData);
280 void Show( QShowEvent * );
281 void Hide( QHideEvent * );
284 virtual void showEvent( QShowEvent * );
285 virtual void hideEvent( QHideEvent * );
286 virtual void onSelectionChanged();
288 void onChangeRotationPoint(bool theIsActivate);
290 void activateSetRotationGravity();
291 void activateSetRotationSelected(void* theData);
292 void activateStartPointSelection();
294 void onUpdateRate(bool theIsActivate);
295 void onNonIsometric(bool theIsActivate);
296 void onGraduatedAxes(bool theIsActivate);
299 void activateWindowFit();
300 void activateRotation();
301 void activatePanning();
302 void activateGlobalPanning();
304 void onPerspectiveMode();
306 void activateProjectionMode(int);
308 void activateSetFocalPointGravity();
309 void activateSetFocalPointSelected();
310 void activateStartFocalPointSelection();
312 void onViewParameters(bool theIsActivate);
314 void onSwitchInteractionStyle(bool theOn);
315 void onSwitchZoomingStyle(bool theOn);
316 void onSwitchDynamicPreSelection(bool theOn);
318 void onStartRecording();
319 void onPlayRecording();
320 void onPauseRecording();
321 void onStopRecording();
324 void selectionChanged();
325 void actorAdded(VTKViewer_Actor*);
326 void actorRemoved(VTKViewer_Actor*);
327 void transformed(SVTK_ViewWindow*);
330 //! Redirect the request to #SVTK_Renderer::OnFrontView
331 virtual void onFrontView();
333 //! Redirect the request to #SVTK_Renderer::OnBackView
334 virtual void onBackView();
336 //! Redirect the request to #SVTK_Renderer::OnTopView
337 virtual void onTopView();
339 //! Redirect the request to #SVTK_Renderer::OnBottomView
340 virtual void onBottomView();
342 //! Redirect the request to #SVTK_Renderer::OnRightView
343 virtual void onRightView();
345 //! Redirect the request to #SVTK_Renderer::OnLeftView
346 virtual void onLeftView();
348 //! Redirect the request to #SVTK_Renderer::onClockWiseView
349 virtual void onClockWiseView();
351 //! Redirect the request to #SVTK_Renderer::onAntiClockWiseView
352 virtual void onAntiClockWiseView();
354 //! Redirect the request to #SVTK_Renderer::OnResetView
355 virtual void onResetView();
357 //! Redirect the request to #SVTK_Renderer::OnFitAll
358 virtual void onFitAll();
360 //! Redirect the request to #SVTK_Renderer::OnViewTrihedron
361 virtual void onViewTrihedron();
363 //! Redirect the request to #SVTK_Renderer::OnViewCubeAxes
364 virtual void onViewCubeAxes();
366 //! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
367 virtual void onAdjustTrihedron();
369 //! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
370 virtual void onAdjustCubeAxes();
372 virtual void synchronize(SVTK_ViewWindow*);
375 void onKeyPressed(QKeyEvent* event);
376 void onKeyReleased(QKeyEvent* event);
377 void onMousePressed(QMouseEvent* event);
378 void onMouseDoubleClicked(QMouseEvent* event);
379 void onMouseReleased(QMouseEvent* event);
380 void onMouseMoving(QMouseEvent* event);
383 virtual void Initialize(SVTK_View* theView,
384 SVTK_ViewModelBase* theModel);
386 // Main process event method
387 static void ProcessEvents(vtkObject* object,
392 void doSetVisualParameters( const QString&, bool = false );
393 void SetEventDispatcher(vtkObject* theDispatcher);
395 QImage dumpViewContent();
397 virtual QString filter() const;
398 virtual bool dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format );
400 virtual bool action( const int );
402 QtxAction* getAction( int ) const;
403 void createToolBar();
404 void createActions(SUIT_ResourceMgr* theResourceMgr);
406 enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId,
407 ChangeRotationPointId, RotationId,
408 FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId, ResetId,
409 ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate,
410 ParallelModeId, ProjectionModeId, ViewParametersId, SynchronizeId, SwitchInteractionStyleId,
411 SwitchZoomingStyleId,SwitchDynamicPreselectionId,
412 StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId };
415 SVTK_ViewModelBase* myModel;
417 SVTK_RenderWindowInteractor* myInteractor;
418 vtkSmartPointer<SVTK_InteractorStyle> myDefaultInteractorStyle;
419 vtkSmartPointer<SVTK_KeyFreeInteractorStyle> myKeyFreeInteractorStyle;
421 QString myVisualParams; // used for delayed setting of view parameters
423 vtkSmartPointer<vtkObject> myEventDispatcher;
425 // Used to process events
426 vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
428 SVTK_NonIsometricDlg* myNonIsometricDlg;
429 SVTK_UpdateRateDlg* myUpdateRateDlg;
430 SVTK_CubeAxesDlg* myCubeAxesDlg;
431 SVTK_SetRotationPointDlg* mySetRotationPointDlg;
432 SVTK_ViewParameterDlg* myViewParameterDlg;
434 QSize myPreRecordingMinSize;
435 QSize myPreRecordingMaxSize;
437 SVTK_Recorder* myRecorder;
438 QtxAction* myStartAction;
439 QtxAction* myPlayAction;
440 QtxAction* myPauseAction;
441 QtxAction* myStopAction;
444 int myRecordingToolBar;
446 vtkPVAxesWidget* myAxesWidget;
447 Qtx::BackgroundData myBackground;
450 void onSynchronizeView(bool);
451 void updateSyncViews();
454 static void synchronizeView( SVTK_ViewWindow*, int );
461 #pragma warning( default:4251 )