From 17260a8b88563eb84b46c9ae0567c36369e165f9 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 30 Mar 2017 11:03:04 +0300 Subject: [PATCH] Correct DoF calculation when adding new entity into fully constrained sketch --- .../PlaneGCSSolver/PlaneGCSSolver_Solver.cpp | 10 ++++++++-- .../PlaneGCSSolver/PlaneGCSSolver_Solver.h | 3 +++ .../PlaneGCSSolver/PlaneGCSSolver_Storage.cpp | 4 ++++ src/SketchSolver/SketchSolver_ConstraintFixed.cpp | 13 ++++++++----- src/SketchSolver/SketchSolver_Group.cpp | 3 ++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp index 2be2d62b5..6681f2072 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp @@ -52,8 +52,8 @@ double* PlaneGCSSolver_Solver::createParameter() { double* aResult = new double(0); myParameters.push_back(aResult); - if (myDOF >= 0) - ++myDOF; + if (myConstraints.empty() && myDOF >= 0) + ++myDOF; // calculate DoF by hand if and only if there is no constraints yet return aResult; } @@ -133,3 +133,9 @@ int PlaneGCSSolver_Solver::dof() solve(); return myDOF; } + +void PlaneGCSSolver_Solver::diagnose() +{ + myEquationSystem->declareUnknowns(myParameters); + myDOF = myEquationSystem->diagnose(); +} diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h index 4da9e60dc..9ac6212f7 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h @@ -52,6 +52,9 @@ public: /// \brief Check the constraint is conflicted with others bool isConflicting(const ConstraintID& theConstraint) const; + /// \brief Check conflicting/redundant constraints and DoF + void diagnose(); + /// \brief Degrees of freedom int dof(); diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp index 472f4add7..69b62e970 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp @@ -57,6 +57,10 @@ void PlaneGCSSolver_Storage::addTemporaryConstraint( if (myConstraintMap.empty()) return; // no need to process temporary constraints if there is no active constraint + // before adding movement constraint to solver, re-check its DOF + if (mySketchSolver->dof() == 0) + mySketchSolver->diagnose(); + theSolverConstraint->setId(CID_MOVEMENT); constraintsToSolver(theSolverConstraint, mySketchSolver); } diff --git a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp index 41ba5d46b..721efb4a1 100644 --- a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp @@ -165,11 +165,14 @@ EntityWrapperPtr getChangedEntity(const FeaturePtr& theFeature, for (; aPIt != aPoints.end(); ++aPIt) { AttributePoint2DPtr aPnt = std::dynamic_pointer_cast(*aPIt); EntityWrapperPtr anEnt = theStorage->entity(*aPIt); - if (!anEnt) - continue; - PointWrapperPtr aPW = std::dynamic_pointer_cast(anEnt); - if (!isSameCoordinates(aPnt, aPW)) - aChangedPoints.push_back(anEnt); + if (anEnt) { + PointWrapperPtr aPW = std::dynamic_pointer_cast(anEnt); + if (!isSameCoordinates(aPnt, aPW)) + aChangedPoints.push_back(anEnt); + } else { + theStorage->update(*aPIt); + aChangedPoints.push_back(theStorage->entity(*aPIt)); + } } EntityWrapperPtr aChanged; diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 26b960e2a..fa98e284e 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -117,7 +117,8 @@ bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) bool SketchSolver_Group::moveFeature(FeaturePtr theFeature) { - if (myDOF == 0) { + bool isFeatureExists = (myStorage->entity(theFeature).get() != 0); + if (myDOF == 0 && isFeatureExists) { // avoid moving elements of fully constrained sketch myStorage->refresh(); return true; -- 2.39.2