Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions kikit/panelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,33 @@ def renameNets(board, renamer):
if name != "" and name not in newNames:
board.RemoveNative(netinfo.GetNetItem(name))

def renameRefs(board, renamer):
def renameRefs(board, renamer, bakeRefText = False):
"""
Given a board and renaming function (taking original name, returning new
name) renames the references
"""
for footprint in board.GetFootprints():
ref = footprint.Reference().GetText()
footprint.Reference().SetText(renamer(ref))

if (bakeRefText):
PhantomRefText = None
if hasattr(pcbnew, "FP_TEXT"):
PhantomRefText = pcbnew.FP_TEXT(footprint.Reference())
elif hasattr(pcbnew, "PCB_TEXT"):
PhantomRefText = pcbnew.PCB_TEXT(footprint.Reference())
else:
raise RuntimeError(
"bakeRefText Error: FP_TEXT or PCB_TEXT class not located, likely a KiCad version incompatibility error"
)

PhantomRefText.SetAttributes(footprint.Reference().GetAttributes())
PhantomRefText.SetPosition(footprint.Reference().GetPosition())
PhantomRefText.SetTextAngle(footprint.Reference().GetTextAngle())
PhantomRefText.SetLayer(footprint.Reference().GetLayer())
PhantomRefText.SetText(ref)
footprint.Add(PhantomRefText)
footprint.Reference().SetVisible(False)

def isBoardEdge(edge):
"""
Expand Down Expand Up @@ -985,7 +1004,7 @@ def appendBoard(self, filename: Union[str, Path], destination: VECTOR2I,
netRenamer: Optional[Callable[[int, str], str]] = None,
refRenamer: Optional[Callable[[int, str], str]] = None,
inheritDrc: bool = True, interpretAnnotations: bool=True,
bakeText: bool = False):
bakeText: bool = False, bakeRefText: bool = False):
"""
Appends a board to the panel.

Expand All @@ -1009,6 +1028,7 @@ def appendBoard(self, filename: Union[str, Path], destination: VECTOR2I,
this boards or not.

Similarly, you can substitute variables in the text via bakeText.
You can also ensure the ref text of each footprint remains unchanged via bakeRefText.

Returns bounding box (BOX2I) of the extracted area placed at the
destination and the extracted substrate of the board.
Expand Down Expand Up @@ -1056,7 +1076,7 @@ def appendBoard(self, filename: Union[str, Path], destination: VECTOR2I,

renameNets(board, netRenamerFn)
if refRenamer is not None:
renameRefs(board, lambda x: refRenamer(len(self.substrates), x))
renameRefs(board, lambda x: refRenamer(len(self.substrates), x), bakeRefText)

drawings = collectItems(board.GetDrawings(), enlargedSourceArea)
footprints = collectFootprints(board.GetFootprints(), enlargedSourceArea)
Expand Down