Пример #1
0
def print_module(name, fill_paths, segment_paths, pads):

    print """PCBNEW-LibModule-V1
$INDEX
"""

    print name
    print """$EndINDEX
$MODULE """ + name + """
Po 0 0 0 15 00000000 00000000 ~~
Li """ + name

    for layer, filename in fill_paths:
        print >> sys.stderr, filename
        with open(filename) as f:
            polygons = svgpath.path_to_polygons(f.read(1000000))

        polygons = svgpath.rescale_polygon_list(polygons, svgpath.scale,
                                                roundint)
        polygons = weakly_simplefy(polygons)

        for p in polygons:
            print_polygon(p, layer)

    for layer, filename, width in segment_paths:
        with open(filename) as f:
            polygons = svgpath.path_to_polygons(f.read(1000000))

        polygons = svgpath.rescale_polygon_list(polygons, svgpath.scale,
                                                roundint)

        for p in polygons:
            print_segments(p, layer, width * svgpath.scale)

    for topleft, w, h, pitch, size in pads:
        pads = pad_grid(topleft, w, h, pitch)
        for pad in pads:
            print_pad(svgpath.rescale_point(pad, svgpath.scale, roundint),
                      size)

    print """$EndMODULE """ + name + """
Пример #2
0
def print_zones_new(zone_paths):

    for layer, label, filename in zone_paths:
        with open(filename) as f:
            polygons = svgpath.path_to_polygons(f.read(1000000))

        polygons = svgpath.rescale_polygon_list(polygons, svgpath.new_scale,
                                                roundint)
        polygons = weakly_simplefy(polygons)

        for p in polygons:
            print_zone_new(p)
Пример #3
0
def load_svg_path(filename,
                  scale=25.4 / 90.,
                  translate=(0, 0),
                  flipX=False,
                  flipY=False):
    with open(filename) as f:
        polygons = svgpath.path_to_polygons(readall(f))
        polygons = svgpath.transform_polygon_list(polygons,
                                                  scale=scale,
                                                  translate=translate,
                                                  flipX=flipX,
                                                  flipY=flipY,
                                                  conv=float)
    return polygons
Пример #4
0
def print_zones(zone_paths):

    for layer, label, filename in zone_paths:
        print """$CZONE_OUTLINE
ZInfo 525A79DA 1 """ + '"' + label + '"' + """
ZLayer """ + layer + """
ZAux 4 E
ZClearance 200 T
ZMinThickness 100
ZOptions 0 16 F 200 200
ZSmoothing 0 0"""
        with open(filename) as f:
            polygons = svgpath.path_to_polygons(f.read(1000000))

        polygons = svgpath.rescale_polygon_list(polygons, svgpath.scale,
                                                roundint)
        polygons = weakly_simplefy(polygons)

        for p in polygons:
            print_zone(p, layer, label)
        print """$endCZONE_OUTLINE"""
Пример #5
0
def extract_pcb_zone(f, zonename):

    tree = ET.parse(f)
    zones = []

    parent_map = {c: p for p in tree.iter() for c in p}

    for layer in tree.findall(
            ".//*[@{http://www.inkscape.org/namespaces/inkscape}groupmode='layer']"
    ):
        name = layer.get('{http://www.inkscape.org/namespaces/inkscape}label')
        namesplit = name.split(':')
        if len(namesplit) == 2 and namesplit[0] == 'zone':
            if zonename == namesplit[1]:
                for e in layer.findall(".//{http://www.w3.org/2000/svg}path"):
                    d = e.get("d")
                    transform = get_transform(e, parent_map)
                    polygons = [
                        apply_transform(transform, p)
                        for p in svgpath.path_to_polygons(d)
                    ]
                    zones.append(polygons)

    return zones
Пример #6
0
def extract_pcb_data(f, parent_layer=None, edges_as_segments=True):

    tree = ET.parse(f)
    segments = []
    paths = []
    pads = []
    vias = []
    holes = []
    slots = []

    parent_map = {c: p for p in tree.iter() for c in p}

    for layer in tree.findall(
            ".//*[@{http://www.inkscape.org/namespaces/inkscape}groupmode='layer']"
    ):
        name = layer.get('{http://www.inkscape.org/namespaces/inkscape}label')
        if parent_map[layer].get(
                '{http://www.inkscape.org/namespaces/inkscape}label',
                default=None) != parent_layer:
            continue
        print("Layer: ", name, file=sys.stderr)
        if name in fab_layers:
            for e in layer.findall(".//{http://www.w3.org/2000/svg}path"):
                d = e.get("d")
                style_elems = parse_style(e.get("style"))
                transform = get_transform(e, parent_map)
                polygons = [
                    apply_transform(transform, p)
                    for p in svgpath.path_to_polygons(d)
                ]
                if name == 'edges':
                    is_poly = not edges_as_segments
                else:
                    is_poly = ('fill' in style_elems
                               and style_elems['fill'] != 'none')

                if is_poly:
                    paths.append((name, polygons))
                else:  # if 'stroke' in style_elems and style_elems['stroke'] != 'none':
                    width = float(
                        style_elems['stroke-width']) * magnitude(transform)
                    segments.append((name, polygons, width))

        namesplit = name.split(':')
        if len(namesplit) == 3 and namesplit[0] == 'pads':
            size, drill = float(namesplit[1]), float(namesplit[2])
            for e in itertools.chain(
                    layer.findall(".//{http://www.w3.org/2000/svg}circle"),
                    layer.findall(".//{http://www.w3.org/2000/svg}ellipse")):
                x = float(e.get("cx"))
                y = float(e.get("cy"))
                transform = get_transform(e, parent_map)
                x, y = apply_transform(transform, [(x, y)])[0]
                pads.append((x, y, size, drill))

        if len(namesplit) == 3 and namesplit[0] == 'vias':
            size, drill = float(namesplit[1]), float(namesplit[2])
            for e in itertools.chain(
                    layer.findall(".//{http://www.w3.org/2000/svg}circle"),
                    layer.findall(".//{http://www.w3.org/2000/svg}ellipse")):
                x = float(e.get("cx"))
                y = float(e.get("cy"))
                transform = get_transform(e, parent_map)
                x, y = apply_transform(transform, [(x, y)])[0]
                vias.append((x, y, size, drill))

        if len(namesplit) == 2 and namesplit[0] == 'holes':
            drill = float(namesplit[1])
            for e in itertools.chain(
                    layer.findall(".//{http://www.w3.org/2000/svg}circle"),
                    layer.findall(".//{http://www.w3.org/2000/svg}ellipse")):
                x = float(e.get("cx"))
                y = float(e.get("cy"))
                transform = get_transform(e, parent_map)
                x, y = apply_transform(transform, [(x, y)])[0]
                holes.append((x, y, drill))

        if len(namesplit) == 3 and namesplit[0] == 'slots':
            copper_width = float(namesplit[1])
            drill_width = float(namesplit[2])
            for e in layer.findall(".//{http://www.w3.org/2000/svg}path"):
                d = e.get("d")
                style_elems = parse_style(e.get("style"))
                transform = get_transform(e, parent_map)
                polygons = [
                    apply_transform(transform, p)
                    for p in svgpath.path_to_polygons(d)
                ]
                if ('stroke' in style_elems and
                        style_elems['stroke'] != 'none') or name == 'edges':
                    slots.append((polygons, copper_width, drill_width))

    return (paths, segments, pads, vias, holes, slots)