]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/BaseInteractorStyle.cxx
Intermediary push, DO NOT USE
[cpPlugins.git] / lib / cpExtensions / Visualization / BaseInteractorStyle.cxx
index 6b9c8efe30fb3c5dbbebe9752e442a40797f1d98..b5641012bc42e43a2fc1b239c601e734056f580e 100644 (file)
@@ -8,15 +8,97 @@
 #include <vtkRenderWindowInteractor.h>
 
 // -------------------------------------------------------------------------
-const long cpExtensions::Visualization::BaseInteractorStyle::MouseButtonEvent::
-MAX_DOUBLE_CLICK = 200; // ms
+long cpExtensions::Visualization::BaseInteractorStyle::_TMouseButtonEvent::
+MaxDoubleClick = 200; // ms
 
 // -------------------------------------------------------------------------
-cpExtensions::Visualization::BaseInteractorStyle::
-Self* cpExtensions::Visualization::BaseInteractorStyle::
-New( )
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddMouseMoveCommand( TMouseCommand command, void* data )
+{
+  this->m_MouseMoveCommands.push_back(
+    std::pair< TMouseCommand, void* >( command, data )
+    );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddMouseClickCommand( TMouseCommand command, void* data )
+{
+  this->m_MouseClickCommands.push_back(
+    std::pair< TMouseCommand, void* >( command, data )
+    );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddMouseDoubleClickCommand( TMouseCommand command, void* data )
 {
-  return( new Self );
+  this->m_MouseDoubleClickCommands.push_back(
+    std::pair< TMouseCommand, void* >( command, data )
+    );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddMouseWheelCommand( TMouseWheelCommand command, void* data )
+{
+  this->m_MouseWheelCommands.push_back(
+    std::pair< TMouseWheelCommand, void* >( command, data )
+    );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddKeyCommand( TKeyCommand command, void* data )
+{
+  this->m_KeyCommands.push_back(
+    std::pair< TKeyCommand, void* >( command, data )
+    );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddExposeCommand( TVoidCommand command, void* data )
+{
+  this->m_ExposeCommands.push_back(
+    std::pair< TVoidCommand, void* >( command, data )
+    );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddConfigureCommand( TVoidCommand command, void* data )
+{
+  this->m_ConfigureCommands.push_back(
+    std::pair< TVoidCommand, void* >( command, data )
+    );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddEnterCommand( TVoidCommand command, void* data )
+{
+  this->m_EnterCommands.push_back(
+    std::pair< TVoidCommand, void* >( command, data )
+    );
+  this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+AddLeaveCommand( TVoidCommand command, void* data )
+{
+  this->m_LeaveCommands.push_back(
+    std::pair< TVoidCommand, void* >( command, data )
+    );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
@@ -69,27 +151,74 @@ OnMouseMove( )
     } // fi
 
   } // fi
+
+  // Get mouse pointer position
+  double pos[ 3 ];
+  if( !( this->_PickPosition( pos ) ) )
+    return;
+
+  // Invoke possible specialized events
+  for( unsigned int i = 0; i < this->m_MouseMoveCommands.size( ); ++i )
+    this->m_MouseMoveCommands[ i ].first(
+      this->m_MouseMoveCommands[ i ].second, button, pos, alt, ctr, sft
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnMouseWheelForward( )
+{
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_MouseWheelCommands.size( ); ++i )
+    this->m_MouseWheelCommands[ i ].first(
+      this->m_MouseWheelCommands[ i ].second, 1,
+      rwi->GetAltKey( ) == 1,
+      rwi->GetControlKey( ) == 1,
+      rwi->GetShiftKey( ) == 1
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnMouseWheelBackward( )
+{
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_MouseWheelCommands.size( ); ++i )
+    this->m_MouseWheelCommands[ i ].first(
+      this->m_MouseWheelCommands[ i ].second, -1,
+      rwi->GetAltKey( ) == 1,
+      rwi->GetControlKey( ) == 1,
+      rwi->GetShiftKey( ) == 1
+      );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::BaseInteractorStyle::
 OnLeftButtonDown( )
 {
-  this->ActiveButton = Self::ButtonID_Left;
+  this->m_ActiveButton = Self::ButtonID_Left;
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::BaseInteractorStyle::
 OnLeftButtonUp( )
 {
-  this->ActiveButton = Self::ButtonID_None;
+  this->m_ActiveButton = Self::ButtonID_None;
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::BaseInteractorStyle::
 OnMiddleButtonDown( )
 {
-  this->ActiveButton = Self::ButtonID_Middle;
+  this->m_ActiveButton = Self::ButtonID_Middle;
 
   // Get current position on the associated actors
   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
@@ -109,7 +238,7 @@ OnMiddleButtonDown( )
 void cpExtensions::Visualization::BaseInteractorStyle::
 OnMiddleButtonUp( )
 {
-  this->ActiveButton = Self::ButtonID_None;
+  this->m_ActiveButton = Self::ButtonID_None;
 
   // Get current position on the associated actors
   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
@@ -135,7 +264,7 @@ OnMiddleButtonUp( )
 void cpExtensions::Visualization::BaseInteractorStyle::
 OnRightButtonDown( )
 {
-  this->ActiveButton = Self::ButtonID_Right;
+  this->m_ActiveButton = Self::ButtonID_Right;
 
   // Get current position on the associated actors
   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
@@ -155,7 +284,7 @@ OnRightButtonDown( )
 void cpExtensions::Visualization::BaseInteractorStyle::
 OnRightButtonUp( )
 {
-  this->ActiveButton = Self::ButtonID_None;
+  this->m_ActiveButton = Self::ButtonID_None;
 
   // Get current position on the associated actors
   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
@@ -177,6 +306,256 @@ OnRightButtonUp( )
   } // hctiws
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnLeftClick( )
+{
+  // Get current position on the associated actors
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Get mouse pointer position
+  double pos[ 3 ];
+  if( !( this->_PickPosition( pos ) ) )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i )
+    this->m_MouseClickCommands[ i ].first(
+      this->m_MouseClickCommands[ i ].second,
+      Self::ButtonID_Left,
+      pos,
+      rwi->GetAltKey( ) == 1,
+      rwi->GetControlKey( ) == 1,
+      rwi->GetShiftKey( ) == 1
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnLeftDoubleClick( )
+{
+  // Get current position on the associated actors
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Get mouse pointer position
+  double pos[ 3 ];
+  if( !( this->_PickPosition( pos ) ) )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i )
+    this->m_MouseDoubleClickCommands[ i ].first(
+      this->m_MouseDoubleClickCommands[ i ].second,
+      Self::ButtonID_Left,
+      pos,
+      rwi->GetAltKey( ) == 1,
+      rwi->GetControlKey( ) == 1,
+      rwi->GetShiftKey( ) == 1
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnMiddleClick( )
+{
+  // Get current position on the associated actors
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Get mouse pointer position
+  double pos[ 3 ];
+  if( !( this->_PickPosition( pos ) ) )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i )
+    this->m_MouseClickCommands[ i ].first(
+      this->m_MouseClickCommands[ i ].second,
+      Self::ButtonID_Middle,
+      pos,
+      rwi->GetAltKey( ) == 1,
+      rwi->GetControlKey( ) == 1,
+      rwi->GetShiftKey( ) == 1
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnMiddleDoubleClick( )
+{
+  // Get current position on the associated actors
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Get mouse pointer position
+  double pos[ 3 ];
+  if( !( this->_PickPosition( pos ) ) )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i )
+    this->m_MouseDoubleClickCommands[ i ].first(
+      this->m_MouseDoubleClickCommands[ i ].second,
+      Self::ButtonID_Middle,
+      pos,
+      rwi->GetAltKey( ) == 1,
+      rwi->GetControlKey( ) == 1,
+      rwi->GetShiftKey( ) == 1
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnRightClick( )
+{
+  // Get current position on the associated actors
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Get mouse pointer position
+  double pos[ 3 ];
+  if( !( this->_PickPosition( pos ) ) )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i )
+    this->m_MouseClickCommands[ i ].first(
+      this->m_MouseClickCommands[ i ].second,
+      Self::ButtonID_Right,
+      pos,
+      rwi->GetAltKey( ) == 1,
+      rwi->GetControlKey( ) == 1,
+      rwi->GetShiftKey( ) == 1
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnRightDoubleClick( )
+{
+  // Get current position on the associated actors
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Get mouse pointer position
+  double pos[ 3 ];
+  if( !( this->_PickPosition( pos ) ) )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_MouseClickCommands.size( ); ++i )
+    this->m_MouseDoubleClickCommands[ i ].first(
+      this->m_MouseDoubleClickCommands[ i ].second,
+      Self::ButtonID_Right,
+      pos,
+      rwi->GetAltKey( ) == 1,
+      rwi->GetControlKey( ) == 1,
+      rwi->GetShiftKey( ) == 1
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnChar( )
+{
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_KeyCommands.size( ); ++i )
+    this->m_KeyCommands[ i ].first(
+      this->m_KeyCommands[ i ].second,
+      rwi->GetKeyCode( )
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnKeyDown( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnKeyUp( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnKeyPress( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnKeyRelease( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnExpose( )
+{
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_ExposeCommands.size( ); ++i )
+    this->m_ExposeCommands[ i ].first( this->m_ExposeCommands[ i ].second );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnConfigure( )
+{
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_ConfigureCommands.size( ); ++i )
+    this->m_ConfigureCommands[ i ].first(
+      this->m_ConfigureCommands[ i ].second
+      );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnEnter( )
+{
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_EnterCommands.size( ); ++i )
+    this->m_EnterCommands[ i ].first( this->m_EnterCommands[ i ].second );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::BaseInteractorStyle::
+OnLeave( )
+{
+  vtkRenderWindowInteractor* rwi = this->GetInteractor( );
+  if( rwi == NULL )
+    return;
+
+  // Invoke possible events
+  for( unsigned int i = 0; i < this->m_LeaveCommands.size( ); ++i )
+    this->m_LeaveCommands[ i ].first( this->m_LeaveCommands[ i ].second );
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::BaseInteractorStyle::
 Dolly( )
@@ -187,7 +566,7 @@ Dolly( )
   vtkRenderWindowInteractor* rwi = this->GetInteractor( );
   double *center = this->CurrentRenderer->GetCenter( );
   int dy = rwi->GetEventPosition( )[ 1 ] - rwi->GetLastEventPosition( )[ 1 ];
-  double dyf = this->MotionFactor * dy / center[ 1 ];
+  double dyf = this->m_MotionFactor * dy / center[ 1 ];
   this->_Dolly( std::pow( 1.1, dyf ) );
 }
 
@@ -251,12 +630,12 @@ Pan( )
 cpExtensions::Visualization::BaseInteractorStyle::
 BaseInteractorStyle( )
   : Superclass( ),
-    MotionFactor( double( 10 ) )
+    m_MotionFactor( double( 10 ) )
 {
-  this->LeftButtonEvent.Reset( );
-  this->MiddleButtonEvent.Reset( );
-  this->RightButtonEvent.Reset( );
-  this->ActiveButton = Self::ButtonID_None;
+  this->m_LeftButtonEvent.Reset( );
+  this->m_MiddleButtonEvent.Reset( );
+  this->m_RightButtonEvent.Reset( );
+  this->m_ActiveButton = Self::ButtonID_None;
 
   this->EventCallbackCommand->SetCallback( Self::_ProcessEvents );
 }
@@ -312,7 +691,7 @@ _ProcessEvents(
   break;
   case vtkCommand::LeftButtonPressEvent:
   {
-    unsigned char nc = s->LeftButtonEvent.Clicks( );
+    unsigned char nc = s->m_LeftButtonEvent.Clicks( );
     if( nc == 2 )
       s->OnLeftDoubleClick( );
     else if( nc == 1 )
@@ -322,13 +701,13 @@ _ProcessEvents(
   break;
   case vtkCommand::LeftButtonReleaseEvent:
   {
-    s->LeftButtonEvent.Release( );
+    s->m_LeftButtonEvent.Release( );
     s->OnLeftButtonUp( );
   }
   break;
   case vtkCommand::MiddleButtonPressEvent:
   {
-    unsigned char nc = s->MiddleButtonEvent.Clicks( );
+    unsigned char nc = s->m_MiddleButtonEvent.Clicks( );
     if( nc == 2 )
       s->OnMiddleDoubleClick( );
     else if( nc == 1 )
@@ -338,13 +717,13 @@ _ProcessEvents(
   break;
   case vtkCommand::MiddleButtonReleaseEvent:
   {
-    s->MiddleButtonEvent.Release( );
+    s->m_MiddleButtonEvent.Release( );
     s->OnMiddleButtonUp( );
   }
   break;
   case vtkCommand::RightButtonPressEvent:
   {
-    unsigned char nc = s->RightButtonEvent.Clicks( );
+    unsigned char nc = s->m_RightButtonEvent.Clicks( );
     if( nc == 2 )
       s->OnRightDoubleClick( );
     else if( nc == 1 )
@@ -354,7 +733,7 @@ _ProcessEvents(
   break;
   case vtkCommand::RightButtonReleaseEvent:
   {
-    s->RightButtonEvent.Release( );
+    s->m_RightButtonEvent.Release( );
     s->OnRightButtonUp( );
   }
   break;