Salome HOME
selection from PyQt first step OK
authorPaul RASCLE <paul.rascle@edf.fr>
Sat, 25 Feb 2017 11:53:50 +0000 (12:53 +0100)
committerPaul RASCLE <paul.rascle@edf.fr>
Sat, 25 Feb 2017 11:53:50 +0000 (12:53 +0100)
src/LightApp/LightApp_Application.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx

index c998c9f1344ff775c72f9118bbffb7ec02e2d94e..0b8cc6431b8c61ca617483f2f7616d3f2cc6935d 100644 (file)
@@ -1007,10 +1007,13 @@ void LightApp_Application::onHelpAbout()
 */
 void LightApp_Application::onSelection()
 {
+  MESSAGE("onSelection_1")
   onSelectionChanged();
+  MESSAGE("onSelection_2")
 
   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
     ((LightApp_Module*)activeModule())->selectionChanged();
+  MESSAGE("onSelection_3")
 }
 
 /*!
index a0f8a41bad11492206b70a418c338906a51dfd13..4cebc3a46578eb620dbbb3dba1ba055758c0912c 100644 (file)
@@ -624,10 +624,10 @@ SUIT_DataObject* SALOME_PYQT_ModuleLight::root() const
 }
 
 
-void SALOME_PYQT_ModuleLight::setSelected( const DataObjectList&, const bool)
+void SALOME_PYQT_ModuleLight::setSelected( const QStringList& entries, const bool isUnused)
 {
   MESSAGE("setSelected");
-
+  return myHelper->selectionUpdated(entries);
 }
 
 
@@ -644,6 +644,6 @@ void SALOME_PYQT_ModuleLight::setLocalSelected(const QStringList & entries)
        mySelector = new SALOME_PYQT_Selector(this, this->getApp()->selectionMgr());
     }
   mySelector->setLocalEntries(entries);
-  emit selectionChanged();
+  emit localSelectionChanged();
 }
 
index c4349532ff78f7b75200c0be7ad4424e4cc286d6..02fd4ae3a09f96c3c515860a49aeff396db1b450 100644 (file)
@@ -102,7 +102,7 @@ public:
   void             getSelected( DataObjectList& ) const;
   unsigned long    getModifiedTime() const;
   SUIT_DataObject* root() const;
-  void             setSelected( const DataObjectList&, const bool = false );
+  void             setSelected( const QStringList&, const bool = false );
 
 protected:
   CAM_DataModel*  createDataModel();
@@ -113,6 +113,7 @@ private:
 
 signals:
   void            selectionChanged();
+  void            localSelectionChanged();
 
 private:
   PyModuleHelper* myHelper;
index 2d9e7455058a81430fc58110460abb679ebd172c..a344757d4766bf2ce8871127fa4c2aee11d3b98f 100644 (file)
@@ -1162,6 +1162,45 @@ void PyModuleHelper::actionActivated()
   PyInterp_Dispatcher::Get()->Exec( new ActionReq( myInterp, this, myModule->actionId( action ) ) );
 }
 
+/*!
+  \brief update selection from other views or modules.
+
+  Called when selection is modified outside.
+*/
+void PyModuleHelper::selectionUpdated(const QStringList& entries)
+{
+  FuncMsg fmsg( "PyModuleHelper::selectionUpdated()" );
+
+  // perform synchronous request to Python event dispatcher
+  class SelectionReq : public PyInterp_LockRequest
+  {
+  public:
+    SelectionReq( PyInterp_Interp* _py_interp,
+                  PyModuleHelper*  _helper,
+                  const QStringList& _entries )
+      : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
+        myHelper( _helper ),
+        myEntries( _entries  )
+    {}
+  protected:
+    virtual void execute()
+    {
+      myHelper->internalSelectionUpdated( myEntries );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    const QStringList& myEntries;
+  };
+
+  // get sender action
+  QAction* action = qobject_cast<QAction*>( sender() );
+  if ( !action )
+    return;
+
+  // post request
+  PyInterp_Dispatcher::Get()->Exec( new SelectionReq( myInterp, this, entries ) );
+}
+
 /*!
   \brief Process context popup menu request.
   
@@ -2220,6 +2259,41 @@ void PyModuleHelper::internalActionActivated( int id )
   }
 }
 
+/*!
+  \brief update selection from other views or modules
+  \internal
+
+  Performs the following actions:
+  - calls Python module's onSelectionpdated(entries) method
+
+  \param list of entries
+*/
+void PyModuleHelper::internalSelectionUpdated(const QStringList& entries)
+{
+  FuncMsg fmsg("--- PyModuleHelper::internalSelectionUpdated()");
+
+  // Python interpreter should be initialized and Python module should be imported first
+  if (!myInterp || !myPyModule)
+    return; // Error
+
+  QStringList* theList = new QStringList(entries);
+
+#if SIP_VERSION < 0x040800
+  PyObjWrapper sipList(sipBuildResult(0, "M", theList, sipClass_QStringList));
+#else
+  PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
+#endif
+  if (PyObject_HasAttrString(myPyModule, (char*) "onSelectionUpdated"))
+    {
+      PyObjWrapper res(PyObject_CallMethod(myPyModule, (char*) "onSelectionUpdated", (char*) "O", sipList.get()));
+
+      if (!res)
+        {
+          PyErr_Print();
+        }
+    }
+}
+
 /*!
   \brief Context popup menu handling callback function
   \internal
index f8e0121590770650c2f8ad6a961a5c05544990a2..e25fc9ab00a61f9445a7978a52568e5f53bf995b 100644 (file)
@@ -91,6 +91,7 @@ public slots:
   void                       preferenceChanged( const QString&, const QString&, const QString& setting );
   void                       studyActivated( SUIT_Study* );
   void                       actionActivated();
+  void                       selectionUpdated(const QStringList&);
   void                       contextMenu( const QString&, QMenu* );
   void                       createPreferences();
   void                       activeViewChanged( SUIT_ViewWindow* );
@@ -121,6 +122,7 @@ private:
   void                       internalPreferencesChanged( const QString&, const QString& );
   void                       internalStudyChanged( SUIT_Study* );
   void                       internalActionActivated( int );
+  void                       internalSelectionUpdated(const QStringList&);
   void                       internalContextMenu( const QString&, QMenu* );
   void                       internalCreatePreferences();
   void                       internalActiveViewChanged( SUIT_ViewWindow* );
index c87a62a02b9f70e2eff482c90c1894dea95396e9..6d115dc73b4a718e839102cc11ba372bb246be23 100644 (file)
@@ -53,7 +53,7 @@ SALOME_PYQT_Selector::SALOME_PYQT_Selector(SALOME_PYQT_ModuleLight* pymod, SUIT_
   MESSAGE("constructor");
   if (myPyModule)
     {
-      connect(myPyModule, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+      connect(myPyModule, SIGNAL(localSelectionChanged()), this, SLOT(onSelectionChanged()));
     }
   setModified();
 }
@@ -159,15 +159,15 @@ void SALOME_PYQT_Selector::setSelection(const SUIT_DataOwnerPtrList& theList)
   if (myEntries.count() == 0 || myModifiedTime < myPyModule->getModifiedTime())
     fillEntries(myEntries);
 
-  DataObjectList objList;
-  for (SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it)
-    {
-      const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>((*it).operator->());
-      if (owner && myEntries.contains(owner->entry()))
-        objList.append(myEntries[owner->entry()]);
-    }
-
-  myPyModule->setSelected(objList);
+//  DataObjectList objList;
+//  for (SUIT_DataOwnerPtrList::const_iterator it = theList.begin(); it != theList.end(); ++it)
+//    {
+//      const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>((*it).operator->());
+//      if (owner && myEntries.contains(owner->entry()))
+//        objList.append(myEntries[owner->entry()]);
+//    }
+//
+//  myPyModule->setSelected(objList);
   mySelectedList.clear();
 }
 
@@ -183,12 +183,12 @@ void SALOME_PYQT_Selector::fillEntries(QMap<QString, LightApp_DataObject*>& entr
   if (!myPyModule)
     return;
 
-  for (SUIT_DataObjectIterator it(myPyModule->root(), SUIT_DataObjectIterator::DepthLeft); it.current(); ++it)
-    {
-      LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(it.current());
-      if (obj)
-        entries.insert(obj->entry(), obj);
-    }
+//  for (SUIT_DataObjectIterator it(myPyModule->root(), SUIT_DataObjectIterator::DepthLeft); it.current(); ++it)
+//    {
+//      LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(it.current());
+//      if (obj)
+//        entries.insert(obj->entry(), obj);
+//    }
 
   setModified();
 }