X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Selection.cpp;h=9e29e8b1b08bf729dd70ae701143b374d9bef318;hb=0dbe381518ba8993c2c4fa0fcb3ddd8fe5b8479b;hp=ed54a60a27ab034ff8100903077474cb28b4320a;hpb=dc7d4d86b58b81684abc9b5a2be8ec30f210c2da;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index ed54a60a2..9e29e8b1b 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "XGUI_Selection.h" @@ -31,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -63,6 +62,7 @@ XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop) QList XGUI_Selection::getSelected(const SelectionPlace& thePlace) const { QList aPresentations; + QList aToRemove; switch (thePlace) { case Browser: @@ -72,8 +72,62 @@ QList XGUI_Selection::getSelected(const SelectionPlace& getSelectedInViewer(aPresentations); break; case AllControls: - getSelectedInViewer(aPresentations); - getSelectedInBrowser(aPresentations); + // Get selection from object browser + getSelectedInBrowser(aPresentations); + + // Filter out all objects except feature if there is no selected results in object browser + // Filter out all features if in object browser there are selected features and their results + bool aHasFeature = false; + bool aHasResult = false; + foreach(ModuleBase_ViewerPrsPtr aVal, aPresentations) { + if (aVal->object().get()) { + FeaturePtr aFeature = std::dynamic_pointer_cast(aVal->object()); + if (aFeature.get()) { + aHasFeature = true; + std::list aResList = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) { + foreach(ModuleBase_ViewerPrsPtr aSel, aPresentations) { + if (aSel->object() == (*aIt)) { + aHasResult = true; + break; + } + } + if (aHasResult) + break; + } + } + } + if (aHasFeature && aHasResult) + break; + } + //Get selection from a viewer + getSelectedInViewer(aPresentations); + + // Filter out extra objects + if (aHasFeature && aHasResult) { + foreach(ModuleBase_ViewerPrsPtr aVal, aPresentations) { + if (aVal->object().get()) { + FeaturePtr aFeature = std::dynamic_pointer_cast(aVal->object()); + if (aFeature.get()) { + aToRemove.append(aVal); + } + } + } + } + else if (aHasFeature && (!aHasResult)) { + foreach(ModuleBase_ViewerPrsPtr aVal, aPresentations) { + if (aVal->object().get()) { + FeaturePtr aFeature = std::dynamic_pointer_cast(aVal->object()); + if (!aFeature.get()) { + aToRemove.append(aVal); + } + } + } + } + foreach(ModuleBase_ViewerPrsPtr aVal, aToRemove) { + aPresentations.removeAll(aVal); + } break; } return aPresentations; @@ -101,14 +155,14 @@ void XGUI_Selection::getSelectedInViewer(QList& thePres { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if (!aContext.IsNull()) { - QList aSelectedIds; // Remember of selected address in order to avoid duplicates + QList aSelectedIds; // Remember of selected address in order to avoid duplicates for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs()); Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); - if (aSelectedIds.contains((long)anOwner.get())) + if (aSelectedIds.contains((size_t)anOwner.get())) continue; - aSelectedIds.append((long)anOwner.get()); + aSelectedIds.append((size_t)anOwner.get()); fillPresentation(aPrs, anOwner); @@ -143,7 +197,6 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs, const Handle(SelectMgr_EntityOwner)& theOwner) const { thePrs->setOwner(theOwner); - Handle(SelectMgr_SelectableObject) aSelectable = theOwner->Selectable(); Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); thePrs->setInteractive(anIO); @@ -265,7 +318,7 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs, // is On and we have to use parent result which corresponds to the CompSolid shape ResultPtr aResult = std::dynamic_pointer_cast(aFeature); if (aResult.get()) { - ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(aResult); + ResultBodyPtr aCompSolid = ModelAPI_Tools::bodyOwner(aResult); if (aCompSolid.get()) { GeomShapePtr aShape = aCompSolid->shape(); if (aShape.get() && aShape->isEqual(thePrs->shape())) { @@ -285,14 +338,14 @@ QList XGUI_Selection::getHighlighted() const if (aContext.IsNull()) return aPresentations; - QList aSelectedIds; // Remember of selected address in order to avoid duplicates + QList aSelectedIds; // Remember of selected address in order to avoid duplicates XGUI_Displayer* aDisplayer = myWorkshop->displayer(); for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner(); if (!anOwner.IsNull()) { - if (aSelectedIds.contains((long)anOwner.get())) + if (aSelectedIds.contains((size_t)anOwner.get())) continue; - aSelectedIds.append((long)anOwner.get()); + aSelectedIds.append((size_t)anOwner.get()); ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs()); fillPresentation(aPrs, anOwner); @@ -374,11 +427,14 @@ void XGUI_Selection::entityOwners(const Handle(AIS_InteractiveObject)& theObject continue; Handle(SelectMgr_Selection) aSelection = theObject->Selection(aMode); - for (aSelection->Init(); aSelection->More(); aSelection->Next()) { - Handle(SelectMgr_SensitiveEntity) anEntity = aSelection->Sensitive(); + NCollection_Vector anEntities = aSelection->Entities(); + for (NCollection_Vector::Iterator anIt(anEntities); + anIt.More(); + anIt.Next()) { + Handle(SelectMgr_SensitiveEntity) anEntity = anIt.Value(); if (anEntity.IsNull()) continue; - Handle(SelectMgr_EntityOwner) anOwner = + Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anEntity->BaseSensitive()->OwnerId()); if (!anOwner.IsNull()) theOwners.Add(anOwner);