]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Merge tag 'V8_3_0a2' into ngr/python3_dev
authorNicolas Geimer <nicolas.geimer@edf.fr>
Mon, 20 Mar 2017 17:19:04 +0000 (18:19 +0100)
committerNicolas Geimer <nicolas.geimer@edf.fr>
Mon, 20 Mar 2017 17:19:04 +0000 (18:19 +0100)
Version 8.3.0 alpha 2

19 files changed:
src/LightApp/LightApp_Application.cxx
src/LightApp/LightApp_VTKSelector.cxx
src/OCCViewer/OCCViewer_VService.cxx
src/OCCViewer/OCCViewer_ViewModel.cxx
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_PyModule.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.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
src/SUITApp/SUITApp.cxx
src/SalomeApp/SalomeApp_Study.cxx
src/Session/SALOME_Session_Server.cxx

index 07fe794f4befeaddaeac899434aa8c43d8af875e..b105560ba3304faa33aa51548da99897a29bae77 100644 (file)
@@ -1007,6 +1007,7 @@ void LightApp_Application::onHelpAbout()
 */
 void LightApp_Application::onSelection()
 {
+  //MESSAGE("onSelection")
   onSelectionChanged();
 
   if ( activeModule() && activeModule()->inherits( "LightApp_Module" ) )
@@ -1461,19 +1462,31 @@ SUIT_ViewManager* LightApp_Application::getViewManager( const QString& vmType, c
 {
   SUIT_ViewManager* aVM = viewManager( vmType );
   SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager();
-
+  MESSAGE("vmType: " << vmType.toStdString() << " aVM: " << aVM << " anActiveVM: " << anActiveVM );
   if ( anActiveVM && anActiveVM->getType() == vmType )
-    aVM = anActiveVM;
+    {
+      MESSAGE("aVM = anActiveVM");
+      aVM = anActiveVM;
+    }
 
   if ( aVM && create )
   {
     if ( !aVM->getActiveView() )
-      aVM->createView();
+      {
+        MESSAGE("aVM->createView()");
+        aVM->createView();
+      }
     else
-      desktop()->setActiveWindow( aVM->getActiveView() );
+      {
+        MESSAGE("desktop()->setActiveWindow: " << aVM->getActiveView());
+        desktop()->setActiveWindow( aVM->getActiveView() );
+      }
   }
   else if ( create )
-    aVM = createViewManager( vmType );
+    {
+      MESSAGE("aVM = createViewManager( vmType )");
+      aVM = createViewManager( vmType );
+    }
 
   return aVM;
 }
index 4bcbead86f2dbeda336e6070f08d78265a449a43..c5f81eecb1236625d3b74157b64c709ebfb34488 100644 (file)
@@ -41,7 +41,7 @@
   #include "SALOME_ListIO.hxx"
 #endif
 
-
+#include <utilities.h>
 
 #ifndef DISABLE_VTKVIEWER
 #ifndef DISABLE_SALOMEOBJECT
@@ -103,7 +103,7 @@ LightApp_SVTKDataOwner
     }
   }
   
