From 94411ee4209d15d6d1cf25bb817675f76f7ea5c0 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Mon, 11 Jan 2016 12:22:55 -0500 Subject: [PATCH] More on graph editor --- appli/cpPipelineEditor/QNodesEditor.cxx | 8 +- appli/cpPipelineEditor/cpPipelineEditor.cxx | 86 ++++--- appli/cpPipelineEditor/cpPipelineEditor.h | 7 +- appli/cpPipelineEditor/main.cxx | 2 +- appli/examples/example_LoadPlugins.cxx | 30 ++- .../examples/example_LoadPluginsFromPath.cxx | 42 ++-- data/workspace_00.xml | 1 - lib/cpExtensions/DataStructures/Graph.h | 3 +- lib/cpExtensions/DataStructures/Graph.hxx | 63 ++++- lib/cpPlugins/Interface/BaseProcessObjects.h | 2 +- lib/cpPlugins/Interface/DataObject.h | 2 +- lib/cpPlugins/Interface/Image.h | 2 +- lib/cpPlugins/Interface/Interface.cxx | 225 +++++++++++++++--- lib/cpPlugins/Interface/Interface.h | 30 ++- lib/cpPlugins/Interface/Macros.h | 4 +- lib/cpPlugins/Interface/Mesh.h | 2 +- lib/cpPlugins/Interface/Object.cxx | 4 +- lib/cpPlugins/Interface/Object.h | 15 +- lib/cpPlugins/Interface/Plugins.cxx | 3 + lib/cpPlugins/Interface/ProcessObject.h | 2 +- lib/cpPlugins/Interface/Workspace.cxx | 214 +++++++++-------- lib/cpPlugins/Interface/Workspace.h | 15 +- lib/cpPlugins/Interface/WorkspaceIO.cxx | 59 +---- .../BasicFilters/BinaryErodeImageFilter.h | 2 +- .../BasicFilters/BinaryThresholdImageFilter.h | 2 +- lib/cpPlugins/Plugins/BasicFilters/Cutter.h | 3 +- .../BasicFilters/DoubleFloodImageFilter.h | 2 +- .../BasicFilters/ExtractSliceImageFilter.h | 2 +- .../BasicFilters/FloodFillImageFilter.h | 2 +- .../Plugins/BasicFilters/MacheteFilter.h | 2 +- .../Plugins/BasicFilters/MacheteImageFilter.h | 2 +- .../Plugins/BasicFilters/MarchingCubes.h | 2 +- .../Plugins/BasicFilters/MedianImageFilter.h | 2 +- .../BasicFilters/OtsuThresholdImageFilter.h | 2 +- .../RGBImageToOtherChannelsFilter.h | 2 +- .../Plugins/BasicFilters/SphereMeshSource.h | 2 +- lib/cpPlugins/Plugins/IO/DicomSeriesReader.h | 2 +- lib/cpPlugins/Plugins/IO/ImageReader.h | 2 +- lib/cpPlugins/Plugins/IO/ImageWriter.h | 2 +- lib/cpPlugins/Plugins/IO/MeshReader.h | 2 +- lib/cpPlugins/Plugins/IO/MeshWriter.h | 2 +- 41 files changed, 557 insertions(+), 301 deletions(-) diff --git a/appli/cpPipelineEditor/QNodesEditor.cxx b/appli/cpPipelineEditor/QNodesEditor.cxx index a499e94..6417636 100644 --- a/appli/cpPipelineEditor/QNodesEditor.cxx +++ b/appli/cpPipelineEditor/QNodesEditor.cxx @@ -76,8 +76,6 @@ workspace( ) const void PipelineEditor::QNodesEditor:: setWorkspace( TWorkspace* ws ) { - if( this->m_Workspace == ws ) - return; this->m_Workspace = ws; this->m_Graph = TGraph::New( ); @@ -184,8 +182,6 @@ itemAt( const QPointF& pos ) return( NULL ); } -#include - // ------------------------------------------------------------------------- void PipelineEditor::QNodesEditor:: _CreateBlock( TFilter* f, const QPointF& pnt ) @@ -196,7 +192,7 @@ _CreateBlock( TFilter* f, const QPointF& pnt ) // Add block QNEBlock* b = new QNEBlock( 0, this->m_Scene ); b->setNamePort( f->GetName( ) ); - b->setTypePort( f->GetClassName( ).c_str( ) ); + b->setTypePort( f->GetClassName( ) ); // TODO: b->setScenePos( pnt ); // Add input ports @@ -212,7 +208,7 @@ _CreateBlock( TFilter* f, const QPointF& pnt ) b->addOutputPort( oIt->c_str( ) ); // Keep a trace of this visual graph - this->m_Graph->InsertVertex( f->GetName( ), b ); + this->m_Graph->SetVertex( f->GetName( ), b ); } // ------------------------------------------------------------------------- diff --git a/appli/cpPipelineEditor/cpPipelineEditor.cxx b/appli/cpPipelineEditor/cpPipelineEditor.cxx index 957158a..6bda2a7 100644 --- a/appli/cpPipelineEditor/cpPipelineEditor.cxx +++ b/appli/cpPipelineEditor/cpPipelineEditor.cxx @@ -23,13 +23,36 @@ // ------------------------------------------------------------------------- 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 ); @@ -44,45 +67,52 @@ cpPipelineEditor:: 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( ); @@ -93,9 +123,8 @@ _UpdateLoadedPlugins( ) // 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 @@ -118,15 +147,11 @@ _ButtonLoadPluginsFile( ) 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 @@ -139,7 +164,6 @@ _ButtonLoadPluginsFile( ) ); // Update view - this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); this->_UpdateLoadedPlugins( ); } @@ -153,13 +177,9 @@ _ButtonLoadPluginsPath( ) 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", @@ -167,7 +187,6 @@ _ButtonLoadPluginsPath( ) ); // Update view - this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); this->_UpdateLoadedPlugins( ); } @@ -189,13 +208,9 @@ _ActionOpenWorkspace( ) 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; @@ -204,8 +219,9 @@ _ActionOpenWorkspace( ) QMessageBox::tr( "Error loading workspace" ), QMessageBox::tr( err.c_str( ) ) ); - - } // fi + } + else + this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace ); } // ------------------------------------------------------------------------- diff --git a/appli/cpPipelineEditor/cpPipelineEditor.h b/appli/cpPipelineEditor/cpPipelineEditor.h index 7192268..8117778 100644 --- a/appli/cpPipelineEditor/cpPipelineEditor.h +++ b/appli/cpPipelineEditor/cpPipelineEditor.h @@ -15,6 +15,7 @@ namespace cpPlugins namespace Interface { class Workspace; + class Interface; } } @@ -30,7 +31,10 @@ public: typedef QMainWindow Superclass; public: - explicit cpPipelineEditor( QWidget* parent = 0 ); + explicit cpPipelineEditor( + int argc, char* argv[], + QWidget* parent = 0 + ); virtual ~cpPipelineEditor( ); protected: @@ -45,6 +49,7 @@ protected slots: private: Ui::cpPipelineEditor* m_UI; cpPlugins::Interface::Workspace* m_Workspace; + cpPlugins::Interface::Interface* m_Plugins; }; #endif // __CPPIPELINEEDITOR__H__ diff --git a/appli/cpPipelineEditor/main.cxx b/appli/cpPipelineEditor/main.cxx index 7154469..3dfe464 100644 --- a/appli/cpPipelineEditor/main.cxx +++ b/appli/cpPipelineEditor/main.cxx @@ -6,7 +6,7 @@ int main( int argc, char* argv[] ) { QApplication a( argc, argv ); - cpPipelineEditor w; + cpPipelineEditor w( argc, argv, NULL ); w.show( ); return( a.exec( ) ); diff --git a/appli/examples/example_LoadPlugins.cxx b/appli/examples/example_LoadPlugins.cxx index b68087c..76c5feb 100644 --- a/appli/examples/example_LoadPlugins.cxx +++ b/appli/examples/example_LoadPlugins.cxx @@ -1,11 +1,10 @@ #include #include -#include +#include // ------------------------------------------------------------------------- -typedef cpPlugins::Interface::Plugins TPlugins; -typedef TPlugins::TStringContainer TStringContainer; +typedef cpPlugins::Interface::Interface TInterface; // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) @@ -17,27 +16,32 @@ 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 ); } diff --git a/appli/examples/example_LoadPluginsFromPath.cxx b/appli/examples/example_LoadPluginsFromPath.cxx index 3747995..ba684ce 100644 --- a/appli/examples/example_LoadPluginsFromPath.cxx +++ b/appli/examples/example_LoadPluginsFromPath.cxx @@ -1,11 +1,10 @@ #include #include -#include +#include // ------------------------------------------------------------------------- -typedef cpPlugins::Interface::Plugins TPlugins; -typedef TPlugins::TStringContainer TStringContainer; +typedef cpPlugins::Interface::Interface TInterface; // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) @@ -17,31 +16,26 @@ 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 ); } diff --git a/data/workspace_00.xml b/data/workspace_00.xml index 7f85219..cbf689b 100644 --- a/data/workspace_00.xml +++ b/data/workspace_00.xml @@ -1,6 +1,5 @@ - diff --git a/lib/cpExtensions/DataStructures/Graph.h b/lib/cpExtensions/DataStructures/Graph.h index 5fb2707..b11b703 100644 --- a/lib/cpExtensions/DataStructures/Graph.h +++ b/lib/cpExtensions/DataStructures/Graph.h @@ -51,7 +51,8 @@ namespace cpExtensions 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; diff --git a/lib/cpExtensions/DataStructures/Graph.hxx b/lib/cpExtensions/DataStructures/Graph.hxx index c567f39..d89be75 100644 --- a/lib/cpExtensions/DataStructures/Graph.hxx +++ b/lib/cpExtensions/DataStructures/Graph.hxx @@ -93,11 +93,72 @@ HasVertexIndex( 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 >:: diff --git a/lib/cpPlugins/Interface/BaseProcessObjects.h b/lib/cpPlugins/Interface/BaseProcessObjects.h index 1b2c8db..a120b84 100644 --- a/lib/cpPlugins/Interface/BaseProcessObjects.h +++ b/lib/cpPlugins/Interface/BaseProcessObjects.h @@ -16,7 +16,7 @@ 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( ); \ diff --git a/lib/cpPlugins/Interface/DataObject.h b/lib/cpPlugins/Interface/DataObject.h index d90f8e9..05b7023 100644 --- a/lib/cpPlugins/Interface/DataObject.h +++ b/lib/cpPlugins/Interface/DataObject.h @@ -28,7 +28,7 @@ namespace cpPlugins public: itkNewMacro( Self ); itkTypeMacro( DataObject, Object ); - cpPlugins_Id_Macro( DataObject, "BasicObject" ); + cpPlugins_Id_Macro( DataObject, BasicObject ); public: ProcessObject* GetSource( ); diff --git a/lib/cpPlugins/Interface/Image.h b/lib/cpPlugins/Interface/Image.h index 30bfbf5..23e1c23 100644 --- a/lib/cpPlugins/Interface/Image.h +++ b/lib/cpPlugins/Interface/Image.h @@ -24,7 +24,7 @@ namespace cpPlugins public: itkNewMacro( Self ); itkTypeMacro( Image, DataObject ); - cpPlugins_Id_Macro( Image, "DataObject" ); + cpPlugins_Id_Macro( Image, DataObject ); public: template< class I > diff --git a/lib/cpPlugins/Interface/Interface.cxx b/lib/cpPlugins/Interface/Interface.cxx index 494f189..34dbf2e 100644 --- a/lib/cpPlugins/Interface/Interface.cxx +++ b/lib/cpPlugins/Interface/Interface.cxx @@ -1,4 +1,36 @@ #include +#include +#include +#include + +#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:: @@ -14,6 +46,56 @@ 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:: @@ -30,28 +112,52 @@ GetClasses( ) const 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 ); } // ------------------------------------------------------------------------- @@ -63,7 +169,13 @@ Load( const std::string& path ) { 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( ... ) { @@ -77,12 +189,28 @@ Load( const std::string& path ) 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( ... ) { @@ -93,20 +221,35 @@ Load( const std::string& folder, const std::string& name ) } // ------------------------------------------------------------------------- -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 ); } // ------------------------------------------------------------------------- @@ -121,6 +264,9 @@ Unload( const std::string& name ) { this->m_Providers.clear( ); this->m_Classes.clear( ); + + // TODO: this->m_LoadedPlugins + this->_LoadClasses( ); } // fi @@ -148,13 +294,7 @@ UnloadAll( ) } // 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( ); } // ------------------------------------------------------------------------- @@ -175,10 +315,39 @@ _LoadClasses( ) // 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$ diff --git a/lib/cpPlugins/Interface/Interface.h b/lib/cpPlugins/Interface/Interface.h index 34f29a8..2c4ad5e 100644 --- a/lib/cpPlugins/Interface/Interface.h +++ b/lib/cpPlugins/Interface/Interface.h @@ -19,8 +19,13 @@ namespace cpPlugins 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; @@ -29,29 +34,38 @@ namespace cpPlugins 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 diff --git a/lib/cpPlugins/Interface/Macros.h b/lib/cpPlugins/Interface/Macros.h index ef726ed..90cea8c 100644 --- a/lib/cpPlugins/Interface/Macros.h +++ b/lib/cpPlugins/Interface/Macros.h @@ -8,8 +8,8 @@ // ------------------------------------------------------------------------- #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 ) \ diff --git a/lib/cpPlugins/Interface/Mesh.h b/lib/cpPlugins/Interface/Mesh.h index 097ed30..e769239 100644 --- a/lib/cpPlugins/Interface/Mesh.h +++ b/lib/cpPlugins/Interface/Mesh.h @@ -21,7 +21,7 @@ namespace cpPlugins public: itkNewMacro( Self ); itkTypeMacro( Mesh, DataObject ); - cpPlugins_Id_Macro( Mesh, "DataObject" ); + cpPlugins_Id_Macro( Mesh, DataObject ); public: template< class M > diff --git a/lib/cpPlugins/Interface/Object.cxx b/lib/cpPlugins/Interface/Object.cxx index 85ef6a1..369b20f 100644 --- a/lib/cpPlugins/Interface/Object.cxx +++ b/lib/cpPlugins/Interface/Object.cxx @@ -4,7 +4,9 @@ cpPlugins::Interface::Object:: Object( ) : Superclass( ), - m_Name( "" ) + m_Name( "" ), + m_ViewX( float( 0 ) ), + m_ViewY( float( 0 ) ) { } diff --git a/lib/cpPlugins/Interface/Object.h b/lib/cpPlugins/Interface/Object.h index 03eb2ae..345be7f 100644 --- a/lib/cpPlugins/Interface/Object.h +++ b/lib/cpPlugins/Interface/Object.h @@ -25,10 +25,22 @@ namespace cpPlugins 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( ); @@ -41,6 +53,7 @@ namespace cpPlugins protected: std::string m_Name; + float m_ViewX, m_ViewY; }; } // ecapseman diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx index 62227a9..ece9dd0 100644 --- a/lib/cpPlugins/Interface/Plugins.cxx +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -143,6 +143,7 @@ SetApplication( BaseApplication* a ) bool cpPlugins::Interface::Plugins:: LoadPluginsPath( const std::string& path, bool r ) { + /* TODO this->BlockWidget( ); // Load all plugins from given folder @@ -166,6 +167,8 @@ LoadPluginsPath( const std::string& path, bool r ) this->UnblockWidget( ); return( ret ); + */ + return( false ); } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/ProcessObject.h b/lib/cpPlugins/Interface/ProcessObject.h index 6c6a8e7..b6cf116 100644 --- a/lib/cpPlugins/Interface/ProcessObject.h +++ b/lib/cpPlugins/Interface/ProcessObject.h @@ -53,7 +53,7 @@ namespace cpPlugins public: itkTypeMacro( ProcessObject, Object ); - cpPlugins_Id_Macro( ProcessObject, "BaseObject" ); + cpPlugins_Id_Macro( ProcessObject, BaseObject ); itkBooleanMacro( Interactive ); diff --git a/lib/cpPlugins/Interface/Workspace.cxx b/lib/cpPlugins/Interface/Workspace.cxx index fb8f91e..8a588af 100644 --- a/lib/cpPlugins/Interface/Workspace.cxx +++ b/lib/cpPlugins/Interface/Workspace.cxx @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: Workspace( ) - : m_LastLoadedPlugin( "" ) + : m_Interface( NULL ) { this->m_Graph = TGraph::New( ); } @@ -15,95 +15,112 @@ cpPlugins::Interface::Workspace:: } // ------------------------------------------------------------------------- -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:: @@ -133,15 +150,18 @@ GetGraph( ) const 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 @@ -301,16 +321,22 @@ Execute( const std::string& name, QWidget* p ) 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$ diff --git a/lib/cpPlugins/Interface/Workspace.h b/lib/cpPlugins/Interface/Workspace.h index 6618644..9a79d29 100644 --- a/lib/cpPlugins/Interface/Workspace.h +++ b/lib/cpPlugins/Interface/Workspace.h @@ -41,14 +41,8 @@ namespace cpPlugins 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 ); @@ -82,10 +76,7 @@ namespace cpPlugins 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; diff --git a/lib/cpPlugins/Interface/WorkspaceIO.cxx b/lib/cpPlugins/Interface/WorkspaceIO.cxx index d1578ba..ce81b86 100644 --- a/lib/cpPlugins/Interface/WorkspaceIO.cxx +++ b/lib/cpPlugins/Interface/WorkspaceIO.cxx @@ -14,51 +14,25 @@ LoadWorkspace( const std::string& fname ) 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" ); @@ -162,19 +136,6 @@ SaveWorkspace( const std::string& fname ) const 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 ) @@ -184,8 +145,10 @@ SaveWorkspace( const std::string& fname ) const 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; diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.h index 3ad43fe..92151bb 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryErodeImageFilter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::BinaryErodeImageFilter, - "ImageToBinaryImageFilter" + ImageToBinaryImageFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.h index 6f83314..38ec83a 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/BinaryThresholdImageFilter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::BinaryThresholdImageFilter, - "ImageToBinaryImageFilter" + ImageToBinaryImageFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/Cutter.h b/lib/cpPlugins/Plugins/BasicFilters/Cutter.h index 8374bbc..8f67a48 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/Cutter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/Cutter.h @@ -23,8 +23,7 @@ namespace cpPlugins itkNewMacro( Self ); itkTypeMacro( Cutter, cpPluginsInterfaceMeshToMeshFilter ); cpPlugins_Id_Macro( - cpPlugins::BasicFilters::Cutter, - "MeshToMeshFilter" + cpPlugins::BasicFilters::Cutter, MeshToMeshFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/DoubleFloodImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/DoubleFloodImageFilter.h index 730ffff..3a887d0 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/DoubleFloodImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/DoubleFloodImageFilter.h @@ -65,7 +65,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::DoubleFloodImageFilter, - "ImageToBinaryImageFilter" + ImageToBinaryImageFilter ); public: diff --git a/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.h index 39414eb..e28ea6c 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/ExtractSliceImageFilter.h @@ -26,7 +26,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::ExtractSliceImageFilter, - "ImageToImageFilter" + ImageToImageFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.h index d6d61ea..1f70e93 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/FloodFillImageFilter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::FloodFillImageFilter, - "ImageToBinaryImageFilter" + ImageToBinaryImageFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h index ecd2ce6..a7461e1 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h @@ -76,7 +76,7 @@ namespace cpPlugins itkNewMacro( Self ); itkTypeMacro( MacheteFilter, FilterObject ); cpPlugins_Id_Macro( - cpPlugins::BasicFilters::MacheteFilter, "FilterObject" + cpPlugins::BasicFilters::MacheteFilter, FilterObject ); public: diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.h index 267f970..e0208de 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/MacheteImageFilter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::MacheteImageFilter, - "ImageToBinaryImageFilter" + ImageToBinaryImageFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.h b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.h index 2e664e5..d4b45b1 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.h +++ b/lib/cpPlugins/Plugins/BasicFilters/MarchingCubes.h @@ -23,7 +23,7 @@ namespace cpPlugins itkNewMacro( Self ); itkTypeMacro( MarchingCubes, cpPluginsInterfaceImageToMeshFilter ); cpPlugins_Id_Macro( - cpPlugins::BasicFilters::MarchingCubes, "ImageToMeshFilter" + cpPlugins::BasicFilters::MarchingCubes, ImageToMeshFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.h index c036a1e..f7034d3 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/MedianImageFilter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::MedianImageFilter, - "ImageToBinaryImageFilter" + ImageToBinaryImageFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.h b/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.h index 671acb5..2e6f852 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/OtsuThresholdImageFilter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::OtsuThresholdImageFilter, - "ImageToBinaryImageFilter" + ImageToBinaryImageFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.h b/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.h index 4a42a5d..9440cd0 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/RGBImageToOtherChannelsFilter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); cpPlugins_Id_Macro( cpPlugins::BasicFilters::RGBImageToOtherChannelsFilter, - "ImageToImageFilter" + ImageToImageFilter ); protected: diff --git a/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.h b/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.h index 5789134..ef180ff 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.h +++ b/lib/cpPlugins/Plugins/BasicFilters/SphereMeshSource.h @@ -23,7 +23,7 @@ namespace cpPlugins itkNewMacro( Self ); itkTypeMacro( SphereMeshSource, cpPluginsInterfaceMeshSource ); cpPlugins_Id_Macro( - cpPlugins::BasicFilters::SphereMeshSource, "MeshSource" + cpPlugins::BasicFilters::SphereMeshSource, MeshSource ); protected: diff --git a/lib/cpPlugins/Plugins/IO/DicomSeriesReader.h b/lib/cpPlugins/Plugins/IO/DicomSeriesReader.h index c74d52a..fb8edb0 100644 --- a/lib/cpPlugins/Plugins/IO/DicomSeriesReader.h +++ b/lib/cpPlugins/Plugins/IO/DicomSeriesReader.h @@ -32,7 +32,7 @@ namespace cpPlugins 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 ); diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.h b/lib/cpPlugins/Plugins/IO/ImageReader.h index 50f0b0a..520ab94 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.h +++ b/lib/cpPlugins/Plugins/IO/ImageReader.h @@ -32,7 +32,7 @@ namespace cpPlugins 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 ); diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.h b/lib/cpPlugins/Plugins/IO/ImageWriter.h index 5394749..0dd3a25 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.h +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.h @@ -22,7 +22,7 @@ namespace cpPlugins 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 ); diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.h b/lib/cpPlugins/Plugins/IO/MeshReader.h index 6e18ff9..c26c3ae 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.h +++ b/lib/cpPlugins/Plugins/IO/MeshReader.h @@ -24,7 +24,7 @@ namespace cpPlugins 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 ); diff --git a/lib/cpPlugins/Plugins/IO/MeshWriter.h b/lib/cpPlugins/Plugins/IO/MeshWriter.h index 51224fe..2dc64a6 100644 --- a/lib/cpPlugins/Plugins/IO/MeshWriter.h +++ b/lib/cpPlugins/Plugins/IO/MeshWriter.h @@ -24,7 +24,7 @@ namespace cpPlugins 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 ); -- 2.45.2