Skip to content

Commit

Permalink
Switch from helpers.get_footprint_by_ref() to the built-in BOARD.Find…
Browse files Browse the repository at this point in the history
…FootprintByReference()
  • Loading branch information
chmorgan committed Jan 14, 2024
1 parent 9878b1c commit d612845
Showing 3 changed files with 11 additions and 16 deletions.
5 changes: 3 additions & 2 deletions fabrication.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
except ImportError:
NO_DRILL_SHAPE = PCB_PLOT_PARAMS.NO_DRILL_SHAPE

from .helpers import get_exclude_from_pos, get_footprint_by_ref
from .helpers import get_exclude_from_pos


class Fabrication:
@@ -269,8 +269,9 @@ def generate_cpl(self):
writer.writerow(
["Designator", "Val", "Package", "Mid X", "Mid Y", "Rotation", "Layer"]
)
board = GetBoard()
for part in self.parent.store.read_pos_parts():
for fp in get_footprint_by_ref(self.board, part[0]):
for fp in board.FindFootprintByReference(part[0]):
if get_exclude_from_pos(fp):
continue
if not add_without_lcsc and not part[3]:
9 changes: 0 additions & 9 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -157,15 +157,6 @@ def get_footprint_keys(fp):
return (package, reference)


def get_footprint_by_ref(board, ref):
"""Get a footprint from the list of footprints by its Reference."""
fps = []
for fp in get_valid_footprints(board):
if str(fp.GetReference()) == ref:
fps.append(fp)
return fps


def get_bit(value, bit):
"""Get the nth bit of a byte."""
return value & (1 << bit)
13 changes: 8 additions & 5 deletions mainwindow.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
GetListIcon,
GetScaleFactor,
HighResWxSize,
get_footprint_by_ref,
getVersion,
loadBitmapScaled,
loadIconScaled,
@@ -575,7 +574,8 @@ def populate_footprint_list(self, *_):
numbers = []
parts = []
for part in self.store.read_all():
fp = get_footprint_by_ref(pcbnew.GetBoard(), part[0])[0]
board = pcbnew.GetBoard()
fp = board.FindFootprintByReference(part[0])
if part[3] and part[3] not in numbers:
numbers.append(part[3])
part.insert(4, "")
@@ -730,7 +730,8 @@ def toggle_bom_pos(self, *_):
row = self.footprint_list.ItemToRow(item)
selected_rows.append(row)
ref = self.footprint_list.GetTextValue(row, 0)
fp = get_footprint_by_ref(pcbnew.GetBoard(), ref)[0]
board = pcbnew.GetBoard()
fp = board.FindFootprintByReference(ref)
bom = toggle_exclude_from_bom(fp)
pos = toggle_exclude_from_pos(fp)
self.store.set_bom(ref, bom)
@@ -749,7 +750,8 @@ def toggle_bom(self, *_):
row = self.footprint_list.ItemToRow(item)
selected_rows.append(row)
ref = self.footprint_list.GetTextValue(row, 0)
fp = get_footprint_by_ref(pcbnew.GetBoard(), ref)[0]
board = pcbnew.GetBoard()
fp = board.FindFootprintByReference(ref)
bom = toggle_exclude_from_bom(fp)
self.store.set_bom(ref, bom)
self.footprint_list.SetValue(
@@ -763,7 +765,8 @@ def toggle_pos(self, *_):
row = self.footprint_list.ItemToRow(item)
selected_rows.append(row)
ref = self.footprint_list.GetTextValue(row, 0)
fp = get_footprint_by_ref(pcbnew.GetBoard(), ref)[0]
board = pcbnew.GetBoard()
fp = board.FindFootprintByReference(ref)
pos = toggle_exclude_from_pos(fp)
self.store.set_pos(ref, pos)
self.footprint_list.SetValue(

0 comments on commit d612845

Please sign in to comment.