From 953119363a54cbf70176287608a2099d74d98a51 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 16 Apr 2015 13:50:23 +0300 Subject: [PATCH] Issue #463: Fillet constraint - closed line is destroyed 1. Avoid conflicting constraints during fixing horizontal segment 2. Change behavior on fixing the base entities of fillet --- src/SketchSolver/SketchSolver_Constraint.cpp | 3 +- .../SketchSolver_ConstraintRigid.cpp | 43 ++++++++++++++++++- .../SketchSolver_ConstraintRigid.h | 3 ++ src/SketchSolver/SketchSolver_Group.cpp | 5 ++- src/SketchSolver/SketchSolver_Storage.cpp | 4 +- 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 737809a98..4db4c4636 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -194,7 +194,8 @@ void SketchSolver_Constraint::update(ConstraintPtr theConstraint) std::vector::iterator aCIter = mySlvsConstraints.begin(); for (; aCIter != mySlvsConstraints.end(); aCIter++) { Slvs_Constraint aConstraint = myStorage->getConstraint(*aCIter); - aConstraint.valA = aValue; + if (aValueAttr) + aConstraint.valA = aValue; Slvs_hEntity* aCoeffs[6] = { &aConstraint.ptA, &aConstraint.ptB, &aConstraint.entityA, &aConstraint.entityB, diff --git a/src/SketchSolver/SketchSolver_ConstraintRigid.cpp b/src/SketchSolver/SketchSolver_ConstraintRigid.cpp index d13285362..7247553ae 100644 --- a/src/SketchSolver/SketchSolver_ConstraintRigid.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintRigid.cpp @@ -13,6 +13,8 @@ #include #include +#include + SketchSolver_ConstraintRigid::SketchSolver_ConstraintRigid(FeaturePtr theFeature) : SketchSolver_Constraint(), myBaseFeature(theFeature) @@ -184,7 +186,34 @@ void SketchSolver_ConstraintRigid::fixPoint(const Slvs_hEntity& thePointID) void SketchSolver_ConstraintRigid::fixLine(const Slvs_Entity& theLine) { Slvs_Constraint anEqual; - if (isUsedInEqual(theLine, anEqual)) { + if (isAxisParallel(theLine)) { + // Fix one point and a line length + Slvs_hConstraint aFixed; + if (!myStorage->isPointFixed(theLine.point[0], aFixed, true) && + !myStorage->isPointFixed(theLine.point[1], aFixed, true)) + fixPoint(theLine.point[0]); + if (!isUsedInEqual(theLine, anEqual)) { + // Calculate distance between points on the line + double aCoords[4]; + for (int i = 0; i < 2; i++) { + Slvs_Entity aPnt = myStorage->getEntity(theLine.point[i]); + for (int j = 0; j < 2; j++) { + Slvs_Param aParam = myStorage->getParameter(aPnt.param[j]); + aCoords[2*i+j] = aParam.val; + } + } + double aLength = sqrt((aCoords[2] - aCoords[0]) * (aCoords[2] - aCoords[0]) + + (aCoords[3] - aCoords[1]) * (aCoords[3] - aCoords[1])); + // fix line length + Slvs_Constraint aDistance = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroup->getId(), + SLVS_C_PT_PT_DISTANCE, myGroup->getWorkplaneId(), aLength, + theLine.point[0], theLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); + aDistance.h = myStorage->addConstraint(aDistance); + mySlvsConstraints.push_back(aDistance.h); + } + return; + } + else if (isUsedInEqual(theLine, anEqual)) { // Check another entity of Equal is already fixed Slvs_hEntity anOtherEntID = anEqual.entityA == theLine.h ? anEqual.entityB : anEqual.entityA; if (myStorage->isEntityFixed(anOtherEntID, true)) { @@ -352,3 +381,15 @@ bool SketchSolver_ConstraintRigid::isUsedInEqual( return false; } +bool SketchSolver_ConstraintRigid::isAxisParallel(const Slvs_Entity& theEntity) const +{ + std::list aConstr = myStorage->getConstraintsByType(SLVS_C_HORIZONTAL); + std::list aVert = myStorage->getConstraintsByType(SLVS_C_VERTICAL); + aConstr.insert(aConstr.end(), aVert.begin(), aVert.end()); + + std::list::const_iterator anIter = aConstr.begin(); + for (; anIter != aConstr.end(); anIter++) + if (anIter->entityA == theEntity.h) + return true; + return false; +} diff --git a/src/SketchSolver/SketchSolver_ConstraintRigid.h b/src/SketchSolver/SketchSolver_ConstraintRigid.h index 4cde52479..1fcb896e1 100644 --- a/src/SketchSolver/SketchSolver_ConstraintRigid.h +++ b/src/SketchSolver/SketchSolver_ConstraintRigid.h @@ -67,6 +67,9 @@ private: /// \return \c true, if the Equal constrait is found bool isUsedInEqual(const Slvs_Entity& theEntity, Slvs_Constraint& theEqual) const; + /// \brief Check the entity is horizontal of vertical + bool isAxisParallel(const Slvs_Entity& theEntity) const; + protected: FeaturePtr myBaseFeature; ///< fixed feature (when it is set, myBaseConstraint should be NULL) }; diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 5479601f9..a7f8d5b48 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -180,7 +180,8 @@ bool SketchSolver_Group::changeConstraint( if (!theConstraint) return false; - if (myConstraints.find(theConstraint) == myConstraints.end()) { + bool isNewConstraint = myConstraints.find(theConstraint) == myConstraints.end(); + if (isNewConstraint) { // Add constraint to the current group SolverConstraintPtr aConstraint = SketchSolver_Builder::getInstance()->createConstraint(theConstraint); @@ -216,7 +217,7 @@ bool SketchSolver_Group::changeConstraint( myConstraints[theConstraint]->update(); // Fix base features for fillet - if (theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) { + if (isNewConstraint && theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) { std::list anAttrList = theConstraint->data()->attributes(ModelAPI_AttributeRefAttr::typeId()); std::list::iterator anAttrIter = anAttrList.begin(); diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 857c634d4..1d5a8332d 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -347,9 +347,11 @@ bool SketchSolver_Storage::isEntityFixed(const Slvs_hEntity& theEntityID, bool t return true; } } - // 2. The line is used in Parallel/Perpendicular and Length constraints + // 2. The line is used in Parallel/Perpendicular/Vertical/Horizontal and Length constraints aList = getConstraintsByType(SLVS_C_PARALLEL); aList.splice(aList.end(), getConstraintsByType(SLVS_C_PERPENDICULAR)); + aList.splice(aList.end(), getConstraintsByType(SLVS_C_VERTICAL)); + aList.splice(aList.end(), getConstraintsByType(SLVS_C_HORIZONTAL)); for (anIt = aList.begin(); anIt != aList.end(); anIt++) if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) { Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA; -- 2.39.2