From: Paul RASCLE Date: Sun, 10 Mar 2019 11:58:49 +0000 (+0100) Subject: fast subShapes selector for PyQt Clients X-Git-Tag: V9_3_0b1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cccc6496b16525866b6e50755c0cf667c3fca8de;p=modules%2Fgeom.git fast subShapes selector for PyQt Clients --- diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index dee0457ec..94c3db42b 100644 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -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 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 diff --git a/src/GEOMBase/GEOMBase_Helper.h b/src/GEOMBase/GEOMBase_Helper.h index a5a635034..2c5144090 100644 --- a/src/GEOMBase/GEOMBase_Helper.h +++ b/src/GEOMBase/GEOMBase_Helper.h @@ -41,6 +41,7 @@ #include #include +#include typedef std::list 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 ); void localSelection( GEOM::GEOM_Object_ptr, const int ); + void localSelection( const std::string&, const std::string&, const std::list ); void localSelection( const std::list ); void localSelection( const int ); void activate( const int ); diff --git a/src/GEOM_SWIG_WITHIHM/CMakeLists.txt b/src/GEOM_SWIG_WITHIHM/CMakeLists.txt index 5cb287cb3..cd2c18388 100644 --- a/src/GEOM_SWIG_WITHIHM/CMakeLists.txt +++ b/src/GEOM_SWIG_WITHIHM/CMakeLists.txt @@ -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 index 000000000..a779f0f75 --- /dev/null +++ b/src/GEOM_SWIG_WITHIHM/GEOM_Swig_LocalSelector.cxx @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +GEOM_Swig_LocalSelector::GEOM_Swig_LocalSelector(QWidget* parent, SUIT_ViewWindow* wnd, const std::string& shapeEntry, int mode) : + GEOMBase_Helper(dynamic_cast(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(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 modes; + modes.push_back(mode); + localSelection(shapeEntry, shapeName, modes); +} + +GEOM_Swig_LocalSelector::~GEOM_Swig_LocalSelector() +{ + MESSAGE("~GEOM_Swig_LocalSelector"); +} + +std::vector 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 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 index 000000000..3109fd121 --- /dev/null +++ b/src/GEOM_SWIG_WITHIHM/GEOM_Swig_LocalSelector.h @@ -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 +#include + +#include + +#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 getSelection(); + +protected: + GEOM::GEOM_Object_var myObject; + GEOM::short_array_var mySubShapesInd; + +}; + +#endif /* _GEOM_SWIG_LOCALSELECTOR_H_ */ diff --git a/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.cxx b/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.cxx index e99aaff07..de120642b 100644 --- a/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.cxx +++ b/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.cxx @@ -28,28 +28,37 @@ #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 #include #include #include +#include +#include #include #include #include #include #include +#include // IDL Headers #include #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( app ) ) + if (myUpdateOB && dynamic_cast( app ) ) dynamic_cast( 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(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 aSelectorList; + mgr->selectors( "OCCViewer", aSelectorList ); + for (int i=0; i< aSelectorList.size(); ++i) + { + if ( LightApp_OCCSelector* aSelector = dynamic_cast( aSelectorList.at(i) ) ) + { + aSelector->setEnabled(false); + } + if ( GEOMGUI_OCCSelector* aSelector = dynamic_cast( 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 GEOM_Swig::getLocalSelection() +{ + class TEventGetLocalSelection: public SALOME_Event + { + public: + typedef std::vector TResult; + TResult myResult; + + TEventGetLocalSelection(){} + + virtual void Execute() + { + MESSAGE("TEventGetLocalSelection myLocalSelector: " << myLocalSelector); + if (myLocalSelector) + myResult = myLocalSelector->getSelection(); + } + }; + + std::vector 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: diff --git a/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.h b/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.h index 6886538e7..95ce49062 100644 --- a/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.h +++ b/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.h @@ -26,11 +26,15 @@ #define LIBGEOM_SWIG_H #include "GEOM_GEOMGUI.hxx" +#include + +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 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 diff --git a/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.i b/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.i index 288b2b8cd..e5248d1d2 100644 --- a/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.i +++ b/src/GEOM_SWIG_WITHIHM/libGEOM_Swig.i @@ -23,12 +23,21 @@ // Project : SALOME // Module : GEOM // + + %module libGEOM_Swig %{ #include "libGEOM_Swig.h" %} +%include "std_vector.i" +namespace std { + %template(IntVector) vector; +} + +#include + /* 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 getLocalSelection(); + void closeLocalSelection(); + int getIndexTopology( const char* theSubIOR, const char* theMainIOR ); const char* getShapeTypeString( const char* theIOR ); const char* getShapeTypeIcon( const char* theIOR );