]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/WorkspaceIO.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / lib / cpPlugins / Interface / WorkspaceIO.cxx
index 029ade420b79aa60ce57a8ca49fc491d16a5783e..e69c3c8060bc515600941209ef311d889057d322 100644 (file)
@@ -6,7 +6,6 @@ void cpPlugins::Interface::Workspace::
 Load( const std::string& fname )
 {
   this->Clear( );
-  TInterface::Pointer interface = TInterface::New( );
 
   // Read from disk
   tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument( );
@@ -25,44 +24,6 @@ Load( const std::string& fname )
 
   } // fi
 
-  // Load plugins
-  auto loaded_plugins = interface->GetPlugins( );
-  tinyxml2::XMLElement* plugins = root->FirstChildElement( "Plugins" );
-  std::string plugins_errors = "";
-  while( plugins != NULL )
-  {
-    tinyxml2::XMLElement* plugin = plugins->FirstChildElement( "Plugin" );
-    while( plugin != NULL )
-    {
-      std::string name = plugin->Attribute( "Name" );
-      if( loaded_plugins.find( name ) == loaded_plugins.end( ) )
-      {
-        try
-        {
-          interface->LoadPlugin( name );
-        }
-        catch( std::exception& err )
-        {
-          plugins_errors += err.what( ) + std::string( "\n" );
-
-        } // yrt
-
-      } // fi
-      plugin = plugin->NextSiblingElement( "Plugin" );
-
-    } // elihw
-    plugins = plugins->NextSiblingElement( "Plugins" );
-
-  } // elihw
-  if( plugins_errors != "" )
-  {
-    delete doc;
-    throw std::runtime_error(
-      std::string( "cpPlugins::Workspace: " ) + plugins_errors
-      );
-
-  } // fi
-
   // Read filters
   std::stringstream err;
   tinyxml2::XMLElement* filter = root->FirstChildElement( "Filter" );
@@ -80,10 +41,10 @@ Load( const std::string& fname )
       );
     if( class_value != NULL && name_value != NULL )
     {
-      auto new_filter =
-        this->CreateFilter( category_value, class_value, name_value );
+      auto new_filter = this->CreateFilter( category_value, class_value );
       if( new_filter != NULL )
       {
+        this->RenameFilter( new_filter->GetName( ), name_value );
         new_filter->SetViewCoords( viewX, viewY );
         new_filter->SetExplicitExecution( explicit_execution == 1 );
         new_filter->GetParameters( )->FromXML( filter );
@@ -118,7 +79,7 @@ Load( const std::string& fname )
       {
         try
         {
-          this->Connect( orig_filter, dest_filter, orig_name, dest_name );
+          this->Connect( orig_filter, orig_name, dest_filter, dest_name );
         }
         catch( std::exception& exc )
         {
@@ -134,30 +95,32 @@ Load( const std::string& fname )
   } // elihw
 
   // Read exposed inputs
-  tinyxml2::XMLElement* port = root->FirstChildElement( "ExposedInput" );
-  while( port != NULL )
-  {
-    this->ExposeInput(
-      port->Attribute( "Name" ),
-      port->Attribute( "Filter" ),
-      port->Attribute( "Input" )
-      );
-    port = port->NextSiblingElement( "ExposedInput" );
-
-  } // elihw
-
-  // Read exposed outputs
-  port = root->FirstChildElement( "ExposedOutput" );
-  while( port != NULL )
-  {
-    this->ExposeOutput(
-      port->Attribute( "Name" ),
-      port->Attribute( "Filter" ),
-      port->Attribute( "Output" )
-      );
-    port = port->NextSiblingElement( "ExposedOutput" );
-
-  } // elihw
+  /* TODO
+     tinyxml2::XMLElement* port = root->FirstChildElement( "ExposedInput" );
+     while( port != NULL )
+     {
+     this->ExposeInput(
+     port->Attribute( "Name" ),
+     port->Attribute( "Filter" ),
+     port->Attribute( "Input" )
+     );
+     port = port->NextSiblingElement( "ExposedInput" );
+
+     } // elihw
+
+     // Read exposed outputs
+     port = root->FirstChildElement( "ExposedOutput" );
+     while( port != NULL )
+     {
+     this->ExposeOutput(
+     port->Attribute( "Name" ),
+     port->Attribute( "Filter" ),
+     port->Attribute( "Output" )
+     );
+     port = port->NextSiblingElement( "ExposedOutput" );
+
+     } // elihw
+  */
 
   // Throw errors
   std::string err_str = err.str( );
@@ -204,15 +167,17 @@ Save( const std::string& fname ) const
   } // rof
 
   // Save used plugins
-  tinyxml2::XMLElement* plugins = doc->NewElement( "Plugins" );
-  for( auto pIt = used_plugins.begin( ); pIt != used_plugins.end( ); ++pIt )
-  {
-    tinyxml2::XMLElement* e = doc->NewElement( "Plugin" );
-    e->SetAttribute( "Name", pIt->c_str( ) );
-    plugins->LinkEndChild( e );
-
-  } // rof
-  root->LinkEndChild( plugins );
+  /* TODO
+     tinyxml2::XMLElement* plugins = doc->NewElement( "Plugins" );
+     for( auto pIt = used_plugins.begin( ); pIt != used_plugins.end( ); ++pIt )
+     {
+     tinyxml2::XMLElement* e = doc->NewElement( "Plugin" );
+     e->SetAttribute( "Name", pIt->c_str( ) );
+     plugins->LinkEndChild( e );
+
+     } // rof
+     root->LinkEndChild( plugins );
+  */
 
   // Save connections
   for( auto i = this->m_Filters.begin( ); i != this->m_Filters.end( ); ++i )
@@ -235,21 +200,26 @@ Save( const std::string& fname ) const
         auto od = orig->GetOutput( *oIt );
         for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
         {
-          auto id = dest->GetInput( *iIt );
-          if( od != NULL && od == id )
+          unsigned int nInputs = dest->GetInputSize( *iIt );
+          for( unsigned int k = 0; k < nInputs; ++k )
           {
-            tinyxml2::XMLElement* e_conn = doc->NewElement( "Connection" );
-            tinyxml2::XMLElement* e_orig = doc->NewElement( "Origin" );
-            tinyxml2::XMLElement* e_dest = doc->NewElement( "Destination" );
-            e_orig->SetAttribute( "Filter", orig->GetName( ) );
-            e_orig->SetAttribute( "Name", oIt->c_str( ) );
-            e_dest->SetAttribute( "Filter", dest->GetName( ) );
-            e_dest->SetAttribute( "Name", iIt->c_str( ) );
-            e_conn->LinkEndChild( e_orig );
-            e_conn->LinkEndChild( e_dest );
-            root->LinkEndChild( e_conn );
-
-          } // fi
+            auto id = dest->GetInput( *iIt, k );
+            if( od != NULL && od == id )
+            {
+              tinyxml2::XMLElement* e_conn = doc->NewElement( "Connection" );
+              tinyxml2::XMLElement* e_orig = doc->NewElement( "Origin" );
+              tinyxml2::XMLElement* e_dest = doc->NewElement( "Destination" );
+              e_orig->SetAttribute( "Filter", orig->GetName( ) );
+              e_orig->SetAttribute( "Name", oIt->c_str( ) );
+              e_dest->SetAttribute( "Filter", dest->GetName( ) );
+              e_dest->SetAttribute( "Name", iIt->c_str( ) );
+              e_conn->LinkEndChild( e_orig );
+              e_conn->LinkEndChild( e_dest );
+              root->LinkEndChild( e_conn );
+
+            } // fi
+
+          } // rof
 
         } // rof
 
@@ -259,29 +229,30 @@ Save( const std::string& fname ) const
 
   } // rof
 
