]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Interaction/SeedWidget.cxx
...
[cpPlugins.git] / lib / cpExtensions / Interaction / SeedWidget.cxx
index 73d13a5b1853320d213bd374f276933946856994..509d7c2605056e4d64d8843504eeb702688180f3 100644 (file)
@@ -1,11 +1,10 @@
 #include <cpExtensions/Interaction/SeedWidget.h>
 
-#include <vtkCallbackCommand.h>
 #include <vtkCommand.h>
+#include <vtkEvent.h>
 #include <vtkRenderWindowInteractor.h>
-#include <vtkSeedRepresentation.h>
-#include <vtkWidgetEventTranslator.h>
-#include <vtkWidgetRepresentation.h>
+#include <vtkWidgetCallbackMapper.h>
+#include <vtkWidgetEvent.h>
 
 // -------------------------------------------------------------------------
 cpExtensions::Interaction::SeedWidget::
@@ -20,18 +19,20 @@ void cpExtensions::Interaction::SeedWidget::
 SetInteractor( vtkRenderWindowInteractor* rwi )
 {
   this->Superclass::SetInteractor( rwi );
-  if( rwi != NULL )
-  {
-    TBaseStyle* s =
-      dynamic_cast< TBaseStyle* >( rwi->GetInteractorStyle( ) );
-    if( s != NULL )
-    {
-      s->AddMouseClickCommand( Self::_Click, this );
-      s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
-
-    } // fi
-
-  } // fi
+  /* TODO
+     if( rwi != NULL )
+     {
+     TBaseStyle* s =
+     dynamic_cast< TBaseStyle* >( rwi->GetInteractorStyle( ) );
+     if( s != NULL )
+     {
+     s->AddMouseClickCommand( Self::_Click, this );
+     s->AddMouseDoubleClickCommand( Self::_DoubleClick, this );
+
+     } // fi
+
+     } // fi
+  */
 }
 
 // -------------------------------------------------------------------------
@@ -39,11 +40,33 @@ cpExtensions::Interaction::SeedWidget::
 SeedWidget( )
   : Superclass( )
 {
-  // Remove default translations
-  vtkWidgetEventTranslator* t = this->GetEventTranslator( );
-  t->RemoveTranslation( vtkCommand::LeftButtonPressEvent );
-  t->RemoveTranslation( vtkCommand::MiddleButtonPressEvent );
-  t->RemoveTranslation( vtkCommand::RightButtonPressEvent );
+  // These are the event callbacks supported by this widget
+  this->CallbackMapper->SetCallbackMethod(
+    vtkCommand::LeftButtonPressEvent,
+    vtkWidgetEvent::AddPoint,
+    this, Self::_AddPointAction
+    );
+  this->CallbackMapper->SetCallbackMethod(
+    vtkCommand::RightButtonPressEvent,
+    vtkWidgetEvent::Completed,
+    this, Self::_CompletedAction
+    );
+  this->CallbackMapper->SetCallbackMethod(
+    vtkCommand::MouseMoveEvent,
+    vtkWidgetEvent::Move,
+    this, Self::_MoveAction
+    );
+  this->CallbackMapper->SetCallbackMethod(
+    vtkCommand::LeftButtonReleaseEvent,
+    vtkWidgetEvent::EndSelect,
+    this, Self::_EndSelectAction
+    );
+  this->CallbackMapper->SetCallbackMethod(
+    vtkCommand::KeyPressEvent,
+    vtkEvent::NoModifier, 127, 1, "Delete",
+    vtkWidgetEvent::Delete,
+    this, Self::_DeleteAction
+    );
 }
 
 // -------------------------------------------------------------------------
@@ -54,40 +77,89 @@ cpExtensions::Interaction::SeedWidget::
 
 // -------------------------------------------------------------------------
 void cpExtensions::Interaction::SeedWidget::
-_Click(
-  void* data, const TBaseStyle::ButtonID& button,
-  int* idx, double* pos, bool alt, bool ctr, bool sft
-  )
+_AddPointAction( vtkAbstractWidget* wdg )
 {
-  SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
+  Self* self = dynamic_cast< Self* >( wdg );
   if( self == NULL )
     return;
-  if( self->WidgetState == vtkSeedWidget::MovingSeed )
+  auto iren = self->GetInteractor( );
+  if( iren == NULL )
     return;
+  int shift = iren->GetShiftKey( );
+  if( shift == 1 )
+    Self::AddPointAction( wdg );
+}
 
-  int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
-  if( st == vtkSeedRepresentation::NearSeed )
-  {
-    self->WidgetState = vtkSeedWidget::MovingSeed;
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::SeedWidget::
+_CompletedAction( vtkAbstractWidget* wdg )
+{
+  // Do nothing
+  Self::CompletedAction( wdg );
+}
 
-    // Invoke an event on ourself for the handles
-    self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL );
-    self->Superclass::StartInteraction( );
-    self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
-    self->EventCallbackCommand->SetAbortFlag( 1 );
-    self->Render( );
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::SeedWidget::
+_MoveAction( vtkAbstractWidget* wdg )
+{
+  // Do nothing
+  Self::MoveAction( wdg );
+}
 
-  } // fi
+// -------------------------------------------------------------------------
+void cpExtensions::Interaction::SeedWidget::
+_EndSelectAction( vtkAbstractWidget* wdg )
+{
+  // Do nothing
+  Self::EndSelectAction( wdg );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Interaction::SeedWidget::
-_DoubleClick(
-  void* data, const TBaseStyle::ButtonID& button,
-  int* idx, double* pos, bool alt, bool ctr, bool sft
-  )
+_DeleteAction( vtkAbstractWidget* wdg )
 {
-  Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) );
+  // Do nothing
+  Self::DeleteAction( wdg );
 }
 
+// -------------------------------------------------------------------------
+/* TODO
+   void cpExtensions::Interaction::SeedWidget::
+   _Click(
+   void* data, const TBaseStyle::ButtonID& button,
+   int* idx, double* pos, bool alt, bool ctr, bool sft
+   )
+   {
+   SeedWidget* self = reinterpret_cast< SeedWidget* >( data );
+   if( self == NULL )
+   return;
+   if( self->WidgetState == vtkSeedWidget::MovingSeed )
+   return;
+
+   int st = self->WidgetRep->ComputeInteractionState( idx[ 0 ], idx[ 1 ] );
+   if( st == vtkSeedRepresentation::NearSeed )
+   {
+   self->WidgetState = vtkSeedWidget::MovingSeed;
+
+   // Invoke an event on ourself for the handles
+   self->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL );
+   self->Superclass::StartInteraction( );
+   self->InvokeEvent( vtkCommand::StartInteractionEvent, NULL );
+   self->EventCallbackCommand->SetAbortFlag( 1 );
+   self->Render( );
+
+   } // fi
+   }
+
+   // -------------------------------------------------------------------------
+   void cpExtensions::Interaction::SeedWidget::
+   _DoubleClick(
+   void* data, const TBaseStyle::ButtonID& button,
+   int* idx, double* pos, bool alt, bool ctr, bool sft
+   )
+   {
+   Self::AddPointAction( reinterpret_cast< vtkAbstractWidget* >( data ) );
+   }
+*/
+
 // eof - $RCSfile$