]> Creatis software - cpPlugins.git/blob - lib/cpBaseQtApplication/MainWindow.h
9e2b6072f1137ec501cf3c08b555cfc29fbaff02
[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/Plugins.h>
7 #include <cpPlugins/Interface/Workspace.h>
8
9 // -------------------------------------------------------------------------
10 #define cpBaseQtApplication_ConnectAction( _act_, _slt_ )               \
11   this->connect(                                                        \
12     this->m_UI->_act_, SIGNAL( triggered( ) ), this, SLOT( _slt_( ) )   \
13     )
14
15 // -------------------------------------------------------------------------
16 #define cpBaseQtApplication_Execute( _cmd_ )            \
17   {                                                     \
18   this->_block( );                                      \
19   try                                                   \
20   {                                                     \
21     _cmd_;                                              \
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 // -------------------------------------------------------------------------
55 namespace cpExtensions { namespace QT { class SimpleMPRWidget; } }
56
57 // -------------------------------------------------------------------------
58 namespace cpBaseQtApplication
59 {
60   class Editor;
61   class PluginsNavigator;
62
63   /**
64    */
65   class cpBaseQtApplication_EXPORT MainWindow
66     : public QMainWindow
67   {
68     Q_OBJECT;
69
70   public:
71     typedef MainWindow  Self;
72     typedef QMainWindow Superclass;
73
74     typedef cpPlugins::Interface::Plugins     TPlugins;
75     typedef cpPlugins::Interface::Workspace   TWorkspace;
76     typedef cpExtensions::QT::SimpleMPRWidget TMPR;
77
78   protected:
79     /**
80      */
81     class _TBlocker
82       : public QObject
83     {
84     protected:
85       virtual bool eventFilter( QObject* obj, QEvent* event ) cpPlugins_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     void updateFilter( const std::string& name );
98     void showData( const std::string& name, const std::string& port );
99     void showData(
100       cpPlugins::BaseObjects::DataObject* data, const std::string& name
101       );
102
103     /* TODO
104        void hideData( const std::string& name, const std::string& port );
105        void hideData( const std::string& name );
106     */
107     void dataProperties( const std::string& name, const std::string& port );
108     void dataProperties( const std::string& name );
109
110   protected:
111     void _block( );
112     void _unBlock( );
113     void _configure( PluginsNavigator* nav, TMPR* mpr, Editor* edt );
114     void _updatePlugins( );
115
116   protected slots:
117     void _loadWorkspace( const std::string& filename );
118     void _loadWorkspace( );
119     void _saveWorkspace( const std::string& filename );
120     void _saveWorkspace( );
121     void _showPlugins( );
122     void _addEnvironmentPaths( const std::string& envs );
123     void _addEnvironmentPaths( );
124     void _loadPlugins( const std::string& filename );
125     void _loadPlugins( );
126     void _loadPluginsFromPath( const std::string& path );
127     void _loadPluginsFromPath( );
128     void _actorsProperties( );
129
130     /* TODO
131        void _ClearWorkspace( );
132        void _LoadPlugins( const std::string& filename );
133        void _LoadPluginsFromPath( const std::string& path );
134
135        void _LoadWorkspace( const std::string& filename );
136        void _SaveWorkspace( const std::string& filename );
137
138        void _BackgroundProperties( unsigned int i );
139        void _DataProperties( const std::string& actor );
140
141        void _AddEnviromentPaths( );
142        void _LoadPlugins( );
143        void _LoadPluginsFromPath( );
144        void _ShowPlugins( );
145        void _LoadWorkspace( );
146        void _SaveWorkspace( );
147        void _DataProperties(
148        const std::string& filter_name, const std::string& output_name
149        );
150     */
151
152   protected:
153     QApplication* m_Application;
154     _TBlocker     m_Blocker;
155
156     std::string         m_RunPath;
157     TPlugins::Pointer   m_Plugins;
158     TWorkspace::Pointer m_Workspace;
159
160     PluginsNavigator* m_Navigator;
161     Editor*           m_Editor;
162     TMPR*             m_MPR;
163
164     /* TODO
165     */
166   };
167
168 } // ecapseman
169
170 #endif // __cpBaseQtApplication__MainWindow__h__
171
172 // eof - $RCSfile$