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 std::cout << "wNAME: " << filter << " " << name << std::endl;
139 auto i = this->m_Graph->BeginVertices( );
140 i != this->m_Graph->EndVertices( );
143 std::cout << "wOBJ: " << i->first << std::endl;
146 // Get or create new filter from name
147 if( !( this->m_Graph->HasVertexIndex( name ) ) )
149 std::cout << "wok" << std::endl;
151 TFilter::Pointer f = this->m_Interface.CreateObject( filter );
155 TObject::Pointer o = f.GetPointer( );
156 o->Print( std::cout );
157 this->m_Graph->InsertVertex( name, o );
165 std::cout << "wno" << std::endl;
170 // -------------------------------------------------------------------------
171 bool cpPlugins::Interface::Workspace::
173 const std::string& orig_filter, const std::string& dest_filter,
174 const std::string& output_name, const std::string& input_name
179 dynamic_cast< TFilter* >(
180 this->m_Graph->GetVertex( orig_filter ).GetPointer( )
183 dynamic_cast< TFilter* >(
184 this->m_Graph->GetVertex( dest_filter ).GetPointer( )
186 if( orig == NULL || dest == NULL )
190 dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) );
191 this->m_Graph->AddConnection(
192 orig_filter, dest_filter,
193 TConnection( output_name, input_name )
198 // -------------------------------------------------------------------------
199 cpPlugins::Interface::Workspace::
200 TParameters* cpPlugins::Interface::Workspace::
201 GetParameters( const std::string& name )
204 dynamic_cast< TFilter* >(
205 this->m_Graph->GetVertex( name ).GetPointer( )
208 return( f->GetParameters( ) );
213 // -------------------------------------------------------------------------
214 const cpPlugins::Interface::Workspace::
215 TParameters* cpPlugins::Interface::Workspace::
216 GetParameters( const std::string& name ) const
219 dynamic_cast< const TFilter* >(
220 this->m_Graph->GetVertex( name ).GetPointer( )
223 return( f->GetParameters( ) );
228 // -------------------------------------------------------------------------
229 cpPlugins::Interface::Workspace::
230 TFilter* cpPlugins::Interface::Workspace::
231 GetFilter( const std::string& name )
234 dynamic_cast< TFilter* >(
235 this->m_Graph->GetVertex( name ).GetPointer( )
240 // -------------------------------------------------------------------------
241 const cpPlugins::Interface::Workspace::
242 TFilter* cpPlugins::Interface::Workspace::
243 GetFilter( const std::string& name ) const
246 dynamic_cast< const TFilter* >(
247 this->m_Graph->GetVertex( name ).GetPointer( )
252 // -------------------------------------------------------------------------
253 bool cpPlugins::Interface::Workspace::
254 Reduce( const std::string& name )
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 )
284 dynamic_cast< TFilter* >(
285 this->m_Graph->GetVertex( name ).GetPointer( )
289 std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) +
290 name + std::string( "\" is not a filter." )
293 // Execute and return
296 auto diag_res = f->ExecConfigurationDialog( p );
297 if( diag_res == TFilter::DialogResult_NoModal )
298 return( f->Update( ) );
303 return( f->Update( ) );
306 // -------------------------------------------------------------------------
307 void cpPlugins::Interface::Workspace::
308 _UpdateLoadedPluginsInformation( )
310 this->m_LoadedFilters.clear( );
311 const TInterface::TClasses& cls = this->m_Interface.GetClasses( );
312 for( auto i = cls.begin( ); i != cls.end( ); ++i )
314 TFilter::Pointer o = this->m_Interface.CreateObject( i->first );
315 std::string name = o->GetClassName( );
316 std::string category = o->GetClassCategory( );
317 this->m_LoadedFilters[ category ].insert( name );