def test_arc_by_points(self):
center = geom.Pnt2d(0, 1)
start = geom.Pnt2d(0, 0)
- end = geom.Pnt2d(0, 1)
+ end = geom.Pnt2d(1, 1)
arc = self.sketch.addArc(center, start, end)
model.do()
self.assertEqual(arc.startPointData().x(), 0)
self.sketch.addArc(0, 1, 1, 1)
with self.assertRaises(WrongNumberOfArguments):
self.sketch.addArc(0, 1)
+
+ def test_modify_arc(self):
+ arc = self.sketch.addArc(0, 1, 0, 0, 1, 1)
+ arc.setCenter(0, 0)
+ arc.setStartPoint(-1.0, 0)
+ arc.setEndPoint(0, 1.0)
+ model.do()
+ self.assertEqual(arc.centerData().x(), 0)
+ self.assertEqual(arc.centerData().y(), 0)
+ self.assertEqual(arc.startPointData().x(), -1)
+ self.assertEqual(arc.startPointData().y(), 0)
+ self.assertEqual(arc.endPointData().x(), 0)
+ self.assertEqual(arc.endPointData().y(), 1)
if __name__ == "__main__":
from TestSketcher import SketcherTestCase
class SketcherAddCircle(SketcherTestCase):
- def runTest(self):
+ 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)
+ def test_modify_circle(self):
+ circle = self.sketch.addCircle(0, 10, 20)
+ model.do()
+ 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)
+
if __name__ == "__main__":
- unittest.main()
\ No newline at end of file
+ unittest.main(verbosity=2)
\ No newline at end of file
from TestSketcher import SketcherTestCase
class SketcherAddLine(SketcherTestCase):
- def runTest(self):
+ def test_add_line(self):
line = self.sketch.addLine(0, 0, 0, 1)
model.do()
- self.assertEqual(line.startPointData().x(), line.endPointData().x())
- self.assertNotEqual(line.startPointData().y(), line.endPointData().y())
-
-
+ self.assertEqual(line.getStartPoint().x(), line.getEndPoint().x())
+ self.assertNotEqual(line.getStartPoint().y(), line.getEndPoint().y())
+
+ def test_modify_line(self):
+ line = self.sketch.addLine(0, 0, 0, 1)
+ model.do()
+ line.setStartPoint(0, 1)
+ line.setEndPoint(1, 1)
+ self.assertEqual(line.getStartPoint().x(), 0)
+ self.assertEqual(line.getStartPoint().y(), 1)
+ self.assertEqual(line.getEndPoint().x(), 1)
+ self.assertEqual(line.getEndPoint().y(), 1)
+
+
if __name__ == "__main__":
- unittest.main()
\ No newline at end of file
+ unittest.main(verbosity=2)
\ No newline at end of file
self.assertEqual(point.pointData().x(), 0.0)
self.assertEqual(point.pointData().y(), 1.0)
+ def test_modify_point(self):
+ point = self.sketch.addPoint(0, 1)
+ point.setValue(1, 2)
+ model.do()
+ self.assertEqual(point.pointData().x(), 1.0)
+ self.assertEqual(point.pointData().y(), 2.0)
+
if __name__ == "__main__":
unittest.main(verbosity=2)
\ No newline at end of file
raise WrongNumberOfArguments(
"Arc takes 3 or 6 arguments (%s given)" % len(args)
)
+ self._execute()
+
+ ########
+ #
+ # Set methods
+ #
+ ########
+
+ def setCenter(self, x, y):
+ """Set arc center."""
+ self._center.setValue(x, y)
+
+ def setStartPoint(self, x, y):
+ """Set start point."""
+ self._start_point.setValue(x, y)
+
+ def setEndPoint(self, x, y):
+ """Set end point value."""
+ self._end_point.setValue(x, y)
+
+
+ ########
+ #
+ # Getters
+ #
+ ########
+
def centerData(self):
"""Return the center point data."""
"""Return the arc circular line attribute."""
return self._feature.lastResult()
+
########
#
# Private methods
#
########
+
def __createByCoordinates(self, center_x, center_y,
start_x, start_y,
end_x, end_y):
"""Create an arc by point coordinates."""
- self._center.setValue(center_x, center_y)
- self._start_point.setValue(start_x, start_y)
- self._end_point.setValue(end_x, end_y)
- self._feature.execute()
+ self.setCenter(center_x, center_y)
+ self.setStartPoint(start_x, start_y)
+ self.setEndPoint(end_x, end_y)
def __createByPoints(self, center, start, end):
"""Create an arc with point objects."""
- self._center.setValue(center.x(), center.y())
- self._start_point.setValue(start.x(), start.y())
- self._end_point.setValue(end.x(), end.y())
- self._feature.execute()
+ self.setCenter(center.x(), center.y())
+ self.setStartPoint(start.x(), start.y())
+ self.setEndPoint(end.x(), end.y())
class Circle(Interface):
"""Interface for circle feature data manipulation."""
- def __init__(self, feature, x, y, r):
+ def __init__(self, feature, x, y, radius):
Interface.__init__(self, feature)
assert(self._feature.getKind() == "SketchCircle")
self._feature.data().attribute("CircleCenter")
)
self._radius = self._feature.data().real("CircleRadius")
- self._center.setValue(x, y)
- self._radius.setValue(r)
+ self.setCenter(x, y)
+ self.setRadius(radius)
self.execute()
+ def setCenter(self, x, y):
+ """Set the center of the circle."""
+ self._center.setValue(x, y)
+
+ def setRadius(self, radius):
+ """Set the radius of the circle."""
+ self._radius.setValue(radius)
+
def centerData(self):
"""Return center data."""
return self._center
self._feature.data().attribute("EndPoint")
)
- assert(self._start_point)
- assert(self._end_point)
-
- if not args:
- return
-
- assert(len(args) in (1, 2, 4))
-
+ # Check that input arguments are not None
+ if args is None:
+ raise WrongNumberOfArguments(
+ "No argument given, at least one argument needed"
+ )
+
# Set attribute values and execute
if len(args) == 4:
self.__createByCoordinates(*args)
self.__createByPoints(*args)
elif len(args) == 1:
self.__createByName(*args)
-
+ else:
+ raise WrongNumberOfArguments(
+ "Arc takes 1, 2 or 4 arguments (%s given)" % len(args)
+ )
self._execute()
- pass
def __createByCoordinates(self, x1, y1, x2, y2):
- self._start_point.setValue(x1, y1)
- self._end_point.setValue(x2, y2)
- pass
+ self.setStartPoint(x1, y1)
+ self.setEndPoint(x2, y2)
def __createByPoints(self, p1, p2):
- self._start_point.setValue(p1.x(), p1.y())
- self._end_point.setValue(p2.x(), p2.y())
- pass
+ self.setStartPoint(p1.x(), p1.y())
+ self.setEndPoint(p2.x(), p2.y())
def __createByName(self, name):
self._feature.data().selection("External").selectSubShape("EDGE", name)
- pass
+
+ #######
+ #
+ # Set methods
+ #
+ #######
+
+ def setStartPoint(self, x, y):
+ """Set the start point of the line."""
+ self._start_point.setValue(x, y)
+
+ def setEndPoint(self, x, y):
+ """Set the end point of the line."""
+ self._end_point.setValue(x, y)
+ # TODO : methods below will be removed.
+ # Kept until all tests have been updated
def startPointData(self):
return self._start_point
self._point_data = geomDataAPI_Point2D(
self._feature.data().attribute("PointCoordinates")
)
+ self.setValue(x, y)
+ self._execute()
+
+ def setValue(self, x, y):
+ """Set point coordinates."""
self._point_data.setValue(x, y)
-
- # Control input and execute
- if self.areInputValid():
- self.execute()
- else:
- raise FeatureInputInvalid(
- "cannot create the Sketch Point, the input is invalid"
- )
def pointData (self):
"""Return the point data."""
"""Sketch Feature Interface
Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
+ finalized by Renaud Nedelec and Sergey Pokhodenko
Copyright (C) 2014-20xx CEA/DEN, EDF R&D
"""