From 330f060e77304f950db9ea603b8c145d9df066f3 Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 4 Dec 2017 10:11:25 +0300 Subject: [PATCH] Update the Split operation to avoid changing positions of the sketch feature after dumping to Python --- src/SketchPlugin/SketchPlugin_Split.cpp | 19 +++++++++++-------- src/SketchPlugin/SketchPlugin_Split.h | 5 ++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_Split.cpp b/src/SketchPlugin/SketchPlugin_Split.cpp index a7a8f69b2..140645e6c 100644 --- a/src/SketchPlugin/SketchPlugin_Split.cpp +++ b/src/SketchPlugin/SketchPlugin_Split.cpp @@ -64,7 +64,7 @@ //#define CREATE_CONSTRAINTS -//#define DEBUG_SPLIT +#define DEBUG_SPLIT #ifdef DEBUG_SPLIT #include #endif @@ -317,7 +317,7 @@ void SketchPlugin_Split::execute() // coincidence to feature updateCoincidenceConstraintsToFeature(aCoincidenceToFeature, aFurtherCoincidences, - aFeatureResults, aSplitFeature); + aFeatureResults, aSplitFeature, aFeaturesToDelete); updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes); @@ -875,7 +875,8 @@ void SketchPlugin_Split::updateCoincidenceConstraintsToFeature( const std::map, IdToPointPair>& theCoincidenceToFeature, const std::set >& theFurtherCoincidences, const std::set& theFeatureResults, - const FeaturePtr& theSplitFeature) + const FeaturePtr& theSplitFeature, + std::set& theFeaturesToDelete) { if (theCoincidenceToFeature.empty()) return; @@ -898,6 +899,9 @@ void SketchPlugin_Split::updateCoincidenceConstraintsToFeature( for (; aCIt != aCLast; aCIt++) { FeaturePtr aCoincFeature = aCIt->first; std::string anAttributeId = aCIt->second.first; + std::string aSecondAttribute = anAttributeId == SketchPlugin_Constraint::ENTITY_A() ? + SketchPlugin_Constraint::ENTITY_B() : SketchPlugin_Constraint::ENTITY_A(); + AttributePoint2DPtr aCoincPoint = aCIt->second.second; std::set::const_iterator aFCIt = theFurtherCoincidences.begin(), aFCLast = theFurtherCoincidences.end(); @@ -909,17 +913,16 @@ void SketchPlugin_Split::updateCoincidenceConstraintsToFeature( aFeaturePointAttribute = aFCAttribute; } if (aFeaturePointAttribute.get()) { - aCoincFeature->refattr(anAttributeId)->setObject(ResultPtr()); - aCoincFeature->refattr(anAttributeId)->setAttr(aFeaturePointAttribute); + // create new constraint and remove the current + aCoincFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(), + aFeaturePointAttribute, aCoincFeature->refattr(aSecondAttribute)->attr()); + theFeaturesToDelete.insert(aCIt->first); // create new coincidences to split feature points std::set::const_iterator aSFIt = aNewCoincidencesToSplitFeature.begin(), aSFLast = aNewCoincidencesToSplitFeature.end(); for (; aSFIt != aSFLast; aSFIt++) { AttributePoint2DPtr aSFAttribute = *aSFIt; if (aCoincPnt->isEqual(aSFAttribute->pnt())) { - std::string aSecondAttribute = SketchPlugin_Constraint::ENTITY_A(); - if (anAttributeId == SketchPlugin_Constraint::ENTITY_A()) - aSecondAttribute = SketchPlugin_Constraint::ENTITY_B(); createConstraint(SketchPlugin_ConstraintCoincidence::ID(), aSFAttribute, aCoincFeature->refattr(aSecondAttribute)->attr()); } diff --git a/src/SketchPlugin/SketchPlugin_Split.h b/src/SketchPlugin/SketchPlugin_Split.h index 1c9ae40e5..37f1e1659 100644 --- a/src/SketchPlugin/SketchPlugin_Split.h +++ b/src/SketchPlugin/SketchPlugin_Split.h @@ -181,12 +181,15 @@ private: /// \param theFurtherCoincidences a list of points where coincidences will be build /// \param theFeatureResults created results after split where constaint might be connected /// \param theSplitFeature feature created by split, new coincidences to points should be created + /// \param theFeaturesToDelete the list of removed features (will be updated here by + /// the coincidences to be removed) /// if theCoincidenceToFeature contains equal points void updateCoincidenceConstraintsToFeature( const std::map, IdToPointPair>& theCoincidenceToFeature, const std::set >& theFurtherCoincidences, const std::set& theFeatureResults, - const FeaturePtr& theSplitFeature); + const FeaturePtr& theSplitFeature, + std::set& theFeaturesToDelete); /// Move constraints from base feature to given feature /// \param theFeature a base feature -- 2.39.2