Salome HOME
Issue #2376: Wrong DoF when creating the sketch
authorazv <azv@opencascade.com>
Fri, 2 Feb 2018 04:47:44 +0000 (07:47 +0300)
committerazv <azv@opencascade.com>
Fri, 2 Feb 2018 04:47:44 +0000 (07:47 +0300)
Remove the supporting elements while deleting Distance constraint

src/SketchPlugin/Test/Test2376.py [new file with mode: 0644]
src/SketchSolver/SketchSolver_ConstraintDistance.cpp
src/SketchSolver/SketchSolver_ConstraintDistance.h

diff --git a/src/SketchPlugin/Test/Test2376.py b/src/SketchPlugin/Test/Test2376.py
new file mode 100644 (file)
index 0000000..98fd041
--- /dev/null
@@ -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<mailto: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())
index 4aa15648da14c82c36c8e290a0d591224c0b5f60..940ecff5c9796bd6835afddcd9a8e938a058981c 100644 (file)
@@ -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<PlaneGCSSolver_Storage> 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<PlaneGCSSolver_Storage> aStorage =
       std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(myStorage);
 
index b11ab1ea317c36e45156392a3de5870847ea3b3b..5ab3b011ee2c6fed3ef7f550299e1867ac13b50d 100644 (file)
@@ -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)