Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Rough draft of the sweep operation implementation. No unit tests yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwright committed Apr 26, 2016
1 parent 8dcc609 commit 3e12726
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cadquery/cq.py
Expand Up @@ -2055,6 +2055,24 @@ def revolve(self, angleDegrees=360.0, axisStart=None, axisEnd=None, combine=True
if clean: newS = newS.clean()
return newS

def sweep(self, path, combine=True, clean=True):
"""
Use all un-extruded wires in the parent chain to create a swept solid.
:param path: A wire along which the pending wires will be swept
:param boolean combine: True to combine the resulting solid with parent solids if found.
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
:return: a CQ object with the resulting solid selected.
"""

r = self._sweep(path.wire()) # returns a Solid (or a compound if there were multiple)
if combine:
newS = self._combineWithBase(r)
else:
newS = self.newObject([r])
if clean: newS = newS.clean()
return newS

def _combineWithBase(self, obj):
"""
Combines the provided object with the base solid, if one can be found.
Expand Down Expand Up @@ -2318,6 +2336,28 @@ def _revolve(self, angleDegrees, axisStart, axisEnd):

return Compound.makeCompound(toFuse)

def _sweep(self, path):
"""
Makes a swept solid from an existing set of pending wires.
:param path: A wire along which the pending wires will be swept
:return:a FreeCAD solid, suitable for boolean operations
"""

# group wires together into faces based on which ones are inside the others
# result is a list of lists
s = time.time()
wireSets = sortWiresByBuildOrder(list(self.ctx.pendingWires), self.plane, [])
# print "sorted wires in %d sec" % ( time.time() - s )
self.ctx.pendingWires = [] # now all of the wires have been used to create an extrusion

toFuse = []
for ws in wireSets:
thisObj = Solid.sweep(ws[0], ws[1:], path)
toFuse.append(thisObj)

return Compound.makeCompound(toFuse)

def box(self, length, width, height, centered=(True, True, True), combine=True, clean=True):
"""
Return a 3d box with specified dimensions for each object on the stack.
Expand Down
22 changes: 22 additions & 0 deletions cadquery/freecad_impl/shapes.py
Expand Up @@ -905,6 +905,28 @@ def revolve(cls, outerWire, innerWires, angleDegrees, axisStart, axisEnd):

return Shape.cast(result)

@classmethod
def sweep(cls, outerWire, innerWires, path):
"""
Attempt to sweep the list of wires into a prismatic solid along the provided path
:param outerWire: the outermost wire
:param innerWires: a list of inner wires
:param path: The wire to sweep the face resulting from the wires over
:return: a Solid object
"""

# FreeCAD allows this in one operation, but others might not
freeCADWires = [outerWire.wrapped]
for w in innerWires:
freeCADWires.append(w.wrapped)

# f = FreeCADPart.Face(freeCADWires)
wire = FreeCADPart.Wire([path.val().wrapped])
result = wire.makePipeShell(freeCADWires, True, True)

return Shape.cast(result)

def tessellate(self, tolerance):
return self.wrapped.tessellate(tolerance)

Expand Down

0 comments on commit 3e12726

Please sign in to comment.