From: nkv Date: Fri, 6 Jun 2008 11:18:21 +0000 (+0000) Subject: Interactor style switch X-Git-Tag: TG_VISU_2008_2008-06-26~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=55cef386f3526c4d47b5f0c23b90f2734d525ece;p=modules%2Fgui.git Interactor style switch --- diff --git a/src/SVTK/Makefile.am b/src/SVTK/Makefile.am index 67d38a199..d3d813984 100755 --- a/src/SVTK/Makefile.am +++ b/src/SVTK/Makefile.am @@ -43,6 +43,7 @@ salomeinclude_HEADERS= \ SVTK_MainWindow.h \ SVTK_Renderer.h \ SVTK_InteractorStyle.h \ + SVTK_KeyFreeInteractorStyle.h \ SVTK_RenderWindowInteractor.h \ SVTK_GenericRenderWindowInteractor.h \ SVTK_Selector.h \ @@ -76,6 +77,7 @@ dist_libSVTK_la_SOURCES= \ SVTK_ViewWindow.cxx \ SVTK_MainWindow.cxx \ SVTK_InteractorStyle.cxx \ + SVTK_KeyFreeInteractorStyle.cxx \ SVTK_RenderWindowInteractor.cxx \ SVTK_GenericRenderWindowInteractor.cxx \ SVTK_SpaceMouse.cxx \ @@ -113,7 +115,8 @@ dist_salomeres_DATA=\ resources/vtk_view_rotation_point.png \ resources/vtk_view_parallel.png \ resources/vtk_view_perspective.png \ - resources/vtk_view_parameters.png + resources/vtk_view_parameters.png \ + resources/vtk_view_style_switch.png nodist_salomeres_DATA= \ SVTK_msg_en.qm \ diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 6fdc00ce7..06870d12f 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -1591,6 +1591,11 @@ void SVTK_InteractorStyle::ProcessEvents( vtkObject* object, */ void SVTK_InteractorStyle::OnChar() { + char key = GetInteractor()->GetKeyCode(); + switch ( key ) { + case '+': ControllerIncrement()->Increase(); break; + case '-': ControllerIncrement()->Decrease(); break; + } } /*! @@ -1681,6 +1686,27 @@ int SVTK_ControllerIncrement::Decrease() return myIncrement; } +vtkStandardNewMacro(SVTK_GeomControllerIncrement); +SVTK_GeomControllerIncrement::SVTK_GeomControllerIncrement() +{ +} +SVTK_GeomControllerIncrement::~SVTK_GeomControllerIncrement() +{ +} +int SVTK_GeomControllerIncrement::Increase() +{ + myIncrement*=2; + return myIncrement; +} +int SVTK_GeomControllerIncrement::Decrease() +{ + myIncrement/=2; + if (myIncrement<1){ + myIncrement=1; + } + return myIncrement; +} + vtkStandardNewMacro(SVTK_ControllerOnKeyDown); /*! diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index c1985352d..ddf067bee 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -49,10 +49,10 @@ #endif // -//! Control the value of increment in SALOME way. +//! Control the value of increment in arithmetic progression mode. /*! This class controls of value of increment, - for pan/rotate/zoom operations in SALOME way + for pan/rotate/zoom operations in arithmetic progression mode */ class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{ public: @@ -79,6 +79,30 @@ class SVTK_EXPORT SVTK_ControllerIncrement : public vtkObject{ SVTK_ControllerIncrement(const SVTK_ControllerIncrement&);//Not implemented void operator=(const SVTK_ControllerIncrement&); //Not implemented }; + +// +//! Control the value of increment in geometric progression mode. +/*! + This class controls of value of increment, + for pan/rotate/zoom operations in geometric progression mode. +*/ +class SVTK_EXPORT SVTK_GeomControllerIncrement : public SVTK_ControllerIncrement{ + public: + vtkTypeMacro(SVTK_GeomControllerIncrement, SVTK_ControllerIncrement); + static SVTK_GeomControllerIncrement* New(); + + //! Increace the increment value by add 1 + virtual int Increase(); + + //! Decreace the increment value by subtract 1 + virtual int Decrease(); + protected: + SVTK_GeomControllerIncrement(); + virtual ~SVTK_GeomControllerIncrement(); + private: + SVTK_GeomControllerIncrement(const SVTK_GeomControllerIncrement&);//Not implemented + void operator=(const SVTK_GeomControllerIncrement&); //Not implemented +}; // //! Control the behaviour of KeyDown event in SALOME way. /*! diff --git a/src/SVTK/SVTK_KeyFreeInteractorStyle.cxx b/src/SVTK/SVTK_KeyFreeInteractorStyle.cxx new file mode 100644 index 000000000..6c12c54fd --- /dev/null +++ b/src/SVTK/SVTK_KeyFreeInteractorStyle.cxx @@ -0,0 +1,161 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : SVTK_KeyFreeInteractorStyle.cxx +// Author : Christophe ATTANASIO +// Module : SALOME +// $Header$ + + +#include "SVTK_KeyFreeInteractorStyle.h" +#include "SVTK_Selector.h" + +#include +#include +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_KeyFreeInteractorStyle); +//---------------------------------------------------------------------------- + +SVTK_KeyFreeInteractorStyle::SVTK_KeyFreeInteractorStyle(): + myIsMidButtonDown( false ), + myIsLeftButtonDown( false ) +{ +} + +//---------------------------------------------------------------------------- +SVTK_KeyFreeInteractorStyle::~SVTK_KeyFreeInteractorStyle() +{ +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnLeftButtonDown(int ctrl, int shift, + int x, int y) +{ + myIsLeftButtonDown = true; + + if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) { + this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL); + return; + } + this->FindPokedRenderer(x, y); + if (this->CurrentRenderer == NULL) { + return; + } + myShiftState = shift; + // finishing current viewer operation + if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + onFinishOperation(); + startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); + } + myOtherPoint = myPoint = QPoint(x, y); + if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + startOperation(ForcedState); + } + else { + if (!(ctrl||shift)){ + if (myIsMidButtonDown){ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + } + else{ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE); + } + } + } + return; +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnMiddleButtonDown(int ctrl, + int shift, + int x, int y) +{ + myIsMidButtonDown = true; + + if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) { + this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL); + return; + } + this->FindPokedRenderer(x, y); + if (this->CurrentRenderer == NULL) { + return; + } + myShiftState = shift; + // finishing current viewer operation + if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + onFinishOperation(); + startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); + } + myOtherPoint = myPoint = QPoint(x, y); + if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) { + startOperation(ForcedState); + } + else { + if (!(ctrl||shift)){ + if ( myIsLeftButtonDown ){ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + } + else{ + startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN); + } + } + } +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnLeftButtonUp(int ctrl, int shift, int x, int y) +{ + myIsLeftButtonDown = false; + SVTK_InteractorStyle::OnLeftButtonUp( ctrl, shift, x, y ); + + if ( myIsMidButtonDown ) + OnMiddleButtonDown( ctrl, shift, x, y ); +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnMiddleButtonUp(int ctrl, int shift, int x, int y) +{ + myIsMidButtonDown = false; + SVTK_InteractorStyle::OnMiddleButtonUp( ctrl, shift, x, y ); + + if ( myIsLeftButtonDown ) + OnLeftButtonDown( ctrl, shift, x, y ); +} + +//---------------------------------------------------------------------------- +void SVTK_KeyFreeInteractorStyle::OnChar() +{ + char key = GetInteractor()->GetKeyCode(); + switch (key) { + case 's': + case 'S': + ActionPicking(); + return; + } + SVTK_InteractorStyle::OnChar(); +} diff --git a/src/SVTK/SVTK_KeyFreeInteractorStyle.h b/src/SVTK/SVTK_KeyFreeInteractorStyle.h new file mode 100644 index 000000000..7e598a3c9 --- /dev/null +++ b/src/SVTK/SVTK_KeyFreeInteractorStyle.h @@ -0,0 +1,72 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : SVTK_KeyFreeInteractorStyle.h +// Author : Christophe ATTANASIO +// Module : SALOME +// $Header$ + +#ifndef __SVTK_KeyFreeInteractorStyle_h +#define __SVTK_KeyFreeInteractorStyle_h + + +#include "SVTK.h" + +#include "SVTK_InteractorStyle.h" + +//! Introduce new style of interaction (keyboard free) +class SVTK_EXPORT SVTK_KeyFreeInteractorStyle : public SVTK_InteractorStyle +{ + public: + static SVTK_KeyFreeInteractorStyle *New(); + vtkTypeMacro(SVTK_KeyFreeInteractorStyle,SVTK_InteractorStyle); + + protected: + SVTK_KeyFreeInteractorStyle(); + ~SVTK_KeyFreeInteractorStyle(); + + SVTK_KeyFreeInteractorStyle(const SVTK_KeyFreeInteractorStyle&); // Not implemented + void operator=(const SVTK_KeyFreeInteractorStyle&); // Not implemented + + // Generic event bindings must be overridden in subclasses + + //! Redefine SVTK_InteractorStyle::OnLeftButtonDown + virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnMiddleButtonDown + virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnLeftButtonUp + virtual void OnLeftButtonUp(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnMiddleButtonUp + virtual void OnMiddleButtonUp(int ctrl, int shift, int x, int y); + + //! Redefine SVTK_InteractorStyle::OnChar + virtual void OnChar(); + + bool myIsMidButtonDown; + bool myIsLeftButtonDown; +}; + +#endif diff --git a/src/SVTK/SVTK_MainWindow.cxx b/src/SVTK/SVTK_MainWindow.cxx index d43acb5b2..5c8f1e600 100644 --- a/src/SVTK/SVTK_MainWindow.cxx +++ b/src/SVTK/SVTK_MainWindow.cxx @@ -55,6 +55,7 @@ #include "SVTK_Renderer.h" #include "SVTK_RenderWindowInteractor.h" #include "SVTK_InteractorStyle.h" +#include "SVTK_KeyFreeInteractorStyle.h" #include "SVTK_Selector.h" #include "SVTK_ComboAction.h" @@ -66,10 +67,13 @@ SVTK_MainWindow::SVTK_MainWindow(QWidget* theParent, SUIT_ResourceMgr* theResourceMgr, SUIT_ViewWindow* theViewWindow) : QMainWindow(theParent), - myViewWindow(theViewWindow) + myViewWindow(theViewWindow), + myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()) { setObjectName(theName); setWindowFlags( windowFlags() & ~Qt::Window ); + // specific of vtkSmartPointer + myKeyFreeInteractorStyle->Delete(); } /*! @@ -563,6 +567,7 @@ void SVTK_MainWindow::createToolBar() QtxActionToolMgr* mgr = toolMgr(); mgr->append( DumpId, myToolBar ); + mgr->append( SwitchInteractionStyleId, myToolBar ); mgr->append( ViewTrihedronId, myToolBar ); QtxMultiAction* aScaleAction = new QtxMultiAction( this ); @@ -597,8 +602,6 @@ void SVTK_MainWindow::createToolBar() mgr->append( ProjectionModeId, myToolBar ); mgr->append( ViewParametersId, myToolBar ); - - mgr->append( SwitchInteractionStyleId, myToolBar ); } /*! @@ -754,6 +757,19 @@ void SVTK_MainWindow::activateWindowFit() */ void SVTK_MainWindow::onSwitchInteractionStyle(bool theOn) { + if (theOn) { + // keep the same style extensions + SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle(); + if ( aStyle ) { + myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement()); + myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown()); + } + + PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer()); + } + else { + PopInteractorStyle(); + } } /*! diff --git a/src/SVTK/SVTK_MainWindow.h b/src/SVTK/SVTK_MainWindow.h index 1281dcb2b..ae9983009 100644 --- a/src/SVTK/SVTK_MainWindow.h +++ b/src/SVTK/SVTK_MainWindow.h @@ -51,6 +51,7 @@ class SVTK_SetRotationPointDlg; class SVTK_ViewParameterDlg; class SVTK_Renderer; class SVTK_Selector; +class SVTK_KeyFreeInteractorStyle; class VTKViewer_Trihedron; class VTKViewer_Actor; @@ -220,14 +221,11 @@ public: protected: virtual QtxActionToolMgr* toolMgr() const; - void - createActions(SUIT_ResourceMgr* theResourceMgr); + void createActions(SUIT_ResourceMgr* theResourceMgr); - void - createToolBar(); + void createToolBar(); - void - SetEventDispatcher(vtkObject* theDispatcher); + void SetEventDispatcher(vtkObject* theDispatcher); QtxAction* action( int ) const; @@ -249,6 +247,7 @@ public: int myToolBar; SVTK_RenderWindowInteractor* myInteractor; + vtkSmartPointer myKeyFreeInteractorStyle; }; #ifdef WIN32