X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FWorkspaceIO.cxx;h=f7b25ca9f129ed26721bb7661b4ffdcf73728d66;hb=24d0c2ad34de2cbd89fed76058f2995cdf81d239;hp=c23852a8ff72675c3dae95e48102bf12dc9c55be;hpb=010f4aa9d69c30818fad4c998bbcb99b4f42f43d;p=cpPlugins.git diff --git a/lib/cpPlugins/WorkspaceIO.cxx b/lib/cpPlugins/WorkspaceIO.cxx index c23852a..f7b25ca 100644 --- a/lib/cpPlugins/WorkspaceIO.cxx +++ b/lib/cpPlugins/WorkspaceIO.cxx @@ -5,6 +5,8 @@ std::string cpPlugins::Workspace:: LoadWorkspace( const std::string& fname ) { + if( this->m_Interface == NULL ) + return( "cpPlugins::Workspace: No valid plugins interface" ); tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument( ); doc->LoadFile( fname.c_str( ) ); tinyxml2::XMLElement* root = doc->RootElement( ); @@ -14,6 +16,38 @@ LoadWorkspace( const std::string& fname ) return( "cpPlugins::Workspace: No valid workspace" ); std::stringstream err; + // Load plugins + auto loaded_plugins = this->m_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 + { + this->m_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 != "" ) + return( std::string( "cpPlugins::Workspace: " ) + plugins_errors ); + // Read filters tinyxml2::XMLElement* filter = root->FirstChildElement( "filter" ); while( filter != NULL ) @@ -107,6 +141,7 @@ SaveWorkspace( const std::string& fname ) const std::stringstream err; tinyxml2::XMLDocument* doc = new tinyxml2::XMLDocument( ); tinyxml2::XMLElement* root = doc->NewElement( "cpPlugins_Workspace" ); + std::set< std::string > used_plugins; // Save vertices auto vIt = this->m_Graph->BeginVertices( ); @@ -116,6 +151,8 @@ SaveWorkspace( const std::string& fname ) const auto data = dynamic_cast< DataObject* >( vIt->second.GetPointer( ) ); if( filter != NULL ) { + used_plugins.insert( this->m_Interface->GetPluginName( filter ) ); + tinyxml2::XMLElement* e = doc->NewElement( "filter" ); e->SetAttribute( "category", filter->GetClassCategory( ) ); e->SetAttribute( "class", filter->GetClassName( ) ); @@ -134,6 +171,17 @@ SaveWorkspace( 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 ); + // Save connections auto mIt = this->m_Graph->BeginEdgesRows( ); for( ; mIt != this->m_Graph->EndEdgesRows( ); ++mIt )