From: asv Date: Tue, 23 Aug 2005 07:09:15 +0000 (+0000) Subject: Space mouse functionality, refactoring, etc. X-Git-Tag: BR-D5-38-2003_D2005-12-09~31 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4265b590110086214b1445b5ff4438fa0507d52b;p=modules%2Fgui.git Space mouse functionality, refactoring, etc. --- diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 102040b87..ce08447f8 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -1239,10 +1239,15 @@ SVTK_InteractorStyle { // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc) vtkInteractorStyle::SetInteractor( interactor ); + + if ( interactor ) { + // initialize renderer attribute + FindPokedRenderer( 0, 0 ); - // register EventCallbackCommand as observer of custorm event (3d space mouse event) - interactor->AddObserver( SpaceMouseMoveEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SpaceMouseButtonEvent, EventCallbackCommand, Priority ); + // register EventCallbackCommand as observer of custorm event (3d space mouse event) + interactor->AddObserver( SpaceMouseMoveEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SpaceMouseButtonEvent, EventCallbackCommand, Priority ); + } } diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index c61f49056..751fee55b 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -106,15 +106,6 @@ class SVTK_EXPORT SVTK_InteractorStyle : virtual void OnRightButtonDown(); virtual void OnRightButtonUp(); - // Generic event bindings must be overridden in subclasses - void OnMouseMove (int ctrl, int shift, int x, int y); - void OnLeftButtonDown(int ctrl, int shift, int x, int y); - void OnLeftButtonUp (int ctrl, int shift, int x, int y); - void OnMiddleButtonDown(int ctrl, int shift, int x, int y); - void OnMiddleButtonUp (int ctrl, int shift, int x, int y); - void OnRightButtonDown(int ctrl, int shift, int x, int y); - void OnRightButtonUp (int ctrl, int shift, int x, int y); - void SetFilter( const Handle(VTKViewer_Filter)& ); @@ -147,6 +138,15 @@ class SVTK_EXPORT SVTK_InteractorStyle : SVTK_InteractorStyle(const SVTK_InteractorStyle&) {}; void operator=(const SVTK_InteractorStyle&) {}; + // Generic event bindings must be overridden in subclasses + virtual void OnMouseMove (int ctrl, int shift, int x, int y); + virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y); + virtual void OnLeftButtonUp (int ctrl, int shift, int x, int y); + virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y); + virtual void OnMiddleButtonUp (int ctrl, int shift, int x, int y); + virtual void OnRightButtonDown(int ctrl, int shift, int x, int y); + virtual void OnRightButtonUp (int ctrl, int shift, int x, int y); + void RotateXY(int dx, int dy); void PanXY(int x, int y, int oldX, int oldY); void DollyXY(int dx, int dy); diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 76c1c0102..fd2751d47 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -50,8 +50,7 @@ SVTK_View SetSelector(SVTK_Selector::New()); GetSelector()->Delete(); - SetInteractorStyle(SVTK_InteractorStyle::New()); - GetInteractorStyle()->Delete(); + pushInteractorStyle( SVTK_InteractorStyle::New() ); } //---------------------------------------------------------------------------- @@ -60,26 +59,6 @@ SVTK_View { } -//---------------------------------------------------------------------------- -SVTK_InteractorStyle* -SVTK_View -::GetInteractorStyle() -{ - return myInteractorStyle.GetPointer(); -} - -void -SVTK_View -::SetInteractorStyle( SVTK_InteractorStyle* theStyle ) -{ - myInteractorStyle = theStyle; - getInteractor()->SetInteractorStyle( theStyle ); - myInteractorStyle->FindPokedRenderer( 0, 0 ); - - myInteractorStyle->SetSelector( GetSelector() ); - myInteractorStyle->SetRenderWidget( this ); -} - //---------------------------------------------------------------------------- SVTK_Selector* SVTK_View @@ -125,7 +104,7 @@ void SVTK_View ::activateZoom() { - myInteractorStyle->startZoom(); + getInteractorStyle()->startZoom(); } //---------------------------------------------------------------------------- @@ -133,7 +112,7 @@ void SVTK_View ::activatePanning() { - myInteractorStyle->startPan(); + getInteractorStyle()->startPan(); } //---------------------------------------------------------------------------- @@ -141,7 +120,7 @@ void SVTK_View ::activateRotation() { - myInteractorStyle->startRotate(); + getInteractorStyle()->startRotate(); } //---------------------------------------------------------------------------- @@ -149,7 +128,7 @@ void SVTK_View ::activateGlobalPanning() { - myInteractorStyle->startGlobalPan(); + getInteractorStyle()->startGlobalPan(); } //---------------------------------------------------------------------------- @@ -157,7 +136,7 @@ void SVTK_View ::activateWindowFit() { - myInteractorStyle->startFitArea(); + getInteractorStyle()->startFitArea(); } //---------------------------------------------------------------- @@ -241,118 +220,6 @@ SVTK_View update(); } -#define INCREMENT_FOR_OP 10 - -//======================================================================= -// name : onPanLeft -// Purpose : Performs incremental panning to the left -//======================================================================= -void -SVTK_View -::onPanLeft() -{ - myInteractorStyle->IncrementalPan( -INCREMENT_FOR_OP, 0 ); -} - -//======================================================================= -// name : onPanRight -// Purpose : Performs incremental panning to the right -//======================================================================= -void -SVTK_View -::onPanRight() -{ - myInteractorStyle->IncrementalPan( INCREMENT_FOR_OP, 0 ); -} - -//======================================================================= -// name : onPanUp -// Purpose : Performs incremental panning to the top -//======================================================================= -void -SVTK_View -::onPanUp() -{ - myInteractorStyle->IncrementalPan( 0, INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onPanDown -// Purpose : Performs incremental panning to the bottom -//======================================================================= -void -SVTK_View -::onPanDown() -{ - myInteractorStyle->IncrementalPan( 0, -INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onZoomIn -// Purpose : Performs incremental zooming in -//======================================================================= -void -SVTK_View -::onZoomIn() -{ - myInteractorStyle->IncrementalZoom( INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onZoomOut -// Purpose : Performs incremental zooming out -//======================================================================= -void -SVTK_View -::onZoomOut() -{ - myInteractorStyle->IncrementalZoom( -INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onRotateLeft -// Purpose : Performs incremental rotating to the left -//======================================================================= -void -SVTK_View -::onRotateLeft() -{ - myInteractorStyle->IncrementalRotate( -INCREMENT_FOR_OP, 0 ); -} - -//======================================================================= -// name : onRotateRight -// Purpose : Performs incremental rotating to the right -//======================================================================= -void -SVTK_View -::onRotateRight() -{ - myInteractorStyle->IncrementalRotate( INCREMENT_FOR_OP, 0 ); -} - -//======================================================================= -// name : onRotateUp -// Purpose : Performs incremental rotating to the top -//======================================================================= -void -SVTK_View -::onRotateUp() -{ - myInteractorStyle->IncrementalRotate( 0, -INCREMENT_FOR_OP ); -} - -//======================================================================= -// name : onRotateDown -// Purpose : Performs incremental rotating to the bottom -//======================================================================= -void -SVTK_View -::onRotateDown() -{ - myInteractorStyle->IncrementalRotate( 0, INCREMENT_FOR_OP ); -} - //---------------------------------------------------------------------------- void SVTK_View @@ -439,3 +306,44 @@ SVTK_View } } } + +//---------------------------------------------------------------------------- +void +SVTK_View +::initInteractorStyle( SVTK_InteractorStyle* interactorStyle ) +{ + getInteractor()->SetInteractorStyle( interactorStyle ); + interactorStyle->FindPokedRenderer( 0, 0 ); + + interactorStyle->SetSelector( GetSelector() ); + interactorStyle->SetRenderWidget( this ); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::pushInteractorStyle( SVTK_InteractorStyle* interactorStyle ) +{ + myInteractorStyles.push( interactorStyle ); + initInteractorStyle( interactorStyle ); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::popInteractorStyle() +{ + if ( getInteractorStyle() ) + myInteractorStyles.pop(); + + if ( getInteractorStyle() ) + initInteractorStyle( getInteractorStyle() ); +} + +//---------------------------------------------------------------------------- +SVTK_InteractorStyle* +SVTK_View +::getInteractorStyle() +{ + return myInteractorStyles.empty() ? 0 : myInteractorStyles.top(); +} diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index f8dcba03d..56c2f6ba3 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -13,6 +13,8 @@ #include +#include + class vtkCallbackCommand; class VTKViewer_Actor; @@ -30,12 +32,13 @@ public: SVTK_View( QWidget*, const char* ); virtual ~SVTK_View(); - SVTK_InteractorStyle* GetInteractorStyle(); - void SetInteractorStyle( SVTK_InteractorStyle* ); - SVTK_Selector* GetSelector(); void SetSelector( SVTK_Selector* theSelector ); + SVTK_InteractorStyle* getInteractorStyle(); + void pushInteractorStyle( SVTK_InteractorStyle* ); + void popInteractorStyle(); + // Main process VTK event method static void @@ -87,17 +90,6 @@ signals: void selectionChanged(); public slots: - void onPanLeft(); - void onPanRight(); - void onPanUp(); - void onPanDown(); - void onZoomIn(); - void onZoomOut(); - void onRotateLeft(); - void onRotateRight(); - void onRotateUp(); - void onRotateDown(); - virtual void activateZoom(); virtual void activateWindowFit(); virtual void activateRotation(); @@ -119,7 +111,9 @@ private: float myPriority; vtkSmartPointer mySelector; - vtkSmartPointer myInteractorStyle; + + void initInteractorStyle( SVTK_InteractorStyle* ); + std::stack myInteractorStyles; double myCurScale; }; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 77305f97a..2854b4cec 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -49,19 +49,18 @@ SVTK_ViewWindow aLayout->setAutoAdd( true ); QSplitter* aSplitter = new QSplitter( Qt::Vertical, aCentralWidget ); - // Create an interactor. + // Create SVTK_View (successor of RenderWindowInteractor). myView = new SVTK_View( aSplitter, "SVTK_View" ); + myView->Initialize(); + myView->setFocusPolicy( StrongFocus ); + myView->setFocus(); + /* SVTK_View* bottomView = new SVTK_View( aSplitter, "BottomView" ); bottomView->getInteractor()->SetInteractorStyle( myInteractorStyle ); bottomView->Initialize(); */ - myView->Initialize(); - - myView->setFocusPolicy( StrongFocus ); - myView->setFocus(); - connect( myView, SIGNAL(KeyPressed( QKeyEvent* )), this, SLOT(onKeyPressed( QKeyEvent* )) ); connect( myView, SIGNAL(KeyReleased( QKeyEvent* )), @@ -79,9 +78,7 @@ SVTK_ViewWindow connect( myView, SIGNAL(selectionChanged()), theModel,SLOT(onSelectionChanged())); - onResetView(); - setFocusProxy( myView ); // send focus events to myView (fixes a bug // when on module activation myView received focusOutEvent } @@ -91,6 +88,15 @@ SVTK_ViewWindow ::~SVTK_ViewWindow() {} + +//---------------------------------------------------------------------------- +SVTK_InteractorStyle* +SVTK_ViewWindow +::getInteractorStyle() +{ + return myView->getInteractorStyle(); +} + //---------------------------------------------------------------------------- vtkRenderer* SVTK_ViewWindow @@ -107,14 +113,6 @@ SVTK_ViewWindow return myView->GetSelector(); } -//---------------------------------------------------------------------------- -SVTK_InteractorStyle* -SVTK_ViewWindow -::getInteractorStyle() -{ - return myView->GetInteractorStyle(); -} - //---------------------------------------------------------------------------- SVTK_View* SVTK_ViewWindow diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 490b6a795..ff747772d 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -13,8 +13,6 @@ #include "SALOME_InteractiveObject.hxx" -#include - class SUIT_Desktop; class VTKViewer_Actor; @@ -23,8 +21,6 @@ class VTKViewer_Trihedron; class SVTK_ViewModelBase; class SVTK_Selector; -//class SVTK_View; -//class SVTK_RenderWindowInteractor; class SVTK_InteractorStyle; class SVTK_CubeAxesActor2D; @@ -43,12 +39,13 @@ public: vtkRenderer* getRenderer(); SVTK_Selector* GetSelector(); - SVTK_InteractorStyle* getInteractorStyle(); - + SVTK_View* getView(); SVTK_View* getRenderWindow(); SVTK_View* getRWInteractor(); + SVTK_InteractorStyle* getInteractorStyle(); + Selection_Mode SelectionMode() const; void SetSelectionMode(Selection_Mode theMode);