Salome HOME
remove view manager from memory when it become unused
[modules/gui.git] / src / LightApp / LightApp_Application.h
1 // File:      LightApp_Application.h
2 // Created:   6/20/2005 18:39:25 PM
3 // Author:    OCC team
4 // Copyright (C) CEA 2005
5
6 #ifndef LIGHTAPP_APPLICATION_H
7 #define LIGHTAPP_APPLICATION_H
8
9 #if _MSC_VER > 1000
10 #pragma once
11 #endif // _MSC_VER > 1000
12
13 #include "LightApp.h"
14 #include <CAM_Application.h>
15
16 class LogWindow;
17 class OB_Browser;
18 class PythonConsole;
19 class STD_Application;
20 class LightApp_WidgetContainer;
21 class LightApp_Preferences;
22 class LightApp_SelectionMgr;
23 class SUIT_Study;
24 class SUIT_Accel;
25 class CAM_Module;
26
27 class QString;
28 class QWidget;
29 class QStringList;
30 class QPixmap;
31
32 #ifdef WIN32
33 #pragma warning( disable:4251 )
34 #endif
35
36 /*!
37   Description : Application containing only LightApp module
38 */
39
40 class LIGHTAPP_EXPORT LightApp_Application : public CAM_Application
41 {
42   Q_OBJECT
43
44 public:
45   typedef enum { WT_ObjectBrowser, WT_PyConsole, WT_LogWindow, WT_User } WindowTypes;
46
47   enum { NewGLViewId = STD_Application::UserID, NewPlot2dId, NewOCCViewId, NewVTKViewId,
48          PreferencesId, MRUId, UserID };
49 public:
50   LightApp_Application();
51   virtual ~LightApp_Application();
52
53   virtual QString                     applicationName() const;
54   virtual QString                     applicationVersion() const;
55
56   virtual CAM_Module*                 loadModule( const QString& );
57   virtual bool                        activateModule( const QString& );
58
59   virtual bool                        useStudy( const QString& );
60
61   LightApp_SelectionMgr*              selectionMgr() const;
62   
63   LogWindow*                          logWindow();
64   OB_Browser*                         objectBrowser();
65   PythonConsole*                      pythonConsole(); 
66
67   virtual void                        updateObjectBrowser( const bool = true );
68
69   LightApp_Preferences*               preferences() const;
70
71   virtual QString                     getFileFilter() const;
72
73   virtual QString                     getFileName( bool open, const QString& initial, const QString& filters, 
74                                                    const QString& caption, QWidget* parent );
75   virtual QString                     getDirectory( const QString& initial, const QString& caption, QWidget* parent );
76   virtual QStringList                 getOpenFileNames( const QString& initial, const QString& filters, 
77                                                         const QString& caption, QWidget* parent );
78
79   void                                updateActions();
80
81   SUIT_ViewManager*                   getViewManager( const QString&, const bool );
82   virtual void                        removeViewManager( SUIT_ViewManager* );
83   QWidget*                            getWindow( const int, const int = -1 );
84   QWidget*                            window( const int, const int = -1 ) const;
85   void                                addWindow( QWidget*, const int, const int = -1 );
86   void                                removeWindow( const int, const int = -1 );
87
88   bool                                isWindowVisible( const int ) const;
89   void                                setWindowShown( const int, const bool );
90
91   virtual void                        start();
92
93   virtual void                        contextMenuPopup( const QString&, QPopupMenu*, QString& );
94
95   virtual void                        createEmptyStudy();
96
97   SUIT_Accel*                         accel() const;
98
99 signals:
100   void                                studyOpened();
101   void                                studySaved();
102   void                                studyClosed();
103
104 public slots:
105   virtual void                        onHelpContentsModule();
106   virtual void                        onNewDoc();
107   virtual void                        onOpenDoc();
108   virtual void                        onHelpAbout();
109   virtual bool                        onOpenDoc( const QString& );
110   virtual bool                        onLoadDoc( const QString& );
111
112 protected:
113   virtual void                        createActions();
114   virtual SUIT_Study*                 createNewStudy();
115   virtual QWidget*                    createWindow( const int );
116   virtual void                        defaultWindows( QMap<int, int>& ) const;
117   void                                defaultViewManagers( QStringList& ) const;
118
119   virtual void                        setActiveStudy( SUIT_Study* );
120   virtual void                        updateCommandsStatus();
121   virtual void                        onSelectionChanged();
122
123   virtual void                        beforeCloseDoc( SUIT_Study* );
124   virtual void                        afterCloseDoc();
125   virtual void                        moduleAdded( CAM_Module* );
126   virtual bool                        activateModule( CAM_Module* = 0 );
127
128   LightApp_Preferences*               preferences( const bool ) const;
129   virtual void                        createPreferences( LightApp_Preferences* );
130   virtual void                        preferencesChanged( const QString&, const QString& );
131   virtual void                        updateDesktopTitle();
132
133 protected slots:
134   virtual void                        onDesktopActivated();
135
136   void                                onNewWindow();
137   void                                onModuleActivation( QAction* );
138   void                                onCloseView( SUIT_ViewManager* );
139
140   void                                onStudyCreated( SUIT_Study* );
141   void                                onStudyOpened( SUIT_Study* );
142   void                                onStudySaved( SUIT_Study* );
143   void                                onStudyClosed( SUIT_Study* );
144
145   void                                onWCDestroyed( QObject* );
146
147 private slots:
148   void                                onSelection();
149   void                                onRefresh();
150   void                                onPreferences();
151   void                                onMRUActivated( QString );
152   void                                onPreferenceChanged( QString&, QString&, QString& );
153
154 protected:
155   void                                updateWindows();
156   void                                updateViewManagers();
157   void                                updateModuleActions();
158
159   void                                loadWindowsGeometry();
160   void                                saveWindowsGeometry();
161
162   void                                updatePreference( const QString&, const QString&, const QString& );
163
164   QString                             defaultModule() const;
165   void                                currentWindows( QMap<int, int>& ) const;
166   void                                currentViewManagers( QStringList& ) const;
167   virtual SUIT_ViewManager*           createViewManager( const QString& vmType );
168   void                                moduleIconNames( QMap<QString, QString>& ) const;
169
170   void                                activateWindows();
171
172 protected:
173   typedef QMap<QString, QAction*>              ActionMap;
174   typedef QMap<int, LightApp_WidgetContainer*> WindowMap;
175
176 protected:
177   LightApp_Preferences*               myPrefs;
178   LightApp_SelectionMgr*              mySelMgr;
179   ActionMap                           myActions;
180   WindowMap                           myWindows;
181
182   SUIT_Accel*                         myAccel;
183
184   static LightApp_Preferences*        _prefs_;
185 };
186
187 #ifdef WIN32
188 #pragma warning( default:4251 )
189 #endif
190
191 #endif