Exemple #1
0
def edge_cuts():
    layertable = get_layertable()
    board = pcbnew.GetBoard()
    #edge cuts
    edgecut = layertable['F.Mask']

    seg1 = pcbnew.DRAWSEGMENT(board)
    board.Add(seg1)
    seg1.SetStart(pcbnew.wxPoint(0, 0))
    seg1.SetEnd(pcbnew.wxPoint(100 * SCALE, 0))
    seg1.SetLayer(edgecut)

    seg1 = pcbnew.DRAWSEGMENT(board)
    board.Add(seg1)
    seg1.SetStart(pcbnew.wxPoint(100 * SCALE, 0))
    seg1.SetEnd(pcbnew.wxPoint(100 * SCALE, 100 * SCALE))
    seg1.SetLayer(edgecut)

    seg1 = pcbnew.DRAWSEGMENT(board)
    board.Add(seg1)
    seg1.SetStart(pcbnew.wxPoint(100 * SCALE, 100 * SCALE))
    seg1.SetEnd(pcbnew.wxPoint(0, 100 * SCALE))
    seg1.SetLayer(edgecut)

    seg1 = pcbnew.DRAWSEGMENT(board)
    board.Add(seg1)
    seg1.SetStart(pcbnew.wxPoint(0, 100 * SCALE))
    seg1.SetEnd(pcbnew.wxPoint(0, 0))
    seg1.SetLayer(edgecut)
    pcbnew.Refresh()
Exemple #2
0
def cutoutComponents(board, components):
    topCutout = extractComponentPolygons(components, "F.CrtYd")
    for polygon in topCutout:
        zone = pcbnew.DRAWSEGMENT()
        zone.SetShape(STROKE_T.S_POLYGON)
        zone.SetPolyShape(shapelyToSHAPE_POLY_SET(polygon))
        zone.SetLayer(Layer.F_Paste)
        board.Add(zone)
    bottomCutout = extractComponentPolygons(components, "B.CrtYd")
    for polygon in bottomCutout:
        zone = pcbnew.DRAWSEGMENT()
        zone.SetShape(STROKE_T.S_POLYGON)
        zone.SetPolyShape(shapelyToSHAPE_POLY_SET(polygon))
        zone.SetLayer(Layer.B_Paste)
        board.Add(zone)
def draw_poly(board, polys, layer):
    # sometimes shapely returns a poly sometimes a multi.
    if not iterable(polys):
        polys = [polys]

    for poly in polys:
        if (not getattr(poly, "exterior", None)):
            print("got line? " + str(poly))
            continue


        seg = pcbnew.DRAWSEGMENT(board)
        seg.SetLayer(layer)
        seg.SetShape(pcbnew.S_SEGMENT)
        board.Add(seg)

        seg.SetShape(pcbnew.S_POLYGON)

        sps = seg.GetPolyShape()

        o = sps.NewOutline()

        # shapely polygons start and end with the same coord
        # so skip the first
        print("ext {}".format(len(list(poly.exterior.coords)[1:])))
        for pt in list(poly.exterior.coords)[1:]:
            sps.Append(int(pt[0]), int(pt[1]), o)

        for hole in poly.interiors:
            h = sps.NewHole()
            print("  hole {}".format(len(list(hole.coords)[1:])))
            for pt in list(hole.coords)[1:]:
                sps.Append(int(pt[0]), int(pt[1]), o, h)
Exemple #4
0
def drawEdge(start, end):
    edge = pcbnew.DRAWSEGMENT()
    edge.SetLayer(pcb.GetLayerID('Edge.Cuts'))
    edge.SetStart(pcbnew.wxPoint(start.x + X_OFFSET, start.y + Y_OFFSET))
    edge.SetEnd(pcbnew.wxPoint(end.x + X_OFFSET, end.y + Y_OFFSET))

    pcb.Add(edge)
