From 27d49388b2c612e8e291734df28478dd79a7cea8 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 27 Jun 2014 10:26:33 +0400 Subject: [PATCH] Problem with redisplay of constraint between points of lines was fixed --- .../SketchSolver_ConstraintGroup.cpp | 54 ++++++++++++++----- .../SketchSolver_ConstraintGroup.h | 3 +- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index d54915677..1e0905031 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -566,7 +566,8 @@ void SketchSolver_ConstraintGroup::resolveConstraints() std::map, Slvs_hEntity>::iterator anEntIter = myEntityAttrMap.begin(); for ( ; anEntIter != myEntityAttrMap.end(); anEntIter++) - updateAttribute(anEntIter->first, anEntIter->second); + if (updateAttribute(anEntIter->first, anEntIter->second)) + updateRelatedConstraints(anEntIter->first); } else if (!myConstraints.empty()) Events_Error::send(ERROR_SOLVE_CONSTRAINTS, this); @@ -789,7 +790,7 @@ bool SketchSolver_ConstraintGroup::updateGroup() // Class: SketchSolver_ConstraintGroup // Purpose: update features of sketch after resolving constraints // ============================================================================ -void SketchSolver_ConstraintGroup::updateAttribute( +bool SketchSolver_ConstraintGroup::updateAttribute( boost::shared_ptr theAttribute, const Slvs_hEntity& theEntityID) { @@ -804,10 +805,16 @@ void SketchSolver_ConstraintGroup::updateAttribute( boost::dynamic_pointer_cast(theAttribute); if (aPoint) { - aPoint->setValue(myParams[aFirstParamPos].val, - myParams[aFirstParamPos+1].val, - myParams[aFirstParamPos+2].val); - return ; + if (fabs(aPoint->x() - myParams[aFirstParamPos].val) > tolerance || + fabs(aPoint->y() - myParams[aFirstParamPos+1].val) > tolerance || + fabs(aPoint->z() - myParams[aFirstParamPos+2].val) > tolerance) + { + aPoint->setValue(myParams[aFirstParamPos].val, + myParams[aFirstParamPos+1].val, + myParams[aFirstParamPos+2].val); + return true; + } + return false; } // Point in 2D @@ -815,9 +822,14 @@ void SketchSolver_ConstraintGroup::updateAttribute( boost::dynamic_pointer_cast(theAttribute); if (aPoint2D) { - aPoint2D->setValue(myParams[aFirstParamPos].val, - myParams[aFirstParamPos+1].val); - return ; + if (fabs(aPoint2D->x() - myParams[aFirstParamPos].val) > tolerance || + fabs(aPoint2D->y() - myParams[aFirstParamPos+1].val) > tolerance) + { + aPoint2D->setValue(myParams[aFirstParamPos].val, + myParams[aFirstParamPos+1].val); + return true; + } + return false; } // Scalar value @@ -825,11 +837,16 @@ void SketchSolver_ConstraintGroup::updateAttribute( boost::dynamic_pointer_cast(theAttribute); if (aScalar) { - aScalar->setValue(myParams[aFirstParamPos].val); - return ; + if (fabs(aScalar->value() - myParams[aFirstParamPos].val) > tolerance) + { + aScalar->setValue(myParams[aFirstParamPos].val); + return true; + } + return false; } /// \todo Support other types of entities + return false; } // ============================================================================ @@ -866,7 +883,8 @@ void SketchSolver_ConstraintGroup::updateEntityIfPossible( // Restore flag of changes myNeedToSolve = myNeedToSolve || aNeedToSolveCopy; - updateRelatedConstraints(theEntity); + if (myNeedToSolve) + updateRelatedConstraints(theEntity); } } @@ -1115,18 +1133,26 @@ void SketchSolver_ConstraintGroup::updateRelatedConstraints( for ( ; aConstrIter != myConstraintMap.end(); aConstrIter++) { std::list< boost::shared_ptr > anAttributes = - aConstrIter->first->data()->attributes(theEntity->attributeType()); + aConstrIter->first->data()->attributes(std::string()); std::list< boost::shared_ptr >::iterator anAttrIter = anAttributes.begin(); for ( ; anAttrIter != anAttributes.end(); anAttrIter++) - if (*anAttrIter == theEntity) + { + bool isUpd = (*anAttrIter == theEntity); + boost::shared_ptr aRefAttr = + boost::dynamic_pointer_cast(*anAttrIter); + if (aRefAttr && !aRefAttr->isFeature() && aRefAttr->attr() == theEntity) + isUpd = true; + + if (isUpd) { static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); Model_FeatureUpdatedMessage aMsg(aConstrIter->first, anEvent); Events_Loop::loop()->send(aMsg, true); break; } + } } } diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.h b/src/SketchSolver/SketchSolver_ConstraintGroup.h index 36d3d12ed..362c31b25 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.h +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.h @@ -146,8 +146,9 @@ protected: /** \brief Change values of attribute by parameters received from SolveSpace solver * \param[in,out] theAttribute pointer to the attribute to be changed * \param[in] theEntityID identifier of SolveSpace entity, which contains updated data + * \return \c true if the attribute's value has changed */ - void updateAttribute(boost::shared_ptr theAttribute, const Slvs_hEntity& theEntityID); + bool updateAttribute(boost::shared_ptr theAttribute, const Slvs_hEntity& theEntityID); /** \brief Adds a constraint for a point which should not be changed during computations * \param[in] theEntity the base for the constraint -- 2.39.2