Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.cpp
index a11c8c2018417011425d6a5c871609c4785f6ac3..c9695948935874cd0a2828b200b479f90c1da630 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -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)
 {
@@ -107,7 +131,7 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr&
 
   // if an owner is null, the selection happens in the Object browser.
   // creates a selection owner on the base of object shape and the object AIS object
-  if ((aOwnersList.Size() > 0) && thePrs->object().get()) {
+  if ((aOwnersList.Size() == 0) && thePrs->object().get()) {
     ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
     GeomShapePtr aShape = aResult.get() ? aResult->shape() : GeomShapePtr();
     // some results have no shape, e.g. the parameter one. So, they should not be validated
@@ -131,42 +155,44 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr&
           AttributeSelectionPtr aSelectAttr =
             std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttr);
           aSelectAttr->setValue(myPresentedObject, GeomShapePtr(), true);
-          GeomShapePtr aShape = aSelectAttr->value();
-          if (!aShape.get() && aSelectAttr->contextFeature().get() &&
+          GeomShapePtr aShapePtr = aSelectAttr->value();
+          if (!aShapePtr.get() && aSelectAttr->contextFeature().get() &&
             aSelectAttr->contextFeature()->firstResult().get()) {
-            aShape = aSelectAttr->contextFeature()->firstResult()->shape();
+            aShapePtr = aSelectAttr->contextFeature()->firstResult()->shape();
           }
-          if (aShape.get()) {
-            const TopoDS_Shape aTDShape = aShape->impl<TopoDS_Shape>();
+          if (aShapePtr.get()) {
+            const TopoDS_Shape aTDShape = aShapePtr->impl<TopoDS_Shape>();
             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));
+          ResultPtr aFirstRes = aFeature->firstResult();
+          if (aFirstRes.get()) {
+            ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aFirstRes);
+            if (aBody.get() && (aBody->numberOfSubs() > 0))
+              collectSubBodies(aBody, aOwnersList);
+            else {
+              GeomShapePtr aShapePtr = ModelAPI_Tools::shape(aFirstRes);
+              if (aShapePtr.get()) {
+                TopoDS_Shape aTDShape = aShapePtr->impl<TopoDS_Shape>();
+                AISObjectPtr aIOPtr = myWorkshop->findPresentation(aFirstRes);
+                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
@@ -302,8 +328,6 @@ bool ModuleBase_WidgetValidated::isValidAttribute(const AttributePtr& theAttribu
 //********************************************************************
 bool ModuleBase_WidgetValidated::isFilterActivated() const
 {
-  bool isActivated = false;
-
   Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
   ModuleBase_IViewer* aViewer = myWorkshop->viewer();