From 4788d6df9fc9bf47d35a8e38ec57983b19ce5d65 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Thu, 23 Feb 2017 15:02:22 +0100 Subject: [PATCH] selection from pyqt: first development --- .../SALOME_PYQT_GUILight/CMakeLists.txt | 7 + .../SALOME_PYQT_BorrowedDataObjectLight.cxx | 174 ++++++++++++++++ .../SALOME_PYQT_BorrowedDataObjectLight.h | 69 +++++++ .../SALOME_PYQT_ModuleLight.cxx | 48 ++++- .../SALOME_PYQT_ModuleLight.h | 11 + .../SALOME_PYQT_Selector.cxx | 195 ++++++++++++++++++ .../SALOME_PYQT_Selector.h | 76 +++++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 26 +++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 1 + src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 1 + 10 files changed, 607 insertions(+), 1 deletion(-) create mode 100644 src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.cxx create mode 100644 src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.h create mode 100644 src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx create mode 100644 src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt b/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt index 5c452c83f..589e537e1 100755 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt @@ -47,6 +47,9 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/tools/PyConsole/src ${PROJECT_SOURCE_DIR}/tools/PyInterp/src ) +IF(SALOME_USE_SALOMEOBJECT) + INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/OBJECT) +ENDIF() # additional preprocessor / compiler flags ADD_DEFINITIONS( @@ -73,11 +76,13 @@ SET(_moc_HEADERS SALOME_PYQT_DataModelLight.h SALOME_PYQT_ModuleLight.h SALOME_PYQT_PyModule.h + SALOME_PYQT_Selector.h ) # header files / no moc processing SET(_other_HEADERS SALOME_PYQT_DataObjectLight.h + SALOME_PYQT_BorrowedDataObjectLight.h SALOME_PYQT_GUILight.h SALOME_PYQT_PyInterp.h ) @@ -102,9 +107,11 @@ PYQT_WRAP_SIP(_sip_SOURCES ${_sip_files}) SET(_other_SOURCES SALOME_PYQT_DataModelLight.cxx SALOME_PYQT_DataObjectLight.cxx + SALOME_PYQT_BorrowedDataObjectLight.cxx SALOME_PYQT_ModuleLight.cxx SALOME_PYQT_PyInterp.cxx SALOME_PYQT_PyModule.cxx + SALOME_PYQT_Selector.cxx ) # sources / to compile diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.cxx new file mode 100644 index 000000000..cdb758ba0 --- /dev/null +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.cxx @@ -0,0 +1,174 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) +// Date : 22/06/2007 +// +#include "SALOME_PYQT_BorrowedDataObjectLight.h" +#include +#include +#include +#include + + +#include +#include + + +/*! + * Class: SALOME_PYQT_BorrowedDataObjectLight + * Description: LIGHT PYTHON module's Borrowed data object: reference objects from other modules + */ + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight() +// purpose : constructor +//================================================================================= +SALOME_PYQT_BorrowedDataObjectLight::SALOME_PYQT_BorrowedDataObjectLight ( QString entry ) + : CAM_DataObject(0), + LightApp_DataObject( 0 ) + +{ + myEntry = entry; +} + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight() +// purpose : destructor +//================================================================================= +SALOME_PYQT_BorrowedDataObjectLight::~SALOME_PYQT_BorrowedDataObjectLight() +{ + +} + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight::entry() +// purpose : return entry of object +//================================================================================= +QString SALOME_PYQT_BorrowedDataObjectLight::entry() const +{ + return myEntry; +} + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight::refEntry() +// purpose : return entry of the data object referenced by this one (if any) +//================================================================================= +QString SALOME_PYQT_BorrowedDataObjectLight::refEntry() const +{ + return myRefEntry; +} + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight::setRefEntry() +// purpose : sets entry of the data object referenced by this one +//================================================================================= +void SALOME_PYQT_BorrowedDataObjectLight::setRefEntry( const QString& refEntry ) +{ + myRefEntry = refEntry; +} + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight::name() +// purpose : return name of object +//================================================================================= +QString SALOME_PYQT_BorrowedDataObjectLight::name() const +{ + return myName; +} + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight::icon() +// purpose : return icon of object +//================================================================================= +QPixmap SALOME_PYQT_BorrowedDataObjectLight::icon(const int index) const +{ + if(index == NameId) + return myIcon; + else + return LightApp_DataObject::icon( index ); +} + + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight::toolTip() +// purpose : return toolTip of object +//================================================================================= +QString SALOME_PYQT_BorrowedDataObjectLight::toolTip(const int index) const +{ + return myToolTip; +} + +//================================================================================= +// function : SALOME_PYQT_BorrowedDataObjectLight::toolTip() +// purpose : return toolTip of object +//================================================================================= +QColor SALOME_PYQT_BorrowedDataObjectLight::color( const ColorRole role, const int id ) const +{ + QColor c; + + switch ( role ) + { + case Text: + case Foreground: + if ( !isReference() ) + c = myColor; + break; + + default: + break; + } + + // Issue 21379: LightApp_DataObject::color() defines colors for valid references + if ( !c.isValid() ) + c = LightApp_DataObject::color( role, id ); + + return c; +} + +bool SALOME_PYQT_BorrowedDataObjectLight::setName(const QString& name) +{ + myName = name; + return true; +} + +void SALOME_PYQT_BorrowedDataObjectLight::setIcon(const QString& iconname) +{ + if(!iconname.isEmpty()) { + LightApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if(anApp) { + QString modulename = anApp->activeModule()->name(); + if(!modulename.isEmpty()) + { + myIcon = SUIT_Session::session()->resourceMgr()->loadPixmap(modulename, + QObject::tr(iconname.toLatin1())); + } + } + } +} + +void SALOME_PYQT_BorrowedDataObjectLight::setToolTip(const QString& tooltip) +{ + myToolTip = tooltip; +} + +void SALOME_PYQT_BorrowedDataObjectLight::setColor(const QColor& color) +{ + myColor = color; +} diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.h new file mode 100644 index 000000000..344818eb6 --- /dev/null +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.h @@ -0,0 +1,69 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) +// Date : 22/06/2007 +// +#ifndef SALOME_PYQT_BORROWEDDATAOBJECTLIGHT_H +#define SALOME_PYQT_BORROWEDDATAOBJECTLIGHT_H + + +#include "SALOME_PYQT_GUILight.h" +#include +#include + +#include + +/*! + * SALOME_PYQT_BorrowedDataObjectLight - PYTHON LIGHT module's data object class + */ +class SALOME_PYQT_LIGHT_EXPORT SALOME_PYQT_BorrowedDataObjectLight : public virtual LightApp_DataObject +{ + + public: + SALOME_PYQT_BorrowedDataObjectLight( QString entry ); + + virtual ~SALOME_PYQT_BorrowedDataObjectLight(); + + virtual QString entry() const; + + virtual QString refEntry() const; + void setRefEntry( const QString& refEntry ); + + virtual QString name() const; + virtual QPixmap icon(const int = NameId) const; + virtual QString toolTip(const int = NameId) const; + + bool setName(const QString& name); + void setIcon(const QString& icon); + void setToolTip(const QString& tooltip); + + virtual QColor color( const ColorRole, const int = NameId ) const; + void setColor(const QColor& color); + + private: + QString myEntry; + QString myRefEntry; + QString myName; + QString myToolTip; + QPixmap myIcon; + QColor myColor; +}; + +#endif // SALOME_PYQT_BORROWEDDATAOBJECTLIGHT_H 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 c1791289b..a0f8a41ba 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx @@ -23,11 +23,13 @@ #include "SALOME_PYQT_DataModelLight.h" #include "SALOME_PYQT_ModuleLight.h" #include "SALOME_PYQT_PyModule.h" +#include "SALOME_PYQT_Selector.h" #include "CAM_Application.h" #include "SUITApp_init_python.hxx" #include "SUIT_DataObjectIterator.h" #include "LightApp_Application.h" +#include "LightApp_SelectionMgr.h" #include "SUIT_DataBrowser.h" #include "sipAPISalomePyQtGUILight.h" @@ -36,6 +38,7 @@ #endif #include +#include // Py_ssize_t for old Pythons // This code is as recommended by" @@ -106,7 +109,7 @@ extern "C" \brief Constructor */ SALOME_PYQT_ModuleLight::SALOME_PYQT_ModuleLight() - : LightApp_Module( "noname" ) // name is set explicitly at the module initialization + : LightApp_Module( "noname" ), mySelector(0) // name is set explicitly at the module initialization { // initialize helper myHelper = new PyModuleHelper( this ); @@ -601,3 +604,46 @@ SALOME_PYQT_DataObjectLight* SALOME_PYQT_ModuleLight::findObject( const QString& } return obj; } + +void SALOME_PYQT_ModuleLight::getSelected( DataObjectList& ) const +{ + MESSAGE("getSelected"); +} + +unsigned long SALOME_PYQT_ModuleLight::getModifiedTime() const +{ + MESSAGE("getModifiedTime"); + +} + + +SUIT_DataObject* SALOME_PYQT_ModuleLight::root() const +{ + MESSAGE("root"); + +} + + +void SALOME_PYQT_ModuleLight::setSelected( const DataObjectList&, const bool) +{ + MESSAGE("setSelected"); + +} + + +//void SALOME_PYQT_ModuleLight::selectionChanged() +//{ +// MESSAGE("signal selectionChanged"); +//} + +void SALOME_PYQT_ModuleLight::setLocalSelected(const QStringList & entries) +{ + MESSAGE("setLocalSelected"); + if (!mySelector) + { + mySelector = new SALOME_PYQT_Selector(this, this->getApp()->selectionMgr()); + } + mySelector->setLocalEntries(entries); + emit selectionChanged(); +} + 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 b0c9dd6e3..c4349532f 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h @@ -34,6 +34,7 @@ class QMenu; class PyModuleHelper; +class SALOME_PYQT_Selector; class SALOME_PYQT_DataObjectLight; class SALOME_PYQT_LIGHT_EXPORT SALOME_PYQT_ModuleLight: public LightApp_Module @@ -97,6 +98,12 @@ public: QStringList getChildren( const QString&, const bool = false ) const; + void setLocalSelected(const QStringList &); + void getSelected( DataObjectList& ) const; + unsigned long getModifiedTime() const; + SUIT_DataObject* root() const; + void setSelected( const DataObjectList&, const bool = false ); + protected: CAM_DataModel* createDataModel(); @@ -104,8 +111,12 @@ private: SALOME_PYQT_DataObjectLight* findObject( const QString& ) const; +signals: + void selectionChanged(); + private: PyModuleHelper* myHelper; + SALOME_PYQT_Selector* mySelector; }; #endif // SALOME_PYQT_MODULELIGHT_H diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx new file mode 100644 index 000000000..c87a62a02 --- /dev/null +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.cxx @@ -0,0 +1,195 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SALOME_PYQT_Selector.cxx +// Author : +// +#include "SALOME_PYQT_Selector.h" + +#include "LightApp_DataOwner.h" +#include "LightApp_DataObject.h" +#include "LightApp_Application.h" +#include "SALOME_PYQT_ModuleLight.h" +#include "SALOME_PYQT_BorrowedDataObjectLight.h" +#include +#include +#include +#include + +#include + +/*! + \class SALOME_PYQT_Selector + \brief Object browser selection handler class. + */ + +/*! + \brief Constructor. + \param pymod Python module interface instance in charge of calling Python module methods from C++ + \param mgr selection manager + */ +SALOME_PYQT_Selector::SALOME_PYQT_Selector(SALOME_PYQT_ModuleLight* pymod, SUIT_SelectionMgr* mgr) : + SUIT_Selector(mgr, pymod), myPyModule(pymod) +{ + MESSAGE("constructor"); + if (myPyModule) + { + connect(myPyModule, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + } + setModified(); +} + +/*! + \brief Destructor. + */ +SALOME_PYQT_Selector::~SALOME_PYQT_Selector() +{ + MESSAGE("destructor"); +} + +/*! + \brief Get Python module interface instance. + \return a pointer to the Python module interface instance. + */ +SALOME_PYQT_ModuleLight* SALOME_PYQT_Selector::pyModule() const +{ + MESSAGE("pyModule"); + return myPyModule; +} + +/*! + \brief Get selector type. + \return selector type + */ +QString SALOME_PYQT_Selector::type() const +{ + MESSAGE("type"); + return "PYQT_Module"; +} + +/*! + \brief Get the time of the last selection changing. + \return latest selection changing time + */ +unsigned long SALOME_PYQT_Selector::getModifiedTime() const +{ + MESSAGE("getModifiedTime"); + return myModifiedTime; +} + +/*! + \brief Update the time of the latest selection changing. + */ +void SALOME_PYQT_Selector::setModified() +{ + MESSAGE("setModified"); + myModifiedTime = clock(); +} + +/*! + \brief Called when the Object browser selection is changed. + */ +void SALOME_PYQT_Selector::onSelectionChanged() +{ + MESSAGE("onSelectionChanged"); + QTime t1 = QTime::currentTime(); + mySelectedList.clear(); + selectionChanged(); + QTime t2 = QTime::currentTime(); + qDebug( QString( "selection time = %1 msecs" ).arg( t1.msecsTo( t2 ) ).toLatin1().constData()); +} + +/*! + \brief Get list of currently selected objects. + \param theList list to be filled with the selected objects owners + */ +void SALOME_PYQT_Selector::getSelection(SUIT_DataOwnerPtrList& theList) const +{ + MESSAGE("getSelection"); + if (mySelectedList.count() == 0) + { + SALOME_PYQT_Selector* that = (SALOME_PYQT_Selector*) this; // because of const... + for (int i = 0; i < myLocalEntries.size(); i++) + { + SALOME_PYQT_BorrowedDataObjectLight *obj = new SALOME_PYQT_BorrowedDataObjectLight(myLocalEntries[i]); +#ifndef DISABLE_SALOMEOBJECT + Handle(SALOME_InteractiveObject)aSObj = new SALOME_InteractiveObject + ( obj->entry().toLatin1().constData(), + obj->componentDataType().toLatin1().constData(), + obj->name().toLatin1().constData() ); + LightApp_DataOwner* owner = new LightApp_DataOwner(aSObj); +#else + LightApp_DataOwner* owner = new LightApp_DataOwner( obj->entry() ); +#endif + that->mySelectedList.append(SUIT_DataOwnerPtr(owner)); + } + } + theList = mySelectedList; +} + +/*! + \brief Set selection. + \param theList list of the object owners to be set selected + */ +void SALOME_PYQT_Selector::setSelection(const SUIT_DataOwnerPtrList& theList) +{ + MESSAGE("setSelection"); + if (!myPyModule) + return; + + 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); + mySelectedList.clear(); +} + +/*! + \brief Fill map of the data objects currently shown in the Object Browser. + \param entries map to be filled + */ +void SALOME_PYQT_Selector::fillEntries(QMap& entries) +{ + MESSAGE("fillEntries"); + entries.clear(); + + 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); + } + + setModified(); +} + diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h new file mode 100644 index 000000000..a6ffc6aa1 --- /dev/null +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h @@ -0,0 +1,76 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SALOME_PYQT_Selector.h +// Author : +// +#ifndef SALOME_PYQT_SELECTOR_H +#define SALOME_PYQT_SELECTOR_H + +#include "SALOME_PYQT_GUILight.h" +#include "PyInterp_Interp.h" // !!! WARNING !!! THIS INCLUDE MUST BE THE VERY FIRST !!! + +#include "LightApp.h" + +#include +#include + +#include + +class SALOME_PYQT_ModuleLight; +class LightApp_DataObject; + +class SALOME_PYQT_LIGHT_EXPORT SALOME_PYQT_Selector : public QObject, public SUIT_Selector +{ + Q_OBJECT + +public: + SALOME_PYQT_Selector( SALOME_PYQT_ModuleLight*, SUIT_SelectionMgr* ); + virtual ~SALOME_PYQT_Selector(); + + SALOME_PYQT_ModuleLight* pyModule() const; + + virtual QString type() const; + + unsigned long getModifiedTime() const; + void setModified(); + void setLocalEntries(const QStringList& entries) { myLocalEntries = entries; }; + +private slots: + void onSelectionChanged(); + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& ); + +private: + void fillEntries( QMap& ); + +private: + QStringList myLocalEntries; + SALOME_PYQT_ModuleLight* myPyModule; + SUIT_DataOwnerPtrList mySelectedList; + QMap myEntries; + unsigned long myModifiedTime; +}; + +#endif diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 53776e264..6e73d1c65 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -244,6 +244,7 @@ SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app ) return sel; } + /*! \brief Constructor. \param p parent object @@ -560,6 +561,31 @@ SALOME_Selection* SalomePyQt::getSelection() return ProcessEvent( new TGetSelectionEvent() ); } +/*! + \fn QStringList* SalomePyQt::setSelection(const QStringList& ); + \brief Send local selection for notification. + + The list of locally selected objects (study entries) is sent for notification of + other listening entities (modules, viewers...). +*/ + +class TSetSelectionEvent: public SALOME_Event +{ + QStringList myEntryList; +public: + TSetSelectionEvent(const QStringList& entryList) : myEntryList(entryList) {} + virtual void Execute() + { + SALOME_PYQT_ModuleLight* module = dynamic_cast( getActiveModule() ); + if ( !module ) return; + module->setLocalSelected(myEntryList); + } +}; +void SalomePyQt::setSelection( const QStringList& entryList) +{ + return ProcessVoidEvent( new TSetSelectionEvent(entryList) ); +} + /*! \fn void SalomePyQt::putInfo( const QString& msg, const int sec ); \brief Put an information message to the current application's diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 4953dbe7e..a5413019f 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -169,6 +169,7 @@ public: static QMenu* getPopupMenu( const QString& ); static QTreeView* getObjectBrowser(); static SALOME_Selection* getSelection(); + static void setSelection( const QStringList& ); static int getStudyId(); static void putInfo( const QString&, const int = 0 ); static const QString getActiveComponent(); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 492050d3d..a01c11840 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -271,6 +271,7 @@ public: static QMenu* getPopupMenu( const QString& ) /ReleaseGIL/ ; static QTreeView* getObjectBrowser() /ReleaseGIL/ ; static SALOME_Selection* getSelection() /Factory,ReleaseGIL/ ; + static void setSelection( const QStringList& ) /ReleaseGIL/ ; static int getStudyId() /ReleaseGIL/ ; static void putInfo( const QString&, const int = 0 ) /ReleaseGIL/ ; static const QString getActiveComponent() /ReleaseGIL/ ; -- 2.39.2