]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_ViewWindow.h
Salome HOME
Help documentation was added. Behavior of OCC and VTK stereo projection toolbar butto...
[modules/gui.git] / src / SVTK / SVTK_ViewWindow.h
1 // Copyright (C) 2007-2015  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 #ifndef SVTK_VIEWWINDOW_H
24 #define SVTK_VIEWWINDOW_H
25
26 #ifdef WIN32
27 #pragma warning( disable:4251 )
28 #endif
29
30 #include "SVTK.h"
31 #include "SVTK_Selection.h"
32 #include "Qtx.h"
33 #include "SUIT_ViewWindow.h"
34
35 #include "SALOME_InteractiveObject.hxx"
36
37 #include <QImage>
38 #include <vtkSmartPointer.h>
39
40 class SUIT_Desktop;
41 class SUIT_ResourceMgr;
42
43 class VTKViewer_Actor;
44 class VTKViewer_Trihedron;
45
46 class SVTK_ViewModelBase;
47 class SVTK_Selector;
48 class SVTK_View;
49
50 class SVTK_CubeAxesActor2D;
51
52 class vtkRenderer;
53 class vtkRenderWindow;
54 class vtkRenderWindowInteractor;
55 class vtkInteractorStyle;
56 class vtkCallbackCommand;
57
58 class SVTK_RenderWindowInteractor;
59 class SVTK_Renderer;
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;
67 class SVTK_Recorder;
68
69 namespace salomevtk
70 {
71   class vtkPVAxesWidget;
72 }
73
74 class vtkObject;
75 class QtxAction;
76
77 namespace SVTK
78 {
79   SVTK_EXPORT
80     int convertAction( const int );
81 }
82
83 //! Define a container for SALOME VTK view window
84 class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
85 {
86   Q_OBJECT;
87
88  public:
89   //! To construct #SVTK_ViewWindow instance
90   SVTK_ViewWindow(SUIT_Desktop* theDesktop);
91
92   virtual ~SVTK_ViewWindow();
93   
94   virtual QImage dumpView();
95
96   //! To initialize #SVTK_ViewWindow instance
97   virtual void Initialize(SVTK_ViewModelBase* theModel);
98
99   //! Get #SVTK_View
100   SVTK_View* getView();
101
102   //! Get render window
103   vtkRenderWindow* getRenderWindow();
104
105   //! Get interactor
106   vtkRenderWindowInteractor* getInteractor() const;
107
108   //! Get SVTK interactor
109   SVTK_RenderWindowInteractor*  GetInteractor() const;
110
111   //! Get current interactor style
112   vtkInteractorStyle* GetInteractorStyle() const;
113
114   //! Add interactor style to the stack of styles
115   void PushInteractorStyle(vtkInteractorStyle* theStyle);
116
117   //! Remove last interactor style from the stack of styles
118   void PopInteractorStyle();
119
120   //! Get renderer
121   vtkRenderer* getRenderer() const;
122   
123   //! Get SVTK renderer
124   SVTK_Renderer* GetRenderer() const;
125
126   //! Get selector
127   SVTK_Selector* GetSelector() const;
128   
129   //! Set selection mode
130   Selection_Mode SelectionMode() const;
131   
132   //! Change selection mode
133   virtual void SetSelectionMode(Selection_Mode theMode);
134
135   //! Set background color [obsolete] 
136   virtual void setBackgroundColor( const QColor& );
137
138   //! Get background color [obsolete]
139   QColor backgroundColor() const;
140
141   //! Set background
142   virtual void setBackground( const Qtx::BackgroundData& );
143
144   //! Get background
145   Qtx::BackgroundData background() const;
146
147   //! Return \c true if "display trihedron" flag is set
148   bool isTrihedronDisplayed();
149
150   //! Return \c true if "show graduated axes" flag is set
151   bool isCubeAxesDisplayed();
152  
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);
158
159   //! Redirect the request to #SVTK_View::unHighlightAll (to support old code)
160   virtual void unHighlightAll();
161
162   //! Redirect the request to #SVTK_View::isInViewer (to support old code)
163   bool isInViewer(const Handle(SALOME_InteractiveObject)& theIObject);
164
165   //! Redirect the request to #SVTK_View::isVisible (to support old code)
166   bool isVisible(const Handle(SALOME_InteractiveObject)& theIObject);
167
168   //! Redirect the request to #SVTK_View::FindIObject (to support old code)
169   //----------------------------------------------------------------------------
170   Handle(SALOME_InteractiveObject) FindIObject(const char* theEntry);
171   
172   /* display */         
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);
177
178   //! Redirect the request to #SVTK_View::DisplayOnly (to support old code)
179   virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject);
180
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);
184
185   //! Redirect the request to #SVTK_View::DisplayAll (to support old code)
186   virtual void DisplayAll();
187
188   //! Redirect the request to #SVTK_View::EraseAll (to support old code)
189   virtual void EraseAll();
190
191   //! To repaint the viewer
192   virtual void Repaint(bool theUpdateTrihedron = true);
193
194   //----------------------------------------------------------------------------
195   //! Redirect the request to #SVTK_Renderer::SetScale
196   virtual void SetScale( double theScale[3] );
197
198   //! Redirect the request to #SVTK_Renderer::GetScale
199   virtual void GetScale( double theScale[3] );
200
201   //! Redirect the request to #SVTK_Renderer::AddActor
202   virtual void AddActor(VTKViewer_Actor* theActor,
203                         bool theIsUpdate = false,
204                         bool theIsAdjustActors = true);
205
206   //! Redirect the request to #SVTK_Renderer::RemoveActor
207   virtual void RemoveActor(VTKViewer_Actor* theActor,
208                            bool theIsUpdate = false,
209                            bool theIsAdjustActors = true);
210
211   //----------------------------------------------------------------------------
212   //! Redirect the request to #SVTK_Renderer::AdjustActors
213   virtual void AdjustTrihedrons(const bool theIsForced);
214
215   //! Redirect the request to #SVTK_Renderer::GetTrihedron
216   VTKViewer_Trihedron* GetTrihedron();
217
218   //! Redirect the request to #SVTK_Renderer::GetCubeAxes
219   SVTK_CubeAxesActor2D* GetCubeAxes();
220
221   //! Redirect the request to #SVTK_Renderer::GetTrihedronSize
222   double GetTrihedronSize() const;
223
224   //! Redirect the request to #SVTK_Renderer::SetTrihedronSize
225   virtual void SetTrihedronSize( const double, const bool = true );
226
227   //! Set incremental speed
228   virtual void SetIncrementalSpeed( const int, const int = 0 );
229
230   //! Set current projection mode
231   virtual void SetProjectionMode( const int );
232
233   //! Sets stereo type
234   virtual void SetStereoType( const int );
235
236   //! Sets anaglyph filter
237   virtual void SetAnaglyphFilter( const int );
238
239   //! Set interactive style
240   virtual void SetInteractionStyle( const int );
241
242   //! Set zooming style
243   virtual void SetZoomingStyle( const int );
244
245   //! Set preselection mode
246   virtual void SetPreSelectionMode( Preselection_Mode );
247
248   //! Enable/disable selection
249   virtual void SetSelectionEnabled( bool );
250
251   //! Customize space mouse buttons
252   virtual void SetSpacemouseButtons( const int, const int, const int );
253
254   //! Set selection properties
255   virtual void SetSelectionProp(const double& theRed = 1, 
256                                 const double& theGreen = 1,
257                                 const double& theBlue = 0, 
258                                 const int& theWidth = 5);
259
260   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
261   virtual void SetPreselectionProp(const double& theRed = 0, 
262                                    const double& theGreen = 1,
263                                    const double& theBlue = 1, 
264                                    const int& theWidth = 5);
265
266   //! Redirect the request to #SVTK_Renderer::SetSelectionTolerance
267   virtual void SetSelectionTolerance(const double& theTolNodes = 0.025, 
268                                      const double& theTolCell = 0.001,
269                                      const double& theTolObjects = 0.025);
270
271   //! Get visibility status of the static trihedron
272   bool IsStaticTrihedronVisible() const;
273
274   //! Set visibility status of the static trihedron
275   virtual void SetStaticTrihedronVisible( const bool );
276
277   //! Methods to save/restore visual parameters of a view (pan, zoom, etc.)
278   virtual QString getVisualParameters();
279   
280   virtual void setVisualParameters( const QString& parameters );
281
282   virtual bool eventFilter( QObject*, QEvent* );
283
284   virtual void RefreshDumpImage();
285
286   void emitTransformed();
287
288   //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance
289   void InvokeEvent(unsigned long theEvent, void* theCallData);
290   
291   virtual SUIT_CameraProperties cameraProperties();
292   
293  signals:
294   void Show( QShowEvent * );
295   void Hide( QHideEvent * );
296
297 public slots:
298   virtual void showEvent( QShowEvent * );
299   virtual void hideEvent( QHideEvent * );
300   virtual void onSelectionChanged();
301
302   void onChangeRotationPoint(bool theIsActivate);
303
304   void activateSetRotationGravity();
305   void activateSetRotationSelected(void* theData);
306   void activateStartPointSelection( Selection_Mode );
307
308   void onUpdateRate(bool theIsActivate);
309   void onNonIsometric(bool theIsActivate);
310   void onGraduatedAxes(bool theIsActivate);
311
312   void activateZoom();
313   void activateWindowFit();
314   void activateRotation();
315   void activatePanning(); 
316   void activateGlobalPanning(); 
317
318   void onProjectionMode( QAction* theAction );
319   void onStereoMode( bool activate );
320   void onProjectionMode();
321
322   void activateProjectionMode(int);
323
324   void activateSetFocalPointGravity();
325   void activateSetFocalPointSelected();
326   void activateStartFocalPointSelection();
327
328   void onViewParameters(bool theIsActivate);
329
330   void onSwitchInteractionStyle(bool theOn);
331   void onSwitchZoomingStyle(bool theOn);
332
333   void onSwitchPreSelectionMode(int theMode);
334   void onEnableSelection(bool theOn);
335
336   void onStartRecording();
337   void onPlayRecording();
338   void onPauseRecording();
339   void onStopRecording();
340
341 signals:
342  void selectionChanged();
343  void actorAdded(VTKViewer_Actor*);
344  void actorRemoved(VTKViewer_Actor*);
345  void transformed(SVTK_ViewWindow*);
346
347 public slots:
348   //! Redirect the request to #SVTK_Renderer::OnFrontView
349   virtual void onFrontView(); 
350
351   //! Redirect the request to #SVTK_Renderer::OnBackView
352   virtual void onBackView(); 
353
354   //! Redirect the request to #SVTK_Renderer::OnTopView
355   virtual void onTopView();
356
357   //! Redirect the request to #SVTK_Renderer::OnBottomView
358   virtual void onBottomView();
359
360   //! Redirect the request to #SVTK_Renderer::OnRightView
361   virtual void onRightView(); 
362
363   //! Redirect the request to #SVTK_Renderer::OnLeftView
364   virtual void onLeftView();     
365
366   //! Redirect the request to #SVTK_Renderer::onClockWiseView
367   virtual void onClockWiseView();
368
369   //! Redirect the request to #SVTK_Renderer::onAntiClockWiseView
370   virtual void onAntiClockWiseView();
371
372   //! Redirect the request to #SVTK_Renderer::OnResetView
373   virtual void onResetView();     
374
375   //! Redirect the request to #SVTK_Renderer::OnFitAll
376   virtual void onFitAll();
377
378   //! Redirect the request to #SVTK_Renderer::OnFitSelection
379   virtual void onFitSelection();
380
381   //! Redirect the request to #SVTK_Renderer::OnViewTrihedron
382   virtual void onViewTrihedron(bool); 
383
384   //! Redirect the request to #SVTK_Renderer::OnViewCubeAxes
385   virtual void onViewCubeAxes();
386
387   //! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
388   virtual void onAdjustTrihedron();
389
390   //! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
391   virtual void onAdjustCubeAxes();
392   
393   virtual void synchronize(SVTK_ViewWindow*);
394     
395 protected slots:
396   void synchronize( SUIT_ViewWindow* );
397   void onKeyPressed(QKeyEvent* event);
398   void onKeyReleased(QKeyEvent* event);
399   void onMousePressed(QMouseEvent* event);
400   void onMouseDoubleClicked(QMouseEvent* event);
401   void onMouseReleased(QMouseEvent* event);
402   void onMouseMoving(QMouseEvent* event);
403
404 public:
405   enum ProjectionType { Parallel, Projection, Stereo };
406
407   enum StereoType { CrystalEyes, RedBlue, Interlaced, Left, Right, Dresden, Anaglyph, Checkerboard, SplitViewPortHorizontal };
408
409   enum AnaglyphFilter { RedCyan, YellowBlue, GreenMagenta };
410
411 protected:
412   virtual void Initialize(SVTK_View* theView,
413                           SVTK_ViewModelBase* theModel);
414
415   // Main process event method
416   static void ProcessEvents(vtkObject* object,
417                             unsigned long event,
418                             void* clientdata,
419                             void* calldata);
420
421   bool isOpenGlStereoSupport() const;
422
423   void doSetVisualParameters( const QString&, bool = false );
424   void SetEventDispatcher(vtkObject* theDispatcher);
425
426   QImage dumpViewContent();
427
428   virtual QString filter() const;
429   virtual bool dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format );
430   
431   virtual bool action( const int );
432   
433   QtxAction* getAction( int ) const;
434   void createToolBar();
435   void createActions(SUIT_ResourceMgr* theResourceMgr);
436
437   enum { DumpId, FitAllId, FitRectId, FitSelectionId, ZoomId, PanId, GlobalPanId,
438          ChangeRotationPointId, RotationId,
439          FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId, ResetId,
440          ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate,
441          ParallelModeId, ProjectionModeId, StereoModeId, ViewParametersId, SynchronizeId, SwitchInteractionStyleId,
442          SwitchZoomingStyleId, 
443          PreselectionId, StandardPreselectionId, DynamicPreselectionId, DisablePreselectionId, 
444          EnableSelectionId,
445          StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId };
446
447   SVTK_View* myView;
448   SVTK_ViewModelBase* myModel;
449
450   SVTK_RenderWindowInteractor* myInteractor;
451   vtkSmartPointer<SVTK_InteractorStyle> myDefaultInteractorStyle;
452   vtkSmartPointer<SVTK_KeyFreeInteractorStyle> myKeyFreeInteractorStyle;
453
454   QString myVisualParams; // used for delayed setting of view parameters 
455
456   vtkSmartPointer<vtkObject> myEventDispatcher;
457
458   // Used to process events
459   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
460
461   SVTK_NonIsometricDlg* myNonIsometricDlg;
462   SVTK_UpdateRateDlg* myUpdateRateDlg;
463   SVTK_CubeAxesDlg* myCubeAxesDlg;
464   SVTK_SetRotationPointDlg* mySetRotationPointDlg;
465   SVTK_ViewParameterDlg* myViewParameterDlg;
466
467   QSize myPreRecordingMinSize;
468   QSize myPreRecordingMaxSize;
469
470   SVTK_Recorder* myRecorder;
471   QtxAction* myStartAction;
472   QtxAction* myPlayAction;
473   QtxAction* myPauseAction;
474   QtxAction* myStopAction;
475
476   int myToolBar;
477   int myRecordingToolBar;
478
479   salomevtk::vtkPVAxesWidget* myAxesWidget;
480   Qtx::BackgroundData myBackground;
481
482 private:
483   QImage myDumpImage;
484 };
485
486 #ifdef WIN32
487 #pragma warning( default:4251 )
488 #endif
489
490 #endif