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