Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/gui.git] / src / SALOME_PYQT / SALOME_PYQT_GUI / SALOME_PYQT_Module.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/
18 //
19
20 #ifndef SALOME_PYQT_MODULE_H
21 #define SALOME_PYQT_MODULE_H
22
23 #include "SALOME_PYQT_GUI.h"
24
25 #include "SALOME_PYQT_PyInterp.h" // this include must be first (see PyInterp_base.h)!
26 #include "SalomeApp_Module.h"
27 #include <map>
28 #include <qaction.h>
29 #include <qptrlist.h>
30 #include <qstringlist.h>
31 #include <qmap.h>
32
33 #include <SALOMEconfig.h>
34 #include CORBA_CLIENT_HEADER(SALOME_Component)
35
36 class SALOME_PYQT_XmlHandler;
37
38 class SALOME_PYQT_EXPORT SALOME_PYQT_Module: public SalomeApp_Module
39 {
40   Q_OBJECT;
41
42   /******************************
43    * Data
44    ******************************/
45
46 private:
47   typedef std::map<int, SALOME_PYQT_PyInterp*> InterpMap;
48
49   /* study-to-subinterpreter map */
50   static InterpMap                 myInterpMap;
51   /* current Python subinterpreter */
52   SALOME_PYQT_PyInterp*            myInterp;
53   /* Python GUI module loaded */
54   PyObjWrapper                     myModule;
55   /* Python GUI being initialized (not zero only during the initialization)*/
56   static SALOME_PYQT_Module*       myInitModule;
57
58   /* own menus list */
59   struct MenuId
60   {
61     int  id;
62     bool constantMenu;
63     MenuId() : id( -1 ), constantMenu( false ) {}
64     MenuId( const int _id, const bool _constantMenu )
65       : id( _id ), constantMenu( _constantMenu ) {}
66   };
67   typedef QValueList<MenuId>   MenuIdList;
68   typedef QMap<int,MenuIdList> MenuMap;
69   MenuMap                      myMenus;
70  
71   /* XML resource file parser */
72   SALOME_PYQT_XmlHandler*          myXmlHandler;  
73   /* windows map*/
74   QMap<int, int>                   myWindowsMap;
75   /* compatible view managers list */
76   QStringList                      myViewMgrList;
77   
78   /******************************
79    * Construction/destruction
80    ******************************/
81
82 public:
83   /* constructor */
84   SALOME_PYQT_Module();
85   /* destructor */
86   ~SALOME_PYQT_Module();
87
88   /* get module engine */
89   Engines::Component_var getEngine() const;
90
91   /******************************
92    * Inherited from SalomeApp_Module 
93    ******************************/
94
95 public:
96   /* little trick : provide an access to being activated Python module from outside;
97      needed by the SalomePyQt library :(
98   */
99   static SALOME_PYQT_Module* getInitModule();
100
101   /* initialization */
102   void            initialize  ( CAM_Application* );
103
104   /* getting windows list */
105   void            windows     ( QMap<int, int>& ) const;
106   /* getting compatible viewer managers list */
107   void            viewManagers( QStringList& ) const;
108
109   /* context popup menu request */
110   void            contextMenuPopup( const QString&, QPopupMenu*, QString& );
111
112   /* get module engine IOR */
113   virtual QString engineIOR() const;
114
115   /* called when study desktop is activated */
116   virtual void    studyActivated();
117
118   /* returns default menu group */
119   static int             defaultMenuGroup();
120
121   /* working with toolbars : open protected methods */
122   int                    createTool( const QString& );
123   int                    createTool( const int, const int, const int = -1 );
124   int                    createTool( const int, const QString&, const int = -1 );
125   int                    createTool( QAction*, const int, const int = -1, const int = -1 );
126   int                    createTool( QAction*, const QString&, const int = -1, const int = -1 );
127
128   /* working with menus : open protected methods */
129   int                    createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1, const bool = false );
130   int                    createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1, const bool = false );
131   int                    createMenu( const int, const int, const int = -1, const int = -1, const bool = false );
132   int                    createMenu( const int, const QString&, const int = -1, const int = -1, const bool = false );
133   int                    createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1, const bool = false );
134   int                    createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1, const bool = false );
135
136   /* clear given menu */
137   bool                   clearMenu( const int = 0, const int = 0, const bool = true );
138
139   /* create separator : open protected method */
140   QAction*               createSeparator();
141
142   /* working with actions : open protected methods */
143   QAction*               action( const int ) const;
144   int                    actionId( const QAction* ) const;
145   QAction*               createAction( const int, const QString&, const QString&, const QString&,
146                                        const QString&, const int, const bool = false );
147   /* load icon from resource file */
148   QIconSet               loadIcon( const QString& fileName );
149
150   /* Show/hide menus/toolbars */
151   void                   setMenuShown( const bool );
152   void                   setToolShown( const bool );
153
154 public slots:
155   /* activation */
156   virtual bool    activateModule( SUIT_Study* );
157   /* deactivation */
158   virtual bool    deactivateModule( SUIT_Study* );
159
160   /******************************
161    * Internal methods
162    ******************************/
163
164 public slots:
165   /* GUI action processing slots */
166   void            onGUIEvent();
167   void            onGUIEvent( int );
168
169 protected:
170   /* Menu processing */
171   bool            hasMenu( const QString&, const int );
172   void            registerMenu( const int, const int, const bool = false );
173   void            unregisterMenu( const int, const int );
174   bool            registered( const int, const int = 0 );
175   bool            isConstantMenu( const int, const int );
176
177 protected slots:
178   void            onMenuHighlighted( int, int );
179
180 private:
181   /* internal initizalition */ 
182   void            init        ( CAM_Application* );
183   /* internal activation */ 
184   void            activate    ( SUIT_Study* );
185   /* internal deactivation */ 
186   void            deactivate  ( SUIT_Study* );
187   /* customization */ 
188   void            customize   ( SUIT_Study* );
189   /* study activation */ 
190   void            studyChanged( SUIT_Study* );
191   /* context popup menu processing */
192   void            contextMenu( const QString&, QPopupMenu* );
193   /* GUI event processing */
194   void            guiEvent( const int );
195   /* Menu highlight processing */
196   void            menuHighlight( const int, const int );
197
198   /* initialize a Python subinterpreter */
199   void            initInterp  ( int );
200   /* import a Python GUI module */
201   void            importModule();
202   /* set workspace to Python GUI module */
203   void            setWorkSpace();
204
205   friend class SALOME_PYQT_XmlHandler;
206 };
207
208 #endif // SALOME_PYQT_MODULE_H