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 dest->SetInput( input_name, orig->GetOutputPort( output_name ) );
215 this->m_Graph->AddEdge(
216 orig_filter, dest_filter,
217 TConnection( output_name, input_name )
222 // -------------------------------------------------------------------------
223 bool cpPlugins::Interface::Workspace::
224 Connect( TData::Pointer* input_object, const std::string& input_name )
226 auto port = this->m_ExposedInputPorts.find( input_name );
227 if( port != this->m_ExposedInputPorts.end( ) )
229 TFilter* filter = this->GetFilter( port->second.first );
232 filter->SetInput( port->second.second, input_object );
242 // -------------------------------------------------------------------------
243 bool cpPlugins::Interface::Workspace::
244 Reduce( const std::string& name )
249 // -------------------------------------------------------------------------
250 void cpPlugins::Interface::Workspace::
252 const std::string& name,
253 const std::string& filter, const std::string& filter_input
256 this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input );
259 // -------------------------------------------------------------------------
260 void cpPlugins::Interface::Workspace::
262 const std::string& name,
263 const std::string& filter, const std::string& filter_output
266 this->m_ExposedOutputPorts[ name ] = TExposedPort( filter, filter_output );
269 // -------------------------------------------------------------------------
270 void cpPlugins::Interface::Workspace::
271 HideInputPort( const std::string& name )
273 auto i = this->m_ExposedInputPorts.find( name );
274 if( i != this->m_ExposedInputPorts.end( ) )
275 this->m_ExposedInputPorts.erase( i );
278 // -------------------------------------------------------------------------
279 void cpPlugins::Interface::Workspace::
280 HideOutputPort( const std::string& name )
282 auto i = this->m_ExposedOutputPorts.find( name );
283 if( i != this->m_ExposedOutputPorts.end( ) )
284 this->m_ExposedOutputPorts.erase( i );
287 // -------------------------------------------------------------------------
288 bool cpPlugins::Interface::Workspace::
289 RenameExposedInputPort(
290 const std::string& old_name,
291 const std::string& new_name
294 auto o = this->m_ExposedInputPorts.find( old_name );
295 auto n = this->m_ExposedInputPorts.find( new_name );
297 o != this->m_ExposedInputPorts.end( ) &&
298 n == this->m_ExposedInputPorts.end( )
301 this->m_ExposedInputPorts[ new_name ] = o->second;
302 this->m_ExposedInputPorts.erase( o );
308 // -------------------------------------------------------------------------
309 bool cpPlugins::Interface::Workspace::
310 RenameExposedOutputPort(
311 const std::string& old_name,
312 const std::string& new_name
315 auto o = this->m_ExposedOutputPorts.find( old_name );
316 auto n = this->m_ExposedOutputPorts.find( new_name );
318 o != this->m_ExposedOutputPorts.end( ) &&
319 n == this->m_ExposedOutputPorts.end( )
322 this->m_ExposedOutputPorts[ new_name ] = o->second;
323 this->m_ExposedOutputPorts.erase( o );
329 // -------------------------------------------------------------------------
330 const cpPlugins::Interface::Workspace::
331 TExposedPorts& cpPlugins::Interface::Workspace::
332 GetExposedInputPorts( ) const
334 return( this->m_ExposedInputPorts );
337 // -------------------------------------------------------------------------
338 const cpPlugins::Interface::Workspace::
339 TExposedPorts& cpPlugins::Interface::Workspace::
340 GetExposedOutputPorts( ) const
342 return( this->m_ExposedOutputPorts );
345 // -------------------------------------------------------------------------
346 std::string cpPlugins::Interface::Workspace::
350 std::set< std::string > sinks = this->m_Graph->GetSinks( );
353 std::string err = "";
354 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
356 std::string lerr = this->Execute( *sIt );
358 err += lerr + std::string( "\n" );
364 // -------------------------------------------------------------------------
365 std::string cpPlugins::Interface::Workspace::
366 Execute( const std::string& name )
369 TFilter* f = this->GetFilter( name );
372 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
373 name + std::string( "\" is not a filter." )
376 // Execute and return
377 return( f->Update( ) );