Use proper CONSTANT_FORMAT
This commit is contained in:
parent
b766fc465a
commit
8293ebe799
163
src/main.py
163
src/main.py
|
|
@ -1,47 +1,50 @@
|
|||
import datetime
|
||||
from math import radians, sin, cos
|
||||
"""
|
||||
Generate Dactyl case
|
||||
"""
|
||||
|
||||
from math import radians, sin
|
||||
from lib import *
|
||||
from shapes import *
|
||||
import lib
|
||||
import mat
|
||||
|
||||
switch_thickness = 1.3
|
||||
switch_top_thickness = 2.8
|
||||
web_thickness = 3
|
||||
switch_rim_thickness = 2
|
||||
SWITCH_THICKNESS = 1.3
|
||||
SWITCH_TOP_THICKNESS = 2.8
|
||||
WEB_THICKNESS = 3
|
||||
SWITCH_RIM_THICKNESS = 2
|
||||
|
||||
post_width = 0.5
|
||||
post_rad = post_width / 2
|
||||
POST_WIDTH = 0.5
|
||||
POST_RAD = POST_WIDTH / 2
|
||||
|
||||
keyhole_size = 13.8
|
||||
keyswitch_height = 15
|
||||
keyswitch_width = 15
|
||||
KEYHOLE_SIZE = 13.8
|
||||
KEYSWITCH_HEIGHT = 15
|
||||
KEYSWITCH_WIDTH = 15
|
||||
|
||||
plate_outer_width = keyhole_size + switch_rim_thickness * 2
|
||||
PLATE_OUTER_WIDTH = KEYHOLE_SIZE + SWITCH_RIM_THICKNESS * 2
|
||||
|
||||
max_num_rows = 4
|
||||
num_cols = 6
|
||||
num_pinky_columns = 2
|
||||
MAX_NUM_ROWS = 4
|
||||
NUM_COLS = 6
|
||||
NUM_PINKY_COLUMNS = 2
|
||||
|
||||
cols_with_max_rows = [2, 3]
|
||||
|
||||
sa_profile_key_height = 2
|
||||
cap_top_height = switch_top_thickness + sa_profile_key_height
|
||||
SA_PROFILE_KEY_HEIGHT = 2
|
||||
CAP_TOP_HEIGHT = SWITCH_TOP_THICKNESS + SA_PROFILE_KEY_HEIGHT
|
||||
|
||||
# extra space between the base of keys
|
||||
extra_height = 3
|
||||
extra_width = 3
|
||||
mount_height = keyswitch_height
|
||||
mount_width = keyswitch_width
|
||||
EXTRA_HEIGHT = 3
|
||||
EXTRA_WIDTH = 3
|
||||
MOUNT_HEIGHT = KEYSWITCH_HEIGHT
|
||||
MOUNT_WIDTH = KEYSWITCH_WIDTH
|
||||
# use 10 for faster prototyping, 15 for real
|
||||
tenting_angle = 11.0
|
||||
z_offset = 9.0
|
||||
TENTING_ANGLE = 11.0
|
||||
Z_OFFSET = 9.0
|
||||
|
||||
should_include_risers = False
|
||||
SHOULD_INCLUDE_RISERS = False
|
||||
|
||||
|
||||
def is_pinky(col):
|
||||
return col >= num_cols - num_pinky_columns
|
||||
return col >= NUM_COLS - NUM_PINKY_COLUMNS
|
||||
|
||||
|
||||
# aka: alpha
|
||||
|
|
@ -53,13 +56,13 @@ def row_curve_deg(col):
|
|||
# aka: beta
|
||||
col_curve_deg = 4.0
|
||||
|
||||
column_radius = cap_top_height + ((mount_width + extra_width) / 2) / sin(
|
||||
column_radius = CAP_TOP_HEIGHT + ((MOUNT_WIDTH + EXTRA_WIDTH) / 2) / sin(
|
||||
radians(col_curve_deg) / 2
|
||||
)
|
||||
|
||||
|
||||
def row_radius(col):
|
||||
return cap_top_height + ((mount_height + extra_height) / 2) / sin(
|
||||
return CAP_TOP_HEIGHT + ((MOUNT_HEIGHT + EXTRA_HEIGHT) / 2) / sin(
|
||||
radians(row_curve_deg(col)) / 2
|
||||
)
|
||||
|
||||
|
|
@ -80,13 +83,13 @@ def column_extra_transform(col):
|
|||
|
||||
def num_rows_for_col(col):
|
||||
if col in cols_with_max_rows:
|
||||
return max_num_rows
|
||||
return MAX_NUM_ROWS
|
||||
else:
|
||||
return max_num_rows - 1
|
||||
return MAX_NUM_ROWS - 1
|
||||
|
||||
|
||||
def does_coord_exist(row, col):
|
||||
return col >= 0 and col < num_cols and row >= 0 and row < num_rows_for_col(col)
|
||||
return col >= 0 and col < NUM_COLS and row >= 0 and row < num_rows_for_col(col)
|
||||
|
||||
|
||||
def negative(vect):
|
||||
|
|
@ -102,21 +105,21 @@ def bottom_hull(shape):
|
|||
|
||||
|
||||
def single_switch_fn():
|
||||
outer_width = keyhole_size + switch_rim_thickness * 2
|
||||
outer_width = KEYHOLE_SIZE + SWITCH_RIM_THICKNESS * 2
|
||||
|
||||
bottom_wall = cube(outer_width, switch_rim_thickness, switch_thickness)
|
||||
top_wall = translate(0, keyhole_size + switch_rim_thickness, 0)(bottom_wall)
|
||||
bottom_wall = cube(outer_width, SWITCH_RIM_THICKNESS, SWITCH_THICKNESS)
|
||||
top_wall = translate(0, KEYHOLE_SIZE + SWITCH_RIM_THICKNESS, 0)(bottom_wall)
|
||||
|
||||
left_wall = cube(switch_rim_thickness, outer_width, switch_thickness)
|
||||
right_wall = translate(keyhole_size + switch_rim_thickness, 0, 0)(left_wall)
|
||||
left_wall = cube(SWITCH_RIM_THICKNESS, outer_width, SWITCH_THICKNESS)
|
||||
right_wall = translate(KEYHOLE_SIZE + SWITCH_RIM_THICKNESS, 0, 0)(left_wall)
|
||||
|
||||
nub_len = 2.75
|
||||
nub_cyl = translate(0, 0, -1)(rotate_x(90)(cylinder(1, nub_len, 30, center=True)))
|
||||
# nub_cube = translate(-switch_rim_thickness / 2, 0, 0.)(cube(switch_rim_thickness, nub_len, 4, center=True))
|
||||
# left_nub = translate(switch_rim_thickness, (outer_width) / 2, 0)(hull(nub_cyl, nub_cube))
|
||||
# nub_cube = translate(-SWITCH_RIM_THICKNESS / 2, 0, 0.)(cube(SWITCH_RIM_THICKNESS, nub_len, 4, center=True))
|
||||
# left_nub = translate(SWITCH_RIM_THICKNESS, (outer_width) / 2, 0)(hull(nub_cyl, nub_cube))
|
||||
|
||||
# right_nub_cube = translate(switch_rim_thickness / 2, 0, 0)(cube(switch_rim_thickness, nub_len, 4, center=True))
|
||||
# right_nub = translate(-switch_rim_thickness + outer_width, (outer_width) / 2, 0)(hull(nub_cyl, right_nub_cube))
|
||||
# right_nub_cube = translate(SWITCH_RIM_THICKNESS / 2, 0, 0)(cube(SWITCH_RIM_THICKNESS, nub_len, 4, center=True))
|
||||
# right_nub = translate(-SWITCH_RIM_THICKNESS + outer_width, (outer_width) / 2, 0)(hull(nub_cyl, right_nub_cube))
|
||||
|
||||
return translate(-outer_width / 2, -outer_width / 2, 0)(
|
||||
union(
|
||||
|
|
@ -132,8 +135,8 @@ def single_switch_fn():
|
|||
|
||||
single_switch = single_switch_fn()
|
||||
|
||||
filled_switch = translate(0, 0, switch_thickness / 2.0)(
|
||||
cube(plate_outer_width, plate_outer_width, switch_thickness, center=True)
|
||||
filled_switch = translate(0, 0, SWITCH_THICKNESS / 2.0)(
|
||||
cube(PLATE_OUTER_WIDTH, PLATE_OUTER_WIDTH, SWITCH_THICKNESS, center=True)
|
||||
)
|
||||
|
||||
sa_length = 16.5
|
||||
|
|
@ -160,7 +163,7 @@ def sa_cap_fn():
|
|||
top = translate(0, 0, sa_extra_height)(top)
|
||||
|
||||
return colour(220, 163, 163, 1)(
|
||||
translate(0, 0, switch_top_thickness + 1.5)(hull(bot, mid, top))
|
||||
translate(0, 0, SWITCH_TOP_THICKNESS + 1.5)(hull(bot, mid, top))
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -168,8 +171,8 @@ sa_cap = sa_cap_fn()
|
|||
|
||||
|
||||
def row_cols():
|
||||
for row in range(max_num_rows):
|
||||
for col in range(num_cols):
|
||||
for row in range(MAX_NUM_ROWS):
|
||||
for col in range(NUM_COLS):
|
||||
if row < num_rows_for_col(col):
|
||||
yield (row, col)
|
||||
|
||||
|
|
@ -178,11 +181,11 @@ def all_of_shape(shape):
|
|||
return [grid_position(row, col, shape) for (row, col) in row_cols()]
|
||||
|
||||
|
||||
web_post = translate(-post_rad, -post_rad, switch_thickness - web_thickness)(
|
||||
cube(post_width, post_width, web_thickness)
|
||||
web_post = translate(-POST_RAD, -POST_RAD, SWITCH_THICKNESS - WEB_THICKNESS)(
|
||||
cube(POST_WIDTH, POST_WIDTH, WEB_THICKNESS)
|
||||
)
|
||||
short_web_post = translate(-post_rad, -post_rad, 0)(
|
||||
cube(post_width, post_width, post_width)
|
||||
short_web_post = translate(-POST_RAD, -POST_RAD, 0)(
|
||||
cube(POST_WIDTH, POST_WIDTH, POST_WIDTH)
|
||||
)
|
||||
|
||||
SQUARE_OFFSET_IDXS = [
|
||||
|
|
@ -209,7 +212,7 @@ def apply_translate_square(square, shape):
|
|||
return square_apply(square, fn)
|
||||
|
||||
|
||||
outer_post_delta = keyhole_size / 2 + switch_rim_thickness # - post_rad/2
|
||||
outer_post_delta = KEYHOLE_SIZE / 2 + SWITCH_RIM_THICKNESS # - POST_RAD/2
|
||||
|
||||
outer_post_translate_square = square_translater_at_offset(outer_post_delta)
|
||||
|
||||
|
|
@ -221,7 +224,7 @@ web_post_bl = translate(-outer_post_delta, -outer_post_delta, 0)(web_post)
|
|||
web_posts = apply_translate_square(outer_post_translate_square, web_post)
|
||||
short_web_posts = apply_translate_square(outer_post_translate_square, short_web_post)
|
||||
|
||||
inner_post_delta = keyhole_size / 2 + post_rad
|
||||
inner_post_delta = KEYHOLE_SIZE / 2 + POST_RAD
|
||||
inner_post_translate_square = square_translater_at_offset(inner_post_delta)
|
||||
|
||||
inner_web_posts = apply_translate_square(inner_post_translate_square, web_post)
|
||||
|
|
@ -304,8 +307,8 @@ def place_on_grid_base(row, column, domain):
|
|||
# Column offset
|
||||
domain.translate(*column_offset(column)),
|
||||
# Misc
|
||||
domain.rotate_y(tenting_angle),
|
||||
domain.translate(0, 0, z_offset),
|
||||
domain.rotate_y(TENTING_ANGLE),
|
||||
domain.translate(0, 0, Z_OFFSET),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -331,8 +334,8 @@ def connectors():
|
|||
return hull(*posts1, *posts2)
|
||||
|
||||
all_connectors = []
|
||||
for col in range(num_cols - 1):
|
||||
for row in range(max_num_rows):
|
||||
for col in range(NUM_COLS - 1):
|
||||
for row in range(MAX_NUM_ROWS):
|
||||
if does_coord_exist(row, col) and does_coord_exist(row, col + 1):
|
||||
if (row, col) == (0, 3):
|
||||
right_edge = [
|
||||
|
|
@ -348,8 +351,8 @@ def connectors():
|
|||
)
|
||||
)
|
||||
|
||||
for col in range(num_cols):
|
||||
for row in range(max_num_rows - 1):
|
||||
for col in range(NUM_COLS):
|
||||
for row in range(MAX_NUM_ROWS - 1):
|
||||
if does_coord_exist(row, col) and does_coord_exist(row + 1, col):
|
||||
all_connectors.append(
|
||||
make_edge_connection(
|
||||
|
|
@ -357,7 +360,7 @@ def connectors():
|
|||
)
|
||||
)
|
||||
|
||||
for col in range(num_cols - 1):
|
||||
for col in range(NUM_COLS - 1):
|
||||
row = num_rows_for_col(col) - 1
|
||||
next_col = col + 1
|
||||
next_row = num_rows_for_col(next_col) - 1
|
||||
|
|
@ -395,8 +398,8 @@ def connectors():
|
|||
return False
|
||||
return True
|
||||
|
||||
for col in range(num_cols - 1):
|
||||
for row in range(max_num_rows - 1):
|
||||
for col in range(NUM_COLS - 1):
|
||||
for row in range(MAX_NUM_ROWS - 1):
|
||||
if does_diag_exist(row, col):
|
||||
p1 = grid_position(row, col, web_post_br)
|
||||
p2 = grid_position(row + 1, col, web_post_tr)
|
||||
|
|
@ -487,7 +490,7 @@ def wall_connect_from_placer(
|
|||
|
||||
shapes = []
|
||||
|
||||
if should_include_risers:
|
||||
if SHOULD_INCLUDE_RISERS:
|
||||
shapes.append(hull(place_fn1(post1), place_fn2(post2)))
|
||||
|
||||
if connectors:
|
||||
|
|
@ -515,15 +518,15 @@ def case_walls():
|
|||
all_shapes = []
|
||||
|
||||
# Top wall
|
||||
for col in range(0, num_cols):
|
||||
for col in range(0, NUM_COLS):
|
||||
all_shapes.append(wall_connect(0, col, square_idx_tl, 0, col, square_idx_tr))
|
||||
for col in range(0, num_cols - 1):
|
||||
for col in range(0, NUM_COLS - 1):
|
||||
all_shapes.append(
|
||||
wall_connect(0, col, square_idx_tr, 0, col + 1, square_idx_tl)
|
||||
)
|
||||
|
||||
# Right wall
|
||||
max_col = num_cols - 1
|
||||
max_col = NUM_COLS - 1
|
||||
for row in range(0, num_rows_for_col(max_col)):
|
||||
all_shapes.append(
|
||||
wall_connect(row, max_col, square_idx_tr, row, max_col, square_idx_br)
|
||||
|
|
@ -545,7 +548,7 @@ def case_walls():
|
|||
def include_wall(col):
|
||||
return col >= 2
|
||||
|
||||
for col in range(0, num_cols):
|
||||
for col in range(0, NUM_COLS):
|
||||
all_shapes.append(
|
||||
wall_connect(
|
||||
num_rows_for_col(col) - 1,
|
||||
|
|
@ -557,7 +560,7 @@ def case_walls():
|
|||
walls=include_wall(col),
|
||||
)
|
||||
)
|
||||
for col in range(0, num_cols - 1):
|
||||
for col in range(0, NUM_COLS - 1):
|
||||
all_shapes.append(
|
||||
wall_connect(
|
||||
num_rows_for_col(col) - 1,
|
||||
|
|
@ -984,7 +987,7 @@ def bottom_edge_at_position(row, col):
|
|||
|
||||
|
||||
def bottom_edge_iterator():
|
||||
for col in range(num_cols):
|
||||
for col in range(NUM_COLS):
|
||||
row = num_rows_for_col(col) - 1
|
||||
|
||||
yield from bottom_edge_at_position(row, col)
|
||||
|
|
@ -1047,11 +1050,11 @@ def screw_insert(col, row, shape, ox, oy):
|
|||
def screw_insert_all_shapes(shape):
|
||||
return union(
|
||||
screw_insert(2, 0, shape, -5.3, 5.9),
|
||||
screw_insert(num_cols - 1, 0, shape, 6.7, 5.5),
|
||||
screw_insert(num_cols - 1, num_rows_for_col(num_cols - 1), shape, 6.8, 14.4),
|
||||
screw_insert(NUM_COLS - 1, 0, shape, 6.7, 5.5),
|
||||
screw_insert(NUM_COLS - 1, num_rows_for_col(NUM_COLS - 1), shape, 6.8, 14.4),
|
||||
screw_insert(0, 0, shape, -6.2, -8),
|
||||
screw_insert(1, max_num_rows + 1, shape, -9.8, 3.4),
|
||||
screw_insert(0, max_num_rows - 1, shape, -17.4, -2),
|
||||
screw_insert(1, MAX_NUM_ROWS + 1, shape, -9.8, 3.4),
|
||||
screw_insert(0, MAX_NUM_ROWS - 1, shape, -17.4, -2),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -1063,7 +1066,7 @@ trrs_front_thickness = 1.8
|
|||
|
||||
|
||||
def trrs_key_holder_position():
|
||||
base_place = point_on_grid(0, 0, 0, keyswitch_width / 2, 0)
|
||||
base_place = point_on_grid(0, 0, 0, KEYSWITCH_WIDTH / 2, 0)
|
||||
return [base_place[0] - 5, base_place[1] + 1.43, 9.0]
|
||||
|
||||
|
||||
|
|
@ -1101,7 +1104,7 @@ usb_holder_thickness = 0.5
|
|||
|
||||
|
||||
def usb_holder_position():
|
||||
base_place = point_on_grid(0, 0, 0, keyswitch_width / 2, 0)
|
||||
base_place = point_on_grid(0, 0, 0, KEYSWITCH_WIDTH / 2, 0)
|
||||
return [base_place[0] + 8, base_place[1] + 2, 4]
|
||||
|
||||
|
||||
|
|
@ -1181,8 +1184,8 @@ reset_switch_body_hole = place_reset_switch_shape(unplaced_reset_switch_body_hol
|
|||
|
||||
|
||||
def right_shell():
|
||||
global should_include_risers
|
||||
should_include_risers = True
|
||||
global SHOULD_INCLUDE_RISERS
|
||||
SHOULD_INCLUDE_RISERS = True
|
||||
|
||||
cover = translate(-60, 20, 0)(cube(15, 15, 20))
|
||||
|
||||
|
|
@ -1232,8 +1235,8 @@ def wall_shape():
|
|||
|
||||
|
||||
def model_outline():
|
||||
global should_include_risers
|
||||
should_include_risers = True
|
||||
global SHOULD_INCLUDE_RISERS
|
||||
SHOULD_INCLUDE_RISERS = True
|
||||
|
||||
solid_bottom = project()(
|
||||
union(
|
||||
|
|
@ -1274,7 +1277,7 @@ def place_weight_hole(x, y):
|
|||
def bottom_weight_cutouts():
|
||||
shapes = []
|
||||
|
||||
base_point = point_on_grid(0, num_cols - 1, 0, 0, 0)
|
||||
base_point = point_on_grid(0, NUM_COLS - 1, 0, 0, 0)
|
||||
base_x = base_point[0] - 9
|
||||
base_y = base_point[1] - 4
|
||||
|
||||
|
|
@ -1335,7 +1338,7 @@ def bottom_plate():
|
|||
cylinderr1r2(screw_hole_radius, screw_hole_radius, bottom_height)
|
||||
),
|
||||
# bottom_weight_cutouts(),
|
||||
# reset_switch_body_hole,
|
||||
reset_switch_body_hole,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -1345,8 +1348,8 @@ def left_bottom_plate():
|
|||
|
||||
|
||||
def thumb_corner():
|
||||
global should_include_risers
|
||||
should_include_risers = False
|
||||
global SHOULD_INCLUDE_RISERS
|
||||
SHOULD_INCLUDE_RISERS = False
|
||||
return difference(
|
||||
union(
|
||||
thumb_switches(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue