from build123d import *
import os

OUT = "/app/projects/esp32-box/exports"
os.makedirs(OUT, exist_ok=True)

# Window dimensions for stretched box (corner=20mm for X, corner=20mm for Y)
# X-walls gap: 80-40 = 40mm, Y-walls gap: 70-40 = 30mm
# Window panel: gap width - 2mm each side for slot clearance
WIN_X_W = 36.0  # X-wall window width (fits 40mm gap)
WIN_Y_W = 26.0  # Y-wall window width (fits 30mm gap)  
WIN_H = 23.0    # window height (original stretched)
WIN_T = 4.8     # thickness (original)

def make_window(width, height, thick, cutouts=None):
    """Rectangular panel with retention tabs."""
    panel = Box(width, thick, height)
    # Retention tabs (original design)
    for side in [-1, 1]:
        tab = Pos(0, side*(thick/2-0.5), 0) * Box(width-2, 1.0, height+0.5)
        panel += tab
    # Cutouts
    if cutouts:
        for cx, cy, cw, ch in cutouts:
            panel -= Pos(cx, 0, cy) * Box(cw, thick+0.4, ch)
    return panel

# X-axis windows (front/back)
print("X-axis windows (36mm wide)...")
smooth_x = make_window(WIN_X_W, WIN_H, WIN_T)
export_stl(smooth_x, f"{OUT}/window_smooth.stl")

kc_x = [(-WIN_X_W/4, 0, 17, WIN_T+0.5), (WIN_X_W/4, 0, 9, 9)]
keystone_x = make_window(WIN_X_W, WIN_H, WIN_T, kc_x)
export_stl(keystone_x, f"{OUT}/window_keystone_dc.stl")

# Y-axis windows (left/right)
print("Y-axis windows (26mm wide)...")
smooth_y = make_window(WIN_Y_W, WIN_H, WIN_T)
export_stl(smooth_y, f"{OUT}/window_smooth_y.stl")

usb_y = [(-0, 0, 9, 5)]
usb_y_win = make_window(WIN_Y_W, WIN_H, WIN_T, usb_y)
export_stl(usb_y_win, f"{OUT}/window_usb.stl")

print("DONE")
