]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Fix a bug : in Python modules which connect directly to the selection by SalomePyQt...
authorvsr <vsr@opencascade.com>
Tue, 17 Jan 2006 16:34:32 +0000 (16:34 +0000)
committervsr <vsr@opencascade.com>
Tue, 17 Jan 2006 16:34:32 +0000 (16:34 +0000)
src/SALOMEGUI/QAD_Study.cxx
src/SALOMEGUI/QAD_Study.h
src/SALOME_PYQT/Makefile.in
src/SALOME_PYQT/SalomePyQt.cxx
src/SALOME_PYQT/SalomePyQt.h [new file with mode: 0644]
src/SALOME_PYQT/SalomePyQt.hxx [deleted file]
src/SALOME_PYQT/SalomePyQt.sip
src/SALOME_PYQT/SalomePyQt_v4.sip

index 370df0689b5a95d66650ed058c0fec67e896b1c0..e811a535deb7aa8d6473846a44ab95bec30514da 100644 (file)
@@ -1333,6 +1333,8 @@ void QAD_Study::Selection( QString aSelection )
   SALOME_Selection* Sel = SALOME_Selection::Selection( QString(myTitle + "_" + aSelection) );
 
   mySelection = aSelection;
+
+  emit selectionModified( this );
 }
 
 /*!
index 409b2aba4dc47e731a21504c2d5127d61a756244..3e5ef37b051678987b0aced8cf6b5df71aea6ba7 100644 (file)
@@ -162,6 +162,7 @@ signals:
   void           docOperationTerminated( bool );
   void            closed();
   void            supervStudyFrameClosing( QAD_ViewFrame* );
+  void            selectionModified( QAD_Study* );
 
 public slots:
   void           onStudyFrameActivated( QAD_StudyFrame* );
index 74bbf6d53100187452967b11e50cca3ca51250dd..1310f9493bf337fbec02e932685306bd18bdc5cf 100644 (file)
@@ -27,7 +27,7 @@ endif
 SIP_FLAGS = -t WS_X11 -t $(QT_VERS) $(PYQT_SIPFLAGS) -s ".cc" -c . -I $(PYQT_SIPS)
 # Sip common sources
 SIP_SRC = sipSalomePyQtSalomePyQt.cc \
-         sipSalomePyQtSALOME_Selection.cc
+         sipSalomePyQtSalomePyQt_Selection.cc
 
 # Sip version-specific sources
 ifeq ($(SIP_VERS),v4_old)
@@ -97,7 +97,8 @@ LIB_SRC = SalomePyQt.cxx \
           $(MOC_SRC) 
 
 # Library moc sources
-LIB_MOC = SALOME_PYQT_GUI.h
+LIB_MOC = SALOME_PYQT_GUI.h \
+         SalomePyQt.h
 
 # Client IDL
 LIB_CLIENT_IDL = SALOME_Exception.idl SALOME_GenericObj.idl
index 8636165484df2c3a6f200ca2362f17f46b451f3a..1c97c3c2306d37e705bbd444e0a23bf7d6423b3b 100644 (file)
@@ -5,7 +5,7 @@
 //  File   : SalomePyQt.cxx
 //  Module : SALOME
 
-#include "SalomePyQt.hxx"
+#include "SalomePyQt.h"
 
 #include <qapplication.h>
 #include <qmenubar.h>
 #include "QAD_Config.h"
 #include "QAD_Settings.h"
 
+//====================================================================================
+// SalomePyQt_Selection class.
+//====================================================================================
+static QMap<QAD_Study*, SalomePyQt_Selection*> SelMap;
+
+/*!
+  SalomePyQt_Selection::GetSelection
+  Creates or finds the selection object (one per study).
+*/
+SalomePyQt_Selection* SalomePyQt_Selection::GetSelection( QAD_Study* study )
+{
+  SalomePyQt_Selection* sel = 0;
+  if ( study && SelMap.find( study ) != SelMap.end() )
+    sel = SelMap[ study ];
+  else 
+    sel = SelMap[ study ] = new SalomePyQt_Selection( study );
+  return sel;
+}
+
+/*!
+  SalomePyQt_Selection::SalomePyQt_Selection
+  Selection constructor.
+*/
+SalomePyQt_Selection::SalomePyQt_Selection( QObject* p ) :
+  QObject( p ), myStudy( 0 ), mySelection( 0 )
+{
+  myStudy = dynamic_cast<QAD_Study*>( p );
+  if ( myStudy ) {
+    mySelection = SALOME_Selection::Selection( myStudy->getSelection() );
+    if ( mySelection ) {
+      connect( mySelection, SIGNAL( currentSelectionChanged() ), 
+              this,        SIGNAL( currentSelectionChanged() ) );
+      connect( mySelection, SIGNAL( destroyed() ),        
+              this,        SLOT  ( onSelectionDestroyed() ) );
+      connect( myStudy,     SIGNAL( selectionModified( QAD_Study* ) ),        
+              this,        SLOT  ( onSelectionModified() ) );
+    }
+  }
+}
+/*!
+  SalomePyQt_Selection::~SalomePyQt_Selection
+  Selection destructor. Removes selection object from the map.
+*/
+SalomePyQt_Selection::~SalomePyQt_Selection()
+{
+  if ( myStudy && SelMap.find( myStudy ) != SelMap.end() )
+    SelMap.remove( myStudy );
+}
+
+/*!
+  SalomePyQt_Selection::onSelectionDestroyed
+  Watches for the selection destroying (e.g. when study is closed).
+*/
+void SalomePyQt_Selection::onSelectionDestroyed()
+{
+  mySelection = 0;
+}
+
+/*!
+  SalomePyQt_Selection::onSelectionModified
+  Updates and reconnect selection when it is changed (e.g. when study is saved).
+*/
+void SalomePyQt_Selection::onSelectionModified()
+{
+  if ( mySelection ) {
+    disconnect( mySelection, SIGNAL( currentSelectionChanged() ), 
+               this,        SIGNAL( currentSelectionChanged() ) );
+    disconnect( mySelection, SIGNAL( destroyed() ),        
+               this,        SLOT  ( onSelectionDestroyed() ) );
+  }
+  
+  mySelection = myStudy ? SALOME_Selection::Selection( myStudy->getSelection() ) : 0;
+    
+  if ( mySelection ) {
+    connect( mySelection, SIGNAL( currentSelectionChanged() ), 
+            this,        SIGNAL( currentSelectionChanged() ) );
+    connect( mySelection, SIGNAL( destroyed() ),        
+            this,        SLOT  ( onSelectionDestroyed() ) );
+  }
+}
+
+/*!
+  SalomePyQt_Selection::Clear
+  Clears the selection.
+*/
+void SalomePyQt_Selection::Clear()
+{
+  if ( mySelection ) mySelection->Clear();
+}
+
+/*!
+  SalomePyQt_Selection::ClearIObjects
+  Clears the selection and emits the signal.
+*/
+void SalomePyQt_Selection::ClearIObjects()
+{
+  if ( mySelection ) mySelection->ClearIObjects();
+}
+
+/*!
+  SalomePyQt_Selection::ClearFilters
+  Removes all selection filters.
+*/
+void SalomePyQt_Selection::ClearFilters()
+{
+  if ( mySelection ) mySelection->ClearFilters();
+}
+
+//====================================================================================
+// SalomePyQt class
+//====================================================================================
+
 using namespace std;
 
 QWidget* SalomePyQt::getDesktop()
