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