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 ),
33 if( clean_line[ 0 ] != '#' )
36 clean_line != "sectionplugins" &&
37 clean_line != "sectionbase_classes" &&
38 clean_line != "sectionsegmentation_classes" &&
39 clean_line != "sectionsegmentation_filter_classes" &&
40 clean_line != "sectionmesh_filter_classes"
43 if( clean_line != "" )
45 if( actual_section == "sectionplugins" )
47 if( !( this->m_Plugins.Load( clean_line ) ) )
51 tr( "Ignoring plugin" ),
52 tr( clean_line.c_str( ) )
60 clean_line.substr( clean_line.find_last_of( ":" ) + 1 );
61 if( actual_section == "sectionbase_classes" )
62 this->m_BaseClasses[ name ] = clean_line;
63 else if( actual_section == "sectionsegmentation_classes" )
64 this->m_SegmentationClasses[ name ] = clean_line;
65 else if( actual_section == "sectionsegmentation_filter_classes" )
66 this->m_SegmentationFilterClasses[ name ] = clean_line;
67 else if( actual_section == "sectionmesh_filter_classes" )
68 this->m_MeshFilterClasses[ name ] = clean_line;
74 else if( clean_line != "" )
76 if( clean_line[ 0 ] != '#' )
77 actual_section = clean_line;
82 std::getline( in, line );
87 // Check classes existence
88 if( !( this->_CheckClassesInPlugins( this->m_BaseClasses ) ) )
90 QMessageBox::critical(
92 tr( "Could not load all base plugins." ),
93 tr( "Could not load all base plugins... Closing application!" )
99 // Needed object from plugins
100 this->_AddPluginActions(
101 this->m_SegmentationClasses, this->m_UI->menuSegmentInputImage,
102 SLOT( _triggered_actionSegmentImage( ) )
104 this->_AddPluginActions(
105 this->m_SegmentationFilterClasses, this->m_UI->menuFilterSegmentedImage,
106 SLOT( _triggered_actionFilterSegmentation( ) )
108 this->_AddPluginActions(
109 this->m_MeshFilterClasses, this->m_UI->menuProcessMesh,
110 SLOT( _triggered_actionProcessMesh( ) )
118 this->m_ImageReaderClassName = "";
119 this->m_ImageSeriesReaderClassName = "";
120 this->m_ImageWriterClassName = "";
125 std::getline( in, plugin );
126 while( !( in.eof( ) ) )
128 if( this->m_Plugins.Load( plugin ) )
130 TPluginsInterface::TClassesIterator cIt =
131 this->m_Plugins.GetClasses( ).begin( );
132 TPluginsInterface::TClassesIterator end_cIt =
133 this->m_Plugins.GetClasses( ).end( );
134 for( ; cIt != end_cIt; ++cIt )
136 std::string c_name = cIt->first;
137 c_name = c_name.substr( c_name.find_last_of( ":" ) + 1 );
138 if( c_name == "ImageReader" )
140 this->m_ImageReaderClassName = cIt->first;
142 else if( c_name == "ImageSeriesReader" )
144 this->m_ImageSeriesReaderClassName = cIt->first;
146 else if( c_name == "ImageWriter" )
148 this->m_ImageWriterClassName = cIt->first;
156 TFilterPlugins::TClassesIterator cIt =
157 this->m_Plugins.BeginClasses( );
158 for( ; cIt != this->m_Plugins.EndClasses( ); ++cIt )
160 TFilterObject* filter =
161 this->m_Plugins.CreateObject( cIt->first );
164 std::string cat = filter->GetCategory( );
165 std::string catType = cat.substr( cat.find_last_of( ":" ) );
166 if( catType == ":BinaryImageToBinaryImageFilter" )
168 QAction* action = this->m_UI->menuFilterSegmentedImage->
169 addAction( QString( cIt->first.c_str( ) ) );
171 action, SIGNAL( triggered( ) ),
172 this, SLOT( triggered_aFilterSegmentedImage( ) )
175 else if( catType == ":ImageToMeshFilter" )
177 QAction* action = this->m_UI->menuExtractMesh->
178 addAction( QString( cIt->first.c_str( ) ) );
180 action, SIGNAL( triggered( ) ),
181 this, SLOT( triggered_aSegmentedImageToMesh( ) )
190 QMessageBox::warning(
192 tr( "Ignoring plugin" ),
193 tr( plugin.c_str( ) )
197 std::getline( in, plugin );
203 QMessageBox::critical(
205 tr( "No plugins file loaded!" ),
206 tr( this->m_PluginsConfigurationFile.c_str( ) )
212 if( this->m_ImageReaderClassName == "" )
214 QMessageBox::critical(
216 tr( "No ImageReader found in plugins!" ),
217 tr( this->m_PluginsConfigurationFile.c_str( ) )
222 if( this->m_ImageWriterClassName == "" )
224 QMessageBox::critical(
226 tr( "No ImageWriter found in plugins!" ),
227 tr( this->m_PluginsConfigurationFile.c_str( ) )
231 this->_UpdateEnabledFlags( );
235 // -------------------------------------------------------------------------
237 _CheckClassesInPlugins( const TStringMap& classes )
240 TStringMap::const_iterator cIt = classes.begin( );
241 for( ; cIt != classes.end( ); ++cIt )
243 TPluginObject* o = this->m_Plugins.CreateObject( cIt->second );
253 // -------------------------------------------------------------------------
256 const TStringMap& classes, QMenu* menu, const char* method
259 TStringMap::const_iterator clIt = classes.begin( );
260 for( ; clIt != classes.end( ); ++clIt )
262 QAction* action = menu->addAction( QString( clIt->first.c_str( ) ) );
263 QObject::connect( action, SIGNAL( triggered( ) ), this, method );