]> Creatis software - cpPlugins.git/blobdiff - appli/bash/cpPlugins_ExecuteWorkspace.cxx
...
[cpPlugins.git] / appli / bash / cpPlugins_ExecuteWorkspace.cxx
index 4c847b14784e29bf1edbf47a6333eabd475c46e1..e5ee4cb07bb98c598ccf32388a2fd28309b3f5eb 100644 (file)
@@ -2,7 +2,8 @@
 #include <set>
 #include <string>
 #include <vector>
-#include <cpPlugins_Config.h>
+#include <cpPlugins/Interface.h>
+#include <cpPlugins/Workspace.h>
 
 int main( int argc, char* argv[] )
 {
@@ -12,21 +13,63 @@ int main( int argc, char* argv[] )
     return( 1 );
 
   } // fi
-  std::set< std::string > parameters;
-  std::set< std::string > plugins;
+  std::string ws_file = argv[ 1 ];
+
+  // Configure a plugin interface and load given workspace
+  cpPlugins::Interface interface;
+  cpPlugins::Workspace ws;
+  ws.SetInterface( &interface );
+  std::string err = ws.LoadWorkspace( ws_file );
+  if( err != "" )
+  {
+    std::cerr
+      << "Error loading workspace \"" << ws_file << "\": "
+      << err << std::endl;
+    return( 1 );
+
+  } // fi
 
   // Read arguments
-  std::string ws_file = argv[ 1 ];
-  for( unsigned int i = 2; i < argc; ++i )
+  for( unsigned int i = 2; i < argc; i += 2 )
   {
     std::vector< std::string > tokens;
-    cpPlugins::TokenizeString( tokens, argv[ i ], "=" );
-    if( tokens.size( ) < 2 )
-      continue;
-    if     ( tokens[ 0 ] == "pl" ) plugins.insert( tokens[ 1 ] );
-    else if( tokens[ 0 ] == "pa" ) parameters.insert( tokens[ 1 ] );
+    cpPlugins::TokenizeString( tokens, argv[ i ], "@" );
+    std::string filter_name = tokens[ 1 ];
+    std::string param_name  = tokens[ 0 ];
+    std::string param_value = argv[ i + 1 ];
+
+    auto filter = ws.GetFilter( filter_name );
+    if( filter != NULL )
+      filter->GetParameters( )->SetString( param_name, param_value );
+    else
+      std::cerr
+        << "Warning: filter \"" << filter_name
+        << "\" is not defined inside the loaded workspace." << std::endl;
 
   } // rof
+
+  // Execute workspace
+  ws.PrintExecutionOn( );
+  try
+  {
+    ws.Execute( );
+  }
+  catch( itk::ExceptionObject& err1 )
+  {
+    std::cerr << "Error caught: " << err1 << std::endl;
+    return( 1 );
+  }
+  catch( std::exception& err2 )
+  {
+    std::cerr << "Error caught: " << err2.what( ) << std::endl;
+    return( 1 );
+  }
+  catch( ... )
+  {
+    std::cerr << "Unknown error caught." << std::endl;
+    return( 1 );
+
+  } // yrt
   return( 0 );
 }