def main(): # load command-line arguments parser = argparse.ArgumentParser() parser.add_argument('--json') parser.add_argument('--pcb') args = parser.parse_args() # read board placement from SMT-PCB print "Reading output from SMT engine." with open(args.json, 'r') as f: json_dict = json.load(f) # load board print 'Loading PCB file.' pcb = Board.load(args.pcb) # move parts to specified locations print 'Placing all components.' place_parts(json_dict, pcb) # draw board edge print 'Drawing board edge.' draw_board_edge(json_dict, pcb) # save board print 'Saving PCB file.' pcb.save() # add net and net class information print 'Adding nets and net classes to the PCB design.' BoardTools.add_nets( json_dict['design_dict'], json_dict['net_class_list'], args.pcb, args.pcb)
def from_board_item(board_item): # type: (_pcbnew.BOARD_ITEM) -> BoardItem item = board_item.Cast() item_type = type(item) if item_type is _pcbnew.TEXTE_PCB: from kicad.pcbnew.text import Text return Text(item) elif item_type is _pcbnew.BOARD: from kicad.pcbnew.board import Board return Board(item) elif item_type is _pcbnew.DIMENSION: from kicad.pcbnew.dimension import Dimension return Dimension(item) elif item_type is _pcbnew.DRAWSEGMENT: from kicad.pcbnew.drawsegment import Drawsegment return Drawsegment.from_drawsegment(item) elif item_type is _pcbnew.EDGE_MODULE: raise NotImplementedError(item_type) elif item_type is _pcbnew.MODULE: from kicad.pcbnew.module import Module return Module(item) elif item_type is _pcbnew.D_PAD: from kicad.pcbnew.pad import Pad return Pad(item) elif item_type is _pcbnew.TEXTE_MODULE: from kicad.pcbnew.text import Text # type: ignore return Text(item) elif item_type is _pcbnew.VIA: from kicad.pcbnew.via import Via return Via(item) elif item_type is _pcbnew.TRACK: from kicad.pcbnew.track import Track return Track(item) elif item_type is _pcbnew.PCB_TARGET: from kicad.pcbnew.pcbtarget import PcbTarget return PcbTarget(item) elif item_type is _pcbnew.ZONE_CONTAINER: from kicad.pcbnew.zone import Zone return Zone(item) else: raise NotImplementedError(item_type)
def main(): # load command-line arguments parser = argparse.ArgumentParser() parser.add_argument('--pcb') parser.add_argument('--ses') args = parser.parse_args() # parse the session file tree = PcbParser.read_pcb_file(args.ses) routes = next(val for val in tree if val[0] == 'routes') out = next(val for val in routes if val[0] == 'network_out') # load board print 'Loading PCB file.' pcb = Board.load(args.pcb) # create nets make_nets(pcb, out) # save board print 'Saving PCB file.' pcb.save()
def compile(self, json_file=None): # add keepouts based on the edge self.add_keepouts() # Create empty PCB pcb = Board() # add all components to the board for comp in self: pcb.add(comp.module) # make the title block self.make_title_block(pcb) # save PCB file without connectivity information pcb.save(self.fname) # write input file for SMT solver self.write_json_dict(json_file)
# -*- coding: utf-8 -*- # # An example script to check for annular ring violations # from kicad.pcbnew.board import Board def annring_size(pad): return min(pad.size) - max(pad.drill) MIN_AR_SIZE = .25 board = Board.from_editor() for m in board.modules: for pad in m.pads: if annring_size(pad) < MIN_AR_SIZE: print("AR violation at %s." % pad.position)
#!/usr/bin/env python from math import cos, sin, radians, pi from kicad.pcbnew.board import Board center = (153, 100) radius_led = 25 radius_c = 21 count = 12 step = 360 / (count) / 180.0 * pi b = Board.load("NavigationThing.kicad_pcb") for m in b.modules: ref = m.native_obj.GetReference() if ref.startswith("LED"): num = (int(ref[3:]) + count / 2) % count angle = 2 * pi - num * step m.x = center[0] + radius_led * cos(angle) m.y = center[1] + radius_led * sin(angle) m.rotation = 3 * pi / 2. - angle print("Diode: " + str(num)) print("({0}, {1})".format(m.x, m.y)) elif ref.startswith("C"): num = (int(ref[1:]) + count / 2) % count angle = (num - 1) * step m.x = center[0] + radius_c * cos(angle) m.y = center[1] + radius_c * sin(angle)
def main(): # load command-line arguments parser = argparse.ArgumentParser() parser.add_argument('--json') parser.add_argument('--pcb') parser.add_argument('--fill_top', default='GND') parser.add_argument('--fill_bot', default='GND') parser.add_argument('--bufx', type=float, default=0.5) parser.add_argument('--bufy', type=float, default=0.5) args = parser.parse_args() # read board placement from SMT-PCB with open(args.json, 'r') as f: json_dict = json.load(f) # get the board edge board_edge = json_dict['board_edge'] board_ul = Point(*BoardTools.get_board_ul(board_edge)) # compute board center cx, cy = BoardTools.get_board_center(board_edge) edge = [] for idx, (x, y) in enumerate(board_edge): if x < cx: px = x - args.bufx else: px = x + args.bufx if y < cy: py = y - args.bufy else: py = y + args.bufy board_edge[idx] = (px, py) # write board edge back with open(args.json, 'w') as f: json.dump(json_dict, f, indent=2, sort_keys=True) # create the new board edge edge = [Point(x, y) + board_ul for x, y in board_edge] # create zone outline for copper pours minx = min([p.x for p in edge]) maxx = max([p.x for p in edge]) miny = min([p.y for p in edge]) maxy = max([p.y for p in edge]) ul = Point(minx, miny) ur = Point(maxx, miny) lr = Point(maxx, maxy) ll = Point(minx, maxy) outline = [ul, ur, lr, ll] # write changes to board pcb = Board.load(args.pcb) # write edge pcb.clearLayer('Edge.Cuts') pcb.add_polyline(edge, layer='Edge.Cuts') # write zones #clearance = max(args.bufx, args.bufy) #pcb.add_zone(outline, args.fill_top, 'F.Cu', clearance) #pcb.add_zone(outline, args.fill_bot, 'B.Cu', clearance) pcb.save()
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # from math import cos, sin, radians, pi from kicad.pcbnew.board import Board # PARAMETERS center = (100, 100) radius = 40 start = 0 # degrees end = radians(-180) # degreees # b = Board.from_editor() # get a list of components to put on arc comps = [] for m in b.modules: # MAYBE FILTER COMPONENTS HERE comps.append(m) # put components on arc angle = end-start step = angle/float(len(comps)-1) for i, comp in enumerate(comps): angle_i = start + step*i comp.x = center[0] + radius * cos(angle_i)