@@ -43,9 +155,9 @@ int SalomePyQt::getStudyId()
   return QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getStudyId();
 }
 
-SALOME_Selection* SalomePyQt::getSelection()
+SalomePyQt_Selection* SalomePyQt::getSelection()
 {
-  return SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getSelection());
+  return SalomePyQt_Selection::GetSelection(QAD_Application::getDesktop()->getActiveApp()->getActiveStudy());
 }
 
 void SalomePyQt::putInfo( const QString& msg )
diff --git a/src/SALOME_PYQT/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt.h
new file mode 100644 (file)
index 0000000..05f160a
--- /dev/null
@@ -0,0 +1,92 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : SalomePyQt.h
+//  Module : SALOME
+
+#ifndef _SALOME_PYQT_H
+#define _SALOME_PYQT_H
+
+#include <qwidget.h>
+#include <qworkspace.h>
+#include <qstring.h>
+#include <qmenubar.h>
+
+class QAD_Study;
+class SALOME_Selection;
+class SalomePyQt_Selection : public QObject
+{
+  Q_OBJECT
+
+public:
+  ~SalomePyQt_Selection();
+  static SalomePyQt_Selection* GetSelection( QAD_Study* );
+
+  void Clear();
+  void ClearIObjects();
+  void ClearFilters();
+
+signals:
+  void currentSelectionChanged();
+
+private slots:
+  void onSelectionDestroyed();
+  void onSelectionModified();
+
+private:
+  QAD_Study*        myStudy;
+  SALOME_Selection* mySelection;
+  
+  SalomePyQt_Selection( QObject* );
+};
+
+enum MenuName {
+  File        = 1,
+  View        = 2,
+  Edit        = 3,
+  Preferences = 4,
+  Tools       = 5,
+  Window      = 6,
+  Help        = 7  
+};
+
+class SalomePyQt
+{
+public:
+  static QWidget*              getDesktop();
+  static QWorkspace*           getMainFrame();
+  static QMenuBar*             getMainMenuBar();
+  static QPopupMenu*           getPopupMenu( const MenuName menu );
+  static SalomePyQt_Selection* getSelection();
+  static int                   getStudyId();
+  static void                  putInfo( const QString& );
+  static void                  putInfo( const QString&, int );
+
+  static const QString&        getActiveComponent();
+
+  static void                  updateObjBrowser( int studyId, bool updateSelection);
+
+  static void                  addStringSetting(QString _name, QString _value, bool _autoValue);
+  static void                  addIntSetting(QString _name, int _value, bool _autoValue);
+  static void                  addDoubleSetting(QString _name, double _value, bool _autoValue);
+  static bool                  removeSettings(QString name);
+  static QString               getSetting(QString name);
+
+  static QString               getFileName(QWidget*           parent, 
+                                          const QString&     initial, 
+                                          const QStringList& filters, 
+                                          const QString&     caption,
+                                          bool               open);
+  static QStringList           getOpenFileNames(QWidget*           parent, 
+                                               const QString&     initial, 
+                                               const QStringList& filters, 
+                                               const QString&     caption);
+  static QString               getExistingDirectory(QWidget*       parent,
+                                                   const QString& initial,
+                                                   const QString& caption);
+  static void                  helpContext(const QString& source, const QString& context);
+  static bool                  dumpView(const QString& filename);
+};
+
+#endif
diff --git a/src/SALOME_PYQT/SalomePyQt.hxx b/src/SALOME_PYQT/SalomePyQt.hxx
deleted file mode 100644 (file)
index 91c369a..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-//  Copyright (C) 2003  CEA/DEN, EDF R&D
-//
-//
-//
-//  File   : SalomePyQt.hxx
-//  Module : SALOME
-
-#ifndef _SALOME_PYQT_H
-#define _SALOME_PYQT_H
-
-#include <SALOME_Selection.h>
-
-#include <qwidget.h>
-#include <qworkspace.h>
-#include <qstring.h>
-#include <qmenubar.h>
-
-enum MenuName {
-  File        = 1,
-  View        = 2,
-  Edit        = 3,
-  Preferences = 4,
-  Tools       = 5,
-  Window      = 6,
-  Help        = 7  
-};
-
-class SalomePyQt
-{
-public:
-  static QWidget*          getDesktop();
-  static QWorkspace*       getMainFrame();
-  static QMenuBar*         getMainMenuBar();
-  static QPopupMenu*       getPopupMenu( const MenuName menu );
-  static SALOME_Selection* getSelection();
-  static int               getStudyId();
-  static void              putInfo( const QString& );
-  static void              putInfo( const QString&, int );
-
-  static const QString&    getActiveComponent();
-
-  static void              updateObjBrowser( int studyId, bool updateSelection);
-
-  static void              addStringSetting(QString _name, QString _value, bool _autoValue);
-  static void              addIntSetting(QString _name, int _value, bool _autoValue);
-  static void              addDoubleSetting(QString _name, double _value, bool _autoValue);
-  static bool              removeSettings(QString name);
-  static QString           getSetting(QString name);
-
-  static QString           getFileName(QWidget*           parent, 
-                                       const QString&     initial, 
-                                       const QStringList& filters, 
-                                       const QString&     caption,
-                                       bool               open);
-  static QStringList       getOpenFileNames(QWidget*           parent, 
-                                            const QString&     initial, 
-                                            const QStringList& filters, 
-                                            const QString&     caption);
-  static QString           getExistingDirectory(QWidget*       parent,
-                                                const QString& initial,
-                                                const QString& caption);
-  static void              helpContext(const QString& source, const QString& context);
-  static bool              dumpView(const QString& filename);
-};
-
-#endif
index ebfac3e001f5b7a5e516328dd909419f490b7408..3a727bcf2c2bb9175344d3e0a7356d7ad98a0205 100644 (file)
@@ -3,18 +3,20 @@
 %Import qtmod.sip
 
 
