2 #include "ui_ImageMPR.h"
7 // -------------------------------------------------------------------------
8 #define ImageMPR_ConnectAction( ACTION ) \
10 this->m_UI->a##ACTION, SIGNAL( triggered( ) ), \
11 this, SLOT( _a##ACTION( ) ) \
14 // -------------------------------------------------------------------------
16 ImageMPR( QWidget* parent )
17 : QMainWindow( parent ),
18 m_UI( new Ui::ImageMPR )
20 this->m_UI->setupUi( this );
21 this->m_Plugins.SetWidget( this );
22 this->m_Plugins.SetApplication( this );
25 ImageMPR_ConnectAction( OpenImage );
26 ImageMPR_ConnectAction( OpenDICOMSeries );
27 ImageMPR_ConnectAction( OpenSegmentation );
28 ImageMPR_ConnectAction( OpenPolyData );
29 ImageMPR_ConnectAction( SaveImage );
30 ImageMPR_ConnectAction( SavePolyData );
31 ImageMPR_ConnectAction( Undo );
32 ImageMPR_ConnectAction( Redo );
33 ImageMPR_ConnectAction( LoadPlugins );
34 ImageMPR_ConnectAction( ShowPlugins );
36 // Associate model with view
37 for( unsigned int i = 0; i < 4; ++i )
38 this->m_Plugins.AddInteractor( this->m_UI->MPR->GetInteractor( i ) );
40 // Try to load default plugins
41 QStringList args = QApplication::arguments( );
42 QFileInfo info( args.at( 0 ) );
43 this->m_Plugins.LoadPluginsPath(
44 info.absolutePath( ).toStdString( ), true
47 // Put loaded plugins into menu
48 this->_AssociatePluginsToMenu( );
51 // -------------------------------------------------------------------------
58 // -------------------------------------------------------------------------
62 if( !( this->m_Plugins.HasActiveFilter( ) ) )
66 TPlugins::TStringContainer outputs;
69 this->m_Plugins.UpdateActiveFilter(
70 outputs, this->m_ActiveFilterMainInput
77 for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
79 std::string parent = this->m_Plugins.GetParent( *oIt );
80 TDataObject* dobj = this->m_Plugins.GetData< TDataObject >( *oIt );
81 if( this->m_UI->MPR->AddData( dobj, *oIt, parent ) )
82 this->m_UI->MPR->ShowData( *oIt );
87 // -------------------------------------------------------------------------
89 _AssociatePluginsToMenu( )
91 this->m_UI->MenuFilters->clear( );
93 TPlugins::TStringContainer categories;
94 this->m_Plugins.GetLoadedCategories( categories );
95 for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt )
97 QMenu* category = this->m_UI->MenuFilters->addMenu( cIt->c_str( ) );
98 const TPlugins::TStringContainer& filters =
99 this->m_Plugins.GetLoadedFilters( *cIt );
100 for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt )
102 QAction* filter = category->addAction( fIt->c_str( ) );
104 filter, SIGNAL( triggered( ) ),
105 this, SLOT( _execPlugin( ) )
113 // -------------------------------------------------------------------------
114 #define ImageMPR_ReadImage( F ) \
115 this->m_UI->MPR->DeleteAllData( ); \
116 this->m_Plugins.ClearDataObjects( ); \
119 std::string name = this->m_Plugins.Read##F( "" ); \
122 TImage* image = this->m_Plugins.GetData< TImage >( name ); \
123 this->m_UI->MPR->AddData( image, name, "" ); \
124 this->m_UI->MPR->SetMainImage( name ); \
125 this->m_UI->MPR->ShowData( name ); \
127 catch( std::exception& err ) \
129 QMessageBox::critical( \
131 QMessageBox::tr( "Error reading image." ), \
132 QMessageBox::tr( err.what( ) ) \
136 void ImageMPR::_aOpenImage( ) { ImageMPR_ReadImage( Image ) }
137 void ImageMPR::_aOpenDICOMSeries( ) { ImageMPR_ReadImage( DicomSeries ) }
139 // -------------------------------------------------------------------------
141 _aOpenSegmentation( )
145 std::string parent = this->m_UI->MPR->GetMainImage( );
146 std::string name = this->m_Plugins.ReadImage( parent );
149 TImage* image = this->m_Plugins.GetData< TImage >( name );
150 this->m_UI->MPR->AddData( image, name, parent );
151 this->m_UI->MPR->ShowData( name );
153 catch( std::exception& err )
155 QMessageBox::critical(
157 QMessageBox::tr( "Error reading image." ),
158 QMessageBox::tr( err.what( ) )
164 // -------------------------------------------------------------------------
170 // -------------------------------------------------------------------------
174 this->m_Plugins.WriteDataObject( this->m_UI->MPR->GetSelectedData( ) );
177 // -------------------------------------------------------------------------
183 // -------------------------------------------------------------------------
189 // -------------------------------------------------------------------------
195 // -------------------------------------------------------------------------
199 this->m_Plugins.DialogLoadPlugins( );
200 this->_AssociatePluginsToMenu( );
203 // -------------------------------------------------------------------------
209 // -------------------------------------------------------------------------
214 QAction* action = dynamic_cast< QAction* >( this->sender( ) );
217 std::string filter_name = action->text( ).toStdString( );
220 if( !( this->m_Plugins.ActivateFilter( filter_name ) ) )
224 TPlugins::TStringContainer inputs;
225 this->m_Plugins.GetActiveFilterInputsNames( inputs );
228 if( inputs.size( ) > 1 )
232 else if( inputs.size( ) == 1 )
234 this->m_ActiveFilterMainInput = this->m_UI->MPR->GetSelectedData( );
235 this->m_Plugins.ConnectInputInActiveFilter(
236 this->m_ActiveFilterMainInput, *( inputs.begin( ) )
241 // Configure paramereters
242 auto dlg_res = this->m_Plugins.ConfigureActiveFilter( );
243 if( dlg_res == TPlugins::TProcessObject::DialogResult_Cancel )
245 // Just deactivate filter, since it was canceled
246 this->m_Plugins.DeactivateFilter( );
249 else if( dlg_res == TPlugins::TProcessObject::DialogResult_NoModal )
251 // Execute automatic filter and associate outputs
252 this->UpdateActualFilter( );
253 this->m_Plugins.DeactivateFilter( );