Skip to content

Commit 41fd4ec

Browse files
committed
More robust way to collect info from components in the PCB
- Using the sheet path instead of the reference - Experimental, might need some adjusts
1 parent 48fb182 commit 41fd4ec

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

kibot/kicad/v6_sch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,7 @@ def load(self, fname, project, parent=None, mapped_uuid=None): # noqa: C901
29932993
comp.set_footprint(s.footprint)
29942994
comp.sheet_path = path
29952995
comp.sheet_path_h = self.path_to_human(path)
2996+
comp.sheet_full_path = s.path
29962997
comp.id = comp.uuid
29972998
if s.reference[-1] == '?':
29982999
comp.annotation_error = True

kibot/kiplot.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,10 @@ def get_board_comps_data(comps, kicad_variant=None):
442442
if not GS.pcb_file:
443443
return
444444
load_board()
445-
comps_hash = {c.ref: c for c in comps}
445+
if GS.ki6:
446+
comps_hash = {c.sheet_full_path: c for c in comps}
447+
else:
448+
comps_hash = {c.ref: c for c in comps}
446449
# Get the KiCad variables for fields
447450
KiConf.init(GS.sch_file)
448451
env = KiConf.kicad_env
@@ -452,22 +455,39 @@ def get_board_comps_data(comps, kicad_variant=None):
452455
GS.board.SetCurrentVariant(kicad_variant)
453456
for m in GS.get_modules():
454457
ref = m.GetReference()
458+
# logger.error(f'{ref} {m.m_Uuid.AsString()} -> {m.GetPath().AsString()}')
455459
attrs = m.GetAttributes()
456-
c = comps_hash.get(ref)
460+
if GS.ki6:
461+
# By full sheet path
462+
c = comps_hash.get(m.GetPath().AsString())
463+
else:
464+
# By reference
465+
c = comps_hash.get(ref)
457466
if c is None:
458467
if not (attrs & MOD_BOARD_ONLY) and not ref.startswith('KiKit_'):
459468
logger.warning(W_PCBNOSCH+f'`{ref}` component in board, but not in schematic')
460469
if not GS.global_include_components_from_pcb:
461470
# v1.6.3 behavior
471+
logger.debugl(3, f"Not including {c.ref} ({m.m_Uuid.AsString()}) only found in PCB")
462472
continue
463473
# Create a component for this so we can include/exclude it using filters
464474
c = create_component_from_footprint(m, ref, env)
465475
if c is None:
466476
continue
477+
if GS.ki6:
478+
logger.debugl(3, f"Including {c.ref} ({m.m_Uuid.AsString()}) only found in PCB")
467479
comps.append(c)
468480
if c.has_pcb_info:
469-
# We already got this reference and filled the PCB info, this is another copy
470-
c = c.copy()
481+
if GS.ki6:
482+
# This is a "feature" in KiCad, you can get a PCB only component linked to an unrelated sch component
483+
c = create_component_from_footprint(m, ref, env)
484+
if c is None:
485+
continue
486+
logger.debugl(3, f"Repeated {c.ref} PCB {m.m_Uuid.AsString()} SCH {m.GetPath().AsString()} making a new one")
487+
else:
488+
# When using references they can be repeated
489+
# We already got this reference and filled the PCB info, this is another copy
490+
c = c.copy()
471491
comps.append(c)
472492
new_value = m.GetValue()
473493
if new_value != c.value and '${' not in c.value:
@@ -479,10 +499,10 @@ def get_board_comps_data(comps, kicad_variant=None):
479499
c.footprint_x = center.x
480500
c.footprint_y = center.y
481501
(c.footprint_w, c.footprint_h) = GS.get_fp_size(m)
482-
c.has_pcb_info = True
483502
c.pad_properties = {}
484503
if GS.global_use_pcb_fields:
485504
copy_fields(c, m, env)
505+
c.has_pcb_info = True
486506
# Net
487507
net_name = set()
488508
net_class = set()
@@ -515,6 +535,7 @@ def get_board_comps_data(comps, kicad_variant=None):
515535
c.in_bom_pcb = False
516536
if attrs & MOD_BOARD_ONLY:
517537
c.in_pcb_only = True
538+
c.pcb_id = m.m_Uuid.AsString()
518539
look_for_type = (not c.smd) and (not c.tht)
519540
for pad in m.Pads():
520541
p = PadProperty()

0 commit comments

Comments
 (0)