From: azv Date: Thu, 16 Apr 2015 13:51:50 +0000 (+0300) Subject: Issue #463: Fillet constraint - closed line is destroyed X-Git-Tag: V_1.1.0~23^2^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b4ac67b9f60f47507f1879649045230a29117c29;p=modules%2Fshaper.git Issue #463: Fillet constraint - closed line is destroyed Allow to move fillet components --- diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index a7f8d5b48..e630978ec 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -411,8 +411,18 @@ bool SketchSolver_Group::resolveConstraints() try { if (myStorage->hasDuplicatedConstraint()) aResult = SLVS_RESULT_INCONSISTENT; - else - aResult = myConstrSolver.solve(); + else { + // To avoid overconstraint situation, we will remove temporary constraints one-by-one + // and try to find the case without overconstraint + int aNbTemp = (int)myTempConstraints.size(); + while (true) { + aResult = myConstrSolver.solve(); + if (aResult == SLVS_RESULT_OKAY || aNbTemp <= 0) + break; + aNbTemp = myStorage->removeFirstTemporaryConstraint(); + myStorage->initializeSolver(myConstrSolver); + } + } } catch (...) { Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this); return false; diff --git a/src/SketchSolver/SketchSolver_Solver.cpp b/src/SketchSolver/SketchSolver_Solver.cpp index 0e7b1761c..4e7a4f0e9 100644 --- a/src/SketchSolver/SketchSolver_Solver.cpp +++ b/src/SketchSolver/SketchSolver_Solver.cpp @@ -63,8 +63,10 @@ void SketchSolver_Solver::setConstraints(Slvs_Constraint* theConstraints, int th myEquationsSystem.constraints = theSize; } else if (myEquationsSystem.constraints != theSize) { - delete[] myEquationsSystem.constraint; - myEquationsSystem.constraint = new Slvs_Constraint[theSize]; + if (theSize > myEquationsSystem.constraints) { + delete[] myEquationsSystem.constraint; + myEquationsSystem.constraint = new Slvs_Constraint[theSize]; + } myEquationsSystem.constraints = theSize; } memcpy(myEquationsSystem.constraint, theConstraints, theSize * sizeof(Slvs_Constraint)); diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 1d5a8332d..250ce7e56 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -546,6 +546,15 @@ void SketchSolver_Storage::removeTemporaryConstraints() myTemporaryConstraints.clear(); } +int SketchSolver_Storage::removeFirstTemporaryConstraint() +{ + if (myTemporaryConstraints.empty()) + return 0; + removeConstraint(*myTemporaryConstraints.begin()); + myTemporaryConstraints.erase(myTemporaryConstraints.begin()); + return (int)myTemporaryConstraints.size(); +} + bool SketchSolver_Storage::isTemporary(const Slvs_hConstraint& theConstraintID) const { return myTemporaryConstraints.find(theConstraintID) != myTemporaryConstraints.end(); diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index fbd9acf64..fc2e46ceb 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -108,6 +108,9 @@ public: void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID); /// \brief Remove all transient constraints void removeTemporaryConstraints(); + /// \brief Remove first temporary constraint + /// \return Number of remaining temporary constraints + int removeFirstTemporaryConstraint(); /// \brief Checks the constraint is temporary bool isTemporary(const Slvs_hConstraint& theConstraintID) const;