1 #include <cpPlugins/Interface/Workspace.h>
2 #include <cpPlugins/Interface/SimpleMPRWidget.h>
3 #include <vtkRenderWindowInteractor.h>
5 // -------------------------------------------------------------------------
6 cpPlugins::Interface::Workspace::
11 this->m_Graph = TGraph::New( );
14 // -------------------------------------------------------------------------
15 cpPlugins::Interface::Workspace::
20 // -------------------------------------------------------------------------
21 cpPlugins::Interface::Workspace::
22 TPlugins* cpPlugins::Interface::Workspace::
25 return( this->m_Plugins );
28 // -------------------------------------------------------------------------
29 const cpPlugins::Interface::Workspace::
30 TPlugins* cpPlugins::Interface::Workspace::
33 return( this->m_Plugins );
36 // -------------------------------------------------------------------------
37 void cpPlugins::Interface::Workspace::
38 SetPlugins( TPlugins* i )
40 if( this->m_Plugins != i )
44 // -------------------------------------------------------------------------
45 cpPlugins::Interface::Workspace::
46 TGraph* cpPlugins::Interface::Workspace::
49 return( this->m_Graph );
52 // -------------------------------------------------------------------------
53 const cpPlugins::Interface::Workspace::
54 TGraph* cpPlugins::Interface::Workspace::
57 return( this->m_Graph );
60 // -------------------------------------------------------------------------
61 void cpPlugins::Interface::Workspace::
64 if( this->m_Graph.IsNotNull( ) )
65 this->m_Graph->Clear( );
68 // -------------------------------------------------------------------------
69 void cpPlugins::Interface::Workspace::
74 // -------------------------------------------------------------------------
75 cpPlugins::Interface::Workspace::
76 TFilter* cpPlugins::Interface::Workspace::
77 GetFilter( const std::string& name )
80 dynamic_cast< TFilter* >(
81 this->m_Graph->GetVertex( name ).GetPointer( )
86 // -------------------------------------------------------------------------
87 const cpPlugins::Interface::Workspace::
88 TFilter* cpPlugins::Interface::Workspace::
89 GetFilter( const std::string& name ) const
92 dynamic_cast< const TFilter* >(
93 this->m_Graph->GetVertex( name ).GetPointer( )
98 // -------------------------------------------------------------------------
99 bool cpPlugins::Interface::Workspace::
100 HasFilter( const std::string& name ) const
102 if( this->m_Graph->HasVertexIndex( name ) )
103 return( this->GetFilter( name ) != NULL );
108 // -------------------------------------------------------------------------
109 cpPlugins::Interface::Workspace::
110 TFilter* cpPlugins::Interface::Workspace::
111 CreateFilter( const std::string& filter, const std::string& name )
113 if( this->m_Plugins == NULL )
116 // Get or create new filter from name
117 if( !( this->m_Graph->HasVertexIndex( name ) ) )
119 TFilter::Pointer f = this->m_Plugins->CreateObject( filter );
123 f->SetSingleInteractor( this->m_SingleInteractor );
124 f->SetMPRViewer( this->m_MPRViewer );
126 TObject::Pointer o = f.GetPointer( );
127 this->m_Graph->SetVertex( name, o );
130 return( f.GetPointer( ) );
133 return( this->GetFilter( name ) );
136 // -------------------------------------------------------------------------
137 bool cpPlugins::Interface::Workspace::
138 RenameFilter( const std::string& old_name, const std::string& new_name )
140 if( this->m_Graph->RenameVertex( old_name, new_name ) )
142 TFilter* f = this->GetFilter( new_name );
143 f->SetName( new_name );
150 // -------------------------------------------------------------------------
151 void cpPlugins::Interface::Workspace::
152 RemoveFilter( const std::string& name )
156 // -------------------------------------------------------------------------
157 vtkRenderWindowInteractor* cpPlugins::Interface::Workspace::
158 GetSingleInteractor( )
160 return( this->m_SingleInteractor );
163 // -------------------------------------------------------------------------
164 const vtkRenderWindowInteractor* cpPlugins::Interface::Workspace::
165 GetSingleInteractor( ) const
167 return( this->m_SingleInteractor );
170 // -------------------------------------------------------------------------
171 void cpPlugins::Interface::Workspace::
172 SetSingleInteractor( vtkRenderWindowInteractor* interactor )
174 this->m_SingleInteractor = interactor;
177 // -------------------------------------------------------------------------
178 cpPlugins::Interface::
179 SimpleMPRWidget* cpPlugins::Interface::Workspace::
182 return( this->m_MPRViewer );
185 // -------------------------------------------------------------------------
186 const cpPlugins::Interface::
187 SimpleMPRWidget* cpPlugins::Interface::Workspace::
188 GetMPRViewer( ) const
190 return( this->m_MPRViewer );
193 // -------------------------------------------------------------------------
194 void cpPlugins::Interface::Workspace::
195 SetMPRViewer( cpPlugins::Interface::SimpleMPRWidget* wdg )
197 this->m_MPRViewer = wdg;
200 // -------------------------------------------------------------------------
201 bool cpPlugins::Interface::Workspace::
203 const std::string& orig_filter, const std::string& dest_filter,
204 const std::string& output_name, const std::string& input_name
208 TFilter* orig = this->GetFilter( orig_filter );
209 TFilter* dest = this->GetFilter( dest_filter );
210 if( orig == NULL || dest == NULL )
214 if( dest->SetInput( input_name, orig->GetOutput( output_name ) ) )
216 this->m_Graph->AddEdge(
217 orig_filter, dest_filter,
218 TConnection( output_name, input_name )
226 // -------------------------------------------------------------------------
227 bool cpPlugins::Interface::Workspace::
229 const ProcessObjectPort& input_port, const std::string& exposed_port
232 auto port = this->m_ExposedInputPorts.find( exposed_port );
233 if( port != this->m_ExposedInputPorts.end( ) )
235 TFilter* filter = this->GetFilter( port->second.first );
237 return( filter->SetInput( port->second.second, input_port ) );
245 // -------------------------------------------------------------------------
246 bool cpPlugins::Interface::Workspace::
247 Reduce( const std::string& name )
252 // -------------------------------------------------------------------------
253 void cpPlugins::Interface::Workspace::
255 const std::string& name,
256 const std::string& filter, const std::string& filter_input
259 this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input );
262 // -------------------------------------------------------------------------
263 void cpPlugins::Interface::Workspace::
265 const std::string& name,
266 const std::string& filter, const std::string& filter_output
269 this->m_ExposedOutputPorts[ name ] = TExposedPort( filter, filter_output );
272 // -------------------------------------------------------------------------
273 void cpPlugins::Interface::Workspace::
274 HideInputPort( const std::string& name )
276 auto i = this->m_ExposedInputPorts.find( name );
277 if( i != this->m_ExposedInputPorts.end( ) )
278 this->m_ExposedInputPorts.erase( i );
281 // -------------------------------------------------------------------------
282 void cpPlugins::Interface::Workspace::
283 HideOutputPort( const std::string& name )
285 auto i = this->m_ExposedOutputPorts.find( name );
286 if( i != this->m_ExposedOutputPorts.end( ) )
287 this->m_ExposedOutputPorts.erase( i );
290 // -------------------------------------------------------------------------
291 bool cpPlugins::Interface::Workspace::
292 RenameExposedInputPort(
293 const std::string& old_name,
294 const std::string& new_name
297 auto o = this->m_ExposedInputPorts.find( old_name );
298 auto n = this->m_ExposedInputPorts.find( new_name );
300 o != this->m_ExposedInputPorts.end( ) &&
301 n == this->m_ExposedInputPorts.end( )
304 this->m_ExposedInputPorts[ new_name ] = o->second;
305 this->m_ExposedInputPorts.erase( o );
311 // -------------------------------------------------------------------------
312 bool cpPlugins::Interface::Workspace::
313 RenameExposedOutputPort(
314 const std::string& old_name,
315 const std::string& new_name
318 auto o = this->m_ExposedOutputPorts.find( old_name );
319 auto n = this->m_ExposedOutputPorts.find( new_name );
321 o != this->m_ExposedOutputPorts.end( ) &&
322 n == this->m_ExposedOutputPorts.end( )
325 this->m_ExposedOutputPorts[ new_name ] = o->second;
326 this->m_ExposedOutputPorts.erase( o );
332 // -------------------------------------------------------------------------
333 const cpPlugins::Interface::Workspace::
334 TExposedPorts& cpPlugins::Interface::Workspace::
335 GetExposedInputPorts( ) const
337 return( this->m_ExposedInputPorts );
340 // -------------------------------------------------------------------------
341 const cpPlugins::Interface::Workspace::
342 TExposedPorts& cpPlugins::Interface::Workspace::
343 GetExposedOutputPorts( ) const
345 return( this->m_ExposedOutputPorts );
348 // -------------------------------------------------------------------------
349 std::string cpPlugins::Interface::Workspace::
353 std::set< std::string > sinks = this->m_Graph->GetSinks( );
356 std::string err = "";
357 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
359 std::string lerr = this->Execute( *sIt );
361 err += lerr + std::string( "\n" );
367 // -------------------------------------------------------------------------
368 std::string cpPlugins::Interface::Workspace::
369 Execute( const std::string& name )
372 TFilter* f = this->GetFilter( name );
375 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
376 name + std::string( "\" is not a filter." )
379 // Execute and return
380 return( f->Update( ) );