]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_Application.h
Salome HOME
351c1663ce5b8f8e3813d506097f2a30f171e7a8
[modules/gui.git] / src / LightApp / LightApp_Application.h
1 // Copyright (C) 2007-2023  CEA, EDF, 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   static void                         logUserEvent(const QString& eventDescription);
195
196 #ifndef DISABLE_PYCONSOLE
197   PyConsole_Interp*                   getPyInterp();
198 #endif
199
200 signals:
201   void                                moduleActivated( const QString& );
202   void                                studyOpened();
203   void                                studySaved();
204   void                                studyClosed();
205   void                                preferenceChanged( const QString&, const QString&, const QString& );
206   void                                preferenceResetToDefaults();
207   void                                operationFinished( const QString&, const QString&, const QStringList& );
208
209 public slots:
210   virtual void                        onHelpContentsModule();
211   virtual void                        onHelpContextModule( const QString&, const QString&, const QString& = QString() );
212   virtual void                        onNewDoc();
213   virtual void                        onOpenDoc();
214
215   virtual void                        onHelpAbout();
216   virtual bool                        onOpenDoc( const QString& );
217   virtual void                        onCopy();
218   virtual void                        onPaste();
219   virtual void                        onSelectionChanged();
220   virtual void                        onDockWindowVisibilityChanged( bool );
221
222 protected:
223   void                                showHelp( const QString& );
224   virtual void                        createActions();
225   virtual void                        addExtensionsActions(LightApp_ModuleAction* moduleAction);
226   virtual void                        customize();
227   virtual void                        createActionForViewer( const int id,
228                                                              const int parentId,
229                                                              const QString& suffix,
230                                                              const int accel );
231   virtual SUIT_Study*                 createNewStudy();
232   virtual QWidget*                    createWindow( const int );
233   virtual void                        defaultWindows( QMap<int, int>& ) const;
234   void                                defaultViewManagers( QStringList& ) const;
235
236   virtual void                        setActiveStudy( SUIT_Study* );
237   virtual void                        updateCommandsStatus();
238
239   virtual bool                        canOpenDoc( const QString& );
240
241   virtual void                        beforeCloseDoc( SUIT_Study* );
242   virtual void                        afterCloseDoc();
243   virtual void                        moduleAdded( CAM_Module* );
244   virtual void                        moduleDeactivated( CAM_Module* );
245   virtual bool                        activateModule( CAM_Module* = 0 );
246
247   LightApp_Preferences*               preferences( const bool ) const;
248   virtual void                        createPreferences( LightApp_Preferences* );
249   virtual void                        preferencesChanged( const QString&, const QString& );
250
251   virtual void                        loadPreferences();
252   virtual void                        savePreferences();
253
254   virtual QMap<int, QString>          activateModuleActions() const;
255   virtual void                        moduleActionSelected( const int );
256
257 #ifndef DISABLE_PYCONSOLE
258   virtual PyConsole_Interp*           createPyInterp();
259 #endif
260
261   virtual void                        addCatalogue( const QString&, const QString& ) {}
262
263 protected slots:
264   virtual void                        onDesktopActivated();
265   virtual void                        onViewManagerRemoved( SUIT_ViewManager* );
266   virtual void                        onWindowActivated( SUIT_ViewWindow* theViewWindow );
267
268   void                                onNewWindow();
269   virtual void                        onModuleActivation( const QString& );
270   void                                onExtAdding();
271   void                                onExtRemoving( const QString& );
272   void                                onShowExtInfo();
273   void                                onCloseView( SUIT_ViewManager* );
274
275   virtual void                        onStudyCreated( SUIT_Study* );
276   virtual void                        onStudyOpened( SUIT_Study* );
277   virtual void                        onStudySaved( SUIT_Study* );
278   virtual void                        onStudyClosed( SUIT_Study* );
279
280   void                                onWCDestroyed( QObject* );
281
282   void                                onMRUActivated( const QString& );
283
284   void                                onStylePreferences();
285   void                                onFullScreen();
286
287   virtual void                        onDesktopMessage( const QString& );
288
289   virtual void                        onInfoPanelShown();
290
291 private slots:
292   void                                onSelection();
293   void                                onRefresh();
294   void                                onDropped( const QList<SUIT_DataObject*>&, SUIT_DataObject*, int, Qt::DropAction );
295   void                                onPreferences();
296   void                                onPreferenceChanged( QString&, QString&, QString& );
297   void                                onRenameWindow();
298   void                                onCloseWindow();
299   void                                onCloseAllWindow();
300   void                                onGroupAllWindow();
301   void                                onRenamed();
302   //void                                onMoved();
303
304 protected:
305   void                                updateWindows();
306   void                                updateViewManagers();
307   void                                updateModuleActions();
308
309   bool                                checkModule( const QString& );
310
311   void                                loadDockWindowsState();
312   void                                saveDockWindowsState();
313
314   virtual void                        studyOpened( SUIT_Study* );
315   virtual void                        studyCreated( SUIT_Study* );
316   virtual void                        studySaved( SUIT_Study* );
317
318   void                                updatePreference( const QString&, const QString&, const QString& );
319
320   QString                             defaultModule() const;
321   virtual void                        currentWindows( QMap<int, int>& ) const;
322   void                                currentViewManagers( QStringList& ) const;
323   QPixmap                             moduleIcon( const QString&, const int = -1 ) const;
324
325   QDockWidget*                        windowDock( QWidget* ) const;
326   QByteArray                          dockWindowsState( const QMap<QString, bool>&, const QMap<QString, bool>& ) const;
327   void                                dockWindowsState( const QByteArray&, QMap<QString, bool>&, QMap<QString, bool>& ) const;
328
329   virtual int                         openChoice( const QString& );
330   virtual bool                        openAction( const int, const QString& );
331
332   void                                showPreferences( const QString& = QString() );
333   void                                showPreferences( const QStringList& );
334
335 private:
336   bool                                addUserModule( const QString&, const QString&, bool = false );
337   void                                removeUserModule(const QString& moduleInnerName, LightApp_ModuleAction* moduleAction);
338   void                                emptyPreferences( const QString& );
339   QList<QToolBar*>                    findToolBars( const QStringList& names = QStringList() );
340   void                                createHelpItems( const QString& );
341   void                                removeHelpItems( const QString& );
342
343   QByteArray                          processState(QByteArray& input,
344                                                    const bool processWin,
345                                                    const bool processTb,
346                                                    const bool isRestoring,
347                                                    QByteArray defaultState = QByteArray());
348
349 protected:
350   typedef QPointer<QWidget>          WinPtr;
351   typedef QMap<int, WinPtr>          WinMap;
352   typedef QMap<QString, QByteArray>  WinVis;
353   typedef QMap<QString, QByteArray>  WinGeom;
354   typedef QList<int>                 IdList;
355   typedef QMap<QString, IdList>      IdMap;
356
357   enum { OpenReload = CAM_Application::OpenExist + 1 };
358
359 protected:
360   LightApp_Preferences*               myPrefs;
361   LightApp_SelectionMgr*              mySelMgr;
362
363   LightApp_FullScreenHelper*          myScreenHelper;
364
365   WinMap                              myWin;
366   WinVis                              myWinVis;
367   IdMap                               myHelpItems;
368
369   SUIT_Accel*                         myAccel;
370   QTimer*                             myAutoSaveTimer;
371
372   static LightApp_Preferences*        _prefs_;
373
374   QStringList                         myUserWmTypes;
375
376   friend void LightAppCleanUpAppResources();
377 };
378
379 #ifdef WIN32
380 #pragma warning( default:4251 )
381 #endif
382
383 #endif