]> Creatis software - cpPlugins.git/blob - lib/cpBaseQtApplication/MainWindow.h
febf21e355c3a6d672de9b82fef611df2447bb97
[cpPlugins.git] / lib / cpBaseQtApplication / MainWindow.h
1 #ifndef __CPBASEQTAPPLICATION__MAINWINDOW__H__
2 #define __CPBASEQTAPPLICATION__MAINWINDOW__H__
3
4 #include <cpBaseQtApplication_Export.h>
5 #include <QMainWindow>
6 #include <cpPlugins/Interface.h>
7 #include <cpPlugins/Workspace.h>
8
9 // -------------------------------------------------------------------------
10 #define cpBaseQtApplication_ConnectAction( _action_, _slot_ )           \
11   this->connect(                                                        \
12     this->m_UI->_action_, SIGNAL( triggered( ) ),                       \
13     this, SLOT( _slot_( ) )                                             \
14     )
15
16 // -------------------------------------------------------------------------
17 #define cpBaseQtApplication_Execute( _command_ )        \
18   this->_Block( );                                      \
19   try                                                   \
20   {                                                     \
21     _command_;                                          \
22     this->_UnBlock( );                                  \
23   }                                                     \
24   catch( itk::ExceptionObject& err1 )                   \
25   {                                                     \
26     this->_UnBlock( );                                  \
27     QMessageBox::critical(                              \
28       this,                                             \
29       QMessageBox::tr( "Error executing filter" ),      \
30       QMessageBox::tr( err1.GetDescription( ) )         \
31       );                                                \
32   }                                                     \
33   catch( std::exception& err2 )                         \
34   {                                                     \
35     this->_UnBlock( );                                  \
36     QMessageBox::critical(                              \
37       this,                                             \
38       QMessageBox::tr( "Error executing filter" ),      \
39       QMessageBox::tr( err2.what( ) )                   \
40       );                                                \
41   }                                                     \
42   catch( ... )                                          \
43   {                                                     \
44     this->_UnBlock( );                                  \
45     QMessageBox::critical(                              \
46       this,                                             \
47       QMessageBox::tr( "Error executing filter" ),      \
48       QMessageBox::tr( "Unknown error" )                \
49       );                                                \
50   }                                                     \
51   this->_UnBlock( )
52
53
54 namespace cpExtensions
55 {
56   namespace QT
57   {
58     class SimpleMPRWidget;
59   }
60 }
61 class QTreeWidget;
62
63 namespace cpBaseQtApplication
64 {
65   class Editor;
66
67   /**
68    */
69   class cpBaseQtApplication_EXPORT MainWindow
70     : public QMainWindow
71   {
72     Q_OBJECT;
73
74   public:
75     typedef MainWindow  Self;
76     typedef QMainWindow Superclass;
77
78   protected:
79     /**
80      */
81     class _TBlocker
82       : public QObject
83     {
84     protected:
85       virtual bool eventFilter( QObject* obj, QEvent* event ) ITK_OVERRIDE;
86     };
87
88   public:
89     explicit MainWindow(
90       int argc, char* argv[],
91       QApplication* app,
92       QWidget* parent = NULL
93       );
94     virtual ~MainWindow( );
95
96     void UpdateEnvironment( );
97
98   protected:
99     void _Configure(
100       QTreeWidget* tree,
101       cpExtensions::QT::SimpleMPRWidget* mpr,
102       cpBaseQtApplication::Editor* editor
103       );
104     void _ClearWorkspace( );
105     void _AddEnvironments( const std::string& environments );
106     void _LoadPlugins( const std::string& filename );
107     void _LoadPluginsFromPath( const std::string& path );
108     void _UpdateLoadedPlugins( );
109     void _Block( );
110     void _UnBlock( );
111
112     void _LoadWorkspace( const std::string& filename );
113     void _SaveWorkspace( const std::string& filename );
114
115     void _BackgroundProperties( unsigned int i );
116     void _DataProperties( const std::string& actor );
117
118   protected slots:
119     void _InteractiveLoadPlugins( );
120     void _InteractiveLoadPluginsFromPath( );
121     void _ShowPlugins( );
122     void _InteractiveLoadWorkspace( );
123     void _InteractiveSaveWorkspace( );
124     void _InteractiveAddEnviromentPaths( );
125     void _ExecFilter( const std::string& filter_name );
126     void _ShowData(
127       const std::string& filter_name, const std::string& output_name
128       );
129     void _HideData(
130       const std::string& filter_name, const std::string& output_name
131       );
132     void _DataProperties(
133       const std::string& filter_name, const std::string& output_name
134       );
135
136   protected:
137     QApplication* m_Application;
138     _TBlocker     m_Blocker;
139     std::string   m_PluginsPath;
140
141     std::string m_RunPath;
142     cpPlugins::Interface m_Interface;
143     cpPlugins::Workspace m_Workspace;
144
145     QTreeWidget* m_TreeWidget;
146     Editor*      m_Editor;
147     cpExtensions::QT::SimpleMPRWidget* m_MPR;
148   };
149
150 } // ecapseman
151
152 #endif // __CPBASEQTAPPLICATION__MAINWINDOW__H__
153
154 // eof - $RCSfile$