1 #include "cpPipelineEditor.h"
2 #include "ui_cpPipelineEditor.h"
6 #include <cpPlugins/Interface/Workspace.h>
8 // -------------------------------------------------------------------------
9 #define cpPipelineEditor_ConnectAction( ACTION ) \
11 this->m_UI->Action##ACTION, SIGNAL( triggered( ) ), \
12 this, SLOT( _Action##ACTION( ) ) \
15 // -------------------------------------------------------------------------
16 #define cpPipelineEditor_ConnectButton( BUTTON ) \
18 this->m_UI->Button##BUTTON, SIGNAL( clicked( ) ), \
19 this, SLOT( _Button##BUTTON( ) ) \
22 // -------------------------------------------------------------------------
24 cpPipelineEditor( QWidget* parent )
25 : QMainWindow( parent ),
26 m_UI( new Ui::cpPipelineEditor ),
29 this->m_UI->setupUi( this );
31 // Connect actions to slots
32 cpPipelineEditor_ConnectButton( LoadPluginsFile );
33 cpPipelineEditor_ConnectButton( LoadPluginsPath );
34 cpPipelineEditor_ConnectAction( OpenWorkspace );
37 // -------------------------------------------------------------------------
42 if( this->m_Workspace != NULL )
43 delete this->m_Workspace;
46 // -------------------------------------------------------------------------
47 void cpPipelineEditor::
48 _UpdateLoadedPlugins( )
50 typedef cpPlugins::Interface::Workspace::TStringContainer _TStrings;
52 if( this->m_Workspace == NULL )
56 this->m_Workspace->GetLoadedPluginCategories( categories );
57 for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt )
59 // Create or get category
60 QList< QTreeWidgetItem* > cat_items =
61 this->m_UI->LoadedPlugins->findItems(
62 cIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
64 QTreeWidgetItem* cat = NULL;
65 if( cat_items.size( ) == 0 )
67 cat = new QTreeWidgetItem(
68 ( QTreeWidgetItem* )( NULL ), QStringList( cIt->c_str( ) )
70 this->m_UI->LoadedPlugins->addTopLevelItem( cat );
76 _TStrings filters = this->m_Workspace->GetLoadedPluginFilters( *cIt );
77 for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt )
80 QList< QTreeWidgetItem* > filter_items =
81 this->m_UI->LoadedPlugins->findItems(
82 fIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
84 auto fiIt = filter_items.begin( );
85 auto found_fiIt = filter_items.end( );
86 for( ; fiIt != filter_items.end( ); ++fiIt )
87 if( ( *fiIt )->parent( ) == cat )
91 if( found_fiIt == filter_items.end( ) )
92 QTreeWidgetItem* filter = new QTreeWidgetItem(
93 cat, QStringList( fIt->c_str( ) )
101 // -------------------------------------------------------------------------
102 void cpPipelineEditor::
103 _ButtonLoadPluginsFile( )
105 QFileDialog dlg( this );
106 dlg.setFileMode( QFileDialog::ExistingFiles );
107 dlg.setDirectory( "." );
109 dlg.setNameFilter( "Plugins file (*.dll);;All files (*)" );
110 dlg.setDefaultSuffix( "dll" );
112 dlg.setNameFilter( "Plugins file (*.so);;All files (*)" );
113 dlg.setDefaultSuffix( "so" );
115 if( !( dlg.exec( ) ) )
118 // Create a new workspace, if not ready
119 if( this->m_Workspace == NULL )
120 this->m_Workspace = new cpPlugins::Interface::Workspace( );
123 QStringList names = dlg.selectedFiles( );
124 std::stringstream err_str;
125 for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt )
126 if( !( this->m_Workspace->LoadPlugins( qIt->toStdString( ) ) ) )
127 err_str << qIt->toStdString( ) << std::endl;
129 // Show an error message
130 std::string err = err_str.str( );
131 if( err.size( ) > 0 )
132 QMessageBox::critical(
134 "Error loading plugins",
139 this->m_UI->Canvas->setWorkspace( this->m_Workspace );
140 this->_UpdateLoadedPlugins( );
143 // -------------------------------------------------------------------------
144 void cpPipelineEditor::
145 _ButtonLoadPluginsPath( )
147 QFileDialog dlg( this );
148 dlg.setFileMode( QFileDialog::DirectoryOnly );
149 dlg.setDirectory( "." );
150 if( !( dlg.exec( ) ) )
153 // Create a new workspace, if not ready
154 if( this->m_Workspace == NULL )
155 this->m_Workspace = new cpPlugins::Interface::Workspace( );
158 std::string dir = dlg.selectedFiles( ).begin( )->toStdString( );
159 if( !( this->m_Workspace->LoadPluginsPath( dir, false ) ) )
160 QMessageBox::critical(
162 "Error loading plugins directory",
167 this->m_UI->Canvas->setWorkspace( this->m_Workspace );
168 this->_UpdateLoadedPlugins( );
171 // -------------------------------------------------------------------------
172 void cpPipelineEditor::
173 _ActionOpenWorkspace( )
175 QFileDialog dlg( this );
176 dlg.setFileMode( QFileDialog::ExistingFile );
177 dlg.setDirectory( "." );
179 QFileDialog::tr( "Workspace file (*.xml);;All files (*)" )
181 dlg.setDefaultSuffix( QFileDialog::tr( "xml" ) );
182 if( !( dlg.exec( ) ) )
184 std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( );
186 if( this->m_Workspace != NULL )
187 delete this->m_Workspace;
188 this->m_Workspace = new cpPlugins::Interface::Workspace( );
189 std::string err = this->m_Workspace->LoadWorkspace( fname );
192 this->m_UI->Canvas->setWorkspace( this->m_Workspace );
196 delete this->m_Workspace;
197 this->m_Workspace = NULL;
198 QMessageBox::critical(
200 QMessageBox::tr( "Error loading workspace" ),
201 QMessageBox::tr( err.c_str( ) )