From 0f4bf6702d41e418c6645c11f7d3af3fda8b042b Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 7 Jun 2019 11:45:02 +0300 Subject: [PATCH] Controlling the current feature of the document if the sketch feature is added. --- src/SketchPlugin/SketchPlugin_Feature.cpp | 15 +++++++++++++++ src/SketchPlugin/SketchPlugin_Feature.h | 9 ++++++++- .../SketchPlugin_IntersectionPoint.cpp | 4 ++++ src/SketchPlugin/SketchPlugin_Projection.cpp | 4 ++++ src/SketchPlugin/SketchPlugin_Split.cpp | 5 +++++ src/SketchPlugin/SketchPlugin_Trim.cpp | 5 +++++ 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index 6ad032f18..9663e22c5 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -57,3 +57,18 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch() return mySketch; } +void SketchPlugin_Feature::keepCurrentFeature() +{ + FeaturePtr aCurFeature = document()->currentFeature(true); + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(aCurFeature); + if (!aSketchFeature || aSketchFeature->sketch() == sketch()) + myCurrentFeature = aCurFeature; +} + +void SketchPlugin_Feature::restoreCurrentFeature() +{ + if (myCurrentFeature) + document()->setCurrentFeature(myCurrentFeature, true); + myCurrentFeature = FeaturePtr(); +} diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index c5403b5c9..7b5eebcbc 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -78,11 +78,18 @@ protected: /// initializes mySketch SketchPlugin_Feature(); + /// Store current feature of the document if it is not the sub-feature of the current sketch + void keepCurrentFeature(); + /// Restore current feature of the document after adding new feature to the sketch + void restoreCurrentFeature(); + friend class SketchPlugin_Sketch; - private: +private: std::shared_ptr myPreview; ///< the preview shape SketchPlugin_Sketch* mySketch; /// sketch that contains this feature + + FeaturePtr myCurrentFeature; /// temporary stored current feature }; #endif diff --git a/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp b/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp index 5563a6bd5..ec038bc96 100644 --- a/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp +++ b/src/SketchPlugin/SketchPlugin_IntersectionPoint.cpp @@ -105,11 +105,15 @@ void SketchPlugin_IntersectionPoint::computePoint(const std::string& theID) aPntIt != anIntersectionsPoints.end(); ++aPntIt, ++aResultIndex) { std::shared_ptr aCurSketchPoint; if (aExistInterIt == anExistentIntersections.end()) { + keepCurrentFeature(); + // create new point aCurSketchPoint = std::dynamic_pointer_cast( sketch()->addFeature(SketchPlugin_Point::ID())); aCurSketchPoint->boolean(COPY_ID())->setValue(true); anIntersectionsList->append(aCurSketchPoint); + + restoreCurrentFeature(); } else { // update existent point aCurSketchPoint = std::dynamic_pointer_cast(*aExistInterIt); diff --git a/src/SketchPlugin/SketchPlugin_Projection.cpp b/src/SketchPlugin/SketchPlugin_Projection.cpp index 0d40b6181..0a1a1b96f 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.cpp +++ b/src/SketchPlugin/SketchPlugin_Projection.cpp @@ -168,6 +168,8 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); } + keepCurrentFeature(); + if (aVertex) { std::shared_ptr aPrjPnt = aSketchPlane->project(aVertex->point()); std::shared_ptr aPntInSketch = sketch()->to2D(aPrjPnt); @@ -264,6 +266,8 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) aProjection->execute(); aRefAttr->setObject(aProjection); + restoreCurrentFeature(); + if (theID == EXTERNAL_FEATURE_ID()) { selection(EXTERNAL_ID())->selectValue(aExtFeature); diff --git a/src/SketchPlugin/SketchPlugin_Split.cpp b/src/SketchPlugin/SketchPlugin_Split.cpp index 720da74a6..ac6a15d6d 100644 --- a/src/SketchPlugin/SketchPlugin_Split.cpp +++ b/src/SketchPlugin/SketchPlugin_Split.cpp @@ -234,6 +234,8 @@ void SketchPlugin_Split::execute() std::cout << std::endl; #endif + keepCurrentFeature(); + std::string aFeatureKind = aBaseFeature->getKind(); FeaturePtr aSplitFeature, anAfterFeature; std::set aFurtherCoincidences; @@ -246,6 +248,9 @@ void SketchPlugin_Split::execute() else if (aFeatureKind == SketchPlugin_Arc::ID()) aNewFeature = splitArc(aSplitFeature, aBaseFeature, anAfterFeature, aFurtherCoincidences, aCreatedFeatures, aModifiedAttributes); + + restoreCurrentFeature(); + if (aFeatureKind == SketchPlugin_Circle::ID()) { FeaturePtr aCircleFeature = aBaseFeature; aReplacingFeature = splitCircle(aSplitFeature, aBaseFeature, anAfterFeature, diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index bfaff6423..66d7157c1 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -295,6 +295,9 @@ void SketchPlugin_Trim::execute() std::cout << "[" << aRefsToFeature.size() << "] " << aRefsInfo << std::endl; std::cout << "---- getRefAttributes:end ----" << std::endl; #endif + + keepCurrentFeature(); + std::set aFurtherCoincidences; std::set> aModifiedAttributes; const std::string& aKind = aBaseFeature->getKind(); @@ -318,6 +321,8 @@ void SketchPlugin_Trim::execute() aFurtherCoincidences, aModifiedAttributes); } + restoreCurrentFeature(); + // constraints to end points of trim feature if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end()) fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints); -- 2.39.2