Exemple #5
0
def add_edge_cuts(tmpdir):
    pcb_path = "{}/keyboard-before.kicad_pcb".format(tmpdir)
    try:
        board = pcbnew.LoadBoard(pcb_path)
        positions = [
            module.GetPosition() for module in board.GetModules()
            if re.match(r"^SW\d+$", module.GetReference())
        ]
        xvals = [position.x for position in positions]
        yvals = [position.y for position in positions]
        xmin = min(xvals) - pcbnew.FromMM(12)
        xmax = max(xvals) + pcbnew.FromMM(12)
        ymin = min(yvals) - pcbnew.FromMM(12)
        ymax = max(yvals) + pcbnew.FromMM(12)
        corners = [
            pcbnew.wxPoint(xmin, ymin),
            pcbnew.wxPoint(xmax, ymin),
            pcbnew.wxPoint(xmax, ymax),
            pcbnew.wxPoint(xmin, ymax),
        ]
        for i in range(len(corners)):
            start = corners[i]
            end = corners[(i + 1) % len(corners)]
            segment = pcbnew.DRAWSEGMENT(board)
            segment.SetLayer(pcbnew.Edge_Cuts)
            segment.SetStart(start)
            segment.SetEnd(end)
            board.Add(segment)

        pcbnew.Refresh()
        pcbnew.SaveBoard(pcb_path, board)
    except Exception as err:
        raise Exception("Adding egde cuts failed") from err
Exemple #6
0
def arc(board, layer, x1, y1, x2, y2):
    seg1 = pcbnew.DRAWSEGMENT(board)
    seg1.SetShape(pcbnew.S_ARC)
    seg1.SetArcStart(pcbnew.wxPoint(x1, y1))
    seg1.SetCenter(pcbnew.wxPoint(x2, y2))
    seg1.SetAngle(deg(90))
    seg1.SetLayer(layer)
    board.Add(seg1)
Exemple #7
0
def DrawLine(board, layer, start, end, width):
    ds = pcbnew.DRAWSEGMENT(board)
    board.Add(ds)
    ds.SetShape(pcbnew.S_SEGMENT)
    ds.SetStart(pcbnew.wxPoint(start[0], start[1]))
    ds.SetEnd(pcbnew.wxPoint(end[0], end[1]))
    ds.SetWidth(width)
    ds.SetLayer(layer)
Exemple #8
0
def DrawCircle(board, layer, center, end, width):
    ds = pcbnew.DRAWSEGMENT(board)
    board.Add(ds)
    ds.SetShape(pcbnew.S_CIRCLE)
    ds.SetStart(pcbnew.wxPoint(center[0], center[1]))
    ds.SetEnd(pcbnew.wxPoint(end[0], end[1]))
    ds.SetWidth(width)
    ds.SetLayer(layer)
Exemple #9
0
def DrawBounding(startx, starty, width, height):
    board = pcbnew.GetBoard()
    global g_startx
    g_startx = startx
    global g_starty
    g_starty = starty
    global g_width
    g_width = width
    global g_height
    g_height = height

    ds = pcbnew.DRAWSEGMENT(board)
    ds.SetStart(pcbnew.wxPoint(GetCoordinates(startx), GetCoordinates(starty)))
    ds.SetEnd(
        pcbnew.wxPoint(GetCoordinates(startx + width), GetCoordinates(starty)))
    ds.SetWidth(board_width)
    board.Add(ds)

    ds = pcbnew.DRAWSEGMENT(board)
    ds.SetStart(
        pcbnew.wxPoint(GetCoordinates(startx + width), GetCoordinates(starty)))
    ds.SetEnd(
        pcbnew.wxPoint(GetCoordinates(startx + width),
                       GetCoordinates(starty + height)))
    ds.SetWidth(board_width)
    board.Add(ds)

    ds = pcbnew.DRAWSEGMENT(board)
    ds.SetStart(
        pcbnew.wxPoint(GetCoordinates(startx + width),
                       GetCoordinates(starty + height)))
    ds.SetEnd(
        pcbnew.wxPoint(GetCoordinates(startx),
                       GetCoordinates(starty + height)))
    ds.SetWidth(board_width)
    board.Add(ds)

    ds = pcbnew.DRAWSEGMENT(board)
    ds.SetStart(
        pcbnew.wxPoint(GetCoordinates(startx),
                       GetCoordinates(starty + height)))
    ds.SetEnd(pcbnew.wxPoint(GetCoordinates(startx), GetCoordinates(starty)))
    ds.SetWidth(board_width)
    board.Add(ds)

    pcbnew.Refresh()
def line(start, end, layer, width=0.05):
    l = pcbnew.DRAWSEGMENT()
    l.SetShape(pcbnew.S_SEGMENT)
    l.SetStart(start)
    l.SetEnd(end)
    l.SetLayer(layer)
    l.SetWidth(int(width * SCALE))
    return l
