]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update dumping of Horizontal/Vertical Distance constraint which value is set by parameter
authorazv <azv@opencascade.com>
Mon, 18 Dec 2017 07:30:01 +0000 (10:30 +0300)
committerazv <azv@opencascade.com>
Mon, 18 Dec 2017 07:45:52 +0000 (10:45 +0300)
src/SketchAPI/SketchAPI_Constraint.cpp
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/Test/TestDistanceDump.py [new file with mode: 0644]

index 5098ce99f5b6896b7e8d9f62ac3c5ffb7d4a1c89..82b5dfab474f323c0f1634ec230e4b25c5f98cfa 100644 (file)
@@ -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;
 
index 5f36a0872b89739ee9b13bbe9dfe7da691049ed7..63e7a10f451ac8b68b5728ecb1e82a98bb9cbab8 100644 (file)
@@ -671,7 +671,8 @@ std::shared_ptr<ModelHighAPI_Interface> 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<ModelHighAPI_Interface> 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));
 }
index c0e7415007d85c9bc2b6fe4cf67224f45c87c50d..c49b4913023edcb1a934f9b8298b6319dbf8ae2e 100644 (file)
@@ -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 (file)
index 0000000..c8375f5
--- /dev/null
@@ -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<mailto: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())