]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/ProcessObject.cxx
1db1a61cb44db76ac27f40400912feab3523d21a
[cpPlugins.git] / lib / cpPlugins / Interface / ProcessObject.cxx
1 #include <cpPlugins/Interface/ProcessObject.h>
2
3 #ifdef cpPlugins_Interface_QT4
4 #include <QApplication>
5 #include <cpPlugins/Interface/ParametersQtDialog.h>
6 #endif // cpPlugins_Interface_QT4
7
8 #include <vtkRenderWindowInteractor.h>
9
10 // -------------------------------------------------------------------------
11 void cpPlugins::Interface::ProcessObject::
12 Modified( ) const
13 {
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( );
19 }
20
21 // -------------------------------------------------------------------------
22 void cpPlugins::Interface::ProcessObject::
23 GetInputsNames( std::set< std::string >& names ) const
24 {
25   names.clear( );
26   auto dIt = this->m_Inputs.begin( );
27   for( ; dIt != this->m_Inputs.end( ); ++dIt )
28     names.insert( dIt->first );
29 }
30
31 // -------------------------------------------------------------------------
32 void cpPlugins::Interface::ProcessObject::
33 GetOutputsNames( std::set< std::string >& names ) const
34 {
35   names.clear( );
36   auto dIt = this->m_Outputs.begin( );
37   for( ; dIt != this->m_Outputs.end( ); ++dIt )
38     names.insert( dIt->first );
39 }
40
41 // -------------------------------------------------------------------------
42 unsigned int cpPlugins::Interface::ProcessObject::
43 GetNumberOfInputs( ) const
44 {
45   return( this->m_Inputs.size( ) );
46 }
47
48 // -------------------------------------------------------------------------
49 unsigned int cpPlugins::Interface::ProcessObject::
50 GetNumberOfOutputs( ) const
51 {
52   return( this->m_Outputs.size( ) );
53 }
54
55 // -------------------------------------------------------------------------
56 bool cpPlugins::Interface::ProcessObject::
57 SetOutputObjectName(
58   const std::string& new_object_name, const std::string& output_name
59   )
60 {
61   auto oIt = this->m_Outputs.find( output_name );
62   if( oIt != this->m_Outputs.end( ) )
63   {
64     this->m_OutputObjectsNames[ output_name ] = new_object_name;
65     this->Modified( );
66     return( true );
67   }
68   else
69     return( false );
70 }
71
72 // -------------------------------------------------------------------------
73 void cpPlugins::Interface::ProcessObject::
74 SetInput( const std::string& id, cpPlugins::Interface::DataObject* dobj )
75 {
76   _TDataContainer::iterator i = this->m_Inputs.find( id );
77   if( i != this->m_Inputs.end( ) )
78   {
79     i->second = dobj;
80     this->Modified( );
81
82   } // fi
83 }
84
85 // -------------------------------------------------------------------------
86 std::string cpPlugins::Interface::ProcessObject::
87 Update( )
88 {
89   std::string r = "";
90
91   // Force upstream updates
92   _TDataContainer::iterator i = this->m_Inputs.begin( );
93   for( ; i != this->m_Inputs.end( ) && r == ""; ++i )
94   {
95     if( i->second.IsNotNull( ) )
96     {
97       Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
98       if( src != NULL )
99         r = src->Update( );
100     }
101     else
102       r = "cpPlugins::Interface::ProcessObject: No input connected.";
103     
104   } // rof
105
106   // Current update
107   if( r == "" )
108     r = this->_GenerateData( );
109
110   // Configure output names
111   auto oIt = this->m_Outputs.begin( );
112   for( ; oIt != this->m_Outputs.end( ); ++oIt )
113   {
114     auto nIt = this->m_OutputObjectsNames.find( oIt->first );
115     if( nIt != this->m_OutputObjectsNames.end( ) )
116       oIt->second->SetName( nIt->second );
117
118   } // rof
119
120   // Return error description, if any
121   return( r );
122 }
123
124 // -------------------------------------------------------------------------
125 void cpPlugins::Interface::ProcessObject::
126 DisconnectOutputs( )
127 {
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( );
132 }
133
134 // -------------------------------------------------------------------------
135 const cpPlugins::Interface::ProcessObject::
136 TInteractors& cpPlugins::Interface::ProcessObject::
137 GetInteractors( ) const
138 {
139   return( this->m_Interactors );
140 }
141
142 // -------------------------------------------------------------------------
143 void cpPlugins::Interface::ProcessObject::
144 AddInteractor( vtkRenderWindowInteractor* interactor )
145 {
146 #ifdef cpPlugins_Interface_QT4
147   if( this->m_ParametersDialog == NULL )
148     this->m_ParametersDialog = new ParametersQtDialog( );
149   this->m_ParametersDialog->addInteractor( interactor );
150 #endif // cpPlugins_Interface_QT4
151   this->m_Interactors.insert( interactor );
152 }
153
154 // -------------------------------------------------------------------------
155 bool cpPlugins::Interface::ProcessObject::
156 ExecConfigurationDialog( QWidget* parent )
157 {
158   bool r = false;
159
160 #ifdef cpPlugins_Interface_QT4
161
162   if( QApplication::instance( ) != NULL )
163   {
164     if( this->m_ParametersDialog == NULL )
165       this->m_ParametersDialog = new ParametersQtDialog( );
166     /* TODO
167        this->m_ParametersDialog->setTitle(
168        this->GetClassName( ) + std::string( " basic configuration" )
169        );
170     */
171
172     this->m_ParametersDialog->setParent( NULL );
173     this->m_ParametersDialog->setParameters( this->m_Parameters );
174
175     r = ( this->m_ParametersDialog->exec( ) == 1 );
176   }
177   else
178     r = false;
179   
180 #endif // cpPlugins_Interface_QT4
181
182   return( r );
183 }
184
185 // -------------------------------------------------------------------------
186 cpPlugins::Interface::ProcessObject::
187 ProcessObject( )
188   : Superclass( ),
189     m_ITKObject( NULL ),
190     m_VTKObject( NULL ),
191     m_ParametersDialog( NULL ),
192     m_Plugins( NULL )
193 {
194   this->m_Parameters = TParameters::New( );
195   this->m_Parameters->SetProcessObject( this );
196 }
197
198 // -------------------------------------------------------------------------
199 cpPlugins::Interface::ProcessObject::
200 ~ProcessObject( )
201 {
202   if( this->m_ParametersDialog != NULL )
203     delete this->m_ParametersDialog;
204 }
205
206 // -------------------------------------------------------------------------
207 void cpPlugins::Interface::ProcessObject::
208 _AddInput( const std::string& name )
209 {
210   this->m_Inputs[ name ] = NULL;
211   this->Modified( );
212 }
213
214 // -------------------------------------------------------------------------
215 CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 );
216
217 // eof - $RCSfile$