]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Interactor style switch
authornkv <nkv@opencascade.com>
Fri, 6 Jun 2008 11:18:21 +0000 (11:18 +0000)
committernkv <nkv@opencascade.com>
Fri, 6 Jun 2008 11:18:21 +0000 (11:18 +0000)
src/SVTK/Makefile.am
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h
src/SVTK/SVTK_KeyFreeInteractorStyle.cxx [new file with mode: 0644]
src/SVTK/SVTK_KeyFreeInteractorStyle.h [new file with mode: 0644]
src/SVTK/SVTK_MainWindow.cxx
src/SVTK/SVTK_MainWindow.h

index 67d38a199b15fa798a365f47f66e7abc5353a637..d3d813984cefcdaa9e1daf6801aa09a3792d7497 100755 (executable)
@@ -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 \
index 6fdc00ce758281a7836ef175b25f17dba1c0d452..06870d12f59d8fcd826560fb5736a88470835d57 100644 (file)
@@ -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);
 
 /*!
index c1985352d636e5a41945ce2e585bee0171a8705f..ddf067bee24087f136965a4a6d93db723f22eafa 100644 (file)
 #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 (file)
index 0000000..6c12c54
--- /dev/null
@@ -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 <vtkObjectFactory.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkCallbackCommand.h>
+#include <vtkCommand.h>
+#include <vtkRenderer.h>
+#include <vtkCamera.h>
+
+
+//----------------------------------------------------------------------------
+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 (file)
index 0000000..7e598a3
--- /dev/null
@@ -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
index d43acb5b2d8b84a870f82deea804ecf97a66bb19..5c8f1e600770bfc41a68a6448b803fc1653539ae 100644 (file)
@@ -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();
+  }
 }
 
 /*!
index 1281dcb2b2d4d57c813305a1caef6e9a1c891a36..ae9983009baf0ad3e4b2fb0830c693ac56c6ebca 100644 (file)
@@ -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<SVTK_KeyFreeInteractorStyle> myKeyFreeInteractorStyle;
 };
 
 #ifdef WIN32