From cf06a94e9687913b9792da9030d10f8575db0ff5 Mon Sep 17 00:00:00 2001 From: asv Date: Fri, 19 Aug 2005 12:18:33 +0000 Subject: [PATCH] New functionality to handle mouse events (zoom on left mouse button, etc.). --- src/VVTK/Makefile.in | 4 +- src/VVTK/VVTK_InteractorStyle.cxx | 148 ++++++++++++++++++++++++++++++ src/VVTK/VVTK_InteractorStyle.h | 63 +++++++++++++ src/VVTK/VVTK_ViewWindow.cxx | 6 +- 4 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 src/VVTK/VVTK_InteractorStyle.cxx create mode 100644 src/VVTK/VVTK_InteractorStyle.h diff --git a/src/VVTK/Makefile.in b/src/VVTK/Makefile.in index fb1023d2..d0c151ea 100755 --- a/src/VVTK/Makefile.in +++ b/src/VVTK/Makefile.in @@ -15,13 +15,15 @@ VPATH=.:@srcdir@ EXPORT_HEADERS= VVTK.h \ VVTK_ViewManager.h \ VVTK_ViewModel.h \ - VVTK_ViewWindow.h + VVTK_InteractorStyle.h \ + VVTK_ViewWindow.h # Libraries targets LIB = libVVTK.la LIB_SRC= VVTK_ViewManager.cxx \ VVTK_ViewModel.cxx \ + VVTK_InteractorStyle.cxx \ VVTK_ViewWindow.cxx LIB_MOC = VVTK_ViewWindow.h \ diff --git a/src/VVTK/VVTK_InteractorStyle.cxx b/src/VVTK/VVTK_InteractorStyle.cxx new file mode 100644 index 00000000..adde9624 --- /dev/null +++ b/src/VVTK/VVTK_InteractorStyle.cxx @@ -0,0 +1,148 @@ +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_InteractorStyle.cxx +// Author : Christophe ATTANASIO +// Module : SALOME +// $Header$ + + +#include "VVTK_InteractorStyle.h" + +#include +#include + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(VVTK_InteractorStyle); +//---------------------------------------------------------------------------- + +VVTK_InteractorStyle +::VVTK_InteractorStyle() +{ + printf ( "\n--- VVTK_InteractorStyle created ---\n" ); +} + +//---------------------------------------------------------------------------- +VVTK_InteractorStyle +::~VVTK_InteractorStyle() +{ +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::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) + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + else { + if ( myIsMidButtonDown ) + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + else + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE); + } + } + return; +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::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 ( myIsLeftButtonDown ) + startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM); + else + startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN); + } +} + +//---------------------------------------------------------------------------- +void +VVTK_InteractorStyle +::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 +VVTK_InteractorStyle +::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 ); +} diff --git a/src/VVTK/VVTK_InteractorStyle.h b/src/VVTK/VVTK_InteractorStyle.h new file mode 100644 index 00000000..eef18a84 --- /dev/null +++ b/src/VVTK/VVTK_InteractorStyle.h @@ -0,0 +1,63 @@ +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VVTK_InteractorStyle.h +// Author : Christophe ATTANASIO +// Module : SALOME +// $Header$ + +#ifndef __VVTK_InteractorStyle_h +#define __VVTK_InteractorStyle_h + +#include "VVTK.h" + +#include "SVTK_InteractorStyle.h" + +class VVTK_EXPORT VVTK_InteractorStyle : public SVTK_InteractorStyle +{ + public: + // Description: + // This class must be supplied with a vtkRenderWindowInteractor wrapper or + // parent. This class should not normally be instantiated by application + // programmers. + static VVTK_InteractorStyle *New(); + vtkTypeMacro(VVTK_InteractorStyle, vtkInteractorStyle); + + protected: + VVTK_InteractorStyle(); + ~VVTK_InteractorStyle(); + VVTK_InteractorStyle(const VVTK_InteractorStyle&) {}; + void operator=(const VVTK_InteractorStyle&) {}; + + // Generic event bindings must be overridden in subclasses + virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y); + virtual void OnMiddleButtonDown(int ctrl, int shift, int x, int y); + virtual void OnLeftButtonUp(int ctrl, int shift, int x, int y); + virtual void OnMiddleButtonUp(int ctrl, int shift, int x, int y); + + private: + bool myIsMidButtonDown; + bool myIsLeftButtonDown; +}; + +#endif diff --git a/src/VVTK/VVTK_ViewWindow.cxx b/src/VVTK/VVTK_ViewWindow.cxx index 806eacdb..cf893755 100755 --- a/src/VVTK/VVTK_ViewWindow.cxx +++ b/src/VVTK/VVTK_ViewWindow.cxx @@ -1,5 +1,6 @@ #include "VVTK_ViewWindow.h" #include "VVTK_ViewModel.h" +#include "VVTK_InteractorStyle.h" //---------------------------------------------------------------------------- VVTK_ViewWindow @@ -7,6 +8,8 @@ VVTK_ViewWindow VVTK_Viewer* theModel ) : SVTK_ViewWindow( theDesktop, theModel ) { + pushInteractorStyle( VVTK_InteractorStyle::New() ); + connect(this,SIGNAL(selectionChanged()), theModel,SLOT(onSelectionChanged())); } @@ -14,4 +17,5 @@ VVTK_ViewWindow //---------------------------------------------------------------------------- VVTK_ViewWindow ::~VVTK_ViewWindow() -{} +{ +} -- 2.39.2