Salome HOME
Issue #2167: error when create circle
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Sketch.cpp
index 4de9585ee05cc0d914186d692e08254624155f13..d1deff5364ac1e1f9369a33889243ee28db68c1b 100755 (executable)
@@ -139,6 +139,7 @@ std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string th
   }
    // set as current also after it becomes sub to set correctly enabled for other sketch subs
   document()->setCurrentFeature(aNew, false);
+
   return aNew;
 }
 
@@ -212,9 +213,10 @@ bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const
 
 void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
   if (theID == SketchPlugin_SketchEntity::EXTERNAL_ID()) {
-    std::shared_ptr<GeomAPI_Shape> aSelection =
-      data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value();
-    if (aSelection) { // update arguments due to the selection value
+    AttributeSelectionPtr aSelAttr = selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+    if (aSelAttr->context().get()) { // update arguments due to the selection value
+      std::shared_ptr<GeomAPI_Shape> aSelection = aSelAttr->value();
+      if (!aSelection.get()) aSelection = aSelAttr->context()->shape();
       // update the sketch plane
       std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aSelection));
       std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
@@ -295,8 +297,8 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur
   theFeature->data()->copyTo(aNewFeature->data());
   // external state should not be copied as a new object is an object of the current sketch
   if (theFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()).get())
-    theFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->setValue(ResultPtr(),
-                                                                              GeomShapePtr());
+    aNewFeature->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->setValue(ResultPtr(),
+                                                                               GeomShapePtr());
   aNewFeature->data()->setName(aUniqueFeatureName);
   // text expressions could block setValue of some attributes
   SketchPlugin_Tools::clearExpressions(aNewFeature);