]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/ProcessObject.cxx
db873e9d4f854724c7606a79af4e4f00a705c5b6
[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 void cpPlugins::Interface::ProcessObject::
136 AddInteractor( vtkRenderWindowInteractor* interactor )
137 {
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 );
144 }
145
146 // -------------------------------------------------------------------------
147 cpPlugins::Interface::ProcessObject::
148 DialogResult cpPlugins::Interface::ProcessObject::
149 ExecConfigurationDialog( QWidget* parent )
150 {
151   DialogResult r = Self::DialogResult_Cancel;
152
153 #ifdef cpPlugins_Interface_QT4
154
155   if( QApplication::instance( ) != NULL )
156   {
157     if( this->m_ParametersDialog == NULL )
158       this->m_ParametersDialog = new ParametersQtDialog( );
159     /* TODO
160        this->m_ParametersDialog->setTitle(
161        this->GetClassName( ) + std::string( " basic configuration" )
162        );
163     */
164
165     this->m_ParametersDialog->setParent( NULL );
166     this->m_ParametersDialog->setParameters( this->m_Parameters );
167
168     if( this->m_ParametersDialog->exec( ) == 1 )
169       r = Self::DialogResult_NoModal;
170     else
171       r = Self::DialogResult_Cancel;
172   }
173   else
174     r = Self::DialogResult_Cancel;
175
176 #endif // cpPlugins_Interface_QT4
177
178   return( r );
179 }
180
181 // -------------------------------------------------------------------------
182 cpPlugins::Interface::ProcessObject::
183 ProcessObject( )
184   : Superclass( ),
185     m_ITKObject( NULL ),
186     m_VTKObject( NULL ),
187     m_ParametersDialog( NULL ),
188     m_Plugins( NULL )
189 {
190   this->m_Parameters = TParameters::New( );
191   this->m_Parameters->SetProcessObject( this );
192 }
193
194 // -------------------------------------------------------------------------
195 cpPlugins::Interface::ProcessObject::
196 ~ProcessObject( )
197 {
198   if( this->m_ParametersDialog != NULL )
199     delete this->m_ParametersDialog;
200 }
201
202 // -------------------------------------------------------------------------
203 void cpPlugins::Interface::ProcessObject::
204 _AddInput( const std::string& name )
205 {
206   this->m_Inputs[ name ] = NULL;
207   this->Modified( );
208 }
209
210 // -------------------------------------------------------------------------
211 CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 );
212
213 // eof - $RCSfile$