#include // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: Workspace( ) : m_Interface( NULL ) { this->m_Graph = TGraph::New( ); } // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: ~Workspace( ) { } // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: TInterface* cpPlugins::Interface::Workspace:: GetInterface( ) { return( this->m_Interface ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: SetInterface( TInterface* i ) { if( this->m_Interface != i ) this->m_Interface = i; } /* TODO bool cpPlugins::Interface::Workspace:: LoadPluginsPath( const std::string& path, bool r ) { // Load all plugins from given folder std::list< std::string > files = this->m_Interface.LoadFromFolder( path, r ); // Update a simple track bool ret = false; if( files.size( ) > 0 ) { for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt ) { this->m_LoadedPlugins.insert( *fIt ); this->m_LastLoadedPlugin = *fIt; } // rof this->_UpdateLoadedPluginsInformation( ); ret = true; } // fi return( ret ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: LoadPlugins( const std::string& fname ) { // Is it already loaded? bool ret = true; if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) ) { // Was it succesfully loaded? ret = this->m_Interface.Load( fname ); // Update a simple track if( ret ) { this->m_LoadedPlugins.insert( fname ); this->m_LastLoadedPlugin = fname; this->_UpdateLoadedPluginsInformation( ); } // fi } // fi return( ret ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::Workspace:: TStringContainer& cpPlugins::Interface::Workspace:: GetLoadedPlugins( ) const { return( this->m_LoadedPlugins ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: GetLoadedPluginCategories( TStringContainer& categories ) const { categories.clear( ); auto fIt = this->m_LoadedFilters.begin( ); for( ; fIt != this->m_LoadedFilters.end( ); ++fIt ) categories.insert( fIt->first ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: GetLoadedPluginFilters( TStringContainer& filters ) const { filters.clear( ); auto pIt = this->m_LoadedFilters.begin( ); for( ; pIt != this->m_LoadedFilters.end( ); ++pIt ) for( auto fIt = pIt->second.begin( ); fIt != pIt->second.end( ); ++fIt ) filters.insert( *fIt ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::Workspace:: TStringContainer& cpPlugins::Interface::Workspace:: GetLoadedPluginFilters( const std::string& category ) const { static const TStringContainer EMPTY; auto pIt = this->m_LoadedFilters.find( category ); if( pIt != this->m_LoadedFilters.end( ) ) return( pIt->second ); else return( EMPTY ); } */ // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: Clear( ) { if( this->m_Graph.IsNotNull( ) ) this->m_Graph->Clear( ); } // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: TGraph* cpPlugins::Interface::Workspace:: GetGraph( ) { return( this->m_Graph ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::Workspace:: TGraph* cpPlugins::Interface::Workspace:: GetGraph( ) const { return( this->m_Graph ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: CreateFilter( const std::string& filter, const std::string& name ) { if( this->m_Interface == NULL ) return( false ); // Get or create new filter from name if( !( this->m_Graph->HasVertexIndex( name ) ) ) { TFilter::Pointer f = this->m_Interface->CreateObject( filter ); if( f.IsNotNull( ) ) { f->SetName( name ); TObject::Pointer o = f.GetPointer( ); this->m_Graph->SetVertex( name, o ); return( true ); } else return( false ); } else return( true ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: Connect( const std::string& orig_filter, const std::string& dest_filter, const std::string& output_name, const std::string& input_name ) { // Get filters TFilter* orig = dynamic_cast< TFilter* >( this->m_Graph->GetVertex( orig_filter ).GetPointer( ) ); TFilter* dest = dynamic_cast< TFilter* >( this->m_Graph->GetVertex( dest_filter ).GetPointer( ) ); if( orig == NULL || dest == NULL ) return( false ); // Real connection dest->SetInput( input_name, orig->GetOutput< TData >( output_name ) ); this->m_Graph->AddConnection( orig_filter, dest_filter, TConnection( output_name, input_name ) ); return( false ); } // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: TParameters* cpPlugins::Interface::Workspace:: GetParameters( const std::string& name ) { TFilter* f = dynamic_cast< TFilter* >( this->m_Graph->GetVertex( name ).GetPointer( ) ); if( f != NULL ) return( f->GetParameters( ) ); else return( NULL ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::Workspace:: TParameters* cpPlugins::Interface::Workspace:: GetParameters( const std::string& name ) const { const TFilter* f = dynamic_cast< const TFilter* >( this->m_Graph->GetVertex( name ).GetPointer( ) ); if( f != NULL ) return( f->GetParameters( ) ); else return( NULL ); } // ------------------------------------------------------------------------- cpPlugins::Interface::Workspace:: TFilter* cpPlugins::Interface::Workspace:: GetFilter( const std::string& name ) { TFilter* f = dynamic_cast< TFilter* >( this->m_Graph->GetVertex( name ).GetPointer( ) ); return( f ); } // ------------------------------------------------------------------------- const cpPlugins::Interface::Workspace:: TFilter* cpPlugins::Interface::Workspace:: GetFilter( const std::string& name ) const { const TFilter* f = dynamic_cast< const TFilter* >( this->m_Graph->GetVertex( name ).GetPointer( ) ); return( f ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: HasFilter( const std::string& name ) const { if( this->m_Graph->HasVertexIndex( name ) ) return( this->GetFilter( name ) != NULL ); else return( false ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::Workspace:: Reduce( const std::string& name ) { return( false ); } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::Workspace:: Execute( ) { // Find sinks std::set< std::string > sinks = this->m_Graph->GetSinks( ); // Update sinks std::string err = ""; for( auto sIt = sinks.begin( ); sIt != sinks.end( ); ++sIt ) { std::string lerr = this->Execute( *sIt, NULL ); if( lerr != "" ) err += lerr + std::string( "\n" ); } // rof return( err ); } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::Workspace:: Execute( const std::string& name, QWidget* p ) { // Get filter TFilter* f = dynamic_cast< TFilter* >( this->m_Graph->GetVertex( name ).GetPointer( ) ); if( f == NULL ) return( std::string( "cpPlugins::Interface::Workspace: Vertex \"" ) + name + std::string( "\" is not a filter." ) ); // Execute and return if( p != NULL ) { auto diag_res = f->ExecConfigurationDialog( p ); if( diag_res == TFilter::DialogResult_NoModal ) return( f->Update( ) ); else return( "" ); } else return( f->Update( ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Workspace:: _UpdateLoadedPluginsInformation( ) { /* TODO if( this->m_Interface != NULL ) { this->m_LoadedFilters.clear( ); const TInterface::TClasses& cls = this->m_Interface->GetClasses( ); for( auto i = cls.begin( ); i != cls.end( ); ++i ) { TFilter::Pointer o = this->m_Interface->CreateObject( i->first ); std::string name = o->GetClassName( ); std::string category = o->GetClassCategory( ); this->m_LoadedFilters[ category ].insert( name ); } // rof } // fi */ } // eof - $RCSfile$