From 16da03ec50245f8793ab79967732ae9779a36e08 Mon Sep 17 00:00:00 2001 From: Renaud NEDELEC Date: Thu, 5 Nov 2015 15:46:30 +0100 Subject: [PATCH] [PythonAPI] Sketch circle interface modification (example of new API style discussed with DBC) --- src/PythonAPI/Test/TestSketcherAddCircle.py | 12 ++++++------ src/PythonAPI/Test/TestSketcherSetRadius.py | 8 ++++---- src/PythonAPI/model/sketcher/circle.py | 14 +++++++++----- src/PythonAPI/model/sketcher/sketch.py | 12 +++++++++++- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/PythonAPI/Test/TestSketcherAddCircle.py b/src/PythonAPI/Test/TestSketcherAddCircle.py index 932bb6881..9bc6e4c9d 100644 --- a/src/PythonAPI/Test/TestSketcherAddCircle.py +++ b/src/PythonAPI/Test/TestSketcherAddCircle.py @@ -6,9 +6,9 @@ class SketcherAddCircle(SketcherTestCase): def test_add_cricle(self): circle = self.sketch.addCircle(0, 10, 20) model.do() - self.assertEqual(circle.centerData().x(), 0.0) - self.assertEqual(circle.centerData().y(), 10.0) - self.assertEqual(circle.radiusData().value(), 20.0) + self.assertEqual(circle.center().x(), 0.0) + self.assertEqual(circle.center().y(), 10.0) + self.assertEqual(circle.radius(), 20.0) def test_modify_circle(self): circle = self.sketch.addCircle(0, 10, 20) @@ -16,9 +16,9 @@ class SketcherAddCircle(SketcherTestCase): circle.setCenter(10, 10) circle.setRadius(30) model.do() - self.assertEqual(circle.centerData().x(), 10.0) - self.assertEqual(circle.centerData().y(), 10.0) - self.assertEqual(circle.radiusData().value(), 30.0) + self.assertEqual(circle.center().x(), 10.0) + self.assertEqual(circle.center().y(), 10.0) + self.assertEqual(circle.radius(), 30.0) if __name__ == "__main__": diff --git a/src/PythonAPI/Test/TestSketcherSetRadius.py b/src/PythonAPI/Test/TestSketcherSetRadius.py index def397927..0cb6ad9a0 100644 --- a/src/PythonAPI/Test/TestSketcherSetRadius.py +++ b/src/PythonAPI/Test/TestSketcherSetRadius.py @@ -7,15 +7,15 @@ class SketcherSetRadius(SketcherTestCase): circle = self.sketch.addCircle(0, 10, 20) self.sketch.setRadius(circle.result(), 30) model.do() - self.assertEqual(circle.radiusData().value(), 30.0) + self.assertEqual(circle.radius(), 30.0) def test_modify_radius(self): circle = self.sketch.addCircle(0, 10, 20) - radius = self.sketch.setRadius(circle.result(), 30) + radius_constraint = self.sketch.setRadius(circle.result(), 30) model.do() - self.sketch.setValue(radius, 20) + self.sketch.setValue(radius_constraint, 20) model.do() - self.assertEqual(circle.radiusData().value(), 20.0) + self.assertEqual(circle.radius(), 20.0) if __name__ == "__main__": unittest.main(verbosity=2) \ No newline at end of file diff --git a/src/PythonAPI/model/sketcher/circle.py b/src/PythonAPI/model/sketcher/circle.py index c815ab110..a3ba89a1e 100644 --- a/src/PythonAPI/model/sketcher/circle.py +++ b/src/PythonAPI/model/sketcher/circle.py @@ -35,13 +35,17 @@ class Circle(Interface): """Set the radius of the circle.""" self._radius.setValue(radius) - def centerData(self): - """Return center data.""" + def center(self): + """Return the center attribute of the circle.""" return self._center - def radiusData(self): - """Return radius data.""" - return self._radius + def radius(self): + """Return the radius value. + + :return: radius + :rtype: double + """ + return self._radius.value() def result(self): """Return the cicular line attribute.""" diff --git a/src/PythonAPI/model/sketcher/sketch.py b/src/PythonAPI/model/sketcher/sketch.py index 1efd09d1d..447e17224 100644 --- a/src/PythonAPI/model/sketcher/sketch.py +++ b/src/PythonAPI/model/sketcher/sketch.py @@ -116,7 +116,16 @@ class Sketch(Interface): return Circle(circle_feature, *args) def addArc(self, *args): - """Add an arc to the sketch.""" + """Add an arc to the sketch. + + :param sequence args: A sequence of arguments that can be: + + * The center, start and end points + * The center, start and end points coordinates + :return: arc object + :rtype: :class:`model.sketcher.Arc` + :raises TypeError: if no argument is provided + """ if not args: raise TypeError("No arguments given") arc_feature = self._feature.addFeature("SketchArc") @@ -279,6 +288,7 @@ class Sketch(Interface): """Add a mirror transformation of the given objects to the sketch. This transformation is a constraint. + :return: interface to the constraint :rtype: Mirror object """ -- 2.39.2