From 54efd32f7a4b076d8bea3336b7082dc9ab7dbe90 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 27 May 2024 11:28:14 -0700 Subject: [PATCH] Ensure nets are referenced to main board We set new elements to the temporary board's netlist. These need to be updated when moving the fooprint to the main board Fixes https://gitlab.com/kicad/code/kicad/-/issues/17242 --- pcbnew/footprint_libraries_utils.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 172ee3e99a..e2943ac008 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -927,6 +927,28 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew ) fixUuid( const_cast( aChild->m_Uuid ) ); } ); + // Right now, we only show the "Unconnected" net in the footprint editor, but this is still + // referenced in the footprint. So we need to update the net pointers in the footprint to + // point to the nets in the main board. + newFootprint->RunOnDescendants( + [&]( BOARD_ITEM* aChild ) + { + if( BOARD_CONNECTED_ITEM* conn = dynamic_cast( aChild ) ) + { + NETINFO_ITEM* net = conn->GetNet(); + auto& netmap = mainpcb->GetNetInfo().NetsByName(); + + if( net ) + { + auto it = netmap.find( net->GetNetname() ); + + if( it != netmap.end() ) + conn->SetNet( it->second ); + } + + } + } ); + BOARD_DESIGN_SETTINGS& bds = m_pcb->GetDesignSettings(); newFootprint->ApplyDefaultSettings( *m_pcb, bds.m_StyleFPFields, bds.m_StyleFPText,