]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Extensions/Visualization/ImageInteractorStyle.cxx
Image interaction updated.
[cpPlugins.git] / lib / cpPlugins / Extensions / Visualization / ImageInteractorStyle.cxx
index a72f68bc95ff9ea8815c52b1326191aa7ccbef6a..67a271f58a058a71543c4cbb3c1b681ab5778bd6 100644 (file)
@@ -1,5 +1,7 @@
 #include <cpPlugins/Extensions/Visualization/ImageInteractorStyle.h>
 
+#include <ctime>
+
 #include <vtkAnnotatedCubeActor.h>
 #include <vtkAxesActor.h>
 #include <vtkCallbackCommand.h>
@@ -16,7 +18,7 @@
 
 // -------------------------------------------------------------------------
 const int cpPlugins::Extensions::Visualization::
-ImageInteractorStyle::SliceEvent = vtkCommand::UserEvent + 1;
+ImageInteractorStyle::DoubleClickEvent = vtkCommand::UserEvent + 1;
 
 // -------------------------------------------------------------------------
 cpPlugins::Extensions::Visualization::ImageInteractorStyle::
@@ -110,6 +112,34 @@ SetInteractor( vtkRenderWindowInteractor* interactor, const int& axis )
   this->OrientationWidget->InteractiveOff( );
 }
 
+// -------------------------------------------------------------------------
+unsigned long cpPlugins::Extensions::Visualization::ImageInteractorStyle::
+AddDoubleClickObserver( vtkCommand* observer )
+{
+  return( this->AddObserver( Self::DoubleClickEvent, observer ) );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
+RemoveDoubleClickObserver( unsigned long tag )
+{
+  this->RemoveObserver( tag );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
+RemoveDoubleClickObserver( vtkCommand* observer )
+{
+  this->RemoveObserver( observer );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
+RemoveDoubleClickObservers( )
+{
+  this->RemoveObservers( Self::DoubleClickEvent );
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 OnMouseMove( )
@@ -153,46 +183,32 @@ OnMouseMove( )
 void cpPlugins::Extensions::Visualization::ImageInteractorStyle::
 OnLeftButtonDown( )
 {
-  int x = this->Interactor->GetEventPosition( )[ 0 ];
-  int y = this->Interactor->GetEventPosition( )[ 1 ];
-
-  this->FindPokedRenderer( x, y );
+  static double pnt[ 3 ];
+  static int pos[ 2 ];
+  this->Interactor->GetEventPosition( pos );
+  this->FindPokedRenderer( pos[ 0 ], pos[ 1 ] );
   if( this->CurrentRenderer == NULL )
     return;
   this->GrabFocus( this->EventCallbackCommand );
 
-  if( this->Interactor->GetControlKey( ) )
-    this->StartCursorMoving( );
-
-  /* TODO
-     if (!this->Interactor->GetShiftKey() && !this->Interactor->GetControlKey())
-     {
-     this->WindowLevelStartPosition[0] = x;
-     this->WindowLevelStartPosition[1] = y;
-     this->StartWindowLevel();
-     }
-
-     // If shift is held down, do a rotation
-     else if (this->InteractionMode == VTKIS_IMAGE3D &&
-     this->Interactor->GetShiftKey())
-     {
-     this->StartRotate();
-     }
-
-     // If ctrl is held down in slicing mode, slice the image
-     else if (this->InteractionMode == VTKIS_IMAGE_SLICING &&
-     this->Interactor->GetControlKey())
-     {
-     this->StartSlice();
-     }
-
-     // The rest of the button + key combinations remain the same
-
-     else
-     {
-     this->Superclass::OnLeftButtonDown();
-     }
-  */
+  // TODO: check this code
+  // Manage double-click
+  static const long epsilon_time = 250;
+  static long last_click_time = -( epsilon_time << 1 );
+  long click_time = static_cast< long >( std::clock( ) );
+  if( ( click_time - last_click_time ) < epsilon_time )
+  {
+    last_click_time = -( epsilon_time << 1 );
+    if( this->_PickPosition( pnt ) )
+      this->InvokeEvent( Self::DoubleClickEvent, pnt );
+  }
+  else
+  {
+    last_click_time = click_time;
+    if( this->Interactor->GetControlKey( ) )
+      this->StartCursorMoving( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------