X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FWorkspaceIO.cxx;h=f811a5e9b6f57640e0ac9bdf196266e818df2e07;hb=1bf710541f1f708f9000096a8d516596bf009d6d;hp=d1578ba12818ddb9a3070f113587fcffc473ae98;hpb=83e946f1e96c001dde06a2785473d08468e28b2e;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/WorkspaceIO.cxx b/lib/cpPlugins/Interface/WorkspaceIO.cxx index d1578ba..f811a5e 100644 --- a/lib/cpPlugins/Interface/WorkspaceIO.cxx +++ b/lib/cpPlugins/Interface/WorkspaceIO.cxx @@ -14,106 +14,25 @@ LoadWorkspace( const std::string& fname ) return( "cpPlugins::Interface::Workspace: No valid workspace" ); std::stringstream err; - // Read plugins files - TiXmlElement* plugins = root->FirstChildElement( "plugins" ); - while( plugins != NULL ) - { - const char* value = plugins->Attribute( "filename" ); - if( value != NULL ) - { - if( !( this->LoadPlugins( value ) ) ) - err << "no valid plugins file \"" << value << "\"" << std::endl; - - } // fi - plugins = plugins->NextSiblingElement( "plugins" ); - - } // elihw - - // Read plugins paths - plugins = root->FirstChildElement( "plugins_dir" ); - while( plugins != NULL ) - { - const char* value = plugins->Attribute( "path" ); - if( value != NULL ) - { - int recursive; - if( plugins->QueryIntAttribute( "recursive", &recursive ) != TIXML_SUCCESS ) - recursive = 0; - if( !( this->LoadPluginsPath( value, recursive == 1 ) ) ) - err << "No valid plugins path \"" << value << "\"" << std::endl; - - } // fi - plugins = plugins->NextSiblingElement( "plugins_dir" ); - - } // elihw - // Read filters TiXmlElement* filter = root->FirstChildElement( "filter" ); while( filter != NULL ) { const char* class_value = filter->Attribute( "class" ); const char* name_value = filter->Attribute( "name" ); + float viewX = float( 0 ), viewY = float( 0 ); + filter->QueryFloatAttribute( "ViewX", &viewX ); + filter->QueryFloatAttribute( "ViewY", &viewY ); if( class_value != NULL && name_value != NULL ) { if( this->CreateFilter( class_value, name_value ) ) { - // Read parameters - TParameters* parameters = this->GetParameters( name_value ); - parameters->Clear( ); - - TiXmlElement* param = filter->FirstChildElement( "parameter" ); - while( param != NULL ) - { - const char* param_name = param->Attribute( "name" ); - const char* param_type = param->Attribute( "type" ); - if( param_name != NULL && param_type != NULL ) - { - std::string param_type_str( param_type ); - const char* value = param->Attribute( "value" ); - if( value != NULL ) - { - if( param_type_str == "String" ) - parameters->ConfigureAsString( param_name ); - else if( param_type_str == "Bool" ) - parameters->ConfigureAsBool( param_name ); - else if( param_type_str == "Int" ) - parameters->ConfigureAsInt( param_name ); - else if( param_type_str == "Uint" ) - parameters->ConfigureAsUint( param_name ); - else if( param_type_str == "Real" ) - parameters->ConfigureAsReal( param_name ); - else if( param_type_str == "Index" ) - parameters->ConfigureAsIndex( param_name ); - else if( param_type_str == "Point" ) - parameters->ConfigureAsPoint( param_name ); - else if( param_type_str == "Vector" ) - parameters->ConfigureAsVector( param_name ); - else if( param_type_str == "StringList" ) - parameters->ConfigureAsStringList( param_name ); - else if( param_type_str == "BoolList" ) - parameters->ConfigureAsBoolList( param_name ); - else if( param_type_str == "IntList" ) - parameters->ConfigureAsIntList( param_name ); - else if( param_type_str == "UintList" ) - parameters->ConfigureAsUintList( param_name ); - else if( param_type_str == "RealList" ) - parameters->ConfigureAsRealList( param_name ); - else if( param_type_str == "IndexList" ) - parameters->ConfigureAsIndexList( param_name ); - else if( param_type_str == "PointList" ) - parameters->ConfigureAsPointList( param_name ); - else if( param_type_str == "VectorList" ) - parameters->ConfigureAsVectorList( param_name ); - else if( param_type_str == "Choices" ) - parameters->ConfigureAsChoices( param_name ); - parameters->SetString( param_name, value, false ); + TFilter* new_filter = this->GetFilter( name_value ); + new_filter->SetViewCoords( viewX, viewY ); - } // fi - - } // fi - param = param->NextSiblingElement( "parameter" ); - - } // elihw + // Read parameters + TParameters* parameters = new_filter->GetParameters( ); + parameters->FromXML( filter ); } else err @@ -149,6 +68,32 @@ LoadWorkspace( const std::string& fname ) } // elihw + // Read exposed inputs + TiXmlElement* port = root->FirstChildElement( "exposed_input_port" ); + while( port != NULL ) + { + this->ExposeInputPort( + port->Attribute( "port_name" ), + port->Attribute( "filter" ), + port->Attribute( "filter_port_name" ) + ); + port = port->NextSiblingElement( "exposed_input_port" ); + + } // elihw + + // Read exposed outputs + port = root->FirstChildElement( "exposed_output_port" ); + while( port != NULL ) + { + this->ExposeOutputPort( + port->Attribute( "port_name" ), + port->Attribute( "filter" ), + port->Attribute( "filter_port_name" ) + ); + port = port->NextSiblingElement( "exposed_output_port" ); + + } // elihw + // Finish and return delete doc; return( err.str( ) ); @@ -162,19 +107,6 @@ SaveWorkspace( const std::string& fname ) const TiXmlDocument* doc = new TiXmlDocument( ); TiXmlElement* root = new TiXmlElement( "cpPlugins_Workspace" ); - // Save plugins - for( - auto plugIt = this->m_LoadedPlugins.begin( ); - plugIt != this->m_LoadedPlugins.end( ); - ++plugIt - ) - { - TiXmlElement* plugin = new TiXmlElement( "plugins" ); - plugin->SetAttribute( "filename", plugIt->c_str( ) ); - root->LinkEndChild( plugin ); - - } // rof - // Save vertices auto vIt = this->m_Graph->BeginVertices( ); for( ; vIt != this->m_Graph->EndVertices( ); ++vIt ) @@ -184,56 +116,14 @@ SaveWorkspace( const std::string& fname ) const if( filter != NULL ) { TiXmlElement* e = new TiXmlElement( "filter" ); - e->SetAttribute( "class", filter->GetClassName( ).c_str( ) ); - e->SetAttribute( "name", filter->GetName( ) ); + e->SetAttribute( "class", filter->GetClassName( ) ); + e->SetAttribute( "name", vIt->first.c_str( ) ); + e->SetAttribute( "ViewX", filter->GetViewX( ) ); + e->SetAttribute( "ViewY", filter->GetViewY( ) ); const TParameters* params = filter->GetParameters( ); - std::vector< std::string > names; - params->GetNames( names ); - for( auto nIt = names.begin( ); nIt != names.end( ); ++nIt ) - { - TiXmlElement* p = new TiXmlElement( "parameter" ); - p->SetAttribute( "name", nIt->c_str( ) ); - if( params->HasString( *nIt ) ) - p->SetAttribute( "type", "String" ); - else if( params->HasBool( *nIt ) ) - p->SetAttribute( "type", "Bool" ); - else if( params->HasInt( *nIt ) ) - p->SetAttribute( "type", "Int" ); - else if( params->HasUint( *nIt ) ) - p->SetAttribute( "type", "Uint" ); - else if( params->HasReal( *nIt ) ) - p->SetAttribute( "type", "Real" ); - else if( params->HasIndex( *nIt ) ) - p->SetAttribute( "type", "Index" ); - else if( params->HasPoint( *nIt ) ) - p->SetAttribute( "type", "Point" ); - else if( params->HasVector( *nIt ) ) - p->SetAttribute( "type", "Vector" ); - else if( params->HasStringList( *nIt ) ) - p->SetAttribute( "type", "StringList" ); - else if( params->HasBoolList( *nIt ) ) - p->SetAttribute( "type", "BoolList" ); - else if( params->HasIntList( *nIt ) ) - p->SetAttribute( "type", "IntList" ); - else if( params->HasUintList( *nIt ) ) - p->SetAttribute( "type", "UintList" ); - else if( params->HasRealList( *nIt ) ) - p->SetAttribute( "type", "RealList" ); - else if( params->HasIndexList( *nIt ) ) - p->SetAttribute( "type", "IndexList" ); - else if( params->HasPointList( *nIt ) ) - p->SetAttribute( "type", "PointList" ); - else if( params->HasVectorList( *nIt ) ) - p->SetAttribute( "type", "VectorList" ); - else if( params->HasChoices( *nIt ) ) - p->SetAttribute( "type", "Choices" ); - p->SetAttribute( - "value", params->GetString( *nIt, false ).c_str( ) - ); - e->LinkEndChild( p ); + params->ToXML( e ); - } // rof root->LinkEndChild( e ); } else if( data != NULL ) @@ -271,6 +161,29 @@ SaveWorkspace( const std::string& fname ) const } // rof + // Save exposed ports + auto eipIt = this->m_ExposedInputPorts.begin( ); + for( ; eipIt != this->m_ExposedInputPorts.end( ); ++eipIt ) + { + TiXmlElement* port = new TiXmlElement( "exposed_input_port" ); + port->SetAttribute( "port_name", eipIt->first.c_str( ) ); + port->SetAttribute( "filter", eipIt->second.first.c_str( ) ); + port->SetAttribute( "filter_port_name", eipIt->second.second.c_str( ) ); + root->LinkEndChild( port ); + + } // rof + + auto eopIt = this->m_ExposedOutputPorts.begin( ); + for( ; eopIt != this->m_ExposedOutputPorts.end( ); ++eopIt ) + { + TiXmlElement* port = new TiXmlElement( "exposed_output_port" ); + port->SetAttribute( "port_name", eopIt->first.c_str( ) ); + port->SetAttribute( "filter", eopIt->second.first.c_str( ) ); + port->SetAttribute( "filter_port_name", eopIt->second.second.c_str( ) ); + root->LinkEndChild( port ); + + } // rof + // Physical write and return doc->LinkEndChild( root ); doc->SaveFile( fname.c_str( ) );