X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_FeatureStorage.cpp;h=34d07b2bfe01066f3c8ad9ad76a3ae1d5271b771;hb=d3883990177d27a12b8a2278cdbb82250ff19b79;hp=610993a74eb5ede2eb4f1e7a634577d43da5a945;hpb=ef017929d9fd0f90a8bc7513148e25ce833971ac;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_FeatureStorage.cpp b/src/SketchSolver/SketchSolver_FeatureStorage.cpp index 610993a74..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) { @@ -91,14 +92,10 @@ void SketchSolver_FeatureStorage::removeConstraint(ConstraintPtr theConstraint) while (aFeatIter != myFeatures.end()) { aCIter = aFeatIter->second.find(theConstraint); if (aCIter != aFeatIter->second.end()) { - aFeatIter->second.erase(aCIter); - if (aFeatIter->second.empty()) { - MapFeatureConstraint::iterator aTmpIter = aFeatIter; // stores iterator for the next element, while the current is deleting - aTmpIter++; - myFeatures.erase(aFeatIter); - aFeatIter = aTmpIter; - continue; - } + FeaturePtr aFeature = aFeatIter->first; + aFeatIter++; + removeFeature(aFeature, theConstraint); + continue; } aFeatIter++; } @@ -200,7 +197,7 @@ void SketchSolver_FeatureStorage::changeFeature(FeaturePtr theFeature, Constrain void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature) { MapFeatureConstraint::iterator aFeatIter = myFeatures.find(theFeature); - if (aFeatIter != myFeatures.end()) + if (aFeatIter == myFeatures.end()) return; // no such feature std::set aConstraints = aFeatIter->second; @@ -212,19 +209,35 @@ void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature) void SketchSolver_FeatureStorage::removeFeature(FeaturePtr theFeature, ConstraintPtr theConstraint) { MapFeatureConstraint::iterator aFeatIter = myFeatures.find(theFeature); - if (aFeatIter != myFeatures.end()) + if (aFeatIter == myFeatures.end()) return; // no such feature - std::list anAttributes = theFeature->data()->attributes(std::string()); - std::list::iterator anIter = anAttributes.begin(); - for (; anIter != anAttributes.end(); anIter++) { - AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(*anIter); - if (aRefAttr) { - if (!aRefAttr->isObject()) - removeAttribute(aRefAttr->attr(), theFeature); - continue; + if (theFeature->data()) { + std::list anAttributes = theFeature->data()->attributes(std::string()); + std::list::iterator anIter = anAttributes.begin(); + for (; anIter != anAttributes.end(); anIter++) { + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(*anIter); + if (aRefAttr) { + if (!aRefAttr->isObject()) + removeAttribute(aRefAttr->attr(), theFeature); + continue; + } + removeAttribute(*anIter, theFeature); + } + } else { + // iterate on attributes to find items refered to theFeature + MapAttributeFeature::iterator anIter = myAttributes.begin(); + while (anIter != myAttributes.end()) { + if (anIter->second.find(theFeature) != anIter->second.end()) { + anIter->second.erase(theFeature); + if (anIter->second.empty()) { + MapAttributeFeature::iterator aDeadIter = anIter++; + myAttributes.erase(aDeadIter); + continue; + } + } + anIter++; } - removeAttribute(*anIter, theFeature); } aFeatIter->second.erase(theConstraint); @@ -236,6 +249,8 @@ bool SketchSolver_FeatureStorage::isInteract(FeaturePtr theFeature) const { if (myFeatures.find(theFeature) != myFeatures.end()) return true; + if (!theFeature->data() || !theFeature->data()->isValid()) + return false; std::list anAttributes = theFeature->data()->attributes(std::string()); std::list::iterator anIter = anAttributes.begin(); @@ -287,10 +302,28 @@ void SketchSolver_FeatureStorage::removeAttribute(AttributePtr theAttribute) void SketchSolver_FeatureStorage::removeAttribute(AttributePtr theAttribute, FeaturePtr theFeature) { MapAttributeFeature::iterator anAttrIter = myAttributes.find(theAttribute); - if (anAttrIter != myAttributes.end()) + if (anAttrIter == myAttributes.end()) 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); }