From ed0f9183c30d963482df80a8f550ef132e430982 Mon Sep 17 00:00:00 2001 From: azv Date: Mon, 18 Dec 2017 10:30:01 +0300 Subject: [PATCH] Update dumping of Horizontal/Vertical Distance constraint which value is set by parameter --- src/SketchAPI/SketchAPI_Constraint.cpp | 10 ++++- src/SketchAPI/SketchAPI_Sketch.cpp | 6 ++- src/SketchPlugin/CMakeLists.txt | 1 + src/SketchPlugin/Test/TestDistanceDump.py | 55 +++++++++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 src/SketchPlugin/Test/TestDistanceDump.py diff --git a/src/SketchAPI/SketchAPI_Constraint.cpp b/src/SketchAPI/SketchAPI_Constraint.cpp index 5098ce99f..82b5dfab4 100644 --- a/src/SketchAPI/SketchAPI_Constraint.cpp +++ b/src/SketchAPI/SketchAPI_Constraint.cpp @@ -199,8 +199,14 @@ void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const } } - AttributeDoublePtr aValueAttr = aBase->real( - isAngle ? SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() :SketchPlugin_Constraint::VALUE()); + AttributeDoublePtr aValueAttr; + if (isAngle) + aValueAttr = aBase->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()); + else if (aBase->getKind() == SketchPlugin_ConstraintDistanceHorizontal::ID() || + aBase->getKind() == SketchPlugin_ConstraintDistanceVertical::ID()) + aValueAttr = aBase->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()); + else + aValueAttr = aBase->real(SketchPlugin_Constraint::VALUE()); if (aValueAttr && aValueAttr->isInitialized()) theDumper << ", " << aValueAttr; diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 5f36a0872..63e7a10f4 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -671,7 +671,8 @@ std::shared_ptr SketchAPI_Sketch::setHorizontalDistance( compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceHorizontal::ID()); fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); - fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE())); + fillAttribute(theValue, + aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID())); aFeature->execute(); return InterfacePtr(new ModelHighAPI_Interface(aFeature)); } @@ -685,7 +686,8 @@ std::shared_ptr SketchAPI_Sketch::setVerticalDistance( compositeFeature()->addFeature(SketchPlugin_ConstraintDistanceVertical::ID()); fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); - fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE())); + fillAttribute(theValue, + aFeature->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID())); aFeature->execute(); return InterfacePtr(new ModelHighAPI_Interface(aFeature)); } diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index c0e741500..c49b49130 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -217,6 +217,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestTrimLine02.py Test2229.py Test2239.py + TestDistanceDump.py TestDistanceSignedVsUnsigned01.py TestDistanceSignedVsUnsigned02.py TestDistanceSignedVsUnsigned03.py diff --git a/src/SketchPlugin/Test/TestDistanceDump.py b/src/SketchPlugin/Test/TestDistanceDump.py new file mode 100644 index 000000000..c8375f581 --- /dev/null +++ b/src/SketchPlugin/Test/TestDistanceDump.py @@ -0,0 +1,55 @@ +## Copyright (C) 2014-2017 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 +## + +""" + TestDistanceDump.py + + Check that distances set by parameters are dumped correctly +""" + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Parameter_1 = model.addParameter(Part_1_doc, "a", "10") +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(22.18754371333437, 31.96766851898132, 36.16301361286303, 24.640865178987) +SketchLine_2 = Sketch_1.addLine(36.16301361286303, 24.640865178987, 45.95667186595785, 26.6618199092043) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(45.95667186595785, 26.6618199092043, 55.95667186595785, 16.6618199092043) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.startPoint(), SketchLine_2.result(), Parameter_1.name().value(), True) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), Parameter_1.name().value()) +SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_2.endPoint(), SketchLine_3.endPoint(), Parameter_1.name().value()) +SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_2.endPoint(), SketchLine_3.endPoint(), Parameter_1.name().value()) +model.do() +model.end() + +def assertEqual(str1, str2): + assert(str1 == str2), "{} != {}".format(str1, str2) + +assertEqual(SketchConstraintDistance_1.feature().real("ConstraintValue").text(), Parameter_1.name().value()) +assertEqual(SketchConstraintLength_1.feature().real("ConstraintValue").text(), Parameter_1.name().value()) +assertEqual(SketchConstraintDistanceHorizontal_1.feature().real("DistanceValue").text(), Parameter_1.name().value()) +assertEqual(SketchConstraintDistanceVertical_1.feature().real("DistanceValue").text(), Parameter_1.name().value()) + +assert(model.checkPythonDump()) -- 2.39.2