from cad_shapes import * mm_inch = 25.4 scale_factor = 0.2 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) def mslot(x, y, width, height): slot = rectangle(-width/2, width/2, -height, 0) slot = move(slot, x, y) return MString(slot) # Render boundaries cwidth = inchn(18) cheight = inchn(12) 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 = inch(1.5) th = 3.9 # 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 chamfer = 0.3 slot_depth = height/3 ################################### # Main panel panel = rectangle( -width/2,# - lip, width/2,# + lip, -height/2 - lip, height/2 + lip) # Shelf shelf = rectangle( -shelf_width/2, shelf_width/2, shelf_offset-shelf_height/2, shelf_offset + shelf_height/2) #panel = subtract(panel, shelf) # Slots x0 = -width/2 + width/7.0 base_th = 3.7 for step in range(0,6): x = x0 + step*width/7.0 cutout = mslot(x, height/2, base_th + step*0.1, height) panel = subtract(panel, cutout) top = panel ################################### # Main panel panel = rectangle( -width/2, width/2, -height/2, height/2 - th) # 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, chamfer) panel = subtract(panel, cutout) front = panel ################################### # Main panel panel = rectangle( -width/2, width/2, -height/2, height/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 slot_inc = width/7.0 x0 = -width/2 + slot_inc for step in range(0,6): # perp panel slot x = x0 + step*slot_inc cutout = reflect_y(wslot(x, 0, th, 2*slot_depth, 0, chamfer), 0) cutout = move(cutout, 0, -height/2, 0) panel = subtract(panel, cutout) perp = panel ################################### margin_left = -cwidth/1.2 margin_top = cheight/1.3 total = move(top, margin_left, margin_top, 0) tlip = 0.6*width tester = rectangle( -tlip, tlip, -tlip, tlip) extlip = 1.3*tlip widths = [0.95*width, width, 1.02*width, 1.05*width] for step in range(0,4): w = widths[step] r = rectangle(-w/2, w/2, 0, extlip) #c = circle(0, extlip, 0.05*step*height) #r = add(r, c) r = rotate(r, step*90) tester = add(tester, r) tester = move(tester, -cwidth/1.22, height/1.2, 0) total = add(total, tester) cad.function = total