#include <cpPlugins/Interface/Plugins.h>
-
-#include <stdexcept>
-
-#include <cpPlugins/Interface/Image.h>
-#include <cpPlugins/Interface/Mesh.h>
-
-#ifdef cpPlugins_Interface_QT4
-
-#include <QApplication>
-#include <QFileDialog>
-#include <QMessageBox>
-#include <QWidget>
-
-#ifdef _WIN32
-# define PLUGIN_PREFIX ""
-# define PLUGIN_EXT "dll"
-# define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
-#else // Linux
-# define PLUGIN_PREFIX "lib"
-# define PLUGIN_EXT "so"
-# define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
-#endif // _WIN32
-
-#endif // cpPlugins_Interface_QT4
+#include <cpPlugins/OS/DLLManager.h>
+#include <cpPlugins/OS/DirContents.h>
+#include <cpPlugins/Utility.h>
// -------------------------------------------------------------------------
-cpPlugins::Interface::Plugins::
-Plugins( )
- : m_Widget( NULL ),
- m_Application( NULL ),
- m_LastLoadedPlugin( "" ),
- m_ActiveFilter( NULL )
-{
-}
+cpPlugins::Interface::Plugins::Pointer
+cpPlugins::Interface::Plugins::m_Singleton = NULL;
// -------------------------------------------------------------------------
cpPlugins::Interface::Plugins::
-~Plugins( )
-{
-}
-
-// -------------------------------------------------------------------------
-QWidget* cpPlugins::Interface::Plugins::
-GetWidget( )
-{
- return( this->m_Widget );
-}
-
-// -------------------------------------------------------------------------
-const QWidget* cpPlugins::Interface::Plugins::
-GetWidget( ) const
-{
- return( this->m_Widget );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-SetWidget( QWidget* widget )
-{
- this->m_Widget = widget;
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-BlockWidget( )
-{
-#ifdef cpPlugins_Interface_QT4
- if( this->m_Widget != NULL )
- {
- QApplication::setOverrideCursor( Qt::WaitCursor );
- this->m_Widget->setEnabled( false );
-
- } // fi
-#endif // cpPlugins_Interface_QT4
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-UnblockWidget( )
-{
-#ifdef cpPlugins_Interface_QT4
- if( this->m_Widget != NULL )
- {
- QApplication::restoreOverrideCursor( );
- this->m_Widget->setEnabled( true );
-
- } // fi
-#endif // cpPlugins_Interface_QT4
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-DialogLoadPlugins( )
-{
-#ifdef cpPlugins_Interface_QT4
- if( this->m_Widget != NULL )
- {
- QFileDialog dialog( this->m_Widget );
- dialog.setFileMode( QFileDialog::ExistingFile );
- dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) );
- dialog.setNameFilter( QFileDialog::tr( PLUGIN_REGEX ) );
- dialog.setDefaultSuffix( QFileDialog::tr( PLUGIN_EXT ) );
- if( !( dialog.exec( ) ) )
- return;
-
- std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
- if( !( this->LoadPlugins( fname ) ) )
- QMessageBox::critical(
- this->m_Widget,
- QMessageBox::tr( "Ignoring plugin" ),
- QMessageBox::tr( fname.c_str( ) )
- );
-
- } // fi
-#endif // cpPlugins_Interface_QT4
-}
-
-// -------------------------------------------------------------------------
-cpPlugins::Interface::
-BaseApplication* cpPlugins::Interface::Plugins::
-GetApplication( )
+Pointer cpPlugins::Interface::Plugins::
+New( )
{
- return( this->m_Application );
-}
-
-// -------------------------------------------------------------------------
-const cpPlugins::Interface::
-BaseApplication* cpPlugins::Interface::Plugins::
-GetApplication( ) const
-{
- return( this->m_Application );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-SetApplication( BaseApplication* a )
-{
- this->m_Application = a;
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-LoadPluginsPath( const std::string& path, bool r )
-{
- this->BlockWidget( );
-
- // Load all plugins from given folder
- std::list< std::string > files =
- this->m_Interface.LoadFromFolder( path, r );
-
- // Update a simple track
- bool ret = false;
- if( files.size( ) > 0 )
- {
- for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt )
- {
- this->m_LoadedPlugins.insert( *fIt );
- this->m_LastLoadedPlugin = *fIt;
- ret = true;
-
- } // rof
- this->_UpdateLoadedPluginsInformation( );
-
- } // fi
-
- this->UnblockWidget( );
- return( ret );
+ if( Self::m_Singleton.IsNull( ) )
+ Self::m_Singleton = new Self( );
+ return( Self::m_Singleton );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-LoadPlugins( const std::string& fname )
+itk::LightObject::Pointer cpPlugins::Interface::Plugins::
+CreateAnother( ) const
{
- this->BlockWidget( );
-
- // Is it already loaded?
- bool ret = true;
- if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) )
- {
- // Was it succesfully loaded?
- ret = this->m_Interface.Load( fname );
-
- // Update a simple track
- if( ret )
- {
- this->m_LoadedPlugins.insert( fname );
- this->m_LastLoadedPlugin = fname;
- this->_UpdateLoadedPluginsInformation( );
-
- } // fi
-
- } // fi
-
- this->UnblockWidget( );
- return( ret );
+ itk::LightObject::Pointer smartPtr;
+ smartPtr = Self::m_Singleton;
+ return( smartPtr );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-LoadPluginsConfigurationFile( const std::string& fname )
+cpPlugins::Interface::Plugins::
+Pointer cpPlugins::Interface::Plugins::
+Clone( ) const
{
- // Load file into a char buffer
- std::ifstream in(
- fname.c_str( ), std::ios::in | std::ios::binary | std::ios::ate
- );
- if( !in.is_open( ) )
- return( false );
-
- std::streampos size = in.tellg( );
- char* buffer = new char[ size ];
- in.seekg( 0, std::ios::beg );
- in.read( buffer, size );
- in.close( );
-
- // Read stream
- std::stringstream in_stream( buffer );
- char line[ 4096 ];
- while( in_stream )
- {
- in_stream.getline( line, 4096 );
- this->LoadPlugins( line );
-
- } // elihw
- delete buffer;
-
- return( true );
+ return( Self::m_Singleton );
}
// -------------------------------------------------------------------------
const cpPlugins::Interface::Plugins::
-TStringContainer& cpPlugins::Interface::Plugins::
-GetLoadedPlugins( ) const
+TFilters& cpPlugins::Interface::Plugins::
+GetFilters( ) const
{
- return( this->m_LoadedPlugins );
+ return( this->m_Filters );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
-GetLoadedCategories( TStringContainer& categories ) const
+LoadPluginsFile( const std::string& libname )
{
- categories.clear( );
- auto fIt = this->m_LoadedFilters.begin( );
- for( ; fIt != this->m_LoadedFilters.end( ); ++fIt )
- categories.insert( fIt->first );
+ std::map< std::string, std::set< std::string > > filters;
+ cpPlugins::OS::DLLManager::GetPluginsLibraryContents( filters, libname );
+ THandlers zero( NULL, NULL );
+ for( auto i : filters )
+ for( auto j : i.second )
+ this->m_Filters[ i.first ][ j ] = TLibData( libname, zero );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
-GetLoadedFilters( TStringContainer& filters ) const
+LoadPluginsDirectory( const std::string& dir )
{
- filters.clear( );
- auto pIt = this->m_LoadedFilters.begin( );
- for( ; pIt != this->m_LoadedFilters.end( ); ++pIt )
- for( auto fIt = pIt->second.begin( ); fIt != pIt->second.end( ); ++fIt )
- filters.insert( *fIt );
-}
+ // Create a globbing pattern
+ std::stringstream glob;
+ glob << cpPlugins_LIB_PREFIX << "*" << cpPlugins_LIB_EXT;
-// -------------------------------------------------------------------------
-const cpPlugins::Interface::Plugins::
-TStringContainer& cpPlugins::Interface::Plugins::
-GetLoadedFilters( const std::string& category ) const
-{
- static const TStringContainer EMPTY;
- auto pIt = this->m_LoadedFilters.find( category );
- if( pIt != this->m_LoadedFilters.end( ) )
- return( pIt->second );
- else
- return( EMPTY );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-AddInteractor( vtkRenderWindowInteractor* interactor )
-{
- this->m_Interactors.insert( interactor );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-RemoveInteractor( vtkRenderWindowInteractor* interactor )
-{
- this->m_Interactors.erase( interactor );
+ // Get possible shared libraries
+ std::set< std::string > files =
+ cpPlugins::OS::LoadDirContents( dir, false, glob.str( ) );
+ this->m_PluginsPaths.insert( dir );
+ for( auto f : files )
+ try { this->LoadPluginsFile( f ); } catch( ... ) { }
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
-ClearInteractors( )
-{
- this->m_Interactors.clear( );
-}
-
-// -------------------------------------------------------------------------
-#define cpPlugins_Plugins_HasMacro( F ) \
- bool cpPlugins::Interface::Plugins:: \
- Has##F( ) const \
- { \
- return( this->m_IOFilters.find( #F ) != this->m_IOFilters.end( ) ); \
- }
-
-cpPlugins_Plugins_HasMacro( ImageReader );
-cpPlugins_Plugins_HasMacro( DicomSeriesReader );
-cpPlugins_Plugins_HasMacro( MeshReader );
-cpPlugins_Plugins_HasMacro( ImageWriter );
-cpPlugins_Plugins_HasMacro( MeshWriter );
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::Plugins::
-ReadImage( const std::string& fname, const std::string& parent )
-{
- std::vector< std::string > fnames( 1, fname );
- return( this->ReadImage( fnames, parent ) );
-}
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::Plugins::
-ReadImage(
- const std::vector< std::string >& fnames, const std::string& parent
- )
-{
- // Load source
- this->_ActivateIOFilter( "ImageReader" );
-
- // Configure reader
- TParameters* params = this->GetActiveFilterParameters( );
- params->ClearStringList( "FileNames" );
- for( auto nIt = fnames.begin( ); nIt != fnames.end( ); ++nIt )
- params->AddToStringList( "FileNames", *nIt );
-
- // Execute filter
- return( this->_ReadData( parent ) );
-}
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::Plugins::
-ReadImage( const std::string& parent )
-{
- // Load source
- this->_ActivateIOFilter( "ImageReader" );
-
- // Try to configure source
- if( this->ConfigureActiveFilter( ) == TProcessObject::DialogResult_Cancel )
- {
- this->DeactivateFilter( );
- return( "" );
-
- } // fi
-
- // Execute filter
- return( this->_ReadData( parent ) );
-}
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::Plugins::
-ReadDicomSeries( const std::string& parent )
-{
- // Load source
- this->_ActivateIOFilter( "DicomSeriesReader" );
-
- // Try to configure source
- if( this->ConfigureActiveFilter( ) == TProcessObject::DialogResult_Cancel )
- {
- this->DeactivateFilter( );
- return( "" );
-
- } // fi
-
- // Execute filter
- return( this->_ReadData( parent ) );
-}
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::Plugins::
-ReadMesh( const std::string& fname, const std::string& parent )
-{
- // Load source
- this->_ActivateIOFilter( "MeshReader" );
-
- // Configure reader
- TParameters* params = this->GetActiveFilterParameters( );
- params->SetString( "FileName", fname );
-
- // Execute filter
- return( this->_ReadData( parent ) );
-}
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::Plugins::
-ReadMesh( const std::string& parent )
-{
- // Load source
- this->_ActivateIOFilter( "MeshReader" );
-
- // Try to configure source
- if( this->ConfigureActiveFilter( ) == TProcessObject::DialogResult_Cancel )
- {
- this->DeactivateFilter( );
- return( "" );
-
- } // fi
-
- // Execute filter
- return( this->_ReadData( parent ) );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-WriteDataObject( const std::string& fname, const std::string& name )
+GuessPlugins( )
{
- typedef cpPlugins::Interface::Image _TImage;
- typedef cpPlugins::Interface::Mesh _TMesh;
+ // Create a globbing pattern
+ std::stringstream glob;
+ glob << cpPlugins_LIB_PREFIX << "*" << cpPlugins_LIB_EXT;
- // Activate sink
- TDataObject* obj = this->GetData< TDataObject >( name );
- if( dynamic_cast< cpPlugins::Interface::Image* >( obj ) != NULL )
- this->_ActivateIOFilter( "ImageWriter" );
- else if( dynamic_cast< cpPlugins::Interface::Mesh* >( obj ) != NULL )
- this->_ActivateIOFilter( "MeshWriter" );
- else
+ // Update paths and get possible shared libraries
+ this->_ReadPluginsPathsVariable( );
+ for( auto dir : this->m_PluginsPaths )
{
- this->DeactivateFilter( );
- return( false );
-
- } // fi
-
- // Configure writer
- TParameters* params = this->GetActiveFilterParameters( );
- params->SetString( "FileName", fname );
-
- // Execute filter
- return( this->_WriteData( name ) );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-WriteDataObject( const std::string& name )
-{
- typedef cpPlugins::Interface::Image _TImage;
- typedef cpPlugins::Interface::Mesh _TMesh;
-
- // Activate sink
- TDataObject* obj = this->GetData< TDataObject >( name );
- if( dynamic_cast< cpPlugins::Interface::Image* >( obj ) != NULL )
- this->_ActivateIOFilter( "ImageWriter" );
- else if( dynamic_cast< cpPlugins::Interface::Mesh* >( obj ) != NULL )
- this->_ActivateIOFilter( "MeshWriter" );
- else
- {
- this->DeactivateFilter( );
- return( false );
-
- } // fi
-
- // Try to configure source
- if( this->ConfigureActiveFilter( ) == TProcessObject::DialogResult_Cancel )
- {
- this->DeactivateFilter( );
- return( false );
-
- } // fi
-
- // Execute filter
- return( this->_WriteData( name ) );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-ClearDataObjects( )
-{
- this->m_DataObjects.clear( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-DeleteDataObject( const std::string& name )
-{
- // Find and delete object
- auto oIt = this->m_DataObjects.find( name );
- if( oIt == this->m_DataObjects.end( ) )
- return;
- this->m_DataObjects.erase( oIt );
-
- // Delete children
- TStringContainer children;
- this->GetChildren( children, name );
- auto cIt = children.begin( );
- for( ; cIt != children.end( ); ++cIt )
- this->DeleteDataObject( *cIt );
-}
+ std::set< std::string > files =
+ cpPlugins::OS::LoadDirContents( dir, false, glob.str( ) );
+ for( auto f : files )
+ try { this->LoadPluginsFile( f ); } catch( ... ) { }
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-GetDataObjects( TStringContainer& names )
-{
- names.clear( );
- auto oIt = this->m_DataObjects.begin( );
- for( ; oIt != this->m_DataObjects.end( ); ++oIt )
- names.insert( oIt->first );
-}
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::Plugins::
-GetParent( const std::string& name ) const
-{
- // Find and delete object
- auto oIt = this->m_DataObjects.find( name );
- if( oIt != this->m_DataObjects.end( ) )
- return( oIt->second.first );
- else
- return( "" );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-GetChildren( TStringContainer& names, const std::string& name ) const
-{
- names.clear( );
- auto oIt = this->m_DataObjects.begin( );
- for( ; oIt != this->m_DataObjects.end( ); ++oIt )
- if( oIt->second.first == name )
- names.insert( oIt->first );
+ } // rof
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
-GetRoots( TStringContainer& names ) const
+GuessEnvironment( const std::string& dir )
{
- this->GetChildren( names, "" );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-ActivateFilter( const std::string& name )
-{
- this->m_ActiveFilter = this->m_Interface.CreateObject( name );
- if( this->m_ActiveFilter.IsNotNull( ) )
+ std::stringstream fname;
+ fname << dir << cpPlugins_PATH_SEPARATOR << cpPlugins_PATHS;
+ std::string buffer;
+ if( cpPlugins::Read( buffer, fname.str( ) ) )
{
- this->m_ActiveFilter->SetPlugins( this );
- auto iIt = this->m_Interactors.begin( );
- for( ; iIt != this->m_Interactors.end( ); ++iIt )
- this->m_ActiveFilter->AddInteractor( *iIt );
- return( true );
- }
- else
- return( false );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-DeactivateFilter( )
-{
- this->m_ActiveFilter = NULL;
-}
+ std::istringstream input( buffer );
+ for( std::string line; std::getline( input, line ); )
+ this->m_PluginsPaths.insert( cpPlugins::CanonicalPath( line ) );
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-HasActiveFilter( ) const
-{
- return( this->m_ActiveFilter.IsNotNull( ) );
+ } // fi
}
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Plugins::
-IsActiveFilterInteractive( ) const
-{
- if( this->m_ActiveFilter.IsNotNull( ) )
- return( this->m_ActiveFilter->GetInteractive( ) );
- else
- return( false );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-GetActiveFilterInputsNames( TStringContainer& names ) const
+SaveEnvironment( const std::string& dir )
{
- if( this->m_ActiveFilter.IsNotNull( ) )
- this->m_ActiveFilter->GetInputsNames( names );
+ std::stringstream buffer;
+ for( auto p : this->m_PluginsPaths )
+ buffer << p << std::endl;
+ std::stringstream fname;
+ fname << dir << cpPlugins_PATH_SEPARATOR << cpPlugins_PATHS;
+ return( cpPlugins::Write( buffer.str( ), fname.str( ) ) );
}
// -------------------------------------------------------------------------
-void cpPlugins::Interface::Plugins::
-GetActiveFilterOutputsNames( TStringContainer& names ) const
-{
- if( this->m_ActiveFilter.IsNotNull( ) )
- this->m_ActiveFilter->GetOutputsNames( names );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-ConnectInputInActiveFilter(
- const std::string& object_name, const std::string& input_name
- )
-{
- if( this->m_ActiveFilter.IsNotNull( ) )
- {
- TDataObject* dobj = this->GetData< TDataObject >( object_name );
- if( dobj != NULL )
+cpPlugins::BaseObjects::ProcessObject::Pointer
+cpPlugins::Interface::Plugins::
+CreateFilter( const std::string& category, const std::string& name )
+{
+ std::cout << "1" << std::endl;
+ typedef void* ( *_TCreator )( );
+ std::cout << "2" << std::endl;
+ typedef cpPlugins::BaseObjects::ProcessObject::Pointer _TPtr;
+ std::cout << "3" << std::endl;
+ _TPtr o = NULL;
+ std::cout << "4" << std::endl;
+ auto cat = this->m_Filters.find( category );
+ std::cout << "5" << std::endl;
+ if( cat != this->m_Filters.end( ) )
+ {
+ std::cout << "6" << std::endl;
+ auto nam = cat->second.find( name );
+ std::cout << "7" << std::endl;
+ if( nam != cat->second.end( ) )
{
- this->m_ActiveFilter->SetInput( input_name, dobj );
- return( true );
+ std::cout << "8" << std::endl;
+ void* l_hnd = nam->second.second.first;
+ std::cout << "9" << std::endl;
+ void* f_hnd = nam->second.second.second;
+ std::cout << "10" << std::endl;
+ if( l_hnd == NULL )
+ {
+ std::cout << "11" << std::endl;
+ l_hnd = cpPlugins::OS::DLLManager::LoadPlugins( nam->second.first );
+ std::cout << "12" << std::endl;
+ nam->second.second.first = l_hnd;
+ std::cout << "13" << std::endl;
+
+ } // fi
+ if( f_hnd == NULL )
+ {
+ std::cout << "14" << std::endl;
+ f_hnd =
+ cpPlugins::OS::DLLManager::LoadCreator( l_hnd, category, name );
+ std::cout << "15" << std::endl;
+ nam->second.second.second = f_hnd;
+ std::cout << "16" << std::endl;
+
+ } // fi
+ std::cout << "17" << std::endl;
+ _TCreator creator = reinterpret_cast< _TCreator >( f_hnd );
+ std::cout << "18" << std::endl;
+ if( creator != NULL )
+ {
+ std::cout << "19 " << creator << " " << f_hnd << std::endl;
+ void* a = creator( );
+ std::cout << "20" << std::endl;
+ std::cout << "20 " << creator << " " << a << std::endl;
+ std::cout << "21" << std::endl;
+ o = reinterpret_cast< _TPtr* >( a )->GetPointer( );
+ std::cout << "22" << std::endl;
+ o->SetName( name );
+ std::cout << "23" << std::endl;
+ o->SetPluginName( nam->second.first );
+ std::cout << "24" << std::endl;
+
+ } // fi
} // fi
} // fi
- return( false );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-SetOutputNameInActiveFilter(
- const std::string& new_object_name, const std::string& output_name
- )
-{
- if( this->m_ActiveFilter.IsNotNull( ) )
- return(
- this->m_ActiveFilter->SetOutputObjectName(
- new_object_name, output_name
- )
+ std::cout << "25" << std::endl;
+ if( o.IsNull( ) )
+ throw std::runtime_error(
+ std::string( "Could not create a valid ProcessObject of type \"" ) +
+ category + std::string( ":" ) +
+ name + std::string( "\"" )
);
- else
- return( false );
+ std::cout << "26" << std::endl;
+ return( o );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetActiveFilterParameters( )
-{
- if( this->m_ActiveFilter.IsNotNull( ) )
- return( this->m_ActiveFilter->GetParameters( ) );
- else
- return( NULL );
-}
-
-// -------------------------------------------------------------------------
-const cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetActiveFilterParameters( ) const
+Plugins( )
+ : Superclass( )
{
- if( this->m_ActiveFilter.IsNotNull( ) )
- return( this->m_ActiveFilter->GetParameters( ) );
- else
- return( NULL );
+ cpPlugins::OS::DLLManager::TeaseLoadedLibraries( );
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Plugins::
-TProcessObject::DialogResult cpPlugins::Interface::Plugins::
-ConfigureActiveFilter( )
-{
- if( this->m_ActiveFilter.IsNotNull( ) )
- return( this->m_ActiveFilter->ExecConfigurationDialog( this->m_Widget ) );
- else
- return( TProcessObject::DialogResult_Cancel );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-UpdateActiveFilter( TStringContainer& outputs, const std::string& parent )
+~Plugins( )
{
- if( this->m_ActiveFilter.IsNull( ) )
- return( false );
-
- // Execute filter
- this->BlockWidget( );
- std::string err = this->m_ActiveFilter->Update( );
- this->UnblockWidget( );
-
- // Associate outputs
- outputs.clear( );
- if( err == "" )
- {
- std::set< std::string > names;
- this->m_ActiveFilter->GetOutputsNames( names );
- for( auto oIt = names.begin( ); oIt != names.end( ); ++oIt )
- {
- TDataObject* dobj =
- this->m_ActiveFilter->GetOutput< TDataObject >( *oIt );
- this->_InsertNewData( dobj, parent );
- outputs.insert( dobj->GetName( ) );
-
- } // rof
- this->m_ActiveFilter->DisconnectOutputs( );
- return( true );
- }
- else
- {
-#ifdef cpPlugins_Interface_QT4
- if( this->m_Widget != NULL )
- QMessageBox::critical(
- this->m_Widget,
- QMessageBox::tr( "Error reading image." ),
- QMessageBox::tr( err.c_str( ) )
- );
- else
- throw std::runtime_error(
- std::string( "Error reading image: " ) + err
- );
-#else // cpPlugins_Interface_QT4
- throw std::runtime_error(
- std::string( "Error reading image: " ) + err
- );
-#endif // cpPlugins_Interface_QT4
- return( false );
-
- } // fi
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
-_UpdateLoadedPluginsInformation( )
+PrintSelf( std::ostream& os, itk::Indent indent ) const
{
- this->m_LoadedFilters.clear( );
- const TInterface::TClasses& cls = this->m_Interface.GetClasses( );
- for( auto i = cls.begin( ); i != cls.end( ); ++i )
+ for( auto i : this->m_Filters )
{
- TProcessObject::Pointer o = this->m_Interface.CreateObject( i->first );
- std::string name = o->GetClassName( );
- std::string category = o->GetClassCategory( );
-
- if(
- category == "ImageReader" ||
- category == "ImageWriter" ||
- category == "MeshReader" ||
- category == "MeshWriter" ||
- category == "DicomSeriesReader"
- )
- this->m_IOFilters[ category ] = o;
- else
- this->m_LoadedFilters[ category ].insert( name );
+ os << indent << "+ " << i.first << std::endl;
+ for( auto j : i.second )
+ os << indent << "|----> " << j.first << std::endl;
} // rof
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-_ActivateIOFilter( const std::string& filter )
-{
- // Activate reader
- auto fIt = this->m_IOFilters.find( filter );
- if( fIt != this->m_IOFilters.end( ) )
- {
- this->m_ActiveFilter = fIt->second;
- return( true );
- }
- else
- return( false );
-}
-
-// -------------------------------------------------------------------------
-std::string cpPlugins::Interface::Plugins::
-_ReadData( const std::string& parent )
-{
- if( !( this->HasActiveFilter( ) ) )
- return( "" );
-
- TStringContainer outputs;
- if( this->UpdateActiveFilter( outputs, parent ) )
- return( *( outputs.begin( ) ) );
- else
- return( "" );
-}
-
-// ------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-_WriteData( const std::string& name )
-{
- if( !( this->HasActiveFilter( ) ) )
- return( false );
-
- TStringContainer inputs;
- this->GetActiveFilterInputsNames( inputs );
- bool r = true;
- for( auto iIt = inputs.begin( ); iIt != inputs.end( ); ++iIt )
- r &= this->ConnectInputInActiveFilter( name, *iIt );
-
- if( r )
- {
- TStringContainer outputs;
- return( this->UpdateActiveFilter( outputs, "" ) );
- }
- else
- return( false );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-_InsertNewData( TDataObject* dobj, const std::string& parent )
+void cpPlugins::Interface::Plugins::
+_ReadPluginsPathsVariable( )
{
- if( parent != "" )
- {
- auto oIt = this->m_DataObjects.find( parent );
- if( oIt == this->m_DataObjects.end( ) )
- return( false );
-
- } // fi
- this->m_DataObjects[ dobj->GetName( ) ] = _TTreeNode( parent, dobj );
- return( true );
+#ifdef cpPlugins_OS_Windows
+ char* p;
+ size_t size;
+ _dupenv_s( &p, &size, cpPlugins_PATHS );
+#else // cpPlugins_OS_Windows
+ char* p = std::getenv( cpPlugins_PATHS );
+#endif // cpPlugins_OS_Windows
+ std::stringstream str;
+ if( p != NULL )
+ str << p << cpPlugins_ENV_SEPARATOR;
+ str << ".";
+ std::vector< std::string > tokens;
+ cpPlugins::Tokenize( tokens, str.str( ), cpPlugins_ENV_SEPARATOR );
+ for( auto dir : tokens )
+ this->m_PluginsPaths.insert( cpPlugins::CanonicalPath( dir ) );
}
// eof - $RCSfile$