]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3096: Collect sub-bodies for testing of selection in filters
authorvsv <vsv@opencascade.com>
Fri, 29 Nov 2019 13:34:08 +0000 (16:34 +0300)
committervsv <vsv@opencascade.com>
Fri, 29 Nov 2019 13:34:08 +0000 (16:34 +0300)
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/ModuleBase/ModuleBase_WidgetValidated.h

index bd9cdbd76b9a019995b20b451caf0bcbdcfa4767..f2583322883824d88e5af9f4b8f1841fec1ef0c5 100644 (file)
@@ -32,7 +32,6 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Events.h>
-#include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeSelection.h>
 
@@ -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<TopoDS_Shape>();
+      aIOPtr = myWorkshop->findPresentation(aSub);
+      if (aIOPtr.get()) {
+        Handle(AIS_InteractiveObject) anIO = aIOPtr->impl<Handle(AIS_InteractiveObject)>();
+        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<TopoDS_Shape>();
-              AISObjectPtr aIOPtr = myWorkshop->findPresentation(aResult);
-              if (aIOPtr.get()) {
-                Handle(AIS_InteractiveObject) anIO = aIOPtr->impl<Handle(AIS_InteractiveObject)>();
-                aOwnersList.Append(new StdSelect_BRepOwner(aTDShape, anIO));
-              }
-              else {
-                aOwnersList.Append(new StdSelect_BRepOwner(aTDShape));
+            ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(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<TopoDS_Shape>();
+                AISObjectPtr aIOPtr = myWorkshop->findPresentation(aResult);
+                if (aIOPtr.get()) {
+                  Handle(AIS_InteractiveObject) anIO = aIOPtr->impl<Handle(AIS_InteractiveObject)>();
+                  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
index 19f7fff888662fd47f219eae5fc5c870503e26a4..ce6752b724950423a3006bf4fa955c058194cd94 100644 (file)
 #include <GeomAPI_AISObject.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Attribute.h>
+#include <ModelAPI_ResultBody.h>
 
 #include <SelectMgr_ListOfFilter.hxx>
 #include <NCollection_DataMap.hxx>
 #include <TopoDS_Shape.hxx>
+#include <AIS_NListOfEntityOwner.hxx>
 
 #include <QList>
 #include <QMap>
@@ -190,6 +192,8 @@ private:
   /// \param theValues a list of presentations.
   void filterCompSolids(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
 
+  void collectSubBodies(const ResultBodyPtr& theBody, AIS_NListOfEntityOwner& theList);
+
 protected:
   /// Reference to workshop
   ModuleBase_IWorkshop* myWorkshop;