]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
fast subShapes selector for PyQt Clients
authorPaul RASCLE <paul.rascle@edf.fr>
Sun, 10 Mar 2019 11:58:49 +0000 (12:58 +0100)
committerPaul RASCLE <paul.rascle@edf.fr>
Sun, 10 Mar 2019 11:58:49 +0000 (12:58 +0100)
src/GEOMBase/GEOMBase_Helper.cxx
src/GEOMBase/GEOMBase_Helper.h
src/GEOM_SWIG_WITHIHM/CMakeLists.txt
src/GEOM_SWIG_WITHIHM/GEOM_Swig_LocalSelector.cxx [new file with mode: 0644]
src/GEOM_SWIG_WITHIHM/GEOM_Swig_LocalSelector.h [new file with mode: 0644]
src/GEOM_SWIG_WITHIHM/libGEOM_Swig.cxx
src/GEOM_SWIG_WITHIHM/libGEOM_Swig.h
src/GEOM_SWIG_WITHIHM/libGEOM_Swig.i

index dee0457ece999e888c6e4abf24e32ddbcbc1fae7..94c3db42b8d98b74343d7d8870a93fc272bee745 100644 (file)
@@ -88,8 +88,8 @@ GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
 // Function : GEOMBase_Helper
 // Purpose  :
 //================================================================
-GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
-  : myDisplayer( 0 ), myCommand( 0 ), myViewWindow( 0 ), isPreview( false ), myDesktop( desktop ),
+GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop, SUIT_ViewWindow* aVW )
+  : myDisplayer( 0 ), myCommand( 0 ), myViewWindow( aVW ), isPreview( false ), myDesktop( desktop ),
     myIsApplyAndClose( false ), myIsOptimizedBrowsing( false ), myIsWaitCursorEnabled( true ),
     myIsDisableBrowsing(false), myIsDisplayResult(true)
 {
@@ -489,6 +489,7 @@ void GEOMBase_Helper::localSelection( const ObjectList& theObjs, const std::list
     QString anEntry = getEntry( anObj );
     if ( anEntry != "" )
     {
+      //MESSAGE("anEntry: "<< anEntry.toStdString().c_str());
       QString aName = GEOMBase::GetName( anObj );
       aListOfIO.Append( new SALOME_InteractiveObject( anEntry.toUtf8().constData(),
                                                       "GEOM", aName.toUtf8().constData() ));
@@ -540,6 +541,20 @@ void GEOMBase_Helper::localSelection( GEOM::GEOM_Object_ptr obj, const int mode
   localSelection( obj, modes );
 }
 
+//================================================================
+// Function : localSelection
+// Purpose  : Activate selection of sub-shapes in accordance with mode
+//            mode is from TopAbs_ShapeEnum
+//================================================================
+void GEOMBase_Helper::localSelection( const std::string& entry,  const std::string& name, const std::list<int> modes)
+{
+  SALOME_ListIO aListOfIO;
+  QString aName = name.c_str();
+  aListOfIO.Append( new SALOME_InteractiveObject( entry.c_str(),
+                                                  "GEOM", aName.toUtf8().constData() ));
+  getDisplayer()->LocalSelection( aListOfIO, modes );
+}
+
 //================================================================
 // Function : localSelection
 // Purpose  : Activate selection of sub-shapes in accordance with mode
index a5a6350345a8ca2f55777dd6e44a1642cf725103..2c5144090715e1584046cf56b030c4d3413df3eb 100644 (file)
@@ -41,6 +41,7 @@
 #include <QMap>
 
 #include <list>
+#include <string>
 
 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
 
@@ -60,7 +61,7 @@ class GEOM_Operation;
 class GEOMBASE_EXPORT GEOMBase_Helper
 {
 public:
-  GEOMBase_Helper( SUIT_Desktop* );
+  GEOMBase_Helper( SUIT_Desktop*, SUIT_ViewWindow* aVW = 0);
   virtual ~GEOMBase_Helper();
   static SUIT_ViewWindow* getActiveView();
 
@@ -105,6 +106,7 @@ protected:
   void localSelection( const ObjectList&, const int );
   void localSelection( GEOM::GEOM_Object_ptr, const std::list<int> );
   void localSelection( GEOM::GEOM_Object_ptr, const int );
+  void localSelection( const std::string&, const std::string&, const std::list<int> );
   void localSelection( const std::list<int> );
   void localSelection( const int );
   void activate( const int );
index 5cb287cb3e14502f4402f0bd51d2868be178667e..cd2c18388aa10aa59c86ccfcb89d9a8ec999f1ac 100644 (file)
@@ -33,6 +33,7 @@ INCLUDE_DIRECTORIES(
   ${PROJECT_BINARY_DIR}/idl
   ${PROJECT_BINARY_DIR}
   ${PROJECT_SOURCE_DIR}/src/OBJECT
+  ${PROJECT_SOURCE_DIR}/src/GEOMBase
   ${PROJECT_SOURCE_DIR}/src/GEOMClient
   ${PROJECT_SOURCE_DIR}/src/GEOMGUI
   ${PROJECT_SOURCE_DIR}/src/Material
@@ -75,9 +76,9 @@ SET(_swig_SCRIPTS
 # --- rules ---
 
 IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") 
-  SWIG_ADD_MODULE(libGEOM_Swig python libGEOM_Swig.i libGEOM_Swig.cxx)
+  SWIG_ADD_MODULE(libGEOM_Swig python libGEOM_Swig.i libGEOM_Swig.cxx  GEOM_Swig_LocalSelector.cxx)
 ELSE()
-  SWIG_ADD_LIBRARY(libGEOM_Swig LANGUAGE python SOURCES libGEOM_Swig.i libGEOM_Swig.cxx)
+  SWIG_ADD_LIBRARY(libGEOM_Swig LANGUAGE python SOURCES libGEOM_Swig.i libGEOM_Swig.cxx  GEOM_Swig_LocalSelector.cxx)
 ENDIF()
 
 SWIG_LINK_LIBRARIES(libGEOM_Swig "${_link_LIBRARIES}")
diff --git a/src/GEOM_SWIG_WITHIHM/GEOM_Swig_LocalSelector.cxx b/src/GEOM_SWIG_WITHIHM/GEOM_Swig_LocalSelector.cxx
new file mode 100644 (file)
index 0000000..a779f0f
--- /dev/null
@@ -0,0 +1,96 @@
+// Copyright (C) 2007-2019  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
+//
+
+#include "GEOM_Swig_LocalSelector.h"
+#include <SalomeApp_Study.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_Session.h>
+#include <GeometryGUI.h>
+#include <SalomeApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SALOMEDSClient_definitions.hxx>
+#include <vector>
+#include <utilities.h>
+
+GEOM_Swig_LocalSelector::GEOM_Swig_LocalSelector(QWidget* parent, SUIT_ViewWindow* wnd, const std::string& shapeEntry, int mode) :
+    GEOMBase_Helper(dynamic_cast<SUIT_Desktop*>(parent), wnd )
+{
+  MESSAGE("GEOM_Swig_LocalSelector " << shapeEntry << " " << mode);
+  myObject = GEOM::GEOM_Object::_nil();
+  mySubShapesInd = new GEOM::short_array();
+  std::string shapeName = "aShape";
+
+  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(SUIT_Session::session()->activeApplication()->activeStudy());
+  if (study)
+    {
+      _PTR(Study) studyDS = study->studyDS();
+      _PTR(SObject) obj( studyDS->FindObjectID( shapeEntry ) );
+      if (obj)
+        {
+          CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(obj);
+          if (!CORBA::is_nil(corbaObj))
+            {
+              myObject = GEOM::GEOM_Object::_narrow(corbaObj);
+              shapeName = myObject->GetName();
+              MESSAGE("shapeName: " << shapeName);
+            }
+        }
+    }
+
+  std::list<int> modes;
+  modes.push_back(mode);
+  localSelection(shapeEntry, shapeName, modes);
+}
+
+GEOM_Swig_LocalSelector::~GEOM_Swig_LocalSelector()
+{
+  MESSAGE("~GEOM_Swig_LocalSelector");
+}
+
+std::vector<int> GEOM_Swig_LocalSelector::getSelection()
+{
+  MESSAGE("getSelection");
+  SalomeApp_Application* app = (SalomeApp_Application*)SUIT_Session::session()->activeApplication();
+  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  SALOME_ListIO aSelList;
+  aSelMgr->selectedObjects(aSelList);
+
+  TColStd_IndexedMapOfInteger aMap;
+  MESSAGE("aSelList.Extent(): " << aSelList.Extent());
+  if (aSelList.Extent() > 0)
+    {
+    Handle(SALOME_InteractiveObject) anIO = aSelList.First();
+    aSelMgr->GetIndexes(anIO, aMap);
+    }
+
+  const int n = aMap.Extent();
+  std::vector<int> ids;
+  for (int i = 1; i <= n; i++)
+    ids.push_back(aMap(i));
+  for (int i =0; i < ids.size(); i++)
+    {
+      MESSAGE("ids[" << i << "] = " << ids[i]);
+    }
+
+  return ids;
+}
+
diff --git a/src/GEOM_SWIG_WITHIHM/GEOM_Swig_LocalSelector.h b/src/GEOM_SWIG_WITHIHM/GEOM_Swig_LocalSelector.h
new file mode 100644 (file)
index 0000000..3109fd1
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (C) 2007-2019  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
+//
+
+#ifndef _GEOM_SWIG_LOCALSELECTOR_H_
+#define _GEOM_SWIG_LOCALSELECTOR_H_
+
+#include <string>
+#include <vector>
+
+#include <QObject>
+
+#include "GEOMBase_Helper.h"
+
+class GEOM_Swig_LocalSelector : public GEOMBase_Helper
+{
+public:
+  GEOM_Swig_LocalSelector(QWidget* parent, SUIT_ViewWindow* wnd, const std::string& shapeEntry, int mode);
+  ~GEOM_Swig_LocalSelector();
+  
+  std::vector<int> getSelection();
+
+protected:
+  GEOM::GEOM_Object_var              myObject;
+  GEOM::short_array_var              mySubShapesInd;
+
+};
+
+#endif /* _GEOM_SWIG_LOCALSELECTOR_H_ */
index e99aaff070fd1d815e88f3657b59c83ca5323fa7..de120642be76bb17eedaad33bb19ac812a3f8949 100644 (file)
 #include "GEOM_Displayer.h"
 #include "GEOM_Constants.h"
 #include "Material_Model.h"
+#include "GEOM_Swig_LocalSelector.h"
+#include "GEOMGUI_OCCSelector.h"
+#include "OCCViewer_ViewManager.h"
 
 #include <SUIT_Desktop.h>
 #include <SUIT_Session.h>
 #include <SUIT_ViewManager.h>
 #include <SUIT_ViewModel.h>
+#include <SUIT_SelectionMgr.h>
+#include <LightApp_SelectionMgr.h>
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 #include <OCCViewer_ViewFrame.h>
 #include <SVTK_ViewWindow.h>
 
 #include <SALOME_Event.h>
+#include <utilities.h>
 
 // IDL Headers
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(GEOM_Gen)
 
+GEOM_Swig_LocalSelector* GEOM_Swig::myLocalSelector = 0;
+GEOMGUI_OCCSelector* GEOM_Swig::myOCCSelector =0;
+
 /*!
   \brief Constructor
 */
-GEOM_Swig::GEOM_Swig()
+GEOM_Swig::GEOM_Swig( bool updateOB )
 {
-  init();
+  init(updateOB);
 }
 
 /*!
@@ -62,12 +71,14 @@ GEOM_Swig::~GEOM_Swig()
 /*!
   \brief Internal initialization
 */
-void GEOM_Swig::init()
+void GEOM_Swig::init( bool updateOB )
 {
   class TEvent: public SALOME_Event
   {
+    bool myUpdateOB;
   public:
-    TEvent()
+    TEvent( bool _updateOB ):
+      myUpdateOB(_updateOB)
     {}
     virtual void Execute()
     {
@@ -99,12 +110,14 @@ void GEOM_Swig::init()
       }
 
       // update Object browser
-      if ( dynamic_cast<SalomeApp_Application*>( app ) )
+      if (myUpdateOB && dynamic_cast<SalomeApp_Application*>( app ) )
         dynamic_cast<SalomeApp_Application*>( app )->updateObjectBrowser( true );
+
+      //myLocalSelector = 0;
     }
   };
 
-  ProcessVoidEvent( new TEvent() );
+  ProcessVoidEvent( new TEvent(updateOB) );
 }
 
 /*!
@@ -477,6 +490,119 @@ void GEOM_Swig::setMaterialProperty( const char* theEntry, const char* theMateri
                                            theMaterial, theUpdateViewer ) );
 }
 
+/*!
+  \brief initialize local subShapes selection on a given shape
+  \param theEntry geometry object's entry
+  \param theMode from enum TopAbs_ShapeEnum
+ */
+void GEOM_Swig::initLocalSelection( const char* theEntry, int theMode)
+{
+  class TEventInitLocalSelection: public SALOME_Event
+  {
+    std::string myEntry;
+    int myMode;
+  public:
+    TEventInitLocalSelection(const char* _entry, int _mode)
+    : myEntry(_entry), myMode(_mode)
+    {}
+    virtual void Execute()
+    {
+      if (myLocalSelector)
+        return;
+      SUIT_Application* app = SUIT_Session::session()->activeApplication();
+      if ( app )
+        {
+          SUIT_ViewWindow* window = app->desktop()->activeWindow();
+          SUIT_ViewWindow* wnd = 0;
+          LightApp_Application* lapp = dynamic_cast<LightApp_Application*>(app);
+          if ( lapp )
+            {
+              SUIT_ViewManager* viewMgr = lapp->activeViewManager();
+              if ( viewMgr )
+                {
+                  wnd = viewMgr->getActiveView();
+                }
+              LightApp_SelectionMgr* mgr = lapp->selectionMgr();
+              if (!myOCCSelector)
+                {
+                  myOCCSelector = new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)viewMgr)->getOCCViewer(), mgr );
+                }
+
+              QList<SUIT_Selector*> aSelectorList;
+              mgr->selectors( "OCCViewer", aSelectorList );
+              for (int i=0; i< aSelectorList.size(); ++i)
+                {
+                  if ( LightApp_OCCSelector* aSelector = dynamic_cast<LightApp_OCCSelector*>( aSelectorList.at(i) ) )
+                    {
+                      aSelector->setEnabled(false);
+                    }
+                  if ( GEOMGUI_OCCSelector* aSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelectorList.at(i) ) )
+                    {
+                      aSelector->setEnabled(true);
+                    }
+                }
+              myOCCSelector->setEnabled(true);
+            }
+
+          myLocalSelector = new GEOM_Swig_LocalSelector(app->desktop(), wnd, myEntry, myMode);
+          MESSAGE("TEventInitLocalSelection myLocalSelector: " << myLocalSelector);
+        }
+    }
+  };
+
+  ProcessVoidEvent(new TEventInitLocalSelection(theEntry, theMode));
+}
+
+/*!
+  \brief get local subShapes selection on a given shape
+  \return a list of selected subShapes indexes
+ */
+std::vector<int> GEOM_Swig::getLocalSelection()
+{
+  class TEventGetLocalSelection: public SALOME_Event
+  {
+  public:
+    typedef std::vector<int> TResult;
+    TResult myResult;
+
+    TEventGetLocalSelection(){}
+
+    virtual void Execute()
+    {
+      MESSAGE("TEventGetLocalSelection myLocalSelector: " << myLocalSelector);
+      if (myLocalSelector)
+        myResult = myLocalSelector->getSelection();
+    }
+  };
+
+  std::vector<int> result = ProcessEvent(new TEventGetLocalSelection());
+  return result;
+}
+
+/*!
+  \brief close local subShapes selection on a given shape
+ */
+void GEOM_Swig::closeLocalSelection()
+{
+  class TEventCloseLocalSelection: public SALOME_Event
+  {
+  public:
+    TEventCloseLocalSelection()
+    {}
+    virtual void Execute()
+    {
+      MESSAGE("TEventCloseLocalSelection myLocalSelector: " << myLocalSelector);
+      if (myLocalSelector)
+        {
+          delete myLocalSelector;
+          myLocalSelector = 0;
+        }
+    }
+  };
+
+  ProcessVoidEvent(new TEventCloseLocalSelection());
+}
+
 class TInitGeomGenEvent: public SALOME_Event
 {
 public:
index 6886538e707931b7513f5d4d76b767ee08e3e41e..95ce490625e0ebf6eac11ebf24eb749789328fd1 100644 (file)
 #define LIBGEOM_SWIG_H
 
 #include "GEOM_GEOMGUI.hxx"
+#include <vector>
+
+class GEOM_Swig_LocalSelector;
+class GEOMGUI_OCCSelector;
 
 class GEOMGUI_EXPORT GEOM_Swig
 {
 public:
-  GEOM_Swig();
+  GEOM_Swig( bool updateOB = true );
   ~GEOM_Swig();
 
   void createAndDisplayGO( const char* theEntry, bool theUpdateViewer = true );
@@ -50,14 +54,21 @@ public:
   void setMaterial( const char* theEntry, const char* theMaterial, bool theUpdateViewer = true );
   void setMaterialProperty( const char* theEntry, const char* theMaterial, bool theUpdateViewer = true );
 
+  void initLocalSelection( const char* theEntry, int theMode);
+  std::vector<int> getLocalSelection();
+  void closeLocalSelection();
+
   int         getIndexTopology( const char* theSubIOR, const char* theMainIOR );
   const char* getShapeTypeString( const char* theIOR );
   const char* getShapeTypeIcon( const char* theIOR );
 
   bool initGeomGen();
-private:
 
-  void init();
+  static GEOM_Swig_LocalSelector* myLocalSelector;
+  static GEOMGUI_OCCSelector* myOCCSelector;
+
+private:
+  void init( bool updateOB );
 };
 
 #endif // LIBGEOM_SWIG_H
index 288b2b8cd3a48408830f9d80d9761067f09ae77c..e5248d1d2f4daf64ab697bc59d118f1e5dcd1641 100644 (file)
 //  Project   : SALOME
 //  Module    : GEOM
 //
+
+
 %module libGEOM_Swig
 
 %{
 #include "libGEOM_Swig.h"
 %}
 
+%include "std_vector.i"
+namespace std {
+  %template(IntVector) vector<int>;
+}
+
+#include <vector>
+
 /*
   managing C++ exception in the Python API
 */
@@ -52,7 +61,7 @@
 class GEOM_Swig
 {
  public:
-  GEOM_Swig();
+  GEOM_Swig( bool updateOB = true );
   ~GEOM_Swig();
 
   void createAndDisplayGO( const char* theEntry, bool theUpdateViewer = true );
@@ -72,6 +81,10 @@ class GEOM_Swig
   void setMaterial( const char* theEntry, const char* theMaterial, bool theUpdateViewer = true );
   void setMaterialProperty( const char* theEntry, const char* theMaterial, bool theUpdateViewer = true );
 
+  void initLocalSelection( const char* theEntry, int theMode);
+  std::vector<int> getLocalSelection();
+  void closeLocalSelection();
+
   int         getIndexTopology( const char* theSubIOR, const char* theMainIOR );
   const char* getShapeTypeString( const char* theIOR );
   const char* getShapeTypeIcon( const char* theIOR );