From: nds Date: Fri, 29 Apr 2016 05:41:42 +0000 (+0300) Subject: Issue #1037 : implementing own AddOrRemoveSelected for list of shapes to improve... X-Git-Tag: V_2.3.0~67 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=705150f40770add58916b939136f6e4975a3a138;p=modules%2Fshaper.git Issue #1037 : implementing own AddOrRemoveSelected for list of shapes to improve performance. [It contains functionality of the similar method in OCCT] --- diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index cba9d0676..6e006e9f7 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,9 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse //#define DEBUG_COMPOSILID_DISPLAY // Workaround for bug #25637 + +//#define DEBUG_OCCT_SHAPE_SELECTION + void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList) { // Get from null point @@ -552,11 +556,17 @@ void XGUI_Displayer::setSelected(const QList& theValue if (aContext->HasOpenedContext()) { aContext->UnhilightSelected(false); aContext->ClearSelected(false); + NCollection_Map aShapesToBeSelected; + foreach (ModuleBase_ViewerPrsPtr aPrs, theValues) { const GeomShapePtr& aGeomShape = aPrs->shape(); if (aGeomShape.get() && !aGeomShape->isNull()) { const TopoDS_Shape& aShape = aGeomShape->impl(); +#ifdef DEBUG_OCCT_SHAPE_SELECTION aContext->AddOrRemoveSelected(aShape, false); +#else + aShapesToBeSelected.Add(aShape); +#endif } else { ObjectPtr anObject = aPrs->object(); ResultPtr aResult = std::dynamic_pointer_cast(anObject); @@ -574,6 +584,8 @@ void XGUI_Displayer::setSelected(const QList& theValue } } } + if (!aShapesToBeSelected.IsEmpty()) + XGUI_Displayer::AddOrRemoveSelectedShapes(aContext, aShapesToBeSelected); } else { aContext->UnhilightCurrents(false); aContext->ClearCurrents(false); @@ -1258,3 +1270,30 @@ QIntList XGUI_Displayer::activeSelectionModes() const } return aModes; } + +void XGUI_Displayer::AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext, + const NCollection_Map& theShapesToBeSelected) +{ + Handle(AIS_LocalContext) aLContext = theContext->LocalContext(); + TCollection_AsciiString aSelectionName = aLContext->SelectionName(); + aLContext->UnhilightPicked(Standard_False); + + NCollection_Map aShapesSelected; + + NCollection_List anActiveOwners; + aLContext->MainSelector()->ActiveOwners(anActiveOwners); + NCollection_List::Iterator anOwnersIt (anActiveOwners); + Handle(SelectMgr_EntityOwner) anOwner; + for (; anOwnersIt.More(); anOwnersIt.Next()) { + anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value()); + Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(anOwner); + if (!BROwnr.IsNull() && BROwnr->HasShape() && theShapesToBeSelected.Contains(BROwnr->Shape())) { + if (aShapesSelected.Contains(BROwnr->Shape())) + continue; + AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner); + anOwner->SetSelected (Standard_True); + aShapesSelected.Add(BROwnr->Shape()); + } + } + aLContext->HilightPicked(Standard_False); +} diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index a25c306f7..a7b72d22e 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -322,6 +322,15 @@ private: /// \return a string representation std::string getResult2AISObjectMapInfo() const; + /// Sets the shapes selected in the context. It contains logic of the similar method + /// in OCCT but improved for performance. The modification is to iterates by a list + /// of owners in the context only once. + /// \param theContext a viewer context. It has opened local context + /// \param theShapesToBeSelected a map of shapes. Owner's shape is searched in the map and the owner + /// is selected if it is found there. Only first owner is processed(according to OCCT logic) + static void AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext, + const NCollection_Map& theShapesToBeSelected); + protected: /// Reference to workshop XGUI_Workshop* myWorkshop;