From 54e257c0eb03a81c44af9ba541dc205156a539d8 Mon Sep 17 00:00:00 2001 From: asv Date: Wed, 24 Aug 2005 12:34:47 +0000 Subject: [PATCH] Handling of various events is moved to InteractorStyle class. The events are fired from RenderWindowInteractor (fireEvent function). --- src/SVTK/Makefile.in | 2 +- .../{SVTK_SpaceMouseEvent.h => SVTK_Event.h} | 23 +++- src/SVTK/SVTK_InteractorStyle.cxx | 109 ++++++++++++------ src/SVTK/SVTK_InteractorStyle.h | 10 +- src/SVTK/SVTK_RenderWindowInteractor.cxx | 9 +- src/SVTK/SVTK_RenderWindowInteractor.h | 3 + src/SVTK/SVTK_ViewWindow.cxx | 34 +++++- src/SVTK/SVTK_ViewWindow.h | 1 + 8 files changed, 148 insertions(+), 43 deletions(-) rename src/SVTK/{SVTK_SpaceMouseEvent.h => SVTK_Event.h} (75%) diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index a5c9b1f8a..f56bd406b 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -30,7 +30,7 @@ EXPORT_HEADERS= SVTK.h \ SVTK_Selection.h \ SVTK_SelectionEvent.h \ SVTK_SpaceMouse.h \ - SVTK_SpaceMouseEvent.h \ + SVTK_Event.h \ SVTK_ViewModelBase.h # Libraries targets diff --git a/src/SVTK/SVTK_SpaceMouseEvent.h b/src/SVTK/SVTK_Event.h similarity index 75% rename from src/SVTK/SVTK_SpaceMouseEvent.h rename to src/SVTK/SVTK_Event.h index a7c4885fd..9bd10735b 100644 --- a/src/SVTK/SVTK_SpaceMouseEvent.h +++ b/src/SVTK/SVTK_Event.h @@ -31,9 +31,28 @@ #include -enum SpaceMouseEvent { +enum Event { SpaceMouseMoveEvent = vtkCommand::UserEvent+1, - SpaceMouseButtonEvent + SpaceMouseButtonEvent, + PanLeftEvent, + PanRightEvent, + PanUpEvent, + PanDownEvent, + ZoomInEvent, + ZoomOutEvent, + RotateLeftEvent, + RotateRightEvent, + RotateUpEvent, + RotateDownEvent, + PlusSpeedIncrementEvent, + MinusSpeedIncrementEvent, + SetSpeedIncrementEvent, + SetSpaceMouseF1Event, + SetSpaceMouseF2Event, + SetSpaceMouseF3Event, + SetSpaceMouseF4Event, + SetSpaceMouseF5Event, + LastEvent }; #endif diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index ce08447f8..eede37589 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -35,7 +35,7 @@ #include "SVTK_RenderWindow.h" #include "SVTK_ViewWindow.h" #include "SVTK_Selection.h" -#include "SVTK_SpaceMouseEvent.h" +#include "SVTK_Event.h" #include "SVTK_Selector.h" #include "SVTK_Functor.h" @@ -47,9 +47,6 @@ #include "SALOME_ListIteratorOfListIO.hxx" #include "SALOME_ListIO.hxx" -#include "SUIT_Session.h" -#include "SUIT_ResourceMgr.h" - #include #include #include @@ -1245,8 +1242,18 @@ SVTK_InteractorStyle FindPokedRenderer( 0, 0 ); // register EventCallbackCommand as observer of custorm event (3d space mouse event) - interactor->AddObserver( SpaceMouseMoveEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SpaceMouseMoveEvent, EventCallbackCommand, Priority ); interactor->AddObserver( SpaceMouseButtonEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( PanLeftEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( PanRightEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( PanUpEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( PanDownEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( ZoomInEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( ZoomOutEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( RotateLeftEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( RotateRightEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( RotateUpEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( RotateDownEvent, EventCallbackCommand, Priority ); } } @@ -1291,35 +1298,11 @@ void SVTK_InteractorStyle ::onSpaceMouseButton( int button ) { - // printf( "Button pressed [%d] \n", button ); - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - if ( resMgr->integerValue( "VISU", "spacemouse_func1_btn" ) == button ) - DecreaseSpeedIncrement(); - if ( resMgr->integerValue( "VISU", "spacemouse_func2_btn" ) == button ) - IncreaseSpeedIncrement(); - if ( resMgr->integerValue( "VISU", "spacemouse_func3_btn" ) == button ) - DecreaseGaussPointMagnification(); - if ( resMgr->integerValue( "VISU", "spacemouse_func4_btn" ) == button ) - IncreaseGaussPointMagnification(); - if ( resMgr->integerValue( "VISU", "spacemouse_func5_btn" ) == button ) - DominantCombinedSwitch(); -} - -//---------------------------------------------------------------------------- -void -SVTK_InteractorStyle -::DecreaseSpeedIncrement() -{ - printf( "\n--DecreaseSpeedIncrement() NOT IMPLEMENTED--\n" ); - -} - -//---------------------------------------------------------------------------- -void -SVTK_InteractorStyle -::IncreaseSpeedIncrement() -{ - printf( "\n--IncreaseSpeedIncrement() NOT IMPLEMENTED--\n" ); + if ( mySpaceMouseBtns[0] == button ) --mySpeedIncrement; + if ( mySpaceMouseBtns[1] == button ) ++mySpeedIncrement; + if ( mySpaceMouseBtns[2] == button ) DecreaseGaussPointMagnification(); + if ( mySpaceMouseBtns[3] == button ) IncreaseGaussPointMagnification(); + if ( mySpaceMouseBtns[4] == button ) DominantCombinedSwitch(); } //---------------------------------------------------------------------------- @@ -1354,10 +1337,10 @@ SVTK_InteractorStyle void* clientData, void* callData ) { - if ( event != SpaceMouseMoveEvent && event != SpaceMouseButtonEvent ) + if ( event < vtkCommand::UserEvent ) vtkInteractorStyle::ProcessEvents( object, event, clientData, callData ); - else if ( clientData && callData ) { + else if ( clientData ) { vtkObject* anObject = reinterpret_cast( clientData ); SVTK_InteractorStyle* self = dynamic_cast( anObject ); if ( self ) { @@ -1368,6 +1351,60 @@ SVTK_InteractorStyle case SpaceMouseButtonEvent : self->onSpaceMouseButton( *((int*)callData) ); break; + case PanLeftEvent: + self->IncrementalPan( -self->mySpeedIncrement, 0 ); + break; + case PanRightEvent: + self->IncrementalPan( self->mySpeedIncrement, 0 ); + break; + case PanUpEvent: + self->IncrementalPan( 0, self->mySpeedIncrement ); + break; + case PanDownEvent: + self->IncrementalPan( 0, -self->mySpeedIncrement ); + break; + case ZoomInEvent: + self->IncrementalZoom( self->mySpeedIncrement ); + break; + case ZoomOutEvent: + self->IncrementalZoom( -self->mySpeedIncrement ); + break; + case RotateLeftEvent: + self->IncrementalRotate( -self->mySpeedIncrement, 0 ); + break; + case RotateRightEvent: + self->IncrementalRotate( self->mySpeedIncrement, 0 ); + break; + case RotateUpEvent: + self->IncrementalRotate( 0, -self->mySpeedIncrement ); + break; + case RotateDownEvent: + self->IncrementalRotate( 0, self->mySpeedIncrement ); + break; + case PlusSpeedIncrementEvent: + ++(self->mySpeedIncrement); + break; + case MinusSpeedIncrementEvent: + --(self->mySpeedIncrement); + break; + case SetSpeedIncrementEvent: + self->mySpeedIncrement = *((int*)callData); + break; + case SetSpaceMouseF1Event: + self->mySpaceMouseBtns[0] = *((int*)callData); + break; + case SetSpaceMouseF2Event: + self->mySpaceMouseBtns[1] = *((int*)callData); + break; + case SetSpaceMouseF3Event: + self->mySpaceMouseBtns[2] = *((int*)callData); + break; + case SetSpaceMouseF4Event: + self->mySpaceMouseBtns[3] = *((int*)callData); + break; + case SetSpaceMouseF5Event: + self->mySpaceMouseBtns[4] = *((int*)callData); + break; } } } diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 751fee55b..ed11cf6d8 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -184,8 +184,6 @@ class SVTK_EXPORT SVTK_InteractorStyle : void onSpaceMouseMove( double* data ); void onSpaceMouseButton( int button ); - void DecreaseSpeedIncrement(); - void IncreaseSpeedIncrement(); void DecreaseGaussPointMagnification(); void IncreaseGaussPointMagnification(); void DominantCombinedSwitch(); @@ -203,6 +201,14 @@ class SVTK_EXPORT SVTK_InteractorStyle : bool myCursorState; bool myShiftState; int ForcedState; + + int mySpeedIncrement; // "increment" for pan/rotate/zoom operations + int mySpaceMouseBtns[5]; // space_mouse_button assigned for functions 1..5 : + // [1] Decrease Speed Increment + // [2] Increase Speed Increment + // [3] Decrease Gauss Point Magnification + // [4] Increase Gauss Point Magnification + // [5] Dominant Combined Switch QWidget* myRenderWidget; vtkSmartPointer mySelector; diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index af266f130..d672ea15d 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -32,7 +32,7 @@ #include "SVTK_Functor.h" #include "SALOME_Actor.h" #include "SVTK_SpaceMouse.h" -#include "SVTK_SpaceMouseEvent.h" +#include "SVTK_Event.h" #include #include @@ -740,3 +740,10 @@ SVTK_RenderWindowInteractor TSetFunction (&SALOME_Actor::setName,theName.latin1())); } + +void +SVTK_RenderWindowInteractor +::FireEvent(const int svtkEvent, void* data) +{ + myInteractor->InvokeEvent( svtkEvent, data ); +} diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index ecfc972fe..a579e9b93 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -190,6 +190,9 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow QColor thecolor); QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject); + // SVTK events manamegent (key accelerators, speed increment, etc.) + void FireEvent( const int svtkAccelEvent, void* data ); + protected: int myDisplayMode; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index a42b6b7b9..4c3ad86a0 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -20,11 +20,12 @@ #include "SUIT_Tools.h" #include "SUIT_ResourceMgr.h" +#include "SUIT_Accel.h" #include "VTKViewer_Utilities.h" #include "VTKViewer_CellRectPicker.h" -//#include "SVTK_View.h" +#include "SVTK_Event.h" #include "SVTK_ViewWindow.h" #include "SVTK_ViewModelBase.h" #include "SVTK_RenderWindowInteractor.h" @@ -488,3 +489,34 @@ SVTK_ViewWindow } } } + +//---------------------------------------------------------------------------- +int convertAction( const int accelAction ) +{ + switch ( accelAction ) { + case SUIT_Accel::PanLeft : return PanLeftEvent; + case SUIT_Accel::PanRight : return PanRightEvent; + case SUIT_Accel::PanUp : return PanUpEvent; + case SUIT_Accel::PanDown : return PanDownEvent; + case SUIT_Accel::ZoomIn : return ZoomInEvent; + case SUIT_Accel::ZoomOut : return ZoomOutEvent; + case SUIT_Accel::RotateLeft : return RotateLeftEvent; + case SUIT_Accel::RotateRight : return RotateRightEvent; + case SUIT_Accel::RotateUp : return RotateUpEvent; + case SUIT_Accel::RotateDown : return RotateDownEvent; + } + return accelAction; +} + +//---------------------------------------------------------------------------- +void +SVTK_ViewWindow +::action( const int accelAction ) +{ + if ( accelAction == SUIT_Accel::ZoomFit ) + onFitAll(); + else { + int svtkEvent = convertAction( accelAction ); + myView->FireEvent( svtkEvent, 0 ); + } +} diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 94ef06637..05afbb3a8 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -127,6 +127,7 @@ protected slots: protected: QImage dumpView(); + virtual void action( const int ); SVTK_View* myView; }; -- 2.39.2