]> Creatis software - cpPlugins.git/blob - appli/cpPipelineEditor/cpPipelineEditor.cxx
87fd6c86e65984f7c81926d1aeac700462407da9
[cpPlugins.git] / appli / cpPipelineEditor / cpPipelineEditor.cxx
1 #include "cpPipelineEditor.h"
2 #include "ui_cpPipelineEditor.h"
3
4 #include <QFileDialog>
5 #include <QMessageBox>
6 #include <cpPlugins/Interface/Workspace.h>
7
8 // -------------------------------------------------------------------------
9 #define cpPipelineEditor_ConnectAction( ACTION )        \
10   QObject::connect(                                     \
11     this->m_UI->Action##ACTION, SIGNAL( triggered( ) ), \
12     this, SLOT( _Action##ACTION( ) )                    \
13     )
14
15 // -------------------------------------------------------------------------
16 cpPipelineEditor::
17 cpPipelineEditor( QWidget* parent )
18   : QMainWindow( parent ),
19     m_UI( new Ui::cpPipelineEditor ),
20     m_Workspace( NULL )
21 {
22   this->m_UI->setupUi( this );
23
24   // Connect actions to slots
25   cpPipelineEditor_ConnectAction( OpenWorkspace );
26 }
27
28 // -------------------------------------------------------------------------
29 cpPipelineEditor::
30 ~cpPipelineEditor( )
31 {
32   delete this->m_UI;
33   if( this->m_Workspace != NULL )
34     delete this->m_Workspace;
35 }
36
37 // -------------------------------------------------------------------------
38 void cpPipelineEditor::
39 _ActionOpenWorkspace( )
40 {
41   QFileDialog dlg( this );
42   dlg.setFileMode( QFileDialog::ExistingFile );
43   dlg.setDirectory( "." );
44   dlg.setNameFilter(
45     QFileDialog::tr( "Workspace file (*.xml);;All files (*)" )
46     );
47   dlg.setDefaultSuffix( QFileDialog::tr( "xml" ) );
48   if( !( dlg.exec( ) ) )
49     return;
50   std::string fname = dlg.selectedFiles( ).at( 0 ).toStdString( );
51
52   if( this->m_Workspace != NULL )
53     delete this->m_Workspace;
54   this->m_Workspace = new cpPlugins::Interface::Workspace( );
55   std::string err = this->m_Workspace->LoadWorkspace( fname );
56   if( err == "" )
57   {
58     this->m_UI->Canvas->setWorkspace( this->m_Workspace );
59   }
60   else
61   {
62     delete this->m_Workspace;
63     this->m_Workspace = NULL;
64     QMessageBox::critical(
65       this,
66       QMessageBox::tr( "Error loading workspace" ),
67       QMessageBox::tr( err.c_str( ) )
68       );
69
70   } // fi
71 }
72
73 // eof - $RCSfile$