X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Sketch.cpp;h=cf87f3b78f4d0fd21a673b9ff297db3977288df8;hb=cdbbde4803e9c320204d537d22af4ac7ef024962;hp=839d3d96193df5376033321f5c030850cac60442;hpb=8b12043df72857ab0e7698d995288ef9e7d7c66b;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 839d3d961..cf87f3b78 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -153,6 +153,19 @@ void SketchPlugin_Sketch::execute() std::shared_ptr SketchPlugin_Sketch::addFeature(std::string theID) { + // 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 aCurSketchFeature = + std::dynamic_pointer_cast(aCurFeature); + std::shared_ptr aCurSketch = + std::dynamic_pointer_cast(aCurFeature); + if ((aCurSketch && aCurSketch.get() == this) || + (aCurSketchFeature && aCurSketchFeature->sketch() == this)) + aCurFeature = FeaturePtr(); // no need to restore feature if it is from the current sketch + // Set last feature of the sketch as current feature. // Reason: Changing of parameter through Python API may lead to creation of new features // (e.g. changing number of copies in MultiRotation). If the sketch is not the last @@ -177,8 +190,10 @@ std::shared_ptr SketchPlugin_Sketch::addFeature(std::string th aSketchFeature->setSketch(this); data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(aNew); } - // set as current also after it becomes sub to set correctly enabled for other sketch subs - document()->setCurrentFeature(aNew, false); + + // set as current also after it becomes sub to set correctly enabled for other sketch subs + // or restore the previous current feature + document()->setCurrentFeature(aCurFeature ? aCurFeature : aNew, false); return aNew; } @@ -413,7 +428,7 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur { FeaturePtr aNewFeature = theSketch->addFeature(theFeature->getKind()); // addFeature generates a unique name for the feature, it caches the name - std::string aUniqueFeatureName = aNewFeature->data()->name(); + std::wstring aUniqueFeatureName = aNewFeature->data()->name(); // all attribute values are copied\pasted to the new feature, name is not an exception theFeature->data()->copyTo(aNewFeature->data()); // external state should not be copied as a new object is an object of the current sketch @@ -582,9 +597,9 @@ void SketchPlugin_Sketch::updateCoordinateAxis(ObjectPtr theSub, GeomAx3Ptr the return; DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr anOX = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OX"); - ObjectPtr anOY = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OY"); - ObjectPtr anOZ = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), "OZ"); + ObjectPtr anOX = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), L"OX"); + ObjectPtr anOY = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), L"OY"); + ObjectPtr anOZ = aRootDoc->objectByName(ModelAPI_ResultConstruction::group(), L"OZ"); AttributeSelectionPtr anExtFeature; if (aFeature->getKind() == SketchPlugin_Projection::ID())