def addPin(nr,c,name,direction): if direction == "R": x = width +p y = (1.5+ c)*p r = 0 f = 0 elif direction == "L": x = p y = p*(1.5 +c) r = 0 f = 1 elif direction == "T": x = (1.5+ c)*p y = p r = 90 f = 1 elif direction == "B": x = p*(1.5 +c) y = height +p r = 90 f = 0 if f == 0: name_anchor = "end" nr_anchor = "start" direction = 1 else: name_anchor = "start" nr_anchor = "end" direction = -1 svg.add_start_g(transform="rotate({r}, {x}, {y}) translate({x},{y}) ".format(x=x,y=y,r=r)) svg.add_path(d=( svg.M(0,-1.2), svg.H(p*direction), svg.V(1.2), svg.H(0), svg.z()), id="connector{0}pin".format(nr)) svg.add_path(d=( svg.M((p)*direction-2.4*direction,-1.2), svg.h(2.4*direction), svg.v(2.4), svg.h(-2.4*direction), svg.z()), id="connector{0}terminal".format(nr)) svg.add_text(name, x=-3*direction, y=3, font_size=10, font_family="DroidSans", text_anchor=name_anchor) svg.add_text(nr, x=+3*direction, y=-2, font_size=7, font_family="DroidSans", text_anchor=nr_anchor) svg.add_end_g()
def create(width, height, name, file_name=None): if file_name == None: file_name = "breadboard_{0}.svg".format(name) inner_l = 3.6 inner_r = 3.6 + width*7.2 inner_t = 3.6 + 7.2 inner_b = height*7.2 - 3.6 outer_l = inner_l -1 outer_r = inner_r +1 outer_t = inner_t - 2.8 outer_b = inner_b + 2.8 center_x = 0.5*(inner_r+inner_l) center_y = 0.5*(inner_t+inner_b) circle_r = 3.6 circle_t = center_y - circle_r circle_b = center_y + circle_r circle_half_way = inner_l + circle_r circle_inner_r = 1.8 circle_inner_t = center_y - circle_inner_r circle_inner_b = center_y + circle_inner_r circle_inner_half_way = inner_l + circle_inner_r debug = False if debug: scale = 16 start(1000, 1000, 1000, 1000, "px") add_start_g(transform='scale({s})'.format(s=scale)) # grid for i in range(int(500/7.2)): add_line(0,i*7.2,500,0, color="#4affff", width=0.5) add_line(i*7.2,0,0,500, color="#4affff", width=0.5) else: svg_width=outer_r-outer_l svg_height=(height-1)*7.2 + 2*1.08 start(svg_width,svg_height, svg_width*127./360, svg_height*127./360, "mm") add_start_g(id='breadboard', transform='translate({x},{y})'.format(x=-outer_l, y=-(7.2-1.08))) # dark background + left shadow add_path(d=( M(outer_l, outer_t), H(outer_r), V(outer_b), H(outer_l), z() ), fill="#202020") # main add_path(d=( M(inner_l, inner_t), V(circle_t), a(circle_r, circle_r, 0,1,1, 0, circle_r*2), V(inner_b), H(inner_r), V(inner_t), z() ), fill="#303030") #shadow top/bottom shadow_top = ( M(outer_l, outer_t), H(outer_r), L(inner_r, inner_t), H(inner_l), z()) add_path(d=shadow_top, fill="#3E3E3E") add_path(d=shadow_top, fill="#010101", transform="rotate(180, {0}, {1})".format(center_x, center_y),) #shadow right add_path(d=( M(outer_r, outer_t), V(outer_b), L(inner_r, inner_b), V(inner_t), z(), ), fill="#161616" ) # shadow circle top add_path(d=( M(inner_l, circle_t), A(circle_r,circle_r, 0,0,1, circle_half_way, center_y), H(x=circle_inner_half_way), A(circle_inner_r, circle_inner_r, 0,0,0, inner_l, circle_inner_t), z() ), fill="#1c1c1c" ) # shadow circle bottom add_path(d=( M(x=circle_half_way, y=center_y), A(circle_r, circle_r, 0,0,1, inner_l, circle_b), V(y=circle_inner_b), A(circle_inner_r, circle_inner_r, 0,0,0, circle_inner_half_way, center_y), z(), ), fill="#383838") # shadow half-circle add_path(d=( M(x=inner_l, y=circle_inner_t), A(circle_inner_r, circle_inner_r, 0,0,1, inner_l, circle_inner_b), z() ), fill="#272727") # pins for i in range(width): add_start_g(transform="translate({x},{y})".format(x=7.2*(1+i), y=7.2)) add_Pin(angle=0) add_bb_connector(width*2-i, y=-1.08) add_end_g() add_start_g(transform="translate({x},{y})".format(x=7.2*(1+i), y=(height)*7.2)) add_Pin(angle=180) add_bb_connector(i+1, y=-2*1.08) add_end_g() # circle for pin #1 add_circle(x=inner_l+4, y=inner_b-3, r=1.5,) # text add_text(text=name, fill="#e6e6e6", font_family="ocra10, OCRA", text_anchor="middle", font_size=5, x=center_x + circle_r/2, y=center_y+2) add_end_g() end() write(file_name)
def create(s, file_name): r,l,t,b = [getattr(s,"getSide")(i) for i in "RLTB"] p = 21.25 # grid height = p*(max(len(r), len(l))) width = p*(max(len(t), len(b))) svg_width = width +2*p svg_height = height+2*p svg.start(svg_width, svg_height, svg_width*127/360, svg_height*127/360, "mm") svg.add_start_g(id="schematic") def addPin(nr,c,name,direction): if direction == "R": x = width +p y = (1.5+ c)*p r = 0 f = 0 elif direction == "L": x = p y = p*(1.5 +c) r = 0 f = 1 elif direction == "T": x = (1.5+ c)*p y = p r = 90 f = 1 elif direction == "B": x = p*(1.5 +c) y = height +p r = 90 f = 0 if f == 0: name_anchor = "end" nr_anchor = "start" direction = 1 else: name_anchor = "start" nr_anchor = "end" direction = -1 svg.add_start_g(transform="rotate({r}, {x}, {y}) translate({x},{y}) ".format(x=x,y=y,r=r)) svg.add_path(d=( svg.M(0,-1.2), svg.H(p*direction), svg.V(1.2), svg.H(0), svg.z()), id="connector{0}pin".format(nr)) svg.add_path(d=( svg.M((p)*direction-2.4*direction,-1.2), svg.h(2.4*direction), svg.v(2.4), svg.h(-2.4*direction), svg.z()), id="connector{0}terminal".format(nr)) svg.add_text(name, x=-3*direction, y=3, font_size=10, font_family="DroidSans", text_anchor=name_anchor) svg.add_text(nr, x=+3*direction, y=-2, font_size=7, font_family="DroidSans", text_anchor=nr_anchor) svg.add_end_g() for data,direction in [(r,"R"), (l,"L"), (t,"T"), (b,"B")]: for i,pin in enumerate(data): if pin: name, description = s.pins.data[pin] addPin(pin, i, name, direction) svg.add_rect(p,p,width,height, fill="none", stroke_width=2.4, stroke="#000000") x = svg_width/2 r = 0 if not any(t): y = 18 elif not any(b): y = svg_height - 1 elif not any(r): r = 90 y = svg_height/2 x = svg_width -18 elif not any(l): r = 270 y = svg_height/2 x = 18 else: x = svg_width/2 y = svg_height/2 r = 270 if width < height else 0 if r != 0: rotate = dict(rotate="rotate({r},{x},{y})".format(r=r,x=x,y=y)) else: rotate = dict() svg.add_text(s.meta.name, font_size=18, font_family="DroidSans", text_anchor="middle", x=x, y=y, **rotate) # name! svg.add_end_g() svg.end() svg.write(file_name)