Beispiel #1
0
def read_edge():
    global vertices, faces, boundarys, toolpaths, contours, slices, \
        uiparams, noise_flag, tracks, gerber_data
    #
    # read edge file
    #
    definedFileTypes = [('gerber', '.gbl .gtl .gbr .cmp'), \
                        ('drill files', '.drl .dbd'), ('all files', '.*')]
    filename = askopenfilename(filetypes=definedFileTypes)

    if ((find(filename, ".gbr") != -1) | (find(filename, ".GBR") != -1)):
        print "reading PCB edge file", filename

        # Load data in SEPARATE data object
        [gerber_data2,edges] = load_file(filename)
        brdoutline = []
        brdseg = -1

        while len(edges) > 0:
            brdoutline.append([])
            brdseg += 1
            brdoutline[brdseg].extend(edges[0])
            edges.remove(edges[0])
            startpnt = brdoutline[brdseg][0]
            endpnt = brdoutline[brdseg][len(brdoutline[brdseg]) - 1]

            while (abs(startpnt[0] - endpnt[0]) > 10) | (abs(startpnt[1] - endpnt[1]) > 10):
                for seg in edges:
                    if abs(seg[0][0] - endpnt[0]) < 10:
                        if abs(seg[0][1] - endpnt[1]) < 10:
                            brdoutline[brdseg].extend(seg)
                            edges.remove(seg)
                            endpnt = brdoutline[brdseg][len(brdoutline[brdseg]) - 1]
                            continue
                    if abs(seg[len(seg) - 1][0] - endpnt[0]) < 10:
                        if abs(seg[len(seg) - 1][1] - endpnt[1]) < 10:
                            edges.remove(seg)
                            seg = seg[::-1]
                            brdoutline[brdseg].extend(seg)
                            endpnt = brdoutline[brdseg][len(brdoutline[brdseg]) - 1]

        pcb_edges = brdoutline
        pcb_edges = pyclipper.CleanPolygons(pcb_edges)

        # Remove existing edge
        layers = list(gerber_data.layers)
        for gl in layers:
            if gl.type == GerberLayer.TYPE_PCBEDGE: gerber_data.layers.remove(gl)

        # Add edge data to existing data
        gerber_data.layers.append(GerberReader.GerberLayer(True, "PCB Edge", pcb_edges, True, False, "blue", GerberLayer.TYPE_PCBEDGE))

        toolpaths = []

        if (find(filename, ".") != -1):
            index2 = find(filename, ".")
            if (find(filename, "/") != -1):
                index1 = find(filename, "/")
                while (find(filename[index1 + 1:index2], "/") != -1):
                    index1 = index1 + 1 + find(filename[index1 + 1:index2], "/")
                infileedge.set(filename[index1 + 1:index2])

        read(0)
