]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Handling of various events is moved to InteractorStyle class. The events are fired...
authorasv <asv@opencascade.com>
Wed, 24 Aug 2005 12:34:47 +0000 (12:34 +0000)
committerasv <asv@opencascade.com>
Wed, 24 Aug 2005 12:34:47 +0000 (12:34 +0000)
src/SVTK/Makefile.in
src/SVTK/SVTK_Event.h [new file with mode: 0644]
src/SVTK/SVTK_InteractorStyle.cxx
src/SVTK/SVTK_InteractorStyle.h
src/SVTK/SVTK_RenderWindowInteractor.cxx
src/SVTK/SVTK_RenderWindowInteractor.h
src/SVTK/SVTK_SpaceMouseEvent.h [deleted file]
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h

index a5c9b1f8a13207cc6ddac9a1906fb99f3eda2f2a..f56bd406bd5a61ac4ca892c779f03bb76ae60b48 100755 (executable)
@@ -30,7 +30,7 @@ EXPORT_HEADERS= SVTK.h \
                SVTK_Selection.h \
                SVTK_SelectionEvent.h \
                SVTK_SpaceMouse.h \
-               SVTK_SpaceMouseEvent.h \
+               SVTK_Event.h \
                SVTK_ViewModelBase.h
 
 # Libraries targets
diff --git a/src/SVTK/SVTK_Event.h b/src/SVTK/SVTK_Event.h
new file mode 100644 (file)
index 0000000..9bd1073
--- /dev/null
@@ -0,0 +1,58 @@
+//  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   : SVTK_SpaceMouseEvent.h
+//  Author : Alexander SLADKOV
+//  Module : SALOME
+//  $Header$
+
+#ifndef SVTK_SpaceMouseEvent_h
+#define SVTK_SpaceMouseEvent_h
+
+#include <vtkCommand.h>
+
+enum Event {
+  SpaceMouseMoveEvent = vtkCommand::UserEvent+1, 
+  SpaceMouseButtonEvent,
+  PanLeftEvent,
+  PanRightEvent,
+  PanUpEvent,
+  PanDownEvent,
+  ZoomInEvent,
+  ZoomOutEvent,
+  RotateLeftEvent,
+  RotateRightEvent,
+  RotateUpEvent,
+  RotateDownEvent,
+  PlusSpeedIncrementEvent,
+  MinusSpeedIncrementEvent,
+  SetSpeedIncrementEvent,
+  SetSpaceMouseF1Event,
+  SetSpaceMouseF2Event,
+  SetSpaceMouseF3Event,
+  SetSpaceMouseF4Event,
+  SetSpaceMouseF5Event,
+  LastEvent
+};
+  
+#endif
index ce08447f89e0f5fc2b9b0ed57001b166dfc93eee..eede37589c10604cbde0ee2790406512043372c4 100644 (file)
@@ -35,7 +35,7 @@
 #include "SVTK_RenderWindow.h"
 #include "SVTK_ViewWindow.h"
 #include "SVTK_Selection.h"
-#include "SVTK_SpaceMouseEvent.h" 
+#include "SVTK_Event.h" 
 #include "SVTK_Selector.h"
 #include "SVTK_Functor.h"
 
@@ -47,9 +47,6 @@
 #include "SALOME_ListIteratorOfListIO.hxx"
 #include "SALOME_ListIO.hxx"
 
-#include "SUIT_Session.h"
-#include "SUIT_ResourceMgr.h"
-
 #include <vtkObjectFactory.h>
 #include <vtkMath.h>
 #include <vtkCommand.h>
@@ -1245,8 +1242,18 @@ SVTK_InteractorStyle
     FindPokedRenderer( 0, 0 );
 
     // register EventCallbackCommand as observer of custorm event (3d space mouse event)
