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;
34 bool cpPlugins::Interface::Workspace::
35 LoadPluginsPath( const std::string& path, bool r )
37 // Load all plugins from given folder
38 std::list< std::string > files =
39 this->m_Interface.LoadFromFolder( path, r );
41 // Update a simple track
43 if( files.size( ) > 0 )
45 for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt )
47 this->m_LoadedPlugins.insert( *fIt );
48 this->m_LastLoadedPlugin = *fIt;
51 this->_UpdateLoadedPluginsInformation( );
58 // -------------------------------------------------------------------------
59 bool cpPlugins::Interface::Workspace::
60 LoadPlugins( const std::string& fname )
62 // Is it already loaded?
64 if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) )
66 // Was it succesfully loaded?
67 ret = this->m_Interface.Load( fname );
69 // Update a simple track
72 this->m_LoadedPlugins.insert( fname );
73 this->m_LastLoadedPlugin = fname;
74 this->_UpdateLoadedPluginsInformation( );
82 // -------------------------------------------------------------------------
83 const cpPlugins::Interface::Workspace::
84 TStringContainer& cpPlugins::Interface::Workspace::
85 GetLoadedPlugins( ) const
87 return( this->m_LoadedPlugins );
90 // -------------------------------------------------------------------------
91 void cpPlugins::Interface::Workspace::
92 GetLoadedPluginCategories( TStringContainer& categories ) const
95 auto fIt = this->m_LoadedFilters.begin( );
96 for( ; fIt != this->m_LoadedFilters.end( ); ++fIt )
97 categories.insert( fIt->first );
100 // -------------------------------------------------------------------------
101 void cpPlugins::Interface::Workspace::
102 GetLoadedPluginFilters( TStringContainer& filters ) const
105 auto pIt = this->m_LoadedFilters.begin( );
106 for( ; pIt != this->m_LoadedFilters.end( ); ++pIt )
107 for( auto fIt = pIt->second.begin( ); fIt != pIt->second.end( ); ++fIt )
108 filters.insert( *fIt );
111 // -------------------------------------------------------------------------
112 const cpPlugins::Interface::Workspace::
113 TStringContainer& cpPlugins::Interface::Workspace::
114 GetLoadedPluginFilters( const std::string& category ) const
116 static const TStringContainer EMPTY;
117 auto pIt = this->m_LoadedFilters.find( category );
118 if( pIt != this->m_LoadedFilters.end( ) )
119 return( pIt->second );
125 // -------------------------------------------------------------------------
126 void cpPlugins::Interface::Workspace::
129 if( this->m_Graph.IsNotNull( ) )
130 this->m_Graph->Clear( );
133 // -------------------------------------------------------------------------
134 cpPlugins::Interface::Workspace::
135 TGraph* cpPlugins::Interface::Workspace::
138 return( this->m_Graph );
141 // -------------------------------------------------------------------------
142 const cpPlugins::Interface::Workspace::
143 TGraph* cpPlugins::Interface::Workspace::
146 return( this->m_Graph );
149 // -------------------------------------------------------------------------
150 bool cpPlugins::Interface::Workspace::
151 CreateFilter( const std::string& filter, const std::string& name )
153 if( this->m_Interface == NULL )
156 // Get or create new filter from name
157 if( !( this->m_Graph->HasVertexIndex( name ) ) )
159 TFilter::Pointer f = this->m_Interface->CreateObject( filter );
163 TObject::Pointer o = f.GetPointer( );
164 this->m_Graph->SetVertex( name, o );
174 // -------------------------------------------------------------------------
175 bool cpPlugins::Interface::Workspace::
177 const std::string& orig_filter, const std::string& dest_filter,
178 const std::string& output_name, const std::string& input_name
183 dynamic_cast< TFilter* >(
184 this->m_Graph->GetVertex( orig_filter ).GetPointer( )
187 dynamic_cast< TFilter* >(
188 this->m_Graph->GetVertex( dest_filter ).GetPointer( )
190 if( orig == NULL || dest == NULL )
194 dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) );
195 this->m_Graph->AddConnection(
196 orig_filter, dest_filter,
197 TConnection( output_name, input_name )
202 // -------------------------------------------------------------------------
203 bool cpPlugins::Interface::Workspace::
204 Connect( const std::string& i, const std::string& o )
206 auto ii = this->m_InputPorts.find( i );
207 auto oi = this->m_OutputPorts.find( o );
208 if( ii != this->m_InputPorts.end( ) && oi != this->m_OutputPorts.end( ) )
221 // -------------------------------------------------------------------------
222 cpPlugins::Interface::Workspace::
223 TParameters* cpPlugins::Interface::Workspace::
224 GetParameters( const std::string& name )
227 dynamic_cast< TFilter* >(
228 this->m_Graph->GetVertex( name ).GetPointer( )
231 return( f->GetParameters( ) );
236 // -------------------------------------------------------------------------
237 const cpPlugins::Interface::Workspace::
238 TParameters* cpPlugins::Interface::Workspace::
239 GetParameters( const std::string& name ) const
242 dynamic_cast< const TFilter* >(
243 this->m_Graph->GetVertex( name ).GetPointer( )
246 return( f->GetParameters( ) );
251 // -------------------------------------------------------------------------
252 cpPlugins::Interface::Workspace::
253 TFilter* cpPlugins::Interface::Workspace::
254 GetFilter( const std::string& name )
257 dynamic_cast< TFilter* >(
258 this->m_Graph->GetVertex( name ).GetPointer( )
263 // -------------------------------------------------------------------------
264 const cpPlugins::Interface::Workspace::
265 TFilter* cpPlugins::Interface::Workspace::
266 GetFilter( const std::string& name ) const
269 dynamic_cast< const TFilter* >(
270 this->m_Graph->GetVertex( name ).GetPointer( )
275 // -------------------------------------------------------------------------
276 bool cpPlugins::Interface::Workspace::
277 HasFilter( const std::string& name ) const
279 if( this->m_Graph->HasVertexIndex( name ) )
280 return( this->GetFilter( name ) != NULL );
285 // -------------------------------------------------------------------------
286 bool cpPlugins::Interface::Workspace::
287 Reduce( const std::string& name )
292 // -------------------------------------------------------------------------
293 void cpPlugins::Interface::Workspace::
295 const std::string& name,
296 const std::string& filter, const std::string& filter_input
299 this->m_InputPorts[ name ] = TGlobalPort( filter, filter_input );
302 // -------------------------------------------------------------------------
303 void cpPlugins::Interface::Workspace::
305 const std::string& name,
306 const std::string& filter, const std::string& filter_output
309 this->m_OutputPorts[ name ] = TGlobalPort( filter, filter_output );
312 // -------------------------------------------------------------------------
313 void cpPlugins::Interface::Workspace::
316 this->m_InputPorts.clear( );
319 // -------------------------------------------------------------------------
320 void cpPlugins::Interface::Workspace::
323 this->m_OutputPorts.clear( );
326 // -------------------------------------------------------------------------
327 std::string cpPlugins::Interface::Workspace::
331 std::set< std::string > sinks = this->m_Graph->GetSinks( );
334 std::string err = "";
335 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
337 std::string lerr = this->Execute( *sIt, NULL );
339 err += lerr + std::string( "\n" );
345 // -------------------------------------------------------------------------
346 std::string cpPlugins::Interface::Workspace::
347 Execute( const std::string& name, QWidget* p )
351 dynamic_cast< TFilter* >(
352 this->m_Graph->GetVertex( name ).GetPointer( )
356 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
357 name + std::string( "\" is not a filter." )
360 // Execute and return
363 auto diag_res = f->ExecConfigurationDialog( p );
364 if( diag_res == TFilter::DialogResult_NoModal )
365 return( f->Update( ) );
370 return( f->Update( ) );
373 // -------------------------------------------------------------------------
374 void cpPlugins::Interface::Workspace::
375 _UpdateLoadedPluginsInformation( )
378 if( this->m_Interface != NULL )
380 this->m_LoadedFilters.clear( );
381 const TInterface::TClasses& cls = this->m_Interface->GetClasses( );
382 for( auto i = cls.begin( ); i != cls.end( ); ++i )
384 TFilter::Pointer o = this->m_Interface->CreateObject( i->first );
385 std::string name = o->GetClassName( );
386 std::string category = o->GetClassCategory( );
387 this->m_LoadedFilters[ category ].insert( name );