Back to index

salome-gui  6.5.0
SVTK_ViewWindow.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef SVTK_VIEWWINDOW_H
00024 #define SVTK_VIEWWINDOW_H
00025 
00026 #ifdef WIN32
00027 #pragma warning( disable:4251 )
00028 #endif
00029 
00030 #include "SVTK.h"
00031 #include "SVTK_Selection.h"
00032 #include "Qtx.h"
00033 #include "SUIT_ViewWindow.h"
00034 
00035 #include "SALOME_InteractiveObject.hxx"
00036 
00037 #include <QImage>
00038 #include <vtkSmartPointer.h>
00039 
00040 class SUIT_Desktop;
00041 class SUIT_ResourceMgr;
00042 
00043 class VTKViewer_Actor;
00044 class VTKViewer_Trihedron;
00045 
00046 class SVTK_ViewModelBase;
00047 class SVTK_Selector;
00048 class SVTK_View;
00049 
00050 class SVTK_CubeAxesActor2D;
00051 
00052 class vtkRenderer;
00053 class vtkRenderWindow;
00054 class vtkRenderWindowInteractor;
00055 class vtkInteractorStyle;
00056 class vtkCallbackCommand;
00057 
00058 class SVTK_RenderWindowInteractor;
00059 class SVTK_Renderer;
00060 class SVTK_NonIsometricDlg;
00061 class SVTK_UpdateRateDlg;
00062 class SVTK_CubeAxesDlg;
00063 class SVTK_SetRotationPointDlg;
00064 class SVTK_InteractorStyle;
00065 class SVTK_KeyFreeInteractorStyle;
00066 class SVTK_ViewParameterDlg;
00067 class SVTK_Recorder;
00068 
00069 class vtkPVAxesWidget;
00070 
00071 class vtkObject;
00072 class QtxAction;
00073 
00074 namespace SVTK
00075 {
00076   SVTK_EXPORT
00077     int convertAction( const int );
00078 }
00079 
00081 class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow
00082 {
00083   Q_OBJECT;
00084 
00085  public:
00087   SVTK_ViewWindow(SUIT_Desktop* theDesktop);
00088 
00089   virtual ~SVTK_ViewWindow();
00090   
00091   virtual QImage dumpView();
00092 
00094   virtual void Initialize(SVTK_ViewModelBase* theModel);
00095 
00097   SVTK_View* getView();
00098 
00100   vtkRenderWindow* getRenderWindow();
00101 
00103   vtkRenderWindowInteractor* getInteractor() const;
00104 
00106   SVTK_RenderWindowInteractor*  GetInteractor() const;
00107 
00109   vtkInteractorStyle* GetInteractorStyle() const;
00110 
00112   void PushInteractorStyle(vtkInteractorStyle* theStyle);
00113 
00115   void PopInteractorStyle();
00116 
00118   vtkRenderer* getRenderer() const;
00119   
00121   SVTK_Renderer* GetRenderer() const;
00122 
00124   SVTK_Selector* GetSelector() const;
00125   
00127   Selection_Mode SelectionMode() const;
00128   
00130   virtual void SetSelectionMode(Selection_Mode theMode);
00131 
00133   virtual void setBackgroundColor( const QColor& );
00134 
00136   QColor backgroundColor() const;
00137 
00139   virtual void setBackground( const Qtx::BackgroundData& );
00140 
00142   Qtx::BackgroundData background() const;
00143 
00145   bool isTrihedronDisplayed();
00146 
00148   bool isCubeAxesDisplayed();
00149  
00150   /*  interactive object management */
00152   virtual void highlight(const Handle(SALOME_InteractiveObject)& theIO, 
00153                          bool theIsHighlight = true, 
00154                          bool theIsUpdate = true);
00155 
00157   virtual void unHighlightAll();
00158 
00160   bool isInViewer(const Handle(SALOME_InteractiveObject)& theIObject);
00161 
00163   bool isVisible(const Handle(SALOME_InteractiveObject)& theIObject);
00164 
00166   //----------------------------------------------------------------------------
00167   Handle(SALOME_InteractiveObject) FindIObject(const char* theEntry);
00168   
00169   /* display */         
00170   //----------------------------------------------------------------------------
00172   virtual void Display(const Handle(SALOME_InteractiveObject)& theIObject,
00173                        bool theImmediatly = true);
00174 
00176   virtual void DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject);
00177 
00179   virtual void Erase(const Handle(SALOME_InteractiveObject)& theIObject,
00180                      bool theImmediatly = true);
00181 
00183   virtual void DisplayAll();
00184 
00186   virtual void EraseAll();
00187 
00189   virtual void Repaint(bool theUpdateTrihedron = true);
00190 
00191   //----------------------------------------------------------------------------
00193   virtual void SetScale( double theScale[3] );
00194 
00196   virtual void GetScale( double theScale[3] );
00197 
00199   virtual void AddActor(VTKViewer_Actor* theActor,
00200                         bool theIsUpdate = false,
00201                         bool theIsAdjustActors = true);
00202 
00204   virtual void RemoveActor(VTKViewer_Actor* theActor,
00205                            bool theIsUpdate = false,
00206                            bool theIsAdjustActors = true);
00207 
00208   //----------------------------------------------------------------------------
00210   virtual void AdjustTrihedrons(const bool theIsForced);
00211 
00213   VTKViewer_Trihedron* GetTrihedron();
00214 
00216   SVTK_CubeAxesActor2D* GetCubeAxes();
00217 
00219   vtkFloatingPointType GetTrihedronSize() const;
00220 
00222   virtual void SetTrihedronSize( const vtkFloatingPointType, const bool = true );
00223 
00225   virtual void SetIncrementalSpeed( const int, const int = 0 );
00226 
00228   virtual void SetProjectionMode( const int );
00229 
00231   virtual void SetInteractionStyle( const int );
00232 
00234   virtual void SetZoomingStyle( const int );
00235 
00237   virtual void SetDynamicPreSelection( bool );
00238 
00240   virtual void SetSpacemouseButtons( const int, const int, const int );
00241 
00243   virtual void SetSelectionProp(const double& theRed = 1, 
00244                                 const double& theGreen = 1,
00245                                 const double& theBlue = 0, 
00246                                 const int& theWidth = 5);
00247 
00249   virtual void SetPreselectionProp(const double& theRed = 0, 
00250                                    const double& theGreen = 1,
00251                                    const double& theBlue = 1, 
00252                                    const int& theWidth = 5);
00253 
00255   virtual void SetSelectionTolerance(const double& theTolNodes = 0.025, 
00256                                      const double& theTolCell = 0.001,
00257                                      const double& theTolObjects = 0.025);
00258 
00260   bool IsStaticTrihedronVisible() const;
00261 
00263   virtual void SetStaticTrihedronVisible( const bool );
00264 
00266   virtual QString getVisualParameters();
00267   
00268   virtual void setVisualParameters( const QString& parameters );
00269 
00270   virtual bool eventFilter( QObject*, QEvent* );
00271 
00272   virtual void RefreshDumpImage();
00273 
00274   void emitTransformed();
00275 
00277   void InvokeEvent(unsigned long theEvent, void* theCallData);
00278   
00279  signals:
00280   void Show( QShowEvent * );
00281   void Hide( QHideEvent * );
00282 
00283 public slots:
00284   virtual void showEvent( QShowEvent * );
00285   virtual void hideEvent( QHideEvent * );
00286   virtual void onSelectionChanged();
00287 
00288   void onChangeRotationPoint(bool theIsActivate);
00289 
00290   void activateSetRotationGravity();
00291   void activateSetRotationSelected(void* theData);
00292   void activateStartPointSelection();
00293 
00294   void onUpdateRate(bool theIsActivate);
00295   void onNonIsometric(bool theIsActivate);
00296   void onGraduatedAxes(bool theIsActivate);
00297 
00298   void activateZoom();
00299   void activateWindowFit();
00300   void activateRotation();
00301   void activatePanning(); 
00302   void activateGlobalPanning(); 
00303 
00304   void onPerspectiveMode();
00305 
00306   void activateProjectionMode(int);
00307 
00308   void activateSetFocalPointGravity();
00309   void activateSetFocalPointSelected();
00310   void activateStartFocalPointSelection();
00311 
00312   void onViewParameters(bool theIsActivate);
00313 
00314   void onSwitchInteractionStyle(bool theOn);
00315   void onSwitchZoomingStyle(bool theOn);
00316   void onSwitchDynamicPreSelection(bool theOn);
00317 
00318   void onStartRecording();
00319   void onPlayRecording();
00320   void onPauseRecording();
00321   void onStopRecording();
00322 
00323 signals:
00324  void selectionChanged();
00325  void actorAdded(VTKViewer_Actor*);
00326  void actorRemoved(VTKViewer_Actor*);
00327  void transformed(SVTK_ViewWindow*);
00328 
00329 public slots:
00331   virtual void onFrontView(); 
00332 
00334   virtual void onBackView(); 
00335 
00337   virtual void onTopView();
00338 
00340   virtual void onBottomView();
00341 
00343   virtual void onRightView(); 
00344 
00346   virtual void onLeftView();     
00347 
00349   virtual void onClockWiseView();
00350 
00352   virtual void onAntiClockWiseView();
00353 
00355   virtual void onResetView();     
00356 
00358   virtual void onFitAll();
00359 
00361   virtual void onViewTrihedron(); 
00362 
00364   virtual void onViewCubeAxes();
00365 
00367   virtual void onAdjustTrihedron();
00368 
00370   virtual void onAdjustCubeAxes();
00371   
00372   virtual void synchronize(SVTK_ViewWindow*);
00373     
00374 protected slots:
00375   void onKeyPressed(QKeyEvent* event);
00376   void onKeyReleased(QKeyEvent* event);
00377   void onMousePressed(QMouseEvent* event);
00378   void onMouseDoubleClicked(QMouseEvent* event);
00379   void onMouseReleased(QMouseEvent* event);
00380   void onMouseMoving(QMouseEvent* event);
00381 
00382 protected:
00383   virtual void Initialize(SVTK_View* theView,
00384                           SVTK_ViewModelBase* theModel);
00385 
00386   // Main process event method
00387   static void ProcessEvents(vtkObject* object,
00388                             unsigned long event,
00389                             void* clientdata,
00390                             void* calldata);
00391 
00392   void doSetVisualParameters( const QString&, bool = false );
00393   void SetEventDispatcher(vtkObject* theDispatcher);
00394 
00395   QImage dumpViewContent();
00396 
00397   virtual QString filter() const;
00398   virtual bool dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format );
00399   
00400   virtual bool action( const int );
00401   
00402   QtxAction* getAction( int ) const;
00403   void createToolBar();
00404   void createActions(SUIT_ResourceMgr* theResourceMgr);
00405 
00406   enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, 
00407          ChangeRotationPointId, RotationId,
00408          FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId, ResetId,
00409         ViewTrihedronId, NonIsometric, GraduatedAxes, UpdateRate,
00410          ParallelModeId, ProjectionModeId, ViewParametersId, SynchronizeId, SwitchInteractionStyleId,
00411          SwitchZoomingStyleId,SwitchDynamicPreselectionId,
00412          StartRecordingId, PlayRecordingId, PauseRecordingId, StopRecordingId };
00413 
00414   SVTK_View* myView;
00415   SVTK_ViewModelBase* myModel;
00416 
00417   SVTK_RenderWindowInteractor* myInteractor;
00418   vtkSmartPointer<SVTK_InteractorStyle> myDefaultInteractorStyle;
00419   vtkSmartPointer<SVTK_KeyFreeInteractorStyle> myKeyFreeInteractorStyle;
00420 
00421   QString myVisualParams; // used for delayed setting of view parameters 
00422 
00423   vtkSmartPointer<vtkObject> myEventDispatcher;
00424 
00425   // Used to process events
00426   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
00427 
00428   SVTK_NonIsometricDlg* myNonIsometricDlg;
00429   SVTK_UpdateRateDlg* myUpdateRateDlg;
00430   SVTK_CubeAxesDlg* myCubeAxesDlg;
00431   SVTK_SetRotationPointDlg* mySetRotationPointDlg;
00432   SVTK_ViewParameterDlg* myViewParameterDlg;
00433 
00434   QSize myPreRecordingMinSize;
00435   QSize myPreRecordingMaxSize;
00436 
00437   SVTK_Recorder* myRecorder;
00438   QtxAction* myStartAction;
00439   QtxAction* myPlayAction;
00440   QtxAction* myPauseAction;
00441   QtxAction* myStopAction;
00442 
00443   int myToolBar;
00444   int myRecordingToolBar;
00445 
00446   vtkPVAxesWidget* myAxesWidget;
00447   Qtx::BackgroundData myBackground;
00448 
00449 private slots:
00450   void onSynchronizeView(bool);
00451   void updateSyncViews();
00452 
00453 private:
00454   static void synchronizeView( SVTK_ViewWindow*, int );
00455 
00456 private:
00457   QImage myDumpImage;
00458 };
00459 
00460 #ifdef WIN32
00461 #pragma warning( default:4251 )
00462 #endif
00463 
00464 #endif