]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/ProcessObject.cxx
9c3148d00fe9adf9abd0a7392bef5c60619a6add
[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 cpPlugins::Interface::ProcessObject::
22 TParameters* cpPlugins::Interface::ProcessObject::
23 GetParameters( )
24 {
25   return( this->m_Parameters.GetPointer( ) );
26 }
27
28 // -------------------------------------------------------------------------
29 const cpPlugins::Interface::ProcessObject::
30 TParameters* cpPlugins::Interface::ProcessObject::
31 GetParameters( ) const
32 {
33   return( this->m_Parameters.GetPointer( ) );
34 }
35
36 // -------------------------------------------------------------------------
37 unsigned int cpPlugins::Interface::ProcessObject::
38 GetNumberOfInputs( ) const
39 {
40   return( this->m_Inputs.size( ) );
41 }
42
43 // -------------------------------------------------------------------------
44 unsigned int cpPlugins::Interface::ProcessObject::
45 GetNumberOfOutputs( ) const
46 {
47   return( this->m_Outputs.size( ) );
48 }
49
50 // -------------------------------------------------------------------------
51 std::vector< std::string > cpPlugins::Interface::ProcessObject::
52 GetInputsNames( ) const
53 {
54   std::vector< std::string > r;
55   auto dIt = this->m_Inputs.begin( );
56   for( ; dIt != this->m_Inputs.end( ); ++dIt )
57     r.push_back( dIt->first );
58   return( r );
59 }
60
61 // -------------------------------------------------------------------------
62 std::vector< std::string > cpPlugins::Interface::ProcessObject::
63 GetOutputsNames( ) const
64 {
65   std::vector< std::string > r;
66   auto dIt = this->m_Outputs.begin( );
67   for( ; dIt != this->m_Outputs.end( ); ++dIt )
68     r.push_back( dIt->first );
69   return( r );
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     Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
96     if( src != NULL )
97       r = src->Update( );
98
99   } // rof
100
101   // Current update
102   if( r == "" )
103     r = this->_GenerateData( );
104
105   // Return error description, if any
106   return( r );
107 }
108
109 // -------------------------------------------------------------------------
110 void cpPlugins::Interface::ProcessObject::
111 DisconnectOutputs( )
112 {
113   _TDataContainer::iterator i = this->m_Outputs.begin( );
114   for( ; i != this->m_Outputs.end( ); ++i )
115     if( i->second.IsNotNull( ) )
116       i->second->DisconnectPipeline( );
117 }
118
119 // -------------------------------------------------------------------------
120 void cpPlugins::Interface::ProcessObject::
121 AddInteractor( vtkRenderWindowInteractor* interactor )
122 {
123 #ifdef cpPlugins_Interface_QT4
124   this->m_ParametersDialog->addInteractor( interactor );
125 #endif // cpPlugins_Interface_QT4
126 }
127
128 // -------------------------------------------------------------------------
129 cpPlugins::Interface::ProcessObject::
130 DialogResult cpPlugins::Interface::ProcessObject::
131 ExecConfigurationDialog( QWidget* parent )
132 {
133   DialogResult r = Self::DialogResult_Cancel;
134
135 #ifdef cpPlugins_Interface_QT4
136
137   this->m_ParametersDialog->setParent( NULL );
138   this->m_ParametersDialog->setParameters( this->m_Parameters );
139
140   if( !( this->m_ParametersDialog->IsModal( ) ) )
141   {
142     this->m_ParametersDialog->show( );
143     r = Self::DialogResult_Modal;
144   }
145   else
146   {
147     if( this->m_ParametersDialog->exec( ) == 1 )
148       r = Self::DialogResult_NoModal;
149     else
150       r = Self::DialogResult_Cancel;
151
152   } // fi
153
154 #endif // cpPlugins_Interface_QT4
155
156   return( r );
157 }
158
159 // -------------------------------------------------------------------------
160 cpPlugins::Interface::ProcessObject::
161 ProcessObject( )
162   : Superclass( ),
163     m_ITKObject( NULL ),
164     m_VTKObject( NULL )
165 {
166   this->m_Parameters = TParameters::New( );
167
168   this->m_ParametersDialog = new ParametersQtDialog( );
169   this->m_ParametersDialog->setTitle(
170     this->GetClassName( ) + std::string( " basic configuration" )
171     );
172 }
173
174 // -------------------------------------------------------------------------
175 cpPlugins::Interface::ProcessObject::
176 ~ProcessObject( )
177 {
178   delete this->m_ParametersDialog;
179 }
180
181 // -------------------------------------------------------------------------
182 void cpPlugins::Interface::ProcessObject::
183 _AddInput( const std::string& name )
184 {
185   this->m_Inputs[ name ] = NULL;
186   this->Modified( );
187 }
188
189 // eof - $RCSfile$