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