From a68cc9ef536d8624189775a930e924a12ad94d10 Mon Sep 17 00:00:00 2001 From: "Ricardo (XenGi) Band" Date: Tue, 22 Feb 2022 03:42:49 +0100 Subject: [PATCH] lower case as model --- mkbd65/lower_case.py | 52 +++++++++++++++++++++++--------------------- mkbd65/main.py | 6 +++++ 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/mkbd65/lower_case.py b/mkbd65/lower_case.py index 993058e..a23e5f9 100644 --- a/mkbd65/lower_case.py +++ b/mkbd65/lower_case.py @@ -1,6 +1,6 @@ from solid import OpenSCADObject, hull, translate, sphere, cube, scale, offset, square -from util import PCB_WIDTH, PCB_HEIGHT, PCB_RADIUS +from util import PCB_WIDTH, PCB_HEIGHT, PCB_RADIUS, forward, backward, up, right def lower_case(phone_width: float, phone_height: float, phone_radius: float) -> OpenSCADObject: @@ -15,33 +15,35 @@ def lower_case(phone_width: float, phone_height: float, phone_radius: float) -> thickness = 2 window_thickness = 0.5 - return (scale(v=(1, 1, thickness / phone_radius))( - hull()( - translate(v=(phone_radius, phone_radius, 0))( - sphere(r=phone_radius), - translate(v=(0, phone_height - 2 * phone_radius, 0))( - sphere(r=phone_radius) - ), - translate(v=(phone_width - 2 * phone_radius, 0, 0))( - sphere(r=phone_radius) - ), - translate(v=(phone_width - 2 * phone_radius, phone_height - 2 * phone_radius, 0))( - sphere(r=phone_radius) + return forward(v=thickness)( + (scale(v=(1, 1, thickness / phone_radius))( + hull()( + translate(v=(phone_radius, phone_radius, 0))( + sphere(r=phone_radius), + up(v=phone_height - 2 * phone_radius)( + sphere(r=phone_radius) + ), + right(v=phone_width - 2 * phone_radius)( + sphere(r=phone_radius) + ), + translate(v=(phone_width - 2 * phone_radius, phone_height - 2 * phone_radius, 0))( + sphere(r=phone_radius) + ) ) ) - ) - ) * translate(v=(0, 0, -1 * thickness))( - cube([phone_width, phone_height, thickness]) - )) - translate(v=(2 * phone_radius, 2 * phone_radius, -1 * thickness / 2))( - scale(v=(1, 1, thickness))( - offset(r=phone_radius)( - square([phone_width - 4 * phone_radius, phone_height - 4 * phone_radius]) + ) * backward(v=thickness)( + cube([phone_width, phone_height, thickness]) + )) - translate(v=(2 * phone_radius, 2 * phone_radius, -1 * thickness / 2))( + scale(v=(1, 1, thickness))( + offset(r=phone_radius)( + square([phone_width - 4 * phone_radius, phone_height - 4 * phone_radius]) + ) ) - ) - ) - translate(v=(phone_width - PCB_WIDTH, phone_radius, -1 * thickness / 2 + window_thickness))( - scale(v=(1, 1, thickness))( - offset(r=PCB_RADIUS)( - square([PCB_WIDTH - 2 * PCB_RADIUS, PCB_HEIGHT - 2 * PCB_RADIUS]) + ) - translate(v=(phone_width - PCB_WIDTH, phone_radius, -1 * thickness / 2 + window_thickness))( + scale(v=(1, 1, thickness))( + offset(r=PCB_RADIUS)( + square([PCB_WIDTH - 2 * PCB_RADIUS, PCB_HEIGHT - 2 * PCB_RADIUS]) + ) ) ) ) diff --git a/mkbd65/main.py b/mkbd65/main.py index a0f6970..c39a47a 100755 --- a/mkbd65/main.py +++ b/mkbd65/main.py @@ -10,6 +10,7 @@ from solid import scad_render_to_file from key_mat import key_mat, key from pcb import pcb from phone import phone +from lower_case import lower_case @click.command() @@ -61,6 +62,11 @@ def cli(layout, variant, stl, emf, amf, detail, config_file): key_height=config.getfloat("key_mat", "key_height", fallback=6), key_padding=config.getfloat("key_mat", "padding", fallback=1) )], + ["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( margin=config.getfloat("key_mat", "margin", fallback=1), padding=config.getfloat("key_mat", "padding", fallback=1),