From: Renaud NEDELEC Date: Tue, 20 Oct 2015 14:43:13 +0000 (+0200) Subject: [PythonAPI / sketcher] added the setEqual method and the setLength test X-Git-Tag: V_2.1.0~206^2~82 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=55f7f421752c988daa93ba2b277d9845d2a2153c;p=modules%2Fshaper.git [PythonAPI / sketcher] added the setEqual method and the setLength test --- diff --git a/src/PythonAPI/CMakeLists.txt b/src/PythonAPI/CMakeLists.txt index 551a8506e..ae884173e 100644 --- a/src/PythonAPI/CMakeLists.txt +++ b/src/PythonAPI/CMakeLists.txt @@ -19,6 +19,8 @@ ADD_UNIT_TESTS( TestSketcherSetPerpendicular.py TestSketcherSetHorizontal.py TestSketcherSetVertical.py + TestSketcherSetLength.py TestSketcherSetRadius.py TestSketcherSetAngle.py + TestSketcherSetEqual.py ) diff --git a/src/PythonAPI/Test/TestSketcherSetEqual.py b/src/PythonAPI/Test/TestSketcherSetEqual.py new file mode 100644 index 000000000..65a7e3cae --- /dev/null +++ b/src/PythonAPI/Test/TestSketcherSetEqual.py @@ -0,0 +1,42 @@ +import unittest +import model +import math +import TestSketcher +from TestSketcher import SketcherTestCase + +class SketcherSetEqual(SketcherTestCase): + def test_length_equality(self): + # Set the constraint + l1 = self.sketch.addLine(0, 0, 0, 1) + l2 = self.sketch.addLine(0, 0, 1, 1) + self.sketch.setEqual(l1.result(), l2.result()) + # Commit the transaction + model.do() + # Check the result + length_1 = math.sqrt( + math.pow((l1.endPointData().x() - l1.startPointData().x()), 2) + + math.pow((l1.endPointData().y() - l1.startPointData().y()), 2) + ) + length_2 = math.sqrt( + math.pow((l1.endPointData().x() - l1.startPointData().x()), 2) + + math.pow((l2.endPointData().y() - l2.startPointData().y()), 2) + ) + self.assertAlmostEqual(length_1, length_2, delta=TestSketcher.DELTA) + + def test_radius_equality(self): + # Set the constraint + circle_1 = self.sketch.addCircle(0, 0, 10.0) + circle_2 = self.sketch.addCircle(1, 2, 25.0) + self.sketch.setEqual(circle_1.result(), circle_2.result()) + # Commit the transaction + model.do() + # Check the result + self.assertAlmostEqual( + circle_1.radiusData().value(), + circle_2.radiusData().value(), + delta=TestSketcher.DELTA + ) + +if __name__ == "__main__": + suite = unittest.TestLoader().loadTestsFromTestCase(SketcherSetEqual) + unittest.TextTestRunner(verbosity=2).run(suite) \ No newline at end of file diff --git a/src/PythonAPI/Test/TestSketcherSetLength.py b/src/PythonAPI/Test/TestSketcherSetLength.py new file mode 100644 index 000000000..b56650b9e --- /dev/null +++ b/src/PythonAPI/Test/TestSketcherSetLength.py @@ -0,0 +1,22 @@ +import unittest +import model +import math +import TestSketcher +from TestSketcher import SketcherTestCase + +class SketcherSetLength(SketcherTestCase): + def runTest(self): + # Set the constraint + line = self.sketch.addLine(0, 0, 0, 1) + self.sketch.setLength(line.result(), 25.0) + # Commit the transaction + model.do() + # Check the result + length = math.sqrt( + math.pow((line.endPointData().x() - line.startPointData().x()), 2) + + math.pow((line.endPointData().y() - line.startPointData().y()), 2) + ) + self.assertAlmostEqual(length, 25.0, delta=TestSketcher.DELTA) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/src/PythonAPI/model/sketcher/sketch.py b/src/PythonAPI/model/sketcher/sketch.py index 4a809f0b4..7ef6af552 100644 --- a/src/PythonAPI/model/sketcher/sketch.py +++ b/src/PythonAPI/model/sketcher/sketch.py @@ -160,6 +160,24 @@ class Sketch(): self._feature.execute() return constraint + def setRadius(self, circle, radius): + """Set the radius of the given circle and add the corresponding + constraint to this Sketch.""" + constraint = self._feature.addFeature("SketchConstraintRadius") + constraint.data().refattr("ConstraintEntityA").setObject(circle) + constraint.data().real("ConstraintValue").setValue(radius) + return constraint + + def setEqual(self, object_1, object_2): + """Set the radii of two circles or the length of two lines equal. + + The corresponding constraint is added to the sketch""" + constraint = self._feature.addFeature("SketchConstraintEqual") + constraint.data().refattr("ConstraintEntityA").setObject(object_1) + constraint.data().refattr("ConstraintEntityB").setObject(object_2) + self._feature.execute() + return constraint + def setAngle(self, line_1, line_2, angle): """Set the angle between the given 2 lines and add the corresponding constraint to the sketch.""" @@ -170,14 +188,6 @@ class Sketch(): self._feature.execute() return constraint - def setRadius(self, circle, radius): - """Set the radius of the given circle and add the corresponding - constraint to this Sketch.""" - constraint = self._feature.addFeature("SketchConstraintRadius") - constraint.data().refattr("ConstraintEntityA").setObject(circle) - constraint.data().real("ConstraintValue").setValue(radius) - return constraint - #------------------------------------------------------------- # # Edition of Dimensional Constraints