From 717edd8fa88c10319eea799f4f55117760999e08 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 17 May 2017 12:06:09 +0300 Subject: [PATCH] Fix crash while updating number of copied of "Multi" constraints. Fix unchangeable value of Multi-Rotation constraint. --- .../SketchSolver_ConstraintMulti.cpp | 2 +- .../SketchSolver_ConstraintMultiRotation.cpp | 18 ++++++++---------- .../SketchSolver_ConstraintMultiRotation.h | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintMulti.cpp b/src/SketchSolver/SketchSolver_ConstraintMulti.cpp index c9b1a338b..9c270943f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMulti.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMulti.cpp @@ -86,7 +86,7 @@ bool SketchSolver_ConstraintMulti::remove() std::dynamic_pointer_cast(*anIt); if (anEntity->isExternal() && !aSketchFeature->isExternal()) myStorage->makeNonExternal(anEntity); - } else + } else if ((*anIt)->data() && (*anIt)->data()->isValid()) myStorage->update(*anIt, true); } diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp index 2a91c6285..59a095d71 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp @@ -16,12 +16,13 @@ #include void SketchSolver_ConstraintMultiRotation::getAttributes( - EntityWrapperPtr& theCenter, EntityWrapperPtr& theAngle, + EntityWrapperPtr& theCenter, ScalarWrapperPtr& theAngle, bool& theFullValue, std::list& theEntities) { AttributePtr anAngleAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::ANGLE_ID()); PlaneGCSSolver_AttributeBuilder aValueBuilder; - theAngle = aValueBuilder.createAttribute(anAngleAttr); + theAngle = std::dynamic_pointer_cast( + aValueBuilder.createAttribute(anAngleAttr)); myStorage->addEntity(anAngleAttr, theAngle); AttributeRefAttrPtr aCenterAttr = @@ -56,15 +57,12 @@ void SketchSolver_ConstraintMultiRotation::process() return; } - EntityWrapperPtr anAngle; EntityWrapperPtr aRotationCenter; std::list aBaseEntities; - getAttributes(aRotationCenter, anAngle, myIsFullValue, aBaseEntities); + getAttributes(aRotationCenter, myAngle, myIsFullValue, aBaseEntities); if (!myErrorMsg.empty()) return; - ScalarWrapperPtr anAngleVal = std::dynamic_pointer_cast(anAngle); - myAngle = anAngleVal->value(); myAdjusted = false; adjustConstraint(); @@ -74,10 +72,10 @@ void SketchSolver_ConstraintMultiRotation::process() void SketchSolver_ConstraintMultiRotation::updateLocal() { double aValue = myBaseConstraint->real(SketchPlugin_MultiRotation::ANGLE_ID())->value(); - if (fabs(myAngle - aValue) > tolerance) + if (fabs(myAngle->value() - aValue) > tolerance) myAdjusted = false; // update angle value - myAngle = aValue; + myAngle->setValue(aValue); // update center DataPtr aData = myBaseConstraint->data(); @@ -102,7 +100,8 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint() if (myAdjusted) return; - if (fabs(myAngle) < tolerance) { + double anAngleValue = myAngle->value(); + if (fabs(anAngleValue) < tolerance) { myStorage->setNeedToResolve(false); return; } @@ -115,7 +114,6 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint() myCenterCoord[0] = *(aCenterPoint->x); myCenterCoord[1] = *(aCenterPoint->y); - double anAngleValue = myAngle; if (myIsFullValue && myNumberOfCopies > 0) anAngleValue /= myNumberOfCopies; diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h index 48f367deb..2806ded69 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h @@ -33,7 +33,7 @@ protected: /// \param[out] theFullValue applying translation using the disstance as a full or single value /// \param[out] theEntities list of base entities void getAttributes(EntityWrapperPtr& theCenter, - EntityWrapperPtr& theAngle, + ScalarWrapperPtr& theAngle, bool& theFullValue, std::list& theEntities); @@ -58,7 +58,7 @@ private: private: AttributePoint2DPtr myCenterPointAttribute; ///< a center of rotation - double myAngle; ///< angle of rotation + ScalarWrapperPtr myAngle; ///< angle of rotation double myCenterCoord[2]; ///< coordinates of rotation center double myRotationVal[2]; ///< sinus and cosine of rotation angle -- 2.39.2