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 TInterface* cpPlugins::Interface::Workspace::
22 return( this->m_Interface );
25 // -------------------------------------------------------------------------
26 void cpPlugins::Interface::Workspace::
27 SetInterface( TInterface* i )
29 if( this->m_Interface != i )
30 this->m_Interface = i;
33 // -------------------------------------------------------------------------
34 void cpPlugins::Interface::Workspace::
37 if( this->m_Graph.IsNotNull( ) )
38 this->m_Graph->Clear( );
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 bool cpPlugins::Interface::Workspace::
59 CreateFilter( const std::string& filter, const std::string& name )
61 if( this->m_Interface == NULL )
64 // Get or create new filter from name
65 if( !( this->m_Graph->HasVertexIndex( name ) ) )
67 TFilter::Pointer f = this->m_Interface->CreateObject( filter );
71 TObject::Pointer o = f.GetPointer( );
72 this->m_Graph->SetVertex( name, o );
82 // -------------------------------------------------------------------------
83 bool cpPlugins::Interface::Workspace::
85 const std::string& orig_filter, const std::string& dest_filter,
86 const std::string& output_name, const std::string& input_name
90 TFilter* orig = this->GetFilter( orig_filter );
91 TFilter* dest = this->GetFilter( dest_filter );
92 if( orig == NULL || dest == NULL )
96 dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) );
97 this->m_Graph->AddConnection(
98 orig_filter, dest_filter,
99 TConnection( output_name, input_name )
104 // -------------------------------------------------------------------------
105 bool cpPlugins::Interface::Workspace::
106 Connect( TData* input_object, const std::string& input_name )
108 auto port = this->m_InputPorts.find( input_name );
109 if( port != this->m_InputPorts.end( ) )
111 TFilter* filter = this->GetFilter( port->second.first );
114 filter->SetInput( port->second.second, input_object );
124 // -------------------------------------------------------------------------
125 cpPlugins::Interface::Workspace::
126 TParameters* cpPlugins::Interface::Workspace::
127 GetParameters( const std::string& name )
129 TFilter* f = this->GetFilter( name );
131 return( f->GetParameters( ) );
136 // -------------------------------------------------------------------------
137 const cpPlugins::Interface::Workspace::
138 TParameters* cpPlugins::Interface::Workspace::
139 GetParameters( const std::string& name ) const
141 const TFilter* f = this->GetFilter( name );
143 return( f->GetParameters( ) );
148 // -------------------------------------------------------------------------
149 cpPlugins::Interface::Workspace::
150 TFilter* cpPlugins::Interface::Workspace::
151 GetFilter( const std::string& name )
154 dynamic_cast< TFilter* >(
155 this->m_Graph->GetVertex( name ).GetPointer( )
160 // -------------------------------------------------------------------------
161 const cpPlugins::Interface::Workspace::
162 TFilter* cpPlugins::Interface::Workspace::
163 GetFilter( const std::string& name ) const
166 dynamic_cast< const TFilter* >(
167 this->m_Graph->GetVertex( name ).GetPointer( )
172 // -------------------------------------------------------------------------
173 bool cpPlugins::Interface::Workspace::
174 HasFilter( const std::string& name ) const
176 if( this->m_Graph->HasVertexIndex( name ) )
177 return( this->GetFilter( name ) != NULL );
182 // -------------------------------------------------------------------------
183 bool cpPlugins::Interface::Workspace::
184 Reduce( const std::string& name )
189 // -------------------------------------------------------------------------
190 void cpPlugins::Interface::Workspace::
192 const std::string& name,
193 const std::string& filter, const std::string& filter_input
196 this->m_InputPorts[ name ] = TGlobalPort( filter, filter_input );
199 // -------------------------------------------------------------------------
200 void cpPlugins::Interface::Workspace::
202 const std::string& name,
203 const std::string& filter, const std::string& filter_output
206 this->m_OutputPorts[ name ] = TGlobalPort( filter, filter_output );
209 // -------------------------------------------------------------------------
210 cpPlugins::Interface::Workspace::
211 TData* cpPlugins::Interface::Workspace::
212 GetOutput( const std::string& name )
214 auto port = this->m_OutputPorts.find( name );
215 if( port != this->m_OutputPorts.end( ) )
217 TFilter* f = this->GetFilter( port->second.first );
219 return( f->GetOutput< TData >( port->second.second ) );
227 // -------------------------------------------------------------------------
228 const cpPlugins::Interface::Workspace::
229 TData* cpPlugins::Interface::Workspace::
230 GetOutput( const std::string& name ) const
232 auto port = this->m_OutputPorts.find( name );
233 if( port != this->m_OutputPorts.end( ) )
235 const TFilter* f = this->GetFilter( port->second.first );
237 return( f->GetOutput< TData >( port->second.second ) );
245 // -------------------------------------------------------------------------
246 void cpPlugins::Interface::Workspace::
249 this->m_InputPorts.clear( );
252 // -------------------------------------------------------------------------
253 void cpPlugins::Interface::Workspace::
256 this->m_OutputPorts.clear( );
259 // -------------------------------------------------------------------------
260 std::string cpPlugins::Interface::Workspace::
264 std::set< std::string > sinks = this->m_Graph->GetSinks( );
267 std::string err = "";
268 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
270 std::string lerr = this->Execute( *sIt, NULL );
272 err += lerr + std::string( "\n" );
278 // -------------------------------------------------------------------------
279 std::string cpPlugins::Interface::Workspace::
280 Execute( const std::string& name, QWidget* p )
283 TFilter* f = this->GetFilter( name );
286 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
287 name + std::string( "\" is not a filter." )
290 // Execute and return
293 auto diag_res = f->ExecConfigurationDialog( p );
294 if( diag_res == TFilter::DialogResult_NoModal )
295 return( f->Update( ) );
300 return( f->Update( ) );