Beispiel #2
0
def read(event):
    global vertices, faces, toolpaths, contours, slices, \
        uiparams, noise_flag, pcb_edges, boundarys

    uiparams.xmin = HUGE
    uiparams.xmax = -HUGE
    uiparams.ymin = HUGE
    uiparams.ymax = -HUGE
    uiparams.zmin = HUGE
    uiparams.zmax = -HUGE

    sum1 = 0
    sumReg = 0
    sumBound = 0
    sumTracks = 0
    sumPads = 0

    pcb_edges = []
    cbounds = pyclipper.Pyclipper()
    boundarys = []

    layers = list(gerber_data.layers);
    for gl in layers:
        if gl.type == GerberLayer.TYPE_PCBEDGE:
            gerber_data.layers.remove(gl)
            pcb_edges.extend(gl.points)
            for segment in gl.points:
                sum1 += len(segment)
                for vertex in segment:
                    x = vertex[0] * (10 ** (-gerber_data.fraction))
                    y = vertex[1] * (10 ** (-gerber_data.fraction))
                    if (x < uiparams.xmin): uiparams.xmin = x
                    if (x > uiparams.xmax): uiparams.xmax = x
                    if (y < uiparams.ymin): uiparams.ymin = y
                    if (y > uiparams.ymax): uiparams.ymax = y
            continue
        if gl.type == GerberLayer.TYPE_REGION:
            sumReg += len(gl.points)
            # regions.extend(gl.points)
            continue
        if gl.type == GerberLayer.TYPE_TRACK:
            sumTracks += len(gl.points)
            continue
        if gl.type == GerberLayer.TYPE_PAD:
            sumPads += len(gl.points)
            continue
        if gl.type == GerberLayer.TYPE_BOUNDARY:
            if gl.isDark:
                boundarys.extend(gl.points)
            else:
                cbounds.AddPaths(boundarys, pyclipper.PT_SUBJECT)
                cbounds.AddPaths(gl.points, pyclipper.PT_CLIP)
                boundarys = cbounds.Execute(pyclipper.CT_DIFFERENCE, pyclipper.PFT_NONZERO, pyclipper.PFT_NONZERO)
                cbounds.Clear()
            sumBound += len(gl.points)
            for segment in gl.points:
                sum1 += len(segment)
                for vertex in segment:
                    x = vertex[0] * (10 ** (-gerber_data.fraction))
                    y = vertex[1] * (10 ** (-gerber_data.fraction))
                    if (x < uiparams.xmin): uiparams.xmin = x
                    if (x > uiparams.xmax): uiparams.xmax = x
                    if (y < uiparams.ymin): uiparams.ymin = y
                    if (y > uiparams.ymax): uiparams.ymax = y
            continue
        if gl.type == GerberLayer.TYPE_MERGEDCOPPER:
            gerber_data.layers.remove(gl)
            continue

    print "   fraction = ",gerber_data.fraction
    print "   found", sumBound, "polygons,", sum1, "vertices"
    print "   found", sumReg, "pours"
    print "   found", sumTracks, "tracks"
    print "   found", sumPads, "pads"
    print "   found", len(pcb_edges), "edge segments"
    print "   xmin: %0.3g " % uiparams.xmin, "xmax: %0.3g " % uiparams.xmax, "dx: %0.3g " % (
        uiparams.xmax - uiparams.xmin)
    print "   ymin: %0.3g " % uiparams.ymin, "ymax: %0.3g " % uiparams.ymax, "dy: %0.3g " % (
        uiparams.ymax - uiparams.ymin)

    outer_offset = 0.01

    if len(pcb_edges) == 0:
        pcb_edge = []
        uiparams.xmax += outer_offset
        uiparams.ymax += outer_offset
        uiparams.xmin -= outer_offset
        uiparams.ymin -= outer_offset
        pcb_edge.append([uiparams.xmax / (10 ** (-gerber_data.fraction)), uiparams.ymax / (10 ** (-gerber_data.fraction))])
        pcb_edge.append([uiparams.xmax / (10 ** (-gerber_data.fraction)), uiparams.ymin / (10 ** (-gerber_data.fraction))])
        pcb_edge.append([uiparams.xmin / (10 ** (-gerber_data.fraction)), uiparams.ymin / (10 ** (-gerber_data.fraction))])
        pcb_edge.append([uiparams.xmin / (10 ** (-gerber_data.fraction)), uiparams.ymax / (10 ** (-gerber_data.fraction))])
        pcb_edges.extend(pcb_edge)
        pcb_edges = [pcb_edges]

    tmpb = GerberReader.replace_holes_with_seams(boundarys)
    gerber_data.layers.append(GerberReader.GerberLayer(True, "PCB Edge", pcb_edges, True, False, "blue", GerberLayer.TYPE_PCBEDGE))
    gerber_data.layers.append(GerberReader.GerberLayer(True, "Merged Copper", tmpb, False, color="brown", type=GerberLayer.TYPE_MERGEDCOPPER))
    # the boundary data with seams in it is for rendering purposes only.

    camselect(event)
    plot()
    autoscale(0)

    LayerEditor.createTable2(layerGeo, gerber_data, plot)