]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3245: Use plane objects on selection of a Sketcher plane as an abstract plane...
authorvsv <vsv@opencascade.com>
Fri, 15 May 2020 09:28:47 +0000 (12:28 +0300)
committervsv <vsv@opencascade.com>
Fri, 15 May 2020 09:28:47 +0000 (12:28 +0300)
src/PartSet/PartSet_WidgetSketchLabel.cpp

index 171cf3abc09f3d1a10a6eb922479634c4d94857d..df0124eb8006000801a0da071cf57b1c93e5c42f 100644 (file)
@@ -39,6 +39,7 @@
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Events.h>
+#include <ModelAPI_ResultConstruction.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_ViewerPrs.h>
@@ -510,48 +511,61 @@ bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_View
 {
   bool isOwnerSet = false;
 
-  const GeomShapePtr& aShape = thePrs->shape();
+  GeomShapePtr aShape = thePrs->shape();
   std::shared_ptr<GeomAPI_Dir> aDir;
 
+  if (!aShape.get() || aShape->isNull()) {
+    if (thePrs->object() && (feature() != thePrs->object())) {
+      if (thePrs->object()->groupName() == ModelAPI_ResultConstruction::group()) {
+        ResultConstructionPtr aConstruction =
+          std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(thePrs->object());
+        if (aConstruction.get())
+          aShape = aConstruction->shape();
+      }
+    }
+  }
+
   if (aShape.get() && !aShape->isNull()) {
     const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
     aDir = setSketchPlane(aTDShape);
     isOwnerSet = aDir.get();
   }
   if (thePrs->object() && (feature() != thePrs->object())) {
-    FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
-    DataPtr aData = feature()->data();
-    AttributeSelectionPtr aSelAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-      (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
-    if (aSelAttr.get()) {
-      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
-      if (aRes.get()) {
-        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);
-          aSelAttr->setValue(aRes, aShapePtr);
-          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 (thePrs->object()->groupName() != ModelAPI_ResultConstruction::group()) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
+      DataPtr aData = feature()->data();
+      AttributeSelectionPtr aSelAttr =
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+        (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+      if (aSelAttr.get()) {
+        ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
+        if (aRes.get()) {
+          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);
+            aSelAttr->setValue(aRes, aShapePtr);
+            isOwnerSet = true;
+          }
         }
-        if (aShape.get() && aShape->isPlanar()) {
-          const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
-          setSketchPlane(aTDShape);
-          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;
+          }
         }
       }
     }