From 54abcd61cd514333fdd304402194fe83bcaec017 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Sat, 25 Feb 2017 12:53:50 +0100 Subject: [PATCH] selection from PyQt first step OK --- src/LightApp/LightApp_Application.cxx | 3 + .../SALOME_PYQT_ModuleLight.cxx | 6 +- .../SALOME_PYQT_ModuleLight.h | 3 +- .../SALOME_PYQT_PyModule.cxx | 74 +++++++++++++++++++ .../SALOME_PYQT_PyModule.h | 2 + .../SALOME_PYQT_Selector.cxx | 32 ++++---- 6 files changed, 100 insertions(+), 20 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index c998c9f13..0b8cc6431 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -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") } /*! diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx index a0f8a41ba..4cebc3a46 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -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(); } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h index c4349532f..02fd4ae3a 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h @@ -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; diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx index 2d9e74550..a344757d4 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx @@ -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( 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 diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h index f8e012159..e25fc9ab0 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h @@ -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* ); diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx index c87a62a02..6d115dc73 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx @@ -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((*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((*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& entr if (!myPyModule) return; - for (SUIT_DataObjectIterator it(myPyModule->root(), SUIT_DataObjectIterator::DepthLeft); it.current(); ++it) - { - LightApp_DataObject* obj = dynamic_cast(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(it.current()); +// if (obj) +// entries.insert(obj->entry(), obj); +// } setModified(); } -- 2.39.2