Refactor battery_holder with single add entry point
This commit is contained in:
parent
7aeb2cc0c1
commit
d9749bc38e
@ -1,4 +1,5 @@
|
||||
import cadquery as cq
|
||||
from utils import punch_hole2, extrude_shape, punch_hole
|
||||
|
||||
stand_positions = [(3.5, 3.5), (61.5, 3.5), (61.5, 52.5), (3.5, 52.5)]
|
||||
stands = (
|
||||
@ -72,7 +73,7 @@ elements = [
|
||||
hex_size = width // 13
|
||||
vent_positions = []
|
||||
for x in range(1, width // hex_size):
|
||||
for y in range(0, int(height // hex_size / 0.8) - 1):
|
||||
for y in range(1, int(height // hex_size / 0.8)):
|
||||
vent_positions.append(
|
||||
(
|
||||
(x + (y % 2) / 2) * hex_size - hex_size * 0.2,
|
||||
@ -99,16 +100,67 @@ holes = [
|
||||
{
|
||||
"x": -15,
|
||||
"y": -1 + pillar_height,
|
||||
"height": 6.5,
|
||||
"width": 12,
|
||||
"fillet": 1,
|
||||
"shape": cq.Sketch().trapezoid(12, 6.5, 90, mode="a").vertices().fillet(1),
|
||||
},
|
||||
# Power button
|
||||
{
|
||||
"x": -67,
|
||||
"y": 5.5 + pillar_height,
|
||||
"height": 7,
|
||||
"width": 7,
|
||||
"fillet": 1,
|
||||
"shape": cq.Sketch().trapezoid(7, 7, 90, mode="a").vertices().fillet(1),
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def add(
|
||||
*,
|
||||
model,
|
||||
width,
|
||||
height,
|
||||
thickness,
|
||||
offset_x,
|
||||
offset_y,
|
||||
bottom_face,
|
||||
back_face,
|
||||
shell_t
|
||||
):
|
||||
|
||||
# Vents
|
||||
for vent in vents:
|
||||
model = punch_hole2(
|
||||
model=model,
|
||||
face=bottom_face,
|
||||
w=width,
|
||||
h=height,
|
||||
x_offset=offset_x + vent["x"],
|
||||
y_offset=shell_t + offset_y + vent["y"],
|
||||
hole=vent,
|
||||
depth=shell_t,
|
||||
)
|
||||
|
||||
# Battery holder stands and pogo pin holder
|
||||
for element in elements:
|
||||
model = extrude_shape(
|
||||
model=model,
|
||||
face=bottom_face,
|
||||
w=width,
|
||||
h=height,
|
||||
x_offset=offset_x + element["x"],
|
||||
y_offset=shell_t + offset_y + element["y"],
|
||||
shape=element["shape"],
|
||||
height=-(element["height"] + shell_t),
|
||||
)
|
||||
|
||||
# Holes
|
||||
for hole in holes:
|
||||
model = punch_hole2(
|
||||
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
|
||||
|
Binary file not shown.
Binary file not shown.
@ -153,19 +153,6 @@ def model():
|
||||
# Now the basic box shape is in place, start adding things
|
||||
# and cutting holes.
|
||||
|
||||
# Holes in the back of the case for battery holder
|
||||
for hole in battery_holder.holes:
|
||||
model = punch_hole(
|
||||
model=model,
|
||||
face=">Y",
|
||||
w=width,
|
||||
h=thickness,
|
||||
x_offset=width - battery_offset_x,
|
||||
y_offset=shell_t,
|
||||
hole=hole,
|
||||
depth=shell_t,
|
||||
)
|
||||
|
||||
# Hole for USB hub in the back
|
||||
for hole in usb_hub.holes:
|
||||
model = punch_hole(
|
||||
@ -205,31 +192,6 @@ def model():
|
||||
depth=shell_t,
|
||||
)
|
||||
|
||||
for vent in battery_holder.vents:
|
||||
model = punch_hole2(
|
||||
model=model,
|
||||
face="<Z",
|
||||
w=width,
|
||||
h=height,
|
||||
x_offset=battery_offset_x + element["x"],
|
||||
y_offset=shell_t + battery_offset_y + element["y"],
|
||||
hole=vent,
|
||||
depth=shell_t,
|
||||
)
|
||||
|
||||
# Battery holder stands and pogo pin holder
|
||||
for element in battery_holder.elements:
|
||||
model = extrude_shape(
|
||||
model=model,
|
||||
face="<Z",
|
||||
w=width,
|
||||
h=height,
|
||||
x_offset=battery_offset_x + element["x"],
|
||||
y_offset=shell_t + battery_offset_y + element["y"],
|
||||
shape=element["shape"],
|
||||
height=-(element["height"] + shell_t),
|
||||
)
|
||||
|
||||
# CPU holder stands
|
||||
for element in cpu_holder.elements:
|
||||
model = extrude_shape(
|
||||
@ -243,6 +205,19 @@ def model():
|
||||
height=-(element["height"] + shell_t),
|
||||
)
|
||||
|
||||
# This adds all the holes and extrusions for the battery system
|
||||
model = battery_holder.add(
|
||||
model=model,
|
||||
width=width,
|
||||
height=height,
|
||||
thickness=thickness,
|
||||
offset_x=battery_offset_x,
|
||||
offset_y=battery_offset_y,
|
||||
bottom_face="<Z",
|
||||
back_face=">Y",
|
||||
shell_t=shell_t,
|
||||
)
|
||||
|
||||
return model
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user