]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2741: Undo of distance argument change produces crash
authorazv <azv@opencascade.com>
Tue, 27 Nov 2018 08:16:40 +0000 (11:16 +0300)
committerazv <azv@opencascade.com>
Tue, 27 Nov 2018 08:16:40 +0000 (11:16 +0300)
Precise processing additional constraints keeping sign of Distance constraint.

src/SketchAPI/SketchAPI_Constraint.cpp
src/SketchAPI/SketchAPI_Constraint.h
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/Test/Test2741.py [new file with mode: 0644]
src/SketchSolver/SketchSolver_ConstraintDistance.cpp

index 82b5dfab474f323c0f1634ec230e4b25c5f98cfa..d9edb13de83dc5627dfa1da7dd8d2a830ddccd48 100644 (file)
@@ -66,6 +66,31 @@ bool SketchAPI_Constraint::initialize()
   return true;
 }
 
+void SketchAPI_Constraint::setEntityA(const ModelHighAPI_RefAttr& theEntity)
+{
+  fillAttribute(theEntity, feature()->refattr(SketchPlugin_Constraint::ENTITY_A()));
+}
+
+void SketchAPI_Constraint::setEntityB(const ModelHighAPI_RefAttr& theEntity)
+{
+  fillAttribute(theEntity, feature()->refattr(SketchPlugin_Constraint::ENTITY_B()));
+}
+
+void SketchAPI_Constraint::setEntityC(const ModelHighAPI_RefAttr& theEntity)
+{
+  fillAttribute(theEntity, feature()->refattr(SketchPlugin_Constraint::ENTITY_C()));
+}
+
+void SketchAPI_Constraint::setEntityD(const ModelHighAPI_RefAttr& theEntity)
+{
+  fillAttribute(theEntity, feature()->refattr(SketchPlugin_Constraint::ENTITY_D()));
+}
+
+void SketchAPI_Constraint::setValue(const ModelHighAPI_Double& theValue)
+{
+  fillAttribute(theValue, feature()->real(SketchPlugin_Constraint::VALUE()));
+}
+
 static const std::string& constraintTypeToSetter(const std::string& theType)
 {
   if (theType == SketchPlugin_ConstraintCoincidence::ID()) {
index 2ad1650650635f2ec363d3bc1b2dc98c2be918a7..958bbdae31c810b98bd36a9e4bfdc95ac3d11669 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <SketchPlugin_Constraint.h>
 
+class ModelHighAPI_Double;
+
 /**\class SketchAPI_Constraint
  * \ingroup CPPHighAPI
  * \brief Interface for Constraint feature
@@ -54,6 +56,13 @@ public:
   SKETCHAPI_EXPORT
   bool initialize();
 
+  SKETCHAPI_EXPORT void setEntityA(const ModelHighAPI_RefAttr& theEntity);
+  SKETCHAPI_EXPORT void setEntityB(const ModelHighAPI_RefAttr& theEntity);
+  SKETCHAPI_EXPORT void setEntityC(const ModelHighAPI_RefAttr& theEntity);
+  SKETCHAPI_EXPORT void setEntityD(const ModelHighAPI_RefAttr& theEntity);
+
+  SKETCHAPI_EXPORT void setValue(const ModelHighAPI_Double& theValue);
+
   /// Dump wrapped feature
   SKETCHAPI_EXPORT
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
index 2682d7b85dda6445e28d7782dc643c35f1db3102..5a0f477a34fcfbe37e22e66e559b1c95ee54cda6 100644 (file)
@@ -188,6 +188,7 @@ ADD_UNIT_TESTS(
   Test2481.py
   Test2654.py
   Test2711.py
+  Test2741.py
   TestArcBehavior.py
   TestConstraintAngle.py
   TestConstraintCoincidence.py
diff --git a/src/SketchPlugin/Test/Test2741.py b/src/SketchPlugin/Test/Test2741.py
new file mode 100644 (file)
index 0000000..549f5af
--- /dev/null
@@ -0,0 +1,44 @@
+## 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>
+##
+
+"""
+    Test2741.py
+    Test case for issue #2741 "Undo of distance argument change produces crash"
+"""
+
+from salome.shaper import model
+from SketchAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(-34.48932587013569, -5.994823429605995, -23.03828378136105, 27.99739301876914)
+SketchLine_2 = Sketch_1.addLine(-23.03828378136105, 27.99739301876914, -14.34307552407934, -3.849202930145424)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.startPoint(), SketchLine_2.result(), 20, True)
+model.do()
+
+# Change point-line distance constraint to point-point distance
+SketchAPI_Constraint(SketchConstraintDistance_1).setEntityB(SketchLine_2.endPoint())
+model.do()
+model.end()
+
+# Check no crash on undo distance changing
+model.undo()
index 44daa41fa087f4bc2ca6f908497ea2bdb69a7be5..1f827a3c637b279b4b2ea6bfa56a99ea96897757 100644 (file)
@@ -167,8 +167,12 @@ void SketchSolver_ConstraintDistance::removeConstraintsKeepingSign()
   aParams.insert(myOddPoint->y);
   aStorage->removeParameters(aParams);
 
-  aGCSConstraints.pop_back();
-  aGCSConstraints.pop_back();
+  // remove constraints keeping sign of point-line distance,
+  // not more than 2 additional constraints is possible
+  if (!aGCSConstraints.empty())
+    aGCSConstraints.pop_back();
+  if (!aGCSConstraints.empty())
+    aGCSConstraints.pop_back();
   aConstraint->setConstraints(aGCSConstraints);
   aStorage->addConstraint(myBaseConstraint, aConstraint);