From: azv Date: Thu, 30 Mar 2017 08:03:04 +0000 (+0300) Subject: Correct DoF calculation when adding new entity into fully constrained sketch X-Git-Tag: V_2.7.0~133 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17260a8b88563eb84b46c9ae0567c36369e165f9;p=modules%2Fshaper.git Correct DoF calculation when adding new entity into fully constrained sketch --- 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;