Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / SVTK / SVTK_ViewWindow.h
1 //  Copyright (C) 2007-2008  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.
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 #ifndef SVTK_VIEWWINDOW_H
23 #define SVTK_VIEWWINDOW_H
24
25 #ifdef WIN32
26 #pragma warning( disable:4251 )
27 #endif
28
29 #include "SVTK.h"
30 #include "SVTK_Selection.h"
31 #include "SUIT_ViewWindow.h"
32
33 #include "SALOME_InteractiveObject.hxx"
34
35 #include <QImage>
36 #include <vtkSmartPointer.h>
37
38 class SUIT_Desktop;
39 class SUIT_ResourceMgr;
40
41 class VTKViewer_Actor;
42 class VTKViewer_Trihedron;
43
44 class SVTK_ViewModelBase;
45 //class SVTK_MainWindow;
46 class SVTK_Selector;
47 class SVTK_View;
48
49 class SVTK_CubeAxesActor2D;
50
51 class vtkRenderer;
52 class vtkRenderWindow;
53 class vtkRenderWindowInteractor;
54 class vtkInteractorStyle;
55 class SVTK_RenderWindowInteractor;
56 class SVTK_Renderer;
57 class SVTK_NonIsometricDlg;
58 class SVTK_UpdateRateDlg;
59 class SVTK_CubeAxesDlg;
60 class SVTK_SetRotationPointDlg;
61 class SVTK_KeyFreeInteractorStyle;
62 class SVTK_ViewParameterDlg;
63 class SVTK_Recorder;
64
65 class vtkObject;
66 class QtxAction;
67
68 namespace SVTK
69 {
70   SVTK_EXPORT
71     int convertAction( const int );
72 }
73
74 //! Define a container for SALOME VTK view window
75 class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
76 {
77   Q_OBJECT;
78
79  public:
80   //! To construct #SVTK_ViewWindow instance
81   SVTK_ViewWindow(SUIT_Desktop* theDesktop);
82
83   virtual ~SVTK_ViewWindow();
84   
85   virtual QImage dumpView();
86
87   //! To initialize #SVTK_ViewWindow instance
88   virtual void Initialize(SVTK_ViewModelBase* theModel);
89
90   //! Get #SVTK_View
91   SVTK_View* getView();
92
93   //! Get #SVTK_MainWindow
94   //SVTK_MainWindow* getMainWindow();
95
96   //! Redirect the request to #SVTK_MainWindow::getRenderWindow
97   vtkRenderWindow* getRenderWindow();
98
99   //! Redirect the request to #SVTK_MainWindow::getInteractor
100   vtkRenderWindowInteractor* getInteractor() const;
101
102   //! Redirect the request to #SVTK_MainWindow::getInteractor
103   SVTK_RenderWindowInteractor*  GetInteractor() const;
104
105   vtkInteractorStyle* GetInteractorStyle() const;
106
107   //! Redirect the request to #SVTK_RenderWindowInteractor::PushInteractorStyle
108   void PushInteractorStyle(vtkInteractorStyle* theStyle);
109
110   //! Redirect the request to #SVTK_RenderWindowInteractor::PopInteractorStyle
111   void PopInteractorStyle();
112
113   //! Redirect the request to #SVTK_MainWindow::getRenderer 
114   vtkRenderer* getRenderer() const;
115
116   SVTK_Renderer* GetRenderer() const;
117
118   //! Redirect the request to #SVTK_MainWindow::GetSelector 
119   SVTK_Selector* GetSelector() const;
120   
121   //! Redirect the request to #SVTK_Selector::SelectionMode
122   Selection_Mode SelectionMode() const;
123   
124   //! Change selection mode
125   virtual void SetSelectionMode(Selection_Mode theMode);
126
127   //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor 
128   virtual void setBackgroundColor( const QColor& );
129
130   //! Redirect the request to #SVTK_MainWindow::SetBackgroundColor 
131   QColor backgroundColor() const;
132
133   //! Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
134   bool isTrihedronDisplayed();
135
136   //! Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
137   bool isCubeAxesDisplayed();
138  
139   /*  interactive object management */
140   //! Redirect the request to #SVTK_View::highlight (to support old code)
141   virtual void highlight(const Handle(SALOME_InteractiveObject)& theIO, 
142                          bool theIsHighlight = true, 
143                          bool theIsUpdate = true);
144
145   //! Redirect the request to #SVTK_View::unHighlightAll (to support old code)
146   virtual void unHighlightAll();
147
148   //! Redirect the request to #SVTK_View::isInViewer (to support old code)
149   bool isInViewer(const Handle(SALOME_InteractiveObject)& theIObject);
150
151   //! Redirect the request to #SVTK_View::isVisible (to support old code)
152   bool isVisible(const Handle(SALOME_InteractiveObject)& theIObject);
153
154   //! Redirect the request to #SVTK_View::FindIObject (to support old code)
155   //----------------------------------------------------------------------------
156   Handle(SALOME_InteractiveObject) FindIObject(const char* theEntry);
157   
158   /* display */         
159   //----------------------------------------------------------------------------
160   //! Redirect the request to #SVTK_View::Display (to support old code)
161   virtual void Display(const Handle(SALOME_InteractiveObject)& theIObject,
162                        bool theImmediatly = true);
163
164   //! Redirect the request to #SVTK_View::DisplayOnly (to support old code)
165   virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject);
166
167   //! Redirect the request to #SVTK_View::Erase (to support old code)
168   virtual void Erase(const Handle(SALOME_InteractiveObject)& theIObject,
169                      bool theImmediatly = true);
170
171   //! Redirect the request to #SVTK_View::DisplayAll (to support old code)
172   virtual void DisplayAll();
173
174   //! Redirect the request to #SVTK_View::EraseAll (to support old code)
175   virtual void EraseAll();
176
177   //! To repaint the viewer
178   virtual void Repaint(bool theUpdateTrihedron = true);
179
180   //----------------------------------------------------------------------------
181   //! Redirect the request to #SVTK_Renderer::SetScale
182   virtual void SetScale( double theScale[3] );
183
184   //! Redirect the request to #SVTK_Renderer::GetScale
185   virtual void GetScale( double theScale[3] );
186
187   //! Redirect the request to #SVTK_Renderer::AddActor
188   virtual void AddActor(VTKViewer_Actor* theActor,
189                         bool theIsUpdate = false);
190
191   //! Redirect the request to #SVTK_Renderer::RemoveActor
192   virtual void RemoveActor(VTKViewer_Actor* theActor,
193                            bool theIsUpdate = false);
194
195   //----------------------------------------------------------------------------
196   //! Redirect the request to #SVTK_Renderer::AdjustActors
197   virtual void AdjustTrihedrons(const bool theIsForced);
198
199   //! Redirect the request to #SVTK_Renderer::GetTrihedron
200   VTKViewer_Trihedron* GetTrihedron();
201
202   //! Redirect the request to #SVTK_Renderer::GetCubeAxes
203   SVTK_CubeAxesActor2D* GetCubeAxes();
204
205   //! Redirect the request to #SVTK_Renderer::GetTrihedronSize
206   vtkFloatingPointType GetTrihedronSize() const;
207
208   //! Redirect the request to #SVTK_Renderer::SetTrihedronSize
209   virtual void SetTrihedronSize( const vtkFloatingPointType, const bool = true );
210
211   //! Redirect the request to #SVTK_MainWindow::SetIncrementalSpeed
212   virtual void SetIncrementalSpeed( const int, const int = 0 );
213
214   //! Redirect the request to #SVTK_MainWindow::SetProjectionMode
215   virtual void SetProjectionMode( const int );
216
217   //! Redirect the request to #SVTK_MainWindow::SetInteractionStyle
218   virtual void SetInteractionStyle( const int );
219
220   //! Redirect the request to #SVTK_MainWindow::SetSpacemouseButtons
221   virtual void SetSpacemouseButtons( const int, const int, const int );
222
223   //! Redirect the request to #SVTK_Renderer::SetSelectionProp
224   virtual void SetSelectionProp(const double& theRed = 1, 
225                                 const double& theGreen = 1,
226                                 const double& theBlue = 0, 
227                                 const int& theWidth = 5);
228
229   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
230   virtual void SetPreselectionProp(const double& theRed = 0, 
231                                    const double& theGreen = 1,
232                                    const double& theBlue = 1, 
233                                    const int& theWidth = 5);
234
235   //! Redirect the request to #SVTK_Renderer::SetSelectionTolerance
236   virtual void SetSelectionTolerance(const double& theTolNodes = 0.025, 
237                                      const double& theTolCell = 0.001,
238                                      const double& theTolObjects = 0.025);
239
240   //! Methods to save/restore visual parameters of a view (pan, zoom, etc.)
241   virtual QString getVisualParameters();
242   
243   virtual void setVisualParameters( const QString& parameters );
244
245   virtual bool eventFilter( QObject*, QEvent* );
246
247   virtual void RefreshDumpImage();
248
249   //! To invoke a VTK event on #SVTK_RenderWindowInteractor instance
250   void InvokeEvent(unsigned long theEvent, void* theCallData);
251   
252  signals:
253   void Show( QShowEvent * );
254   void Hide( QHideEvent * );
255
256 public slots:
257   virtual void showEvent( QShowEvent * );
258   virtual void hideEvent( QHideEvent * );
259   virtual void onSelectionChanged();
260
261   void onChangeRotationPoint(bool theIsActivate);
262
263   void activateSetRotationGravity();
264   void activateSetRotationSelected(void* theData);
265   void activateStartPointSelection();
266
267   void onUpdateRate(bool theIsActivate);
268   void onNonIsometric(bool theIsActivate);
269   void onGraduatedAxes(bool theIsActivate);
270
271   void activateZoom();
272   void activateWindowFit();
273   void activateRotation();
274   void activatePanning(); 
275   void activateGlobalPanning(); 
276
277   void onPerspectiveMode();
278
279   void activateProjectionMode(int);
280
281   void activateSetFocalPointGravity();
282   void activateSetFocalPointSelected();
283   void activateStartFocalPointSelection();
284
285   void onViewParameters(bool theIsActivate);
286
287   void onSwitchInteractionStyle(bool theOn);
288
289   void onStartRecording();
290   void onPlayRecording();
291   void onPauseRecording();
292   void onStopRecording();
293
294 signals:
295  void selectionChanged();
296  void actorAdded(VTKViewer_Actor*);
297  void actorRemoved(VTKViewer_Actor*);
298
299 public slots:
300   //! Redirect the request to #SVTK_Renderer::OnFrontView
301   virtual void onFrontView(); 
302
303   //! Redirect the request to #SVTK_Renderer::OnBackView
304   virtual void onBackView(); 
305
306   //! Redirect the request to #SVTK_Renderer::OnTopView
307   virtual void onTopView();
308
309   //! Redirect the request to #SVTK_Renderer::OnBottomView
310   virtual void onBottomView();
311
312   //! Redirect the request to #SVTK_Renderer::OnRightView
313   virtual void onRightView(); 
314
315   //! Redirect the request to #SVTK_Renderer::OnLeftView
316   virtual void onLeftView();     
317
318   //! Redirect the request to #SVTK_Renderer::OnResetView
319   virtual void onResetView();     
320
321   //! Redirect the request to #SVTK_Renderer::OnFitAll
322   virtual void onFitAll();
323
324   //! Redirect the request to #SVTK_Renderer::OnViewTrihedron
325   virtual void onViewTrihedron(); 
326
327   //! Redirect the request to #SVTK_Renderer::OnViewCubeAxes
328   virtual void onViewCubeAxes();
329
330   //! Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
331   virtual void onAdjustTrihedron();
332
333   //! Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
334   virtual void onAdjustCubeAxes();
335
336 protected slots:
337   void onKeyPressed(QKeyEvent* event);
338   void onKeyReleased(QKeyEvent* event);
339   void onMousePressed(QMouseEvent* event);
340   void onMouseDoubleClicked(QMouseEvent* event);
341   void onMouseReleased(QMouseEvent* event);
342   void onMouseMoving(QMouseEvent* event);
343
344 protected:
345   virtual void Initialize(SVTK_View* theView,
346                           SVTK_ViewModelBase* theModel);
347
348   void doSetVisualParameters( const QString& );
349   void SetEventDispatcher(vtkObject* theDispatcher);
350
351   QImage dumpViewContent();
352
353   virtual QString filter() const;
354   virtual bool dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format );
355   
356   virtual bool action( const int );
357   
358   QtxAction* getAction( int ) const;
359   void createToolBar();
360   void createActions(SUIT_ResourceMgr* theResourceMgr);
361
362   enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, 
363          ChangeRotationPointId, RotationId,
364          FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, 
365          ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate,
366          ParallelModeId, ProjectionModeId, ViewParametersId, SwitchInteractionStyleId,
367          StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId };
368
369
370   SVTK_View* myView;
371   //SVTK_MainWindow* myMainWindow;
372   SVTK_ViewModelBase* myModel;
373
374   SVTK_RenderWindowInteractor* myInteractor;
375   vtkSmartPointer<SVTK_KeyFreeInteractorStyle> myKeyFreeInteractorStyle;
376
377   QString myVisualParams; // used for delayed setting of view parameters 
378
379   vtkSmartPointer<vtkObject> myEventDispatcher;
380
381   SVTK_NonIsometricDlg* myNonIsometricDlg;
382   SVTK_UpdateRateDlg* myUpdateRateDlg;
383   SVTK_CubeAxesDlg* myCubeAxesDlg;
384   SVTK_SetRotationPointDlg* mySetRotationPointDlg;
385   SVTK_ViewParameterDlg* myViewParameterDlg;
386
387   QSize myPreRecordingMinSize;
388   QSize myPreRecordingMaxSize;
389
390   SVTK_Recorder* myRecorder;
391   QtxAction* myStartAction;
392   QtxAction* myPlayAction;
393   QtxAction* myPauseAction;
394   QtxAction* myStopAction;
395
396   int myToolBar;
397   int myRecordingToolBar;
398
399 private:
400   QImage myDumpImage;
401 };
402
403 #ifdef WIN32
404 #pragma warning( default:4251 )
405 #endif
406
407 #endif