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