-    interactor->AddObserver( SpaceMouseMoveEvent,   EventCallbackCommand, Priority );
+    interactor->AddObserver( SpaceMouseMoveEvent, EventCallbackCommand, Priority );
     interactor->AddObserver( SpaceMouseButtonEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( PanLeftEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( PanRightEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( PanUpEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( PanDownEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( ZoomInEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( ZoomOutEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( RotateLeftEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( RotateRightEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( RotateUpEvent, EventCallbackCommand, Priority );
+    interactor->AddObserver( RotateDownEvent, EventCallbackCommand, Priority );
   }
 }
 
@@ -1291,35 +1298,11 @@ void
 SVTK_InteractorStyle
 ::onSpaceMouseButton( int button )
 {
-  //  printf( "Button pressed [%d]  \n", button );
-  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-  if ( resMgr->integerValue( "VISU", "spacemouse_func1_btn" ) == button )
-    DecreaseSpeedIncrement();
-  if ( resMgr->integerValue( "VISU", "spacemouse_func2_btn" ) == button )
-    IncreaseSpeedIncrement();
-  if ( resMgr->integerValue( "VISU", "spacemouse_func3_btn" ) == button )
-    DecreaseGaussPointMagnification();
-  if ( resMgr->integerValue( "VISU", "spacemouse_func4_btn" ) == button )
-    IncreaseGaussPointMagnification();
-  if ( resMgr->integerValue( "VISU", "spacemouse_func5_btn" ) == button )
-    DominantCombinedSwitch();
-}
-
-//----------------------------------------------------------------------------
-void
-SVTK_InteractorStyle
-::DecreaseSpeedIncrement()
-{
-  printf( "\n--DecreaseSpeedIncrement() NOT IMPLEMENTED--\n" );
-  
-}
-
-//----------------------------------------------------------------------------
-void
-SVTK_InteractorStyle
-::IncreaseSpeedIncrement()
-{
-  printf( "\n--IncreaseSpeedIncrement() NOT IMPLEMENTED--\n" );
+  if ( mySpaceMouseBtns[0] == button )    --mySpeedIncrement;
+  if ( mySpaceMouseBtns[1] == button )    ++mySpeedIncrement;
+  if ( mySpaceMouseBtns[2] == button )    DecreaseGaussPointMagnification();
+  if ( mySpaceMouseBtns[3] == button )    IncreaseGaussPointMagnification();
+  if ( mySpaceMouseBtns[4] == button )    DominantCombinedSwitch();
 }
 
 //----------------------------------------------------------------------------
@@ -1354,10 +1337,10 @@ SVTK_InteractorStyle
                 void* clientData, 
                 void* callData )
 {
-  if ( event != SpaceMouseMoveEvent && event != SpaceMouseButtonEvent )
+  if ( event < vtkCommand::UserEvent  )
     vtkInteractorStyle::ProcessEvents( object, event, clientData, callData );
 
-  else if ( clientData && callData ) {
+  else if ( clientData ) {
     vtkObject* anObject = reinterpret_cast<vtkObject*>( clientData );
     SVTK_InteractorStyle* self = dynamic_cast<SVTK_InteractorStyle*>( anObject );
     if ( self ) {
@@ -1368,6 +1351,60 @@ SVTK_InteractorStyle
       case SpaceMouseButtonEvent : 
        self->onSpaceMouseButton( *((int*)callData) ); 
        break;
+      case PanLeftEvent: 
+       self->IncrementalPan( -self->mySpeedIncrement, 0 );
+       break;
+      case PanRightEvent:
+       self->IncrementalPan( self->mySpeedIncrement, 0 );
+       break;
+      case PanUpEvent:
+       self->IncrementalPan( 0, self->mySpeedIncrement );
+       break;
+      case PanDownEvent:
+       self->IncrementalPan( 0, -self->mySpeedIncrement );
+       break;
+      case ZoomInEvent:
+       self->IncrementalZoom( self->mySpeedIncrement );
+       break;
+      case ZoomOutEvent:
+       self->IncrementalZoom( -self->mySpeedIncrement );
+       break;
+      case RotateLeftEvent: 
+       self->IncrementalRotate( -self->mySpeedIncrement, 0 );
+       break;
+      case RotateRightEvent:
+       self->IncrementalRotate( self->mySpeedIncrement, 0 );
+       break;
+      case RotateUpEvent:
+       self->IncrementalRotate( 0, -self->mySpeedIncrement );
+       break;
+      case RotateDownEvent:
+       self->IncrementalRotate( 0, self->mySpeedIncrement );
+       break;
+      case PlusSpeedIncrementEvent:
+       ++(self->mySpeedIncrement);
+       break;
+      case MinusSpeedIncrementEvent:
+       --(self->mySpeedIncrement);
+       break;
+      case SetSpeedIncrementEvent:
+       self->mySpeedIncrement = *((int*)callData);
+       break;
+      case SetSpaceMouseF1Event:
+       self->mySpaceMouseBtns[0] = *((int*)callData);
+       break;
+      case SetSpaceMouseF2Event:
+       self->mySpaceMouseBtns[1] = *((int*)callData);
+       break;
+      case SetSpaceMouseF3Event:
+       self->mySpaceMouseBtns[2] = *((int*)callData);
+       break;
+      case SetSpaceMouseF4Event:
+       self->mySpaceMouseBtns[3] = *((int*)callData);
+       break;
+      case SetSpaceMouseF5Event:
+       self->mySpaceMouseBtns[4] = *((int*)callData);
+       break;
       }
     }
   }
index 751fee55b5305dbdf777af4c6d91295cfe83c5c2..ed11cf6d86a3465928f6e185f0a49ae609521b78 100644 (file)
@@ -184,8 +184,6 @@ class SVTK_EXPORT SVTK_InteractorStyle :
   void onSpaceMouseMove( double* data );
   void onSpaceMouseButton( int button );
 
-  void DecreaseSpeedIncrement();
-  void IncreaseSpeedIncrement();
   void DecreaseGaussPointMagnification();
   void IncreaseGaussPointMagnification();
   void DominantCombinedSwitch();
@@ -203,6 +201,14 @@ class SVTK_EXPORT SVTK_InteractorStyle :
   bool                      myCursorState;
   bool                      myShiftState;
   int                       ForcedState;
+
+  int                       mySpeedIncrement; // "increment" for pan/rotate/zoom operations
+  int                       mySpaceMouseBtns[5];  // space_mouse_button assigned for functions 1..5 :
+  // [1] Decrease Speed Increment
+  // [2] Increase Speed Increment
+  // [3] Decrease Gauss Point Magnification
+  // [4] Increase Gauss Point Magnification
+  // [5] Dominant Combined Switch
   
   QWidget*                  myRenderWidget;
   vtkSmartPointer<SVTK_Selector> mySelector;
index af266f13054f6c4774114e5d9b1b7501e0e7adbf..d672ea15d9fecd1221a74513adf366470f3edc83 100644 (file)
@@ -32,7 +32,7 @@
 #include "SVTK_Functor.h"
 #include "SALOME_Actor.h"
 #include "SVTK_SpaceMouse.h" 
-#include "SVTK_SpaceMouseEvent.h" 
+#include "SVTK_Event.h" 
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -740,3 +740,10 @@ SVTK_RenderWindowInteractor
                          TSetFunction<SALOME_Actor,const char*,QString>
                          (&SALOME_Actor::setName,theName.latin1()));
 }
+
+void
+SVTK_RenderWindowInteractor
+::FireEvent(const int svtkEvent, void* data)
+{
+  myInteractor->InvokeEvent( svtkEvent, data );
+}
index ecfc972fece580c417c7d488a47dc2e459628635..a579e9b939071ae07649fee6da1e27e86dd7a809 100644 (file)
@@ -190,6 +190,9 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow
                QColor thecolor);
   QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
 
+  // SVTK events manamegent (key accelerators, speed increment, etc.)
+  void FireEvent( const int svtkAccelEvent, void* data );
+
  protected:
   int myDisplayMode;
 
diff --git a/src/SVTK/SVTK_SpaceMouseEvent.h b/src/SVTK/SVTK_SpaceMouseEvent.h
deleted file mode 100644 (file)
index a7c4885..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-//  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   : SVTK_SpaceMouseEvent.h
-//  Author : Alexander SLADKOV
-//  Module : SALOME
-//  $Header$
-
-#ifndef SVTK_SpaceMouseEvent_h
-#define SVTK_SpaceMouseEvent_h
-
-#include <vtkCommand.h>
-
-enum SpaceMouseEvent {
-  SpaceMouseMoveEvent = vtkCommand::UserEvent+1, 
-  SpaceMouseButtonEvent 
-};
-  
-#endif
index a42b6b7b9d1d950b9d5f16dc22880e83c1b8ed41..4c3ad86a0bdef925d12da3d98e9a90b1db46be37 100755 (executable)
 
 #include "SUIT_Tools.h"
 #include "SUIT_ResourceMgr.h"
+#include "SUIT_Accel.h"
 
 #include "VTKViewer_Utilities.h"
 #include "VTKViewer_CellRectPicker.h"
 
-//#include "SVTK_View.h"
+#include "SVTK_Event.h"
 #include "SVTK_ViewWindow.h"
 #include "SVTK_ViewModelBase.h"
 #include "SVTK_RenderWindowInteractor.h"
@@ -488,3 +489,34 @@ SVTK_ViewWindow
     }
   }
 }
+
+//----------------------------------------------------------------------------
+int convertAction( const int accelAction )
+{
+  switch ( accelAction ) {
+  case SUIT_Accel::PanLeft     : return PanLeftEvent;
+  case SUIT_Accel::PanRight    : return PanRightEvent;
+  case SUIT_Accel::PanUp       : return PanUpEvent;
+  case SUIT_Accel::PanDown     : return PanDownEvent;
+  case SUIT_Accel::ZoomIn      : return ZoomInEvent;
+  case SUIT_Accel::ZoomOut     : return ZoomOutEvent;
+  case SUIT_Accel::RotateLeft  : return RotateLeftEvent;
+  case SUIT_Accel::RotateRight : return RotateRightEvent;
+  case SUIT_Accel::RotateUp    : return RotateUpEvent;
+  case SUIT_Accel::RotateDown  : return RotateDownEvent;  
+  }
+  return accelAction;
+}
+
+//----------------------------------------------------------------------------
+void 
+SVTK_ViewWindow
+::action( const int accelAction  )
+{
+  if ( accelAction == SUIT_Accel::ZoomFit )
+    onFitAll();
+  else {
+    int svtkEvent = convertAction( accelAction );
+    myView->FireEvent( svtkEvent, 0 );
+  }
+}
index 94ef0663724c4064c546d97001efb0d76ba03a45..05afbb3a8501f1396583e7d9570945e9851f6157 100755 (executable)
@@ -127,6 +127,7 @@ protected slots:
 
 protected:
   QImage dumpView();
+  virtual void      action( const int );
 
   SVTK_View* myView;
 };