1 #include <cpPlugins/Interface/ProcessObject.h>
3 #ifdef cpPlugins_Interface_QT4
4 #include <QApplication>
5 #include <cpPlugins/Interface/ParametersQtDialog.h>
6 #endif // cpPlugins_Interface_QT4
8 #include <vtkRenderWindowInteractor.h>
10 // -------------------------------------------------------------------------
11 void cpPlugins::Interface::ProcessObject::
14 if( this->m_ITKObject.IsNotNull( ) )
15 this->m_ITKObject->Modified( );
16 if( this->m_VTKObject.GetPointer( ) != NULL )
17 this->m_VTKObject->Modified( );
18 this->Superclass::Modified( );
21 // -------------------------------------------------------------------------
22 void cpPlugins::Interface::ProcessObject::
23 GetInputsNames( std::set< std::string >& names ) const
26 auto dIt = this->m_Inputs.begin( );
27 for( ; dIt != this->m_Inputs.end( ); ++dIt )
28 names.insert( dIt->first );
31 // -------------------------------------------------------------------------
32 void cpPlugins::Interface::ProcessObject::
33 GetOutputsNames( std::set< std::string >& names ) const
36 auto dIt = this->m_Outputs.begin( );
37 for( ; dIt != this->m_Outputs.end( ); ++dIt )
38 names.insert( dIt->first );
41 // -------------------------------------------------------------------------
42 unsigned int cpPlugins::Interface::ProcessObject::
43 GetNumberOfInputs( ) const
45 return( this->m_Inputs.size( ) );
48 // -------------------------------------------------------------------------
49 unsigned int cpPlugins::Interface::ProcessObject::
50 GetNumberOfOutputs( ) const
52 return( this->m_Outputs.size( ) );
55 // -------------------------------------------------------------------------
56 bool cpPlugins::Interface::ProcessObject::
58 const std::string& new_object_name, const std::string& output_name
61 auto oIt = this->m_Outputs.find( output_name );
62 if( oIt != this->m_Outputs.end( ) )
64 this->m_OutputObjectsNames[ output_name ] = new_object_name;
72 // -------------------------------------------------------------------------
73 void cpPlugins::Interface::ProcessObject::
74 SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
76 _TDataContainer::iterator i = this->m_Inputs.find( id );
77 if( i != this->m_Inputs.end( ) )
85 // -------------------------------------------------------------------------
86 std::string cpPlugins::Interface::ProcessObject::
91 // Force upstream updates
92 _TDataContainer::iterator i = this->m_Inputs.begin( );
93 for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
95 if( i->second.IsNotNull( ) )
97 Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
102 r = "cpPlugins::Interface::ProcessObject: No input connected.";
108 r = this->_GenerateData( );
110 // Configure output names
111 auto oIt = this->m_Outputs.begin( );
112 for( ; oIt != this->m_Outputs.end( ); ++oIt )
114 auto nIt = this->m_OutputObjectsNames.find( oIt->first );
115 if( nIt != this->m_OutputObjectsNames.end( ) )
116 oIt->second->SetName( nIt->second );
120 // Return error description, if any
124 // -------------------------------------------------------------------------
125 void cpPlugins::Interface::ProcessObject::
128 _TDataContainer::iterator i = this->m_Outputs.begin( );
129 for( ; i != this->m_Outputs.end( ); ++i )
130 if( i->second.IsNotNull( ) )
131 i->second->DisconnectPipeline( );
134 // -------------------------------------------------------------------------
135 void cpPlugins::Interface::ProcessObject::
136 AddInteractor( vtkRenderWindowInteractor* interactor )
138 #ifdef cpPlugins_Interface_QT4
139 if( this->m_ParametersDialog == NULL )
140 this->m_ParametersDialog = new ParametersQtDialog( );
141 this->m_ParametersDialog->addInteractor( interactor );
142 #endif // cpPlugins_Interface_QT4
143 this->m_Interactors.insert( interactor );
146 // -------------------------------------------------------------------------
147 cpPlugins::Interface::ProcessObject::
148 DialogResult cpPlugins::Interface::ProcessObject::
149 ExecConfigurationDialog( QWidget* parent )
151 DialogResult r = Self::DialogResult_Cancel;
153 #ifdef cpPlugins_Interface_QT4
155 if( QApplication::instance( ) != NULL )
157 if( this->m_ParametersDialog == NULL )
158 this->m_ParametersDialog = new ParametersQtDialog( );
160 this->m_ParametersDialog->setTitle(
161 this->GetClassName( ) + std::string( " basic configuration" )
165 this->m_ParametersDialog->setParent( NULL );
166 this->m_ParametersDialog->setParameters( this->m_Parameters );
168 if( !( this->m_ParametersDialog->IsModal( ) ) )
170 this->m_ParametersDialog->show( );
171 r = Self::DialogResult_Modal;
175 if( this->m_ParametersDialog->exec( ) == 1 )
176 r = Self::DialogResult_NoModal;
178 r = Self::DialogResult_Cancel;
183 r = Self::DialogResult_Cancel;
185 #endif // cpPlugins_Interface_QT4
190 // -------------------------------------------------------------------------
191 cpPlugins::Interface::ProcessObject::
196 m_ParametersDialog( NULL ),
199 this->m_Parameters = TParameters::New( );
200 this->m_Parameters->SetProcessObject( this );
203 // -------------------------------------------------------------------------
204 cpPlugins::Interface::ProcessObject::
207 if( this->m_ParametersDialog != NULL )
208 delete this->m_ParametersDialog;
211 // -------------------------------------------------------------------------
212 void cpPlugins::Interface::ProcessObject::
213 _AddInput( const std::string& name )
215 this->m_Inputs[ name ] = NULL;
219 // -------------------------------------------------------------------------
220 CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 );