Esempio n. 1
0
File: test.py Progetto: Pokour/kicad
def get_area():
    board = pcbnew.GetBoard()
    layertable = get_layertable()

    newarea = board.InsertArea(0, 0, layertable["F.Mask"], 0, 0,
                               pcbnew.CPolyLine.DIAGONAL_EDGE)

    newoutline = newarea.Outline()
    newoutline.Append(SCALE * 100, 0)
    newoutline.Append(SCALE * 100, SCALE * 100)
    newoutline.Append(0, SCALE * 100)
    #http://ci.kicad-pcb.org/job/kicad-doxygen/ws/build/pcbnew/doxygen-python/html/classpcbnew_1_1SHAPE__POLY__SET.html
    poly_set = pcbnew.SHAPE_POLY_SET()
    #http://ci.kicad-pcb.org/job/kicad-doxygen/ws/build/pcbnew/doxygen-python/html/classpcbnew_1_1CPolyLine.html
    poly_set.NewOutline()
    poly_set.Append(0, 0)
    poly_set.Append(SCALE * 100, 0)
    poly_set.Append(SCALE * 100, SCALE * 100)
    poly_set.Append(0, SCALE * 100)
    poly_set.Append(0, 0)
    newarea.AddFilledPolygon(poly_set)

    #newarea.AddFilledPolygon() # ?
    pcbnew.Refresh()
    return newarea
Esempio n. 2
0
def convert(pcb, brd):
    IU_PER_MM = PCB_IU_PER_MM = 1e6
    IU_PER_MILS = (IU_PER_MM * 0.0254)

    conv_unit_inch = 0.001 / IU_PER_MILS
    conv_unit_mm = 1.0 / IU_PER_MM

    units = pcbnew.GetUserUnits()

    # TODO: select units from board somehow
    conv_unit = conv_unit_mm

    # Board outline
    outlines = pcbnew.SHAPE_POLY_SET()
    pcb.GetBoardPolygonOutlines(outlines, "")
    outline = outlines.Outline(0)
    outline_points = [outline.Point(n) for n in range(outline.PointCount())]
    outline_maxx = max(map(lambda p: p.x, outline_points))
    outline_maxy = max(map(lambda p: p.y, outline_points))
    m_place_offset = pcb.GetDesignSettings().m_AuxOrigin

    # Parts
    module_list = pcb.GetModules()
    modules = []
    while module_list:
        if not skip_module(module_list):
            modules.append(module_list)
        module_list = module_list.Next()

    pin_at = 0

    writer = csv.writer(brd)
    # Logic taken from pcbnew/exporters/export_footprints_placefile.cpp
    # See https://gitlab.com/kicad/code/kicad/-/issues/2453
    for module in modules:
        footprint_pos = module.GetPosition()
        footprint_pos -= m_place_offset

        layer = module.GetLayer()
        if (layer not in (pcbnew.B_Cu, pcbnew.F_Cu)):
            continue

        if (layer == pcbnew.B_Cu):
            footprint_pos.x = -footprint_pos.x

        module_bbox = module.GetBoundingBox()
        writer.writerow([
            module.GetReference(),
            module.GetValue(),
            module.GetFPID().GetLibItemName(),
            round(footprint_pos.x * conv_unit, 4),
            round(-footprint_pos.y * conv_unit, 4),
            module.GetOrientation() / 10.0,
            "top" if layer == pcbnew.F_Cu else "bottom",
        ])

        pin_at += module.GetPadCount()
Esempio n. 3
0
 def build(self, center_x, center_y, radius, keepout, edge_count):
     sp = pcbnew.SHAPE_POLY_SET()
     sp.NewOutline()
     cnt = int(edge_count)
     for i in range(cnt):
         x = int(center_x + radius * cos(i * 2 * pi / cnt))
         y = int(center_y + radius * sin(i * 2 * pi / cnt))
         sp.Append(x, y)
     # sp.OutlineCount()
     sp.thisown = 0
     zone = pcbnew.ZONE_CONTAINER(self.pcb)
     zone.SetOutline(sp)
     zone.SetLayer(pcbnew.F_Cu)
     zone.SetIsKeepout(keepout)
     zone.thisown = 0
     self.pcb.Add(zone)
 def fullZone(self,layer):
     """
     Define a full copper pour on the front panel
     """
     bbox=self.fp.GetBoardEdgesBoundingBox()
     sp = pcbnew.SHAPE_POLY_SET()
     sp.NewOutline()
     sp.Append(bbox.GetLeft() ,bbox.GetTop())
     sp.Append(bbox.GetRight(),bbox.GetTop())
     sp.Append(bbox.GetRight() ,bbox.GetBottom())
     sp.Append(bbox.GetLeft(),bbox.GetBottom())
     # sp.OutlineCount()
     sp.thisown = 0
     zone = pcbnew.ZONE_CONTAINER(self.fp)
     zone.SetOutline(sp)
     zone.SetLayer(layer)
     zone.thisown = 0
     self.fp.Add(zone)
