X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FInteractiveDeformableMeshSegmentation%2FMainWnd_LoadPlugins.cxx;fp=appli%2FInteractiveDeformableMeshSegmentation%2FMainWnd_LoadPlugins.cxx;h=8f673c1a638095a6d6c1088a1b4b9d50e54e973d;hb=6d6bf5d5e3b9318a507216f2f231c32299d1a941;hp=0000000000000000000000000000000000000000;hpb=de28025e5f1835fba69cb0a6666d02f0b7daec0d;p=cpMesh.git diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd_LoadPlugins.cxx b/appli/InteractiveDeformableMeshSegmentation/MainWnd_LoadPlugins.cxx new file mode 100644 index 0000000..8f673c1 --- /dev/null +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd_LoadPlugins.cxx @@ -0,0 +1,238 @@ +#include "MainWnd.h" +#include "ui_MainWnd.h" + +#include +#include +#include + +// ------------------------------------------------------------------------- +bool MainWnd:: +_LoadPlugins( ) +{ + // Clear states + this->m_Plugins.UnloadAll( ); + this->m_BaseClasses.clear( ); + this->m_SegmentationClasses.clear( ); + this->m_SegmentationFilterClasses.clear( ); + this->m_MeshFilterClasses.clear( ); + + // Read file and load plugins + std::ifstream in( this->m_PluginsConfigurationFile.c_str( ) ); + if( !in ) + return( false ); + this->m_LastOpenedFile = this->m_PluginsConfigurationFile; + std::string line, actual_section = ""; + std::getline( in, line ); + while( !( in.eof( ) ) ) + { + std::string clean_line = line; + clean_line.erase( + std::remove_if( clean_line.begin( ), clean_line.end( ), isspace ), + clean_line.end( ) + ); + if( + clean_line != "sectionplugins" && + clean_line != "sectionbase_classes" && + clean_line != "sectionsegmentation_classes" && + clean_line != "sectionsegmentation_filter_classes" && + clean_line != "sectionmesh_filter_classes" + ) + { + if( clean_line != "" ) + { + if( actual_section == "sectionplugins" ) + { + if( !( this->m_Plugins.Load( clean_line ) ) ) + { + QMessageBox::warning( + this, + tr( "Ignoring plugin" ), + tr( clean_line.c_str( ) ) + ); + + } // fi + } + else + { + std::string name = + clean_line.substr( clean_line.find_last_of( ":" ) + 1 ); + if( actual_section == "sectionbase_classes" ) + this->m_BaseClasses[ name ] = clean_line; + else if( actual_section == "sectionsegmentation_classes" ) + this->m_SegmentationClasses[ name ] = clean_line; + else if( actual_section == "sectionsegmentation_filter_classes" ) + this->m_SegmentationFilterClasses[ name ] = clean_line; + else if( actual_section == "sectionmesh_filter_classes" ) + this->m_MeshFilterClasses[ name ] = clean_line; + + } // fi + + } // fi + } + else if( clean_line != "" ) + { + if( clean_line[ 0 ] != '#' ) + actual_section = clean_line; + + } // fi + + std::getline( in, line ); + + } // elihw + in.close( ); + + // Check classes existence + if( !( this->_CheckClassesInPlugins( this->m_BaseClasses ) ) ) + { + QMessageBox::critical( + this, + tr( "Could not load all base plugins." ), + tr( "Could not load all base plugins... Closing application!" ) + ); + std::exit( 1 ); + + } // fi + + // Needed object from plugins + + // Historic objects + + + + /* + this->m_ImageReaderClassName = ""; + this->m_ImageSeriesReaderClassName = ""; + this->m_ImageWriterClassName = ""; + + if( in ) + { + std::string plugin; + std::getline( in, plugin ); + while( !( in.eof( ) ) ) + { + if( this->m_Plugins.Load( plugin ) ) + { + TPluginsInterface::TClassesIterator cIt = + this->m_Plugins.GetClasses( ).begin( ); + TPluginsInterface::TClassesIterator end_cIt = + this->m_Plugins.GetClasses( ).end( ); + for( ; cIt != end_cIt; ++cIt ) + { + std::string c_name = cIt->first; + c_name = c_name.substr( c_name.find_last_of( ":" ) + 1 ); + if( c_name == "ImageReader" ) + { + this->m_ImageReaderClassName = cIt->first; + } + else if( c_name == "ImageSeriesReader" ) + { + this->m_ImageSeriesReaderClassName = cIt->first; + } + else if( c_name == "ImageWriter" ) + { + this->m_ImageWriterClassName = cIt->first; + } + else + { + } // fi + + } // rof + + TFilterPlugins::TClassesIterator cIt = + this->m_Plugins.BeginClasses( ); + for( ; cIt != this->m_Plugins.EndClasses( ); ++cIt ) + { + TFilterObject* filter = + this->m_Plugins.CreateObject( cIt->first ); + if( filter == NULL ) + continue; + std::string cat = filter->GetCategory( ); + std::string catType = cat.substr( cat.find_last_of( ":" ) ); + if( catType == ":BinaryImageToBinaryImageFilter" ) + { + QAction* action = this->m_UI->menuFilterSegmentedImage-> + addAction( QString( cIt->first.c_str( ) ) ); + QObject::connect( + action, SIGNAL( triggered( ) ), + this, SLOT( triggered_aFilterSegmentedImage( ) ) + ); + } + else if( catType == ":ImageToMeshFilter" ) + { + QAction* action = this->m_UI->menuExtractMesh-> + addAction( QString( cIt->first.c_str( ) ) ); + QObject::connect( + action, SIGNAL( triggered( ) ), + this, SLOT( triggered_aSegmentedImageToMesh( ) ) + ); + + } // fi + delete filter; + } // rof + } + else + { + QMessageBox::warning( + this, + tr( "Ignoring plugin" ), + tr( plugin.c_str( ) ) + ); + + } // fi + std::getline( in, plugin ); + + } // elihw + } + else + { + QMessageBox::critical( + this, + tr( "No plugins file loaded!" ), + tr( this->m_PluginsConfigurationFile.c_str( ) ) + ); + + } // fi + in.close( ); + + if( this->m_ImageReaderClassName == "" ) + { + QMessageBox::critical( + this, + tr( "No ImageReader found in plugins!" ), + tr( this->m_PluginsConfigurationFile.c_str( ) ) + ); + + } // fi + + if( this->m_ImageWriterClassName == "" ) + { + QMessageBox::critical( + this, + tr( "No ImageWriter found in plugins!" ), + tr( this->m_PluginsConfigurationFile.c_str( ) ) + ); + + } // fi + this->_UpdateEnabledFlags( ); + */ + } + +// ------------------------------------------------------------------------- +bool MainWnd:: +_CheckClassesInPlugins( const TStringMap& classes ) +{ + bool r = true; + TStringMap::const_iterator cIt = classes.begin( ); + for( ; cIt != classes.end( ); ++cIt ) + { + TPluginObject* o = this->m_Plugins.CreateObject( cIt->second ); + if( o != NULL ) + delete o; + else + r &= false; + + } // rof + return( r ); +} + +// eof - $RCSfile$