Salome HOME
Fix selection by filters on sphere. Check for degenerated edge before calling filters.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelectionFilter.cpp
index 8e44be6a9b15eead26a011f29718a7f70693bcf1..2c10b1adbd5f12e2f927e9a63e300f4c602b810e 100644 (file)
@@ -34,7 +34,9 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_FiltersFactory.h>
 #include <ModelAPI_ResultBody.h>
+
 #include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_Edge.h>
 
 #include <Events_Loop.h>
 #include <Config_ValidatorReader.h>
@@ -472,22 +474,35 @@ void ModuleBase_WidgetSelectionFilter::onSelect()
       TopoDS_Shape aTShape = aSubShape->impl<TopoDS_Shape>();
       if (!alreadyThere.Add(aTShape))
         continue;
+
+      // degenerated edge is not valid selection
+      if ((GeomAPI_Shape::ShapeType)mySelectionType == GeomAPI_Shape::EDGE)
+        if (aSubShape->edge()->isDegenerated())
+          continue;
+
       static SessionPtr aSession = ModelAPI_Session::get();
       bool isValid = aSession->filters()->isValid(myFeature, aBody, aSubShape);
+
       if (isValid) {
         aBuilder.Add(aComp, aTShape);
         // bos #24043: Naming on a compsolid works wrong.
         // Find a simple sub-result for the ViewerPrs context:
-        ObjectPtr aSubResultObj = aObj;
-        for (int aSubIndex = 0; aSubIndex < aBody->numberOfSubs(); aSubIndex++) {
-          ResultBodyPtr aSubResult = aBody->subResult(aSubIndex);
-          GeomShapePtr aSubResultShape = aSubResult->shape();
-          if (aSubResultShape->isSubShape(aSubShape)) {
-            aSubResultObj = aSubResult;
-            break;
+        ResultBodyPtr aContext = aBody;
+        bool isComposite = aContext->numberOfSubs() > 0;
+        while (isComposite) {
+          isComposite = false;
+          int nbSubs = aContext->numberOfSubs();
+          for (int aSubIndex = 0; aSubIndex < nbSubs; aSubIndex++) {
+            ResultBodyPtr aSubResult = aContext->subResult(aSubIndex);
+            GeomShapePtr aSubResultShape = aSubResult->shape();
+            if (aSubResultShape->isSubShape(aSubShape)) {
+              aContext = aSubResult;
+              isComposite = aContext->numberOfSubs() > 0;
+              break;
+            }
           }
         }
-        ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aSubResultObj, aSubShape));
+        ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aContext, aSubShape));
         //ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aSubShape));
         myValues.append(aValue);
       }