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