From 4cd0afc29e4e4360a7d8aa400c551978a90ba545 Mon Sep 17 00:00:00 2001 From: Jeremy Mack Wright Date: Tue, 13 Oct 2015 11:30:17 -0400 Subject: [PATCH] Changed polyline to work with a list of edges instead of a wire. --- cadquery/CQ.py | 36 +++++++++++++++++++++++------------- tests/TestCadQuery.py | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cadquery/CQ.py b/cadquery/CQ.py index 3c70a39..6d5425d 100644 --- a/cadquery/CQ.py +++ b/cadquery/CQ.py @@ -996,7 +996,7 @@ class Workplane(CQ): NOTE: """ - obj = self.objects[0] + obj = self.objects[-1] p = None if isinstance(obj, Edge): p = obj.endPoint() @@ -1657,23 +1657,33 @@ class Workplane(CQ): :param listOfXYTuple: a list of points in Workplane coordinates :type listOfXYTuple: list of 2-tuples - :param forConstruction: should the new wire be reference geometry only? - :type forConstruction: true if the wire is for reference, false if they are creating + :param forConstruction: whether or not the edges are used for reference + :type forConstruction: true if the edges are for reference, false if they are for creating geometry part geometry - :return: a new CQ object with the new wire on the stack + :return: a new CQ object with a list of edges on the stack *NOTE* most commonly, the resulting wire should be closed. - - Future Enhancement: - This should probably yield a list of edges, not a wire, so that - it is possible to combine a polyline with other edges and arcs """ - vecs = [self.plane.toWorldCoords(p) for p in listOfXYTuple] - w = Wire.makePolygon(vecs) - if not forConstruction: - self._addPendingWire(w) - return self.newObject([w]) + # Our list of new edges that will go into a new CQ object + p = [] + + # The very first startPoint comes from our original object, but not after that + startPoint = self._findFromPoint(False) + + # Draw a line for each set of points, starting from the from-point of the original CQ object + for curTuple in listOfXYTuple: + endPoint = self.plane.toWorldCoords(curTuple) + + p.append(Edge.makeLine(startPoint, endPoint)) + + # We need to move the start point for the next line that we draw or we get stuck at the same startPoint + startPoint = endPoint + + if not forConstruction: + self._addPendingEdge(p[-1]) + + return self.newObject(p) def close(self): """ diff --git a/tests/TestCadQuery.py b/tests/TestCadQuery.py index 438e20a..1d62c02 100644 --- a/tests/TestCadQuery.py +++ b/tests/TestCadQuery.py @@ -753,7 +753,7 @@ class TestCadQuery(BaseTest): r = Workplane("XY").polyline(points).mirrorX() self.assertEquals(1, r.wires().size()) - self.assertEquals(16, r.edges().size()) + self.assertEquals(18, r.edges().size()) # def testChainedMirror(self): # """