]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/Workspace.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / Workspace.cxx
index bdc67e000d0c351e8a7e68ad39276fdc9e50ea4f..4fbcb2bbf3b154e11332f29b0a32cd7201630f95 100644 (file)
@@ -1,5 +1,5 @@
 #include <cpPlugins/Interface/Workspace.h>
-#include <cpPlugins/BaseObjects/Widget.h>
+#include <cpPlugins/Pipeline/Widget.h>
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::Workspace::
@@ -78,19 +78,22 @@ HasWidget( const std::string& name ) const
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Workspace::
 TFilter* cpPlugins::Interface::Workspace::
-CreateFilter( const std::string& category, const std::string& filter )
+CreateFilter(
+  const std::string& category, const std::string& filter,
+  const std::string& name
+  )
 {
-  typedef cpPlugins::BaseObjects::Widget _TWidget;
+  typedef cpPlugins::Pipeline::Widget _TWidget;
 
-  TFilter::Pointer o = this->m_Plugins->CreateFilter( category, filter );
+  TFilter::Pointer o = this->m_Loader.CreateFilter( category, filter );
   if( o.IsNotNull( ) )
   {
     // Choose a name
-    std::string name = filter;
-    while( this->GetFilter( name ) != NULL )
-      name += std::string( "_" );
+    std::string real_name = name;
+    while( this->GetFilter( real_name ) != NULL )
+      real_name += std::string( "_" );
     o->SetPrintExecution( this->m_PrintExecution );
-    o->SetName( name );
+    o->SetName( real_name );
 
     // Interactors
     for(
@@ -101,12 +104,20 @@ CreateFilter( const std::string& category, const std::string& filter )
       o->AddInteractor( *i );
 
     // Finish association
-    this->m_Filters[ name ] = o;
+    this->m_Filters[ real_name ] = o;
 
   } // fi
   return( o.GetPointer( ) );
 }
 
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Workspace::
+TFilter* cpPlugins::Interface::Workspace::
+CreateFilter( const std::string& category, const std::string& filter )
+{
+  return( this->CreateFilter( category, filter, filter ) );
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::Workspace::
 RenameFilter( const std::string& old_name, const std::string& new_name )
@@ -232,6 +243,48 @@ Connect(
   return( ok );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+Connect(
+  TDataObject* input,
+  const std::string& destination_filter,
+  const std::string& destination_input
+  )
+{
+  // Get filters and check pertinence
+  if( input == NULL )
+    return( false );
+  TFilter* destination = this->GetFilter( destination_filter );
+  if( destination == NULL )
+    return( false );
+  if( !( destination->HasInput( destination_input ) ) )
+    return( false );
+
+  // Check if there is room for a new connection
+  bool ok = true;
+  if( destination->IsInputMultiple( destination_input ) )
+  {
+    for(
+      unsigned int i = 0;
+      i < destination->GetInputSize( destination_input );
+      ++i
+      )
+      if(
+        destination->GetInput( destination_input, i )->GetSource( ) ==
+        input->GetSource( )
+        )
+        ok = false;
+  }
+  else
+    ok = ( destination->GetInput( destination_input ) == NULL );
+  if( ok )
+    destination->AddInput(
+      destination_input,
+      input
+      );
+  return( ok );
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::Workspace::
 Disconnect(
@@ -290,7 +343,7 @@ GetExposedOutputs( ) const
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::BaseObjects::DataObject* cpPlugins::Interface::Workspace::
+cpPlugins::Pipeline::DataObject* cpPlugins::Interface::Workspace::
 GetExposedOutput( const std::string& name )
 {
   auto i = this->m_ExposedOutputs.find( name );
@@ -307,7 +360,7 @@ GetExposedOutput( const std::string& name )
 }
 
 // -------------------------------------------------------------------------
-const cpPlugins::BaseObjects::DataObject* cpPlugins::Interface::Workspace::
+const cpPlugins::Pipeline::DataObject* cpPlugins::Interface::Workspace::
 GetExposedOutput( const std::string& name ) const
 {
   auto i = this->m_ExposedOutputs.find( name );
@@ -487,7 +540,7 @@ Connect(
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::Workspace::
 Connect(
-  cpPlugins::BaseObjects::DataObject* output,
+  cpPlugins::Pipeline::DataObject* output,
   const std::string& dest_filter, const std::string& input_name
   )
 {
@@ -499,7 +552,7 @@ Connect(
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::Workspace::
 Connect(
-  cpPlugins::BaseObjects::DataObject* output,
+  cpPlugins::Pipeline::DataObject* output,
   const std::string& exposed_input_name
   )
 {
@@ -523,7 +576,7 @@ Disconnect(
     auto in = dest->GetInput( input_name );
     if( out != NULL && out == in )
       dest->SetInput(
-        input_name, ( cpPlugins::BaseObjects::DataObject* )( NULL )
+        input_name, ( cpPlugins::Pipeline::DataObject* )( NULL )
         );
 
   } // fi
@@ -569,7 +622,6 @@ Workspace( )
   : Superclass( ),
     m_PrintExecution( false )
 {
-  this->m_Plugins = TPlugins::New( );
 }
 
 // -------------------------------------------------------------------------