Back to index

salome-gui  6.5.0
SALOME_PYQT_ModuleLight.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File   : SALOME_PYQT_Module.h
00021 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00022 //
00023 #ifndef SALOME_PYQT_MODULELIGHT_H
00024 #define SALOME_PYQT_MODULELIGHT_H
00025 
00026 #include "PyInterp_Interp.h" // // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!!
00027 #include "SALOME_PYQT_GUILight.h"
00028 #include "LightApp_Module.h"
00029 #include "SALOME_PYQT_DataObjectLight.h"
00030 #include <CAM_Module.h>
00031 
00032 #include <map>
00033 #include <QStringList>
00034 #include <QList>
00035 #include <QMap>
00036 #include <QIcon>
00037 
00038 class SALOME_PYQT_RootObjectLight;
00039 class SALOME_PYQT_PyInterp;
00040 class SUIT_ViewWindow;
00041 class QAction;
00042 class QtxActionGroup;
00043 class QMenu;
00044 
00045 
00046 class SALOME_PYQT_LIGHT_EXPORT SALOME_PYQT_ModuleLight: virtual public LightApp_Module
00047 {
00048   Q_OBJECT;
00049 
00050 private:
00051   class XmlHandler;
00052 
00054   typedef QMap<int, PyInterp_Interp*> InterpMap;
00055   static SALOME_PYQT_ModuleLight* myInitModule; 
00056 
00057   XmlHandler*                myXmlHandler; 
00058   QMap<int, int>             myWindowsMap; 
00059   QStringList                myViewMgrList;
00060   bool                       myLastActivateStatus; 
00061 
00062 protected:
00063   PyObject*                  myModule;     
00064   PyInterp_Interp*           myInterp;     
00065   static InterpMap           myInterpMap;  
00066 
00067 public:
00068   SALOME_PYQT_ModuleLight();
00069   ~SALOME_PYQT_ModuleLight();
00070 
00071 public:
00072   static SALOME_PYQT_ModuleLight* getInitModule();
00073 
00074   void                       initialize( CAM_Application* );
00075   void                       windows( QMap<int, int>& ) const;
00076   void                       viewManagers( QStringList& ) const;
00077   void                       contextMenuPopup( const QString&, QMenu*, QString& );
00078   void                       createPreferences();
00079   void                       studyActivated();
00080   void                       preferencesChanged( const QString&, const QString& );
00081 
00082   static int                 defaultMenuGroup();
00083 
00084   int                        createTool( const QString& );
00085   int                        createTool( const int, const int, const int = -1 );
00086   int                        createTool( const int, const QString&, const int = -1 );
00087   int                        createTool( QAction*, const int, 
00088                                          const int = -1, const int = -1 );
00089   int                        createTool( QAction*, const QString&, 
00090                                          const int = -1, const int = -1 );
00091 
00092   int                        createMenu( const QString&, const int, 
00093                                          const int = -1, const int = -1, const int = -1 );
00094   int                        createMenu( const QString&, const QString&, 
00095                                          const int = -1, const int = -1, const int = -1 );
00096   int                        createMenu( const int, const int, 
00097                                          const int = -1, const int = -1 );
00098   int                        createMenu( const int, const QString&, 
00099                                          const int = -1, const int = -1 );
00100   int                        createMenu( QAction*, const int, 
00101                                          const int = -1, const int = -1, const int = -1 );
00102   int                        createMenu( QAction*, const QString&, 
00103                                          const int = -1, const int = -1, const int = -1 );
00104 
00105   QAction*                   separator();
00106 
00107   QAction*                   action( const int ) const;
00108   int                        actionId( const QAction* ) const;
00109   QAction*                   createAction( const int, const QString&, const QString&, 
00110                                            const QString&, const QString&, const int, 
00111                                            const bool = false, QObject* = 0 );
00112   QtxActionGroup*            createActionGroup( const int, const bool );
00113 
00114 
00115   QIcon                      loadIcon( const QString& fileName );
00116 
00117   int                        addGlobalPreference( const QString& );
00118   int                        addPreference( const QString& );
00119   int                        addPreference( const QString&, const int, const int = LightApp_Preferences::Auto,
00120                                             const QString& = QString(),
00121                                             const QString& = QString() );
00122   QVariant                   preferenceProperty( const int, const QString& ) const;
00123   void                       setPreferenceProperty( const int, const QString&, 
00124                                                     const QVariant& );
00125 
00126   void                       save(QStringList& theListOfFiles);
00127   bool                       open(QStringList theListOfFiles);
00128   void                       dumpPython(QStringList& theListOfFiles);
00129 
00130   /*create new SALOME_PYQT_DataObjectLight and return its entry*/
00131   QString                    createObject(const QString& parent);
00132   QString                    createObject(const QString& name, 
00133                                      const QString& iconname,
00134                                      const QString& tooltip,
00135                                      const QString& parent);
00136   /*Sets Name, Icon and Tool Tip for object*/
00137   void                      setName(const QString& obj,const QString& iconname);
00138   void                      setIcon(const QString& obj,const QString& name);
00139   void                      setToolTip(const QString& obj, const QString& tooltip);
00140 
00141   /*Gets Name and Tool Tip for object*/
00142   QString                   getName(const QString& obj);
00143   QString                   getToolTip(const QString& obj);
00144 
00145   void                      setColor(const QString& obj, const QColor& color);
00146   QColor                    getColor(const QString& obj);
00147 
00148   void                      setReference( const QString& obj, 
00149                                      const QString& refEntry ); 
00150   QString                   getReference( const QString& obj );
00151 
00152                              /*remove object*/
00153   void                      removeObject(const QString& obj);
00154                             /*remove child*/
00155   void                      removeChild(const QString& obj);
00156                             /*return list of child objets*/
00157   QStringList               getChildren(const QString& obj, const bool rec);
00158 
00159   /*Access to the underlying Python module object */
00160   PyObject*                 getPythonModule();
00161 
00162   /*Drag and drop support*/
00163   virtual bool              isDraggable( const SUIT_DataObject* ) const;
00164   virtual bool              isDropAccepted( const SUIT_DataObject* ) const;
00165   virtual void              dropObjects( const DataObjectList&, SUIT_DataObject*,
00166                                     const int, Qt::DropAction );
00167 
00168 public slots:
00169   virtual bool               activateModule( SUIT_Study* );
00170   virtual bool               deactivateModule( SUIT_Study* );
00171   void                       preferenceChanged( const QString&, 
00172                                                 const QString&, 
00173                                                 const QString& );
00174   void                       onGUIEvent();
00175 
00176   void                       onActiveViewChanged( SUIT_ViewWindow* );
00177   void                       onViewTryClose( SUIT_ViewWindow* );
00178   void                       onViewClosed( SUIT_ViewWindow* );
00179   void                       onViewCloned( SUIT_ViewWindow* );
00180 
00181 protected:
00182   /* create data model */
00183   virtual CAM_DataModel*     createDataModel();
00184   virtual bool               activateModuleInternal( SUIT_Study* );
00185 
00186 private:
00187   void                       init( CAM_Application* );
00188   void                       activate( SUIT_Study* );
00189   void                       deactivate( SUIT_Study* );
00190   bool                       lastActivationStatus() const;
00191   void                       customize( SUIT_Study* );
00192   void                       studyChanged( SUIT_Study* );
00193   void                       contextMenu( const QString&, QMenu* );
00194   void                       guiEvent( const int );
00195   void                       initPreferences();
00196   void                       prefChanged( const QString&, const QString& );
00197 
00198   virtual void               initInterp  ( int );
00199   void                       importModule();
00200   void                       setWorkSpace();
00201   
00202   void                       activeViewChanged( const SUIT_ViewWindow* );
00203   void                       viewTryClose( const SUIT_ViewWindow* );
00204   void                       viewClosed( const SUIT_ViewWindow* );
00205   void                       viewCloned( const SUIT_ViewWindow* );
00206   void                       connectView( const SUIT_ViewWindow* );
00207 
00208   void                       saveEvent(QStringList& theListOfFiles);
00209   void                       dumpEvent(QStringList& theListOfFiles);
00210   void                       openEvent(QStringList theListOfFiles, bool& opened);
00211   
00212   bool                       isDraggableEvent( LightApp_DataObject* );
00213   bool                       isDropAcceptedEvent( LightApp_DataObject* );
00214   void                       dropObjectsEvent( const DataObjectList&, SUIT_DataObject*,
00215                                           const int, Qt::DropAction );
00216 
00217   SALOME_PYQT_DataObjectLight* findObject(const QString& entry);
00218 
00219   friend class XmlHandler;
00220 };
00221 
00222 #endif // SALOME_PYQT_MODULELIGHT_H