ADD_UNIT_TESTS(
TestModeler.py
+ TestSketcherAddPoint.py
TestSketcherAddLine.py
+ TestSketcherAddArc.py
TestSketcherAddCircle.py
TestSketcherSetCoincident.py
TestSketcherSetParallel.py
--- /dev/null
+import unittest
+
+import modeler
+import geom
+from modeler import WrongNumberOfArguments
+
+from TestSketcher import SketcherTestCase
+
+class SketcherAddArc(SketcherTestCase):
+ def test_arc_by_coords(self):
+ arc = self.sketch.addArc(0, 1, 0, 0, 1, 1)
+ self.assertEqual(arc.startPointData().x(), 0)
+ self.assertEqual(arc.startPointData().y(), 0)
+
+ def test_arc_by_points(self):
+ center = geom.Pnt2d(0, 1)
+ start = geom.Pnt2d(0, 0)
+ end = geom.Pnt2d(0, 1)
+ arc = self.sketch.addArc(center, start, end)
+ self.assertEqual(arc.startPointData().x(), 0)
+ self.assertEqual(arc.startPointData().y(), 0)
+
+ def test_number_of_args(self):
+ with self.assertRaises(WrongNumberOfArguments):
+ self.sketch.addArc(0, 1, 1, 1)
+ with self.assertRaises(WrongNumberOfArguments):
+ self.sketch.addArc(0, 1)
+
+
+if __name__ == "__main__":
+ suite = unittest.TestLoader().loadTestsFromTestCase(SketcherAddArc)
+ unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
--- /dev/null
+import unittest
+import modeler
+from TestSketcher import SketcherTestCase
+
+class SketcherAddPoint(SketcherTestCase):
+ def runTest(self):
+ point = self.sketch.addPoint(0, 1)
+ self.assertEqual(point.pointData().x(), 0.0)
+ self.assertEqual(point.pointData().y(), 1.0)
+
+
+if __name__ == "__main__":
+ unittest.main()
\ No newline at end of file
from boolean import Addition as addAddition
from boolean import Subtraction as addSubtraction
from boolean import Intersection as addIntersection
+
+# Custom exceptions
+
+from errors import WrongNumberOfArguments
\ No newline at end of file
--- /dev/null
+# Package exceptions
+
+class ModelerError(Exception):
+ """Base class for exceptions in this package."""
+ pass
+
+class WrongNumberOfArguments(ModelerError):
+ """Exception raised when a wrong number of arguments is given."""
+ pass
+
+ #Attributes:
+ #expr -- input expression in which the error occurred
+ #msg -- explanation of the error
+ #"""
+
+ #def __init__(self, expr, msg):
+ #self.expr = expr
+ #self.msg = msg
--- /dev/null
+"""Sketch circle feature interface."""
+
+from GeomDataAPI import geomDataAPI_Point2D
+from modeler.errors import WrongNumberOfArguments
+
+class Arc():
+ def __init__(self, arc_feature, *args):
+ self._feature = arc_feature
+ self._center = geomDataAPI_Point2D(
+ self._feature.data().attribute("ArcCenter")
+ )
+ self._start_point = geomDataAPI_Point2D(
+ self._feature.data().attribute("ArcStartPoint")
+ )
+ self._end_point = geomDataAPI_Point2D(
+ self._feature.data().attribute("ArcEndPoint")
+ )
+ if len(args) == 6:
+ self.__createByCoordinates(*args)
+ elif len(args) == 3:
+ self.__createByPoints(*args)
+ else:
+ raise WrongNumberOfArguments(
+ "Arc takes 3 or 6 arguments (%s given)" % len(args)
+ )
+
+ def centerData (self):
+ return self._center
+
+ def startPointData (self):
+ return self._start_point
+
+ def endPointData (self):
+ return self._end_point
+
+ def result (self):
+ 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()
+
+ 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()
+
+
+
+
+
from modeler.sketcher.point import Point
from modeler.sketcher.line import Line
from modeler.sketcher.circle import Circle
+from modeler.sketcher.arc import Arc
def addSketch(doc, plane):
"""Add a Sketch feature to the Part or PartSet and return an interface
"""Add a circle to this Sketch."""
circle_feature = self._feature.addFeature("SketchCircle")
return Circle(circle_feature, *args)
+
+ def addArc (self, *args):
+ """Add an arc to this Sketch."""
+ arc_feature = self._feature.addFeature("SketchArc")
+ return Arc(arc_feature, *args)
def addPolyline (self, *coords):
"""Adds a poly-line to this Sketch.
/// Coordinates of the point
inline static const std::string& COORD_ID()
{
- static const std::string MY_COORD_ID("PointCoordindates");
+ static const std::string MY_COORD_ID("PointCoordinates");
return MY_COORD_ID;
}
/// Returns the kind of a feature