]> Creatis software - cpPlugins.git/blob - cpPlugins/Interface/ProcessObject.cxx
Moved to version 1.0
[cpPlugins.git] / 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     this->m_ParametersDialog->setTitle(
160       this->GetClassName( ) + std::string( " basic configuration" )
161       );
162
163     this->m_ParametersDialog->setParent( NULL );
164     this->m_ParametersDialog->setParameters( this->m_Parameters );
165
166     if( !( this->m_ParametersDialog->IsModal( ) ) )
167     {
168       this->m_ParametersDialog->show( );
169       r = Self::DialogResult_Modal;
170     }
171     else
172     {
173       if( this->m_ParametersDialog->exec( ) == 1 )
174         r = Self::DialogResult_NoModal;
175       else
176         r = Self::DialogResult_Cancel;
177
178     } // fi
179   }
180   else
181     r = Self::DialogResult_Cancel;
182
183 #endif // cpPlugins_Interface_QT4
184
185   return( r );
186 }
187
188 // -------------------------------------------------------------------------
189 cpPlugins::Interface::ProcessObject::
190 ProcessObject( )
191   : Superclass( ),
192     m_ITKObject( NULL ),
193     m_VTKObject( NULL ),
194     m_ParametersDialog( NULL ),
195     m_Plugins( NULL )
196 {
197   this->m_Parameters = TParameters::New( );
198   this->m_Parameters->SetProcessObject( this );
199 }
200
201 // -------------------------------------------------------------------------
202 cpPlugins::Interface::ProcessObject::
203 ~ProcessObject( )
204 {
205   if( this->m_ParametersDialog != NULL )
206     delete this->m_ParametersDialog;
207 }
208
209 // -------------------------------------------------------------------------
210 void cpPlugins::Interface::ProcessObject::
211 _AddInput( const std::string& name )
212 {
213   this->m_Inputs[ name ] = NULL;
214   this->Modified( );
215 }
216
217 // -------------------------------------------------------------------------
218 CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 );
219
220 // eof - $RCSfile$