From f5552e385dc4efe2e124e0f37e9567c5afec6721 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 29 Nov 2019 16:34:08 +0300 Subject: [PATCH] Issue #3096: Collect sub-bodies for testing of selection in filters --- src/ModuleBase/ModuleBase_WidgetValidated.cpp | 59 +++++++++++++------ src/ModuleBase/ModuleBase_WidgetValidated.h | 4 ++ 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index bd9cdbd76..f25833228 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -97,6 +96,31 @@ void ModuleBase_WidgetValidated::restoreAttributeValue(const AttributePtr& theAt myAttributeStore->restoreAttributeValue(theAttribute, myWorkshop); } + +//******************************************************************** +void ModuleBase_WidgetValidated::collectSubBodies(const ResultBodyPtr& theBody, + AIS_NListOfEntityOwner& theList) +{ + AISObjectPtr aIOPtr; + TopoDS_Shape aTDShape; + int aNb = theBody->numberOfSubs(); + for (int i = 0; i < aNb; i++) { + ResultBodyPtr aSub = theBody->subResult(i); + if (aSub->numberOfSubs() > 0) + collectSubBodies(aSub, theList); + else { + aTDShape = aSub->shape()->impl(); + aIOPtr = myWorkshop->findPresentation(aSub); + if (aIOPtr.get()) { + Handle(AIS_InteractiveObject) anIO = aIOPtr->impl(); + theList.Append(new StdSelect_BRepOwner(aTDShape, anIO)); + } + else + theList.Append(new StdSelect_BRepOwner(aTDShape)); + } + } +} + //******************************************************************** bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr& thePrs) { @@ -141,32 +165,33 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr& Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs); aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO)); } - else - aValid = false; - //aSelectAttr->setValue(ObjectPtr(), GeomShapePtr(), true); } else { ResultPtr aResult = aFeature->firstResult(); if (aResult.get()) { - GeomShapePtr aShapePtr = ModelAPI_Tools::shape(aResult); - if (aShapePtr.get()) { - const TopoDS_Shape aTDShape = aShapePtr->impl(); - AISObjectPtr aIOPtr = myWorkshop->findPresentation(aResult); - if (aIOPtr.get()) { - Handle(AIS_InteractiveObject) anIO = aIOPtr->impl(); - aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO)); - } - else { - aOwnersList.Append(new StdSelect_BRepOwner(aTDShape)); + ResultBodyPtr aBody = std::dynamic_pointer_cast(aResult); + if (aBody.get() && (aBody->numberOfSubs() > 0)) + collectSubBodies(aBody, aOwnersList); + else { + GeomShapePtr aShapePtr = ModelAPI_Tools::shape(aResult); + if (aShapePtr.get()) { + TopoDS_Shape aTDShape = aShapePtr->impl(); + AISObjectPtr aIOPtr = myWorkshop->findPresentation(aResult); + if (aIOPtr.get()) { + Handle(AIS_InteractiveObject) anIO = aIOPtr->impl(); + aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO)); + } + else + aOwnersList.Append(new StdSelect_BRepOwner(aTDShape)); } } } - aValid = (aOwnersList.Size() > 0); // only results with a shape can be filtered } - } else - aValid = false; // only results with a shape can be filtered + } } } + aValid = (aOwnersList.Size() > 0); // only results with a shape can be filtered + // checks the owner by the AIS context activated filters if (aOwnersList.Size() > 0) { // the widget validator filter should be active, but during check by preselection diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index 19f7fff88..ce6752b72 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -27,10 +27,12 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -190,6 +192,8 @@ private: /// \param theValues a list of presentations. void filterCompSolids(QList>& theValues); + void collectSubBodies(const ResultBodyPtr& theBody, AIS_NListOfEntityOwner& theList); + protected: /// Reference to workshop ModuleBase_IWorkshop* myWorkshop; -- 2.39.2