void SketchSolver_Constraint::update(ConstraintPtr theConstraint)
{
cleanErrorMsg();
- if (theConstraint && theConstraint != myBaseConstraint) {
- if (theConstraint->getKind() != myBaseConstraint->getKind())
+ bool needToRebuild = (theConstraint && theConstraint != myBaseConstraint);
+ if (!needToRebuild) {
+ // Check the attrbutes of constraint are changed
+ ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
+ std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
+ std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
+ for (; anAttrIter != anAttrList.end(); anAttrIter++) {
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+ if (aRefAttr) {
+ if (aRefAttr->isObject()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+ if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
+ needToRebuild = true;
+ break;
+ }
+ } else if (aRefAttr->attr() &&
+ myAttributeMap.find(aRefAttr->attr()) == myAttributeMap.end()) {
+ needToRebuild = true;
+ break;
+ }
+ }
+ AttributeRefListPtr aRefList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
+ if (aRefList) {
+ std::list<ObjectPtr> anItems = aRefList->list();
+ std::list<ObjectPtr>::iterator anIt = anItems.begin();
+ for (; anIt != anItems.end(); anIt++) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
+ needToRebuild = true;
+ break;
+ }
+ }
+ if (needToRebuild)
+ break;
+ }
+ }
+ }
+ if (needToRebuild) {
+ if (theConstraint && theConstraint->getKind() != myBaseConstraint->getKind())
return;
remove(myBaseConstraint);
- myBaseConstraint = theConstraint;
+ if (theConstraint)
+ myBaseConstraint = theConstraint;
process();
+ return;
}
// Update all attributes
std::map<FeaturePtr, Slvs_hEntity>::const_iterator aFIter = myFeatureMap.find(theFeature);
if (aFIter == myFeatureMap.end())
return SLVS_E_UNKNOWN;
- return aFIter->second;
+ // check the Feature is really in the storage
+ Slvs_Entity anEntity = myStorage->getEntity(aFIter->second);
+ if (anEntity.h == SLVS_E_UNKNOWN) {
+ // rebuild feature
+ int aType;
+ anEntity.h = const_cast<SketchSolver_Constraint*>(this)->changeEntity(aFIter->first, aType);
+ const_cast<SketchSolver_Constraint*>(this)->myFeatureMap[theFeature] = anEntity.h;
+ }
+ return anEntity.h;
}
Slvs_hEntity SketchSolver_Constraint::getId(AttributePtr theAttribute) const
setTemporary(aConstraint);
}
}
- // Fix base features for mirror
- if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
- AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
- theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_B()));
- fixFeaturesList(aRefList);
- }
+ //// Fix base features for mirror
+ //if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
+ // AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+ // theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_B()));
+ // fixFeaturesList(aRefList);
+ //}
if (!myFeatureStorage)
myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
bool aResult = true;
int aPos = Search(theEntityID, myEntities);
if (aPos >= 0 && aPos < (int)myEntities.size()) {
- // Firstly, check the entity is not used elsewhere
+ // Firstly, check the entity and its attributes is not used elsewhere
+ std::set<Slvs_hEntity> anEntAndSubs;
+ anEntAndSubs.insert(theEntityID);
+ for (int i = 0; i < 4; i++)
+ if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
+ anEntAndSubs.insert(myEntities[aPos].point[i]);
+
std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
for (; anEntIter != myEntities.end(); anEntIter++) {
for (int i = 0; i < 4; i++)
- if (anEntIter->point[i] == theEntityID)
+ if (anEntAndSubs.find(anEntIter->point[i]) != anEntAndSubs.end())
return false;
- if (anEntIter->distance == theEntityID)
+ if (anEntAndSubs.find(anEntIter->distance) != anEntAndSubs.end())
return false;
}
std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
aConstrIter->entityA, aConstrIter->entityB,
aConstrIter->entityC, aConstrIter->entityD};
for (int i = 0; i < 6; i++)
- if (anEntIDs[i] == theEntityID)
+ if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end())
return false;
}
// The entity is not used, remove it and its parameters
// Entity is not found, return empty object
static Slvs_Entity aDummy;
- aDummy.h = 0;
+ aDummy.h = SLVS_E_UNKNOWN;
return aDummy;
}
aResIndex--;
while (aResIndex < aVecSize && aResIndex >= 0 && theEntities[aResIndex].h < theEntityID)
aResIndex++;
- if (aResIndex == -1)
+ if (aResIndex == -1 || (aResIndex < aVecSize && theEntities[aResIndex].h != theEntityID))
aResIndex = aVecSize;
return aResIndex;
}