2022-03-01 17:49:04 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-03-01 12:18:18 -05:00
|
|
|
import cadquery as cq
|
|
|
|
from cadquery import exporters
|
|
|
|
|
|
|
|
import key_bittings
|
2022-03-01 12:38:31 -05:00
|
|
|
from key_bittings import BittingSpecification
|
2022-03-01 12:18:18 -05:00
|
|
|
|
|
|
|
MM_PER_IN = 25.4
|
|
|
|
|
2022-03-01 12:38:31 -05:00
|
|
|
extra_key_thickness = 0.2
|
2022-03-01 12:18:18 -05:00
|
|
|
|
|
|
|
text_size = 4
|
|
|
|
text_depth = 0.5
|
|
|
|
text_margin = 2
|
|
|
|
|
|
|
|
lishi_width = 18 - 0.3
|
|
|
|
lishi_depth = 5
|
|
|
|
lishi_height = 9.98
|
|
|
|
lishi_overhang_height = 2.25
|
|
|
|
lishi_overhang_width = 1
|
|
|
|
lishi_overhang_radius = 1 - .000000001 # workaround to fillet a part with the same thickness
|
|
|
|
corner_radius = 0.5
|
|
|
|
side_thickness = 1
|
|
|
|
bottom_thickness = 2
|
|
|
|
back_thickness = 1.5
|
|
|
|
# this number is somewhat estimated, but quite important
|
|
|
|
# it is the offset from the end of the pliers to the point of the cutter
|
|
|
|
lishi_cutter_offset = .54 * MM_PER_IN
|
|
|
|
key_guide_height = 12.5
|
|
|
|
|
|
|
|
notch_width = 1
|
2022-03-01 12:38:31 -05:00
|
|
|
notch_height = 1.5
|
2022-03-01 12:18:18 -05:00
|
|
|
notch_depth = 0.5
|
|
|
|
|
|
|
|
|
2022-03-01 16:59:44 -05:00
|
|
|
def lishi_template(spec: BittingSpecification, name: str, depth: float, profile: cq.Sketch):
|
2022-03-01 12:39:38 -05:00
|
|
|
key_guide_width = lishi_width/2 + side_thickness + spec.TFC - spec.BCC/2
|
|
|
|
|
2022-03-01 12:18:18 -05:00
|
|
|
result = (
|
|
|
|
cq
|
|
|
|
.Workplane("front")
|
|
|
|
.box(lishi_width + side_thickness * 2, lishi_depth + lishi_overhang_width, lishi_height + bottom_thickness)
|
|
|
|
.tag("lishi_interface")
|
|
|
|
.edges("not >Y").fillet(corner_radius)
|
|
|
|
)
|
|
|
|
|
|
|
|
# TODO: positioning could be better
|
|
|
|
result = (
|
|
|
|
result
|
|
|
|
.faces("<Y").workplane().move(0, bottom_thickness/2)
|
|
|
|
.rect(lishi_width, lishi_height).cutBlind(-lishi_depth)
|
|
|
|
)
|
|
|
|
|
|
|
|
result = (
|
|
|
|
result
|
|
|
|
.faces("<X", tag="lishi_interface").vertices(">Y and >Z")
|
|
|
|
.workplane(offset=-side_thickness, centerOption="CenterOfMass")
|
|
|
|
.rect(lishi_overhang_width, lishi_overhang_height, centered=False).extrude(-lishi_width)
|
|
|
|
.edges(">Z").edges("<Y").fillet(lishi_overhang_radius)
|
|
|
|
)
|
|
|
|
|
|
|
|
result = (
|
|
|
|
result
|
2022-05-05 17:42:03 -04:00
|
|
|
.faces(">Y", tag="lishi_interface").vertices("<X and <Z")
|
|
|
|
.workplane(centerOption="CenterOfMass").center(-key_guide_width, 0)
|
2022-03-01 12:38:31 -05:00
|
|
|
.rect(key_guide_width, key_guide_height, centered=False).extrude(spec.key_thickness + extra_key_thickness + back_thickness, combine=False)
|
2022-03-01 12:18:18 -05:00
|
|
|
.tag("key_guide")
|
|
|
|
.edges("not <Y").fillet(corner_radius)
|
|
|
|
.faces(">X", tag="key_guide").vertices("<Z and <Y").workplane(centerOption="CenterOfMass").center(0, bottom_thickness + lishi_cutter_offset - depth)
|
2022-03-01 16:59:44 -05:00
|
|
|
.placeSketch(profile).cutThruAll()
|
2022-03-01 12:18:18 -05:00
|
|
|
.union(result) # this seems like a fairly bad way to do this, but it does work
|
|
|
|
)
|
|
|
|
|
|
|
|
result = (
|
|
|
|
result
|
|
|
|
.add(result.objects[0].Edges())
|
2022-05-05 17:42:03 -04:00
|
|
|
.faces(">Y", tag="key_guide").vertices("<X and >Z").workplane(centerOption="CenterOfMass")
|
2022-03-01 12:18:18 -05:00
|
|
|
# TODO: better positioning
|
2022-05-05 17:42:03 -04:00
|
|
|
.moveTo(-(lishi_width / 2 + side_thickness), -notch_height/2)
|
2022-03-01 12:18:18 -05:00
|
|
|
.rect(notch_width, notch_height).cutBlind(-notch_depth)
|
|
|
|
.faces(">Y").workplane(centerOption="CenterOfMass").text(name, text_size, -text_depth)
|
|
|
|
)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2022-03-01 12:38:31 -05:00
|
|
|
spec = key_bittings.national_disc_tumbler
|
|
|
|
for name, depth in spec.depths.items():
|
2022-03-01 16:59:44 -05:00
|
|
|
profile = (
|
|
|
|
cq.Sketch()
|
|
|
|
.push([((spec.key_thickness + extra_key_thickness)/2, depth/2)])
|
|
|
|
.rect(spec.key_thickness + extra_key_thickness, depth)
|
|
|
|
|
|
|
|
# notch to hold key straight
|
|
|
|
.push([(spec.key_thickness + extra_key_thickness - 0.5, 0.5 + 0.5)])
|
|
|
|
.rect(1, 1, mode="s")
|
|
|
|
|
|
|
|
# fillet inner corners
|
|
|
|
.reset().vertices("not(>X or <X)") .fillet(0.3)
|
|
|
|
)
|
|
|
|
|
|
|
|
result = lishi_template(spec, name, depth, profile)
|
2022-03-01 12:18:18 -05:00
|
|
|
exporters.export(result, f'national_disc_tumbler_{name}.stl')
|