]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/ProcessObject.cxx
Merge ssh://git.creatis.insa-lyon.fr/cpPlugins
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
1 #include <cpPlugins/Interface/ProcessObject.h>
2
3 #ifdef cpPlugins_Interface_QT4
4 #include <cpPlugins/Interface/ParametersQtDialog.h>
5 #endif // cpPlugins_Interface_QT4
6
7 #include <vtkRenderWindowInteractor.h>
8
9 // -------------------------------------------------------------------------
10 void cpPlugins::Interface::ProcessObject::
11 Modified( ) const
12 {
13   if( this->m_ITKObject.IsNotNull( ) )
14     this->m_ITKObject->Modified( );
15   if( this->m_VTKObject.GetPointer( ) != NULL )
16     this->m_VTKObject->Modified( );
17   this->Superclass::Modified( );
18 }
19
20 // -------------------------------------------------------------------------
21 bool cpPlugins::Interface::ProcessObject::
22 IsInteractive( ) const
23 {
24   std::vector< std::string > names;
25   this->m_Parameters->GetNames( names );
26   bool res = false;
27   auto i = names.begin( );
28   for( ; i != names.end( ); ++i )
29   {
30     TParameters::Type t = this->m_Parameters->GetType( *i );
31     res |= ( t == TParameters::Point );
32     res |= ( t == TParameters::Index );
33     res |= ( t == TParameters::PointList );
34     res |= ( t == TParameters::IndexList );
35
36   } // rof
37   return( res );
38 }
39
40 // -------------------------------------------------------------------------
41 cpPlugins::Interface::ProcessObject::
42 TParameters* cpPlugins::Interface::ProcessObject::
43 GetParameters( )
44 {
45   return( this->m_Parameters.GetPointer( ) );
46 }
47
48 // -------------------------------------------------------------------------
49 const cpPlugins::Interface::ProcessObject::
50 TParameters* cpPlugins::Interface::ProcessObject::
51 GetParameters( ) const
52 {
53   return( this->m_Parameters.GetPointer( ) );
54 }
55
56 // -------------------------------------------------------------------------
57 cpPlugins::Interface::
58 Plugins* cpPlugins::Interface::ProcessObject::
59 GetPlugins( )
60 {
61   return( this->m_Plugins );
62 }
63
64 // -------------------------------------------------------------------------
65 const cpPlugins::Interface::
66 Plugins* cpPlugins::Interface::ProcessObject::
67 GetPlugins( ) const
68 {
69   return( this->m_Plugins );
70 }
71
72 // -------------------------------------------------------------------------
73 void cpPlugins::Interface::ProcessObject::
74 SetPlugins( Plugins* p )
75 {
76   this->m_Plugins = p;
77 }
78
79 // -------------------------------------------------------------------------
80 unsigned int cpPlugins::Interface::ProcessObject::
81 GetNumberOfInputs( ) const
82 {
83   return( this->m_Inputs.size( ) );
84 }
85
86 // -------------------------------------------------------------------------
87 unsigned int cpPlugins::Interface::ProcessObject::
88 GetNumberOfOutputs( ) const
89 {
90   return( this->m_Outputs.size( ) );
91 }
92
93 // -------------------------------------------------------------------------
94 std::vector< std::string > cpPlugins::Interface::ProcessObject::
95 GetInputsNames( ) const
96 {
97   std::vector< std::string > r;
98   auto dIt = this->m_Inputs.begin( );
99   for( ; dIt != this->m_Inputs.end( ); ++dIt )
100     r.push_back( dIt->first );
101   return( r );
102 }
103
104 // -------------------------------------------------------------------------
105 std::vector< std::string > cpPlugins::Interface::ProcessObject::
106 GetOutputsNames( ) const
107 {
108   std::vector< std::string > r;
109   auto dIt = this->m_Outputs.begin( );
110   for( ; dIt != this->m_Outputs.end( ); ++dIt )
111     r.push_back( dIt->first );
112   return( r );
113 }
114
115 // -------------------------------------------------------------------------
116 void cpPlugins::Interface::ProcessObject::
117 SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
118 {
119   _TDataContainer::iterator i = this->m_Inputs.find( id );
120   if( i != this->m_Inputs.end( ) )
121   {
122     i->second = dobj;
123     this->Modified( );
124
125   } // fi
126 }
127
128 // -------------------------------------------------------------------------
129 std::string cpPlugins::Interface::ProcessObject::
130 Update( )
131 {
132   std::string r = "";
133
134   // Force upstream updates
135   _TDataContainer::iterator i = this->m_Inputs.begin( );
136   for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
137   {
138     Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
139     if( src != NULL )
140       r = src->Update( );
141
142   } // rof
143
144   // Current update
145   if( r == "" )
146     r = this->_GenerateData( );
147
148   // Return error description, if any
149   return( r );
150 }
151
152 // -------------------------------------------------------------------------
153 void cpPlugins::Interface::ProcessObject::
154 DisconnectOutputs( )
155 {
156   _TDataContainer::iterator i = this->m_Outputs.begin( );
157   for( ; i != this->m_Outputs.end( ); ++i )
158     if( i->second.IsNotNull( ) )
159       i->second->DisconnectPipeline( );
160 }
161
162 // -------------------------------------------------------------------------
163 void cpPlugins::Interface::ProcessObject::
164 AddInteractor( vtkRenderWindowInteractor* interactor )
165 {
166 #ifdef cpPlugins_Interface_QT4
167   this->m_ParametersDialog->addInteractor( interactor );
168 #endif // cpPlugins_Interface_QT4
169 }
170
171 // -------------------------------------------------------------------------
172 cpPlugins::Interface::ProcessObject::
173 DialogResult cpPlugins::Interface::ProcessObject::
174 ExecConfigurationDialog( QWidget* parent )
175 {
176   DialogResult r = Self::DialogResult_Cancel;
177
178 #ifdef cpPlugins_Interface_QT4
179
180   this->m_ParametersDialog->setParent( NULL );
181   this->m_ParametersDialog->setParameters( this->m_Parameters );
182
183   if( !( this->m_ParametersDialog->IsModal( ) ) )
184   {
185     this->m_ParametersDialog->show( );
186     r = Self::DialogResult_Modal;
187   }
188   else
189   {
190     if( this->m_ParametersDialog->exec( ) == 1 )
191       r = Self::DialogResult_NoModal;
192     else
193       r = Self::DialogResult_Cancel;
194
195   } // fi
196
197 #endif // cpPlugins_Interface_QT4
198
199   return( r );
200 }
201
202 // -------------------------------------------------------------------------
203 cpPlugins::Interface::ProcessObject::
204 ProcessObject( )
205   : Superclass( ),
206     m_ITKObject( NULL ),
207     m_VTKObject( NULL ),
208     m_Plugins( NULL )
209 {
210   this->m_Parameters = TParameters::New( );
211   this->m_Parameters->SetProcessObject( this );
212
213   this->m_ParametersDialog = new ParametersQtDialog( );
214   this->m_ParametersDialog->setTitle(
215     this->GetClassName( ) + std::string( " basic configuration" )
216     );
217 }
218
219 // -------------------------------------------------------------------------
220 cpPlugins::Interface::ProcessObject::
221 ~ProcessObject( )
222 {
223   delete this->m_ParametersDialog;
224 }
225
226 // -------------------------------------------------------------------------
227 void cpPlugins::Interface::ProcessObject::
228 _AddInput( const std::string& name )
229 {
230   this->m_Inputs[ name ] = NULL;
231   this->Modified( );
232 }
233
234 // eof - $RCSfile$