]> Creatis software - cpPlugins.git/blobdiff - lib/cpPipelineEditor/BaseQtMainWindow.cxx
...
[cpPlugins.git] / lib / cpPipelineEditor / BaseQtMainWindow.cxx
index 8d4a98bf715526b61d57255df23ea8fb5ba2198f..1cc22c3ebaf000fffcf8767ec5357fd67875519f 100644 (file)
@@ -43,26 +43,25 @@ BaseQtMainWindow(
   : Superclass( parent ),
     m_Application( app ),
     m_PluginsPath( "." ),
+    m_Interface( NULL ),
+    m_Workspace( NULL ),
     m_TreeWidget( NULL ),
     m_Editor( NULL ),
     m_MPR( NULL )
 {
-  this->m_Interface.GuessAccesiblePlugins( );
-
-  // Try to load plugins from executable dir
+  this->m_ApplicationPath = ".";
   QFileInfo info( argv[ 0 ] );
   if( info.exists( ) )
-    this->_LoadPluginsFromPath( info.canonicalPath( ).toStdString( ) );
-
-  // Prepare workspace
-  this->m_Workspace.SetInterface( &( this->m_Interface ) );
+    this->m_ApplicationPath = info.canonicalPath( ).toStdString( );
 }
 
 // -------------------------------------------------------------------------
 cpPipelineEditor::BaseQtMainWindow::
 ~BaseQtMainWindow( )
 {
-  this->m_Interface.UnloadAll( );
+  if( this->m_Workspace != NULL )
+    delete this->m_Workspace;
+  delete this->m_Interface;
 }
 
 // -------------------------------------------------------------------------
@@ -73,15 +72,56 @@ _Configure(
   cpPipelineEditor::Editor* editor
   )
 {
+  if( this->m_Interface != NULL )
+  {
+    delete this->m_Interface;
+    this->m_Interface = NULL;
+
+  } // fi
+
+  try
+  {
+    this->m_Interface = new cpPlugins::Interface( );
+    this->m_Interface->GuessAccesiblePlugins( );
+  }
+  catch( std::exception& err )
+  {
+    if( this->m_Interface != NULL )
+      delete this->m_Interface;
+    this->m_Interface = NULL;
+    QMessageBox::critical(
+      this,
+      "Error creating plugins interface",
+      err.what( )
+      );
+    std::exit( 1 );
+
+  } // yrt
+
+  // Try to load plugins from executable dir
+  this->_LoadPluginsFromPath( this->m_ApplicationPath );
+
+  // Finish configuration
   this->m_TreeWidget = tree;
   if( this->m_TreeWidget != NULL )
     this->_UpdateLoadedPlugins( );
   this->m_Editor = editor;
-  if( this->m_Editor != NULL )
-    this->m_Editor->setWorkspace( &( this->m_Workspace ) );
-  if( mpr != NULL )
-    this->m_Workspace.SetMPRViewer( mpr );
   this->m_MPR = mpr;
+  this->_CreateWorkspace( );
+}
+
+// -------------------------------------------------------------------------
+void cpPipelineEditor::BaseQtMainWindow::
+_CreateWorkspace( )
+{
+  if( this->m_Workspace != NULL )
+    delete this->m_Workspace;
+  this->m_Workspace = new cpPlugins::Workspace( );
+  this->m_Workspace->SetInterface( this->m_Interface );
+  if( this->m_Editor != NULL )
+    this->m_Editor->setWorkspace( this->m_Workspace );
+  if( this->m_MPR != NULL )
+    this->m_Workspace->SetMPRViewer( this->m_MPR );
 }
 
 // -------------------------------------------------------------------------
@@ -90,7 +130,7 @@ _LoadPlugins( const std::string& filename )
 {
   try
   {
-    this->m_Interface.LoadPluginFile( filename );
+    this->m_Interface->LoadPluginFile( filename );
     this->_UpdateLoadedPlugins( );
   }
   catch( std::exception& err )
@@ -110,7 +150,7 @@ _LoadPluginsFromPath( const std::string& path )
 {
   try
   {
-    this->m_Interface.LoadPluginDir( path );
+    this->m_Interface->LoadPluginDir( path );
     this->_UpdateLoadedPlugins( );
   }
   catch( std::exception& err )
@@ -129,7 +169,7 @@ void cpPipelineEditor::BaseQtMainWindow::
 _UpdateLoadedPlugins( )
 {
   this->_Block( );
-  auto filters = this->m_Interface.GetFilters( );
+  auto filters = this->m_Interface->GetFilters( );
   if( filters.size( ) == 0 )
   {
     this->_UnBlock( );
@@ -211,7 +251,8 @@ _UnBlock( )
 void cpPipelineEditor::BaseQtMainWindow::
 _LoadWorkspace( const std::string& filename )
 {
-  std::string err = this->m_Workspace.LoadWorkspace( filename );
+  this->_CreateWorkspace( );
+  std::string err = this->m_Workspace->LoadWorkspace( filename );
   if( err != "" )
   {
     QMessageBox::critical(
@@ -223,7 +264,7 @@ _LoadWorkspace( const std::string& filename )
   else
   {
     if( this->m_Editor != NULL )
-      this->m_Editor->setWorkspace( &( this->m_Workspace ) );
+      this->m_Editor->setWorkspace( this->m_Workspace );
 
   } // fi
 }
@@ -232,22 +273,27 @@ _LoadWorkspace( const std::string& filename )
 void cpPipelineEditor::BaseQtMainWindow::
 _SaveWorkspace( const std::string& filename )
 {
-  std::string err = this->m_Workspace.SaveWorkspace( filename );
-  if( err != "" )
-    QMessageBox::critical(
-      this,
-      QMessageBox::tr( "Error saving workspace" ),
-      QMessageBox::tr( err.c_str( ) )
-      );
+  if( this->m_Workspace != NULL )
+  {
+    std::string err = this->m_Workspace->SaveWorkspace( filename );
+    if( err != "" )
+      QMessageBox::critical(
+        this,
+        QMessageBox::tr( "Error saving workspace" ),
+        QMessageBox::tr( err.c_str( ) )
+        );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpPipelineEditor::BaseQtMainWindow::
 _ShowData( const std::string& filter_name, const std::string& output_name )
 {
-  if( this->m_MPR == NULL )
+  if( this->m_MPR == NULL || this->m_Workspace == NULL )
     return;
-  auto output = this->m_Workspace.GetOutput( filter_name, output_name );
+
+  auto output = this->m_Workspace->GetOutput( filter_name, output_name );
   if( output != NULL )
   {
     this->_Block( );
@@ -282,6 +328,9 @@ _ShowData( const std::string& filter_name, const std::string& output_name )
 void cpPipelineEditor::BaseQtMainWindow::
 _HideData( const std::string& filter, const std::string& output )
 {
+  std::cout << "BaseQtMainWindow::HideData" << std::endl;
+  /* TODO
+   */
 }
 
 // -------------------------------------------------------------------------
@@ -290,9 +339,10 @@ _DataProperties(
   const std::string& filter_name, const std::string& output_name
   )
 {
-  if( this->m_MPR == NULL )
+  if( this->m_MPR == NULL || this->m_Workspace == NULL )
     return;
-  auto output = this->m_Workspace.GetOutput( filter_name, output_name );
+
+  auto output = this->m_Workspace->GetOutput( filter_name, output_name );
   if( output != NULL )
   {
     this->_Block( );
@@ -321,6 +371,9 @@ _DataProperties(
 void cpPipelineEditor::BaseQtMainWindow::
 _BackgroundProperties( unsigned int i )
 {
+  if( this->m_MPR == NULL )
+    return;
+
   QColor color =
     QColorDialog::getColor(
       QColor( 0, 0, 0 ),
@@ -371,15 +424,13 @@ _InteractiveLoadPlugins( )
   dlg.setFileMode( QFileDialog::ExistingFiles );
   dlg.setDirectory( this->m_PluginsPath.c_str( ) );
 
-  std::stringstream name_filter;
+  std::stringstream filter;
   std::string suffix = std::string( cpPlugins_LIB_EXT );
-  name_filter
-    << "Plugins file (*." << cpPlugins_LIB_EXT << ");;All files (*)";
-  dlg.setNameFilter( name_filter.str( ).c_str( ) );
+  filter << "Plugins file (*." << cpPlugins_LIB_EXT << ");;All files (*)";
+  dlg.setNameFilter( filter.str( ).c_str( ) );
   dlg.setDefaultSuffix( suffix.c_str( ) );
   if( !( dlg.exec( ) ) )
     return;
-
   QStringList names = dlg.selectedFiles( );
   for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt )
     this->_LoadPlugins( qIt->toStdString( ) );
@@ -389,12 +440,12 @@ _InteractiveLoadPlugins( )
 void cpPipelineEditor::BaseQtMainWindow::
 _InteractiveLoadPluginsFromPath( )
 {
-  QFileDialog dlg( this );
-  dlg.setFileMode( QFileDialog::DirectoryOnly );
-  dlg.setDirectory( this->m_PluginsPath.c_str( ) );
-  if( !( dlg.exec( ) ) )
+  QFileDialog d( this );
+  d.setFileMode( QFileDialog::DirectoryOnly );
+  d.setDirectory( this->m_PluginsPath.c_str( ) );
+  if( !( d.exec( ) ) )
     return;
-  this->_LoadPluginsFromPath( dlg.selectedFiles( ).begin( )->toStdString( ) );
+  this->_LoadPluginsFromPath( d.selectedFiles( ).begin( )->toStdString( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -417,27 +468,34 @@ _InteractiveLoadWorkspace( )
 void cpPipelineEditor::BaseQtMainWindow::
 _InteractiveSaveWorkspace( )
 {
-  QFileDialog dlg( this );
-  dlg.setFileMode( QFileDialog::AnyFile );
-  dlg.setDirectory( "." );
-  dlg.setAcceptMode( QFileDialog::AcceptSave );
-  dlg.setNameFilter(
-    QFileDialog::tr( "Workspace file (*.wxml);;All files (*)" )
-    );
-  dlg.setDefaultSuffix( QFileDialog::tr( "wxml" ) );
-  if( !( dlg.exec( ) ) )
-    return;
-  this->_SaveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) );
+  if( this->m_Workspace != NULL )
+  {
+    QFileDialog dlg( this );
+    dlg.setFileMode( QFileDialog::AnyFile );
+    dlg.setDirectory( "." );
+    dlg.setAcceptMode( QFileDialog::AcceptSave );
+    dlg.setNameFilter(
+      QFileDialog::tr( "Workspace file (*.wxml);;All files (*)" )
+      );
+    dlg.setDefaultSuffix( QFileDialog::tr( "wxml" ) );
+    if( !( dlg.exec( ) ) )
+      return;
+    this->_SaveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpPipelineEditor::BaseQtMainWindow::
 _ExecFilter( const std::string& filter_name )
 {
+  if( this->m_Workspace == NULL )
+    return;
+
   this->_Block( );
   try
   {
-    this->m_Workspace.Execute( filter_name );
+    this->m_Workspace->Execute( filter_name );
     this->_UnBlock( );
   }
   catch( itk::ExceptionObject& err1 )