Salome HOME
Merge from V6_main 01/04/2013
[modules/gui.git] / src / LightApp / LightApp_Application.h
1 // Copyright (C) 2007-2013  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
23 // File:      LightApp_Application.h
24 // Created:   6/20/2005 18:39:25 PM
25 // Author:    OCC team
26
27 #ifndef LIGHTAPP_APPLICATION_H
28 #define LIGHTAPP_APPLICATION_H
29
30 #if _MSC_VER > 1000
31 #pragma once
32 #endif // _MSC_VER > 1000
33
34 #include "LightApp.h"
35 #include <SUIT_TreeModel.h>
36 #include <CAM_Application.h>
37
38 #include <QPointer>
39 #include <QStringList>
40
41 class LogWindow;
42 #ifndef DISABLE_PYCONSOLE
43 class PyConsole_Console;
44 #endif
45 class LightApp_WidgetContainer;
46 class LightApp_Preferences;
47 class LightApp_SelectionMgr;
48 class LightApp_FullScreenHelper;
49 class LightApp_DataObject;
50 class SUIT_DataBrowser;
51 class SUIT_Study;
52 class SUIT_Accel;
53 class CAM_Module;
54
55 class QString;
56 class QWidget;
57 class QStringList;
58 class QDockWidget;
59 class QTimer;
60
61 #ifdef WIN32
62 #pragma warning( disable:4251 )
63 #endif
64
65 /*!
66   Description : Application containing only LightApp module
67 */
68
69 class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application, public SUIT_DataSearcher
70 {
71   Q_OBJECT
72
73 public:
74   typedef enum { WT_ObjectBrowser,
75 #ifndef DISABLE_PYCONSOLE
76                  WT_PyConsole,
77 #endif
78                  WT_LogWindow,
79                  WT_User }
80   WindowTypes;
81
82   enum { MenuWindowId = 6 };
83
84   enum { RenameId = CAM_Application::UserID,
85          CloseId, CloseAllId, GroupAllId,
86          PreferencesId, MRUId, ModulesListId,
87          NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId,
88          NewQxSceneViewId = NewQxGraphViewId, StyleId, FullScreenId,
89          UserID };
90
91 protected:
92   enum { NewStudyId = 1, OpenStudyId };
93
94   enum BrowsePolicy { BP_Never = 0, BP_ApplyAndClose, BP_Always };
95
96 public:
97   LightApp_Application();
98   virtual ~LightApp_Application();
99
100   virtual QString                     applicationName() const;
101   virtual QString                     applicationVersion() const;
102
103   virtual CAM_Module*                 loadModule( const QString&, const bool = true );
104   virtual bool                        activateModule( const QString& );
105
106   LightApp_SelectionMgr*              selectionMgr() const;
107
108   LogWindow*                          logWindow();
109   SUIT_DataBrowser*                   objectBrowser();
110 #ifndef DISABLE_PYCONSOLE
111   PyConsole_Console*                  pythonConsole(const bool force = false);
112 #endif
113
114   virtual void                        updateObjectBrowser( const bool = true );
115
116   LightApp_Preferences*               preferences() const;
117
118   virtual QString                     getFileFilter() const;
119
120   virtual QString                     getFileName( bool open, const QString& initial, const QString& filters,
121                                                    const QString& caption, QWidget* parent );
122   virtual QString                     getDirectory( const QString& initial, const QString& caption, QWidget* parent );
123   virtual QStringList                 getOpenFileNames( const QString& initial, const QString& filters,
124                                                         const QString& caption, QWidget* parent );
125
126   void                                updateActions();
127
128   SUIT_ViewManager*                   getViewManager( const QString&, const bool );
129   virtual void                        addViewManager( SUIT_ViewManager* );
130   virtual void                        removeViewManager( SUIT_ViewManager* );
131   virtual SUIT_ViewManager*           createViewManager( const QString& vmType );
132   virtual SUIT_ViewManager*           createViewManager( const QString& vmType, QWidget* w );
133
134   QWidget*                            getWindow( const int, const int = -1 );
135   QWidget*                            dockWindow( const int ) const;
136   void                                removeDockWindow( const int );
137   void                                insertDockWindow( const int, QWidget* );
138   void                                placeDockWindow( const int, Qt::DockWidgetArea );
139
140   virtual void                        start();
141
142   virtual void                        contextMenuPopup( const QString&, QMenu*, QString& );
143
144   virtual void                        createEmptyStudy();
145
146   virtual void                        setDesktop( SUIT_Desktop* );
147
148   SUIT_Accel*                         accel() const;
149
150   void                                setDefaultStudyName( const QString& theName );
151
152   static int                          studyId();
153
154   virtual bool                        event( QEvent* );
155
156   virtual bool                        checkDataObject( LightApp_DataObject* theObj );
157
158   virtual void                        updateDesktopTitle();
159
160   //! Returns list of view manager types which are supported by this application
161   QStringList                          viewManagersTypes() const;
162
163   //! Removes ViewManagers only of known type
164   virtual void                        clearKnownViewManagers();
165
166   virtual QString                     browseObjects( const QStringList& theEntryList,
167                                                      const bool theIsApplyAndClose = true,
168                                                      const bool theIsOptimizedBrowsing = false );
169
170   virtual SUIT_DataObject*            findObject( const QString& ) const;
171
172   virtual bool                        renameAllowed( const QString& ) const;
173   virtual bool                        renameObject( const QString&, const QString& );
174
175 signals:
176   void                                studyOpened();
177   void                                studySaved();
178   void                                studyClosed();
179   void                                preferenceChanged( const QString&, const QString&, const QString& );
180
181 public slots:
182   virtual void                        onHelpContentsModule();
183   virtual void                        onHelpContextModule( const QString&, const QString&, const QString& = QString() );
184   virtual void                        onNewDoc();
185   virtual void                        onOpenDoc();
186   virtual void                        onHelpAbout();
187   virtual bool                        onOpenDoc( const QString& );
188   virtual void                        onCopy();
189   virtual void                        onPaste();
190   virtual void                        onSelectionChanged();
191
192 protected:
193   virtual void                        createActions();
194   virtual void                        createActionForViewer( const int id,
195                                                              const int parentId,
196                                                              const QString& suffix,
197                                                              const int accel );
198   virtual SUIT_Study*                 createNewStudy();
199   virtual QWidget*                    createWindow( const int );
200   virtual void                        defaultWindows( QMap<int, int>& ) const;
201   void                                defaultViewManagers( QStringList& ) const;
202
203   virtual void                        setActiveStudy( SUIT_Study* );
204   virtual void                        updateCommandsStatus();
205
206   virtual void                        beforeCloseDoc( SUIT_Study* );
207   virtual void                        afterCloseDoc();
208   virtual void                        moduleAdded( CAM_Module* );
209   virtual bool                        activateModule( CAM_Module* = 0 );
210
211   LightApp_Preferences*               preferences( const bool ) const;
212   virtual void                        createPreferences( LightApp_Preferences* );
213   virtual void                        preferencesChanged( const QString&, const QString& );
214
215   virtual void                        loadPreferences();
216   virtual void                        savePreferences();
217
218   virtual QMap<int, QString>          activateModuleActions() const;
219   virtual void                        moduleActionSelected( const int );
220
221 protected slots:
222   virtual void                        onDesktopActivated();
223
224   void                                onNewWindow();
225   void                                onModuleActivation( const QString& );
226   void                                onCloseView( SUIT_ViewManager* );
227
228   void                                onStudyCreated( SUIT_Study* );
229   void                                onStudyOpened( SUIT_Study* );
230   void                                onStudySaved( SUIT_Study* );
231   void                                onStudyClosed( SUIT_Study* );
232
233   void                                onWCDestroyed( QObject* );
234
235   void                                onMRUActivated( const QString& );
236
237   void                                onStylePreferences();
238   void                                onFullScreen();
239
240   virtual void                        onDesktopMessage( const QString& );
241
242 private slots:
243   void                                onSelection();
244   void                                onRefresh();
245   void                                onDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction );
246   void                                onPreferences();
247   void                                onPreferenceChanged( QString&, QString&, QString& );
248   void                                onRenameWindow();
249   void                                onCloseWindow();
250   void                                onCloseAllWindow();
251   void                                onGroupAllWindow();
252
253 protected:
254   void                                updateWindows();
255   void                                updateViewManagers();
256   void                                updateModuleActions();
257   void                                removeModuleAction( const QString& );
258
259   void                                loadDockWindowsState();
260   void                                saveDockWindowsState();
261
262   virtual void                        studyOpened( SUIT_Study* );
263   virtual void                        studyCreated( SUIT_Study* );
264   virtual void                        studySaved( SUIT_Study* );
265
266   void                                updatePreference( const QString&, const QString&, const QString& );
267
268   QString                             defaultModule() const;
269   virtual void                        currentWindows( QMap<int, int>& ) const;
270   void                                currentViewManagers( QStringList& ) const;
271   void                                moduleIconNames( QMap<QString, QString>& ) const;
272
273   bool                                isLibExists( const QString& ) const;
274
275   QDockWidget*                        windowDock( QWidget* ) const;
276   QByteArray                          dockWindowsState( const QMap<QString, bool>&, const QMap<QString, bool>& ) const;
277   void                                dockWindowsState( const QByteArray&, QMap<QString, bool>&, QMap<QString, bool>& ) const;
278
279   virtual int                         openChoice( const QString& );
280   virtual bool                        openAction( const int, const QString& );
281
282   void                                showPreferences( const QString& = QString() );
283
284 private:
285   void                                emptyPreferences( const QString& );
286
287 protected:
288   typedef QPointer<QWidget>         WinPtr;
289   typedef QMap<int, WinPtr>         WinMap;
290   typedef QMap<QString, QByteArray> WinVis;
291   typedef QMap<QString, QByteArray> WinGeom;
292
293   enum { OpenReload = CAM_Application::OpenExist + 1 };
294
295 protected:
296   LightApp_Preferences*               myPrefs;
297   LightApp_SelectionMgr*              mySelMgr;
298
299   LightApp_FullScreenHelper*          myScreenHelper;
300
301   WinMap                              myWin;
302   WinVis                              myWinVis;
303   WinGeom                             myWinGeom;
304
305   SUIT_Accel*                         myAccel;
306   QTimer*                             myAutoSaveTimer;
307
308   static LightApp_Preferences*        _prefs_;
309
310   static int                          lastStudyId;
311   QStringList                         myUserWmTypes;
312 };
313
314 #ifdef WIN32
315 #pragma warning( default:4251 )
316 #endif
317
318 #endif