From 6b48364b1da91a4958ce92d392e8bc49a3cbd7a2 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 27 Nov 2018 11:16:40 +0300 Subject: [PATCH] Issue #2741: Undo of distance argument change produces crash Precise processing additional constraints keeping sign of Distance constraint. --- src/SketchAPI/SketchAPI_Constraint.cpp | 25 +++++++++++ src/SketchAPI/SketchAPI_Constraint.h | 9 ++++ src/SketchPlugin/CMakeLists.txt | 1 + src/SketchPlugin/Test/Test2741.py | 44 +++++++++++++++++++ .../SketchSolver_ConstraintDistance.cpp | 8 +++- 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/SketchPlugin/Test/Test2741.py diff --git a/src/SketchAPI/SketchAPI_Constraint.cpp b/src/SketchAPI/SketchAPI_Constraint.cpp index 82b5dfab4..d9edb13de 100644 --- a/src/SketchAPI/SketchAPI_Constraint.cpp +++ b/src/SketchAPI/SketchAPI_Constraint.cpp @@ -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()) { diff --git a/src/SketchAPI/SketchAPI_Constraint.h b/src/SketchAPI/SketchAPI_Constraint.h index 2ad165065..958bbdae3 100644 --- a/src/SketchAPI/SketchAPI_Constraint.h +++ b/src/SketchAPI/SketchAPI_Constraint.h @@ -29,6 +29,8 @@ #include +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; diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 2682d7b85..5a0f477a3 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -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 index 000000000..549f5af67 --- /dev/null +++ b/src/SketchPlugin/Test/Test2741.py @@ -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 +## + +""" + 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() diff --git a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp index 44daa41fa..1f827a3c6 100644 --- a/src/SketchSolver/SketchSolver_ConstraintDistance.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintDistance.cpp @@ -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); -- 2.39.2