]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/ProcessObject.cxx
little error on Windows solved
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
1 #include <cpPlugins/Interface/ProcessObject.h>
2 #include <itkProcessObject.h>
3
4 #ifdef cpPlugins_Interface_QT4
5 #include <QApplication>
6 #include <cpPlugins/Interface/ParametersQtDialog.h>
7 #include <cpPlugins/Interface/SimpleMPRWidget.h>
8 #endif // cpPlugins_Interface_QT4
9
10 // -------------------------------------------------------------------------
11 std::set< std::string > cpPlugins::Interface::ProcessObject::
12 GetInputsNames( ) const
13 {
14   std::set< std::string > names;
15   for( auto i = this->m_Inputs.begin( ); i != this->m_Inputs.end( ); ++i )
16     names.insert( i->first );
17   return( names );
18 }
19
20 // -------------------------------------------------------------------------
21 std::set< std::string > cpPlugins::Interface::ProcessObject::
22 GetOutputsNames( ) const
23 {
24   std::set< std::string > names;
25   for( auto i = this->m_Outputs.begin( ); i != this->m_Outputs.end( ); ++i )
26     names.insert( i->first );
27   return( names );
28 }
29
30 // -------------------------------------------------------------------------
31 unsigned int cpPlugins::Interface::ProcessObject::
32 GetNumberOfInputs( ) const
33 {
34   return( this->m_Inputs.size( ) );
35 }
36
37 // -------------------------------------------------------------------------
38 unsigned int cpPlugins::Interface::ProcessObject::
39 GetNumberOfOutputs( ) const
40 {
41   return( this->m_Outputs.size( ) );
42 }
43
44 // -------------------------------------------------------------------------
45 cpPlugins::Interface::
46 OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
47 GetOutput( const std::string& id )
48 {
49   static OutputProcessObjectPort null_port;
50   auto i = this->m_Outputs.find( id );
51   if( i == this->m_Outputs.end( ) )
52   {
53     null_port = NULL;
54     return( null_port );
55   }
56   else
57     return( i->second );
58 }
59
60 // -------------------------------------------------------------------------
61 const cpPlugins::Interface::
62 OutputProcessObjectPort& cpPlugins::Interface::ProcessObject::
63 GetOutput( const std::string& id ) const
64 {
65   static const OutputProcessObjectPort null_port;
66   auto i = this->m_Outputs.find( id );
67   if( i == this->m_Outputs.end( ) )
68     return( null_port );
69   else
70     return( i->second );
71 }
72
73 // -------------------------------------------------------------------------
74 bool cpPlugins::Interface::ProcessObject::
75 SetInput( const std::string& id, const OutputProcessObjectPort& port )
76 {
77   auto i = this->m_Inputs.find( id );
78   if( i != this->m_Inputs.end( ) )
79   {
80     if( i->second.GetPointer( ) != port.GetPointer( ) )
81     {
82       i->second = port;
83       this->Modified( );
84
85     } // fi
86     return( true );
87   }
88   else
89     return( false );
90 }
91
92 // -------------------------------------------------------------------------
93 void cpPlugins::Interface::ProcessObject::
94 DisconnectInputs( )
95 {
96   auto i = this->m_Inputs.begin( );
97   for( ; i != this->m_Inputs.end( ); ++i )
98     i->second = NULL;
99   this->Modified( );
100 }
101
102 // -------------------------------------------------------------------------
103 void cpPlugins::Interface::ProcessObject::
104 DisconnectOutputs( )
105 {
106   auto i = this->m_Outputs.begin( );
107   for( ; i != this->m_Outputs.end( ); ++i )
108     if( i->second.IsValid( ) )
109       i->second->DisconnectFromPipeline( );
110   this->Modified( );
111 }
112
113 // -------------------------------------------------------------------------
114 void cpPlugins::Interface::ProcessObject::
115 Disconnect( )
116 {
117   this->DisconnectInputs( );
118   this->DisconnectOutputs( );
119 }
120
121 // -------------------------------------------------------------------------
122 itk::ModifiedTimeType cpPlugins::Interface::ProcessObject::
123 GetMTime( ) const
124 {
125   auto params_time = this->m_Parameters->GetMTime( );
126   auto filter_time = this->Superclass::GetMTime( );
127   return( ( params_time < filter_time )? params_time: filter_time );
128 }
129
130 // -------------------------------------------------------------------------
131 std::string cpPlugins::Interface::ProcessObject::
132 Update( )
133 {
134   std::string r = "";
135
136   // Force upstream updates
137   auto i = this->m_Inputs.begin( );
138   bool need_to_update = false;
139   for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
140   {
141     if( i->second.IsValid( ) )
142     {
143       Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
144       if( src != NULL )
145       {
146         need_to_update |= ( this->m_LastExecutionTime < src->GetMTime( ) );
147         r = src->Update( );
148
149       } // fi
150
151     } // fi
152
153   } // rof
154
155   // Current update
156   if( r == "" )
157   {
158     if( this->m_LastExecutionTime < this->GetMTime( ) || need_to_update )
159     {
160       r = this->_GenerateData( );
161       this->m_LastExecutionTime = this->GetMTime( );
162
163     } // fi
164
165   } // fi
166
167   // Return error description, if any
168   return( r );
169 }
170
171 // -------------------------------------------------------------------------
172 cpPlugins::Interface::ProcessObject::
173 ProcessObject( )
174   : Superclass( ),
175     m_LastExecutionTime( 0 ),
176     m_ParametersDialog( NULL ),
177     m_MPRViewer( NULL )
178 {
179   this->m_Parameters = TParameters::New( );
180   this->m_Parameters->SetProcessObject( this );
181
182 #ifdef cpPlugins_Interface_QT4
183   if( QApplication::instance( ) != NULL )
184   {
185     this->m_ParametersDialog = new ParametersQtDialog( );
186     this->m_ParametersDialog->setParameters( this->m_Parameters );
187
188   } // fi
189 #endif // cpPlugins_Interface_QT4
190 }
191
192 // -------------------------------------------------------------------------
193 cpPlugins::Interface::ProcessObject::
194 ~ProcessObject( )
195 {
196   this->Disconnect( );
197   if( this->m_ParametersDialog != NULL )
198     delete this->m_ParametersDialog;
199 }
200
201 // -------------------------------------------------------------------------
202 void cpPlugins::Interface::ProcessObject::
203 _AddInput( const std::string& name, bool required )
204 {
205 //  typedef typename _TInputs::value_type _TValue;
206   auto i = this->m_Inputs.find( name );
207   if( i == this->m_Inputs.end( ) )
208   {
209     InputProcessObjectPort new_port( required );
210     this->m_Inputs[ name ] = new_port;
211     this->Modified( );
212
213   } // fi
214 }
215
216 // eof - $RCSfile$