From 44ca526fe104612bf5368d35bdb1f3be2b9e5de6 Mon Sep 17 00:00:00 2001 From: RubenB-ITENG <94007802+ruben-iteng@users.noreply.github.com> Date: Mon, 21 Oct 2024 20:07:32 +0200 Subject: [PATCH] Fix: Exporter: PCB: PCB net numbers (#95) * Replicate bug example * Revert changes to example * Fix net number gap * Sort the list of nets --- src/faebryk/exporters/pcb/kicad/pcb.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/faebryk/exporters/pcb/kicad/pcb.py b/src/faebryk/exporters/pcb/kicad/pcb.py index 53e51b7e..9ea89ef2 100644 --- a/src/faebryk/exporters/pcb/kicad/pcb.py +++ b/src/faebryk/exporters/pcb/kicad/pcb.py @@ -131,8 +131,10 @@ def apply_netlist(pcb_path: Path, netlist_path: Path): # Remove nets ------------------------------------------------------------------ logger.debug(f"Removed nets: {nets_removed}") + removed_net_numbers = list[int]() for net_name in nets_removed: pcb_net, pads = pcb_nets[net_name] + removed_net_numbers.append(pcb_net.number) pcb.kicad_pcb.nets.remove(pcb_net) for pad in pads: assert pad.net @@ -166,12 +168,17 @@ def apply_netlist(pcb_path: Path, netlist_path: Path): logger.debug(f"New nets: {nets_added}") for net_name in nets_added: # nl_net = nl_nets[net_name] + if removed_net_numbers: + net_number = removed_net_numbers.pop() + else: + net_number = len(pcb.kicad_pcb.nets) pcb_net = C_kicad_pcb_file.C_kicad_pcb.C_net( name=net_name, - number=len(pcb.kicad_pcb.nets), + number=net_number, ) pcb.kicad_pcb.nets.append(pcb_net) pcb_nets[net_name] = (pcb_net, []) + pcb.kicad_pcb.nets.sort(key=lambda x: x.number) # Components =================================================================== pcb_comps = {