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