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 );
122 f->SetSingleInteractor( this->m_SingleInteractor );
123 f->SetMPRViewer( this->m_MPRViewer );
125 TObject::Pointer o = f.GetPointer( );
126 this->m_Graph->SetVertex( name, o );
129 return( f.GetPointer( ) );
132 return( this->GetFilter( name ) );
135 // -------------------------------------------------------------------------
136 bool cpPlugins::Interface::Workspace::
137 RenameFilter( const std::string& old_name, const std::string& new_name )
139 return( this->m_Graph->RenameVertex( old_name, new_name ) );
142 // -------------------------------------------------------------------------
143 void cpPlugins::Interface::Workspace::
144 RemoveFilter( const std::string& name )
148 // -------------------------------------------------------------------------
149 vtkRenderWindowInteractor* cpPlugins::Interface::Workspace::
150 GetSingleInteractor( )
152 return( this->m_SingleInteractor );
155 // -------------------------------------------------------------------------
156 const vtkRenderWindowInteractor* cpPlugins::Interface::Workspace::
157 GetSingleInteractor( ) const
159 return( this->m_SingleInteractor );
162 // -------------------------------------------------------------------------
163 void cpPlugins::Interface::Workspace::
164 SetSingleInteractor( vtkRenderWindowInteractor* interactor )
166 this->m_SingleInteractor = interactor;
169 // -------------------------------------------------------------------------
170 cpPlugins::Interface::
171 SimpleMPRWidget* cpPlugins::Interface::Workspace::
174 return( this->m_MPRViewer );
177 // -------------------------------------------------------------------------
178 const cpPlugins::Interface::
179 SimpleMPRWidget* cpPlugins::Interface::Workspace::
180 GetMPRViewer( ) const
182 return( this->m_MPRViewer );
185 // -------------------------------------------------------------------------
186 void cpPlugins::Interface::Workspace::
187 SetMPRViewer( cpPlugins::Interface::SimpleMPRWidget* wdg )
189 this->m_MPRViewer = wdg;
192 // -------------------------------------------------------------------------
193 bool cpPlugins::Interface::Workspace::
195 const std::string& orig_filter, const std::string& dest_filter,
196 const std::string& output_name, const std::string& input_name
200 TFilter* orig = this->GetFilter( orig_filter );
201 TFilter* dest = this->GetFilter( dest_filter );
202 if( orig == NULL || dest == NULL )
206 if( dest->SetInput( input_name, orig->GetOutput( output_name ) ) )
208 this->m_Graph->AddEdge(
209 orig_filter, dest_filter,
210 TConnection( output_name, input_name )
218 // -------------------------------------------------------------------------
219 bool cpPlugins::Interface::Workspace::
221 const OutputProcessObjectPort& port, const std::string& exposed_port
224 auto i = this->m_ExposedInputPorts.find( exposed_port );
225 if( i != this->m_ExposedInputPorts.end( ) )
227 TFilter* filter = this->GetFilter( i->second.first );
229 return( filter->SetInput( i->second.second, port ) );
237 // -------------------------------------------------------------------------
238 bool cpPlugins::Interface::Workspace::
239 Reduce( const std::string& name )
244 // -------------------------------------------------------------------------
245 void cpPlugins::Interface::Workspace::
247 const std::string& name,
248 const std::string& filter, const std::string& filter_input
251 this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input );
254 // -------------------------------------------------------------------------
255 void cpPlugins::Interface::Workspace::
257 const std::string& name,
258 const std::string& filter, const std::string& filter_output
261 this->m_ExposedOutputPorts[ name ] = TExposedPort( filter, filter_output );
264 // -------------------------------------------------------------------------
265 void cpPlugins::Interface::Workspace::
266 HideInputPort( const std::string& name )
268 auto i = this->m_ExposedInputPorts.find( name );
269 if( i != this->m_ExposedInputPorts.end( ) )
270 this->m_ExposedInputPorts.erase( i );
273 // -------------------------------------------------------------------------
274 void cpPlugins::Interface::Workspace::
275 HideOutputPort( const std::string& name )
277 auto i = this->m_ExposedOutputPorts.find( name );
278 if( i != this->m_ExposedOutputPorts.end( ) )
279 this->m_ExposedOutputPorts.erase( i );
282 // -------------------------------------------------------------------------
283 bool cpPlugins::Interface::Workspace::
284 RenameExposedInputPort(
285 const std::string& old_name,
286 const std::string& new_name
289 auto o = this->m_ExposedInputPorts.find( old_name );
290 auto n = this->m_ExposedInputPorts.find( new_name );
292 o != this->m_ExposedInputPorts.end( ) &&
293 n == this->m_ExposedInputPorts.end( )
296 this->m_ExposedInputPorts[ new_name ] = o->second;
297 this->m_ExposedInputPorts.erase( o );
303 // -------------------------------------------------------------------------
304 bool cpPlugins::Interface::Workspace::
305 RenameExposedOutputPort(
306 const std::string& old_name,
307 const std::string& new_name
310 auto o = this->m_ExposedOutputPorts.find( old_name );
311 auto n = this->m_ExposedOutputPorts.find( new_name );
313 o != this->m_ExposedOutputPorts.end( ) &&
314 n == this->m_ExposedOutputPorts.end( )
317 this->m_ExposedOutputPorts[ new_name ] = o->second;
318 this->m_ExposedOutputPorts.erase( o );
324 // -------------------------------------------------------------------------
325 const cpPlugins::Interface::Workspace::
326 TExposedPorts& cpPlugins::Interface::Workspace::
327 GetExposedInputPorts( ) const
329 return( this->m_ExposedInputPorts );
332 // -------------------------------------------------------------------------
333 const cpPlugins::Interface::Workspace::
334 TExposedPorts& cpPlugins::Interface::Workspace::
335 GetExposedOutputPorts( ) const
337 return( this->m_ExposedOutputPorts );
340 // -------------------------------------------------------------------------
341 std::string cpPlugins::Interface::Workspace::
345 std::set< std::string > sinks = this->m_Graph->GetSinks( );
348 std::string err = "";
349 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
351 std::string lerr = this->Execute( *sIt );
353 err += lerr + std::string( "\n" );
359 // -------------------------------------------------------------------------
360 std::string cpPlugins::Interface::Workspace::
361 Execute( const std::string& name )
364 TFilter* f = this->GetFilter( name );
367 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
368 name + std::string( "\" is not a filter." )
371 // Execute and return
372 return( f->Update( ) );