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