From 28038c772769f15a06376fa01d55529e7daa1aa9 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 2 Feb 2018 07:47:44 +0300 Subject: [PATCH] Issue #2376: Wrong DoF when creating the sketch Remove the supporting elements while deleting Distance constraint --- src/SketchPlugin/Test/Test2376.py | 56 +++++++++++++++++++ .../SketchSolver_ConstraintDistance.cpp | 9 +++ .../SketchSolver_ConstraintDistance.h | 3 + 3 files changed, 68 insertions(+) create mode 100644 src/SketchPlugin/Test/Test2376.py diff --git a/src/SketchPlugin/Test/Test2376.py b/src/SketchPlugin/Test/Test2376.py new file mode 100644 index 000000000..98fd0413c --- /dev/null +++ b/src/SketchPlugin/Test/Test2376.py @@ -0,0 +1,56 @@ +## Copyright (C) 2018-20xx CEA/DEN, EDF R&D +## +## This library is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with this library; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## +## See http:##www.salome-platform.org/ or +## email : webmaster.salome@opencascade.com +## + +""" + Test2376.py + Test case for issue #2376 "Wrong DoF when creating the sketch" +""" + + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(20, 25, 50, 25) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "OX"), False) +SketchLine_2 = SketchProjection_1.createdFeature() +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.endPoint(), SketchLine_2.result(), 25, True) +model.do() + +SKETCH_DOF = 2 +model.checkSketch(Sketch_1, SKETCH_DOF) + +# add one more distance constraint, DoF should be the same +SketchConstraintDistance_2 = Sketch_1.setDistance(SketchLine_1.startPoint(), SketchLine_2.result(), 25, True) +model.do() +model.checkSketch(Sketch_1, SKETCH_DOF) +# TODO: following line should be uncommented when PlanGCS will be able to determine over-constraint in this case +#assert Sketch_1.solverError().value() != "", "FAILED: Sketch should report over-constrained situation" + +# remove last constraint +partSet.removeFeature(SketchConstraintDistance_2.feature()) +model.do() +model.checkSketch(Sketch_1, SKETCH_DOF) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp index 4aa15648d..940ecff5c 100644 --- a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp @@ -87,6 +87,12 @@ void SketchSolver_ConstraintDistance::update() SketchSolver_Constraint::update(); } +bool SketchSolver_ConstraintDistance::remove() +{ + removeConstraintsKeepingSign(); + return SketchSolver_Constraint::remove(); +} + void SketchSolver_ConstraintDistance::addConstraintsToKeepSign() { std::shared_ptr aStorage = @@ -144,6 +150,9 @@ void SketchSolver_ConstraintDistance::addConstraintsToKeepSign() void SketchSolver_ConstraintDistance::removeConstraintsKeepingSign() { + if (!myOddPoint) + return; // no sign kept => nothing to remove + std::shared_ptr aStorage = std::dynamic_pointer_cast(myStorage); diff --git a/src/SketchSolver/SketchSolver_ConstraintDistance.h b/src/SketchSolver/SketchSolver_ConstraintDistance.h index b11ab1ea3..5ab3b011e 100644 --- a/src/SketchSolver/SketchSolver_ConstraintDistance.h +++ b/src/SketchSolver/SketchSolver_ConstraintDistance.h @@ -40,6 +40,9 @@ public: /// \brief Update constraint virtual void update(); + /// \brief Remove constraint + virtual bool remove(); + protected: /// \brief Generate list of attributes of constraint in order useful for constraints /// \param[out] theValue numerical characteristic of constraint (e.g. distance) -- 2.39.2