void PipelineEditor::QNodesEditor::\r
setWorkspace( TWorkspace* ws )\r
{\r
- if( this->m_Workspace == ws )\r
- return;\r
this->m_Workspace = ws;\r
this->m_Graph = TGraph::New( );\r
\r
return( NULL );\r
}\r
\r
-#include <iostream>\r
-\r
// -------------------------------------------------------------------------\r
void PipelineEditor::QNodesEditor::\r
_CreateBlock( TFilter* f, const QPointF& pnt )\r
// Add block\r
QNEBlock* b = new QNEBlock( 0, this->m_Scene );\r
b->setNamePort( f->GetName( ) );\r
- b->setTypePort( f->GetClassName( ).c_str( ) );\r
+ b->setTypePort( f->GetClassName( ) );\r
// TODO: b->setScenePos( pnt );\r
\r
// Add input ports\r
b->addOutputPort( oIt->c_str( ) );\r
\r
// Keep a trace of this visual graph\r
- this->m_Graph->InsertVertex( f->GetName( ), b );\r
+ this->m_Graph->SetVertex( f->GetName( ), b );\r
}\r
\r
// -------------------------------------------------------------------------\r
// -------------------------------------------------------------------------
cpPipelineEditor::
-cpPipelineEditor( QWidget* parent )
+cpPipelineEditor( int argc, char* argv[], QWidget* parent )
: QMainWindow( parent ),
m_UI( new Ui::cpPipelineEditor ),
m_Workspace( NULL )
{
this->m_UI->setupUi( this );
+ // Prepare plugins interface
+ this->m_Plugins = new cpPlugins::Interface::Interface( );
+ QFileInfo info( argv[ 0 ] );
+ if( info.exists( ) )
+ {
+ std::string path = info.canonicalPath( ).toStdString( );
+ if( !( this->m_Plugins->LoadDefaultConfiguration( path ) ) )
+ if( this->m_Plugins->LoadFromFolder( path, false ) )
+ if( !( this->m_Plugins->SaveDefaultConfiguration( path ) ) )
+ QMessageBox::critical(
+ this,
+ "Error creating default plugins configuration",
+ "Could not save default plugins configuration"
+ );
+ this->_UpdateLoadedPlugins( );
+
+ } // fi
+
+ // Create an empty workspace
+ this->m_Workspace = new cpPlugins::Interface::Workspace( );
+ this->m_Workspace->SetInterface( this->m_Plugins );
+ this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
+
// Connect actions to slots
cpPipelineEditor_ConnectButton( LoadPluginsFile );
cpPipelineEditor_ConnectButton( LoadPluginsPath );
delete this->m_UI;
if( this->m_Workspace != NULL )
delete this->m_Workspace;
+ delete this->m_Plugins;
}
// -------------------------------------------------------------------------
void cpPipelineEditor::
_UpdateLoadedPlugins( )
{
- typedef cpPlugins::Interface::Workspace::TStringContainer _TStrings;
+ auto& classes = this->m_Plugins->GetClasses( );
- if( this->m_Workspace == NULL )
+ if( classes.size( ) == 0 )
+ {
+ QMessageBox::critical(
+ this,
+ "Error loading default plugins",
+ "No plugins loaded: remember to load some!!!"
+ );
return;
- _TStrings categories;
- this->m_Workspace->GetLoadedPluginCategories( categories );
- for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt )
+ } // fi
+
+ auto catIt = classes.begin( );
+ for( ; catIt != classes.end( ); ++catIt )
{
// Create or get category
QList< QTreeWidgetItem* > cat_items =
this->m_UI->LoadedPlugins->findItems(
- cIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
+ catIt->first.c_str( ), Qt::MatchExactly | Qt::MatchRecursive
);
QTreeWidgetItem* cat = NULL;
if( cat_items.size( ) == 0 )
{
cat = new QTreeWidgetItem(
- ( QTreeWidgetItem* )( NULL ), QStringList( cIt->c_str( ) )
+ ( QTreeWidgetItem* )( NULL ), QStringList( catIt->first.c_str( ) )
);
this->m_UI->LoadedPlugins->addTopLevelItem( cat );
}
else
cat = cat_items[ 0 ];
- // Add filters
- _TStrings filters = this->m_Workspace->GetLoadedPluginFilters( *cIt );
- for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt )
+ // Create filters
+ auto fIt = catIt->second.begin( );
+ for( ; fIt != catIt->second.end( ); ++fIt )
{
- // Find filter
QList< QTreeWidgetItem* > filter_items =
this->m_UI->LoadedPlugins->findItems(
- fIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
+ fIt->first.c_str( ), Qt::MatchExactly | Qt::MatchRecursive
);
auto fiIt = filter_items.begin( );
auto found_fiIt = filter_items.end( );
// Add filter
if( found_fiIt == filter_items.end( ) )
QTreeWidgetItem* filter = new QTreeWidgetItem(
- cat, QStringList( fIt->c_str( ) )
+ cat, QStringList( fIt->first.c_str( ) )
);
-
} // rof
} // rof
if( !( dlg.exec( ) ) )
return;
- // Create a new workspace, if not ready
- if( this->m_Workspace == NULL )
- this->m_Workspace = new cpPlugins::Interface::Workspace( );
-
// Read
QStringList names = dlg.selectedFiles( );
std::stringstream err_str;
for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt )
- if( !( this->m_Workspace->LoadPlugins( qIt->toStdString( ) ) ) )
+ if( !( this->m_Plugins->Load( qIt->toStdString( ) ) ) )
err_str << qIt->toStdString( ) << std::endl;
// Show an error message
);
// Update view
- this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
this->_UpdateLoadedPlugins( );
}
if( !( dlg.exec( ) ) )
return;
- // Create a new workspace, if not ready
- if( this->m_Workspace == NULL )
- this->m_Workspace = new cpPlugins::Interface::Workspace( );
-
// Read
std::string dir = dlg.selectedFiles( ).begin( )->toStdString( );
- if( !( this->m_Workspace->LoadPluginsPath( dir, false ) ) )
+ if( !( this->m_Plugins->LoadFromFolder( dir, false ) ) )
QMessageBox::critical(
this,
"Error loading plugins directory",
);
// Update view
- this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
this->_UpdateLoadedPlugins( );
}
if( this->m_Workspace != NULL )
delete this->m_Workspace;
this->m_Workspace = new cpPlugins::Interface::Workspace( );
+ this->m_Workspace->SetInterface( this->m_Plugins );
std::string err = this->m_Workspace->LoadWorkspace( fname );
- if( err == "" )
- {
- this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
- this->_UpdateLoadedPlugins( );
- }
- else
+ if( err != "" )
{
delete this->m_Workspace;
this->m_Workspace = NULL;
QMessageBox::tr( "Error loading workspace" ),
QMessageBox::tr( err.c_str( ) )
);
-
- } // fi
+ }
+ else
+ this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
}
// -------------------------------------------------------------------------
namespace Interface
{
class Workspace;
+ class Interface;
}
}
typedef QMainWindow Superclass;
public:
- explicit cpPipelineEditor( QWidget* parent = 0 );
+ explicit cpPipelineEditor(
+ int argc, char* argv[],
+ QWidget* parent = 0
+ );
virtual ~cpPipelineEditor( );
protected:
private:
Ui::cpPipelineEditor* m_UI;
cpPlugins::Interface::Workspace* m_Workspace;
+ cpPlugins::Interface::Interface* m_Plugins;
};
#endif // __CPPIPELINEEDITOR__H__
int main( int argc, char* argv[] )
{
QApplication a( argc, argv );
- cpPipelineEditor w;
+ cpPipelineEditor w( argc, argv, NULL );
w.show( );
return( a.exec( ) );
#include <iostream>
#include <string>
-#include <cpPlugins/Interface/Plugins.h>
+#include <cpPlugins/Interface/Interface.h>
// -------------------------------------------------------------------------
-typedef cpPlugins::Interface::Plugins TPlugins;
-typedef TPlugins::TStringContainer TStringContainer;
+typedef cpPlugins::Interface::Interface TInterface;
// -------------------------------------------------------------------------
int main( int argc, char* argv[] )
} // fi
- // Create interface
- cpPlugins::Interface::Plugins plugins;
+ // Create interface and load plugins
+ TInterface interface;
for( int i = 1; i < argc; ++i )
- if( !plugins.LoadPlugins( argv[ i ] ) )
+ if( !interface.Load( argv[ i ] ) )
std::cerr
<< "Error loading plugins file \""
<< argv[ i ] << "\""
<< std::endl;
- TStringContainer categories;
- plugins.GetLoadedCategories( categories );
- for( auto pIt = categories.begin( ); pIt != categories.end( ); ++pIt )
+ // Show info
+ auto i = interface.GetLoadedPlugins( ).begin( );
+ for( ; i != interface.GetLoadedPlugins( ).end( ); ++i )
{
- std::cout << "Category: " << *pIt << std::endl;
- const TStringContainer& filters = plugins.GetLoadedFilters( *pIt );
- for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt )
- std::cout << "\t" << *fIt << std::endl;
+ std::cout << "Folder: " << i->first << std::endl;
+ auto j = i->second.begin( );
+ for( ; j != i->second.end( ); ++j )
+ std::cout << "\tPlugin: " << *j << std::endl;
} // rof
+ // Show loaded classes
+ auto c = interface.GetClasses( ).begin( );
+ for( ; c != interface.GetClasses( ).end( ); ++c )
+ std::cout << "Class -> " << c->first << std::endl;
+
return( 0 );
}
#include <iostream>
#include <string>
-#include <cpPlugins/Interface/Plugins.h>
+#include <cpPlugins/Interface/Interface.h>
// -------------------------------------------------------------------------
-typedef cpPlugins::Interface::Plugins TPlugins;
-typedef TPlugins::TStringContainer TStringContainer;
+typedef cpPlugins::Interface::Interface TInterface;
// -------------------------------------------------------------------------
int main( int argc, char* argv[] )
} // fi
- // Create interface
- cpPlugins::Interface::Plugins plugins;
-
- if( !plugins.LoadPluginsPath( argv[ 1 ] ) )
- std::cerr
- << "Error loading plugins from folder \""
- << argv[ 1 ] << "\""
- << std::endl;
-
- const TStringContainer& loaded_plugins = plugins.GetLoadedPlugins( );
- auto pIt = loaded_plugins.begin( );
- for( ; pIt != loaded_plugins.end( ); ++pIt )
- std::cout << "Plugin: " << *pIt << std::endl;
-
- TStringContainer categories;
- plugins.GetLoadedCategories( categories );
- for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt )
+ // Create interface and load plugins
+ TInterface interface;
+ interface.LoadFromFolder( argv[ 1 ], true );
+
+ // Show info
+ auto i = interface.GetLoadedPlugins( ).begin( );
+ for( ; i != interface.GetLoadedPlugins( ).end( ); ++i )
{
- std::cout << "Category: " << *cIt << std::endl;
- const TStringContainer& filters = plugins.GetLoadedFilters( *cIt );
- for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt )
- std::cout << "\t" << *fIt << std::endl;
+ std::cout << "Folder: " << i->first << std::endl;
+ auto j = i->second.begin( );
+ for( ; j != i->second.end( ); ++j )
+ std::cout << "\tPlugin: " << *j << std::endl;
} // rof
+ // Show loaded classes
+ auto c = interface.GetClasses( ).begin( );
+ for( ; c != interface.GetClasses( ).end( ); ++c )
+ std::cout << "Class -> " << c->first << std::endl;
+
return( 0 );
}
<?xml version="1.0" ?>
<cpPlugins_Workspace>
- <plugins_dir path="/home/leonardo/devel/cpPlugins/build" recursive="0"/>
<filter class="cpPlugins::IO::ImageReader" name="reader">
<parameter name="FileNames" type="StringList">
<item value="test.mhd" />
void Clear( );
bool HasVertexIndex( const I& index ) const;
- void InsertVertex( const I& index, V& vertex );
+ void SetVertex( const I& index, V& vertex );
+ bool RenameVertex( const I& old_index, const I& new_index );
V& GetVertex( const I& index );
const V& GetVertex( const I& index ) const;
// -------------------------------------------------------------------------
template< class V, class C, class I >
void cpExtensions::DataStructures::Graph< V, C, I >::
-InsertVertex( const I& index, V& vertex )
+SetVertex( const I& index, V& vertex )
{
this->m_Vertices[ index ] = vertex;
}
+// -------------------------------------------------------------------------
+template< class V, class C, class I >
+bool cpExtensions::DataStructures::Graph< V, C, I >::
+RenameVertex( const I& old_index, const I& new_index )
+{
+ auto old_v = this->m_Vertices.find( old_index );
+ auto new_v = this->m_Vertices.find( new_index );
+ if( old_v != this->m_Vertices.end( ) && new_v == this->m_Vertices.end( ) )
+ {
+ // Replace vertex
+ typename TVertices::value_type new_entry( new_index, old_v->second );
+ new_v = this->m_Vertices.insert( new_entry ).first;
+ this->m_Vertices.erase( old_index );
+
+ // Duplicate edges
+ auto mIt = this->m_Matrix.begin( );
+ auto found_row = this->m_Matrix.end( );
+ for( ; mIt != this->m_Matrix.end( ); ++mIt )
+ {
+ if( mIt->first == old_index )
+ found_row = mIt;
+
+ auto rIt = mIt->second.begin( );
+ for( ; rIt != mIt->second.end( ); ++rIt )
+ {
+ if( mIt->first == old_index )
+ this->m_Matrix[ new_index ][ rIt->first ].push_back( rIt->second );
+ else if( rIt->first == old_index )
+ this->m_Matrix[ mIt->first ][ new_index ].push_back( rIt->second );
+
+ } // rof
+
+ } // rof
+
+ // Delete old edges
+ if( found_row != this->m_Matrix.end( ) )
+ this->m_Matrix.erase( found_row );
+
+ mIt = this->m_Matrix.begin( );
+ for( ; mIt != this->m_Matrix.end( ); ++mIt )
+ {
+ auto rIt = mIt->second.begin( );
+ while( rIt != mIt->second.end( ) )
+ {
+ if( rIt->first == old_index )
+ {
+ mIt->second.erase( rIt );
+ rIt = mIt->second.begin( );
+ }
+ else
+ ++rIt;
+
+ } // elihw
+
+ } // rof
+ return( true );
+ }
+ else
+ return( false );
+}
+
// -------------------------------------------------------------------------
template< class V, class C, class I >
V& cpExtensions::DataStructures::Graph< V, C, I >::
typedef itk::SmartPointer< const Self > ConstPointer; \
public: \
itkTypeMacro( O, S ); \
- cpPlugins_Id_Macro( cpPlugins::Interface::O, "ProcessObject" ); \
+ cpPlugins_Id_Macro( cpPlugins::Interface::O, ProcessObject ); \
protected: \
O( ); \
virtual ~O( ); \
public:
itkNewMacro( Self );
itkTypeMacro( DataObject, Object );
- cpPlugins_Id_Macro( DataObject, "BasicObject" );
+ cpPlugins_Id_Macro( DataObject, BasicObject );
public:
ProcessObject* GetSource( );
public:
itkNewMacro( Self );
itkTypeMacro( Image, DataObject );
- cpPlugins_Id_Macro( Image, "DataObject" );
+ cpPlugins_Id_Macro( Image, DataObject );
public:
template< class I >
#include <cpPlugins/Interface/Interface.h>
+#include <cstdlib>
+#include <fstream>
+#include <sstream>
+
+#ifdef _WIN32
+# define PLUGIN_PREFIX ""
+# define PLUGIN_EXT ".dll"
+#else // Linux
+# define PLUGIN_PREFIX "lib"
+# define PLUGIN_EXT ".so"
+#endif // _WIN32
+#define PLUGIN_CONFIG_FILE "plugins.cfg"
+
+namespace cpPlugins
+{
+ namespace Interface
+ {
+ struct PathSeparator
+ {
+ bool operator()( char c ) const
+ {
+#ifdef _WIN32
+ return( c == '\\' || c == '/' );
+#else // Linux like
+ return( c == '/' );
+#endif // _WIN32
+ }
+ };
+
+ } // ecapseman
+
+} // ecapseman
// -------------------------------------------------------------------------
cpPlugins::Interface::Interface::
this->UnloadAll( );
}
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Interface::
+LoadDefaultConfiguration( const std::string& path )
+{
+ std::ifstream file( PLUGIN_CONFIG_FILE );
+ if( file )
+ {
+ char buffer[ 1000 ];
+ while( file.getline( buffer, 1000 ) )
+ {
+ // std::string line( buffer );
+ std::istringstream line( buffer );
+ std::string name, folder;
+ std::getline( line, name, '@' );
+ std::getline( line, folder, '@' );
+ std::stringstream path;
+ path << folder << "/" << PLUGIN_PREFIX << name << PLUGIN_EXT;
+ this->Load( path.str( ) );
+
+ } // elihw
+
+ file.close( );
+ return( true );
+ }
+ else
+ return( false );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Interface::
+SaveDefaultConfiguration( const std::string& path )
+{
+ std::ofstream file( PLUGIN_CONFIG_FILE );
+ if( file )
+ {
+ auto pIt = this->m_LoadedPlugins.begin( );
+ for( ; pIt != this->m_LoadedPlugins.end( ); ++pIt )
+ {
+ auto fIt = pIt->second.begin( );
+ for( ; fIt != pIt->second.end( ); ++fIt )
+ file << *fIt << "@" << pIt->first << std::endl;
+
+ } // rof
+ file.close( );
+ return( true );
+ }
+ else
+ return( false );
+}
+
// -------------------------------------------------------------------------
cpPlugins::Interface::Interface::
TClasses& cpPlugins::Interface::Interface::
return( this->m_Classes );
}
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Interface::
+TLoadedPlugins& cpPlugins::Interface::Interface::
+GetLoadedPlugins( )
+{
+ return( this->m_LoadedPlugins );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Interface::
+TLoadedPlugins& cpPlugins::Interface::Interface::
+GetLoadedPlugins( ) const
+{
+ return( this->m_LoadedPlugins );
+}
+
// -------------------------------------------------------------------------
cpPlugins::Interface::ProcessObject::Pointer
cpPlugins::Interface::Interface::
CreateObject( const std::string& name ) const
{
- TClassesIterator cIt = this->m_Classes.find( name );
- if( cIt != this->m_Classes.end( ) )
+ cpPlugins::Interface::ProcessObject::Pointer po = NULL;
+ auto catIt = this->m_Classes.begin( );
+ while( catIt != this->m_Classes.end( ) )
{
- ProcessObjectProvider* provider =
- dynamic_cast< ProcessObjectProvider* >(
- this->m_Providers[ cIt->second ]
- );
- if( provider != NULL )
+ auto classIt = catIt->second.find( name );
+ if( classIt != catIt->second.end( ) )
{
- cpPlugins::Interface::ProcessObject::Pointer po = provider->create( );
- po->SetName( name );
- return( po );
+ ProcessObjectProvider* provider =
+ dynamic_cast< ProcessObjectProvider* >(
+ this->m_Providers[ classIt->second ]
+ );
+ if( provider != NULL )
+ {
+ po = provider->create( );
+ po->SetName( name );
- } // fi
+ } // fi
+ catIt = this->m_Classes.end( );
+ }
+ else
+ catIt++;
- } // fi
- return( NULL );
+ } // elihw
+
+ return( po );
}
// -------------------------------------------------------------------------
{
ret = this->m_Pluma.load( path );
if( ret )
+ {
+ std::string folder, name;
+ Self::_SepFName( path, folder, name );
+ this->m_LoadedPlugins[ folder ].push_back( name );
this->_LoadClasses( );
+
+ } // fi
}
catch( ... )
{
bool cpPlugins::Interface::Interface::
Load( const std::string& folder, const std::string& name )
{
+ std::string real_folder = folder;
+ PathSeparator sep;
+ if( sep( folder[ folder.size( ) - 1 ] ) )
+ real_folder = folder.substr( 0, folder.size( ) - 1 );
+ real_folder = std::string( realpath( real_folder.c_str( ), NULL ) );
bool ret = true;
try
{
- ret = this->m_Pluma.load( folder, name );
+ ret = this->m_Pluma.load( real_folder, name );
if( ret )
+ {
+ // Update loaded plugins
+ std::string prefix( PLUGIN_PREFIX );
+ std::string ext( PLUGIN_EXT );
+ std::string real_name = name;
+ if( prefix != "" )
+ real_name.replace( real_name.find( prefix ), prefix.size( ), "" );
+ real_name.replace( real_name.find( ext ), ext.size( ), "" );
+ this->m_LoadedPlugins[ real_folder ].push_back( real_name );
this->_LoadClasses( );
+
+ } // fi
}
catch( ... )
{
}
// -------------------------------------------------------------------------
-std::list< std::string > cpPlugins::Interface::Interface::
+bool cpPlugins::Interface::Interface::
LoadFromFolder( const std::string& folder, bool r )
{
- std::list< std::string > files;
try
{
- files = this->m_Pluma.loadFromFolder( folder, r );
- if( files.size( ) > 0 )
+ std::list< std::string > f = this->m_Pluma.loadFromFolder( folder, r );
+ if( f.size( ) > 0 )
+ {
+ // Update loaded plugins
+ for( auto i = f.begin( ); i != f.end( ); ++i )
+ {
+ std::string folder, name;
+ Self::_SepFName( *i, folder, name );
+ this->m_LoadedPlugins[ folder ].push_back( name );
+
+ } // rof
+
+ // Load classes
this->_LoadClasses( );
+ return( true );
+ }
+ else
+ return( false );
}
catch( ... )
{
+ return( false );
+
} // yrt
- return( files );
}
// -------------------------------------------------------------------------
{
this->m_Providers.clear( );
this->m_Classes.clear( );
+
+ // TODO: this->m_LoadedPlugins
+
this->_LoadClasses( );
} // fi
} // yrt
this->m_Providers.clear( );
this->m_Classes.clear( );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Interface::
-GetLoadedPlugins( std::vector< const std::string* >& names ) const
-{
- this->m_Pluma.getLoadedPlugins( names );
+ this->m_LoadedPlugins.clear( );
}
// -------------------------------------------------------------------------
// Get reader provider
for( unsigned int i = 0; i < this->m_Providers.size( ); ++i )
{
- ProcessObject::Pointer dummy = this->m_Providers[ i ]->create( );
- this->m_Classes[ dummy->GetClassName( ) ] = i;
+ ProcessObject::Pointer d = this->m_Providers[ i ]->create( );
+ this->m_Classes[ d->GetClassCategory( ) ][ d->GetClassName( ) ] = i;
} // rof
}
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Interface::
+_SepFName( const std::string& path, std::string& folder, std::string& name )
+{
+ PathSeparator sep;
+
+ // Get absolute path
+ std::string real_path = std::string( realpath( path.c_str( ), NULL ) );
+
+ // Get name
+ name = std::string(
+ std::find_if( real_path.rbegin( ), real_path.rend( ), sep ).base( ),
+ real_path.end( )
+ );
+
+ // Get containing folder
+ folder = real_path;
+ folder.replace( folder.find( name ), name.size( ), "" );
+ if( sep( folder[ folder.size( ) - 1 ] ) )
+ folder = folder.substr( 0, folder.size( ) - 1 );
+
+ // Erase prefix and extension from filename
+ std::string prefix( PLUGIN_PREFIX );
+ std::string ext( PLUGIN_EXT );
+ if( prefix != "" )
+ name.replace( name.find( prefix ), prefix.size( ), "" );
+ name.replace( name.find( ext ), ext.size( ), "" );
+}
+
// eof - $RCSfile$
class cpPlugins_Interface_EXPORT Interface
{
public:
+ typedef Interface Self;
typedef std::vector< ProcessObjectProvider* > TProviders;
- typedef std::map< std::string, unsigned int > TClasses;
+ typedef std::map< std::string, unsigned int > TClass;
+ typedef std::map< std::string, TClass > TClasses;
+ typedef
+ std::map< std::string, std::vector< std::string > >
+ TLoadedPlugins;
typedef TProviders::const_iterator TProvidersIterator;
typedef TClasses::const_iterator TClassesIterator;
Interface( );
virtual ~Interface( );
+ bool LoadDefaultConfiguration( const std::string& path );
+ bool SaveDefaultConfiguration( const std::string& path );
+
// Plugin access
TClasses& GetClasses( );
const TClasses& GetClasses( ) const;
+ TLoadedPlugins& GetLoadedPlugins( );
+ const TLoadedPlugins& GetLoadedPlugins( ) const;
ProcessObject::Pointer CreateObject( const std::string& name ) const;
// Interface to PLUMA
bool Load( const std::string& path );
bool Load( const std::string& folder, const std::string& name );
- std::list< std::string > LoadFromFolder(
- const std::string& folder, bool r = false
- );
+ bool LoadFromFolder( const std::string& folder, bool r = false );
bool Unload( const std::string& name );
void UnloadAll( );
- void GetLoadedPlugins( std::vector< const std::string* >& names ) const;
bool IsLoaded( const std::string& name ) const;
protected:
void _LoadClasses( );
+ static void _SepFName(
+ const std::string& path,
+ std::string& folder,
+ std::string& name
+ );
+
protected:
- pluma::Pluma m_Pluma;
- TProviders m_Providers;
- TClasses m_Classes;
+ pluma::Pluma m_Pluma;
+ TProviders m_Providers;
+ TClasses m_Classes;
+ TLoadedPlugins m_LoadedPlugins;
};
} // ecapseman
// -------------------------------------------------------------------------
#define cpPlugins_Id_Macro( name, category ) \
public: \
- virtual std::string GetClassName( ) { return( #name ); } \
- virtual std::string GetClassCategory( ) { return( category ); }
+ virtual const char* GetClassName( ) const { return( #name ); } \
+ virtual const char* GetClassCategory( ) const { return( #category ); }
// -------------------------------------------------------------------------
#define CPPLUGINS_PROVIDER_HEADER_BEGIN( TYPE ) \
public:
itkNewMacro( Self );
itkTypeMacro( Mesh, DataObject );
- cpPlugins_Id_Macro( Mesh, "DataObject" );
+ cpPlugins_Id_Macro( Mesh, DataObject );
public:
template< class M >
cpPlugins::Interface::Object::
Object( )
: Superclass( ),
- m_Name( "" )
+ m_Name( "" ),
+ m_ViewX( float( 0 ) ),
+ m_ViewY( float( 0 ) )
{
}
public:
itkNewMacro( Self );
itkTypeMacro( Object, itkObject );
- cpPlugins_Id_Macro( Object, "BaseObject" );
+ cpPlugins_Id_Macro( Object, BaseObject );
itkGetStringMacro( Name );
+ itkGetConstMacro( ViewX, float );
+ itkGetConstMacro( ViewY, float );
+
itkSetStringMacro( Name );
+ itkSetMacro( ViewX, float );
+ itkSetMacro( ViewY, float );
+
+ public:
+ inline float SetViewCoords( float x, float y )
+ {
+ this->SetViewX( x );
+ this->SetViewY( y );
+ }
protected:
Object( );
protected:
std::string m_Name;
+ float m_ViewX, m_ViewY;
};
} // ecapseman
bool cpPlugins::Interface::Plugins::
LoadPluginsPath( const std::string& path, bool r )
{
+ /* TODO
this->BlockWidget( );
// Load all plugins from given folder
this->UnblockWidget( );
return( ret );
+ */
+ return( false );
}
// -------------------------------------------------------------------------
public:
itkTypeMacro( ProcessObject, Object );
- cpPlugins_Id_Macro( ProcessObject, "BaseObject" );
+ cpPlugins_Id_Macro( ProcessObject, BaseObject );
itkBooleanMacro( Interactive );
// -------------------------------------------------------------------------
cpPlugins::Interface::Workspace::
Workspace( )
- : m_LastLoadedPlugin( "" )
+ : m_Interface( NULL )
{
this->m_Graph = TGraph::New( );
}
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Workspace::
-LoadPluginsPath( const std::string& path, bool r )
-{
- // 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;
-
- } // rof
- this->_UpdateLoadedPluginsInformation( );
- ret = true;
-
- } // fi
- return( ret );
-}
-
-// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Workspace::
-LoadPlugins( const std::string& fname )
-{
- // 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
- return( ret );
-}
-
-// -------------------------------------------------------------------------
-const cpPlugins::Interface::Workspace::
-TStringContainer& cpPlugins::Interface::Workspace::
-GetLoadedPlugins( ) const
-{
- return( this->m_LoadedPlugins );
-}
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Workspace::
-GetLoadedPluginCategories( TStringContainer& categories ) const
+cpPlugins::Interface::Workspace::
+TInterface* cpPlugins::Interface::Workspace::
+GetInterface( )
{
- categories.clear( );
- auto fIt = this->m_LoadedFilters.begin( );
- for( ; fIt != this->m_LoadedFilters.end( ); ++fIt )
- categories.insert( fIt->first );
+ return( this->m_Interface );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Workspace::
-GetLoadedPluginFilters( TStringContainer& filters ) const
+SetInterface( TInterface* i )
{
- 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 );
+ if( this->m_Interface != i )
+ this->m_Interface = i;
}
-// -------------------------------------------------------------------------
-const cpPlugins::Interface::Workspace::
-TStringContainer& cpPlugins::Interface::Workspace::
-GetLoadedPluginFilters( 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 );
-}
+/* TODO
+ bool cpPlugins::Interface::Workspace::
+ LoadPluginsPath( const std::string& path, bool r )
+ {
+ // 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;
+
+ } // rof
+ this->_UpdateLoadedPluginsInformation( );
+ ret = true;
+
+ } // fi
+ return( ret );
+ }
+
+ // -------------------------------------------------------------------------
+ bool cpPlugins::Interface::Workspace::
+ LoadPlugins( const std::string& fname )
+ {
+ // 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
+ return( ret );
+ }
+
+ // -------------------------------------------------------------------------
+ const cpPlugins::Interface::Workspace::
+ TStringContainer& cpPlugins::Interface::Workspace::
+ GetLoadedPlugins( ) const
+ {
+ return( this->m_LoadedPlugins );
+ }
+
+ // -------------------------------------------------------------------------
+ void cpPlugins::Interface::Workspace::
+ GetLoadedPluginCategories( TStringContainer& categories ) const
+ {
+ categories.clear( );
+ auto fIt = this->m_LoadedFilters.begin( );
+ for( ; fIt != this->m_LoadedFilters.end( ); ++fIt )
+ categories.insert( fIt->first );
+ }
+
+ // -------------------------------------------------------------------------
+ void cpPlugins::Interface::Workspace::
+ GetLoadedPluginFilters( TStringContainer& filters ) const
+ {
+ 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 );
+ }
+
+ // -------------------------------------------------------------------------
+ const cpPlugins::Interface::Workspace::
+ TStringContainer& cpPlugins::Interface::Workspace::
+ GetLoadedPluginFilters( 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::Workspace::
bool cpPlugins::Interface::Workspace::
CreateFilter( const std::string& filter, const std::string& name )
{
+ if( this->m_Interface == NULL )
+ return( false );
+
// Get or create new filter from name
if( !( this->m_Graph->HasVertexIndex( name ) ) )
{
- TFilter::Pointer f = this->m_Interface.CreateObject( filter );
+ TFilter::Pointer f = this->m_Interface->CreateObject( filter );
if( f.IsNotNull( ) )
{
f->SetName( name );
TObject::Pointer o = f.GetPointer( );
- this->m_Graph->InsertVertex( name, o );
+ this->m_Graph->SetVertex( name, o );
return( true );
}
else
void cpPlugins::Interface::Workspace::
_UpdateLoadedPluginsInformation( )
{
- this->m_LoadedFilters.clear( );
- const TInterface::TClasses& cls = this->m_Interface.GetClasses( );
- for( auto i = cls.begin( ); i != cls.end( ); ++i )
- {
- TFilter::Pointer o = this->m_Interface.CreateObject( i->first );
- std::string name = o->GetClassName( );
- std::string category = o->GetClassCategory( );
- this->m_LoadedFilters[ category ].insert( name );
-
- } // rof
+ /* TODO
+ if( this->m_Interface != NULL )
+ {
+ this->m_LoadedFilters.clear( );
+ const TInterface::TClasses& cls = this->m_Interface->GetClasses( );
+ for( auto i = cls.begin( ); i != cls.end( ); ++i )
+ {
+ TFilter::Pointer o = this->m_Interface->CreateObject( i->first );
+ std::string name = o->GetClassName( );
+ std::string category = o->GetClassCategory( );
+ this->m_LoadedFilters[ category ].insert( name );
+
+ } // rof
+
+ } // fi
+ */
}
// eof - $RCSfile$
virtual ~Workspace( );
// Plugins management
- bool LoadPluginsPath( const std::string& path, bool r = false );
- bool LoadPlugins( const std::string& fname );
- const TStringContainer& GetLoadedPlugins( ) const;
- void GetLoadedPluginCategories( TStringContainer& categories ) const;
- void GetLoadedPluginFilters( TStringContainer& filters ) const;
- const TStringContainer& GetLoadedPluginFilters(
- const std::string& category
- ) const;
+ TInterface* GetInterface( );
+ void SetInterface( TInterface* i );
// Workspace IO
std::string LoadWorkspace( const std::string& fname );
protected:
// Plugins interface
- TInterface m_Interface;
- std::string m_LastLoadedPlugin;
- TStringContainer m_LoadedPlugins;
- std::map< std::string, TStringContainer > m_LoadedFilters;
+ TInterface* m_Interface;
// Processing graph
typename TGraph::Pointer m_Graph;
return( "cpPlugins::Interface::Workspace: No valid workspace" );
std::stringstream err;
- // Read plugins files
- TiXmlElement* plugins = root->FirstChildElement( "plugins" );
- while( plugins != NULL )
- {
- const char* value = plugins->Attribute( "filename" );
- if( value != NULL )
- {
- if( !( this->LoadPlugins( value ) ) )
- err << "no valid plugins file \"" << value << "\"" << std::endl;
-
- } // fi
- plugins = plugins->NextSiblingElement( "plugins" );
-
- } // elihw
-
- // Read plugins paths
- plugins = root->FirstChildElement( "plugins_dir" );
- while( plugins != NULL )
- {
- const char* value = plugins->Attribute( "path" );
- if( value != NULL )
- {
- int recursive;
- if( plugins->QueryIntAttribute( "recursive", &recursive ) != TIXML_SUCCESS )
- recursive = 0;
- if( !( this->LoadPluginsPath( value, recursive == 1 ) ) )
- err << "No valid plugins path \"" << value << "\"" << std::endl;
-
- } // fi
- plugins = plugins->NextSiblingElement( "plugins_dir" );
-
- } // elihw
-
// Read filters
TiXmlElement* filter = root->FirstChildElement( "filter" );
while( filter != NULL )
{
const char* class_value = filter->Attribute( "class" );
const char* name_value = filter->Attribute( "name" );
+ float viewX = float( 0 );
+ float viewY = float( 0 );
+ filter->QueryFloatAttribute( "ViewX", &viewX );
+ filter->QueryFloatAttribute( "ViewY", &viewY );
if( class_value != NULL && name_value != NULL )
{
if( this->CreateFilter( class_value, name_value ) )
{
+ TFilter* new_filter = this->GetFilter( name_value );
+ new_filter->SetViewCoords( viewX, viewY );
+
// Read parameters
- TParameters* parameters = this->GetParameters( name_value );
+ TParameters* parameters = new_filter->GetParameters( );
parameters->Clear( );
TiXmlElement* param = filter->FirstChildElement( "parameter" );
TiXmlDocument* doc = new TiXmlDocument( );
TiXmlElement* root = new TiXmlElement( "cpPlugins_Workspace" );
- // Save plugins
- for(
- auto plugIt = this->m_LoadedPlugins.begin( );
- plugIt != this->m_LoadedPlugins.end( );
- ++plugIt
- )
- {
- TiXmlElement* plugin = new TiXmlElement( "plugins" );
- plugin->SetAttribute( "filename", plugIt->c_str( ) );
- root->LinkEndChild( plugin );
-
- } // rof
-
// Save vertices
auto vIt = this->m_Graph->BeginVertices( );
for( ; vIt != this->m_Graph->EndVertices( ); ++vIt )
if( filter != NULL )
{
TiXmlElement* e = new TiXmlElement( "filter" );
- e->SetAttribute( "class", filter->GetClassName( ).c_str( ) );
+ e->SetAttribute( "class", filter->GetClassName( ) );
e->SetAttribute( "name", filter->GetName( ) );
+ e->SetAttribute( "ViewX", filter->GetViewX( ) );
+ e->SetAttribute( "ViewY", filter->GetViewY( ) );
const TParameters* params = filter->GetParameters( );
std::vector< std::string > names;
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::BinaryErodeImageFilter,
- "ImageToBinaryImageFilter"
+ ImageToBinaryImageFilter
);
protected:
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::BinaryThresholdImageFilter,
- "ImageToBinaryImageFilter"
+ ImageToBinaryImageFilter
);
protected:
itkNewMacro( Self );
itkTypeMacro( Cutter, cpPluginsInterfaceMeshToMeshFilter );
cpPlugins_Id_Macro(
- cpPlugins::BasicFilters::Cutter,
- "MeshToMeshFilter"
+ cpPlugins::BasicFilters::Cutter, MeshToMeshFilter
);
protected:
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::DoubleFloodImageFilter,
- "ImageToBinaryImageFilter"
+ ImageToBinaryImageFilter
);
public:
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::ExtractSliceImageFilter,
- "ImageToImageFilter"
+ ImageToImageFilter
);
protected:
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::FloodFillImageFilter,
- "ImageToBinaryImageFilter"
+ ImageToBinaryImageFilter
);
protected:
itkNewMacro( Self );
itkTypeMacro( MacheteFilter, FilterObject );
cpPlugins_Id_Macro(
- cpPlugins::BasicFilters::MacheteFilter, "FilterObject"
+ cpPlugins::BasicFilters::MacheteFilter, FilterObject
);
public:
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::MacheteImageFilter,
- "ImageToBinaryImageFilter"
+ ImageToBinaryImageFilter
);
protected:
itkNewMacro( Self );
itkTypeMacro( MarchingCubes, cpPluginsInterfaceImageToMeshFilter );
cpPlugins_Id_Macro(
- cpPlugins::BasicFilters::MarchingCubes, "ImageToMeshFilter"
+ cpPlugins::BasicFilters::MarchingCubes, ImageToMeshFilter
);
protected:
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::MedianImageFilter,
- "ImageToBinaryImageFilter"
+ ImageToBinaryImageFilter
);
protected:
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::OtsuThresholdImageFilter,
- "ImageToBinaryImageFilter"
+ ImageToBinaryImageFilter
);
protected:
);
cpPlugins_Id_Macro(
cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter,
- "ImageToImageFilter"
+ ImageToImageFilter
);
protected:
itkNewMacro( Self );
itkTypeMacro( SphereMeshSource, cpPluginsInterfaceMeshSource );
cpPlugins_Id_Macro(
- cpPlugins::BasicFilters::SphereMeshSource, "MeshSource"
+ cpPlugins::BasicFilters::SphereMeshSource, MeshSource
);
protected:
public:
itkNewMacro( Self );
itkTypeMacro( DicomSeriesReader, ImageReader );
- cpPlugins_Id_Macro( cpPlugins::IO::DicomSeriesReader, "IO" );
+ cpPlugins_Id_Macro( cpPlugins::IO::DicomSeriesReader, IO );
public:
virtual DialogResult ExecConfigurationDialog( QWidget* parent );
public:
itkNewMacro( Self );
itkTypeMacro( ImageReader, cpPluginsInterfaceImageSource );
- cpPlugins_Id_Macro( cpPlugins::IO::ImageReader, "IO" );
+ cpPlugins_Id_Macro( cpPlugins::IO::ImageReader, IO );
public:
virtual DialogResult ExecConfigurationDialog( QWidget* parent );
public:
itkNewMacro( Self );
itkTypeMacro( ImageWriter, cpPluginsInterfaceImageSink );
- cpPlugins_Id_Macro( cpPlugins::IO::ImageWriter, "IO" );
+ cpPlugins_Id_Macro( cpPlugins::IO::ImageWriter, IO );
public:
virtual DialogResult ExecConfigurationDialog( QWidget* parent );
public:
itkNewMacro( Self );
itkTypeMacro( MeshReader, cpPluginsInterfaceMeshSource );
- cpPlugins_Id_Macro( cpPlugins::IO::MeshReader, "IO" );
+ cpPlugins_Id_Macro( cpPlugins::IO::MeshReader, IO );
public:
virtual DialogResult ExecConfigurationDialog( QWidget* parent );
public:
itkNewMacro( Self );
itkTypeMacro( MeshWriter, cpPluginsInterfaceMeshSink );
- cpPlugins_Id_Macro( cpPlugins::IO::MeshWriter, "IO" );
+ cpPlugins_Id_Macro( cpPlugins::IO::MeshWriter, IO );
public:
virtual DialogResult ExecConfigurationDialog( QWidget* parent );