From 77a9613cab0b85e0b443be8e7127df4f47332cda Mon Sep 17 00:00:00 2001 From: pkv Date: Wed, 23 Nov 2005 09:46:55 +0000 Subject: [PATCH] Provides "S"- key for picking in both interactor styles --- src/SVTK/SVTK_InteractorStyle.cxx | 88 ++++++++++++++++++++++++------- src/SVTK/SVTK_InteractorStyle.h | 75 +++++++++++++++++++------- 2 files changed, 123 insertions(+), 40 deletions(-) diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 58a95e2f2..8e1a1a8e7 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -109,14 +109,14 @@ namespace //---------------------------------------------------------------------------- vtkStandardNewMacro(SVTK_InteractorStyle); //---------------------------------------------------------------------------- - SVTK_InteractorStyle ::SVTK_InteractorStyle(): mySelectionEvent(new SVTK_SelectionEvent()), myPicker(vtkPicker::New()), myLastHighlitedActor(NULL), myLastPreHighlitedActor(NULL), - myInteractorStyleController(SVTK_InteractorStyleController::New()) + myControllerIncrement(SVTK_ControllerIncrement::New()), + myControllerOnKeyDown(SVTK_ControllerOnKeyDown::New()) { myPicker->Delete(); @@ -136,7 +136,9 @@ SVTK_InteractorStyle mySMDecreaseSpeedBtn = 1; mySMIncreaseSpeedBtn = 2; mySMDominantCombinedSwitchBtn = 9; - myInteractorStyleController->Delete(); + // + myControllerIncrement->Delete(); + myControllerOnKeyDown->Delete(); } //---------------------------------------------------------------------------- @@ -1224,10 +1226,10 @@ SVTK_InteractorStyle ::onSpaceMouseButton( int button ) { if( mySMDecreaseSpeedBtn == button ) { - Controller()->IncrementDecrease(); + ControllerIncrement()->Decrease(); } if( mySMIncreaseSpeedBtn == button ) { - Controller()->IncrementIncrease(); + ControllerIncrement()->Increase(); } if( mySMDominantCombinedSwitchBtn == button ) DominantCombinedSwitch(); @@ -1252,7 +1254,7 @@ SVTK_InteractorStyle if ( clientData ) { vtkObject* anObject = reinterpret_cast( clientData ); SVTK_InteractorStyle* self = dynamic_cast( anObject ); - int aSpeedIncrement=self->Controller()->IncrementCurrent(); + int aSpeedIncrement=self->ControllerIncrement()->Current(); if ( self ) { switch ( event ) { case SVTK::SpaceMouseMoveEvent : @@ -1292,13 +1294,13 @@ SVTK_InteractorStyle self->IncrementalRotate(0, aSpeedIncrement); return; case SVTK::PlusSpeedIncrementEvent: - self->Controller()->IncrementIncrease(); + self->ControllerIncrement()->Increase(); return; case SVTK::MinusSpeedIncrementEvent: - self->Controller()->IncrementDecrease(); + self->ControllerIncrement()->Decrease(); return; case SVTK::SetSpeedIncrementEvent: - self->Controller()->SetIncrementStartValue(*((int*)callData)); + self->ControllerIncrement()->SetStartValue(*((int*)callData)); return; case SVTK::SetSMDecreaseSpeedEvent: @@ -1337,47 +1339,93 @@ void SVTK_InteractorStyle::OnChar() { } //---------------------------------------------------------------------------- -void SVTK_InteractorStyle::SetController(SVTK_InteractorStyleController* theController) +void SVTK_InteractorStyle::OnKeyDown() +{ + bool bInvokeSuperclass=myControllerOnKeyDown->OnKeyDown(this); + if (bInvokeSuperclass){ + Superclass::OnKeyDown(); + } +} +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle::ActionPicking() +{ + int x, y; + Interactor->GetEventPosition( x, y ); + FindPokedRenderer( x, y ); + + myOtherPoint = myPoint = QPoint(x, y); + + startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT); + onFinishOperation(); + startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); +} +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle::SetControllerOnKeyDown(SVTK_ControllerOnKeyDown* theController) +{ + myControllerOnKeyDown=theController; +} +//---------------------------------------------------------------------------- +SVTK_ControllerOnKeyDown* SVTK_InteractorStyle::ControllerOnKeyDown() +{ + return myControllerOnKeyDown.GetPointer(); +} +//---------------------------------------------------------------------------- +void SVTK_InteractorStyle::SetControllerIncrement(SVTK_ControllerIncrement* theController) { - myInteractorStyleController=theController; + myControllerIncrement=theController; } //---------------------------------------------------------------------------- -SVTK_InteractorStyleController* SVTK_InteractorStyle::Controller() +SVTK_ControllerIncrement* SVTK_InteractorStyle::ControllerIncrement() { - return myInteractorStyleController.GetPointer(); + return myControllerIncrement.GetPointer(); } -vtkStandardNewMacro(SVTK_InteractorStyleController); +vtkStandardNewMacro(SVTK_ControllerIncrement); //---------------------------------------------------------------------------- -SVTK_InteractorStyleController::SVTK_InteractorStyleController() +SVTK_ControllerIncrement::SVTK_ControllerIncrement() { myIncrement=10; } //---------------------------------------------------------------------------- -SVTK_InteractorStyleController::~SVTK_InteractorStyleController() +SVTK_ControllerIncrement::~SVTK_ControllerIncrement() { } //---------------------------------------------------------------------------- -void SVTK_InteractorStyleController::SetIncrementStartValue(const int theValue) +void SVTK_ControllerIncrement::SetStartValue(const int theValue) { myIncrement=theValue; } //---------------------------------------------------------------------------- -int SVTK_InteractorStyleController::IncrementCurrent()const +int SVTK_ControllerIncrement::Current()const { return myIncrement; } //---------------------------------------------------------------------------- -int SVTK_InteractorStyleController::IncrementIncrease() +int SVTK_ControllerIncrement::Increase() { ++myIncrement; return myIncrement; } //---------------------------------------------------------------------------- -int SVTK_InteractorStyleController::IncrementDecrease() +int SVTK_ControllerIncrement::Decrease() { if (myIncrement>1){ --myIncrement; } return myIncrement; } + +vtkStandardNewMacro(SVTK_ControllerOnKeyDown); +//---------------------------------------------------------------------------- +SVTK_ControllerOnKeyDown::SVTK_ControllerOnKeyDown() +{ +} +//---------------------------------------------------------------------------- +SVTK_ControllerOnKeyDown::~SVTK_ControllerOnKeyDown() +{ +} +//---------------------------------------------------------------------------- +bool SVTK_ControllerOnKeyDown::OnKeyDown(vtkInteractorStyle* theIS) +{ + return true; +} diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 3fb6216f4..7ea671df4 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -51,32 +51,53 @@ This class controls of value of increment, for pan/rotate/zoom operations in SALOME way */ -class SVTK_InteractorStyleController : public vtkObject{ +class SVTK_ControllerIncrement : public vtkObject{ public: - vtkTypeMacro(SVTK_InteractorStyleController, vtkObject); - static SVTK_InteractorStyleController* New(); + vtkTypeMacro(SVTK_ControllerIncrement, vtkObject); + static SVTK_ControllerIncrement* New(); //! Set start value of increment - void SetIncrementStartValue(const int ); + void SetStartValue(const int ); //! Get current value of increment - int IncrementCurrent()const; + int Current()const; //! Increace the increment value by add 1 - virtual int IncrementIncrease(); + virtual int Increase(); //! Decreace the increment value by subtract 1 - virtual int IncrementDecrease(); - + virtual int Decrease(); + protected: + SVTK_ControllerIncrement(); + virtual ~SVTK_ControllerIncrement(); protected: - SVTK_InteractorStyleController(); - virtual ~SVTK_InteractorStyleController(); + int myIncrement; + private: + SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented + void operator=(const SVTK_ControllerIncrement&); //Not implemented +}; +// +//------------------------------------------- +//! Control the behaviour of KeyDown event in SALOME way. +/*! + This class controls the behaviour of KeyDown event + in SALOME way +*/ +class SVTK_ControllerOnKeyDown : public vtkObject{ + public: + vtkTypeMacro(SVTK_ControllerOnKeyDown, vtkObject); + static SVTK_ControllerOnKeyDown* New(); + + //! Provides the action on event + virtual bool OnKeyDown(vtkInteractorStyle* ); + protected: - int myIncrement; + SVTK_ControllerOnKeyDown(); + virtual ~SVTK_ControllerOnKeyDown(); private: - SVTK_InteractorStyleController(const SVTK_InteractorStyleController&); //Not implemented - void operator=(const SVTK_InteractorStyleController&); //Not implemented + SVTK_ControllerOnKeyDown(const SVTK_ControllerOnKeyDown&);//Not implemented + void operator=(const SVTK_ControllerOnKeyDown&); //Not implemented }; //------------------------------------------- @@ -183,21 +204,32 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle OnChar(); //! To set current increment controller - void SetController(SVTK_InteractorStyleController*); + void SetControllerIncrement(SVTK_ControllerIncrement*); //! To get current increment controller - SVTK_InteractorStyleController* Controller(); + SVTK_ControllerIncrement* ControllerIncrement(); + //! Redefine vtkInteractorStyle::OnKeyDown + virtual void OnKeyDown(); + + //! Provide instructions for Picking + void ActionPicking(); + + //! To set current OnKeyDown controller + void SetControllerOnKeyDown(SVTK_ControllerOnKeyDown*); + + //! To get current OnKeyDown controller + SVTK_ControllerOnKeyDown* ControllerOnKeyDown(); + + SVTK_Selector* GetSelector(); + protected: SVTK_InteractorStyle(); ~SVTK_InteractorStyle(); QWidget* GetRenderWidget(); - - SVTK_Selector* - GetSelector(); - + // 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); @@ -276,7 +308,10 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle vtkSmartPointer myLastPreHighlitedActor; //! "Increment" controller for pan/rotate/zoom operations - vtkSmartPointer myInteractorStyleController; + vtkSmartPointer myControllerIncrement; + + //!controls the behaviour of KeyDown event in SALOME way + vtkSmartPointer myControllerOnKeyDown; // SpaceMouse short cuts int mySMDecreaseSpeedBtn; -- 2.39.2