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 std::cout << name << " " << filter << " " << filter_input << std::endl;
198 this->m_InputPorts[ name ] = TGlobalPort( filter, filter_input );
201 // -------------------------------------------------------------------------
202 void cpPlugins::Interface::Workspace::
204 const std::string& name,
205 const std::string& filter, const std::string& filter_output
208 this->m_OutputPorts[ name ] = TGlobalPort( filter, filter_output );
211 // -------------------------------------------------------------------------
212 cpPlugins::Interface::Workspace::
213 TData* cpPlugins::Interface::Workspace::
214 GetOutput( const std::string& name )
216 auto port = this->m_OutputPorts.find( name );
217 if( port != this->m_OutputPorts.end( ) )
219 TFilter* f = this->GetFilter( port->second.first );
221 return( f->GetOutput< TData >( port->second.second ) );
229 // -------------------------------------------------------------------------
230 const cpPlugins::Interface::Workspace::
231 TData* cpPlugins::Interface::Workspace::
232 GetOutput( const std::string& name ) const
234 auto port = this->m_OutputPorts.find( name );
235 if( port != this->m_OutputPorts.end( ) )
237 const TFilter* f = this->GetFilter( port->second.first );
239 return( f->GetOutput< TData >( port->second.second ) );
247 // -------------------------------------------------------------------------
248 void cpPlugins::Interface::Workspace::
251 this->m_InputPorts.clear( );
254 // -------------------------------------------------------------------------
255 void cpPlugins::Interface::Workspace::
258 this->m_OutputPorts.clear( );
261 // -------------------------------------------------------------------------
262 std::string cpPlugins::Interface::Workspace::
266 std::set< std::string > sinks = this->m_Graph->GetSinks( );
269 std::string err = "";
270 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
272 std::string lerr = this->Execute( *sIt, NULL );
274 err += lerr + std::string( "\n" );
280 // -------------------------------------------------------------------------
281 std::string cpPlugins::Interface::Workspace::
282 Execute( const std::string& name, QWidget* p )
285 TFilter* f = this->GetFilter( name );
288 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
289 name + std::string( "\" is not a filter." )
292 // Execute and return
295 auto diag_res = f->ExecConfigurationDialog( p );
296 if( diag_res == TFilter::DialogResult_NoModal )
297 return( f->Update( ) );
302 return( f->Update( ) );