Got revolution mostly working except for defaulting the axis of revolution end point if the user doesn't specify one.
This commit is contained in:
@ -1886,7 +1886,21 @@ class Workplane(CQ):
|
||||
* if combine is true, the value is combined with the context solid if it exists,
|
||||
and the resulting solid becomes the new context solid.
|
||||
"""
|
||||
r = self._revolve(angleDegrees) #returns a Solid ( or a compound if there were multiple )
|
||||
#Make sure we account for users specifying angles larger than 360 degrees
|
||||
angleDegrees = angleDegrees % 360
|
||||
|
||||
#Compensate for FreeCAD not assuming that a 0 degree revolve means a 360 degree revolve
|
||||
angleDegrees = 360 if angleDegrees == 0 else angleDegrees
|
||||
|
||||
#The default start point of the vector defining the axis of rotation will be the origin of the workplane
|
||||
if axisStart is None:
|
||||
axisStart = self.plane.origin.toTuple()
|
||||
|
||||
#The default end point of the vector defining the axis of rotation should be along the normal from the plane
|
||||
if axisEnd is None:
|
||||
axisEnd = (0, 1, 0)
|
||||
|
||||
r = self._revolve(angleDegrees, axisStart, axisEnd) #returns a Solid ( or a compound if there were multiple )
|
||||
if combine:
|
||||
return self._combineWithBase(r)
|
||||
else:
|
||||
@ -2129,7 +2143,7 @@ class Workplane(CQ):
|
||||
|
||||
return Compound.makeCompound(toFuse)
|
||||
|
||||
def _revolve(self,angleDegrees=360,axisStart=None,axisEnd=None):
|
||||
def _revolve(self,angleDegrees,axisStart,axisEnd):
|
||||
"""
|
||||
Make a solid from the existing set of pending wires.
|
||||
|
||||
@ -2149,7 +2163,7 @@ class Workplane(CQ):
|
||||
#Revolve the wires, make a compound out of them and then fuse them
|
||||
toFuse = []
|
||||
for ws in wireSets:
|
||||
thisObj = Solid.revolve(ws[0], ws[1:], angleDegrees)
|
||||
thisObj = Solid.revolve(ws[0], ws[1:], angleDegrees, axisStart, axisEnd)
|
||||
toFuse.append(thisObj)
|
||||
|
||||
return Compound.makeCompound(toFuse)
|
||||
|
@ -51,8 +51,10 @@ from cadquery import Vector,BoundBox
|
||||
import FreeCAD
|
||||
|
||||
from .verutil import fc_import
|
||||
|
||||
FreeCADPart = fc_import("FreeCAD.Part")
|
||||
|
||||
|
||||
class Shape(object):
|
||||
"""
|
||||
Represents a shape in the system.
|
||||
@ -101,6 +103,7 @@ class Shape(object):
|
||||
|
||||
tr.forConstruction = forConstruction
|
||||
return tr
|
||||
|
||||
# TODO: all these should move into the exporters folder.
|
||||
# we dont need a bunch of exporting code stored in here!
|
||||
#
|
||||
@ -189,6 +192,7 @@ class Shape(object):
|
||||
return Vector(self.wrapped.CenterOfMass)
|
||||
except:
|
||||
pass
|
||||
|
||||
def Closed(self):
|
||||
return self.wrapped.Closed
|
||||
|
||||
@ -288,6 +292,7 @@ class Shape(object):
|
||||
def __hash__(self):
|
||||
return self.wrapped.hashCode()
|
||||
|
||||
|
||||
class Vertex(Shape):
|
||||
def __init__(self, obj, forConstruction=False):
|
||||
"""
|
||||
@ -308,6 +313,7 @@ class Vertex(Shape):
|
||||
"""
|
||||
return Vector(self.wrapped.Point)
|
||||
|
||||
|
||||
class Edge(Shape):
|
||||
def __init__(self, obj):
|
||||
"""
|
||||
@ -631,7 +637,8 @@ class Solid(Shape):
|
||||
Make a wedge located in pnt\nBy default pnt=Vector(0,0,0) and dir=Vec
|
||||
tor(0,0,1)'
|
||||
"""
|
||||
return Shape.cast(FreeCADPart.makeWedge(xmin,ymin,zmin,z2min,x2min,xmax,ymax,zmax,z2max,x2max,pnt,dir))
|
||||
return Shape.cast(
|
||||
FreeCADPart.makeWedge(xmin, ymin, zmin, z2min, x2min, xmax, ymax, zmax, z2max, x2max, pnt, dir))
|
||||
|
||||
@classmethod
|
||||
def makeSphere(cls, radius, pnt=None, angleDegrees1=None, angleDegrees2=None, angleDegrees3=None):
|
||||
@ -738,7 +745,7 @@ class Solid(Shape):
|
||||
return Shape.cast(result)
|
||||
|
||||
@classmethod
|
||||
def revolve(cls,outerWire,innerWires,angleDegrees):
|
||||
def revolve(cls, outerWire, innerWires, angleDegrees, axisStart, axisEnd):
|
||||
"""
|
||||
Attempt to revolve the list of wires into a solid in the provided direction
|
||||
|
||||
@ -766,6 +773,9 @@ class Solid(Shape):
|
||||
f = FreeCADPart.Face(freeCADWires)
|
||||
result = f.revolve(FreeCAD.Base.Vector(-5,-5,0), FreeCAD.Base.Vector(0,1,0), angleDegrees)
|
||||
|
||||
result = f.revolve(FreeCAD.Base.Vector(axisStart),
|
||||
FreeCAD.Base.Vector(axisEnd), angleDegrees)
|
||||
|
||||
return Shape.cast(result)
|
||||
|
||||
def tessellate(self, tolerance):
|
||||
@ -810,6 +820,7 @@ class Solid(Shape):
|
||||
nativeFaces = [f.wrapped for f in faceList]
|
||||
return Shape.cast(self.wrapped.makeThickness(nativeFaces, thickness, tolerance))
|
||||
|
||||
|
||||
class Compound(Shape):
|
||||
def __init__(self, obj):
|
||||
"""
|
||||
|
@ -21,16 +21,16 @@ import Part
|
||||
|
||||
#The dimensions of the model. These can be modified rather than changing the shape's code directly.
|
||||
rectangle_width = 10.0
|
||||
rectange_length = 10.0
|
||||
rectangle_length = 10.0
|
||||
angleDegrees = 360.0
|
||||
|
||||
#Revolve a cylinder from a rectangle
|
||||
#Switch comments around in this section to try the revolve operation with different parameters
|
||||
result = cadquery.Workplane("XY").rect(rectangle_width, rectange_length).revolve()
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectange_length).revolve(angleDegrees)
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectange_length).revolve(angleDegrees,(-5,-5,0))
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectange_length).revolve(angleDegrees,(-5,-5,0),(-5,5,0))
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectange_length).revolve(angleDegrees,(-5,-5,0),(-5,5,0),False)
|
||||
result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length, False).revolve()
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angleDegrees)
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angleDegrees,(-5,-5,0))
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angleDegrees,(-5,-5,0),(-5,5,0))
|
||||
#result = cadquery.Workplane("XY").rect(rectangle_width, rectangle_length).revolve(angleDegrees,(-5,-5,0),(-5,5,0),False)
|
||||
|
||||
#Get a cadquery solid object
|
||||
solid = result.val()
|
||||
|
Reference in New Issue
Block a user