-  return -1;
+  return ActorSelection; // workaround for embedded VTK viewer in a module : is it safe ?
 }
 
 /*!
@@ -228,6 +228,7 @@ LightApp_VTKSelector
           for(; anIter != theList.end(); ++anIter){
             const SUIT_DataOwner* aDataOwner = (*anIter).get();
             if(const LightApp_SVTKDataOwner* anOwner = dynamic_cast<const LightApp_SVTKDataOwner*>(aDataOwner)){
+              MESSAGE("aSelector->SetSelectionMode("<<anOwner->GetMode()<<");");
               aSelector->SetSelectionMode(anOwner->GetMode());
               Handle(SALOME_InteractiveObject) anIO = anOwner->IO();
 
index 1102899a50545a10ae050ba17f254b9cf6c75cc5..a9cd79fe79c69f26fcd4a61b7acbe1208d0627fd 100644 (file)
@@ -91,7 +91,7 @@ Handle(V3d_Viewer) OCCViewer_VService::CreateViewer( const Standard_ExtString na
 #endif
   }
 
-#if OCC_VERSION_LARGE > 0x07010000
+#if OCC_VERSION_LARGE > 0x07010001
   return new V3d_Viewer( aGraphicDriver, name, domain, viewSize, viewProjection,
                         Quantity_NOC_GRAY30, V3d_ZBUFFER, V3d_GOURAUD,
                         computedMode, defaultComputedMode );
index 1318d5fe6a1fee5e2e8e49ac3e9d6dc49665a10f..3285f015edb5c3f80f7d8009e1102150c7fe6fbb 100644 (file)
@@ -129,13 +129,15 @@ OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron)
 
   // init selector
   myAISContext = new AIS_InteractiveContext( myV3dViewer );
-#if OCC_VERSION_LARGE > 0x07000000
-    
+#if OCC_VERSION_LARGE > 0x07010100
+  myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_LocalSelected)->SetColor( Quantity_NOC_WHITE );
+  myAISContext->HighlightStyle(Prs3d_TypeOfHighlight_Selected)->SetColor( Quantity_NOC_WHITE );
+#elif OCC_VERSION_LARGE > 0x07000000
   const Handle(Graphic3d_HighlightStyle)& sStyle = myAISContext->SelectionStyle();
-  sStyle->SetColor( Quantity_NOC_WHITE ); 
-#else  
+  sStyle->SetColor( Quantity_NOC_WHITE );
+#else
   myAISContext->SelectionColor( Quantity_NOC_WHITE );
-#endif  
+#endif
   
   // display isoline on planar faces (box for ex.)
   myAISContext->IsoOnPlane( true );
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..fd5147e
--- /dev/null
@@ -0,0 +1,176 @@
+// 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.
+ *  Used to propagate selection in a light module client of other modules publishing objects in study.
+ *  (copied from SALOME_PYQT_DataObjectLight)
+ */
+
+//=================================================================================
+// 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..e0e8ebf
--- /dev/null
@@ -0,0 +1,72 @@
+// 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
+ * for objects created by other modules and referenced in a light module.
+ * Used to propagate selection in a light module client of other modules publishing objects in study.
+ * (copied from SALOME_PYQT_DataObjectLight)
+ */
+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 0e8a5804907345bdc6691ba057f2668aa2761b82..a72dd69cac63a186876dc3099efa41e6bf52e22e 100644 (file)
 #include "SALOME_PYQT_ModuleLight.h"
 #include "SALOME_PYQT_DataModelLight.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 );
@@ -177,6 +180,8 @@ void SALOME_PYQT_ModuleLight::onModelClosed()
 {
   // call helper
   myHelper->modelClosed(application()->activeStudy());
+  if (mySelector)
+    mySelector->clear();
   LightApp_Module::onModelClosed();
 }
 
@@ -601,3 +606,53 @@ SALOME_PYQT_DataObjectLight* SALOME_PYQT_ModuleLight::findObject( const QString&
   }
   return obj;
 }
+
+/*!
+  \brief not used yet
+*/
+void SALOME_PYQT_ModuleLight::getSelected( DataObjectList& ) const
+{
+  MESSAGE("getSelected");
+}
+
+/*!
+  \brief not used yet
+*/
+unsigned long SALOME_PYQT_ModuleLight::getModifiedTime() const
+{
+  MESSAGE("getModifiedTime");
+}
+
+/*!
+  \brief not used yet
+*/
+SUIT_DataObject* SALOME_PYQT_ModuleLight::root() const
+{
+  MESSAGE("root");
+}
+
+/*!
+  \brief Used to notify a Python light module of a modification of selection in study (propagation of a remote selection)
+  \param list of study entries
+*/
+void SALOME_PYQT_ModuleLight::setSelected( const QStringList& entries, const bool isUnused)
+{
+  MESSAGE("setSelected");
+  return myHelper->selectionUpdated(entries);
+}
+
+/*!
+  \brief called by Python module to notify a list of study entries locally selected (for selection propagation)
+  \param list of study entries
+*/
+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 localSelectionChanged();
+}
+
index b0c9dd6e35d1f1c8ab9d8d2ac32c7e23e37391e1..02fd4ae3a09f96c3c515860a49aeff396db1b450 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 QStringList&, const bool = false );
+
 protected:
   CAM_DataModel*  createDataModel();
 
