]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ParametersQtDialog.cxx
Machete filter with interactive plane: it now supports images and meshes. Not yet...
[cpPlugins.git] / lib / cpPlugins / Interface / ParametersQtDialog.cxx
index 0891a2b5c09c409c9c5d80381ef5114a27b441cd..90393ffc9150fe4e3daebfc167b8374d123a9fb4 100644 (file)
@@ -6,11 +6,8 @@
 
 #include <cpPlugins/Interface/ParametersListWidget.h>
 
-#include <vtkSmartPointer.h>
-#include <cpExtensions/Interaction/SeedWidget.h>
-#include <vtkPointHandleRepresentation3D.h>
-#include <vtkProperty.h>
-#include <vtkSeedRepresentation.h>
+#include <vtkCommand.h>
+#include <vtkRenderWindowInteractor.h>
 
 #include <QCheckBox>
 #include <QDialogButtonBox>
 #include <QLineEdit>
 #include <QWidget>
 
+// -------------------------------------------------------------------------
+#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Plugins.h>
+#include <cpPlugins/Interface/BaseApplication.h>
+
+class SingleSeedCommand
+  : public vtkCommand
+{
+public:
+  static SingleSeedCommand* New( )
+    { return( new SingleSeedCommand ); }
+  virtual void Execute( vtkObject* caller, unsigned long eid, void* data )
+    {
+      // Get seed, avoiding segfaults!!!
+      if( eid != vtkCommand::PlacePointEvent || this->Dialog == NULL )
+        return;
+      vtkSeedWidget* widget = dynamic_cast< vtkSeedWidget* >( caller );
+      if( widget == NULL )
+        return;
+      vtkSeedRepresentation* rep = widget->GetSeedRepresentation( );
+      if( rep == NULL )
+        return;
+      if( rep->GetNumberOfSeeds( ) == 0 )
+        return;
+      double seed[ 3 ];
+      rep->GetSeedWorldPosition( 0, seed );
+
+      // Delete all seeds (remember that this command is just for one seed)
+      while( rep->GetNumberOfSeeds( ) > 0 )
+        widget->DeleteSeed( 0 );
+
+      if( this->Dialog->getParameters( )->HasIndex( this->Name ) )
+      {
+      }
+      else if( this->Dialog->getParameters( )->HasPoint( this->Name ) )
+      {
+        this->Dialog->getParameters( )->SetPoint( this->Name, 3, seed );
+        this->Dialog->syncParameters( );
+        auto filter = this->Dialog->getParameters( )->GetProcessObject( );
+        if( filter != NULL )
+        {
+          auto plugins = filter->GetPlugins( );
+          if( plugins != NULL )
+          {
+            auto app = plugins->GetApplication( );
+            if( app != NULL )
+              app->UpdateActualFilter( );
+
+          } // fi
+
+        } // fi
+
+      } // fi
+    }
+protected:
+  SingleSeedCommand( )
+    : vtkCommand( ),
+      Dialog( NULL )
+    {
+    }
+  virtual ~SingleSeedCommand( )
+    {
+    }
+
+public:
+  cpPlugins::Interface::ParametersQtDialog* Dialog;
+  std::string Name;
+};
+
 // -------------------------------------------------------------------------
 cpPlugins::Interface::ParametersQtDialog::
 ParametersQtDialog( QWidget* parent, Qt::WindowFlags f )
   : QDialog( parent, f ),
     m_Parameters( NULL ),
-    m_IsModal( false ),
-    m_Interactor( NULL )
+    m_IsModal( false )
 {
   this->m_Title = new QLabel( this );
   this->m_Title->setText( "Parameters dialog title" );
@@ -43,9 +108,6 @@ cpPlugins::Interface::ParametersQtDialog::
   delete this->m_Title;
   delete this->m_ToolsLayout;
   delete this->m_MainLayout;
-
-  for( unsigned int i = 0; i < this->m_Widgets.size( ); ++i )
-    this->m_Widgets[ i ]->Delete( );
 }
 
 // -------------------------------------------------------------------------
@@ -65,9 +127,25 @@ getParameters( ) const
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::ParametersQtDialog::
-setInteractor( vtkRenderWindowInteractor* interactor )
+addInteractor( vtkRenderWindowInteractor* interactor )
 {
-  this->m_Interactor = interactor;
+  this->m_Interactors.insert( interactor );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ParametersQtDialog::
+TInteractors& cpPlugins::Interface::ParametersQtDialog::
+getInteractors( )
+{
+  return( this->m_Interactors );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::ParametersQtDialog::
+TInteractors& cpPlugins::Interface::ParametersQtDialog::
+getInteractors( ) const
+{
+  return( this->m_Interactors );
 }
 
 // -------------------------------------------------------------------------
@@ -139,26 +217,25 @@ setParameters( Parameters* parameters )
     }
     else if( pt == Parameters::Point || pt == Parameters::Index )
     {
-      if( this->m_Interactor != NULL )
+      vtkSmartPointer< SingleSeedCommand > command =
+        vtkSmartPointer< SingleSeedCommand >::New( );
+      command->Dialog = this;
+      command->Name = *nIt;
+
+      auto iIt = this->m_Interactors.begin( );
+      for( ; iIt != this->m_Interactors.end( ); ++iIt )
       {
-        // Create a point widget and its representation
-        vtkSmartPointer< vtkPointHandleRepresentation3D > handle =
-          vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
-        handle->GetProperty( )->SetColor( 1, 0, 0 );
-        vtkSmartPointer< vtkSeedRepresentation > rep =
-          vtkSmartPointer< vtkSeedRepresentation >::New( );
-        rep->SetHandleRepresentation( handle );
-
-        cpExtensions::Interaction::SeedWidget* widget =
-          cpExtensions::Interaction::SeedWidget::New( );
-        widget->SetInteractor( this->m_Interactor );
-        widget->SetRepresentation( rep );
-        widget->On( );
-
-        this->m_Widgets.push_back( widget );
-        this->m_IsModal = false;
+        TStyle* style =
+          dynamic_cast< TStyle* >( ( *iIt )->GetInteractorStyle( ) );
+        if( style != NULL )
+        {
+          style->SeedWidgetOn( );
+          style->SetSeedWidgetCommand( command );
 
-      } // fi
+        } // fi
+
+      } // rof
+      this->m_IsModal = false;
 
     } // fi