From: azv Date: Fri, 10 Apr 2015 14:02:23 +0000 (+0300) Subject: Update the SketchSolver to make constraints changeable X-Git-Tag: V_1.1.0~48^2^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=847d5098f79ae0c9fc7237b8181d29809e3c0409;p=modules%2Fshaper.git Update the SketchSolver to make constraints changeable --- diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 2a2c85f38..737809a98 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -116,12 +116,53 @@ void SketchSolver_Constraint::process() 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 anAttrList = aConstraint->data()->attributes(std::string()); + std::list::iterator anAttrIter = anAttrList.begin(); + for (; anAttrIter != anAttrList.end(); anAttrIter++) { + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(*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(*anAttrIter); + if (aRefList) { + std::list anItems = aRefList->list(); + std::list::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 @@ -564,7 +605,15 @@ Slvs_hEntity SketchSolver_Constraint::getId(FeaturePtr theFeature) const std::map::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(this)->changeEntity(aFIter->first, aType); + const_cast(this)->myFeatureMap[theFeature] = anEntity.h; + } + return anEntity.h; } Slvs_hEntity SketchSolver_Constraint::getId(AttributePtr theAttribute) const diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 9ccf3fa73..58d822786 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -235,12 +235,12 @@ bool SketchSolver_Group::changeConstraint( setTemporary(aConstraint); } } - // Fix base features for mirror - if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) { - AttributeRefListPtr aRefList = std::dynamic_pointer_cast( - 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( + // theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_B())); + // fixFeaturesList(aRefList); + //} if (!myFeatureStorage) myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage); diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index eddd630c9..421696c17 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -142,13 +142,19 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID) 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 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::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::const_iterator aConstrIter = myConstraints.begin(); @@ -157,7 +163,7 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID) 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 @@ -188,7 +194,7 @@ const Slvs_Entity& SketchSolver_Storage::getEntity(const Slvs_hEntity& theEntity // Entity is not found, return empty object static Slvs_Entity aDummy; - aDummy.h = 0; + aDummy.h = SLVS_E_UNKNOWN; return aDummy; } @@ -639,7 +645,7 @@ int Search(const uint32_t& theEntityID, const std::vector& theEntities) 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; }