]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/Parameters.cxx
Now it's broken :-(
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.cxx
index 52b2e47d423eccc3463a89a133de20acd5982d7b..1b239725411c8b5cc87e947b3c6ce6db21db0f7f 100644 (file)
@@ -1,5 +1,6 @@
 #include <cpPlugins/Interface/Parameters.h>
 #include <cpPlugins/Interface/ProcessObject.h>
+#include <third_party/tinyxml/tinyxml.h>
 
 #include <sstream>
 
@@ -460,6 +461,122 @@ SetSelectedChoice( const TString& name, const TString& choice )
     return( false );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Parameters::
+ToXML( TiXmlElement* parent_elem ) const
+{
+  if( parent_elem == NULL )
+    return( false );
+
+  auto pIt = this->m_Parameters.begin( );
+  for( ; pIt != this->m_Parameters.end( ); ++pIt )
+  {
+    TiXmlElement* p = new TiXmlElement( "parameter" );
+    p->SetAttribute( "name", pIt->first.c_str( ) );
+    p->SetAttribute( "value", pIt->second.second.c_str( ) );
+    if( pIt->second.first == Self::String )
+      p->SetAttribute( "type", "String" );
+    else if( pIt->second.first == Self::Bool )
+      p->SetAttribute( "type", "Bool" );
+    else if( pIt->second.first == Self::Int )
+      p->SetAttribute( "type", "Int" );
+    else if( pIt->second.first == Self::Uint )
+      p->SetAttribute( "type", "Uint" );
+    else if( pIt->second.first == Self::Real )
+      p->SetAttribute( "type", "Real" );
+    else if( pIt->second.first == Self::Index )
+      p->SetAttribute( "type", "Index" );
+    else if( pIt->second.first == Self::Point )
+      p->SetAttribute( "type", "Point" );
+    else if( pIt->second.first == Self::Vector )
+      p->SetAttribute( "type", "Vector" );
+    else if( pIt->second.first == Self::StringList )
+      p->SetAttribute( "type", "StringList" );
+    else if( pIt->second.first == Self::BoolList )
+      p->SetAttribute( "type", "BoolList" );
+    else if( pIt->second.first == Self::IntList )
+      p->SetAttribute( "type", "IntList" );
+    else if( pIt->second.first == Self::UintList )
+      p->SetAttribute( "type", "UintList" );
+    else if( pIt->second.first == Self::RealList )
+      p->SetAttribute( "type", "RealList" );
+    else if( pIt->second.first == Self::IndexList )
+      p->SetAttribute( "type", "IndexList" );
+    else if( pIt->second.first == Self::PointList )
+      p->SetAttribute( "type", "PointList" );
+    else if( pIt->second.first == Self::VectorList )
+      p->SetAttribute( "type", "VectorList" );
+    else if( pIt->second.first == Self::Choices )
+      p->SetAttribute( "type", "Choices" );
+    parent_elem->LinkEndChild( p );
+
+  } // rof
+  return( true );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Parameters::
+FromXML( const TiXmlElement* filter_elem )
+{
+  this->m_Parameters.clear( );
+
+  const TiXmlElement* param = filter_elem->FirstChildElement( "parameter" );
+  bool ret = false;
+  while( param != NULL )
+  {
+    const char* param_name = param->Attribute( "name" );
+    const char* param_type = param->Attribute( "type" );
+    if( param_name != NULL && param_type != NULL )
+    {
+      TParameter value;
+      value.second = param->Attribute( "value" );
+
+      std::string param_type_str( param_type );
+      if( param_type_str == "Bool" )
+        value.first = Self::Bool;
+      else if( param_type_str == "Int" )
+        value.first = Self::Int;
+      else if( param_type_str == "Uint" )
+        value.first = Self::Uint;
+      else if( param_type_str == "Real" )
+        value.first = Self::Real;
+      else if( param_type_str == "Index" )
+        value.first = Self::Index;
+      else if( param_type_str == "Point" )
+        value.first = Self::Point;
+      else if( param_type_str == "Vector" )
+        value.first = Self::Vector;
+      else if( param_type_str == "StringList" )
+        value.first = Self::StringList;
+      else if( param_type_str == "BoolList" )
+        value.first = Self::BoolList;
+      else if( param_type_str == "IntList" )
+        value.first = Self::IntList;
+      else if( param_type_str == "UintList" )
+        value.first = Self::UintList;
+      else if( param_type_str == "RealList" )
+        value.first = Self::RealList;
+      else if( param_type_str == "IndexList" )
+        value.first = Self::IndexList;
+      else if( param_type_str == "PointList" )
+        value.first = Self::PointList;
+      else if( param_type_str == "VectorList" )
+        value.first = Self::VectorList;
+      else if( param_type_str == "Choices" )
+        value.first = Self::Choices;
+      else
+        value.first = Self::String;
+
+      this->m_Parameters[ param_name ] = value;
+
+    } // fi
+    param = param->NextSiblingElement( "parameter" );
+    ret = true;
+
+  } // elihw
+  return( ret );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Parameters::
 Parameters( )