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 );
119 TObject::Pointer o = f.GetPointer( );
120 this->m_Graph->SetVertex( name, o );
130 // -------------------------------------------------------------------------
131 bool cpPlugins::Interface::Workspace::
132 RenameFilter( const std::string& old_name, const std::string& new_name )
134 if( this->m_Graph->RenameVertex( old_name, new_name ) )
136 TFilter* f = this->GetFilter( new_name );
137 f->SetName( new_name );
144 // -------------------------------------------------------------------------
145 void cpPlugins::Interface::Workspace::
146 RemoveFilter( const std::string& name )
150 // -------------------------------------------------------------------------
151 bool cpPlugins::Interface::Workspace::
153 const std::string& orig_filter, const std::string& dest_filter,
154 const std::string& output_name, const std::string& input_name
158 TFilter* orig = this->GetFilter( orig_filter );
159 TFilter* dest = this->GetFilter( dest_filter );
160 if( orig == NULL || dest == NULL )
164 dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) );
165 this->m_Graph->AddEdge(
166 orig_filter, dest_filter,
167 TConnection( output_name, input_name )
172 // -------------------------------------------------------------------------
173 bool cpPlugins::Interface::Workspace::
174 Connect( TData* input_object, const std::string& input_name )
176 auto port = this->m_ExposedInputPorts.find( input_name );
177 if( port != this->m_ExposedInputPorts.end( ) )
179 TFilter* filter = this->GetFilter( port->second.first );
182 filter->SetInput( port->second.second, input_object );
192 // -------------------------------------------------------------------------
193 bool cpPlugins::Interface::Workspace::
194 Reduce( const std::string& name )
199 // -------------------------------------------------------------------------
200 void cpPlugins::Interface::Workspace::
202 const std::string& name,
203 const std::string& filter, const std::string& filter_input
206 this->m_ExposedInputPorts[ name ] = TExposedPort( filter, filter_input );
209 // -------------------------------------------------------------------------
210 void cpPlugins::Interface::Workspace::
212 const std::string& name,
213 const std::string& filter, const std::string& filter_output
216 this->m_ExposedOutputPorts[ name ] = TExposedPort( filter, filter_output );
219 // -------------------------------------------------------------------------
220 void cpPlugins::Interface::Workspace::
221 HideInputPort( const std::string& name )
223 auto i = this->m_ExposedInputPorts.find( name );
224 if( i != this->m_ExposedInputPorts.end( ) )
225 this->m_ExposedInputPorts.erase( i );
228 // -------------------------------------------------------------------------
229 void cpPlugins::Interface::Workspace::
230 HideOutputPort( const std::string& name )
232 auto i = this->m_ExposedOutputPorts.find( name );
233 if( i != this->m_ExposedOutputPorts.end( ) )
234 this->m_ExposedOutputPorts.erase( i );
237 // -------------------------------------------------------------------------
238 bool cpPlugins::Interface::Workspace::
239 RenameExposedInputPort(
240 const std::string& old_name,
241 const std::string& new_name
244 auto o = this->m_ExposedInputPorts.find( old_name );
245 auto n = this->m_ExposedInputPorts.find( new_name );
247 o != this->m_ExposedInputPorts.end( ) &&
248 n == this->m_ExposedInputPorts.end( )
251 this->m_ExposedInputPorts[ new_name ] = o->second;
252 this->m_ExposedInputPorts.erase( o );
258 // -------------------------------------------------------------------------
259 bool cpPlugins::Interface::Workspace::
260 RenameExposedOutputPort(
261 const std::string& old_name,
262 const std::string& new_name
265 auto o = this->m_ExposedOutputPorts.find( old_name );
266 auto n = this->m_ExposedOutputPorts.find( new_name );
268 o != this->m_ExposedOutputPorts.end( ) &&
269 n == this->m_ExposedOutputPorts.end( )
272 this->m_ExposedOutputPorts[ new_name ] = o->second;
273 this->m_ExposedOutputPorts.erase( o );
279 // -------------------------------------------------------------------------
281 cpPlugins::Interface::Workspace::
282 TData* cpPlugins::Interface::Workspace::
283 GetOutput( const std::string& name )
285 auto port = this->m_ExposedOutputPorts.find( name );
286 if( port != this->m_ExposedOutputPorts.end( ) )
288 TFilter* f = this->GetFilter( port->second.first );
290 return( f->GetOutput< TData >( port->second.second ) );
298 // -------------------------------------------------------------------------
299 const cpPlugins::Interface::Workspace::
300 TData* cpPlugins::Interface::Workspace::
301 GetOutput( const std::string& name ) const
303 auto port = this->m_ExposedOutputPorts.find( name );
304 if( port != this->m_ExposedOutputPorts.end( ) )
306 const TFilter* f = this->GetFilter( port->second.first );
308 return( f->GetOutput< TData >( port->second.second ) );
316 // -------------------------------------------------------------------------
317 void cpPlugins::Interface::Workspace::
320 this->m_ExposedInputPorts.clear( );
323 // -------------------------------------------------------------------------
324 void cpPlugins::Interface::Workspace::
327 this->m_ExposedOutputPorts.clear( );
331 // -------------------------------------------------------------------------
332 std::string cpPlugins::Interface::Workspace::
333 Execute( QWidget* p )
336 std::set< std::string > sinks = this->m_Graph->GetSinks( );
339 std::string err = "";
340 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
342 std::string lerr = this->Execute( *sIt, p );
344 err += lerr + std::string( "\n" );
350 // -------------------------------------------------------------------------
351 std::string cpPlugins::Interface::Workspace::
352 Execute( const std::string& name, QWidget* p )
355 TFilter* f = this->GetFilter( name );
358 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
359 name + std::string( "\" is not a filter." )
362 // Execute and return
365 auto diag_res = f->ExecConfigurationDialog( p );
366 if( diag_res == TFilter::DialogResult_NoModal )
367 return( f->Update( ) );
372 return( f->Update( ) );