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