def appendBoard(self, filename, destination, sourceArea=None, origin=Origin.Center, rotationAngle=0, shrink=False, tolerance=0, bufferOutline=fromMm(0.001), netRenamer=None, refRenamer=None): """ Appends a board to the panel. The sourceArea (wxRect) of the board specified by filename is extracted and placed at destination (wxPoint). The source area (wxRect) can be auto detected if it is not provided. Only board items which fit entirely into the source area are selected. You can also specify rotation. Both translation and rotation origin are specified by origin. Origin specifies which point of the sourceArea is used for translation and rotation (origin it is placed to destination). It is possible to specify coarse source area and automatically shrink it if shrink is True. Tolerance enlarges (even shrinked) source area - useful for inclusion of filled zones which can reach out of the board edges. You can also specify functions which will rename the net and ref names. By default, nets are renamed to "Board_{n}-{orig}", refs are unchanged. The renamers are given board seq number and original name Returns bounding box (wxRect) of the extracted area placed at the destination and the extracted substrate of the board. """ board = LoadBoard(filename) thickness = board.GetDesignSettings().GetBoardThickness() if self.boardCounter == 0: self.board.GetDesignSettings().SetBoardThickness(thickness) else: panelThickness = self.board.GetDesignSettings().GetBoardThickness() if panelThickness != thickness: raise PanelError(f"Cannot append board {filename} as its " \ f"thickness ({toMm(thickness)} mm) differs from " \ f"thickness of the panel ({toMm(panelThickness)}) mm") self.boardCounter += 1 self.inheritCopperLayers(board) if not sourceArea: sourceArea = findBoardBoundingBox(board) elif shrink: sourceArea = findBoardBoundingBox(board, sourceArea) enlargedSourceArea = expandRect(sourceArea, tolerance) originPoint = getOriginCoord(origin, sourceArea) translation = wxPoint(destination[0] - originPoint[0], destination[1] - originPoint[1]) if netRenamer is None: netRenamer = lambda x, y: self._uniquePrefix() + y renameNets(board, lambda x: netRenamer(self.boardCounter, x)) if refRenamer is not None: renameRefs(board, lambda x: refRenamer(self.boardCounter, x)) drawings = collectItems(board.GetDrawings(), enlargedSourceArea) footprints = collectFootprints(board.GetFootprints(), enlargedSourceArea) tracks = collectItems(board.GetTracks(), enlargedSourceArea) zones = collectItems(board.Zones(), enlargedSourceArea) edges = [] for footprint in footprints: footprint.Rotate(originPoint, rotationAngle) footprint.Move(translation) edges += removeCutsFromFootprint(footprint) appendItem(self.board, footprint) for track in tracks: track.Rotate(originPoint, rotationAngle) track.Move(translation) appendItem(self.board, track) for zone in zones: zone.Rotate(originPoint, rotationAngle) zone.Move(translation) appendItem(self.board, zone) for netId in board.GetNetInfo().NetsByNetcode(): self.board.Add(board.GetNetInfo().GetNetItem(netId)) # Treat drawings differently since they contains board edges for drawing in drawings: drawing.Rotate(originPoint, rotationAngle) drawing.Move(translation) edges += [edge for edge in drawings if isBoardEdge(edge)] otherDrawings = [edge for edge in drawings if not isBoardEdge(edge)] try: s = Substrate(edges, bufferOutline) self.boardSubstrate.union(s) self.substrates.append(s) except substrate.PositionError as e: point = undoTransformation(e.point, rotationAngle, originPoint, translation) raise substrate.PositionError(filename + ": " + e.origMessage, point) for drawing in otherDrawings: appendItem(self.board, drawing) return findBoundingBox(edges)
def appendBoard(self, filename, destination, sourceArea=None, origin=Origin.Center, rotationAngle=0, shrink=False, tolerance=0, bufferOutline=fromMm(0.001)): """ Appends a board to the panel. The sourceArea (wxRect) of the board specified by filename is extracted and placed at destination (wxPoint). The source area (wxRect) can be auto detected if it is not provided. Only board items which fit entirely into the source area are selected. You can also specify rotation. Both translation and rotation origin are specified by origin. Origin specifies which point of the sourceArea is used for translation and rotation (origin it is placed to destination). It is possible to specify coarse source area and automatically shrink it if shrink is True. Tolerance enlarges (even shrinked) source area - useful for inclusion of filled zones which can reach out of the board edges. Returns bounding box (wxRect) of the extracted area placed at the destination. """ board = LoadBoard(filename) self.boardCounter += 1 if not sourceArea: sourceArea = findBoardBoundingBox(board) elif shrink: sourceArea = findBoardBoundingBox(board, sourceArea) enlargedSourceArea = expandRect(sourceArea, tolerance) originPoint = getOriginCoord(origin, sourceArea) translation = wxPoint(destination[0] - originPoint[0], destination[1] - originPoint[1]) self._makeNetNamesUnique(board) drawings = collectItems(board.GetDrawings(), enlargedSourceArea) modules = collectItems(board.GetModules(), enlargedSourceArea) tracks = collectItems(board.GetTracks(), enlargedSourceArea) zones = collectItems(board.Zones(), enlargedSourceArea) for module in modules: module.Rotate(originPoint, rotationAngle) module.Move(translation) appendItem(self.board, module) for track in tracks: track.Rotate(originPoint, rotationAngle) track.Move(translation) appendItem(self.board, track) for zone in zones: zone.Rotate(originPoint, rotationAngle) zone.Move(translation) appendItem(self.board, zone) for netId in board.GetNetInfo().NetsByNetcode(): self.board.Add(board.GetNetInfo().GetNetItem(netId)) # Treat drawings differently since they contains board edges for drawing in drawings: drawing.Rotate(originPoint, rotationAngle) drawing.Move(translation) edges = [edge for edge in drawings if edge.GetLayerName() == "Edge.Cuts"] otherDrawings = [edge for edge in drawings if edge.GetLayerName() != "Edge.Cuts"] try: self.boardSubstrate.union(Substrate(edges, bufferOutline)) except substrate.PositionError as e: point = undoTransformation(e.point, rotationAngle, originPoint, translation) raise substrate.PositionError(filename + ": " + e.origMessage, point) for drawing in otherDrawings: appendItem(self.board, drawing) return findBoundingBox(edges)