cadquery/notebook_nueva/audio_plug.py

88 lines
1.8 KiB
Python
Raw Normal View History

# Hole to expose a USB audio card (YMMV)
2023-03-20 13:19:14 -03:00
import cadquery as cq
2023-04-01 14:26:48 -03:00
from utils import extrude_shape, punch_hole
2023-03-20 13:19:14 -03:00
# The hole is for a random USB sound card.
# Consumers should set proper offsets for the hole
2023-04-01 14:26:48 -03:00
# FIXME: use actual sizes
item_w = 40
item_h = 20
hole_w = 17
hole_h = 5
holes = [
# 2-jack plug
{
2023-04-01 14:26:48 -03:00
"x": -item_h / 2,
"y": 4,
2023-04-01 14:26:48 -03:00
"shape": cq.Sketch()
.trapezoid(hole_w, hole_h, 90, mode="a")
.vertices()
.fillet(2),
},
]
elements = [
# Outline
{
"x": item_w / 2,
"y": item_h / 2,
"shape": (
cq.Sketch()
.trapezoid(item_w, item_h, 90, mode="a")
.trapezoid(item_w - 2, item_h - 2, 90, mode="s")
),
"height": 0.2,
},
]
2023-03-20 13:19:14 -03:00
def add(
*,
model,
width,
height,
thickness,
offset_x,
offset_y,
bottom_face,
back_face,
shell_t
):
2023-04-01 14:26:48 -03:00
# Extrusions
if bottom_face:
for element in elements:
model = extrude_shape(
model=model,
face=bottom_face,
w=width,
h=height,
x_offset=offset_x,
y_offset=offset_y,
element=element,
height=-(element["height"] + shell_t),
)
2023-03-20 13:19:14 -03:00
# Holes
if back_face:
for hole in holes:
model = punch_hole(
2023-03-20 13:19:14 -03:00
model=model,
face=back_face,
# FIXME: This is weird because it's the RIGHT side,
2023-04-01 14:26:48 -03:00
# So it's height instead of w, offset_y instead of x
2023-03-20 13:19:14 -03:00
# need to work on making these coherent
w=height,
h=thickness,
2023-04-01 14:26:48 -03:00
x_offset=height - offset_y,
2023-03-20 13:19:14 -03:00
y_offset=shell_t,
hole=hole,
depth=shell_t,
)
return model