diff --git a/notebook_nueva/audio_plug.py b/notebook_nueva/audio_plug.py index 68e35d8..3402948 100644 --- a/notebook_nueva/audio_plug.py +++ b/notebook_nueva/audio_plug.py @@ -2,7 +2,7 @@ import cadquery as cq -from utils import punch_hole2, extrude_shape2 +from utils import punch_hole # The hole is for a random USB sound card. # Consumers should set proper offsets for the hole @@ -33,7 +33,7 @@ def add( # Holes if back_face: for hole in holes: - model = punch_hole2( + model = punch_hole( model=model, face=back_face, # FIXME: This is weird because it's the RIGHT side, diff --git a/notebook_nueva/battery_holder.py b/notebook_nueva/battery_holder.py index df3c6fb..bd5ffc2 100644 --- a/notebook_nueva/battery_holder.py +++ b/notebook_nueva/battery_holder.py @@ -1,6 +1,6 @@ import cadquery as cq -from utils import extrude_shape, punch_hole2, hex_vents +from utils import extrude_shape, punch_hole, hex_vents stand_positions = [(3.5, 3.5), (61.5, 3.5), (61.5, 52.5), (3.5, 52.5)] stands = ( @@ -71,7 +71,7 @@ elements = [ ] -vents = hex_vents(size=6, width=width, height=height) +vents = hex_vents(size=3, width=width, height=height) # Hole distances are relative to the rightmost pillar @@ -110,7 +110,7 @@ def add( if bottom_face: # Vents for vent in vents: - model = punch_hole2( + model = punch_hole( model=model, face=bottom_face, w=width, @@ -128,16 +128,16 @@ def add( face=bottom_face, w=width, h=height, - x_offset=offset_x + element["x"], - y_offset=shell_t + offset_y + element["y"], - shape=element["shape"], + x_offset=offset_x, + y_offset=shell_t + offset_y, + element=element, height=-(element["height"] + shell_t), ) if back_face: # Holes for hole in holes: - model = punch_hole2( + model = punch_hole( model=model, face=back_face, w=width, diff --git a/notebook_nueva/model.stl b/notebook_nueva/model.stl index 203cc99..a09fbb9 100644 Binary files a/notebook_nueva/model.stl and b/notebook_nueva/model.stl differ diff --git a/notebook_nueva/modelo.py b/notebook_nueva/modelo.py index 47d9dbc..687c48a 100644 --- a/notebook_nueva/modelo.py +++ b/notebook_nueva/modelo.py @@ -7,7 +7,6 @@ import usb_hub import zero_holder as cpu_holder import screen_pillars import keyboard -from utils import extrude_shape, punch_hole, punch_hole2 # Base for the notebook. Basically a kbd base that extends back # as much as possible diff --git a/notebook_nueva/screen_pillars.py b/notebook_nueva/screen_pillars.py index bd519ff..4ab2fee 100644 --- a/notebook_nueva/screen_pillars.py +++ b/notebook_nueva/screen_pillars.py @@ -1,4 +1,4 @@ -from utils import extrude_shape, punch_hole2 +from utils import extrude_shape, punch_hole import cadquery as cq elements = None @@ -52,20 +52,20 @@ def add( face=bottom_face, w=width, h=height, - x_offset=offset_x + element["x"], - y_offset=shell_t + offset_y + element["y"], - shape=element["shape"], + x_offset=offset_x, + y_offset=shell_t + offset_y, + element=element, height=-(element["height"] + shell_t), ) # Screw holes for hole in bottom_holes: - model = punch_hole2( + model = punch_hole( model=model, face=bottom_face, w=width, h=height, - x_offset=offset_x + hole["x"], - y_offset=shell_t + offset_y + hole["y"], + x_offset=offset_x, + y_offset=shell_t + offset_y, hole=hole, depth=hole["depth"], ) diff --git a/notebook_nueva/usb_hub.py b/notebook_nueva/usb_hub.py index 3e996df..4553d31 100644 --- a/notebook_nueva/usb_hub.py +++ b/notebook_nueva/usb_hub.py @@ -1,6 +1,6 @@ import cadquery as cq -from utils import punch_hole2, extrude_shape, extrude_shape2 +from utils import punch_hole, extrude_shape # Measurements for my USB hub, YMMV @@ -54,16 +54,16 @@ def add( face=bottom_face, w=width, h=height, - x_offset=offset_x + element["x"], - y_offset=shell_t + offset_y + element["y"], - shape=element["shape"], + x_offset=offset_x, + y_offset=shell_t + offset_y, + element=element, height=-(element["height"] + shell_t), ) # Holes if back_face: for hole in holes: - model = punch_hole2( + model = punch_hole( model=model, face=back_face, w=width, diff --git a/notebook_nueva/utils.py b/notebook_nueva/utils.py index 29659ac..38e78fe 100644 --- a/notebook_nueva/utils.py +++ b/notebook_nueva/utils.py @@ -1,12 +1,13 @@ import cadquery as cq +from math import floor -# TODO make API of extrude_shape and punch_hole more consistent -def extrude_shape(*, model, face, w, h, x_offset, y_offset, shape, height): + +def extrude_shape(*, model, face, w, h, x_offset, y_offset, element, height): return ( model.faces(face) .workplane(centerOption="CenterOfBoundBox") - .center(-w / 2 + x_offset, -h / 2 + y_offset) - .placeSketch(shape) + .center(-w / 2 + x_offset + element["x"], -h / 2 + y_offset + element["y"]) + .placeSketch(element["shape"]) .extrude(height) ) @@ -16,12 +17,7 @@ def punch_hole(*, model, face, w, h, x_offset, y_offset, hole, depth): model.faces(face) .workplane(centerOption="CenterOfBoundBox") .center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"]) - .placeSketch( - cq.Sketch() - .trapezoid(hole["width"], hole["height"], 90, mode="a") - .vertices() - .fillet(hole["fillet"]) - ) + .placeSketch(hole["shape"]) .cutBlind(-depth) ) @@ -36,31 +32,41 @@ def extrude_shape2(*, model, face, w, h, x_offset, y_offset, hole, depth): ) -def punch_hole2(*, model, face, w, h, x_offset, y_offset, hole, depth): - return ( - model.faces(face) - .workplane(centerOption="CenterOfBoundBox") - .center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"]) - .placeSketch(hole["shape"]) - .cutBlind(-depth) - ) - - def hex_vents(*, size, width, height): + # size is radius of the hexagon + # Information about how this works: + # https://www.redblobgames.com/grids/hexagons/ + + x_step = size * (3**0.5) + y_step = size * 3 / 2 + + x_count = floor(width / x_step) - 1 + + if height > 4 * size: + y_count = floor((height - 2 * size) / (1.5 * size)) + else: + y_count = 1 + + x_size = (x_count + 0.5) * x_step # Assumes at least 2 rows + y_size = 2 * size + 1.5 * size * (y_count - 1) + + x_offset = (width - x_size) / 2 + 0.5 * x_step + y_offset = (height - y_size) / 2 + size + vent_positions = [] - for x in range(1, width // size): - for y in range(1, int(height // size / 0.8)): + for x in range(0, x_count): + for y in range(0, y_count): vent_positions.append( ( - (x + (y % 2) / 2) * size - size * 0.2, - y * size * 0.8 + size * 0.2, + (x + (y % 2) / 2) * x_step + x_offset, + y * y_step + y_offset, ) ) vents = [ { "x": 0, "y": 0, - "shape": cq.Sketch().push(vent_positions).regularPolygon((size) / 2, 6), + "shape": cq.Sketch().push(vent_positions).regularPolygon(size * 0.9, 6), } ] diff --git a/notebook_nueva/zero_holder.py b/notebook_nueva/zero_holder.py index daf8d10..0895873 100644 --- a/notebook_nueva/zero_holder.py +++ b/notebook_nueva/zero_holder.py @@ -1,6 +1,6 @@ import cadquery as cq -from utils import extrude_shape, punch_hole2, hex_vents +from utils import extrude_shape, punch_hole, hex_vents width = 65 height = 30 @@ -42,7 +42,7 @@ elements = [ }, ] -vents = hex_vents(size=6, width=width, height=height) +vents = hex_vents(size=3, width=width, height=height) holes = [ # One hole for everything TODO: improve @@ -70,7 +70,7 @@ def add( if bottom_face: # Vents for vent in vents: - model = punch_hole2( + model = punch_hole( model=model, face=bottom_face, w=width, @@ -88,16 +88,16 @@ def add( face=bottom_face, w=width, h=height, - x_offset=offset_x + element["x"], - y_offset=shell_t + offset_y + element["y"], - shape=element["shape"], + x_offset=offset_x, + y_offset=shell_t + offset_y, + element=element, height=-(element["height"] + shell_t), ) # Holes if back_face: for hole in holes: - model = punch_hole2( + model = punch_hole( model=model, face=back_face, w=width,