Salome HOME
selection from pyqt: first development
authorPaul RASCLE <paul.rascle@edf.fr>
Thu, 23 Feb 2017 14:02:22 +0000 (15:02 +0100)
committerPaul RASCLE <paul.rascle@edf.fr>
Thu, 23 Feb 2017 14:02:22 +0000 (15:02 +0100)
src/SALOME_PYQT/SALOME_PYQT_GUILight/CMakeLists.txt
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.cxx [new file with mode: 0644]
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_BorrowedDataObjectLight.h [new file with mode: 0644]
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_Selector.cxx [new file with mode: 0644]
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_Selector.h [new file with mode: 0644]
src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx
src/SALOME_PYQT/SalomePyQt/SalomePyQt.h
src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip

index 5c452c83f8c84aa9746d4fd650ae5a4e2b7425da..589e537e1ab5e09b05d2ad2935f580f9a3b962eb 100755 (executable)
@@ -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 (file)
index 0000000..cdb758b
--- /dev/null
@@ -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 <LightApp_Application.h>
+#include <SUIT_Session.h>
+#include <utilities.h>
+#include <SUIT_ResourceMgr.h>
+
+
+#include <CAM_DataModel.h>
+#include <CAM_Module.h>
+
+
+/*!
+ *  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<LightApp_Application*>( 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 (file)
index 0000000..344818e
--- /dev/null
@@ -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 <LightApp_DataObject.h>
+#include <LightApp_Study.h>
+
+#include <qstring.h>
+
+/*!
+ * 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
index c1791289b815627573db8e0cf0c14ea3718587ef..a0f8a41bad11492206b70a418c338906a51dfd13 100644 (file)
 #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 <QCoreApplication>
+#include <utilities.h>
 
 // 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();
+}
+
index b0c9dd6e35d1f1c8ab9d8d2ac32c7e23e37391e1..c4349532ff78f7b75200c0be7ad4424e4cc286d6 100644 (file)
@@ -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 (file)
index 0000000..c87a62a
--- /dev/null
@@ -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 <SUIT_Session.h>
+#include <SUIT_DataObjectIterator.h>
+#include <QTime>
+#include <time.h>
+
+#include <utilities.h>
+
+/*!
+ \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<const LightApp_DataOwner*>((*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<QString, LightApp_DataObject*>& 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<LightApp_DataObject*>(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 (file)
index 0000000..a6ffc6a
--- /dev/null
@@ -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 <SUIT_Selector.h>
+#include <SUIT_DataOwner.h>
+
+#include <QObject>
+
+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<QString, LightApp_DataObject*>& );
+
+private:
+  QStringList                         myLocalEntries;
+  SALOME_PYQT_ModuleLight*            myPyModule;
+  SUIT_DataOwnerPtrList               mySelectedList;
+  QMap<QString, LightApp_DataObject*> myEntries;
+  unsigned long                       myModifiedTime;
+};
+
+#endif
index 53776e2647da7df232d0ee5c54489fbac5026d4d..6e73d1c6532903f807483c38302af05ae00d35b5 100644 (file)
@@ -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<SALOME_PYQT_ModuleLight*>( 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 
index 4953dbe7ef7e601f187611e126b8d9ad3d82ac91..a5413019fabced06b83ed60e98ce0866aebfa9dc 100644 (file)
@@ -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();
index 492050d3d5baf586ca496000a77037a599ee4bc7..a01c11840039498faeac65312de6d38996c640c9 100644 (file)
@@ -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/ ;