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