]> Creatis software - cpPlugins.git/blobdiff - appli/plugins/ExecutePipeline.cxx
...
[cpPlugins.git] / appli / plugins / ExecutePipeline.cxx
diff --git a/appli/plugins/ExecutePipeline.cxx b/appli/plugins/ExecutePipeline.cxx
new file mode 100644 (file)
index 0000000..128583d
--- /dev/null
@@ -0,0 +1,84 @@
+#include <iostream>
+#include <cpPlugins/Utility.h>
+#include <cpPlugins/Interface/Plugins.h>
+#include <cpPlugins/Interface/Workspace.h>
+
+int main( int argc, char* argv[] )
+{
+  // Manage inputs
+  if( argc < 2 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " workspace [parameters]" << std::endl;
+    return( 1 );
+
+  } // fi
+
+  // Create interface and load library
+  cpPlugins::Interface::Plugins::Pointer interface =
+    cpPlugins::Interface::Plugins::New( );
+  try
+  {
+    interface->GuessPlugins( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+
+  // Workspace
+  cpPlugins::Interface::Workspace::Pointer workspace =
+    cpPlugins::Interface::Workspace::New( );
+  try
+  {
+    workspace->Load( argv[ 1 ] );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr
+      << "Error loading workspace \"" << argv[ 1 ]
+      << "\": " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+    
+  // Read parameters
+  for( int i = 2; i < argc; ++i )
+  {
+    std::vector< std::string > tokens;
+    cpPlugins::Tokenize( tokens, argv[ i ], "@=" );
+    if( tokens.size( ) == 3 )
+    {
+      auto filter = workspace->GetFilter( tokens[ 1 ] );
+      if( filter != NULL )
+      {
+        auto params = filter->GetParameters( );
+        params->SetString( tokens[ 0 ], tokens[ 2 ], true );
+
+      } // fi
+
+    } // fi
+
+  } // rof
+
+  // Execute filter
+  workspace->PrintExecutionOn( );
+  try
+  {
+    workspace->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << std::endl << "********************************" << std::endl;
+    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    std::cerr << "********************************" << std::endl;
+    return( 1 );
+
+  } // yrt
+  return( 0 );
+}
+
+// eof - $RCSfile$