def place_parts(json_dict, pcb): # compute upper left corner of board board_ul = Point(*BoardTools.get_board_ul(json_dict['board_edge'])) # place all components for name, module in json_dict['module_dict'].items(): if module['type'] == 'comp': # set rotation rot = module['rotation'] pcb.modules[name].rotation = rot # make the buffer vector if round(degrees(rot)) in [0, 180]: buf_space = Point(module['bufx'], module['bufy']) elif round(degrees(rot)) in [90, 270]: buf_space = Point(module['bufy'], module['bufx']) else: raise Exception("Can't determine rotation.") # set position pcb.modules[name].position = \ pcb.modules[name].position \ + Point(module['x'], module['y']) \ + buf_space \ + board_ul \ - pcb.modules[name].boundingBox.ul elif module['type'] == 'keepout': pass else: raise Exception('Unimplemented component type: ' + str(module['type']))
def draw_board_edge(json_dict, pcb): # compute upper left corner of board board_ul = Point(*BoardTools.get_board_ul(json_dict['board_edge'])) # draw edge edge = [Point(x, y) + board_ul for x, y in json_dict['board_edge']] pcb.add_polyline(edge, layer='Edge.Cuts')
def boundary(edge): ul = Point(*BoardTools.get_board_ul(edge)) edge = [ul + Point(x, y) for x, y in edge] # repeat the last point edge = edge + [edge[-1]] # add points to the edge path = ['path', 'pcb', '0'] for point in edge: # convert points from mm to um # and negate y coordinate x = '%d' % dsnx(point.x) y = '%d' % dsny(point.y) path = path[:] + [x, y] return ['boundary', path]
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()