Exemple #1
0
 def add_pin_shortcut(i,x,y,r=0):
     pin_nr = i
     svg.add_start_g(transform="translate({x},{y})".format(
                         x=x,
                         y=y))
     if r != 0: svg.add_start_g(transform="rotate({0})".format(r))
     add_pin(pin_nr)
     svg.add_end_g()
     if r != 0: svg.add_end_g()
Exemple #2
0
    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()
Exemple #3
0
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)
Exemple #4
0
def create(p, file_name):

    pin, size = p.definition["pin"].split(" ", 1)
    chip_width = to_pixel(p.definition["c"]) # TODO: error check
    pins_gap = to_pixel(p.definition["e"]) # TODO: error check

    if p.definition["ch"] != None:
        chip_height = to_pixel(p.definition["ch"])
    else:
        chip_height = None

    if pin.strip() == "THT":
        is_smd = False
        dimension = size.split(",")

        d, pin_width, pin_height = map(to_pixel, dimension)
        stroke_width = 0.5*(min(pin_width, pin_height) - d)

        def add_pin(nr):
            if pin_width == pin_height:
                svg.add_circle(0,0, d/2+stroke_width/2, stroke_width=stroke_width, fill="none", stroke="#F7BD13")
            else:
                offset = pin_width/3.
                svg.add_path(transform="rotate(90,0,0)",
                        d=(
                        svg.M(-pin_width/2+offset, -pin_height/2),
                        svg.h(pin_width-offset*2),
                        svg.l(offset, offset),
                        svg.v(pin_height-offset*2),
                        svg.l(-offset, offset),
                        svg.h(-pin_width+offset*2),
                        svg.l(-offset, -offset),
                        svg.v(-pin_height+offset*2),
                        svg.z(),
                        svg.M(0,-d/2),
                        svg.A(d/2, d/2, 0,1,0, 0, d/2), 
                        svg.A(d/2, d/2, 0,1,0, 0, -d/2), # can not draw a whole circle at once :-P
                        svg.z()
                        ), fill="#F7BD13")
            if nr != None:
                arg = dict(id="connector{0}pin".format(nr))
            else:
                arg = dict()
            svg.add_circle(0,0, d/2+stroke_width/2, stroke_width=stroke_width, fill="none", stroke="#F7BD13", **arg)


    else:
        is_smd = True
        pin_width,pin_height = map(to_pixel, size.split(","))
        def add_pin(nr):
            if nr != None:
                arg = dict(id="connector{0}pin".format(nr))
            else:
                arg = dict()
            svg.add_rect(-pin_width/2, -pin_height/2, pin_width, pin_height, fill="#F7BD13",
                    transform="rotate(90,0,0)", **arg)

    count = len(p.getPins())

    if chip_height == None:
        # only two sides
        svg_width = chip_width+pin_height
        svg_height = pins_gap*(count/2 )+1

        svg.start(svg_width, svg_height, svg_width*127/360, svg_height*127/360, "mm")
        #svg.add_rect(-500,-500,1000,1000) # debug
        transform_translate="translate({x},{y})".format(x=svg_width/2, y=0.5 + pins_gap * 0.5)
        offset = pin_height/2 + 1.5
        svg.add_start_g(id="silkscreen", transform=transform_translate)
        svg.add_path(d=(
                svg.M(-chip_width/2 + offset, 0-0.5*pins_gap),
                svg.v(pins_gap*count/2),
                svg.h(chip_width-offset*2),
                svg.v(-pins_gap*count/2),
                svg.z()
                ), stroke="#ffffff", fill="none")
        svg.add_circle(-chip_width/2 + offset + 3,-0.25*pins_gap +1 ,1.5, fill="#ffffff")
        svg.add_end_g()

        svg.add_start_g(id="copper1", transform=transform_translate)
        if not is_smd: svg.add_start_g(id="copper0")
        for i in range(count/2):
            #left
            svg.add_start_g(transform="translate({x},{y})".format(x=-chip_width/2,y=i*pins_gap))
            add_pin(i+1)
            svg.add_end_g()

            #right
            svg.add_start_g(transform="translate({x},{y})".format(x=+chip_width/2,y=(count/2-1-i)*pins_gap))
            add_pin(count-i)
            svg.add_end_g()

        if not is_smd: svg.add_end_g()
        svg.add_end_g()
    else:
        # 4 sides of pins
        
        svg_width = chip_width + pin_height
        svg_height = chip_height + pin_height

        svg.start(svg_width, svg_height, svg_width*127/360, svg_height*127/360, "mm")
        #svg.add_rect(-500,-500,1000,1000,fill="#cccccc") # debug
        transform_translate = "translate({x},{y})".format(x=chip_width/2+pin_height/2, y=chip_height/2+pin_height/2)
        #svg.add_circle(0,0,1,fill="0000ff") # debug
        
        offset_h = (chip_height - (count/4-1)*pins_gap) / 2
        offset_v = (chip_width - (count/4-1)*pins_gap) / 2

        svg.add_start_g(id="silkscreen", transform=transform_translate)
       
        svg.add_circle(-chip_width/2, -chip_height/2, pin_height/2, fill="#fff")

        for angle in (0,90,180,270):
            svg.add_path(d=(
                svg.M(-chip_width/2 + offset_h - 1, -chip_height/2),
                svg.h(-offset_h+1),
                svg.v(+offset_v-1),
                ),      fill="none",
                        stroke="#ffffff",
                        stroke_width="0.5",
                        transform="rotate({angle})".format(angle=angle))

        svg.add_end_g()


        svg.add_start_g(id="copper1", transform=transform_translate)
        if not is_smd: svg.add_start_g(id="copper0")

        def add_pin_shortcut(i,x,y,r=0):
            pin_nr = i
            svg.add_start_g(transform="translate({x},{y})".format(
                                x=x,
                                y=y))
            if r != 0: svg.add_start_g(transform="rotate({0})".format(r))
            add_pin(pin_nr)
            svg.add_end_g()
            if r != 0: svg.add_end_g()

        for i in range(count/4):
            #left
            add_pin_shortcut(
                    i=i+1,
                    x=-chip_width/2,
                    y=-chip_height/2 + offset_h + pins_gap*i)
            
            #bottom
            add_pin_shortcut(
                    i=1+ count/4 + i,
                    x=-chip_width/2 + offset_v + pins_gap*i,
                    y=chip_height/2,
                    r=90)
            
            #right
            add_pin_shortcut(
                    i=1+ 2*count/4 + i,
                    x=chip_width/2,
                    y=+chip_height/2 - offset_h - pins_gap*i)
            
            #top
            add_pin_shortcut(
                    i=1+ 3*count/4 + i,
                    x=chip_width/2 - offset_v - pins_gap*i,
                    y=-chip_height/2,
                    r=90)

        if not is_smd: svg.add_end_g()
        svg.add_end_g()

    svg.end()
    svg.write(file_name)
Exemple #5
0
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)