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