2023-03-28 13:46:48 +00:00
|
|
|
import cadquery as cq
|
|
|
|
|
2023-04-15 22:21:03 +00:00
|
|
|
# These should be set from dimensions.py
|
|
|
|
elements = None
|
|
|
|
kbd_pillar_positions = []
|
|
|
|
kbd_height = 0
|
|
|
|
kbd_width = 0
|
|
|
|
kbd_back_thickness = 0
|
|
|
|
kbd_front_thickness = 0
|
|
|
|
kbd_actual_height = 0
|
|
|
|
kbd_angle = 0
|
2023-03-28 13:46:48 +00:00
|
|
|
|
|
|
|
|
2023-04-15 22:21:03 +00:00
|
|
|
def init():
|
|
|
|
global elements
|
2023-03-28 13:46:48 +00:00
|
|
|
|
2023-04-15 22:21:03 +00:00
|
|
|
elements = [
|
|
|
|
# Shorter pillars
|
|
|
|
{
|
|
|
|
"x": 0,
|
|
|
|
"y": 0,
|
|
|
|
"z": 5.5,
|
|
|
|
"shape": cq.Sketch().push(kbd_pillar_positions).circle(5, mode="a"),
|
|
|
|
},
|
|
|
|
# Taller pillars with holes for self-tapping screws
|
|
|
|
{
|
|
|
|
"x": 0,
|
|
|
|
"y": 0,
|
|
|
|
"z": 2.5,
|
|
|
|
"shape": (
|
|
|
|
cq.Sketch()
|
|
|
|
.push(kbd_pillar_positions)
|
|
|
|
.circle(2.4, mode="a")
|
|
|
|
.circle(1.1, mode="s")
|
|
|
|
),
|
|
|
|
},
|
|
|
|
]
|
2023-03-28 13:46:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def add(
|
|
|
|
*,
|
|
|
|
model,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
thickness,
|
|
|
|
offset_x,
|
|
|
|
offset_y,
|
|
|
|
bottom_face,
|
|
|
|
back_face,
|
|
|
|
shell_t
|
|
|
|
):
|
|
|
|
# This one is special, it creates angled things and cuts off the
|
|
|
|
# case, so ... it's going to do weird stuff
|
|
|
|
|
|
|
|
if bottom_face:
|
|
|
|
model = (
|
|
|
|
model.faces(bottom_face)
|
2023-04-15 22:21:03 +00:00
|
|
|
.workplane(centerOption="CenterOfBoundBox", offset=-kbd_front_thickness)
|
2023-03-28 13:46:48 +00:00
|
|
|
.center(
|
|
|
|
-width / 2,
|
|
|
|
height / 2,
|
|
|
|
)
|
|
|
|
.transformed(rotate=cq.Vector(kbd_angle, 0, 0))
|
|
|
|
.tag("kbd_sloped")
|
|
|
|
)
|
|
|
|
for element in elements:
|
|
|
|
model = (
|
|
|
|
model.workplaneFromTagged("kbd_sloped")
|
|
|
|
.center(offset_x + element["x"], -offset_y - element["y"])
|
|
|
|
.workplane(offset=element["z"])
|
|
|
|
.placeSketch(element["shape"])
|
|
|
|
.extrude(100)
|
|
|
|
)
|
|
|
|
|
|
|
|
model = (
|
|
|
|
model.workplaneFromTagged("mid_height")
|
|
|
|
.transformed(offset=cq.Vector(0, 0, -thickness / 2))
|
|
|
|
.split(keepTop=True)
|
|
|
|
.faces(">X")
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
|
|
|
.center(-height / 2, -thickness / 2)
|
|
|
|
.placeSketch(
|
|
|
|
cq.Sketch().polygon(
|
|
|
|
[
|
2023-04-15 22:21:03 +00:00
|
|
|
[0, kbd_front_thickness],
|
|
|
|
[shell_t, kbd_front_thickness],
|
|
|
|
[kbd_actual_height + shell_t, kbd_back_thickness],
|
|
|
|
[kbd_actual_height + shell_t, 1000],
|
2023-03-28 13:46:48 +00:00
|
|
|
[0, 1000],
|
2023-04-15 22:21:03 +00:00
|
|
|
[0, kbd_front_thickness],
|
2023-03-28 13:46:48 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.cutBlind(-1000)
|
|
|
|
)
|
|
|
|
return model
|