Exemple #11
0
def draw_seg(board, p1, p2, layer):
    seg = pcbnew.DRAWSEGMENT(board)
    seg.SetShape(pcbnew.S_SEGMENT)
    seg.SetLayer(layer)

    seg.SetStart(pcbnew.wxPoint(*p1))
    seg.SetEnd(pcbnew.wxPoint(*p2))
    board.Add(seg)
Exemple #12
0
def addLine(board, start, end, thickness):
    line = pcbnew.DRAWSEGMENT()
    line.SetShape(STROKE_T.S_SEGMENT)
    line.SetStart(wxPoint(start[0], start[1]))
    line.SetEnd(wxPoint(end[0], end[1]))
    line.SetWidth(thickness)
    line.SetLayer(Layer.F_Paste)
    board.Add(line)
    addBottomCounterpart(board, line)
Exemple #13
0
def addHole(board, position, radius):
    circle = pcbnew.DRAWSEGMENT()
    circle.SetShape(STROKE_T.S_CIRCLE)
    circle.SetCenter(wxPoint(position[0], position[1]))
    circle.SetArcStart(wxPoint(position[0], position[1]) + wxPoint(radius/2, 0))
    circle.SetWidth(radius)
    circle.SetLayer(Layer.F_Paste)
    board.Add(circle)
    addBottomCounterpart(board, circle)
Exemple #14
0
def draw_segment(p1, p2, layer, width):
    pcb = pcbnew.GetBoard()
    ds = pcbnew.DRAWSEGMENT(pcb)
    pcb.Add(ds)
    ds.SetStart(p1)
    ds.SetEnd(p2)
    ds.SetLayer(layer)
    ds.SetWidth(max(1, int(width)))
    return ds
Exemple #15
0
def draw_segment(board, x1, y1, x2, y2):
    layer = pcbnew.Edge_Cuts
    thickness = 0.15 * pcbnew.IU_PER_MM
    ds = pcbnew.DRAWSEGMENT(board)
    ds.SetLayer(layer)
    ds.SetWidth(max(1, int(thickness)))
    board.Add(ds)
    ds.SetStart(pcbnew.wxPoint(x1, y1))
    ds.SetEnd(pcbnew.wxPoint(x2, y2))
def arc(center, start, angle, layer, width=0.05):
    a = pcbnew.DRAWSEGMENT()
    a.SetShape(pcbnew.S_ARC)
    a.SetCenter(center)
    a.SetArcStart(start)
    a.SetAngle(angle * 10)
    a.SetLayer(layer)
    a.SetWidth(int(width * SCALE))
    return a
Exemple #17
0
 def add_line(self, start, end, layer='F.SilkS', width=0.15):
     """Create a graphic line on the board"""
     a = pcbnew.DRAWSEGMENT(self._board)
     a.SetShape(pcbnew.S_SEGMENT)
     a.SetStart(_to_wxpoint(start[0], start[1]))
     a.SetEnd(_to_wxpoint(end[0], end[1]))
     a.SetLayer(_get_layer(layer))
     a.SetWidth(_to_iu(width))
     self._board.Add(a)
     return a
def draw_segment(start, end, layer='F.SilkS', width=0.15):
    line = pcbnew.DRAWSEGMENT(board._obj)
    board._obj.Add(line)
    line.SetShape(pcbnew.S_SEGMENT)
    line.SetStart(start.wxPoint())
    line.SetEnd(end.wxPoint())
    print("LINE from (%f, %f) to (%f, %f)" % (start.x, start.y, end.x, end.y))
    line.SetLayer(layertable[layer])
    line.SetWidth(int(width * pcbnew.IU_PER_MM))
    return line
def draw_circle(center, radius, layer='F.SilkS', width=0.15):
    circle = pcbnew.DRAWSEGMENT(board._obj)
    board._obj.Add(circle)
    circle.SetShape(pcbnew.S_CIRCLE)
    circle.SetCenter(center.wxPoint())
    center.translate(Point(0, radius))
    circle.SetArcStart(center.wxPoint())
    circle.SetLayer(layertable[layer])
    circle.SetWidth(int(width * pcbnew.IU_PER_MM))
    return circle
Exemple #20
0
def add_line_rawunit(a, b, layer='Edge.Cuts', width=2):
    if a[0] == b[0] and a[1] == b[1]:
        print("add_line_rawunit: identical", a)
        return None
    line = pcbnew.DRAWSEGMENT()
    line.SetStart(a)
    line.SetEnd(b)
    line.SetLayer(pcb.GetLayerID(layer))
    line.SetWidth(pcbnew.FromMils(width))
    pcb.Add(line)
    return line
