Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[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 SUIT_Study;
44 class SUIT_Accel;
45 class CAM_Module;
46
47 class QString;
48 class QWidget;
49 class QStringList;
50 class QPixmap;
51
52 #ifdef WIN32
53 #pragma warning( disable:4251 )
54 #endif
55
56 /*!
57   Description : Application containing only LightApp module
58 */
59
60 class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application
61 {
62   Q_OBJECT
63
64 public:
65   typedef enum { WT_ObjectBrowser, 
66 #ifndef DISABLE_PYCONSOLE
67                  WT_PyConsole,
68 #endif
69                  WT_LogWindow,
70                  WT_User }
71   WindowTypes;
72
73   enum { MenuWindowId = 6 };
74
75   enum { RenameId = CAM_Application::UserID,
76
77 #ifndef DISABLE_GLVIEWER
78          NewGLViewId ,
79 #endif
80
81 #ifndef DISABLE_PLOT2DVIEWER
82          NewPlot2dId,
83 #endif
84
85 #ifndef DISABLE_OCCVIEWER
86          NewOCCViewId,
87 #endif
88
89 #ifndef DISABLE_VTKVIEWER
90          NewVTKViewId,
91 #endif
92
93          PreferencesId, MRUId, UserID };
94 public:
95   LightApp_Application();
96   virtual ~LightApp_Application();
97
98   virtual QString                     applicationName() const;
99   virtual QString                     applicationVersion() const;
100
101   virtual CAM_Module*                 loadModule( const QString& );
102   virtual bool                        activateModule( const QString& );
103
104   virtual bool                        useStudy( const QString& );
105
106   LightApp_SelectionMgr*              selectionMgr() const;
107   
108   LogWindow*                          logWindow();
109   OB_Browser*                         objectBrowser();
110 #ifndef DISABLE_PYCONSOLE
111   PythonConsole*                      pythonConsole(); 
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   QWidget*                            getWindow( const int, const int = -1 );
132   QWidget*                            window( const int, const int = -1 ) const;
133   void                                addWindow( QWidget*, const int, const int = -1 );
134   void                                removeWindow( const int, const int = -1 );
135
136   bool                                isWindowVisible( const int ) const;
137   void                                setWindowShown( const int, const bool );
138
139   virtual void                        start();
140
141   virtual void                        contextMenuPopup( const QString&, QPopupMenu*, QString& );
142
143   virtual void                        createEmptyStudy();
144
145   SUIT_Accel*                         accel() const;
146
147   void                                setDefaultStudyName( const QString& theName );
148
149   static int                          studyId();
150
151   virtual bool                        event( QEvent* );
152
153 signals:
154   void                                studyOpened();
155   void                                studySaved();
156   void                                studyClosed();
157
158 public slots:
159   virtual void                        onHelpContentsModule();
160   virtual void                        onHelpContextModule( const QString&, const QString& );
161   virtual void                        onNewDoc();
162   virtual void                        onOpenDoc();
163   virtual void                        onHelpAbout();
164   virtual bool                        onOpenDoc( const QString& );
165   virtual bool                        onLoadDoc( const QString& );
166
167 protected:
168   virtual void                        createActions();
169   virtual void                        createActionForViewer( const int id,
170                                                              const int parentId,
171                                                              const QString& suffix,
172                                                              const int accel );
173   virtual SUIT_Study*                 createNewStudy();
174   virtual QWidget*                    createWindow( const int );
175   virtual void                        defaultWindows( QMap<int, int>& ) const;
176   void                                defaultViewManagers( QStringList& ) const;
177
178   virtual void                        setActiveStudy( SUIT_Study* );
179   virtual void                        updateCommandsStatus();
180   virtual void                        onSelectionChanged();
181
182   virtual void                        beforeCloseDoc( SUIT_Study* );
183   virtual void                        afterCloseDoc();
184   virtual void                        moduleAdded( CAM_Module* );
185   virtual bool                        activateModule( CAM_Module* = 0 );
186
187   LightApp_Preferences*               preferences( const bool ) const;
188   virtual void                        createPreferences( LightApp_Preferences* );
189   virtual void                        preferencesChanged( const QString&, const QString& );
190   virtual void                        savePreferences();
191   virtual void                        updateDesktopTitle();
192
193 protected slots:
194   virtual void                        onDesktopActivated();
195
196   void                                onNewWindow();
197   void                                onModuleActivation( QAction* );
198   void                                onCloseView( SUIT_ViewManager* );
199
200   void                                onStudyCreated( SUIT_Study* );
201   void                                onStudyOpened( SUIT_Study* );
202   void                                onStudySaved( SUIT_Study* );
203   void                                onStudyClosed( SUIT_Study* );
204
205   void                                onWCDestroyed( QObject* );
206
207 private slots:
208   void                                onSelection();
209   void                                onRefresh();
210   void                                onPreferences();
211   void                                onMRUActivated( QString );
212   void                                onPreferenceChanged( QString&, QString&, QString& );
213   void                                onRenameWindow();
214   void                                onVisibilityChanged( bool );
215
216 protected:
217   void                                updateWindows();
218   void                                updateViewManagers();
219   void                                updateModuleActions();
220
221   void                                loadWindowsGeometry();
222   void                                saveWindowsGeometry();
223
224   void                                updatePreference( const QString&, const QString&, const QString& );
225
226   QString                             defaultModule() const;
227   void                                currentWindows( QMap<int, int>& ) const;
228   void                                currentViewManagers( QStringList& ) const;
229   virtual SUIT_ViewManager*           createViewManager( const QString& vmType );
230   void                                moduleIconNames( QMap<QString, QString>& ) const;
231
232   void                                activateWindows();
233   bool                                isLibExists( const QString& ) const;
234
235 protected:
236   typedef QMap<QString, QAction*>              ActionMap;
237   typedef QMap<int, LightApp_WidgetContainer*> WindowMap;
238   typedef QMap<int, bool>                      WindowVisibilityMap;
239
240 protected:
241   LightApp_Preferences*               myPrefs;
242   LightApp_SelectionMgr*              mySelMgr;
243   ActionMap                           myActions;
244   WindowMap                           myWindows;
245   WindowVisibilityMap                 myWindowsVisible;
246
247   SUIT_Accel*                         myAccel;
248
249   static LightApp_Preferences*        _prefs_;
250
251   static int                          lastStudyId;
252 };
253
254 #ifdef WIN32
255 #pragma warning( default:4251 )
256 #endif
257
258 #endif