]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/ProcessObject.cxx
MPR finished
[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     Self* src = dynamic_cast< Self* >( i->second->GetSource( ) );
82     if( src != NULL )
83       r = src->Update( );
84
85   } // rof
86
87   // Current update
88   if( r == "" )
89     r = this->_GenerateData( );
90
91   // Configure output names
92   auto oIt = this->m_Outputs.begin( );
93   for( ; oIt != this->m_Outputs.end( ); ++oIt )
94   {
95     auto nIt = this->m_OutputObjectsNames.find( oIt->first );
96     if( nIt != this->m_OutputObjectsNames.end( ) )
97       oIt->second->SetName( nIt->second );
98
99   } // rof
100
101   // Return error description, if any
102   return( r );
103 }
104
105 // -------------------------------------------------------------------------
106 void cpPlugins::Interface::ProcessObject::
107 DisconnectOutputs( )
108 {
109   _TDataContainer::iterator i = this->m_Outputs.begin( );
110   for( ; i != this->m_Outputs.end( ); ++i )
111     if( i->second.IsNotNull( ) )
112       i->second->DisconnectPipeline( );
113 }
114
115 // -------------------------------------------------------------------------
116 void cpPlugins::Interface::ProcessObject::
117 AddInteractor( vtkRenderWindowInteractor* interactor )
118 {
119 #ifdef cpPlugins_Interface_QT4
120   if( this->m_ParametersDialog == NULL )
121     this->m_ParametersDialog = new ParametersQtDialog( );
122   this->m_ParametersDialog->addInteractor( interactor );
123 #endif // cpPlugins_Interface_QT4
124   this->m_Interactors.insert( interactor );
125 }
126
127 // -------------------------------------------------------------------------
128 cpPlugins::Interface::ProcessObject::
129 DialogResult cpPlugins::Interface::ProcessObject::
130 ExecConfigurationDialog( QWidget* parent )
131 {
132   DialogResult r = Self::DialogResult_Cancel;
133
134 #ifdef cpPlugins_Interface_QT4
135
136   if( QApplication::instance( ) != NULL )
137   {
138     if( this->m_ParametersDialog == NULL )
139       this->m_ParametersDialog = new ParametersQtDialog( );
140     this->m_ParametersDialog->setTitle(
141       this->GetClassName( ) + std::string( " basic configuration" )
142       );
143
144     this->m_ParametersDialog->setParent( NULL );
145     this->m_ParametersDialog->setParameters( this->m_Parameters );
146
147     if( !( this->m_ParametersDialog->IsModal( ) ) )
148     {
149       this->m_ParametersDialog->show( );
150       r = Self::DialogResult_Modal;
151     }
152     else
153     {
154       if( this->m_ParametersDialog->exec( ) == 1 )
155         r = Self::DialogResult_NoModal;
156       else
157         r = Self::DialogResult_Cancel;
158
159     } // fi
160   }
161   else
162     r = Self::DialogResult_Cancel;
163
164 #endif // cpPlugins_Interface_QT4
165
166   return( r );
167 }
168
169 // -------------------------------------------------------------------------
170 cpPlugins::Interface::ProcessObject::
171 ProcessObject( )
172   : Superclass( ),
173     m_ITKObject( NULL ),
174     m_VTKObject( NULL ),
175     m_ParametersDialog( NULL ),
176     m_Plugins( NULL )
177 {
178   this->m_Parameters = TParameters::New( );
179   this->m_Parameters->SetProcessObject( this );
180 }
181
182 // -------------------------------------------------------------------------
183 cpPlugins::Interface::ProcessObject::
184 ~ProcessObject( )
185 {
186   if( this->m_ParametersDialog != NULL )
187     delete this->m_ParametersDialog;
188 }
189
190 // -------------------------------------------------------------------------
191 void cpPlugins::Interface::ProcessObject::
192 _AddInput( const std::string& name )
193 {
194   this->m_Inputs[ name ] = NULL;
195   this->Modified( );
196 }
197
198 // -------------------------------------------------------------------------
199 CPPLUGINS_PROVIDER_SOURCE( cpPlugins::Interface::ProcessObject, 1, 1 );
200
201 // eof - $RCSfile$