Exemple #21
0
 def add_circle(self, center, radius, layer='F.SilkS', width=0.15):
     """Create a graphic circle on the board"""
     a = pcbnew.DRAWSEGMENT(self._board)
     a.SetShape(pcbnew.S_CIRCLE)
     a.SetCenter(_to_wxpoint(center[0], center[1]))
     start_coord = _to_wxpoint(center[0], center[1] + radius)
     a.SetArcStart(start_coord)
     a.SetLayer(_get_layer(layer))
     a.SetWidth(_to_iu(width))
     self._board.Add(a)
     return a
def CopyModuleCourtyard(module, brd = None, layer = pcbnew.F_Paste):
    ''' Copy module courtyard to the destination layer
    '''
    if not brd:
        brd = pcbnew.GetBoard()
    poly = module.GetPolyCourtyardFront()
    dw = pcbnew.DRAWSEGMENT()
    dw.SetShape(pcbnew.S_POLYGON)
    dw.SetLayer(layer)
    dw.SetPolyShape(poly)
    brd.Add(dw)
Exemple #23
0
def draw_arc(board, cx, cy, sx, sy, a):
    layer = pcbnew.Edge_Cuts
    thickness = 0.15 * pcbnew.IU_PER_MM
    ds = pcbnew.DRAWSEGMENT(board)
    ds.SetLayer(layer)
    ds.SetWidth(max(1, int(thickness)))
    board.Add(ds)
    ds.SetShape(pcbnew.S_ARC)
    ds.SetCenter(pcbnew.wxPoint(cx, cy))
    ds.SetArcStart(pcbnew.wxPoint(sx, sy))
    ds.SetAngle(a * 10)
Exemple #24
0
def make_line(board, start, end, layer):

    start = pcbnew.wxPoint(pcbnew.Millimeter2iu(start[0]), pcbnew.Millimeter2iu(start[1]))
    end   = pcbnew.wxPoint(pcbnew.Millimeter2iu(end[0]),   pcbnew.Millimeter2iu(end[1]))
    if (start == end):
        return
    seg = pcbnew.DRAWSEGMENT(board)
    seg.SetLayer(layer)
    seg.SetShape(pcbnew.S_SEGMENT)
    seg.SetStart(start)
    seg.SetEnd(end)
    board.Add(seg)
Exemple #25
0
def add_arc(ctr, pos, angle, layer='Edge.Cuts', width=2):
    pnt_ctr = pnt.to_unit(vec2.round(ctr, PointDigits), UnitMM)
    pnt_pos = pnt.to_unit(vec2.round(pos, PointDigits), UnitMM)
    arc = pcbnew.DRAWSEGMENT()
    arc.SetShape(pcbnew.S_ARC)
    arc.SetCenter(pnt_ctr)
    arc.SetArcStart(pnt_pos)
    arc.SetAngle(10 * angle)
    arc.SetLayer(pcb.GetLayerID(layer))
    arc.SetWidth(scalar_to_unit(width, UnitMM))
    pcb.Add(arc)
    return arc
Exemple #26
0
 def _serializeRing(self, ring):
     coords = list(ring.coords)
     segments = []
     # ToDo: Reconstruct arcs
     for a, b in zip(coords, coords[1:]):
         segment = pcbnew.DRAWSEGMENT()
         segment.SetShape(STROKE_T.S_SEGMENT)
         segment.SetLayer(Layer.Edge_Cuts)
         segment.SetStart(pcbnew.wxPoint(a[0], a[1]))
         segment.SetEnd(pcbnew.wxPoint(b[0], b[1]))
         segments.append(segment)
     return segments
def draw_arc_2(center, arcStartPoint, totalAngle, layer='F.SilkS', width=0.15):
    print(
        "Drawing arc with center: (%f, %f), arc point at (%f,%f), total angle %f"
        % (center.x, center.y, arcStartPoint.x, arcStartPoint.y, totalAngle))
    arc = pcbnew.DRAWSEGMENT(board._obj)
    board._obj.Add(arc)
    arc.SetShape(pcbnew.S_ARC)
    arc.SetCenter(center.wxPoint())
    arc.SetArcStart(arcStartPoint.wxPoint())
    arc.SetAngle(totalAngle * 180 / pi * 10)
    arc.SetLayer(layertable[layer])
    arc.SetWidth(int(width * pcbnew.IU_PER_MM))
    return arc
