Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/gui.git] / src / LightApp / LightApp_Application.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File:      LightApp_Application.h
20 // Created:   6/20/2005 18:39:25 PM
21 // Author:    OCC team
22 // Copyright (C) CEA 2005
23
24 #ifndef LIGHTAPP_APPLICATION_H
25 #define LIGHTAPP_APPLICATION_H
26
27 #if _MSC_VER > 1000
28 #pragma once
29 #endif // _MSC_VER > 1000
30
31 #include "LightApp.h"
32 #include <CAM_Application.h>
33
34 class LogWindow;
35 class OB_Browser;
36 #ifndef DISABLE_PYCONSOLE
37   class PythonConsole;
38 #endif
39 class STD_Application;
40 class LightApp_WidgetContainer;
41 class LightApp_Preferences;
42 class LightApp_SelectionMgr;
43 class LightApp_DataObject;
44 class SUIT_Study;
45 class SUIT_Accel;
46 class CAM_Module;
47
48 class QString;
49 class QWidget;
50 class QStringList;
51 class QPixmap;
52
53 #ifdef WIN32
54 #pragma warning( disable:4251 )
55 #endif
56
57 /*!
58   Description : Application containing only LightApp module
59 */
60
61 class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application
62 {
63   Q_OBJECT
64
65 public:
66   typedef enum { WT_ObjectBrowser, 
67 #ifndef DISABLE_PYCONSOLE
68                  WT_PyConsole,
69 #endif
70                  WT_LogWindow,
71                  WT_User }
72   WindowTypes;
73
74   enum { MenuWindowId = 6 };
75
76   enum { RenameId = CAM_Application::UserID,
77
78 #ifndef DISABLE_GLVIEWER
79          NewGLViewId ,
80 #endif
81
82 #ifndef DISABLE_PLOT2DVIEWER
83          NewPlot2dId,
84 #endif
85
86 #ifndef DISABLE_OCCVIEWER
87          NewOCCViewId,
88 #endif
89
90 #ifndef DISABLE_VTKVIEWER
91          NewVTKViewId,
92 #endif
93
94 #ifndef DISABLE_QXGRAPHVIEWER
95          NewQxGraphViewId,
96 #endif
97
98          PreferencesId, MRUId, UserID };
99
100 protected:
101   enum { NewStudyId = 1, OpenStudyId };
102
103 public:
104   LightApp_Application();
105   virtual ~LightApp_Application();
106
107   virtual QString                     applicationName() const;
108   virtual QString                     applicationVersion() const;
109
110   virtual CAM_Module*                 loadModule( const QString& );
111   virtual bool                        activateModule( const QString& );
112
113   virtual bool                        useStudy( const QString& );
114
115   LightApp_SelectionMgr*              selectionMgr() const;
116   
117   LogWindow*                          logWindow();
118   OB_Browser*                         objectBrowser();
119 #ifndef DISABLE_PYCONSOLE
120   PythonConsole*                      pythonConsole(); 
121 #endif
122
123   virtual void                        updateObjectBrowser( const bool = true );
124
125   LightApp_Preferences*               preferences() const;
126
127   virtual QString                     getFileFilter() 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 );
141
142   QWidget*                            getWindow( const int, const int = -1 );
143   QWidget*                            window( const int, const int = -1 ) const;
144   void                                addWindow( QWidget*, const int, const int = -1 );
145   void                                removeWindow( const int, const int = -1 );
146
147   bool                                isWindowVisible( const int ) const;
148   void                                setWindowShown( const int, const bool );
149
150   virtual void                        start();
151
152   virtual void                        contextMenuPopup( const QString&, QPopupMenu*, QString& );
153
154   virtual void                        createEmptyStudy();
155
156   SUIT_Accel*                         accel() const;
157
158   void                                setDefaultStudyName( const QString& theName );
159
160   static int                          studyId();
161
162   virtual bool                        event( QEvent* );
163   
164   virtual bool                        checkDataObject( LightApp_DataObject* theObj );
165
166 signals:
167   void                                studyOpened();
168   void                                studySaved();
169   void                                studyClosed();
170   void                                preferenceChanged( const QString&, const QString&, const QString& );
171
172 public slots:
173   virtual void                        onHelpContentsModule();
174   virtual void                        onHelpContextModule( const QString&, const QString& );
175   virtual void                        onNewDoc();
176   virtual void                        onOpenDoc();
177   virtual void                        onHelpAbout();
178   virtual bool                        onOpenDoc( const QString& );
179   virtual bool                        onLoadDoc( const QString& );
180
181 protected:
182   virtual void                        createActions();
183   virtual void                        createActionForViewer( const int id,
184                                                              const int parentId,
185                                                              const QString& suffix,
186                                                              const int accel );
187   virtual SUIT_Study*                 createNewStudy();
188   virtual QWidget*                    createWindow( const int );
189   virtual void                        defaultWindows( QMap<int, int>& ) const;
190   void                                defaultViewManagers( QStringList& ) const;
191
192   virtual void                        setActiveStudy( SUIT_Study* );
193   virtual void                        updateCommandsStatus();
194   virtual void                        onSelectionChanged();
195
196   virtual void                        beforeCloseDoc( SUIT_Study* );
197   virtual void                        afterCloseDoc();
198   virtual void                        moduleAdded( CAM_Module* );
199   virtual bool                        activateModule( CAM_Module* = 0 );
200
201   LightApp_Preferences*               preferences( const bool ) const;
202   virtual void                        createPreferences( LightApp_Preferences* );
203   virtual void                        preferencesChanged( const QString&, const QString& );
204   virtual void                        savePreferences();
205   virtual void                        updateDesktopTitle();
206   
207   virtual QMap<int, QString>          activateModuleActions() const;
208   virtual void                        moduleActionSelected( const int );
209
210 protected slots:
211   virtual void                        onDesktopActivated();
212
213   void                                onNewWindow();
214   void                                onModuleActivation( QAction* );
215   void                                onCloseView( SUIT_ViewManager* );
216
217   void                                onStudyCreated( SUIT_Study* );
218   void                                onStudyOpened( SUIT_Study* );
219   void                                onStudySaved( SUIT_Study* );
220   void                                onStudyClosed( SUIT_Study* );
221
222   void                                onWCDestroyed( QObject* );
223
224 private slots:
225   void                                onSelection();
226   void                                onRefresh();
227   void                                onFind();
228   void                                onPreferences();
229   void                                onMRUActivated( QString );
230   void                                onPreferenceChanged( QString&, QString&, QString& );
231   void                                onRenameWindow();
232   void                                onVisibilityChanged( bool );
233
234 protected:
235   void                                updateWindows();
236   void                                updateViewManagers();
237   void                                updateModuleActions();
238
239   void                                loadWindowsGeometry();
240   void                                saveWindowsGeometry();
241
242   void                                updatePreference( const QString&, const QString&, const QString& );
243
244   QString                             defaultModule() const;
245   void                                currentWindows( QMap<int, int>& ) const;
246   void                                currentViewManagers( QStringList& ) const;
247   void                                moduleIconNames( QMap<QString, QString>& ) const;
248
249   void                                activateWindows();
250   bool                                isLibExists( const QString& ) const;
251
252 protected:
253   typedef QMap<QString, QAction*>              ActionMap;
254   typedef QMap<int, LightApp_WidgetContainer*> WindowMap;
255   typedef QMap<int, bool>                      WindowVisibilityMap;
256
257 protected:
258   LightApp_Preferences*               myPrefs;
259   LightApp_SelectionMgr*              mySelMgr;
260   ActionMap                           myActions;
261   WindowMap                           myWindows;
262   WindowVisibilityMap                 myWindowsVisible;
263
264   SUIT_Accel*                         myAccel;
265
266   static LightApp_Preferences*        _prefs_;
267
268   static int                          lastStudyId;
269 };
270
271 #ifdef WIN32
272 #pragma warning( default:4251 )
273 #endif
274
275 #endif