+ // It is necessary to keep and restore the current feature in the document,
+ // if the sketch is updated from Python API. Because in that case, the current feature
+ // may be a non-sketch feature, so it is required to set it back, after adding a sketch feature,
+ // to keep the sequence of non-sketch features within the document.
+ FeaturePtr aCurFeature = document()->currentFeature(false);
+ std::shared_ptr<SketchPlugin_Feature> aCurSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aCurFeature);
+ std::shared_ptr<SketchPlugin_Sketch> aCurSketch =
+ std::dynamic_pointer_cast<SketchPlugin_Sketch>(aCurFeature);
+ if ((aCurSketch && aCurSketch.get() == this) ||
+ (aCurSketchFeature && aCurSketchFeature->sketch() == this))
+ aCurFeature = FeaturePtr(); // no need to restore feature if it is from the current sketch
+