]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/QT/MPRInteractionCommand.cxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / QT / MPRInteractionCommand.cxx
diff --git a/lib/cpExtensions/QT/MPRInteractionCommand.cxx b/lib/cpExtensions/QT/MPRInteractionCommand.cxx
new file mode 100644 (file)
index 0000000..39dc19d
--- /dev/null
@@ -0,0 +1,97 @@
+#include <cpExtensions/QT/MPRInteractionCommand.h>
+#include <cpExtensions/Interaction/ImageSliceStyle.h>
+#include <cpExtensions/Visualization/ImageViewerActors.h>
+#include <cpExtensions/QT/ImageWidget.h>
+#include <cpExtensions/QT/MPR3DWidget.h>
+#include <vtkImageData.h>
+
+// -------------------------------------------------------------------------
+cpExtensions::QT::MPRInteractionCommand::
+Self* cpExtensions::QT::MPRInteractionCommand::
+New( )
+{
+  return( new Self( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::MPRInteractionCommand::
+AddWidget( QWidget* w )
+{
+  typedef cpExtensions::QT::ImageWidget _TImageWidget;
+  typedef cpExtensions::QT::MPR3DWidget _TMPR3DWidget;
+
+  auto img = dynamic_cast< _TImageWidget* >( w );
+  auto ren = dynamic_cast< _TMPR3DWidget* >( w );
+  if( img != NULL )
+    this->m_ImageWidgets.insert( img );
+  else if( ren != NULL )
+    this->m_MPR3DWidgets.insert( ren );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::MPRInteractionCommand::
+Execute( vtkObject* caller, unsigned long evId, void* data )
+{
+  typedef cpExtensions::Interaction::ImageSliceStyle _TStyle;
+
+  static const unsigned long _SuperCursor = vtkCommand::UserEvent + 1;
+  static const unsigned long _Slice = vtkCommand::UserEvent + 2;
+
+  // Prepare interaction data
+  auto* src = dynamic_cast< _TStyle* >( caller );
+  if( src == NULL || ( evId != _SuperCursor && evId != _Slice ) )
+    return;
+  if( evId == _SuperCursor )
+  {
+    /* TODO
+       auto ori = src->GetActors( )->GetOrientation( );
+       auto img = src->GetActors( )->GetImage( );
+       auto pos = reinterpret_cast< double* >( data );
+       int ijk[ 3 ];
+       double pcoords[ 3 ];
+       img->ComputeStructuredCoordinates( pos, ijk, pcoords );
+
+       for(
+       auto i = this->m_ImageWidgets.begin( );
+       i != this->m_ImageWidgets.end( );
+       ++i
+       )
+       if( ( *i )->GetInteractorStyle( ) != src )
+       ( *i )->SetSliceNumber( ijk[ ( *i )->GetOrientation( ) ] );
+    
+       for(
+       auto r = this->m_MPR3DWidgets.begin( );
+       r != this->m_MPR3DWidgets.end( );
+       ++r
+       )
+       ( *r )->SetSlicesNumbers( ijk[ 0 ], ijk[ 1 ], ijk[ 2 ] );
+    */
+  }
+  else if( evId == _Slice )
+  {
+    int slc = src->GetSliceNumber( );
+    int ori = src->GetOrientation( );
+    for(
+      auto r = this->m_MPR3DWidgets.begin( );
+      r != this->m_MPR3DWidgets.end( );
+      ++r
+      )
+      ( *r )->SetSliceNumber( ori, slc );
+
+  } // fi
+}
+      
+// -------------------------------------------------------------------------
+cpExtensions::QT::MPRInteractionCommand::
+MPRInteractionCommand( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpExtensions::QT::MPRInteractionCommand::
+~MPRInteractionCommand( )
+{
+}
+
+// eof - $RCSfile$