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