2023-03-01 18:47:06 +00:00
|
|
|
import cadquery as cq
|
|
|
|
|
2023-03-27 19:57:55 +00:00
|
|
|
from utils import punch_hole, extrude_shape
|
2023-03-20 18:04:19 +00:00
|
|
|
|
2023-03-01 18:47:06 +00:00
|
|
|
# Measurements for my USB hub, YMMV
|
|
|
|
|
|
|
|
# The hole is for a USB-A plug, y is measured in the hub
|
|
|
|
# (from the bottom face to middle of the hole)
|
|
|
|
# Consumers should set proper offsets for the hole
|
|
|
|
|
|
|
|
holes = [
|
|
|
|
# USB-A port
|
|
|
|
{
|
|
|
|
"x": 0,
|
|
|
|
"y": 4,
|
2023-04-01 14:31:15 +00:00
|
|
|
"shape": cq.Sketch().trapezoid(13, 5, 90, mode="a").vertices().fillet(1),
|
2023-03-01 18:47:06 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
elements = [
|
|
|
|
# Thing to grab the hub
|
|
|
|
{
|
|
|
|
"x": 0,
|
|
|
|
"y": 5,
|
|
|
|
"shape": (
|
2023-03-27 20:15:49 +00:00
|
|
|
cq.Sketch().trapezoid(22, 10, 90, mode="a").trapezoid(17, 10, 90, mode="s")
|
2023-03-01 18:47:06 +00:00
|
|
|
),
|
|
|
|
"height": 8,
|
2023-04-01 16:42:40 +00:00
|
|
|
},
|
|
|
|
# Outline
|
|
|
|
{
|
|
|
|
"x": 0,
|
|
|
|
"y": 35,
|
|
|
|
"shape": (
|
|
|
|
cq.Sketch()
|
2023-04-01 16:42:54 +00:00
|
|
|
# FIXME: use actual size
|
2023-04-01 16:42:40 +00:00
|
|
|
.trapezoid(17, 70, 90, mode="a")
|
|
|
|
.trapezoid(15, 68, 90, mode="s")
|
|
|
|
.vertices()
|
|
|
|
.fillet(3)
|
|
|
|
),
|
|
|
|
"height": 0.2,
|
|
|
|
},
|
2023-03-01 18:47:06 +00:00
|
|
|
]
|
2023-03-20 18:04:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def add(
|
|
|
|
*,
|
|
|
|
model,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
thickness,
|
|
|
|
offset_x,
|
|
|
|
offset_y,
|
|
|
|
bottom_face,
|
|
|
|
back_face,
|
|
|
|
shell_t
|
|
|
|
):
|
|
|
|
# USB Hub extrusions
|
|
|
|
if bottom_face:
|
|
|
|
for element in elements:
|
|
|
|
model = extrude_shape(
|
|
|
|
model=model,
|
|
|
|
face=bottom_face,
|
|
|
|
w=width,
|
|
|
|
h=height,
|
2023-04-01 16:42:40 +00:00
|
|
|
x_offset=offset_x,
|
|
|
|
y_offset=shell_t + offset_y,
|
2023-03-27 19:57:55 +00:00
|
|
|
element=element,
|
2023-03-20 18:04:19 +00:00
|
|
|
height=-(element["height"] + shell_t),
|
|
|
|
)
|
|
|
|
|
|
|
|
# Holes
|
|
|
|
if back_face:
|
|
|
|
for hole in holes:
|
2023-03-27 19:57:55 +00:00
|
|
|
model = punch_hole(
|
2023-03-20 18:04:19 +00:00
|
|
|
model=model,
|
|
|
|
face=back_face,
|
|
|
|
w=width,
|
|
|
|
h=thickness,
|
|
|
|
x_offset=width - offset_x,
|
|
|
|
y_offset=shell_t,
|
|
|
|
hole=hole,
|
|
|
|
depth=shell_t,
|
|
|
|
)
|
|
|
|
|
|
|
|
return model
|