2 #include "ui_MainWnd.h"
8 // -------------------------------------------------------------------------
13 this->m_Plugins.UnloadAll( );
14 this->m_BaseClasses.clear( );
15 this->m_SegmentationClasses.clear( );
16 this->m_SegmentationFilterClasses.clear( );
17 this->m_MeshFilterClasses.clear( );
19 // Read file and load plugins
20 std::ifstream in( this->m_PluginsConfigurationFile.c_str( ) );
23 this->m_LastOpenedFile = this->m_PluginsConfigurationFile;
24 std::string line, actual_section = "";
25 std::getline( in, line );
26 while( !( in.eof( ) ) )
28 std::string clean_line = line;
30 std::remove_if( clean_line.begin( ), clean_line.end( ), isspace ),
34 clean_line != "sectionplugins" &&
35 clean_line != "sectionbase_classes" &&
36 clean_line != "sectionsegmentation_classes" &&
37 clean_line != "sectionsegmentation_filter_classes" &&
38 clean_line != "sectionmesh_filter_classes"
41 if( clean_line != "" )
43 if( actual_section == "sectionplugins" )
45 if( !( this->m_Plugins.Load( clean_line ) ) )
49 tr( "Ignoring plugin" ),
50 tr( clean_line.c_str( ) )
58 clean_line.substr( clean_line.find_last_of( ":" ) + 1 );
59 if( actual_section == "sectionbase_classes" )
60 this->m_BaseClasses[ name ] = clean_line;
61 else if( actual_section == "sectionsegmentation_classes" )
62 this->m_SegmentationClasses[ name ] = clean_line;
63 else if( actual_section == "sectionsegmentation_filter_classes" )
64 this->m_SegmentationFilterClasses[ name ] = clean_line;
65 else if( actual_section == "sectionmesh_filter_classes" )
66 this->m_MeshFilterClasses[ name ] = clean_line;
72 else if( clean_line != "" )
74 if( clean_line[ 0 ] != '#' )
75 actual_section = clean_line;
79 std::getline( in, line );
84 // Check classes existence
85 if( !( this->_CheckClassesInPlugins( this->m_BaseClasses ) ) )
87 QMessageBox::critical(
89 tr( "Could not load all base plugins." ),
90 tr( "Could not load all base plugins... Closing application!" )
96 // Needed object from plugins
103 this->m_ImageReaderClassName = "";
104 this->m_ImageSeriesReaderClassName = "";
105 this->m_ImageWriterClassName = "";
110 std::getline( in, plugin );
111 while( !( in.eof( ) ) )
113 if( this->m_Plugins.Load( plugin ) )
115 TPluginsInterface::TClassesIterator cIt =
116 this->m_Plugins.GetClasses( ).begin( );
117 TPluginsInterface::TClassesIterator end_cIt =
118 this->m_Plugins.GetClasses( ).end( );
119 for( ; cIt != end_cIt; ++cIt )
121 std::string c_name = cIt->first;
122 c_name = c_name.substr( c_name.find_last_of( ":" ) + 1 );
123 if( c_name == "ImageReader" )
125 this->m_ImageReaderClassName = cIt->first;
127 else if( c_name == "ImageSeriesReader" )
129 this->m_ImageSeriesReaderClassName = cIt->first;
131 else if( c_name == "ImageWriter" )
133 this->m_ImageWriterClassName = cIt->first;
141 TFilterPlugins::TClassesIterator cIt =
142 this->m_Plugins.BeginClasses( );
143 for( ; cIt != this->m_Plugins.EndClasses( ); ++cIt )
145 TFilterObject* filter =
146 this->m_Plugins.CreateObject( cIt->first );
149 std::string cat = filter->GetCategory( );
150 std::string catType = cat.substr( cat.find_last_of( ":" ) );
151 if( catType == ":BinaryImageToBinaryImageFilter" )
153 QAction* action = this->m_UI->menuFilterSegmentedImage->
154 addAction( QString( cIt->first.c_str( ) ) );
156 action, SIGNAL( triggered( ) ),
157 this, SLOT( triggered_aFilterSegmentedImage( ) )
160 else if( catType == ":ImageToMeshFilter" )
162 QAction* action = this->m_UI->menuExtractMesh->
163 addAction( QString( cIt->first.c_str( ) ) );
165 action, SIGNAL( triggered( ) ),
166 this, SLOT( triggered_aSegmentedImageToMesh( ) )
175 QMessageBox::warning(
177 tr( "Ignoring plugin" ),
178 tr( plugin.c_str( ) )
182 std::getline( in, plugin );
188 QMessageBox::critical(
190 tr( "No plugins file loaded!" ),
191 tr( this->m_PluginsConfigurationFile.c_str( ) )
197 if( this->m_ImageReaderClassName == "" )
199 QMessageBox::critical(
201 tr( "No ImageReader found in plugins!" ),
202 tr( this->m_PluginsConfigurationFile.c_str( ) )
207 if( this->m_ImageWriterClassName == "" )
209 QMessageBox::critical(
211 tr( "No ImageWriter found in plugins!" ),
212 tr( this->m_PluginsConfigurationFile.c_str( ) )
216 this->_UpdateEnabledFlags( );
220 // -------------------------------------------------------------------------
222 _CheckClassesInPlugins( const TStringMap& classes )
225 TStringMap::const_iterator cIt = classes.begin( );
226 for( ; cIt != classes.end( ); ++cIt )
228 TPluginObject* o = this->m_Plugins.CreateObject( cIt->second );