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 cpPlugins::Interface::Workspace::
204 TParameters* cpPlugins::Interface::Workspace::
205 GetParameters( const std::string& name )
208 dynamic_cast< TFilter* >(
209 this->m_Graph->GetVertex( name ).GetPointer( )
212 return( f->GetParameters( ) );
217 // -------------------------------------------------------------------------
218 const cpPlugins::Interface::Workspace::
219 TParameters* cpPlugins::Interface::Workspace::
220 GetParameters( const std::string& name ) const
223 dynamic_cast< const TFilter* >(
224 this->m_Graph->GetVertex( name ).GetPointer( )
227 return( f->GetParameters( ) );
232 // -------------------------------------------------------------------------
233 cpPlugins::Interface::Workspace::
234 TFilter* cpPlugins::Interface::Workspace::
235 GetFilter( const std::string& name )
238 dynamic_cast< TFilter* >(
239 this->m_Graph->GetVertex( name ).GetPointer( )
244 // -------------------------------------------------------------------------
245 const cpPlugins::Interface::Workspace::
246 TFilter* cpPlugins::Interface::Workspace::
247 GetFilter( const std::string& name ) const
250 dynamic_cast< const TFilter* >(
251 this->m_Graph->GetVertex( name ).GetPointer( )
256 // -------------------------------------------------------------------------
257 bool cpPlugins::Interface::Workspace::
258 HasFilter( const std::string& name ) const
260 if( this->m_Graph->HasVertexIndex( name ) )
261 return( this->GetFilter( name ) != NULL );
266 // -------------------------------------------------------------------------
267 bool cpPlugins::Interface::Workspace::
268 Reduce( const std::string& name )
273 // -------------------------------------------------------------------------
274 std::string cpPlugins::Interface::Workspace::
278 std::set< std::string > sinks = this->m_Graph->GetSinks( );
281 std::string err = "";
282 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
284 std::string lerr = this->Execute( *sIt, NULL );
286 err += lerr + std::string( "\n" );
292 // -------------------------------------------------------------------------
293 std::string cpPlugins::Interface::Workspace::
294 Execute( const std::string& name, QWidget* p )
298 dynamic_cast< TFilter* >(
299 this->m_Graph->GetVertex( name ).GetPointer( )
303 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
304 name + std::string( "\" is not a filter." )
307 // Execute and return
310 auto diag_res = f->ExecConfigurationDialog( p );
311 if( diag_res == TFilter::DialogResult_NoModal )
312 return( f->Update( ) );
317 return( f->Update( ) );
320 // -------------------------------------------------------------------------
321 void cpPlugins::Interface::Workspace::
322 _UpdateLoadedPluginsInformation( )
325 if( this->m_Interface != NULL )
327 this->m_LoadedFilters.clear( );
328 const TInterface::TClasses& cls = this->m_Interface->GetClasses( );
329 for( auto i = cls.begin( ); i != cls.end( ); ++i )
331 TFilter::Pointer o = this->m_Interface->CreateObject( i->first );
332 std::string name = o->GetClassName( );
333 std::string category = o->GetClassCategory( );
334 this->m_LoadedFilters[ category ].insert( name );