@@ -104,8 +111,13 @@ private:
   SALOME_PYQT_DataObjectLight* 
                   findObject( const QString& ) const;
 
+signals:
+  void            selectionChanged();
+  void            localSelectionChanged();
+
 private:
   PyModuleHelper* myHelper;
+  SALOME_PYQT_Selector* mySelector;
 };
 
 #endif // SALOME_PYQT_MODULELIGHT_H
index d1ee2dab48c7909021fb4d22e647e4b5220b0b90..459839a9b74c549636310023d832868e505a5644 100644 (file)
@@ -1162,6 +1162,44 @@ 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()" );
+  MESSAGE("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  )
+    {
+      MESSAGE("SelectionReq");
+    }
+  protected:
+    virtual void execute()
+    {
+      MESSAGE("execute");
+      myHelper->internalSelectionUpdated( myEntries );
+    }
+  private:
+    PyModuleHelper* myHelper;
+    const QStringList& myEntries;
+  };
+
+  // post request
+  PyInterp_Dispatcher::Get()->Exec( new SelectionReq( myInterp, this, entries ) );
+}
+
 /*!
   \brief Process context popup menu request.
   
@@ -2220,6 +2258,43 @@ 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()");
+  MESSAGE("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"))
+    {
+      MESSAGE("call 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* );
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..84e6e64
--- /dev/null
@@ -0,0 +1,202 @@
+// 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");
+  myLocalEntries.clear();
+  mySelectedList.clear();
+  myEntries.clear();
+  myModifiedTime = 0;
+  if (myPyModule)
+    {
+      connect(myPyModule, SIGNAL(localSelectionChanged()), this, SLOT(onSelectionChanged()));
+    }
+  setModified();
+}
+
+/*!
+ \brief Destructor.
+ */
+SALOME_PYQT_Selector::~SALOME_PYQT_Selector()
+{
+  MESSAGE("destructor");
+}
+
+/*!
+ \brief Reset selection internally. Used on close study.
+ */
+void SALOME_PYQT_Selector::clear()
+{
+  MESSAGE("clear");
+  myLocalEntries.clear();
+  mySelectedList.clear();
+  myEntries.clear();
+}
+
+/*!
+ \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)
+    {
+      MESSAGE("mySelectedList.count(): " << mySelectedList.count() << " myLocalEntries.size(): "<< myLocalEntries.size());
+      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;
+
+  myEntries.clear();
+  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)
+        {
+          QString entry = owner->entry();
+          myEntries.append(entry);
+          MESSAGE("Selected: "<< entry.toStdString());
+        }
+    }
+  fillEntries(myEntries);
+  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(QStringList& entries)
+{
+  MESSAGE("fillEntries");
+  if (!myPyModule)
+    return;
+  myPyModule->setSelected(entries);
+  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..97b8946
--- /dev/null
@@ -0,0 +1,77 @@
+// 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; };
+  void               clear();
+
+private slots:
+  void               onSelectionChanged();
+
+protected:
+  virtual void       getSelection( SUIT_DataOwnerPtrList& ) const;
+  virtual void       setSelection( const SUIT_DataOwnerPtrList& );
+
+private:
+  void               fillEntries( QStringList& );
+
+private:
+  QStringList                         myLocalEntries;
+  SALOME_PYQT_ModuleLight*            myPyModule;
+  SUIT_DataOwnerPtrList               mySelectedList;
+  QStringList                         myEntries;
+  unsigned long                       myModifiedTime;
+};
+
+#endif
index 67c57f31d7a844f315f5ae778d81cc46e1633762..f674cbf1890f45234e027cd8dd92f75a95976c00 100644 (file)
@@ -68,6 +68,7 @@
 #include <QPaintEvent>
 #include <QCoreApplication>
 
+#include <utilities.h>
 namespace
 {
   /*!
@@ -243,6 +244,7 @@ SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
   return sel;
 }
 
+
 /*!
   \brief Constructor.
   \param p parent object
@@ -559,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 
@@ -2809,7 +2836,10 @@ public:
         for ( int i = 0, n = vec.size(); i < n; i++ ) {
           SUIT_ViewWindow* wnd = vec[ i ];
           if ( wnd )
-            myResult.append( wnd->getId() );
+            {
+              MESSAGE("SUIT_ViewWindow*: "<< wnd << " id: " << wnd->getId());
+              myResult.append( wnd->getId() );
+            }
         }
       }
     }
@@ -2839,6 +2869,7 @@ public:
   virtual void Execute() 
   {
     SUIT_ViewWindow* wnd = getWnd( myWndId );
+    MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
     if ( wnd ) {
       wnd->setFocus();
       myResult = true;
@@ -2850,6 +2881,67 @@ bool SalomePyQt::activateView( const int id )
   return ProcessEvent( new TActivateView( id ) );
 }
 
+/*!
+  \fn bool SalomePyQt::activateManagerAndView( const int id );
+  \brief Activate view manager and view: useful for a view embedded in a module main Window
+  \param id window identifier
+  \return \c true if operation is completed successfully and \c false otherwise
+ */
+
+class TActivateViewManagerAndView: public SALOME_Event
+{
+public:
+  typedef bool TResult;
+  TResult myResult;
+  int myWndId;
+  TActivateViewManagerAndView( const int id )
+    : myResult( false ),
+      myWndId( id ) {}
+  virtual void Execute()
+  {
+    SUIT_ViewWindow* wnd = getWnd( myWndId );
+    MESSAGE("window id:" << myWndId << " SUIT_ViewWindow*: " << wnd);
+    if ( wnd )
+      {
+        LightApp_Application* app  = getApplication();
+        app->desktop()->windowActivated(wnd); // equivalent to app->setActiveViewManager(wnd->getViewManager())
+        wnd->setFocus();
+        myResult = true;
+      }
+  }
+};
+bool SalomePyQt::activateViewManagerAndView( const int id )
+{
+  return ProcessEvent( new TActivateViewManagerAndView( id ) );
+}
+
+/*!
+ *
+ */
+
+class TGetViewWidget: public SALOME_Event
+{
+public:
+  typedef QWidget* TResult;
+  TResult myResult;
+  int myWndId;
+  TGetViewWidget( const int id )
+    : myResult( 0 ),
+      myWndId( id ) {}
+  virtual void Execute()
+  {
+    SUIT_ViewWindow* wnd = getWnd( myWndId );
+    if ( wnd ) {
+        myResult = (QWidget*)wnd;
+    }
+  }
+};
+QWidget* SalomePyQt::getViewWidget( const int id)
+{
+  return ProcessEvent( new TGetViewWidget( id ) );
+}
+
+
 /*!
   \fn int SalomePyQt::createView( const QString& type, bool visible = true, const int width = 0, const int height = 0 );
   \brief Create new view and activate it
index 4194fa3b664df1ecc4d4ea2af42fd33714085c1f..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();
@@ -287,6 +288,8 @@ public:
   static bool              setViewSize( const int, const int, const int = 0 );
   static QList<int>        findViews( const QString& );
   static bool              activateView( const int );
+  static bool              activateViewManagerAndView( const int );
+  static QWidget*          getViewWidget( const int );
   static int               createView( const QString&, bool visible = true, const int width = 0, const int height = 0 );
   static int               createView( const QString&, QWidget* );
   static bool              closeView( const int );
index c481c24449ac6e70327aeb184ebd44065c7c279f..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/ ;
@@ -404,6 +405,8 @@ public:
   static bool              setViewSize( const int, const int, const int = 0 ) /ReleaseGIL/ ;
   static QList<int>        findViews( const QString& ) /ReleaseGIL/ ;
   static bool              activateView( const int ) /ReleaseGIL/ ;
+  static bool              activateViewManagerAndView( const int ) /ReleaseGIL/ ;
+  static QWidget*          getViewWidget( const int ) /ReleaseGIL/ ;
   static int               createView( const QString&, bool visible = true, const int width = 0, const int height = 0 ) /ReleaseGIL/ ;
   static int               createView( const QString&, QWidget* ) /ReleaseGIL/ ;
   static bool              closeView( const int ) /ReleaseGIL/ ;
index 979783334852ad305733f82479eb07a5278fa09e..8c1fd4b6c84d9916e7f3dd0a8a0cff4ec81d726c 100644 (file)
@@ -57,6 +57,9 @@
 #include <QRegExp>
 #include <QString>
 #include <QStringList>
+#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
+#include <QSurfaceFormat>
+#endif
 
 #include <stdlib.h>
 
@@ -179,6 +182,15 @@ int main( int argc, char* argv[] )
     }
   }
 
+#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
+  // initialization of the X11 visual on Linux
+  QSurfaceFormat format;
+  format.setDepthBufferSize(16);
+  format.setStencilBufferSize(1);
+  format.setProfile(QSurfaceFormat::CompatibilityProfile);
+  QSurfaceFormat::setDefaultFormat(format);
+#endif
+
   // add <qtdir>/plugins directory to the pluins search path for image plugins
   QString qtdir = Qtx::qtDir( "plugins" );
   if ( !qtdir.isEmpty() )
index 7bad2406b12a0bd3ecbed3b21b0933c33a1ded9b..e44ceb9aef65f4662c9eaebc01a7c5f57073386b 100644 (file)
@@ -161,6 +161,12 @@ public:
             if (oldFather) {
               oldFather->removeChild(suit_obj, false);
               SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( myStudy->application() );
+//              MESSAGE("myStudy: " << myStudy->id() << " app " << app);
+//              MESSAGE("objectBrowser: "<< app->objectBrowser());
+              if (!app->objectBrowser()) {
+                MESSAGE("Object Browser not found. Problem ??");
+                return;
+              }
               SUIT_AbstractModel* model = dynamic_cast<SUIT_AbstractModel*>(app->objectBrowser()->model());
               model->forgetObject( suit_obj );
                 
index 4389fb8ebb24a9b8261f28fd37c03cde644a1bf7..c8465bfd0b5d1e01b283b6442b5466a9e85c2c91 100755 (executable)
@@ -77,6 +77,9 @@
 #include <QWaitCondition>
 #include <QRegExp>
 #include <QTextStream>
+#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
+#include <QSurfaceFormat>
+#endif
 
 /*! - read arguments, define list of server to launch with their arguments.
  * - wait for naming service
@@ -366,6 +369,15 @@ int main( int argc, char **argv )
       QLocale::setDefault( QLocale::system() );
     }
   }
+  
+#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
+  // initialization of the X11 visual on Linux
+  QSurfaceFormat format;
+  format.setDepthBufferSize(16);
+  format.setStencilBufferSize(1);
+  format.setProfile(QSurfaceFormat::CompatibilityProfile);
+  QSurfaceFormat::setDefaultFormat(format);
+#endif
 
   // Create Qt application instance;
   // this should be done the very first!