-
   // Save exposed ports
-  auto eipIt = this->m_ExposedInputs.begin( );
-  for( ; eipIt != this->m_ExposedInputs.end( ); ++eipIt )
-  {
-    tinyxml2::XMLElement* port = doc->NewElement( "ExposedInput" );
-    port->SetAttribute( "Name", eipIt->first.c_str( ) );
-    port->SetAttribute( "Filter", eipIt->second.first.c_str( ) );
-    port->SetAttribute( "Input", eipIt->second.second.c_str( ) );
-    root->LinkEndChild( port );
-
-  } // rof
-
-  auto eopIt = this->m_ExposedOutputs.begin( );
-  for( ; eopIt != this->m_ExposedOutputs.end( ); ++eopIt )
-  {
-    tinyxml2::XMLElement* port = doc->NewElement( "ExposedOutput" );
-    port->SetAttribute( "Name", eopIt->first.c_str( ) );
-    port->SetAttribute( "Filter", eopIt->second.first.c_str( ) );
-    port->SetAttribute( "Output", eopIt->second.second.c_str( ) );
-    root->LinkEndChild( port );
-
-  } // rof
+  /* TODO
+     auto eipIt = this->m_ExposedInputs.begin( );
+     for( ; eipIt != this->m_ExposedInputs.end( ); ++eipIt )
+     {
+     tinyxml2::XMLElement* port = doc->NewElement( "ExposedInput" );
+     port->SetAttribute( "Name", eipIt->first.c_str( ) );
+     port->SetAttribute( "Filter", eipIt->second.first.c_str( ) );
+     port->SetAttribute( "Input", eipIt->second.second.c_str( ) );
+     root->LinkEndChild( port );
+
+     } // rof
+
+     auto eopIt = this->m_ExposedOutputs.begin( );
+     for( ; eopIt != this->m_ExposedOutputs.end( ); ++eopIt )
+     {
+     tinyxml2::XMLElement* port = doc->NewElement( "ExposedOutput" );
+     port->SetAttribute( "Name", eopIt->first.c_str( ) );
+     port->SetAttribute( "Filter", eopIt->second.first.c_str( ) );
+     port->SetAttribute( "Output", eopIt->second.second.c_str( ) );
+     root->LinkEndChild( port );
+
+     } // rof
+  */
 
   // Physical write and return
   doc->LinkEndChild( root );