From a87dc5357a5af2e1bacb73a87294e69429625a3a Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 16 Apr 2015 11:49:49 +0300 Subject: [PATCH] Fix the SketchSolver problems on Undo-Redo operations --- .../SketchSolver_ConstraintManager.cpp | 16 +++++++++++----- .../SketchSolver_FeatureStorage.cpp | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintManager.cpp b/src/SketchSolver/SketchSolver_ConstraintManager.cpp index 79616858f..8e2aa58b6 100644 --- a/src/SketchSolver/SketchSolver_ConstraintManager.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintManager.cpp @@ -82,6 +82,9 @@ void SketchSolver_ConstraintManager::processEvent( std::dynamic_pointer_cast(theMessage); std::set aFeatures = anUpdateMsg->objects(); + // Shows the message has at least one feature applicable for solver + bool hasProperFeature = false; + bool isMovedEvt = theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED); if (isMovedEvt) { @@ -89,8 +92,10 @@ void SketchSolver_ConstraintManager::processEvent( for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { std::shared_ptr aSFeature = std::dynamic_pointer_cast(*aFeatIter); - if (aSFeature) + if (aSFeature) { moveEntity(aSFeature); + hasProperFeature = true; + } } } else { std::set::iterator aFeatIter; @@ -103,7 +108,7 @@ void SketchSolver_ConstraintManager::processEvent( if (aFeatureKind.compare(SketchPlugin_Sketch::ID()) == 0) { std::shared_ptr aSketch = std::dynamic_pointer_cast< ModelAPI_CompositeFeature>(aFeature); - changeWorkplane(aSketch); + hasProperFeature = changeWorkplane(aSketch) || hasProperFeature; } } // then get anything but not the sketch @@ -118,7 +123,7 @@ void SketchSolver_ConstraintManager::processEvent( aComplexConstraints.insert(aFeature); continue; } - changeConstraintOrEntity(aFeature); + hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature; } // processing remain constraints aFeatIter = aComplexConstraints.begin(); @@ -127,12 +132,13 @@ void SketchSolver_ConstraintManager::processEvent( std::dynamic_pointer_cast(*aFeatIter); if (!aFeature) continue; - changeConstraintOrEntity(aFeature); + hasProperFeature = changeConstraintOrEntity(aFeature) || hasProperFeature; } } // Solve the set of constraints - resolveConstraints(isMovedEvt); // send update for movement in any case + if (hasProperFeature) + resolveConstraints(isMovedEvt); // send update for movement in any case } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { std::shared_ptr aDeleteMsg = std::dynamic_pointer_cast(theMessage); diff --git a/src/SketchSolver/SketchSolver_FeatureStorage.cpp b/src/SketchSolver/SketchSolver_FeatureStorage.cpp index e274244fb..34d07b2bf 100644 --- a/src/SketchSolver/SketchSolver_FeatureStorage.cpp +++ b/src/SketchSolver/SketchSolver_FeatureStorage.cpp @@ -9,6 +9,7 @@ #include #include #include +#include void SketchSolver_FeatureStorage::changeConstraint(ConstraintPtr theConstraint) { @@ -305,6 +306,24 @@ void SketchSolver_FeatureStorage::removeAttribute(AttributePtr theAttribute, Fea return; // no such attribute anAttrIter->second.erase(theFeature); + if (!anAttrIter->second.empty()) + return; + + // Check there is no features containing such attribute + MapFeatureConstraint::iterator aFeatIter = myFeatures.begin(); + for (; aFeatIter != myFeatures.end(); aFeatIter++) { + DataPtr aData = aFeatIter->first->data(); + if (!aData || !aData->isValid()) + continue; + std::list anAttrList = aData->attributes(GeomDataAPI_Point2D::typeId()); + std::list::iterator anAtIt = anAttrList.begin(); + for (; anAtIt != anAttrList.end(); anAtIt++) { + std::shared_ptr aPoint = + std::dynamic_pointer_cast(*anAtIt); + if (aPoint == theAttribute) + anAttrIter->second.insert(aFeatIter->first); + } + } if (anAttrIter->second.empty()) myAttributes.erase(anAttrIter); } -- 2.39.2