Exemple #28
0
def addRoundedCorner(board, center, start, end, thickness):
    corner = pcbnew.DRAWSEGMENT()
    corner.SetShape(STROKE_T.S_ARC)
    corner.SetCenter(wxPoint(center[0], center[1]))
    corner.SetArcStart(wxPoint(start[0], start[1]))
    if np.cross(start - center, end - center) > 0:
        corner.SetAngle(fromDegrees(90))
    else:
        corner.SetAngle(fromDegrees(-90))
    corner.SetWidth(thickness)
    corner.SetLayer(Layer.F_Paste)
    board.Add(corner)
    addBottomCounterpart(board, corner)
    def draw_edge_cuts(self, pcb):
        vertices = {
            TriadPiece.LEFT: [
                self.switch_data.get_corner((0, 0), Corner.TOP_LEFT),
                self.switch_data.get_corner((0, 3), Corner.TOP_LEFT),
                self.switch_data.get_corner((0, 3), Corner.TOP_RIGHT),
                # self.switch_data.get_corner((0,5), Corner.TOP_RIGHT),
                (146.451, 29.036),
                self.switch_data.get_corner((4, 6), Corner.TOP_RIGHT),
                # (163.125, 123.6),
                self.switch_data.get_corner((4, 6), Corner.BOTTOM_RIGHT),
                self.switch_data.get_corner((5, 5), Corner.BOTTOM_LEFT),
                self.switch_data.get_corner((5, 1), Corner.BOTTOM_RIGHT),
                self.switch_data.get_corner((5, 0), Corner.BOTTOM_LEFT),
            ],
            TriadPiece.CENTER: [
                (self.switch_data.get_corner((0, 6),
                                             Corner.TOP_LEFT)[0], 14.92),
                (self.switch_data.get_corner((0, 8),
                                             Corner.TOP_RIGHT)[0], 14.92),
                self.switch_data.get_corner((5, 8), Corner.BOTTOM_RIGHT),
                self.switch_data.get_corner((5, 6), Corner.BOTTOM_LEFT),
            ],
            TriadPiece.RIGHT: [
                self.switch_data.get_corner((0, 14), Corner.TOP_RIGHT),
                self.switch_data.get_corner((0, 11), Corner.TOP_RIGHT),
                self.switch_data.get_corner((0, 11), Corner.TOP_LEFT),
                # TODO: Replace these two to make left side 10*
                # self.switch_data.get_corner((0,9), Corner.TOP_LEFT),
                (46.449, 29.036),
                self.switch_data.get_corner((4, 8), Corner.TOP_LEFT),
                self.switch_data.get_corner((4, 8), Corner.BOTTOM_LEFT),
                self.switch_data.get_corner((5, 9), Corner.BOTTOM_RIGHT),
                self.switch_data.get_corner((5, 13), Corner.BOTTOM_LEFT),
                self.switch_data.get_corner((5, 14), Corner.BOTTOM_RIGHT),
            ],
        }

        l = len(vertices[self.piece])
        for i in range(0, l):
            start = vertices[self.piece][i]
            end = vertices[self.piece][(i + 1) % l]
            segment = pcbnew.DRAWSEGMENT()
            segment.SetStartX(int(start[0] * POSITION_SCALE))
            segment.SetStartY(int(start[1] * POSITION_SCALE))
            segment.SetEndX(int(end[0] * POSITION_SCALE))
            segment.SetEndY(int(end[1] * POSITION_SCALE))
            segment.SetAngle(int(90 * ROTATION_SCALE))
            segment.SetWidth(int(0.3 * POSITION_SCALE))
            segment.SetLayer(pcbnew.Edge_Cuts)
            pcb.Add(segment)
Exemple #30
0
 def _serializeRing(self, ring):
     coords = list(ring.simplify(pcbnew.FromMM(0.001)).coords)
     segments = []
     # ToDo: Reconstruct arcs
     if coords[0] != coords[-1]:
         raise RuntimeError("Ring is incomplete")
     for a, b in zip(coords, coords[1:]):
         segment = pcbnew.DRAWSEGMENT()
         segment.SetShape(STROKE_T.S_SEGMENT)
         segment.SetLayer(Layer.Edge_Cuts)
         segment.SetStart(roundPoint(a))
         segment.SetEnd(roundPoint(b))
         segments.append(segment)
     return segments