class SketcherAddLineTestCase(SketcherTestCase):
def runTest(self):
- self.sketch.addLine(0, 0, 0, 1)
+ line = self.sketch.addLine(0, 0, 0, 1)
+ self.assertEqual(line.startPointData().x(), line.endPointData().x())
+ self.assertNotEqual(line.startPointData().y(), line.endPointData().y())
+
if __name__ == "__main__":
unittest.main()
\ No newline at end of file
from GeomDataAPI import geomDataAPI_Point2D
-
-class Line():
-
- def __init__(self, sketch, *args):
- self.my = sketch.addFeature("SketchLine")
- if len(args) == 4:
- self.__createByCoordinates(*args)
- elif len(args) == 2:
- self.__createByPoints(*args)
- elif len(args) == 1:
- self.__createByName(sketch, *args)
- else:
- raise Exception("cannot create the Line")
-
- def __createByCoordinates(self, x1, y1, x2, y2):
- geomDataAPI_Point2D( self.my.data().attribute("StartPoint") ).setValue(x1, y1)
- geomDataAPI_Point2D( self.my.data().attribute("EndPoint") ).setValue(x2, y2)
- self.my.execute()
-
- def __createByPoints(self, p1, p2):
- geomDataAPI_Point2D( self.my.data().attribute("StartPoint") ).setValue(p1.x(), p1.y())
- geomDataAPI_Point2D( self.my.data().attribute("EndPoint") ).setValue(p2.x(), p2.y())
- self.my.execute()
-
- def __createByName(self, sketch, name):
- self.my.data().selection("External").selectSubShape("EDGE", name)
- self.my.execute()
- rigid = sketch.addFeature("SketchConstraintRigid")
- rigid.refattr("ConstraintEntityA").setObject( self.my.firstResult() )
-
- def startPointData (self):
- return geomDataAPI_Point2D( self.my.data().attribute("StartPoint") )
-
- def endPointData (self):
- return geomDataAPI_Point2D( self.my.data().attribute("EndPoint") )
-
- def result (self):
- return self.my.firstResult()
\ No newline at end of file
+def addLine(sketch, *args):
+ sketch_feature = sketch.addFeature("SketchLine")
+ return LineInterface(sketch_feature, *args)
+
+
+class LineInterface():
+ """Interface for editing of a sketch line feature."""
+ def __init__(self, line_feature, *args):
+ self._feature = line_feature
+ self._start_point = geomDataAPI_Point2D(
+ self._feature.data().attribute("StartPoint")
+ )
+ self._end_point = geomDataAPI_Point2D(
+ self._feature.data().attribute("EndPoint")
+ )
+ if len(args) == 4:
+ self.__createByCoordinates(*args)
+ elif len(args) == 2:
+ self.__createByPoints(*args)
+ elif len(args) == 1:
+ self.__createByName(sketch, *args)
+ else:
+ raise Exception("cannot create the Line")
+
+ def __createByCoordinates(self, x1, y1, x2, y2):
+ self._start_point.setValue(x1, y1)
+ self._end_point.setValue(x2, y2)
+ self._feature.execute()
+
+ def __createByPoints(self, p1, p2):
+ self._start_point.setValue(p1.x(), p1.y())
+ self._end_point.setValue(p2.x(), p2.y())
+ self._feature.execute()
+
+ def __createByName(self, sketch, name):
+ self._feature.data().selection("External").selectSubShape("EDGE", name)
+ self._feature.execute()
+ rigid = sketch.addFeature("SketchConstraintRigid")
+ rigid.refattr("ConstraintEntityA").setObject( self._feature.firstResult() )
+
+ def startPointData (self):
+ return self._start_point
+
+ def endPointData (self):
+ return self._end_point
+
+ def result (self):
+ return self._feature.firstResult()
\ No newline at end of file
-# Class definitions of Sketch features
+"""Sketch point feature interface."""
from GeomDataAPI import geomDataAPI_Point2D
-class Point():
+def addPoint(sketch, x, y):
+ """Add a sketch point feature to the sketch.
+
+ :return: Interface object on this feature
+ :rtype: sketcher.Point
+ """
+ sketch_point_feature = sketch.addFeature("SketchPoint")
+ return PointInterface(sketch_feature, x, y)
- def __init__(self, sketch, x, y):
- self.my = sketch.addFeature("SketchPoint")
- geomDataAPI_Point2D( self.my.data().attribute("PointCoordindates") ).setValue(x, y)
- self.my.execute()
- def pointData (self):
- return geomDataAPI_Point2D( self.my.data().attribute("PointCoordindates") )
+class PointInterface():
+ """Interface on point feature for data manipulation."""
+ def __init__(self, point_feature, x, y):
+ self._point_feature = point_feature
+ self._point_data = geomDataAPI_Point2D(
+ self._point_feature.data().attribute("PointCoordinates")
+ )
+ self._point_data.setValue(x, y)
+ self._point_feature.execute()
- def result (self):
- return self.my.firstResult()
+ def pointData (self):
+ """Return the point data."""
+ return self._point_data
+
+ def result (self):
+ """Return the feature result."""
+ return self._point_feature.firstResult()
from ModelAPI import *
from GeomDataAPI import *
from GeomAlgoAPI import *
-from modeler.sketcher.point import Point
-from modeler.sketcher.line import Line
+import modeler.sketcher.point as sk_point
+import modeler.sketcher.line as sk_line
from modeler.sketcher.circle import Circle
def addSketch(doc, plane):
- """Add a Sketch feature to the Part or PartSet.
+ """Add a Sketch feature to the Part or PartSet and return an interface
+ on it.
- A Sketch object is instanciated with the built feature
- it provides an interface for manipulating the feature data.
+ A Sketch object is instanciated with a feature as input parameter
+ it provides an interface for manipulation of the feature data.
:return: interface on the feature
:rtype: Sketch object"""
feature = featureToCompositeFeature( doc.addFeature("Sketch") )
- an existing face identified by its topological name.
"""
self._feature = feature
- self._selection = None # Entities used for building the result shape
- # self.resultype ="Face" # Type of Sketch result
+ self._selection = None # Entities used for building the result shape
+ # self.resultype ="Face" # Type of Sketch result
if isinstance(plane, str):
self.__sketchOnFace(plane)
else:
def addPoint (self, *args):
"""Adds a point to this Sketch."""
- return Point(self._feature, *args)
+ point_interface = sk_point.addPoint(self._feature, *args)
+ return point_interface
def addLine (self, *args):
"""Adds a line to this Sketch."""
- return Line(self._feature, *args)
+ line_interface = sk_line.addLine(self._feature, *args)
+ return line_interface
def addPolyline (self, *coords):
"""Adds a poly-line to this Sketch.
+
The end of consecutive segments are defined as coincident.
"""
c0 = coords[0]
# Adding and connecting next lines
for c2 in coords[2:]:
line_2 = self.addLine(c1, c2)
- self.setCoincident( line_1.endPointData(), line_2.startPointData() )
+ self.setCoincident(line_1.endPointData(), line_2.startPointData())
polyline.append(line_2)
c1 = c2
line_1 = line_2
# Getters
def selectFace (self, *args):
- """Selects the geometrical entities of this Sketch on which the result Face must be built.
- When no entity is given, the face is based on all existing geometry of this Sketch.
+ """Select the geometrical entities of this Sketch on which
+ the result Face must be built.
+
+ When no entity is given, the face is based on all existing
+ geometry of this Sketch.
"""
#self.resultype ="Face"
if len(args) == 0:
- self._selection = modelAPI_ResultConstruction( self._feature.firstResult() ).shape()
+ self._selection = modelAPI_ResultConstruction(
+ self._feature.firstResult()).shape()
elif len(args) == 1:
self._selection = args[0].shape()
else: