from cad_shapes import * mm_inch = 25.4 scale_factor = 1.0 def inchn(x): return mm_inch * x def inch(x): return scale_factor * mm_inch * x def wslot(x, y, width, height, angle = 0, chamfer = 0.2): slot = rectangle(-width/2, width/2, -height, 0) inset = triangle(width/2, 0, width/2 + width * chamfer, 0, width/2, -chamfer*width) inset = add(inset, reflect_x(inset)) slot = add(slot, inset) slot = rotate(slot, angle) slot = move(slot, x, y) return MString(slot) # Render boundaries cad.xmin = inchn(-18) cad.xmax = inchn(18) cad.ymin = inchn(-12) cad.ymax = inchn(12) #cad.mm_per_unit = 25.4 # inch units cad.mm_per_unit = 1.0 # Overall variables width = height = inch(18) lip = 0 th = 4.0 # Shelf variables shelf_width = inch(11.5) shelf_height = inch(6) shelf_offset = -height/6 wall_offset = th # Slot variables delta = width/2 - shelf_width/2 cham = 1.75 slot_depth = height/3 # Main panel panel = rectangle( -width/2 - lip, width/2 + lip, -height/2 - lip, height/2 + lip - inchn(0.2)) # Shelf shelf = rectangle( -shelf_width/2, shelf_width/2, shelf_offset-shelf_height/2, shelf_offset + shelf_height/2) panel = subtract(panel, shelf) # Slots slots = [] slots.append(-shelf_width/2 - delta/2) slots.append(-shelf_width/2 - wall_offset) slots.append(shelf_width/2 + wall_offset) slots.append(shelf_width/2 + delta/2) for x in slots: # front panel slot cutout = wslot(x, height/2, th, slot_depth, 0, cham) panel = subtract(panel, cutout) cad.function = panel