1 #include <cpPlugins/Interface/Workspace.h>
3 // -------------------------------------------------------------------------
4 cpPlugins::Interface::Workspace::
8 this->m_Graph = TGraph::New( );
11 // -------------------------------------------------------------------------
12 cpPlugins::Interface::Workspace::
17 // -------------------------------------------------------------------------
18 cpPlugins::Interface::Workspace::
19 TPlugins* cpPlugins::Interface::Workspace::
22 return( this->m_Plugins );
25 // -------------------------------------------------------------------------
26 const cpPlugins::Interface::Workspace::
27 TPlugins* cpPlugins::Interface::Workspace::
30 return( this->m_Plugins );
33 // -------------------------------------------------------------------------
34 void cpPlugins::Interface::Workspace::
35 SetPlugins( TPlugins* i )
37 if( this->m_Plugins != i )
41 // -------------------------------------------------------------------------
42 cpPlugins::Interface::Workspace::
43 TGraph* cpPlugins::Interface::Workspace::
46 return( this->m_Graph );
49 // -------------------------------------------------------------------------
50 const cpPlugins::Interface::Workspace::
51 TGraph* cpPlugins::Interface::Workspace::
54 return( this->m_Graph );
57 // -------------------------------------------------------------------------
58 void cpPlugins::Interface::Workspace::
61 if( this->m_Graph.IsNotNull( ) )
62 this->m_Graph->Clear( );
65 // -------------------------------------------------------------------------
66 void cpPlugins::Interface::Workspace::
71 // -------------------------------------------------------------------------
72 cpPlugins::Interface::Workspace::
73 TFilter* cpPlugins::Interface::Workspace::
74 GetFilter( const std::string& name )
77 dynamic_cast< TFilter* >(
78 this->m_Graph->GetVertex( name ).GetPointer( )
83 // -------------------------------------------------------------------------
84 const cpPlugins::Interface::Workspace::
85 TFilter* cpPlugins::Interface::Workspace::
86 GetFilter( const std::string& name ) const
89 dynamic_cast< const TFilter* >(
90 this->m_Graph->GetVertex( name ).GetPointer( )
95 // -------------------------------------------------------------------------
96 bool cpPlugins::Interface::Workspace::
97 HasFilter( const std::string& name ) const
99 if( this->m_Graph->HasVertexIndex( name ) )
100 return( this->GetFilter( name ) != NULL );
105 // -------------------------------------------------------------------------
106 bool cpPlugins::Interface::Workspace::
107 CreateFilter( const std::string& filter, const std::string& name )
109 if( this->m_Plugins == NULL )
112 // Get or create new filter from name
113 if( !( this->m_Graph->HasVertexIndex( name ) ) )
115 TFilter::Pointer f = this->m_Plugins->CreateObject( filter );
120 auto iIt = this->m_Interactors.begin( );
121 iIt != this->m_Interactors.end( );
124 f->AddInteractor( *iIt );
126 TObject::Pointer o = f.GetPointer( );
127 this->m_Graph->SetVertex( name, o );
137 // -------------------------------------------------------------------------
138 bool cpPlugins::Interface::Workspace::
139 RenameFilter( const std::string& old_name, const std::string& new_name )
141 if( this->m_Graph->RenameVertex( old_name, new_name ) )
143 TFilter* f = this->GetFilter( new_name );
144 f->SetName( new_name );
151 // -------------------------------------------------------------------------
152 void cpPlugins::Interface::Workspace::
153 RemoveFilter( const std::string& name )
157 // -------------------------------------------------------------------------
158 const cpPlugins::Interface::Workspace::
159 TInteractors& cpPlugins::Interface::Workspace::
160 GetInteractors( ) const
162 return( this->m_Interactors );
165 // -------------------------------------------------------------------------
166 void cpPlugins::Interface::Workspace::
167 AddInteractor( vtkRenderWindowInteractor* interactor )
169 this->m_Interactors.insert( interactor );
172 // -------------------------------------------------------------------------
173 bool cpPlugins::Interface::Workspace::
175 const std::string& orig_filter, const std::string& dest_filter,
176 const std::string& output_name, const std::string& input_name
180 TFilter* orig = this->GetFilter( orig_filter );
181 TFilter* dest = this->GetFilter( dest_filter );
182 if( orig == NULL || dest == NULL )
186 dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) );
187 this->m_Graph->AddEdge(
188 orig_filter, dest_filter,
189 TConnection( output_name, input_name )
194 // -------------------------------------------------------------------------
195 bool cpPlugins::Interface::Workspace::
196 Connect( TData* input_object, const std::string& input_name )
198 auto port = this->m_ExposedInputPorts.find( input_name );
199 if( port != this->m_ExposedInputPorts.end( ) )
201 TFilter* filter = this->GetFilter( port->second.first );
204 filter->SetInput( port->second.second, input_object );
214 // -------------------------------------------------------------------------
215 bool cpPlugins::Interface::Workspace::
216 Reduce( const std::string& name )
221 // -------------------------------------------------------------------------
222 void cpPlugins::Interface::Workspace::
224 const std::string& name,
225 const std::string& filter, const std::string& filter_input
228 this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input );
231 // -------------------------------------------------------------------------
232 void cpPlugins::Interface::Workspace::
234 const std::string& name,
235 const std::string& filter, const std::string& filter_output
238 this->m_ExposedOutputPorts[ name ] = TExposedPort( filter, filter_output );
241 // -------------------------------------------------------------------------
242 void cpPlugins::Interface::Workspace::
243 HideInputPort( const std::string& name )
245 auto i = this->m_ExposedInputPorts.find( name );
246 if( i != this->m_ExposedInputPorts.end( ) )
247 this->m_ExposedInputPorts.erase( i );
250 // -------------------------------------------------------------------------
251 void cpPlugins::Interface::Workspace::
252 HideOutputPort( const std::string& name )
254 auto i = this->m_ExposedOutputPorts.find( name );
255 if( i != this->m_ExposedOutputPorts.end( ) )
256 this->m_ExposedOutputPorts.erase( i );
259 // -------------------------------------------------------------------------
260 bool cpPlugins::Interface::Workspace::
261 RenameExposedInputPort(
262 const std::string& old_name,
263 const std::string& new_name
266 auto o = this->m_ExposedInputPorts.find( old_name );
267 auto n = this->m_ExposedInputPorts.find( new_name );
269 o != this->m_ExposedInputPorts.end( ) &&
270 n == this->m_ExposedInputPorts.end( )
273 this->m_ExposedInputPorts[ new_name ] = o->second;
274 this->m_ExposedInputPorts.erase( o );
280 // -------------------------------------------------------------------------
281 bool cpPlugins::Interface::Workspace::
282 RenameExposedOutputPort(
283 const std::string& old_name,
284 const std::string& new_name
287 auto o = this->m_ExposedOutputPorts.find( old_name );
288 auto n = this->m_ExposedOutputPorts.find( new_name );
290 o != this->m_ExposedOutputPorts.end( ) &&
291 n == this->m_ExposedOutputPorts.end( )
294 this->m_ExposedOutputPorts[ new_name ] = o->second;
295 this->m_ExposedOutputPorts.erase( o );
301 // -------------------------------------------------------------------------
302 const cpPlugins::Interface::Workspace::
303 TExposedPorts& cpPlugins::Interface::Workspace::
304 GetExposedInputPorts( ) const
306 return( this->m_ExposedInputPorts );
309 // -------------------------------------------------------------------------
310 const cpPlugins::Interface::Workspace::
311 TExposedPorts& cpPlugins::Interface::Workspace::
312 GetExposedOutputPorts( ) const
314 return( this->m_ExposedOutputPorts );
317 // -------------------------------------------------------------------------
318 std::string cpPlugins::Interface::Workspace::
322 std::set< std::string > sinks = this->m_Graph->GetSinks( );
325 std::string err = "";
326 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
328 std::string lerr = this->Execute( *sIt );
330 err += lerr + std::string( "\n" );
336 // -------------------------------------------------------------------------
337 std::string cpPlugins::Interface::Workspace::
338 Execute( const std::string& name )
341 TFilter* f = this->GetFilter( name );
344 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
345 name + std::string( "\" is not a filter." )
348 // Execute and return
349 return( f->Update( ) );