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