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