Ejemplo n.º 1
0
def SVG2Graphic(filename, board, layer):
    # the internal coorinate space of pcbnew is 10E-6 mm. (a millionth of a mm)
    # the coordinate 121550000 corresponds to 121.550000
    SCALE = 1000000.0

    # here I load from drawing.svg in the current directory. You'll want to change that path.
    paths = parse_svg_path.parse_svg_path(filename)
    if not paths:
        raise ValueError('wasnt able to read any paths from file')

    for path in paths:
        for shape in path.group_by_bound_and_holes():

            lastPt = shape.bound[0]
            for pt in shape.bound[1:]:
                # I'm getting repeated points from the svg. haven't investigated why.
                if (pt == lastPt):
                    continue
                make_line(board, lastPt, pt, layer)
                lastPt = pt

            for hole in shape.holes:
                lastPt = hole[0]
                for pt in hole[1:]:
                    if (pt == lastPt):
                        continue
                    make_line(board, lastPt, pt, layer)
                    lastPt = pt
Ejemplo n.º 2
0
def SVG2Zone(filename, board, layer, net):

    # the internal coorinate space of pcbnew is 10E-6 mm. (a millionth of a mm)
    # the coordinate 121550000 corresponds to 121.550000
    SCALE = 1000000.0


    # here I load from drawing.svg in the current directory. You'll want to change that path.
    paths = parse_svg_path.parse_svg_path(filename)
    if not paths:
        raise ValueError('wasnt able to read any paths from file')


    # things are a little tricky below, because the first boundary has its first
    # point passed into the creation of the new area. subsequent bounds are not
    # done that way.
    zone_container = None
    shape_poly_set = None

    for path in paths:
        for shape in path.group_by_bound_and_holes():
            shapeid = None
            if not shape_poly_set:
                # the call to GetNet() gets the netcode, an integer.
                zone_container = board.InsertArea(net.GetNet(), 0, layer,
                                                  int(shape.bound[0][0]*SCALE),
                                                  int(shape.bound[0][1]*SCALE),
                                                  pcbnew.CPolyLine.DIAGONAL_EDGE)
                shape_poly_set = zone_container.Outline()
                shapeid = 0
            else:
                shapeid = shape_poly_set.NewOutline()
                shape_poly_set.Append(int(shape.bound[0][0]*SCALE),
                                      int(shape.bound[0][1]*SCALE),
                                      shapeid)

            for pt in shape.bound[1:]:
                shape_poly_set.Append(int(pt[0]*SCALE), int(pt[1]*SCALE))

            for hole in shape.holes:
                hi = shape_poly_set.NewHole()
                # -1 to the third arg maintains the default behavior of
                # using the last outline.
                for pt in hole:
                    shape_poly_set.Append(int(pt[0]*SCALE), int(pt[1]*SCALE), -1, hi)

            zone_container.Hatch()
Ejemplo n.º 3
0
import inspect

import sys, os.path
oldpath = sys.path
# inspect.stack()[0][1] is the full path to the current file.
sys.path.insert(0, os.path.dirname(inspect.stack()[0][1]))
import parse_svg_path
sys.path = oldpath

paths = parse_svg_path.parse_svg_path(
    '/home/mmccoo/kicad/kicad_mmccoo/svg2border/drawing.svg')

for path in paths:
    print("path {}".format(parse_svg_path.path_bbox(path)))
    #for poly in path.polys:
    #print("    points {}".format(poly))
    #print("        is hole {}".format(parse_svg_path.poly_is_hole(poly)))
    # print("    points 18{}".format(poly))
    for shape in path.group_by_bound_and_holes():
        print("bounds: {}".format(shape.bound))
        print("with holes:")
        for hole in shape.holes:
            print("   hole: {}".format(hole))