diff --git a/cadquery/cq.py b/cadquery/cq.py index 4f87f64..0bf1548 100644 --- a/cadquery/cq.py +++ b/cadquery/cq.py @@ -2055,7 +2055,7 @@ class Workplane(CQ): if clean: newS = newS.clean() return newS - def sweep(self, path, combine=True, clean=True): + def sweep(self, path, makeSolid=True, isFrenet=False, combine=True, clean=True): """ Use all un-extruded wires in the parent chain to create a swept solid. @@ -2065,7 +2065,7 @@ class Workplane(CQ): :return: a CQ object with the resulting solid selected. """ - r = self._sweep(path.wire()) # returns a Solid (or a compound if there were multiple) + r = self._sweep(path.wire(), makeSolid, isFrenet) # returns a Solid (or a compound if there were multiple) if combine: newS = self._combineWithBase(r) else: @@ -2336,7 +2336,7 @@ class Workplane(CQ): return Compound.makeCompound(toFuse) - def _sweep(self, path): + def _sweep(self, path, makeSolid=True, isFrenet=False): """ Makes a swept solid from an existing set of pending wires. @@ -2353,7 +2353,7 @@ class Workplane(CQ): toFuse = [] for ws in wireSets: - thisObj = Solid.sweep(ws[0], ws[1:], path) + thisObj = Solid.sweep(ws[0], ws[1:], path, makeSolid, isFrenet) toFuse.append(thisObj) return Compound.makeCompound(toFuse) diff --git a/cadquery/freecad_impl/shapes.py b/cadquery/freecad_impl/shapes.py index 4c823f1..e486709 100644 --- a/cadquery/freecad_impl/shapes.py +++ b/cadquery/freecad_impl/shapes.py @@ -906,7 +906,7 @@ class Solid(Shape): return Shape.cast(result) @classmethod - def sweep(cls, outerWire, innerWires, path): + def sweep(cls, outerWire, innerWires, path, makeSolid=True, isFrenet=False): """ Attempt to sweep the list of wires into a prismatic solid along the provided path @@ -923,7 +923,7 @@ class Solid(Shape): # f = FreeCADPart.Face(freeCADWires) wire = FreeCADPart.Wire([path.val().wrapped]) - result = wire.makePipeShell(freeCADWires, True, True) + result = wire.makePipeShell(freeCADWires, makeSolid, isFrenet) return Shape.cast(result) diff --git a/doc/_static/PillowBlock.PNG b/doc/_static/parametric-pillowblock-screencap.png similarity index 100% rename from doc/_static/PillowBlock.PNG rename to doc/_static/parametric-pillowblock-screencap.png diff --git a/tests/TestCadQuery.py b/tests/TestCadQuery.py index f8b9b2a..7947ee1 100644 --- a/tests/TestCadQuery.py +++ b/tests/TestCadQuery.py @@ -349,6 +349,60 @@ class TestCadQuery(BaseTest): self.assertEqual(2, result.vertices().size()) self.assertEqual(3, result.edges().size()) + def testSweep(self): + """ + Tests the operation of sweeping a wire(s) along a path + """ + pts = [ + (0, 1), + (1, 2), + (2, 4) + ] + + # Spline path + path = Workplane("XZ").spline(pts) + + # Test defaults + result = Workplane("XY").circle(1.0).sweep(path) + self.assertEqual(3, result.faces().size()) + self.assertEqual(3, result.edges().size()) + + # Test with makeSolid False + result = Workplane("XY").circle(1.0).sweep(path, makeSolid=False) + self.assertEqual(1, result.faces().size()) + self.assertEqual(3, result.edges().size()) + + # Test with isFrenet True + result = Workplane("XY").circle(1.0).sweep(path, isFrenet=True) + self.assertEqual(3, result.faces().size()) + self.assertEqual(3, result.edges().size()) + + # Test with makeSolid False and isFrenet True + result = Workplane("XY").circle(1.0).sweep(path, makeSolid=False, isFrenet=True) + self.assertEqual(1, result.faces().size()) + self.assertEqual(3, result.edges().size()) + + # Test rectangle with defaults + result = Workplane("XY").rect(1.0, 1.0).sweep(path) + self.assertEqual(6, result.faces().size()) + self.assertEqual(12, result.edges().size()) + + # Polyline path + path = Workplane("XZ").polyline(pts) + + # Test defaults + result = Workplane("XY").circle(0.1).sweep(path) + self.assertEqual(5, result.faces().size()) + self.assertEqual(7, result.edges().size()) + + # Arc path + path = Workplane("XZ").threePointArc((1.0, 1.5),(0.0, 1.0)) + + # Test defaults + result = Workplane("XY").circle(0.1).sweep(path) + self.assertEqual(3, result.faces().size()) + self.assertEqual(3, result.edges().size()) + def testTwistExtrude(self): """ Tests extrusion while twisting through an angle.