2024-07-06 16:41:13 -07:00
|
|
|
"""
|
|
|
|
Marking utilities for `Cq.Workplane`
|
|
|
|
|
|
|
|
Adds the functions to `Cq.Workplane`:
|
|
|
|
1. `tagPoint`
|
|
|
|
2. `tagPlane`
|
|
|
|
"""
|
|
|
|
import cadquery as Cq
|
2024-07-07 21:01:40 -07:00
|
|
|
from typing import Union, Tuple
|
2024-07-06 16:41:13 -07:00
|
|
|
|
|
|
|
|
|
|
|
def tagPoint(self, tag: str):
|
|
|
|
"""
|
|
|
|
Adds a vertex that can be used in `Point` constraints.
|
|
|
|
"""
|
|
|
|
vertex = Cq.Vertex.makeVertex(0, 0, 0)
|
|
|
|
self.eachpoint(vertex.moved, useLocalCoordinates=True).tag(tag)
|
|
|
|
|
|
|
|
Cq.Workplane.tagPoint = tagPoint
|
|
|
|
|
|
|
|
|
2024-07-07 21:01:40 -07:00
|
|
|
def tagPlane(self, tag: str,
|
|
|
|
direction: Union[str, Cq.Vector, Tuple[float, float, float]] = '+Z'):
|
2024-07-06 16:41:13 -07:00
|
|
|
"""
|
|
|
|
Adds a phantom `Cq.Edge` in the given location which can be referenced in a
|
|
|
|
`Axis`, `Point`, or `Plane` constraint.
|
|
|
|
"""
|
2024-07-07 21:01:40 -07:00
|
|
|
if isinstance(direction, str):
|
|
|
|
x, y, z = 0, 0, 0
|
|
|
|
assert len(direction) == 2
|
|
|
|
sign, axis = direction
|
|
|
|
if axis in ('z', 'Z'):
|
|
|
|
z = 1
|
|
|
|
elif axis in ('y', 'Y'):
|
|
|
|
y = 1
|
|
|
|
elif axis in ('x', 'X'):
|
|
|
|
x = 1
|
|
|
|
else:
|
|
|
|
assert False, "Axis must be one of x,y,z"
|
|
|
|
if sign == '+':
|
|
|
|
sign = 1
|
|
|
|
elif sign == '-':
|
|
|
|
sign = -1
|
|
|
|
else:
|
|
|
|
assert False, "Sign must be one of +/-"
|
|
|
|
v = Cq.Vector(x, y, z) * sign
|
2024-07-06 16:41:13 -07:00
|
|
|
else:
|
2024-07-07 21:01:40 -07:00
|
|
|
v = Cq.Vector(direction)
|
|
|
|
edge = Cq.Edge.makeLine(v * (-1), v)
|
2024-07-06 16:41:13 -07:00
|
|
|
self.eachpoint(edge.moved, useLocalCoordinates=True).tag(tag)
|
|
|
|
|
|
|
|
Cq.Workplane.tagPlane = tagPlane
|