1 #include "cpPipelineEditor.h"
2 #include "ui_cpPipelineEditor.h"
4 #include "QNodesEditor.h"
8 #include <cpPlugins/Interface/Workspace.h>
10 // -------------------------------------------------------------------------
11 #define cpPipelineEditor_ConnectAction( ACTION ) \
13 this->m_UI->Action##ACTION, SIGNAL( triggered( ) ), \
14 this, SLOT( _Action##ACTION( ) ) \
17 // -------------------------------------------------------------------------
18 #define cpPipelineEditor_ConnectButton( BUTTON ) \
20 this->m_UI->Button##BUTTON, SIGNAL( clicked( ) ), \
21 this, SLOT( _Button##BUTTON( ) ) \
24 // -------------------------------------------------------------------------
26 cpPipelineEditor( QWidget* parent )
27 : QMainWindow( parent ),
28 m_UI( new Ui::cpPipelineEditor ),
31 this->m_UI->setupUi( this );
33 // Connect actions to slots
34 cpPipelineEditor_ConnectButton( LoadPluginsFile );
35 cpPipelineEditor_ConnectButton( LoadPluginsPath );
36 cpPipelineEditor_ConnectAction( OpenWorkspace );
37 cpPipelineEditor_ConnectAction( SaveWorkspace );
40 // -------------------------------------------------------------------------
45 if( this->m_Workspace != NULL )
46 delete this->m_Workspace;
49 // -------------------------------------------------------------------------
50 void cpPipelineEditor::
51 _UpdateLoadedPlugins( )
53 typedef cpPlugins::Interface::Workspace::TStringContainer _TStrings;
55 if( this->m_Workspace == NULL )
59 this->m_Workspace->GetLoadedPluginCategories( categories );
60 for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt )
62 // Create or get category
63 QList< QTreeWidgetItem* > cat_items =
64 this->m_UI->LoadedPlugins->findItems(
65 cIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
67 QTreeWidgetItem* cat = NULL;
68 if( cat_items.size( ) == 0 )
70 cat = new QTreeWidgetItem(
71 ( QTreeWidgetItem* )( NULL ), QStringList( cIt->c_str( ) )
73 this->m_UI->LoadedPlugins->addTopLevelItem( cat );
79 _TStrings filters = this->m_Workspace->GetLoadedPluginFilters( *cIt );
80 for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt )
83 QList< QTreeWidgetItem* > filter_items =
84 this->m_UI->LoadedPlugins->findItems(
85 fIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
87 auto fiIt = filter_items.begin( );
88 auto found_fiIt = filter_items.end( );
89 for( ; fiIt != filter_items.end( ); ++fiIt )
90 if( ( *fiIt )->parent( ) == cat )
94 if( found_fiIt == filter_items.end( ) )
95 QTreeWidgetItem* filter = new QTreeWidgetItem(
96 cat, QStringList( fIt->c_str( ) )
104 // -------------------------------------------------------------------------
105 void cpPipelineEditor::
106 _ButtonLoadPluginsFile( )
108 QFileDialog dlg( this );
109 dlg.setFileMode( QFileDialog::ExistingFiles );
110 dlg.setDirectory( "." );
112 dlg.setNameFilter( "Plugins file (*.dll);;All files (*)" );
113 dlg.setDefaultSuffix( "dll" );
115 dlg.setNameFilter( "Plugins file (*.so);;All files (*)" );
116 dlg.setDefaultSuffix( "so" );
118 if( !( dlg.exec( ) ) )
121 // Create a new workspace, if not ready
122 if( this->m_Workspace == NULL )
123 this->m_Workspace = new cpPlugins::Interface::Workspace( );
126 QStringList names = dlg.selectedFiles( );
127 std::stringstream err_str;
128 for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt )
129 if( !( this->m_Workspace->LoadPlugins( qIt->toStdString( ) ) ) )
130 err_str << qIt->toStdString( ) << std::endl;
132 // Show an error message
133 std::string err = err_str.str( );
134 if( err.size( ) > 0 )
135 QMessageBox::critical(
137 "Error loading plugins",
142 this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
143 this->_UpdateLoadedPlugins( );
146 // -------------------------------------------------------------------------
147 void cpPipelineEditor::
148 _ButtonLoadPluginsPath( )
150 QFileDialog dlg( this );
151 dlg.setFileMode( QFileDialog::DirectoryOnly );
152 dlg.setDirectory( "." );
153 if( !( dlg.exec( ) ) )
156 // Create a new workspace, if not ready
157 if( this->m_Workspace == NULL )
158 this->m_Workspace = new cpPlugins::Interface::Workspace( );
161 std::string dir = dlg.selectedFiles( ).begin( )->toStdString( );
162 if( !( this->m_Workspace->LoadPluginsPath( dir, false ) ) )
163 QMessageBox::critical(
165 "Error loading plugins directory",
170 this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
171 this->_UpdateLoadedPlugins( );
174 // -------------------------------------------------------------------------
175 void cpPipelineEditor::
176 _ActionOpenWorkspace( )
178 QFileDialog dlg( this );
179 dlg.setFileMode( QFileDialog::ExistingFile );
180 dlg.setDirectory( "." );
182 QFileDialog::tr( "Workspace file (*.xml);;All files (*)" )
184 dlg.setDefaultSuffix( QFileDialog::tr( "xml" ) );
185 if( !( dlg.exec( ) ) )
187 std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( );
189 if( this->m_Workspace != NULL )
190 delete this->m_Workspace;
191 this->m_Workspace = new cpPlugins::Interface::Workspace( );
192 std::string err = this->m_Workspace->LoadWorkspace( fname );
195 this->m_UI->Canvas->editor( )->setWorkspace( this->m_Workspace );
199 delete this->m_Workspace;
200 this->m_Workspace = NULL;
201 QMessageBox::critical(
203 QMessageBox::tr( "Error loading workspace" ),
204 QMessageBox::tr( err.c_str( ) )
210 // -------------------------------------------------------------------------
211 void cpPipelineEditor::
212 _ActionSaveWorkspace( )
214 if( this->m_Workspace == NULL )
217 QFileDialog dlg( this );
218 dlg.setFileMode( QFileDialog::AnyFile );
219 dlg.setDirectory( "." );
220 dlg.setAcceptMode( QFileDialog::AcceptSave );
222 QFileDialog::tr( "Workspace file (*.xml);;All files (*)" )
224 dlg.setDefaultSuffix( QFileDialog::tr( "xml" ) );
225 if( !( dlg.exec( ) ) )
227 std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( );
229 std::string err = this->m_Workspace->SaveWorkspace( fname );
231 QMessageBox::critical(
233 QMessageBox::tr( "Error saving workspace" ),
234 QMessageBox::tr( err.c_str( ) )