From: azv Date: Mon, 21 Dec 2015 05:41:57 +0000 (+0300) Subject: Minor updates in SketchSolver plugin X-Git-Tag: V_2.1.0~134 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4e04f27e9f9639aaf902c9221e494677c70b94ae;p=modules%2Fshaper.git Minor updates in SketchSolver plugin --- diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 1de16cfe7..7dbde50c7 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -122,7 +122,10 @@ void SketchSolver_Constraint::update() if (aValueAttr) { std::list::iterator aWIt = aWrapper.begin(); for (; aWIt != aWrapper.end(); ++aWIt) - (*aWIt)->setValue(aValueAttr->value()); + if (fabs((*aWIt)->value() - aValueAttr->value()) > tolerance) { + (*aWIt)->setValue(aValueAttr->value()); + myStorage->setNeedToResolve(true); + } } myStorage->addConstraint(myBaseConstraint, aWrapper); diff --git a/src/SketchSolver/SketchSolver_ConstraintMirror.cpp b/src/SketchSolver/SketchSolver_ConstraintMirror.cpp index c496b719d..f271d1817 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMirror.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMirror.cpp @@ -18,7 +18,7 @@ void SketchSolver_ConstraintMirror::getAttributes( } myType = TYPE(myBaseConstraint); - myStorage->update(aMirLineAttr, myGroupID); + myStorage->update(aMirLineAttr/*, myGroupID*/); theMirrorLine = myStorage->entity(aMirLineAttr); // Create SolveSpace entity for all features @@ -45,7 +45,7 @@ void SketchSolver_ConstraintMirror::getAttributes( if (!aFeature) continue; - myStorage->update(aFeature, myGroupID); + myStorage->update(aFeature/*, myGroupID*/); aList->push_back(myStorage->entity(aFeature)); } } diff --git a/src/SketchSolver/SketchSolver_ConstraintTangent.cpp b/src/SketchSolver/SketchSolver_ConstraintTangent.cpp index bf551e43c..51d87e276 100644 --- a/src/SketchSolver/SketchSolver_ConstraintTangent.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintTangent.cpp @@ -21,8 +21,12 @@ static bool hasSingleCoincidence(EntityWrapperPtr theEntity1, EntityWrapperPtr t int aNbCoinc = 0; std::list::const_iterator anIt1, anIt2; for (anIt1 = aStartIt1; anIt1 != aPoints1.end(); ++anIt1) { + if ((*anIt1)->type() != ENTITY_POINT) + continue; std::shared_ptr aPt1 = aBuilder->point(*anIt1); for (anIt2 = aStartIt2; anIt2 != aPoints2.end(); ++anIt2) { + if ((*anIt2)->type() != ENTITY_POINT) + continue; std::shared_ptr aPt2 = aBuilder->point(*anIt2); if (aPt1->distance(aPt2) < tolerance) ++aNbCoinc; diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 0959722ee..bf64e49db 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -196,6 +196,17 @@ void SketchSolver_Group::updateConstraints() myChangedConstraints.clear(); } +static void updateMultiConstraints(ConstraintConstraintMap& theConstraints, FeaturePtr theFeature) +{ + ConstraintConstraintMap::iterator aCIt = theConstraints.begin(); + for (; aCIt != theConstraints.end(); ++aCIt) { + if ((aCIt->second->getType() == CONSTRAINT_MULTI_ROTATION || + aCIt->second->getType() == CONSTRAINT_MULTI_TRANSLATION) + && aCIt->second->isUsed(theFeature)) + std::dynamic_pointer_cast(aCIt->second)->update(true); + } +} + bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) { if (!checkFeatureValidity(theFeature)) @@ -203,7 +214,10 @@ bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) myStorage->blockEvents(true); myStorage->refresh(true); - return myStorage->update(theFeature); + bool isUpdated = myStorage->update(theFeature); + + updateMultiConstraints(myConstraints, theFeature); + return isUpdated; } void SketchSolver_Group::moveFeature(FeaturePtr theFeature) @@ -214,22 +228,16 @@ void SketchSolver_Group::moveFeature(FeaturePtr theFeature) myStorage->blockEvents(true); myStorage->refresh(true); - // Secondly, search attributes of the feature in the list of the Multi constraints and update them - ConstraintConstraintMap::iterator aCIt = myConstraints.begin(); - for (; aCIt != myConstraints.end(); ++aCIt) { - if ((aCIt->second->getType() == CONSTRAINT_MULTI_ROTATION || - aCIt->second->getType() == CONSTRAINT_MULTI_TRANSLATION) - && aCIt->second->isUsed(theFeature)) - std::dynamic_pointer_cast(aCIt->second)->update(true); - } - - // Then, create temporary rigid constraint + // Then, create temporary Fixed constraint SolverConstraintPtr aConstraint = aBuilder->createMovementConstraint(theFeature); if (!aConstraint) return; aConstraint->process(myStorage, getId(), getWorkplaneId()); if (aConstraint->error().empty()) setTemporary(aConstraint); + + // Secondly, search attributes of the feature in the list of the Multi constraints and update them + updateMultiConstraints(myConstraints, theFeature); } // ============================================================================ diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index feae88f9c..2e283a90f 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -209,8 +210,10 @@ bool SketchSolver_Storage::removeConstraint(ConstraintPtr theConstraint) ++anIt; } } - if (!isFullyRemoved) - myConstraintMap[theConstraint] = aConstrList; + if (!isFullyRemoved) { + // revert removed constraint + addConstraint(theConstraint, aConstrList); + } return isFullyRemoved; } @@ -235,6 +238,9 @@ static bool isUsed(EntityWrapperPtr theFeature, AttributePtr theSubEntity) bool SketchSolver_Storage::isUsed(FeaturePtr theFeature) const { + if (myFeatureMap.find(theFeature) != myFeatureMap.end()) + return true; + // check constraints std::map >::const_iterator aCIt = myConstraintMap.begin(); std::list::const_iterator aCWIt; @@ -262,6 +268,9 @@ bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const anAttribute = aRefAttr->attr(); } + if (myAttributeMap.find(theAttribute) != myAttributeMap.end()) + return true; + // check in constraints std::map >::const_iterator aCIt = myConstraintMap.begin(); std::list::const_iterator aCWIt; @@ -269,6 +278,11 @@ bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt) if (::isUsed(*aCWIt, anAttribute)) return true; + // check in features + std::map::const_iterator aFIt = myFeatureMap.begin(); + for (; aFIt != myFeatureMap.end(); ++aFIt) + if (::isUsed(aFIt->second, anAttribute)) + return true; return false; } @@ -290,6 +304,7 @@ bool SketchSolver_Storage::removeEntity(FeaturePtr theFeature) return true; // feature is not removed, revert operation myFeatureMap[theFeature] = anEntity; + update(anEntity); return false; } @@ -315,6 +330,7 @@ bool SketchSolver_Storage::removeEntity(AttributePtr theAttribute) return true; // attribute is not removed, revert operation myAttributeMap[theAttribute] = anEntity; + update(anEntity); return false; } @@ -380,6 +396,19 @@ bool SketchSolver_Storage::isInteract(const AttributePtr& theAttribute) const if (!theAttribute) return false; + AttributeRefListPtr aRefList = + std::dynamic_pointer_cast(theAttribute); + if (aRefList) { + std::list anObjects = aRefList->list(); + std::list::iterator anObjIt = anObjects.begin(); + for (; anObjIt != anObjects.end(); ++anObjIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anObjIt); + if (isInteract(aFeature)) + return true; + } + return false; + } + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); if (!aRefAttr) diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp index 2c47352ad..5e1b85015 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp @@ -231,8 +231,7 @@ std::list SolveSpaceSolver_Builder::createMirror( std::list::const_iterator anIt1 = theEntity1->subEntities().begin(); std::list::const_iterator anIt2 = theEntity2->subEntities().begin(); if ((*anIt2)->group() == theGroupID) // mirrored point is not fixed - makeMirrorPoints(theEntity1->subEntities().front(), - theEntity2->subEntities().front(), theMirrorLine); + makeMirrorPoints(*anIt1, *anIt2, theMirrorLine); // Workaround to avoid problems in SolveSpace. // The symmetry of two arcs will be done using symmetry of three points on these arcs: