blub
This commit is contained in:
parent
1b64b3a2c8
commit
e732a591db
5 changed files with 50 additions and 36 deletions
66
mkbd65.py
66
mkbd65.py
|
|
@ -5,12 +5,13 @@ from subprocess import run
|
|||
from configparser import ConfigParser
|
||||
|
||||
import click
|
||||
from solid import scad_render_to_file
|
||||
from solid import scad_render_to_file, translate
|
||||
|
||||
from mkbd65.key_mat import key_mat, key
|
||||
from mkbd65.pcb import pcb
|
||||
from mkbd65.phone import phone
|
||||
from mkbd65.lower_case import lower_case
|
||||
from mkbd65.util import PCB_WIDTH
|
||||
|
||||
|
||||
@click.command()
|
||||
|
|
@ -29,23 +30,23 @@ def cli(layout, variant, stl, emf, amf, detail, config_file):
|
|||
config = ConfigParser()
|
||||
config.read(config_file)
|
||||
|
||||
components = [
|
||||
["phone", phone(
|
||||
components = {
|
||||
"phone": phone(
|
||||
width=config.getfloat("phone", "width"),
|
||||
height=config.getfloat("phone", "height"),
|
||||
thickness=config.getfloat("phone", "thickness"),
|
||||
corner_radius=config.getfloat("phone", "corner_radius"),
|
||||
side_radius=config.getfloat("phone", "side_radius")
|
||||
)],
|
||||
["key", key(
|
||||
),
|
||||
"key": key(
|
||||
width=config.getfloat("key_mat", "key_width", fallback=9),
|
||||
height=config.getfloat("key_mat", "key_height", fallback=6),
|
||||
thickness=config.getfloat("key_mat", "key_thickness", fallback=2),
|
||||
corner_radius=config.getfloat("key_mat", "key_corner_radius", fallback=1),
|
||||
label="❤️",
|
||||
font=config.get("key_mat", "font", fallback="DejaVu Sans:style=Bold")
|
||||
)],
|
||||
["key_mat", key_mat(
|
||||
),
|
||||
"key_mat": key_mat(
|
||||
margin=config.getfloat("key_mat", "margin", fallback=1),
|
||||
padding=config.getfloat("key_mat", "padding", fallback=1),
|
||||
thickness=config.getfloat("key_mat", "thickness", fallback=0.5),
|
||||
|
|
@ -56,18 +57,18 @@ def cli(layout, variant, stl, emf, amf, detail, config_file):
|
|||
layout=layout,
|
||||
variant=variant,
|
||||
font=config.get("key_mat", "font", fallback="DejaVu Sans:style=Bold")
|
||||
)],
|
||||
["pcb", pcb(
|
||||
),
|
||||
"pcb": pcb(
|
||||
key_width=config.getfloat("key_mat", "key_width", fallback=9),
|
||||
key_height=config.getfloat("key_mat", "key_height", fallback=6),
|
||||
key_padding=config.getfloat("key_mat", "padding", fallback=1)
|
||||
)],
|
||||
["lower_case", lower_case(
|
||||
),
|
||||
"lower_case": lower_case(
|
||||
phone_width=config.getfloat("phone", "width"),
|
||||
phone_height=config.getfloat("phone", "height"),
|
||||
phone_radius=config.getfloat("phone", "corner_radius")
|
||||
)],
|
||||
["test_key_mat", key_mat(
|
||||
),
|
||||
"test_key_mat": key_mat(
|
||||
margin=config.getfloat("key_mat", "margin", fallback=1),
|
||||
padding=config.getfloat("key_mat", "padding", fallback=1),
|
||||
thickness=config.getfloat("key_mat", "thickness", fallback=0.5),
|
||||
|
|
@ -80,28 +81,41 @@ def cli(layout, variant, stl, emf, amf, detail, config_file):
|
|||
font=config.get("key_mat", "font", fallback="DejaVu Sans:style=Bold"),
|
||||
keys_h=5,
|
||||
keys_v=3
|
||||
)]
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
for component in components:
|
||||
print(f"Render component {component[0]}...")
|
||||
key_mat_width = 13 * config.getfloat("key_mat", "key_width", fallback=9) + 12 * config.getfloat("key_mat", "padding", fallback=1) + 2 * config.getfloat("key_mat", "margin", fallback=1)
|
||||
full_model = components["lower_case"] + translate(v=((config.getfloat("phone", "width") - PCB_WIDTH) / 2, config.getfloat("phone", "corner_radius") / 2, 0.5))(
|
||||
components["pcb"]
|
||||
) + translate(v=((config.getfloat("phone", "width") - key_mat_width) / 2, 3 + config.getfloat("key_mat", "margin", fallback=1) + (config.getfloat("key_mat", "key_height", fallback=6) - 4) / 2 , 1.78))(
|
||||
components["key_mat"]
|
||||
)
|
||||
|
||||
scad_render_to_file(
|
||||
full_model,
|
||||
filepath=f"mkbd65.scad",
|
||||
file_header=f'$fn = {detail};',
|
||||
include_orig_code=False
|
||||
)
|
||||
|
||||
for component in components.keys():
|
||||
print(f"Rendering component {component}...")
|
||||
scad_render_to_file(
|
||||
component[1],
|
||||
filepath=f"mkbd65_{component[0]}.scad",
|
||||
components[component],
|
||||
filepath=f"mkbd65_{component}.scad",
|
||||
file_header=f'$fn = {detail};',
|
||||
include_orig_code=False
|
||||
)
|
||||
if stl:
|
||||
print(f"Generate STL for component {component[0]}...")
|
||||
run(["openscad", "-o", f"mkbd65_{component[0]}.stl", f"mkbd65_{component[0]}.scad"])
|
||||
print(f"Generate STL for component {component}...")
|
||||
run(["openscad", "-o", f"mkbd65_{component}.stl", f"mkbd65_{component}.scad"])
|
||||
if emf:
|
||||
print(f"Generate 3MF for component {component[0]}...")
|
||||
run(["openscad", "-o", f"mkbd65_{component[0]}.3mf", f"mkbd65_{component[0]}.scad"])
|
||||
print(f"Generate 3MF for component {component}...")
|
||||
run(["openscad", "-o", f"mkbd65_{component}.3mf", f"mkbd65_{component}.scad"])
|
||||
if amf:
|
||||
print(f"Generate AMF for component {component[0]}...")
|
||||
run(["openscad", "-o", f"mkbd65_{component[0]}.amf", f"mkbd65_{component[0]}.scad"])
|
||||
print(f"Generate AMF for component {component}...")
|
||||
run(["openscad", "-o", f"mkbd65_{component}.amf", f"mkbd65_{component}.scad"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
|
||||
|
|
|
|||
0
mkbd65/__init__.py
Normal file
0
mkbd65/__init__.py
Normal file
|
|
@ -3,7 +3,7 @@ from typing import Tuple
|
|||
from solid import OpenSCADObject, cube, linear_extrude, text, translate, scale, rotate, cylinder, union, color, square, offset
|
||||
from solid.utils import up
|
||||
|
||||
from util import get_label_size, FILAMENT_LAYER, LAYOUTS
|
||||
from mkbd65.util import get_label_size, FILAMENT_LAYER, LAYOUTS
|
||||
|
||||
|
||||
def key(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from solid import OpenSCADObject, hull, translate, sphere, cube, scale, offset, square
|
||||
from solid.utils import up, right, down
|
||||
from solid import OpenSCADObject, hull, translate, sphere, cube, scale, offset, square, color
|
||||
from solid.utils import up, right, down, forward
|
||||
|
||||
from util import PCB_WIDTH, PCB_HEIGHT, PCB_RADIUS
|
||||
from mkbd65.util import PCB_WIDTH, PCB_HEIGHT, PCB_RADIUS
|
||||
|
||||
|
||||
def lower_case(phone_width: float, phone_height: float, phone_radius: float) -> OpenSCADObject:
|
||||
|
|
@ -16,12 +16,12 @@ def lower_case(phone_width: float, phone_height: float, phone_radius: float) ->
|
|||
thickness = 2
|
||||
window_thickness = 0.5
|
||||
|
||||
return up(z=thickness)(
|
||||
return color("DarkSlateGray")(up(z=thickness)(
|
||||
(scale(v=(1, 1, thickness / phone_radius))(
|
||||
hull()(
|
||||
translate(v=(phone_radius, phone_radius, 0))(
|
||||
sphere(r=phone_radius),
|
||||
up(z=phone_height - 2 * phone_radius)(
|
||||
forward(y=phone_height - 2 * phone_radius)(
|
||||
sphere(r=phone_radius)
|
||||
),
|
||||
right(x=phone_width - 2 * phone_radius)(
|
||||
|
|
@ -47,7 +47,7 @@ def lower_case(phone_width: float, phone_height: float, phone_radius: float) ->
|
|||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
))
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from solid import OpenSCADObject, color, linear_extrude, polygon, translate, scale, offset, square, union, cylinder
|
||||
|
||||
from util import PCB_WIDTH, PCB_HEIGHT, PCB_RADIUS
|
||||
from mkbd65.util import PCB_WIDTH, PCB_HEIGHT, PCB_RADIUS
|
||||
|
||||
|
||||
def switch() -> OpenSCADObject:
|
||||
|
|
@ -36,7 +36,7 @@ def pcb(key_width: float, key_height: float, key_padding: float) -> OpenSCADObje
|
|||
"""
|
||||
pcb_thickness = 0.5
|
||||
rows = 5
|
||||
columns = 12
|
||||
columns = 13
|
||||
|
||||
board = color(c="Purple")(
|
||||
translate(v=(PCB_RADIUS, PCB_RADIUS, pcb_thickness/2))(
|
||||
|
|
@ -49,7 +49,7 @@ def pcb(key_width: float, key_height: float, key_padding: float) -> OpenSCADObje
|
|||
)
|
||||
|
||||
switches = []
|
||||
margin_x = (PCB_WIDTH - (columns * key_width + (columns - 1) * key_padding)) / 2
|
||||
margin_x = (PCB_WIDTH - (columns * key_width + (columns - 1) * key_padding)) / 2 + (key_width - 6) / 2
|
||||
margin_y = 3
|
||||
|
||||
for x in range(columns):
|
||||
|
|
|
|||
Loading…
Reference in a new issue