-class SALOME_Selection : QObject
+class SalomePyQt_Selection : QObject
 {
 
 %HeaderCode
-#include <SALOME_Selection.h>
+#include <SalomePyQt.h>
 %End
 
-
 public:
-  SALOME_Selection(const QString &);
   void Clear();
   void ClearIObjects();
+  void ClearFilters();
+
+private:
+  SalomePyQt_Selection( QObject* /TransferThis/ );
 
 signals:
   void currentSelectionChanged();
@@ -34,33 +36,41 @@ class SalomePyQt
 {
 
 %HeaderCode
-#include <SalomePyQt.hxx>
+#include <SalomePyQt.h>
 %End
 
 public:
-  static QWidget*    getDesktop();
-  static QWorkspace* getMainFrame();
-  static QMenuBar*   getMainMenuBar();
-  static QPopupMenu* getPopupMenu( const MenuName );
-  static SALOME_Selection* getSelection();
-  static int getStudyId();
-  static void putInfo( const QString& );
-  static void putInfo( const QString&, int );
-
-  static const QString& getActiveComponent();
-
-  static void updateObjBrowser( int, bool );
-
-
-  static bool removeSettings(QString);
-  static QString getSetting(QString);
-  static void addStringSetting(QString, QString, bool);
-  static void addIntSetting(QString, int, bool);
-  static void addDoubleSetting(QString, double, bool);
-
-  static QString getFileName(QWidget*, const QString&, const QStringList&, const QString&, bool);
-  static QStringList getOpenFileNames(QWidget*, const QString&, const QStringList&, const QString&);
-  static QString getExistingDirectory(QWidget*, const QString&, const QString&);
-  static void helpContext(const QString&, const QString&);
-  static bool dumpView(const QString&);
+  static QWidget*              getDesktop();
+  static QWorkspace*           getMainFrame();
+  static QMenuBar*             getMainMenuBar();
+  static QPopupMenu*           getPopupMenu( const MenuName );
+  static SalomePyQt_Selection* getSelection() /Factory/;
+  static int                   getStudyId();
+  static void                  putInfo( const QString& );
+  static void                  putInfo( const QString&, int );
+
+  static const QString&        getActiveComponent();
+
+  static void                  updateObjBrowser( int, bool );
+
+
+  static bool                  removeSettings(QString);
+  static QString               getSetting(QString);
+  static void                  addStringSetting(QString, QString, bool);
+  static void                  addIntSetting(QString, int, bool);
+  static void                  addDoubleSetting(QString, double, bool);
+
+  static QString               getFileName(QWidget*, 
+                                           const QString&,
+                                           const QStringList&,
+                                           const QString&, bool) /ReleaseGIL/;
+  static QStringList           getOpenFileNames(QWidget*, 
+                                                const QString&,
+                                                const QStringList&,
+                                                const QString&) /ReleaseGIL/;
+  static QString               getExistingDirectory(QWidget*, 
+                                                    const QString&, 
+                                                    const QString&) /ReleaseGIL/;
+  static void                  helpContext(const QString&, const QString&);
+  static bool                  dumpView(const QString&);
 };
index 69bbcfd135c8ef8e365cbb1d767152655aea7167..d747b2d54a67a4f1d65e820003af403340bab222 100644 (file)
@@ -2,16 +2,20 @@
 
 %Import qtmod.sip
 
-class SALOME_Selection : QObject
+
+class SalomePyQt_Selection : QObject
 {
 %TypeHeaderCode
-#include <SALOME_Selection.h>
+#include <SalomePyQt.h>
 %End
 
 public:
-  SALOME_Selection(const QString &);
   void Clear();
   void ClearIObjects();
+  void ClearFilters();
+
+private:
+  SalomePyQt_Selection( QObject* /TransferThis/ );
 
 signals:
   void currentSelectionChanged();
@@ -30,33 +34,41 @@ enum MenuName {
 class SalomePyQt
 {
 %TypeHeaderCode
-#include <SalomePyQt.hxx>
+#include <SalomePyQt.h>
 %End
 
 public:
-  static QWidget*    getDesktop();
-  static QWorkspace* getMainFrame();
-  static QMenuBar*   getMainMenuBar();
-  static QPopupMenu* getPopupMenu( const MenuName );
-  static SALOME_Selection* getSelection();
-  static int getStudyId();
-  static void putInfo( const QString& );
-  static void putInfo( const QString&, int );
-
-  static const QString& getActiveComponent();
-
-  static void updateObjBrowser( int, bool );
-
-
-  static bool removeSettings(QString);
-  static QString getSetting(QString);
-  static void addStringSetting(QString, QString, bool);
-  static void addIntSetting(QString, int, bool);
-  static void addDoubleSetting(QString, double, bool);
-
-  static QString getFileName(QWidget*, const QString&, const QStringList&, const QString&, bool);
-  static QStringList getOpenFileNames(QWidget*, const QString&, const QStringList&, const QString&);
-  static QString getExistingDirectory(QWidget*, const QString&, const QString&);
-  static void helpContext(const QString&, const QString&);
-  static bool dumpView(const QString&);
+  static QWidget*              getDesktop();
+  static QWorkspace*           getMainFrame();
+  static QMenuBar*             getMainMenuBar();
+  static QPopupMenu*           getPopupMenu( const MenuName );
+  static SalomePyQt_Selection* getSelection() /Factory/;
+  static int                   getStudyId();
+  static void                  putInfo( const QString& );
+  static void                  putInfo( const QString&, int );
+
+  static const QString&        getActiveComponent();
+
+  static void                  updateObjBrowser( int, bool );
+
+
+  static bool                  removeSettings(QString);
+  static QString               getSetting(QString);
+  static void                  addStringSetting(QString, QString, bool);
+  static void                  addIntSetting(QString, int, bool);
+  static void                  addDoubleSetting(QString, double, bool);
+
+  static QString               getFileName(QWidget*, 
+                                           const QString&,
+                                           const QStringList&,
+                                           const QString&, bool) /ReleaseGIL/;
+  static QStringList           getOpenFileNames(QWidget*, 
+                                                const QString&,
+                                                const QStringList&,
+                                                const QString&) /ReleaseGIL/;
+  static QString               getExistingDirectory(QWidget*, 
+                                                    const QString&, 
+                                                    const QString&) /ReleaseGIL/;
+  static void                  helpContext(const QString&, const QString&);
+  static bool                  dumpView(const QString&);
 };