#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_ResultConstruction.h>
+#include <GeomDataAPI_Point2D.h>
void SketchSolver_FeatureStorage::changeConstraint(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++;
}
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<ConstraintPtr> aConstraints = aFeatIter->second;
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<AttributePtr> anAttributes = theFeature->data()->attributes(std::string());
- std::list<AttributePtr>::iterator anIter = anAttributes.begin();
- for (; anIter != anAttributes.end(); anIter++) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
- if (aRefAttr) {
- if (!aRefAttr->isObject())
- removeAttribute(aRefAttr->attr(), theFeature);
- continue;
+ if (theFeature->data()) {
+ std::list<AttributePtr> anAttributes = theFeature->data()->attributes(std::string());
+ std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+ for (; anIter != anAttributes.end(); anIter++) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*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);
{
if (myFeatures.find(theFeature) != myFeatures.end())
return true;
+ if (!theFeature->data() || !theFeature->data()->isValid())
+ return false;
std::list<AttributePtr> anAttributes = theFeature->data()->attributes(std::string());
std::list<AttributePtr>::iterator anIter = anAttributes.begin();
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<AttributePtr> anAttrList = aData->attributes(GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr>::iterator anAtIt = anAttrList.begin();
+ for (; anAtIt != anAttrList.end(); anAtIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anAtIt);
+ if (aPoint == theAttribute)
+ anAttrIter->second.insert(aFeatIter->first);
+ }
+ }
if (anAttrIter->second.empty())
myAttributes.erase(anAttrIter);
}
for (; aFIter != myFeatures.end(); aFIter++)
if (!aFIter->first->data() || !aFIter->first->data()->isValid())
return false;
-//// // Check the attributes are valid
-//// MapAttributeFeature::const_iterator aTIter = myAttributes.begin();
-//// for (; aTIter != myAttributes.end(); aTIter++)
-//// if (!aTIter->first->isInitialized())
-//// return false;
return true;
}