#!/usr/bin/python import shape # # gnuplot the outline # def outline_gnuplot(sk, points): while len(points): print points.pop(0), points.pop(0) print def gnuplot_line(x0, y0, x1, y1): print x0, y0 print x1, y1 print # # make a HeeksCAD sketch of the outline # def cad_line(sk, x0, y0, x1, y1): cad.line(x0, y0, x1, y1) cad.add(sk, cad.getlastobj()) def outline_cad(sk, points): last_x = points.pop(0) last_y = points.pop(0) while len(points): x = points.pop(0) y = points.pop(0) cad_line(sk, last_x, last_y, x, y) last_x = x last_y = y cad.reorder(sk) return sk def closed_outline(sk, *args): l = list(args) l.append(args[0]) l.append(args[1]) do(sk, l) def open_outline(sk, *args): do(sk, list(args)) def line(*args): do_line(*args) # # Make the cover sheet 2 mm larger than the counterweight on all sides. We need # the following exceptions to avoid mechanical interference: # # - at the power connector, keep the ymin edge flush with the counterweight # - follow the counterweight's J-shaped space for the reset button, with the # border reduced from 2 mm to 0.5 mm # - next to the long side of the battery, follow the counterweight's edge # - also follow the counterweight's bay for the battery cover's tongue and # make it even 0.5 mm larger, anticipating imperfect registration # # Also, as a simplification, we don't follow steps and recesses in these cases: # # - 1 mm steps on the left and right side. Just use the larger size. # - the whole sponge area. Just put the cover on top of the sponge. # - all recesses near the batter, except the one for the lid's central tongue # # The above simplifications are possible, because, being on top of the # counterweight, we've already cleared the obstacles these steps and recesses # are designed to avoid. # # # Note: to visualize the shape defined below, plot the counterweight in 2D with # gnuplot and follow the shape it the mouse. # # To visualize the result, do this: # # ./cw.py >cw.gnuplot # ./cvr.py >cvr.gnuplot # gnuplot # gnuplot> set style data lines # gnuplot> plot "cw.gnuplot", "cvr.gnuplot" # def outline(sk): closed_outline(sk, # counterweight corners: (16, 46) and (15, 60) 13, 46, # (15, 69.5) 13, 71.5, # (82.5, 65), (82.5, 64), (89.5, 64), (89.5, 69) 83, 71.5, 83, 64.5, 89, 64.5, 89, 71, # (100, 69) 102, 71, # (99.5, 46) 102, 44, # (88, 46) 86, 44, # (88, 55), (82, 50) 86, 50, # (59.5, 55), (59.5, 56.5), (52.5, 56.5), (52.5, 55) 60, 50, 60, 57, 52, 57, 52, 50, # (24, 55) 26, 50, # (24, 46) 26, 46) def label(sk): u = 2 x = 40 y = 66 # C open_outline(sk, x+u, y+2*u, x, y+2*u, x, y, x+u, y) x += u*1.6 # W open_outline(sk, x, y+2*u, x, y, x+0.5*u, y+u, x+u, y, x+u, y+2*u) # ----- Counterweight outline ------------------------------------------------- lines = [] def rect_outline(x0, y0, z0, x1, y1, z1): global lines lines.append((x0, y0, x0, y1)) lines.append((x1, y0, x1, y1)) lines.append((x0, y0, x1, y0)) lines.append((x0, y1, x1, y1)) # ----- Main ------------------------------------------------------------------ if __name__ == "__main__": do = outline_gnuplot sk = None else: import HeeksPython as cad do = outline_cad cad.sketch() sk = cad.getlastobj() outline(sk) label(sk) shape.rect = rect_outline shape.make_base() if __name__ == "__main__": for e in lines: gnuplot_line(*e) else: for e in lines: cad_line(sk, *e)