]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To customize SpaceMause interaction
authorapo <apo@opencascade.com>
Wed, 5 Oct 2005 14:04:23 +0000 (14:04 +0000)
committerapo <apo@opencascade.com>
Wed, 5 Oct 2005 14:04:23 +0000 (14:04 +0000)
(introduce magnification functionality)

src/VVTK/Makefile.in
src/VVTK/VVTK_Event.h [new file with mode: 0644]
src/VVTK/VVTK_InteractorStyle.cxx
src/VVTK/VVTK_InteractorStyle.h

index 1516f7dc6ad32b107738b2292be5856f5e6764ee..331be56e0c40e2df195eb8bda1c9bc782cb8f779 100755 (executable)
@@ -14,6 +14,7 @@ VPATH=.:@srcdir@
 # header files
 EXPORT_HEADERS = \
        VVTK.h \
+       VVTK_Event.h \
        VVTK_ViewManager.h \
        VVTK_ViewModel.h \
        VVTK_InteractorStyle.h \
diff --git a/src/VVTK/VVTK_Event.h b/src/VVTK/VVTK_Event.h
new file mode 100644 (file)
index 0000000..793f9b4
--- /dev/null
@@ -0,0 +1,44 @@
+//  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   : 
+//  Author : Alexander SLADKOV
+//  Module : SALOME
+//  $Header$
+
+#ifndef VVTK_Event_h
+#define VVTK_Event_h
+
+#include "SVTK_Event.h"
+
+namespace VVTK
+{
+  enum Event 
+  {
+    SetSMDecreaseMagnificationEvent = SVTK::LastEvent + 100, 
+    SetSMIncreaseMagnificationEvent,
+    LastEvent
+  };
+}
+  
+#endif
index 31abefa1e3c497cb7b2d96708b155a45f46504a8..43f85d68e0fce5cff0f094233fbbed39902ac952 100644 (file)
 
 
 #include "VVTK_InteractorStyle.h"
+#include "SVTK_Selector.h"
+#include "VVTK_Event.h" 
 
 #include <vtkObjectFactory.h>
 #include <vtkRenderWindowInteractor.h>
+#include <vtkCallbackCommand.h>
 #include <vtkCommand.h>
 #include <vtkRenderer.h>
 #include <vtkCamera.h>
 
-#include <SVTK_Selector.h>
+
 //----------------------------------------------------------------------------
 vtkStandardNewMacro(VVTK_InteractorStyle);
 //----------------------------------------------------------------------------
@@ -43,7 +46,9 @@ vtkStandardNewMacro(VVTK_InteractorStyle);
 VVTK_InteractorStyle
 ::VVTK_InteractorStyle():
   myIsMidButtonDown( false ),
-  myIsLeftButtonDown( false )
+  myIsLeftButtonDown( false ),
+  mySMDecreaseMagnificationBtn(10),
+  mySMIncreaseMagnificationBtn(11)
 {
 }
 
@@ -215,3 +220,74 @@ void  VVTK_InteractorStyle::onFinishOperation()
     }
   }
 }
+
+
+//----------------------------------------------------------------------------
+void
+VVTK_InteractorStyle
+::SetInteractor( vtkRenderWindowInteractor* theInteractor )
+{
+  // register EventCallbackCommand as observer of standard events (keypress, mousemove, etc)
+  Superclass::SetInteractor( theInteractor );
+  if(theInteractor){ 
+    theInteractor->AddObserver( VVTK::SetSMDecreaseMagnificationEvent, EventCallbackCommand, Priority );
+    theInteractor->AddObserver( VVTK::SetSMIncreaseMagnificationEvent, EventCallbackCommand, Priority );
+  }
+}
+
+//----------------------------------------------------------------------------
+void
+VVTK_InteractorStyle
+::ProcessEvents( vtkObject* object,
+                unsigned long event,
+                void* clientData, 
+                void* callData )
+{
+  if ( clientData ) {
+    vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
+    VVTK_InteractorStyle* self = dynamic_cast<VVTK_InteractorStyle*>( anObject );
+    if( self ){
+      switch ( event ) {
+      case VVTK::SetSMDecreaseMagnificationEvent:
+       self->mySMDecreaseMagnificationBtn = *((int*)callData);
+       return;
+      case VVTK::SetSMIncreaseMagnificationEvent:
+       self->mySMIncreaseMagnificationBtn = *((int*)callData);
+       return;
+      }
+    }
+  }
+
+  Superclass::ProcessEvents( object, event, clientData, callData );
+}
+
+
+//----------------------------------------------------------------------------
+void
+VVTK_InteractorStyle
+::onSpaceMouseButton( int button )
+{
+  if( mySMDecreaseMagnificationBtn == button )    
+    DecreaseGaussPointMagnification();
+  if( mySMIncreaseMagnificationBtn == button )    
+    IncreaseGaussPointMagnification();
+
+  Superclass::onSpaceMouseButton( button );
+}
+
+//----------------------------------------------------------------------------
+void
+VVTK_InteractorStyle
+::DecreaseGaussPointMagnification()
+{
+  printf( "\n--DecreaseGaussPointMagnification() NOT IMPLEMENTED--\n" );
+}
+
+//----------------------------------------------------------------------------
+void
+VVTK_InteractorStyle
+::IncreaseGaussPointMagnification()
+{
+  printf( "\n--IncreaseGaussPointMagnification() NOT IMPLEMENTED--\n" );
+}
index 245b7f8f08c2b359531f8c636deb27d28d7e5704..14a9b08745780d83f9a680900b54face10eee7ab 100644 (file)
@@ -41,14 +41,19 @@ class VVTK_EXPORT VVTK_InteractorStyle : public SVTK_InteractorStyle
   // parent. This class should not normally be instantiated by application
   // programmers.
   static VVTK_InteractorStyle *New();
-  vtkTypeMacro(VVTK_InteractorStyle, vtkInteractorStyle);
+  vtkTypeMacro(VVTK_InteractorStyle,SVTK_InteractorStyle);
 
+  // redefined in order to add an observer (callback) for custorm event (space mouse event)
+  virtual
+  void
+  SetInteractor( vtkRenderWindowInteractor* );
 
  protected:
   VVTK_InteractorStyle();
   ~VVTK_InteractorStyle();
-  VVTK_InteractorStyle(const VVTK_InteractorStyle&) {};
-  void operator=(const VVTK_InteractorStyle&) {};
+
+  VVTK_InteractorStyle(const VVTK_InteractorStyle&); // Not implemented
+  void operator=(const VVTK_InteractorStyle&); // Not implemented
 
   // Generic event bindings must be overridden in subclasses
   virtual void OnLeftButtonDown(int ctrl, int shift, int x, int y);
@@ -58,10 +63,24 @@ class VVTK_EXPORT VVTK_InteractorStyle : public SVTK_InteractorStyle
   virtual void OnKeyDown();
   virtual void onFinishOperation();
 
- private:
+  // Main process VTK event method
+  static 
+  void
+  ProcessEvents(vtkObject* object, 
+               unsigned long event,
+               void* clientData, 
+               void* callData );
+
+  virtual void onSpaceMouseButton( int button );
+  void DecreaseGaussPointMagnification();
+  void IncreaseGaussPointMagnification();
+
+  // SpaceMouse short cuts
+  int mySMDecreaseMagnificationBtn;
+  int mySMIncreaseMagnificationBtn;
+
   bool myIsMidButtonDown;
   bool myIsLeftButtonDown;
-
 };
 
 #endif