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