ProjectedOrigin with origin point option
Removed ProjectedGlobalOrigin option for centerOption for the workplane cunstructor. Added origin keyword parameter that defaults to (0,0,0).
This commit is contained in:
@ -261,16 +261,19 @@ class CQ(object):
|
|||||||
|
|
||||||
return self.objects[0].wrapped
|
return self.objects[0].wrapped
|
||||||
|
|
||||||
def workplane(self, offset=0.0, invert=False, centerOption='CenterOfMass'):
|
def workplane(self, offset=0.0, invert=False, centerOption='CenterOfMass',
|
||||||
|
origin=(0, 0, 0)):
|
||||||
"""
|
"""
|
||||||
Creates a new 2-D workplane, located relative to the first face on the stack.
|
Creates a new 2-D workplane, located relative to the first face on the stack.
|
||||||
|
|
||||||
:param offset: offset for the work plane in the Z direction. Default
|
:param offset: offset for the work plane in the Z direction. Default
|
||||||
:param invert: invert the Z direction from that of the face.
|
:param invert: invert the Z direction from that of the face.
|
||||||
:param centerOption: how local origin of workplane is determined
|
:param centerOption: how local origin of workplane is determined.
|
||||||
|
:param origin: origin for plane center, requires 'ProjectedOrigin' centerOption.
|
||||||
:type offset: float or None=0.0
|
:type offset: float or None=0.0
|
||||||
:type invert: boolean or None=False
|
:type invert: boolean or None=False
|
||||||
:type centerOption: string or None='CenterOfMass'
|
:type centerOption: string or None='CenterOfMass'
|
||||||
|
:type origin: tuple
|
||||||
:rtype: Workplane object ( which is a subclass of CQ )
|
:rtype: Workplane object ( which is a subclass of CQ )
|
||||||
|
|
||||||
The first element on the stack must be a face, a set of
|
The first element on the stack must be a face, a set of
|
||||||
@ -285,11 +288,10 @@ class CQ(object):
|
|||||||
face/faces, if a face/faces was selected. If a vertex was
|
face/faces, if a face/faces was selected. If a vertex was
|
||||||
selected, the origin will be at the vertex, and located
|
selected, the origin will be at the vertex, and located
|
||||||
on the face. The centerOption paramter sets how the center is defined.
|
on the face. The centerOption paramter sets how the center is defined.
|
||||||
Options are 'CenterOfMass', 'CenterOfBoundBox', 'ProjectedOrigin', or
|
Options are 'CenterOfMass', 'CenterOfBoundBox', or 'ProjectedOrigin'.
|
||||||
'ProjectedGlobalOrigin'. 'CenterOfMass' and 'CenterOfBoundBox' are
|
'CenterOfMass' and 'CenterOfBoundBox' are in relation to the selected
|
||||||
in relation to the selected face/faces. 'ProjectedOrigin' uses the
|
face/faces. 'ProjectedOrigin' uses the supplied origin, which defaults
|
||||||
current origin that may have been updated by calls to transformed or
|
to (0, 0, 0).
|
||||||
center. 'ProjectedGlobalOrigin' projects the global (0,0,0) origin.
|
|
||||||
* The Z direction will be normal to the plane of the face,computed
|
* The Z direction will be normal to the plane of the face,computed
|
||||||
at the center point.
|
at the center point.
|
||||||
* The X direction will be parallel to the x-y plane. If the workplane is parallel to
|
* The X direction will be parallel to the x-y plane. If the workplane is parallel to
|
||||||
@ -338,6 +340,9 @@ class CQ(object):
|
|||||||
xd = Vector(1, 0, 0)
|
xd = Vector(1, 0, 0)
|
||||||
return xd
|
return xd
|
||||||
|
|
||||||
|
if centerOption not in {'CenterOfMass', 'ProjectedOrigin', 'CenterOfBoundBox'}:
|
||||||
|
raise ValueError('Undefined centerOption value provided.')
|
||||||
|
|
||||||
if len(self.objects) > 1:
|
if len(self.objects) > 1:
|
||||||
# are all objects 'PLANE'?
|
# are all objects 'PLANE'?
|
||||||
if not all(o.geomType() in ('PLANE', 'CIRCLE') for o in self.objects):
|
if not all(o.geomType() in ('PLANE', 'CIRCLE') for o in self.objects):
|
||||||
@ -348,12 +353,10 @@ class CQ(object):
|
|||||||
if not all(_isCoPlanar(self.objects[0], f) for f in self.objects[1:]):
|
if not all(_isCoPlanar(self.objects[0], f) for f in self.objects[1:]):
|
||||||
raise ValueError("Selected faces must be co-planar.")
|
raise ValueError("Selected faces must be co-planar.")
|
||||||
|
|
||||||
if centerOption in {'CenterOfMass', 'ProjectedOrigin', 'ProjectedGlobalOrigin'}:
|
if centerOption in {'CenterOfMass', 'ProjectedOrigin'}:
|
||||||
center = Shape.CombinedCenter(self.objects)
|
center = Shape.CombinedCenter(self.objects)
|
||||||
elif centerOption == 'CenterOfBoundBox':
|
elif centerOption == 'CenterOfBoundBox':
|
||||||
center = Shape.CombinedCenterOfBoundBox(self.objects)
|
center = Shape.CombinedCenterOfBoundBox(self.objects)
|
||||||
else:
|
|
||||||
raise ValueError('Undefined value passed to centerOption')
|
|
||||||
|
|
||||||
normal = self.objects[0].normalAt()
|
normal = self.objects[0].normalAt()
|
||||||
xDir = _computeXdir(normal)
|
xDir = _computeXdir(normal)
|
||||||
@ -362,7 +365,7 @@ class CQ(object):
|
|||||||
obj = self.objects[0]
|
obj = self.objects[0]
|
||||||
|
|
||||||
if isinstance(obj, Face):
|
if isinstance(obj, Face):
|
||||||
if centerOption in {'CenterOfMass', 'ProjectedOrigin', 'ProjectedGlobalOrigin'}:
|
if centerOption in {'CenterOfMass', 'ProjectedOrigin'}:
|
||||||
center = obj.Center()
|
center = obj.Center()
|
||||||
elif centerOption == 'CenterOfBoundBox':
|
elif centerOption == 'CenterOfBoundBox':
|
||||||
center = obj.CenterOfBoundBox()
|
center = obj.CenterOfBoundBox()
|
||||||
@ -370,7 +373,7 @@ class CQ(object):
|
|||||||
xDir = _computeXdir(normal)
|
xDir = _computeXdir(normal)
|
||||||
else:
|
else:
|
||||||
if hasattr(obj, 'Center'):
|
if hasattr(obj, 'Center'):
|
||||||
if centerOption in {'CenterOfMass', 'ProjectedOrigin', 'ProjectedGlobalOrigin'}:
|
if centerOption in {'CenterOfMass', 'ProjectedOrigin'}:
|
||||||
center = obj.Center()
|
center = obj.Center()
|
||||||
elif centerOption == 'CenterOfBoundBox':
|
elif centerOption == 'CenterOfBoundBox':
|
||||||
center = obj.CenterOfBoundBox()
|
center = obj.CenterOfBoundBox()
|
||||||
@ -382,9 +385,7 @@ class CQ(object):
|
|||||||
|
|
||||||
# update center to projected origin if desired
|
# update center to projected origin if desired
|
||||||
if centerOption == 'ProjectedOrigin':
|
if centerOption == 'ProjectedOrigin':
|
||||||
center = self.plane.origin.projectToPlane(Plane(center, xDir, normal))
|
center = Vector(origin).projectToPlane(Plane(center, xDir, normal))
|
||||||
elif centerOption == 'ProjectedGlobalOrigin':
|
|
||||||
center = Vector(0,0,0).projectToPlane(Plane(center, xDir, normal))
|
|
||||||
|
|
||||||
# invert if requested
|
# invert if requested
|
||||||
if invert:
|
if invert:
|
||||||
|
|||||||
@ -1924,17 +1924,9 @@ class TestCadQuery(BaseTest):
|
|||||||
.plane.origin.toTuple()
|
.plane.origin.toTuple()
|
||||||
self.assertTupleAlmostEquals(origin, (45.0, 30.0, 10.0), decimal_places)
|
self.assertTupleAlmostEquals(origin, (45.0, 30.0, 10.0), decimal_places)
|
||||||
|
|
||||||
# test case where plane origin is shifted with center call
|
origin = r.faces(">Z").workplane(centerOption='ProjectedOrigin',origin=(30,10,20)) \
|
||||||
r = r.faces(">Z").workplane(centerOption='ProjectedOrigin').center(30,0) \
|
|
||||||
.hole(90)
|
|
||||||
|
|
||||||
origin = r.faces(">Z").workplane(centerOption='ProjectedOrigin') \
|
|
||||||
.plane.origin.toTuple()
|
.plane.origin.toTuple()
|
||||||
self.assertTupleAlmostEquals(origin, (30.0, 0.0, 10.0), decimal_places)
|
self.assertTupleAlmostEquals(origin, (30.0, 10.0, 10.0), decimal_places)
|
||||||
|
|
||||||
origin = r.faces(">Z").workplane(centerOption='ProjectedGlobalOrigin') \
|
|
||||||
.plane.origin.toTuple()
|
|
||||||
self.assertTupleAlmostEquals(origin, (0.0, 0.0, 10.0), decimal_places)
|
|
||||||
|
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
origin = r.faces(">Z").workplane(centerOption='undefined')
|
origin = r.faces(">Z").workplane(centerOption='undefined')
|
||||||
|
|||||||
Reference in New Issue
Block a user