Esempio n. 5
0
def convert(pcb, brd):
    # Board outline
    outlines = pcbnew.SHAPE_POLY_SET()
    pcb.GetBoardPolygonOutlines(outlines)
    outline = outlines.Outline(0)
    outline_points = [outline.GetPoint(n) for n in range(outline.PointCount())]
    outline_maxx = max(map(lambda p: p.x, outline_points))
    outline_maxy = max(map(lambda p: p.y, outline_points))

    brd.write("0\n")  # unknown

    brd.write("BRDOUT: {count} {width} {height}\n".format(
        count=len(outline_points) + outline.IsClosed(),
        width=coord(outline_maxx),
        height=coord(outline_maxy)))
    for point in outline_points:
        brd.write("{x} {y}\n".format(x=coord(point.x), y=coord(point.y)))
    if outline.IsClosed():
        brd.write("{x} {y}\n".format(x=coord(outline_points[0].x),
                                     y=coord(outline_points[0].y)))
    brd.write("\n")

    # Nets
    net_info = pcb.GetNetInfo()
    net_items = [
        net_info.GetNetItem(n) for n in range(1, net_info.GetNetCount())
    ]

    brd.write("NETS: {count}\n".format(count=len(net_items)))
    for net_item in net_items:
        brd.write("{code} {name}\n".format(code=net_item.GetNetCode(),
                                           name=net_item.GetNetname()))
    brd.write("\n")

    # Parts
    module_list = pcb.GetFootprints()
    modules = []
    for module in module_list:
        if not skip_module(module):
            modules.append(module)

    brd.write("PARTS: {count}\n".format(count=len(modules)))
    pin_at = 0
    for module in modules:
        module_bbox = module.GetBoundingBox()
        brd.write("{ref} {x1} {y1} {x2} {y2} {pin} {side}\n".format(
            ref=module.Reference().GetText(),
            x1=coord(module_bbox.GetLeft()),
            y1=y_coord(module, outline_maxy, module_bbox.GetTop()),
            x2=coord(module_bbox.GetRight()),
            y2=y_coord(module, outline_maxy, module_bbox.GetBottom()),
            pin=pin_at,
            side=1 + module.IsFlipped()))
        pin_at += module.GetPadCount()
    brd.write("\n")

    # Pins
    module_list = pcb.GetFootprints()
    pads = []
    for module in module_list:
        if not skip_module(module):
            pads_list = module.Pads()
            for pad in sorted(pads_list,
                              key=lambda pad: pad_sort_key(pad.GetName())):
                pads.append(pad)

    brd.write("PINS: {count}\n".format(count=len(pads)))
    for pad in pads:
        pad_pos = pad.GetPosition()
        brd.write("{x} {y} {net} {side}\n".format(x=coord(pad_pos.x),
                                                  y=y_coord(
                                                      pad, outline_maxy,
                                                      pad_pos.y),
                                                  net=pad.GetNetCode(),
                                                  side=1 + pad.IsFlipped()))
    brd.write("\n")

    # Nails
    module_list = pcb.GetFootprints()
    testpoints = []
    for module in module_list:
        if not skip_module(module, tp=True):
            pads_list = module.Pads()
            for pad in sorted(pads_list,
                              key=lambda pad: pad_sort_key(pad.GetName())):
                testpoints.append((module, pad))

    brd.write("NAILS: {count}\n".format(count=len(testpoints)))
    for module, pad in testpoints:
        pad_pos = pad.GetPosition()
        brd.write("{probe} {x} {y} {net} {side}\n".format(
            probe=module.GetReference()[2:],
            x=coord(pad_pos.x),
            y=y_coord(pad, outline_maxy, pad_pos.y),
            net=pad.GetNetCode(),
            side=1 + pad.IsFlipped()))
    brd.write("\n")
Esempio n. 6
0
def shapelyToSHAPE_POLY_SET(polygon):
    p = pcbnew.SHAPE_POLY_SET()
    print(polygon.exterior)
    p.AddOutline(linestringToKicad(polygon.exterior))
    return p