1 #include <cpPlugins/Interface/Workspace.h>
3 // -------------------------------------------------------------------------
4 cpPlugins::Interface::Workspace::
6 : m_LastLoadedPlugin( "" )
8 this->m_Graph = TGraph::New( );
11 // -------------------------------------------------------------------------
12 cpPlugins::Interface::Workspace::
17 // -------------------------------------------------------------------------
18 bool cpPlugins::Interface::Workspace::
19 LoadPluginsPath( const std::string& path, bool r )
21 // Load all plugins from given folder
22 std::list< std::string > files =
23 this->m_Interface.LoadFromFolder( path, r );
25 // Update a simple track
27 if( files.size( ) > 0 )
29 for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt )
31 this->m_LoadedPlugins.insert( *fIt );
32 this->m_LastLoadedPlugin = *fIt;
35 this->_UpdateLoadedPluginsInformation( );
42 // -------------------------------------------------------------------------
43 bool cpPlugins::Interface::Workspace::
44 LoadPlugins( const std::string& fname )
46 // Is it already loaded?
48 if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) )
50 // Was it succesfully loaded?
51 ret = this->m_Interface.Load( fname );
53 // Update a simple track
56 this->m_LoadedPlugins.insert( fname );
57 this->m_LastLoadedPlugin = fname;
58 this->_UpdateLoadedPluginsInformation( );
66 // -------------------------------------------------------------------------
67 const cpPlugins::Interface::Workspace::
68 TStringContainer& cpPlugins::Interface::Workspace::
69 GetLoadedPlugins( ) const
71 return( this->m_LoadedPlugins );
74 // -------------------------------------------------------------------------
75 void cpPlugins::Interface::Workspace::
76 GetLoadedPluginCategories( TStringContainer& categories ) const
79 auto fIt = this->m_LoadedFilters.begin( );
80 for( ; fIt != this->m_LoadedFilters.end( ); ++fIt )
81 categories.insert( fIt->first );
84 // -------------------------------------------------------------------------
85 void cpPlugins::Interface::Workspace::
86 GetLoadedPluginFilters( TStringContainer& filters ) const
89 auto pIt = this->m_LoadedFilters.begin( );
90 for( ; pIt != this->m_LoadedFilters.end( ); ++pIt )
91 for( auto fIt = pIt->second.begin( ); fIt != pIt->second.end( ); ++fIt )
92 filters.insert( *fIt );
95 // -------------------------------------------------------------------------
96 const cpPlugins::Interface::Workspace::
97 TStringContainer& cpPlugins::Interface::Workspace::
98 GetLoadedPluginFilters( const std::string& category ) const
100 static const TStringContainer EMPTY;
101 auto pIt = this->m_LoadedFilters.find( category );
102 if( pIt != this->m_LoadedFilters.end( ) )
103 return( pIt->second );
108 // -------------------------------------------------------------------------
109 void cpPlugins::Interface::Workspace::
112 if( this->m_Graph.IsNotNull( ) )
113 this->m_Graph->Clear( );
116 // -------------------------------------------------------------------------
117 cpPlugins::Interface::Workspace::
118 TGraph* cpPlugins::Interface::Workspace::
121 return( this->m_Graph );
124 // -------------------------------------------------------------------------
125 const cpPlugins::Interface::Workspace::
126 TGraph* cpPlugins::Interface::Workspace::
129 return( this->m_Graph );
132 // -------------------------------------------------------------------------
133 bool cpPlugins::Interface::Workspace::
134 CreateFilter( const std::string& filter, const std::string& name )
136 // Get or create new filter from name
137 if( !( this->m_Graph->HasVertexIndex( name ) ) )
139 TFilter::Pointer f = this->m_Interface.CreateObject( filter );
143 TObject::Pointer o = f.GetPointer( );
144 this->m_Graph->InsertVertex( name, o );
154 // -------------------------------------------------------------------------
155 bool cpPlugins::Interface::Workspace::
157 const std::string& orig_filter, const std::string& dest_filter,
158 const std::string& output_name, const std::string& input_name
163 dynamic_cast< TFilter* >(
164 this->m_Graph->GetVertex( orig_filter ).GetPointer( )
167 dynamic_cast< TFilter* >(
168 this->m_Graph->GetVertex( dest_filter ).GetPointer( )
170 if( orig == NULL || dest == NULL )
174 dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) );
175 this->m_Graph->AddConnection(
176 orig_filter, dest_filter,
177 TConnection( output_name, input_name )
182 // -------------------------------------------------------------------------
183 cpPlugins::Interface::Workspace::
184 TParameters* cpPlugins::Interface::Workspace::
185 GetParameters( const std::string& name )
188 dynamic_cast< TFilter* >(
189 this->m_Graph->GetVertex( name ).GetPointer( )
192 return( f->GetParameters( ) );
197 // -------------------------------------------------------------------------
198 const cpPlugins::Interface::Workspace::
199 TParameters* cpPlugins::Interface::Workspace::
200 GetParameters( const std::string& name ) const
203 dynamic_cast< const TFilter* >(
204 this->m_Graph->GetVertex( name ).GetPointer( )
207 return( f->GetParameters( ) );
212 // -------------------------------------------------------------------------
213 cpPlugins::Interface::Workspace::
214 TFilter* cpPlugins::Interface::Workspace::
215 GetFilter( const std::string& name )
218 dynamic_cast< TFilter* >(
219 this->m_Graph->GetVertex( name ).GetPointer( )
224 // -------------------------------------------------------------------------
225 const cpPlugins::Interface::Workspace::
226 TFilter* cpPlugins::Interface::Workspace::
227 GetFilter( const std::string& name ) const
230 dynamic_cast< const TFilter* >(
231 this->m_Graph->GetVertex( name ).GetPointer( )
236 // -------------------------------------------------------------------------
237 bool cpPlugins::Interface::Workspace::
238 HasFilter( const std::string& name ) const
240 if( this->m_Graph->HasVertexIndex( name ) )
241 return( this->GetFilter( name ) != NULL );
246 // -------------------------------------------------------------------------
247 bool cpPlugins::Interface::Workspace::
248 Reduce( const std::string& name )
253 // -------------------------------------------------------------------------
254 std::string cpPlugins::Interface::Workspace::
258 std::set< std::string > sinks = this->m_Graph->GetSinks( );
261 std::string err = "";
262 for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt )
264 std::string lerr = this->Execute( *sIt, NULL );
266 err += lerr + std::string( "\n" );
272 // -------------------------------------------------------------------------
273 std::string cpPlugins::Interface::Workspace::
274 Execute( const std::string& name, QWidget* p )
278 dynamic_cast< TFilter* >(
279 this->m_Graph->GetVertex( name ).GetPointer( )
283 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
284 name + std::string( "\" is not a filter." )
287 // Execute and return
290 auto diag_res = f->ExecConfigurationDialog( p );
291 if( diag_res == TFilter::DialogResult_NoModal )
292 return( f->Update( ) );
297 return( f->Update( ) );
300 // -------------------------------------------------------------------------
301 void cpPlugins::Interface::Workspace::
302 _UpdateLoadedPluginsInformation( )
304 this->m_LoadedFilters.clear( );
305 const TInterface::TClasses& cls = this->m_Interface.GetClasses( );
306 for( auto i = cls.begin( ); i != cls.end( ); ++i )
308 TFilter::Pointer o = this->m_Interface.CreateObject( i->first );
309 std::string name = o->GetClassName( );
310 std::string category = o->GetClassCategory( );
311 this->m_LoadedFilters[ category ].insert( name );