1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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;
71 class vtkPVAxesWidget;
80 int convertAction( const int );
83 //! Define a container for SALOME VTK view window
84 class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
89 //! To construct #SVTK_ViewWindow instance
90 SVTK_ViewWindow(SUIT_Desktop* theDesktop);
92 virtual ~SVTK_ViewWindow();
94 virtual QImage dumpView();
96 //! To initialize #SVTK_ViewWindow instance
97 virtual void Initialize(SVTK_ViewModelBase* theModel);
100 SVTK_View* getView();
102 //! Get render window
103 vtkRenderWindow* getRenderWindow();
106 vtkRenderWindowInteractor* getInteractor() const;
108 //! Get SVTK interactor
109 SVTK_RenderWindowInteractor* GetInteractor() const;
111 //! Get current interactor style
112 vtkInteractorStyle* GetInteractorStyle() const;
114 //! Add interactor style to the stack of styles
115 void PushInteractorStyle(vtkInteractorStyle* theStyle);
117 //! Remove last interactor style from the stack of styles
118 void PopInteractorStyle();
121 vtkRenderer* getRenderer() const;
123 //! Get SVTK renderer
124 SVTK_Renderer* GetRenderer() const;
127 SVTK_Selector* GetSelector() const;
129 //! Set selection mode
130 Selection_Mode SelectionMode() const;
132 //! Change selection mode
133 virtual void SetSelectionMode(Selection_Mode theMode);
135 //! Set background color [obsolete]
136 virtual void setBackgroundColor( const QColor& );
138 //! Get background color [obsolete]
139 QColor backgroundColor() const;
142 virtual void setBackground( const Qtx::BackgroundData& );
145 Qtx::BackgroundData background() const;
147 //! Return \c true if "display trihedron" flag is set
148 bool isTrihedronDisplayed();
150 //! Return \c true if "show graduated axes" flag is set
151 bool isCubeAxesDisplayed();
153 /* interactive object management */
154 //! Redirect the request to #SVTK_View::highlight (to support old code)
155 virtual void highlight(const Handle(SALOME_InteractiveObject)& theIO,
156 bool theIsHighlight = true,
157 bool theIsUpdate = true);
159 //! Redirect the request to #SVTK_View::unHighlightAll (to support old code)
160 virtual void unHighlightAll();
162 //! Redirect the request to #SVTK_View::isInViewer (to support old code)
163 bool isInViewer(const Handle(SALOME_InteractiveObject)& theIObject);
165 //! Redirect the request to #SVTK_View::isVisible (to support old code)
166 bool isVisible(const Handle(SALOME_InteractiveObject)& theIObject);
168 //! Redirect the request to #SVTK_View::FindIObject (to support old code)
169 //----------------------------------------------------------------------------
170 Handle(SALOME_InteractiveObject) FindIObject(const char* theEntry);
173 //----------------------------------------------------------------------------
174 //! Redirect the request to #SVTK_View::Display (to support old code)
175 virtual void Display(const Handle(SALOME_InteractiveObject)& theIObject,
176 bool theImmediatly = true);
178 //! Redirect the request to #SVTK_View::DisplayOnly (to support old code)
179 virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject);
181 //! Redirect the request to #SVTK_View::Erase (to support old code)
182 virtual void Erase(const Handle(SALOME_InteractiveObject)& theIObject,
183 bool theImmediatly = true);
185 //! Redirect the request to #SVTK_View::DisplayAll (to support old code)
186 virtual void DisplayAll();
188 //! Redirect the request to #SVTK_View::EraseAll (to support old code)
189 virtual void EraseAll();
191 //! To repaint the viewer
192 virtual void Repaint(bool theUpdateTrihedron = true);
194 //----------------------------------------------------------------------------
195 //! Redirect the request to #SVTK_Renderer::SetScale
196 virtual void SetScale( double theScale[3] );
198 //! Redirect the request to #SVTK_Renderer::GetScale
199 virtual void GetScale( double theScale[3] );
201 //! Redirect the request to #SVTK_Renderer::AddActor
202 virtual void AddActor(VTKViewer_Actor* theActor,
203 bool theIsUpdate = false,
204 bool theIsAdjustActors = true);
206 //! Redirect the request to #SVTK_Renderer::RemoveActor
207 virtual void RemoveActor(VTKViewer_Actor* theActor,
208 bool theIsUpdate = false,
209 bool theIsAdjustActors = true);
211 //----------------------------------------------------------------------------
212 //! Redirect the request to #SVTK_Renderer::AdjustActors
213 virtual void AdjustTrihedrons(const bool theIsForced);
215 //! Redirect the request to #SVTK_Renderer::GetTrihedron
216 VTKViewer_Trihedron* GetTrihedron();
218 //! Redirect the request to #SVTK_Renderer::GetCubeAxes
219 SVTK_CubeAxesActor2D* GetCubeAxes();
221 //! Redirect the request to #SVTK_Renderer::GetTrihedronSize
222 double GetTrihedronSize() const;
224 //! Redirect the request to #SVTK_Renderer::SetTrihedronSize
225 virtual void SetTrihedronSize( const double, const bool = true );
227 //! Set incremental speed
228 virtual void SetIncrementalSpeed( const int, const int = 0 );
230 //! Set current projection mode
231 virtual void SetProjectionMode( const int );
234 virtual void SetStereoType( const int );
236 //! Sets anaglyph filter
237 virtual void SetAnaglyphFilter( const int );
239 //! Set support quad-buffered stereo
240 virtual void SetQuadBufferSupport( const bool );
242 //! Set interactive style
243 virtual void SetInteractionStyle( const int );
245 //! Set zooming style
246 virtual void SetZoomingStyle( const int );
248 //! Set preselection mode
249 virtual void SetPreSelectionMode( Preselection_Mode );
251 //! Enable/disable selection
252 virtual void SetSelectionEnabled( bool );
254 //! Customize space mouse buttons
255 virtual void SetSpacemouseButtons( const int, const int, const int );
257 //! Set selection properties
258 virtual void SetSelectionProp(const double& theRed = 1,
259 const double& theGreen = 1,
260 const double& theBlue = 0,
261 const int& theWidth = 5);
263 //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
264 virtual void SetPreselectionProp(const double& theRed = 0,
265 const double& theGreen = 1,
266 const double& theBlue = 1,
267 const int& theWidth = 5);
269 //! Redirect the request to #SVTK_Renderer::SetSelectionTolerance
270 virtual void SetSelectionTolerance(const double& theTolNodes = 0.025,
271 const double& theTolCell = 0.001,
272 const double& theTolObjects = 0.025);
274 //! Get visibility status of the static trihedron
275 bool IsStaticTrihedronVisible() const;
277 //! Set visibility status of the static trihedron
278 virtual void SetStaticTrihedronVisible( const bool );
280 //! Methods to save/restore visual parameters of a view (pan, zoom, etc.)
281 virtual QString getVisualParameters();
283 virtual void setVisualParameters( const QString& parameters );
285 virtual bool eventFilter( QObject*, QEvent* );
287 virtual void RefreshDumpImage();
289 void emitTransformed();
291 //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance
292 void InvokeEvent(unsigned long theEvent, void* theCallData);
294 virtual SUIT_CameraProperties cameraProperties();
297 void Show( QShowEvent * );
298 void Hide( QHideEvent * );
301 virtual void showEvent( QShowEvent * );
302 virtual void hideEvent( QHideEvent * );
303 virtual void onSelectionChanged();
305 void onChangeRotationPoint(bool theIsActivate);
307 void activateSetRotationGravity();
308 void activateSetRotationSelected(void* theData);
309 void activateStartPointSelection( Selection_Mode );
311 void onUpdateRate(bool theIsActivate);
312 void onNonIsometric(bool theIsActivate);
313 void onGraduatedAxes(bool theIsActivate);
316 void activateWindowFit();
317 void activateRotation();
318 void activatePanning();
319 void activateGlobalPanning();
321 void onProjectionMode( QAction* theAction );
322 void onStereoMode( bool activate );
323 void onProjectionMode();
325 void activateProjectionMode(int);
327 void activateSetFocalPointGravity();
328 void activateSetFocalPointSelected();
329 void activateStartFocalPointSelection();
331 void onViewParameters(bool theIsActivate);
333 void onSwitchInteractionStyle(bool theOn);
334 void onSwitchZoomingStyle(bool theOn);
336 void onSwitchPreSelectionMode(int theMode);
337 void onEnableSelection(bool theOn);
339 void onStartRecording();
340 void onPlayRecording();
341 void onPauseRecording();
342 void onStopRecording();
345 void selectionChanged();
346 void actorAdded(VTKViewer_Actor*);
347 void actorRemoved(VTKViewer_Actor*);
348 void transformed(SVTK_ViewWindow*);
351 //! Redirect the request to #SVTK_Renderer::OnFrontView
352 virtual void onFrontView();
354 //! Redirect the request to #SVTK_Renderer::OnBackView
355 virtual void onBackView();
357 //! Redirect the request to #SVTK_Renderer::OnTopView
358 virtual void onTopView();
360 //! Redirect the request to #SVTK_Renderer::OnBottomView
361 virtual void onBottomView();
363 //! Redirect the request to #SVTK_Renderer::OnRightView
364 virtual void onRightView();
366 //! Redirect the request to #SVTK_Renderer::OnLeftView
367 virtual void onLeftView();
369 //! Redirect the request to #SVTK_Renderer::onClockWiseView
370 virtual void onClockWiseView();
372 //! Redirect the request to #SVTK_Renderer::onAntiClockWiseView
373 virtual void onAntiClockWiseView();
375 //! Redirect the request to #SVTK_Renderer::OnResetView
376 virtual void onResetView();
378 //! Redirect the request to #SVTK_Renderer::OnFitAll
379 virtual void onFitAll();
381 //! Redirect the request to #SVTK_Renderer::OnFitSelection
382 virtual void onFitSelection();
384 //! Redirect the request to #SVTK_Renderer::OnViewTrihedron
385 virtual void onViewTrihedron(bool);
387 //! Redirect the request to #SVTK_Renderer::OnViewCubeAxes
388 virtual void onViewCubeAxes();
390 //! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
391 virtual void onAdjustTrihedron();
393 //! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
394 virtual void onAdjustCubeAxes();
396 virtual void synchronize(SVTK_ViewWindow*);
399 void synchronize( SUIT_ViewWindow* );
400 void onKeyPressed(QKeyEvent* event);
401 void onKeyReleased(QKeyEvent* event);
402 void onMousePressed(QMouseEvent* event);
403 void onMouseDoubleClicked(QMouseEvent* event);
404 void onMouseReleased(QMouseEvent* event);
405 void onMouseMoving(QMouseEvent* event);
408 enum ProjectionType { Parallel, Projection, Stereo };
410 enum StereoType { CrystalEyes, RedBlue, Interlaced, Left, Right, Dresden, Anaglyph, Checkerboard, SplitViewPortHorizontal };
412 enum AnaglyphFilter { RedCyan, YellowBlue, GreenMagenta };
415 virtual void Initialize(SVTK_View* theView,
416 SVTK_ViewModelBase* theModel);
418 // Main process event method
419 static void ProcessEvents(vtkObject* object,
424 bool isOpenGlStereoSupport() const;
426 void doSetVisualParameters( const QString&, bool = false );
427 void SetEventDispatcher(vtkObject* theDispatcher);
429 QImage dumpViewContent();
431 virtual QString filter() const;
432 virtual bool dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format );
434 virtual bool action( const int );
436 QtxAction* getAction( int ) const;
437 void createToolBar();
438 void createActions(SUIT_ResourceMgr* theResourceMgr);
440 enum { DumpId, FitAllId, FitRectId, FitSelectionId, ZoomId, PanId, GlobalPanId,
441 ChangeRotationPointId, RotationId,
442 FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId, ResetId,
443 ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate,
444 ParallelModeId, ProjectionModeId, StereoModeId, ViewParametersId, SynchronizeId, SwitchInteractionStyleId,
445 SwitchZoomingStyleId,
446 PreselectionId, StandardPreselectionId, DynamicPreselectionId, DisablePreselectionId,
448 StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId };
451 SVTK_ViewModelBase* myModel;
453 SVTK_RenderWindowInteractor* myInteractor;
454 vtkSmartPointer<SVTK_InteractorStyle> myDefaultInteractorStyle;
455 vtkSmartPointer<SVTK_KeyFreeInteractorStyle> myKeyFreeInteractorStyle;
457 QString myVisualParams; // used for delayed setting of view parameters
459 vtkSmartPointer<vtkObject> myEventDispatcher;
461 // Used to process events
462 vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
464 SVTK_NonIsometricDlg* myNonIsometricDlg;
465 SVTK_UpdateRateDlg* myUpdateRateDlg;
466 SVTK_CubeAxesDlg* myCubeAxesDlg;
467 SVTK_SetRotationPointDlg* mySetRotationPointDlg;
468 SVTK_ViewParameterDlg* myViewParameterDlg;
470 QSize myPreRecordingMinSize;
471 QSize myPreRecordingMaxSize;
473 SVTK_Recorder* myRecorder;
474 QtxAction* myStartAction;
475 QtxAction* myPlayAction;
476 QtxAction* myPauseAction;
477 QtxAction* myStopAction;
480 int myRecordingToolBar;
482 salomevtk::vtkPVAxesWidget* myAxesWidget;
483 Qtx::BackgroundData myBackground;
490 #pragma warning( default:4251 )