Salome HOME
Fix for the #2716 comment 3 : make smash allow sub-solids selected, but "Apply" butto...
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.cpp
index 8e83afc0dd60407fb0f5e4554819070129d9da21..14c7fbe576df29fc159cde3c618d86a771cc4900 100644 (file)
@@ -448,7 +448,13 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_View
     if (aSelAttr.get()) {
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
       if (aRes.get()) {
-        GeomShapePtr aShapePtr = ModelAPI_Tools::shape(aRes);
+        GeomShapePtr aShapePtr;
+        if (!aShape.get() || aShape->isNull()) {  // selection happens in the OCC viewer
+          aShapePtr = ModelAPI_Tools::shape(aRes);
+        }
+        else { // selection happens in OB browser
+          aShapePtr = aShape;
+        }
         if (aShapePtr.get() && aShapePtr->isFace()) {
           const TopoDS_Shape& aTDShape = aShapePtr->impl<TopoDS_Shape>();
           setSketchPlane(aTDShape);
@@ -456,6 +462,19 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_View
           isOwnerSet = true;
         }
       }
+      else {
+        aSelAttr->setValue(aFeature, GeomShapePtr());
+        GeomShapePtr aShape = aSelAttr->value();
+        if (!aShape.get() && aSelAttr->contextFeature().get() &&
+          aSelAttr->contextFeature()->firstResult().get()) {
+          aShape = aSelAttr->contextFeature()->firstResult()->shape();
+        }
+        if (aShape.get() && aShape->isPlanar()) {
+          const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
+          setSketchPlane(aTDShape);
+          isOwnerSet = true;
+        }
+      }
     }
   }
   return isOwnerSet;