Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / LightApp / LightApp_Application.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      LightApp_Application.h
23 // Created:   6/20/2005 18:39:25 PM
24 // Author:    OCC team
25 //
26 #ifndef LIGHTAPP_APPLICATION_H
27 #define LIGHTAPP_APPLICATION_H
28
29 #if _MSC_VER > 1000
30 #pragma once
31 #endif // _MSC_VER > 1000
32
33 #include "LightApp.h"
34 #include <CAM_Application.h>
35
36 #include <QPointer>
37
38 class LogWindow;
39 #ifndef DISABLE_PYCONSOLE
40 class PyConsole_Console;
41 #endif
42 class LightApp_WidgetContainer;
43 class LightApp_Preferences;
44 class LightApp_SelectionMgr;
45 class LightApp_DataObject;
46 class SUIT_DataBrowser;
47 class SUIT_Study;
48 class SUIT_Accel;
49 class CAM_Module;
50
51 class QString;
52 class QWidget;
53 class QStringList;
54 class QDockWidget;
55
56 #ifdef WIN32
57 #pragma warning( disable:4251 )
58 #endif
59
60 /*!
61   Description : Application containing only LightApp module
62 */
63
64 class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application
65 {
66   Q_OBJECT
67
68 public:
69   typedef enum { WT_ObjectBrowser,
70 #ifndef DISABLE_PYCONSOLE
71                  WT_PyConsole,
72 #endif
73                  WT_LogWindow,
74                  WT_User }
75   WindowTypes;
76
77   enum { MenuWindowId = 6 };
78
79   enum { RenameId = CAM_Application::UserID,
80          CloseId, CloseAllId, GroupAllId,
81          PreferencesId, MRUId, ModulesListId,
82          NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId,
83          NewQxSceneViewId, StyleId,
84          UserID };
85
86 protected:
87   enum { NewStudyId = 1, OpenStudyId };
88
89 public:
90   LightApp_Application();
91   virtual ~LightApp_Application();
92
93   virtual QString                     applicationName() const;
94   virtual QString                     applicationVersion() const;
95
96   virtual CAM_Module*                 loadModule( const QString&, const bool = true );
97   virtual bool                        activateModule( const QString& );
98
99   LightApp_SelectionMgr*              selectionMgr() const;
100
101   LogWindow*                          logWindow();
102   SUIT_DataBrowser*                   objectBrowser();
103 #ifndef DISABLE_PYCONSOLE
104   PyConsole_Console*                  pythonConsole();
105 #endif
106
107   virtual void                        updateObjectBrowser( const bool = true );
108
109   LightApp_Preferences*               preferences() const;
110
111   virtual QString                     getFileFilter() const;
112
113   virtual QString                     getFileName( bool open, const QString& initial, const QString& filters,
114                                                    const QString& caption, QWidget* parent );
115   virtual QString                     getDirectory( const QString& initial, const QString& caption, QWidget* parent );
116   virtual QStringList                 getOpenFileNames( const QString& initial, const QString& filters,
117                                                         const QString& caption, QWidget* parent );
118
119   void                                updateActions();
120
121   SUIT_ViewManager*                   getViewManager( const QString&, const bool );
122   virtual void                        addViewManager( SUIT_ViewManager* );
123   virtual void                        removeViewManager( SUIT_ViewManager* );
124   virtual SUIT_ViewManager*           createViewManager( const QString& vmType );
125
126   QWidget*                            getWindow( const int, const int = -1 );
127   QWidget*                            dockWindow( const int ) const;
128   void                                removeDockWindow( const int );
129   void                                insertDockWindow( const int, QWidget* );
130   void                                placeDockWindow( const int, Qt::DockWidgetArea );
131
132   virtual void                        start();
133
134   virtual void                        contextMenuPopup( const QString&, QMenu*, QString& );
135
136   virtual void                        createEmptyStudy();
137
138   SUIT_Accel*                         accel() const;
139
140   void                                setDefaultStudyName( const QString& theName );
141
142   static int                          studyId();
143
144   virtual bool                        event( QEvent* );
145
146   virtual bool                        checkDataObject( LightApp_DataObject* theObj );
147
148   virtual void                        updateDesktopTitle();
149
150 signals:
151   void                                studyOpened();
152   void                                studySaved();
153   void                                studyClosed();
154   void                                preferenceChanged( const QString&, const QString&, const QString& );
155
156 public slots:
157   virtual void                        onHelpContentsModule();
158   virtual void                        onHelpContextModule( const QString&, const QString&, const QString& = QString() );
159   virtual void                        onNewDoc();
160   virtual void                        onOpenDoc();
161   virtual void                        onHelpAbout();
162   virtual bool                        onOpenDoc( const QString& );
163
164 protected:
165   virtual void                        createActions();
166   virtual void                        createActionForViewer( const int id,
167                                                              const int parentId,
168                                                              const QString& suffix,
169                                                              const int accel );
170   virtual SUIT_Study*                 createNewStudy();
171   virtual QWidget*                    createWindow( const int );
172   virtual void                        defaultWindows( QMap<int, int>& ) const;
173   void                                defaultViewManagers( QStringList& ) const;
174
175   virtual void                        setActiveStudy( SUIT_Study* );
176   virtual void                        updateCommandsStatus();
177   virtual void                        onSelectionChanged();
178
179   virtual void                        beforeCloseDoc( SUIT_Study* );
180   virtual void                        afterCloseDoc();
181   virtual void                        moduleAdded( CAM_Module* );
182   virtual bool                        activateModule( CAM_Module* = 0 );
183
184   LightApp_Preferences*               preferences( const bool ) const;
185   virtual void                        createPreferences( LightApp_Preferences* );
186   virtual void                        preferencesChanged( const QString&, const QString& );
187
188   virtual void                        loadPreferences();
189   virtual void                        savePreferences();
190
191   virtual QMap<int, QString>          activateModuleActions() const;
192   virtual void                        moduleActionSelected( const int );
193
194 protected slots:
195   virtual void                        onDesktopActivated();
196
197   void                                onNewWindow();
198   void                                onModuleActivation( const QString& );
199   void                                onCloseView( SUIT_ViewManager* );
200
201   void                                onStudyCreated( SUIT_Study* );
202   void                                onStudyOpened( SUIT_Study* );
203   void                                onStudySaved( SUIT_Study* );
204   void                                onStudyClosed( SUIT_Study* );
205
206   void                                onWCDestroyed( QObject* );
207
208   void                                onMRUActivated( const QString& );
209
210   void                                onStylePreferences();
211
212 private slots:
213   void                                onSelection();
214   void                                onRefresh();
215   void                                onPreferences();
216   void                                onPreferenceChanged( QString&, QString&, QString& );
217   void                                onRenameWindow();
218   void                                onCloseWindow();
219   void                                onCloseAllWindow();
220   void                                onGroupAllWindow();
221
222 protected:
223   void                                updateWindows();
224   void                                updateViewManagers();
225   void                                updateModuleActions();
226
227   void                                loadDockWindowsState();
228   void                                saveDockWindowsState();
229
230   virtual void                        studyOpened( SUIT_Study* );
231   virtual void                        studyCreated( SUIT_Study* );
232
233   void                                updatePreference( const QString&, const QString&, const QString& );
234
235   QString                             defaultModule() const;
236   void                                currentWindows( QMap<int, int>& ) const;
237   void                                currentViewManagers( QStringList& ) const;
238   void                                moduleIconNames( QMap<QString, QString>& ) const;
239
240   bool                                isLibExists( const QString& ) const;
241
242   QDockWidget*                        windowDock( QWidget* ) const;
243   QByteArray                          dockWindowsState( const QMap<QString, bool>&, const QMap<QString, bool>& ) const;
244   void                                dockWindowsState( const QByteArray&, QMap<QString, bool>&, QMap<QString, bool>& ) const;
245
246   virtual int                         openChoice( const QString& );
247   virtual bool                        openAction( const int, const QString& );
248
249   void                                showPreferences( const QString& = QString() );
250
251 private:
252   void                                emptyPreferences( const QString& );
253
254 protected:
255   typedef QPointer<QWidget>         WinPtr;
256   typedef QMap<int, WinPtr>         WinMap;
257   typedef QMap<QString, QByteArray> WinVis;
258   typedef QMap<QString, QByteArray> WinGeom;
259
260   enum { OpenReload = CAM_Application::OpenExist + 1 };
261
262 protected:
263   LightApp_Preferences*               myPrefs;
264   LightApp_SelectionMgr*              mySelMgr;
265
266   WinMap                              myWin;
267   WinVis                              myWinVis;
268   WinGeom                             myWinGeom;
269
270   SUIT_Accel*                         myAccel;
271
272   static LightApp_Preferences*        _prefs_;
273
274   static int                          lastStudyId;
275 };
276
277 #ifdef WIN32
278 #pragma warning( default:4251 )
279 #endif
280
281 #endif