Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / SALOME_PYQT / SALOME_PYQT_GUI / SALOME_PYQT_Module.h
1 //  Copyright (C) 2007-2008  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.
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 // File   : SALOME_PYQT_Module.h
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24 //
25 #ifndef SALOME_PYQT_MODULE_H
26 #define SALOME_PYQT_MODULE_H
27
28 #include "SALOME_PYQT_GUI.h"
29 #include "SALOME_PYQT_PyInterp.h" // this include must be first (see PyInterp_Interp.h)!
30
31 #include <SalomeApp_Module.h>
32
33 #include <QStringList>
34 #include <QList>
35 #include <QMap>
36 #include <QIcon>
37
38 #include <SALOMEconfig.h>
39 #include CORBA_CLIENT_HEADER(SALOME_Component)
40
41 class SALOME_PYQT_PyInterp;
42 class SUIT_ViewWindow;
43 class QAction;
44 class QtxActionGroup;
45 class QMenu;
46
47 class SALOME_PYQT_EXPORT SALOME_PYQT_Module: public SalomeApp_Module
48 {
49   Q_OBJECT;
50
51 private:
52   class XmlHandler;
53
54   //! study to Python subinterpreter map
55   typedef QMap<int, SALOME_PYQT_PyInterp*> InterpMap;
56
57   static InterpMap           myInterpMap;  //!< study to Python subinterpreter map
58   SALOME_PYQT_PyInterp*      myInterp;     //!< current Python subinterpreter
59   PyObjWrapper               myModule;     //!< Python GUI module
60   static SALOME_PYQT_Module* myInitModule; //!< Python GUI being initialized (not zero only during the initialization)
61
62   XmlHandler*                myXmlHandler; //!< XML resource file parser
63   QMap<int, int>             myWindowsMap; //!< windows map
64   QStringList                myViewMgrList;//!< compatible view managers list
65
66   bool                       myLastActivateStatus; //!< latest module activation status
67
68 public:
69   SALOME_PYQT_Module();
70   ~SALOME_PYQT_Module();
71
72 public:
73   static SALOME_PYQT_Module* getInitModule();
74
75   void                       initialize( CAM_Application* );
76   void                       windows( QMap<int, int>& ) const;
77   void                       viewManagers( QStringList& ) const;
78   void                       contextMenuPopup( const QString&, QMenu*, QString& );
79   void                       createPreferences();
80   QString                    engineIOR() const;
81   void                       studyActivated();
82   void                       preferencesChanged( const QString&, const QString& );
83
84   static int                 defaultMenuGroup();
85
86   int                        createTool( const QString& );
87   int                        createTool( const int, const int, const int = -1 );
88   int                        createTool( const int, const QString&, const int = -1 );
89   int                        createTool( QAction*, const int, 
90                                          const int = -1, const int = -1 );
91   int                        createTool( QAction*, const QString&, 
92                                          const int = -1, const int = -1 );
93
94   int                        createMenu( const QString&, const int, 
95                                          const int = -1, const int = -1, const int = -1 );
96   int                        createMenu( const QString&, const QString&, 
97                                          const int = -1, const int = -1, const int = -1 );
98   int                        createMenu( const int, const int, 
99                                          const int = -1, const int = -1 );
100   int                        createMenu( const int, const QString&, 
101                                          const int = -1, const int = -1 );
102   int                        createMenu( QAction*, const int, 
103                                          const int = -1, const int = -1, const int = -1 );
104   int                        createMenu( QAction*, const QString&, 
105                                          const int = -1, const int = -1, const int = -1 );
106
107   QAction*                   separator();
108
109   QAction*                   action( const int ) const;
110   int                        actionId( const QAction* ) const;
111   QAction*                   createAction( const int, const QString&, const QString&, 
112                                            const QString&, const QString&, const int, 
113                                            const bool = false, QObject* = 0 );
114   QtxActionGroup*            createActionGroup( const int, const bool );
115
116
117   QIcon                      loadIcon( const QString& fileName );
118
119   int                        addGlobalPreference( const QString& );
120   int                        addPreference( const QString& );
121   int                        addPreference( const QString&, const int, const int = LightApp_Preferences::Auto,
122                                             const QString& = QString(),
123                                             const QString& = QString() );
124   QVariant                   preferenceProperty( const int, const QString& ) const;
125   void                       setPreferenceProperty( const int, const QString&, 
126                                                     const QVariant& );
127
128 public slots:
129   virtual bool               activateModule( SUIT_Study* );
130   virtual bool               deactivateModule( SUIT_Study* );
131   void                       preferenceChanged( const QString&, 
132                                                 const QString&, 
133                                                 const QString& );
134   void                       onGUIEvent();
135
136   void                       onActiveViewChanged( SUIT_ViewWindow* );
137   void                       onViewClosed( SUIT_ViewWindow* );
138   void                       onViewCloned( SUIT_ViewWindow* );
139
140 protected:
141   Engines::Component_var     getEngine() const;
142
143 private:
144   void                       init( CAM_Application* );
145   void                       activate( SUIT_Study* );
146   void                       deactivate( SUIT_Study* );
147   bool                       lastActivationStatus() const;
148   void                       customize( SUIT_Study* );
149   void                       studyChanged( SUIT_Study* );
150   void                       contextMenu( const QString&, QMenu* );
151   void                       guiEvent( const int );
152   void                       initPreferences();
153   void                       prefChanged( const QString&, const QString& );
154
155   void                       initInterp  ( int );
156   void                       importModule();
157   void                       setWorkSpace();
158   
159   void                       activeViewChanged( const SUIT_ViewWindow* );
160   void                       viewClosed( const SUIT_ViewWindow* );
161   void                       viewCloned( const SUIT_ViewWindow* );
162   void                       connectView( const SUIT_ViewWindow* );
163
164   friend class XmlHandler;
165 };
166
167 #endif // SALOME_PYQT_MODULE_H