]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
New functionality to handle mouse events (zoom on left mouse button, etc.).
authorasv <asv@opencascade.com>
Fri, 19 Aug 2005 12:18:33 +0000 (12:18 +0000)
committerasv <asv@opencascade.com>
Fri, 19 Aug 2005 12:18:33 +0000 (12:18 +0000)
src/VVTK/Makefile.in
src/VVTK/VVTK_InteractorStyle.cxx [new file with mode: 0644]
src/VVTK/VVTK_InteractorStyle.h [new file with mode: 0644]
src/VVTK/VVTK_ViewWindow.cxx

index fb1023d2c8150fb29407ce84918dfa390996ce9f..d0c151ea83d37a89b8f486d2e742dcdf79479f54 100755 (executable)
@@ -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 (file)
index 0000000..adde962
--- /dev/null
@@ -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 <vtkObjectFactory.h>
+#include <vtkCommand.h>
+
+//----------------------------------------------------------------------------
+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 (file)
index 0000000..eef18a8
--- /dev/null
@@ -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
index 806eacdb3bf48f9ca3fb3ca2402e77c014d5375b..cf8937556994f4ddaa3e6621b45953b4ad85edd4 100755 (executable)
@@ -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()
-{}
+{
+}