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