1 #include <cpPlugins/Interface/Plugins.h>
2 #include <cpPlugins/Interface/Config.h>
7 #ifdef cpPlugins_Interface_QT4
9 #include <QApplication>
10 #include <QFileDialog>
12 #include <QMessageBox>
16 # define PLUGIN_PREFIX ""
17 # define PLUGIN_EXT "dll"
18 # define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
20 # define PLUGIN_PREFIX "lib"
21 # define PLUGIN_EXT "so"
22 # define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
25 #endif // cpPlugins_Interface_QT4
27 // -------------------------------------------------------------------------
28 cpPlugins::Interface::Plugins::
29 Plugins( QWidget* widget )
31 m_Application( NULL ),
32 m_LastLoadedPlugin( "." )
36 // -------------------------------------------------------------------------
37 cpPlugins::Interface::Plugins::
40 // TODO: this causes a segfault? this->m_Interface.UnloadAll( );
43 // -------------------------------------------------------------------------
44 QWidget* cpPlugins::Interface::Plugins::
47 return( this->m_Widget );
50 // -------------------------------------------------------------------------
51 const QWidget* cpPlugins::Interface::Plugins::
54 return( this->m_Widget );
57 // -------------------------------------------------------------------------
58 void cpPlugins::Interface::Plugins::
59 SetWidget( QWidget* widget )
61 this->m_Widget = widget;
64 // -------------------------------------------------------------------------
65 void cpPlugins::Interface::Plugins::
68 #ifdef cpPlugins_Interface_QT4
69 if( this->m_Widget != NULL )
71 QApplication::setOverrideCursor( Qt::WaitCursor );
72 this->m_Widget->setEnabled( false );
75 #endif // cpPlugins_Interface_QT4
78 // -------------------------------------------------------------------------
79 void cpPlugins::Interface::Plugins::
82 #ifdef cpPlugins_Interface_QT4
83 if( this->m_Widget != NULL )
85 QApplication::restoreOverrideCursor( );
86 this->m_Widget->setEnabled( true );
89 #endif // cpPlugins_Interface_QT4
92 // -------------------------------------------------------------------------
93 void cpPlugins::Interface::Plugins::
96 #ifdef cpPlugins_Interface_QT4
97 if( this->m_Widget != NULL )
99 QFileDialog dialog( this->m_Widget );
100 dialog.setFileMode( QFileDialog::ExistingFile );
101 dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) );
102 dialog.setNameFilter( QFileDialog::tr( PLUGIN_REGEX ) );
103 dialog.setDefaultSuffix( QFileDialog::tr( PLUGIN_EXT ) );
104 if( !( dialog.exec( ) ) )
107 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
108 if( !( this->LoadPlugins( fname ) ) )
109 QMessageBox::critical(
111 QMessageBox::tr( "Ignoring plugin" ),
112 QMessageBox::tr( fname.c_str( ) )
116 #endif // cpPlugins_Interface_QT4
119 // -------------------------------------------------------------------------
120 void cpPlugins::Interface::Plugins::
121 AssociatePluginsToMenu( QMenu* menu, QObject* obj, const char* slot )
123 #ifdef cpPlugins_Interface_QT4
124 std::map< std::string, std::set< std::string > >::const_iterator i;
125 std::set< std::string >::const_iterator j;
128 for( i = this->m_Filters.begin( ); i != this->m_Filters.end( ); i++ )
130 QMenu* newMenu = menu->addMenu( i->first.c_str( ) );
131 for( j = i->second.begin( ); j != i->second.end( ); ++j )
133 QAction* a = newMenu->addAction( j->c_str( ) );
134 QObject::connect( a, SIGNAL( triggered( ) ), obj, slot );
139 #endif // cpPlugins_Interface_QT4
142 // -------------------------------------------------------------------------
143 cpPlugins::Interface::
144 BasePluginsApplication* cpPlugins::Interface::Plugins::
147 return( this->m_Application );
150 // -------------------------------------------------------------------------
151 const cpPlugins::Interface::
152 BasePluginsApplication* cpPlugins::Interface::Plugins::
153 GetApplication( ) const
155 return( this->m_Application );
158 // -------------------------------------------------------------------------
159 void cpPlugins::Interface::Plugins::
160 SetApplication( cpPlugins::Interface::BasePluginsApplication* a )
162 this->m_Application = a;
165 // -------------------------------------------------------------------------
166 bool cpPlugins::Interface::Plugins::
167 LoadPlugins( const std::string& fname )
169 this->BlockWidget( );
171 // Is it already loaded?
173 if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) )
175 // Was it succesfully loaded?
176 ret = this->m_Interface.Load( fname );
178 // Update a simple track
181 this->m_LoadedPlugins.insert( fname );
182 this->m_LastLoadedPlugin = fname;
183 this->_UpdateLoadedPluginsInformation( );
189 this->UnblockWidget( );
193 // -------------------------------------------------------------------------
194 bool cpPlugins::Interface::Plugins::
195 LoadPluginsConfigurationFile( const std::string& fname )
197 // Load file into a char buffer
199 fname.c_str( ), std::ios::in | std::ios::binary | std::ios::ate
204 std::streampos size = in.tellg( );
205 char* buffer = new char[ size ];
206 in.seekg( 0, std::ios::beg );
207 in.read( buffer, size );
211 std::stringstream in_stream( buffer );
215 in_stream.getline( line, 4096 );
216 this->LoadPlugins( line );
224 // -------------------------------------------------------------------------
225 void cpPlugins::Interface::Plugins::
226 AddInteractor( vtkRenderWindowInteractor* interactor )
228 this->m_Interactors.insert( interactor );
231 // -------------------------------------------------------------------------
232 void cpPlugins::Interface::Plugins::
233 RemoveInteractor( vtkRenderWindowInteractor* interactor )
235 this->m_Interactors.erase( interactor );
238 // -------------------------------------------------------------------------
239 void cpPlugins::Interface::Plugins::
242 this->m_Interactors.clear( );
245 // -------------------------------------------------------------------------
246 bool cpPlugins::Interface::Plugins::
247 HasImageReader( ) const
249 return( this->m_ImageReader.IsNotNull( ) );
252 // -------------------------------------------------------------------------
253 bool cpPlugins::Interface::Plugins::
254 HasDicomSeriesReader( ) const
256 return( this->m_DicomSeriesReader.IsNotNull( ) );
259 // -------------------------------------------------------------------------
260 bool cpPlugins::Interface::Plugins::
261 HasMeshReader( ) const
263 return( this->m_MeshReader.IsNotNull( ) );
266 // -------------------------------------------------------------------------
267 bool cpPlugins::Interface::Plugins::
268 HasImageWriter( ) const
270 return( this->m_ImageWriter.IsNotNull( ) );
273 // -------------------------------------------------------------------------
274 bool cpPlugins::Interface::Plugins::
275 HasMeshWriter( ) const
277 return( this->m_MeshWriter.IsNotNull( ) );
280 // -------------------------------------------------------------------------
281 std::string cpPlugins::Interface::Plugins::
282 ReadImage( const std::string& fname, const std::string& parent )
284 std::vector< std::string > fnames;
285 fnames.push_back( fname );
286 return( this->ReadImage( fnames, parent ) );
289 // -------------------------------------------------------------------------
290 std::string cpPlugins::Interface::Plugins::
292 const std::vector< std::string >& fnames, const std::string& parent
295 // Check if object exists
296 if( this->m_ImageReader.IsNull( ) )
300 TParameters* params = this->m_ImageReader->GetParameters( );
301 params->ClearStringList( "FileNames" );
302 auto i = fnames.begin( );
303 for( ; i != fnames.end( ); ++i )
304 params->AddToStringList( "FileNames", *i );
307 this->BlockWidget( );
308 std::string err = this->m_ImageReader->Update( );
309 this->UnblockWidget( );
311 // Get result, if any
314 TImage* image = this->m_ImageReader->GetOutput< TImage >( "Output" );
315 this->m_ImageReader->DisconnectOutputs( );
317 // Add newly added data
318 if( this->_InsertNewData( image, parent ) )
319 return( image->GetName( ) );
325 #ifdef cpPlugins_Interface_QT4
326 if( this->m_Widget != NULL )
327 QMessageBox::critical(
329 QMessageBox::tr( "Error reading image." ),
330 QMessageBox::tr( err.c_str( ) )
332 #else // cpPlugins_Interface_QT4
333 std::cerr << "Error reading image: " << err << std::endl;
334 #endif // cpPlugins_Interface_QT4
340 // -------------------------------------------------------------------------
341 std::string cpPlugins::Interface::Plugins::
342 ReadImage( const std::string& parent )
344 // Check if object exists
345 if( this->m_ImageReader.IsNull( ) )
349 TProcessObject::DialogResult dret =
350 this->m_ImageReader->ExecConfigurationDialog( this->m_Widget );
351 if( dret == TProcessObject::DialogResult_Cancel )
355 this->BlockWidget( );
356 std::string err = this->m_ImageReader->Update( );
357 this->UnblockWidget( );
359 // Get result, if any
362 TImage* image = this->m_ImageReader->GetOutput< TImage >( "Output" );
363 this->m_ImageReader->DisconnectOutputs( );
365 // Add newly added data
366 if( this->_InsertNewData( image, parent ) )
367 return( image->GetName( ) );
373 #ifdef cpPlugins_Interface_QT4
374 if( this->m_Widget != NULL )
375 QMessageBox::critical(
377 QMessageBox::tr( "Error reading image." ),
378 QMessageBox::tr( err.c_str( ) )
380 #else // cpPlugins_Interface_QT4
381 std::cerr << "Error reading image: " << err << std::endl;
382 #endif // cpPlugins_Interface_QT4
388 // -------------------------------------------------------------------------
389 std::string cpPlugins::Interface::Plugins::
390 ReadDicomSeries( const std::string& parent )
392 // Check if object exists
393 if( this->m_DicomSeriesReader.IsNull( ) )
397 TProcessObject::DialogResult dret =
398 this->m_DicomSeriesReader->ExecConfigurationDialog( this->m_Widget );
399 if( dret == TProcessObject::DialogResult_Cancel )
403 this->BlockWidget( );
404 std::string err = this->m_DicomSeriesReader->Update( );
405 this->UnblockWidget( );
407 // Get result, if any
411 this->m_DicomSeriesReader->GetOutput< TImage >( "Output" );
412 this->m_DicomSeriesReader->DisconnectOutputs( );
414 // Add newly added data
415 if( this->_InsertNewData( image, parent ) )
416 return( image->GetName( ) );
422 #ifdef cpPlugins_Interface_QT4
423 if( this->m_Widget != NULL )
424 QMessageBox::critical(
426 QMessageBox::tr( "Error reading image." ),
427 QMessageBox::tr( err.c_str( ) )
429 #else // cpPlugins_Interface_QT4
430 std::cerr << "Error reading image: " << err << std::endl;
431 #endif // cpPlugins_Interface_QT4
437 // -------------------------------------------------------------------------
438 std::string cpPlugins::Interface::Plugins::
439 ReadMesh( const std::string& fname, const std::string& parent )
441 // Check if object exists
442 if( this->m_MeshReader.IsNull( ) )
446 TParameters* params = this->m_MeshReader->GetParameters( );
447 params->SetString( "FileName", fname );
450 this->BlockWidget( );
451 std::string err = this->m_MeshReader->Update( );
452 this->UnblockWidget( );
454 // Get result, if any
457 TMesh* mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" );
458 this->m_MeshReader->DisconnectOutputs( );
460 // Add newly added data
461 if( this->_InsertNewData( mesh, parent ) )
462 return( mesh->GetName( ) );
468 #ifdef cpPlugins_Interface_QT4
469 if( this->m_Widget != NULL )
470 QMessageBox::critical(
472 QMessageBox::tr( "Error reading mesh." ),
473 QMessageBox::tr( err.c_str( ) )
475 #else // cpPlugins_Interface_QT4
476 std::cerr << "Error reading mesh: " << err << std::endl;
477 #endif // cpPlugins_Interface_QT4
483 // -------------------------------------------------------------------------
484 std::string cpPlugins::Interface::Plugins::
485 ReadMesh( const std::string& parent )
487 // Check if object exists
488 if( this->m_MeshReader.IsNull( ) )
492 TProcessObject::DialogResult dret =
493 this->m_MeshReader->ExecConfigurationDialog( this->m_Widget );
494 if( dret == TProcessObject::DialogResult_Cancel )
498 this->BlockWidget( );
499 std::string err = this->m_MeshReader->Update( );
500 this->UnblockWidget( );
502 // Get result, if any
505 TMesh* mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" );
506 this->m_MeshReader->DisconnectOutputs( );
508 // Add newly added data
509 if( this->_InsertNewData( mesh, parent ) )
510 return( mesh->GetName( ) );
516 #ifdef cpPlugins_Interface_QT4
517 if( this->m_Widget != NULL )
518 QMessageBox::critical(
520 QMessageBox::tr( "Error reading mesh." ),
521 QMessageBox::tr( err.c_str( ) )
523 #else // cpPlugins_Interface_QT4
524 std::cerr << "Error reading mesh: " << err << std::endl;
525 #endif // cpPlugins_Interface_QT4
531 // -------------------------------------------------------------------------
532 bool cpPlugins::Interface::Plugins::
533 WriteImage( const std::string& fname, const std::string& name )
535 // Check if objects exist
536 if( this->m_ImageWriter.IsNull( ) )
538 TImage* image = this->GetImage( name );
543 this->m_ImageWriter->GetParameters( )->SetString( "FileName", fname );
544 this->m_ImageWriter->SetInput( "Input", image );
547 this->BlockWidget( );
548 std::string err = this->m_ImageWriter->Update( );
549 this->UnblockWidget( );
551 // Get result, if any
554 #ifdef cpPlugins_Interface_QT4
555 if( this->m_Widget != NULL )
556 QMessageBox::critical(
558 QMessageBox::tr( "Error reading mesh." ),
559 QMessageBox::tr( err.c_str( ) )
561 #else // cpPlugins_Interface_QT4
562 std::cerr << "Error reading mesh: " << err << std::endl;
563 #endif // cpPlugins_Interface_QT4
570 // -------------------------------------------------------------------------
571 bool cpPlugins::Interface::Plugins::
572 WriteImage( const std::string& name )
574 // Check if objects exist
575 if( this->m_ImageWriter.IsNull( ) )
577 TImage* image = this->GetImage( name );
582 TProcessObject::DialogResult dret =
583 this->m_ImageWriter->ExecConfigurationDialog( this->m_Widget );
584 if( dret == TProcessObject::DialogResult_Cancel )
586 this->m_ImageWriter->SetInput( "Input", image );
589 this->BlockWidget( );
590 std::string err = this->m_ImageWriter->Update( );
591 this->UnblockWidget( );
593 // Get result, if any
596 #ifdef cpPlugins_Interface_QT4
597 if( this->m_Widget != NULL )
598 QMessageBox::critical(
600 QMessageBox::tr( "Error reading mesh." ),
601 QMessageBox::tr( err.c_str( ) )
603 #else // cpPlugins_Interface_QT4
604 std::cerr << "Error reading mesh: " << err << std::endl;
605 #endif // cpPlugins_Interface_QT4
612 // -------------------------------------------------------------------------
613 bool cpPlugins::Interface::Plugins::
614 WriteMesh( const std::string& fname, const std::string& name )
616 // Check if objects exist
617 if( this->m_MeshWriter.IsNull( ) )
619 TMesh* mesh = this->GetMesh( name );
624 this->m_MeshWriter->GetParameters( )->SetString( "FileName", fname );
625 this->m_MeshWriter->SetInput( "Input", mesh );
628 this->BlockWidget( );
629 std::string err = this->m_MeshWriter->Update( );
630 this->UnblockWidget( );
632 // Get result, if any
635 #ifdef cpPlugins_Interface_QT4
636 if( this->m_Widget != NULL )
637 QMessageBox::critical(
639 QMessageBox::tr( "Error reading mesh." ),
640 QMessageBox::tr( err.c_str( ) )
642 #else // cpPlugins_Interface_QT4
643 std::cerr << "Error reading mesh: " << err << std::endl;
644 #endif // cpPlugins_Interface_QT4
651 // -------------------------------------------------------------------------
652 bool cpPlugins::Interface::Plugins::
653 WriteMesh( const std::string& name )
655 // Check if objects exist
656 if( this->m_MeshWriter.IsNull( ) )
658 TMesh* mesh = this->GetMesh( name );
663 TProcessObject::DialogResult dret =
664 this->m_MeshWriter->ExecConfigurationDialog( this->m_Widget );
665 if( dret == TProcessObject::DialogResult_Cancel )
667 this->m_MeshWriter->SetInput( "Input", mesh );
670 this->BlockWidget( );
671 std::string err = this->m_MeshWriter->Update( );
672 this->UnblockWidget( );
674 // Get result, if any
677 #ifdef cpPlugins_Interface_QT4
678 if( this->m_Widget != NULL )
679 QMessageBox::critical(
681 QMessageBox::tr( "Error reading mesh." ),
682 QMessageBox::tr( err.c_str( ) )
684 #else // cpPlugins_Interface_QT4
685 std::cerr << "Error reading mesh: " << err << std::endl;
686 #endif // cpPlugins_Interface_QT4
693 // -------------------------------------------------------------------------
694 void cpPlugins::Interface::Plugins::
697 this->m_Objects.clear( );
700 // -------------------------------------------------------------------------
701 void cpPlugins::Interface::Plugins::
702 DeleteDataObject( const std::string& name )
704 auto i = this->m_Objects.find( name );
705 if( i != this->m_Objects.end( ) )
707 this->m_Objects.erase( i );
710 std::vector< std::string > children;
711 for( i = this->m_Objects.begin( ); i != this->m_Objects.end( ); ++i )
712 if( i->second.first == name )
713 children.push_back( i->first );
716 auto c = children.begin( );
717 for( ; c != children.end( ); ++c )
718 this->DeleteDataObject( *c );
723 // -------------------------------------------------------------------------
724 std::string cpPlugins::Interface::Plugins::
725 GetParent( const std::string& name ) const
727 auto i = this->m_Objects.find( name );
728 if( i != this->m_Objects.end( ) )
729 return( i->second.first );
734 // -------------------------------------------------------------------------
735 const cpPlugins::Interface::Plugins::
736 TTree& cpPlugins::Interface::Plugins::
737 GetDataObjects( ) const
739 return( this->m_Objects );
742 // -------------------------------------------------------------------------
743 cpPlugins::Interface::Plugins::
744 TDataObject* cpPlugins::Interface::Plugins::
745 GetDataObject( const std::string& name )
747 auto i = this->m_Objects.find( name );
748 if( i != this->m_Objects.end( ) )
749 return( dynamic_cast< TDataObject* >( i->second.second.GetPointer( ) ) );
754 // -------------------------------------------------------------------------
755 const cpPlugins::Interface::Plugins::
756 TDataObject* cpPlugins::Interface::Plugins::
757 GetDataObject( const std::string& name ) const
759 auto i = this->m_Objects.find( name );
760 if( i != this->m_Objects.end( ) )
762 dynamic_cast< const TDataObject* >( i->second.second.GetPointer( ) )
768 // -------------------------------------------------------------------------
769 cpPlugins::Interface::Plugins::
770 TImage* cpPlugins::Interface::Plugins::
771 GetImage( const std::string& name )
773 auto i = this->m_Objects.find( name );
774 if( i != this->m_Objects.end( ) )
775 return( dynamic_cast< TImage* >( i->second.second.GetPointer( ) ) );
780 // -------------------------------------------------------------------------
781 const cpPlugins::Interface::Plugins::
782 TImage* cpPlugins::Interface::Plugins::
783 GetImage( const std::string& name ) const
785 auto i = this->m_Objects.find( name );
786 if( i != this->m_Objects.end( ) )
787 return( dynamic_cast< const TImage* >( i->second.second.GetPointer( ) ) );
792 // -------------------------------------------------------------------------
793 cpPlugins::Interface::Plugins::
794 TMesh* cpPlugins::Interface::Plugins::
795 GetMesh( const std::string& name )
797 auto i = this->m_Objects.find( name );
798 if( i != this->m_Objects.end( ) )
799 return( dynamic_cast< TMesh* >( i->second.second.GetPointer( ) ) );
804 // -------------------------------------------------------------------------
805 const cpPlugins::Interface::Plugins::
806 TMesh* cpPlugins::Interface::Plugins::
807 GetMesh( const std::string& name ) const
809 auto i = this->m_Objects.find( name );
810 if( i != this->m_Objects.end( ) )
811 return( dynamic_cast< const TMesh* >( i->second.second.GetPointer( ) ) );
816 // -------------------------------------------------------------------------
817 bool cpPlugins::Interface::Plugins::
818 ActivateFilter( const std::string& name )
820 this->m_ActiveFilter = this->m_Interface.CreateProcessObject( name );
821 if( this->m_ActiveFilter.IsNotNull( ) )
823 this->m_ActiveFilter->SetPlugins( this );
824 this->m_ActiveFilterOutputs.clear( );
825 auto i = this->m_Interactors.begin( );
826 for( ; i != this->m_Interactors.end( ); ++i )
827 this->m_ActiveFilter->AddInteractor( *i );
834 // -------------------------------------------------------------------------
835 void cpPlugins::Interface::Plugins::
838 this->m_ActiveFilter = NULL;
841 // -------------------------------------------------------------------------
842 bool cpPlugins::Interface::Plugins::
843 HasActiveFilter( ) const
845 return( this->m_ActiveFilter.IsNotNull( ) );
848 // -------------------------------------------------------------------------
849 bool cpPlugins::Interface::Plugins::
850 IsActiveFilterInteractive( ) const
852 if( this->m_ActiveFilter.IsNotNull( ) )
853 return( this->m_ActiveFilter->IsInteractive( ) );
858 // -------------------------------------------------------------------------
859 unsigned int cpPlugins::Interface::Plugins::
860 GetNumberOfInputsInActiveFilter( ) const
862 if( this->m_ActiveFilter.IsNotNull( ) )
863 return( this->m_ActiveFilter->GetNumberOfInputs( ) );
868 // -------------------------------------------------------------------------
869 unsigned int cpPlugins::Interface::Plugins::
870 GetNumberOfOutputsInActiveFilter( ) const
872 if( this->m_ActiveFilter.IsNotNull( ) )
873 return( this->m_ActiveFilter->GetNumberOfOutputs( ) );
878 // -------------------------------------------------------------------------
879 std::vector< std::string > cpPlugins::Interface::Plugins::
880 GetActiveFilterInputsNames( ) const
882 if( this->m_ActiveFilter.IsNotNull( ) )
883 return( this->m_ActiveFilter->GetInputsNames( ) );
885 return( std::vector< std::string >( ) );
888 // -------------------------------------------------------------------------
889 std::vector< std::string > cpPlugins::Interface::Plugins::
890 GetActiveFilterOutputsNames( ) const
892 if( this->m_ActiveFilter.IsNotNull( ) )
893 return( this->m_ActiveFilter->GetOutputsNames( ) );
895 return( std::vector< std::string >( ) );
898 // -------------------------------------------------------------------------
899 void cpPlugins::Interface::Plugins::
900 ConnectInputInActiveFilter(
901 const std::string& object_name, const std::string& input
904 if( this->m_ActiveFilter.IsNotNull( ) )
906 TDataObject* dobj = this->GetDataObject( object_name );
908 this->m_ActiveFilter->SetInput( input, dobj );
913 // -------------------------------------------------------------------------
914 void cpPlugins::Interface::Plugins::
915 SetOutputNameInActiveFilter(
916 const std::string& new_name, const std::string& output
919 this->m_ActiveFilterOutputs[ output ] = new_name;
922 // -------------------------------------------------------------------------
923 cpPlugins::Interface::Plugins::
924 TParameters* cpPlugins::Interface::Plugins::
925 GetActiveFilterParameters( )
927 if( this->m_ActiveFilter.IsNotNull( ) )
928 return( this->m_ActiveFilter->GetParameters( ) );
933 // -------------------------------------------------------------------------
934 const cpPlugins::Interface::Plugins::
935 TParameters* cpPlugins::Interface::Plugins::
936 GetActiveFilterParameters( ) const
938 if( this->m_ActiveFilter.IsNotNull( ) )
939 return( this->m_ActiveFilter->GetParameters( ) );
944 // -------------------------------------------------------------------------
945 cpPlugins::Interface::Plugins::
946 TProcessObject::DialogResult cpPlugins::Interface::Plugins::
947 ConfigureActiveFilter( )
949 if( this->m_ActiveFilter.IsNotNull( ) )
950 return( this->m_ActiveFilter->ExecConfigurationDialog( this->m_Widget ) );
952 return( TProcessObject::DialogResult_Cancel );
955 // -------------------------------------------------------------------------
956 std::string cpPlugins::Interface::Plugins::
957 UpdateActiveFilter( std::vector< std::string >& outputs )
960 this->BlockWidget( );
961 std::string err = this->m_ActiveFilter->Update( );
962 this->UnblockWidget( );
968 std::string parent = "";
969 if( this->GetNumberOfInputsInActiveFilter( ) > 0 )
971 std::string input = this->m_ActiveFilter->GetInputsNames( )[ 0 ];
973 this->m_ActiveFilter->GetInput< TDataObject >( input )->GetName( );
977 auto i = this->m_ActiveFilterOutputs.begin( );
978 for( ; i != this->m_ActiveFilterOutputs.end( ); ++i )
981 this->m_ActiveFilter->GetOutput< TDataObject >( i->first );
982 out->SetName( i->second );
983 outputs.push_back( out->GetName( ) );
984 this->_InsertNewData( out, parent );
992 // -------------------------------------------------------------------------
993 void cpPlugins::Interface::Plugins::
994 _UpdateLoadedPluginsInformation( )
996 typedef TInterface::TClasses _C;
998 this->m_Filters.clear( );
999 _C& classes = this->m_Interface.GetClasses( );
1000 for( _C::const_iterator i = classes.begin( ); i != classes.end( ); ++i )
1002 TProcessObject::Pointer o =
1003 this->m_Interface.CreateProcessObject( i->first );
1004 std::string name = o->GetClassName( );
1005 std::string category = o->GetClassCategory( );
1006 if( category == "ImageReader" )
1007 this->m_ImageReader = o;
1008 else if( category == "ImageWriter" )
1009 this->m_ImageWriter = o;
1010 else if( category == "MeshReader" )
1011 this->m_MeshReader = o;
1012 else if( category == "MeshWriter" )
1013 this->m_MeshWriter = o;
1014 else if( category == "DicomSeriesReader" )
1015 this->m_DicomSeriesReader = o;
1017 this->m_Filters[ category ].insert( name );
1022 // -------------------------------------------------------------------------
1023 bool cpPlugins::Interface::Plugins::
1024 _InsertNewData( TDataObject* dobj, const std::string& parent )
1026 std::string name = dobj->GetName( );
1027 auto i = this->m_Objects.find( name );
1029 if( i == this->m_Objects.end( ) )
1033 auto j = this->m_Objects.find( parent );
1034 if( j != this->m_Objects.end( ) )
1035 this->m_Objects[ name ] = TTreeNode( parent, dobj );
1040 this->m_Objects[ name ] = TTreeNode( "", dobj );
1043 i->second.second = dobj;
1047 #ifdef cpPlugins_Interface_QT4
1048 if( this->m_Widget != NULL )
1049 QMessageBox::critical(
1051 QMessageBox::tr( "Error inserting data." ),
1052 QMessageBox::tr( "Given parent does not exists." )
1054 #else // cpPlugins_Interface_QT4
1056 << "Error inserting data: Given parent does not exists."
1058 #endif // cpPlugins_Interface_QT4