From f31a109ab419aa1ecdfdfd4b7d15e9e5f4fbe654 Mon Sep 17 00:00:00 2001 From: John Beard Date: Thu, 21 Aug 2025 00:06:57 +0800 Subject: [PATCH] Pcbnew: fix refdes ordering in arrays The first cell of the array needs to not be reannotated, or it will skips its own number(s) and take what we expect for the second cell. The repeats until the last entry, which didn't reannotate anything, leaving the original numbers. Producing a 'rotation' like 2,3,4,5,1 rather than the expected 1,2,3,4,5. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/20935 --- pcbnew/tools/array_tool.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pcbnew/tools/array_tool.cpp b/pcbnew/tools/array_tool.cpp index af095a0115..485cab1a3a 100644 --- a/pcbnew/tools/array_tool.cpp +++ b/pcbnew/tools/array_tool.cpp @@ -221,6 +221,8 @@ void ARRAY_TOOL::onDialogClosed( wxCloseEvent& aEvent ) return; } + const bool will_reannotate = !m_isFootprintEditor && m_array_opts->ShouldReannotateFootprints(); + // Iterate in reverse so the original items go last, and we can // use them for the positions of the clones. for( int ptN = arraySize - 1; ptN >= 0; --ptN ) @@ -317,9 +319,6 @@ void ARRAY_TOOL::onDialogClosed( wxCloseEvent& aEvent ) } } - // Add new items to selection (footprints in the selection will be reannotated) - items_for_this_block.Add( this_item ); - if( this_item ) { // Because aItem is/can be created from a selected item, and inherits from @@ -352,6 +351,10 @@ void ARRAY_TOOL::onDialogClosed( wxCloseEvent& aEvent ) } } + // Add new items to selection (footprints in the selection will be reannotated) + if( this_item ) + items_for_this_block.Add( this_item ); + // attempt to renumber items if the array parameters define // a complete numbering scheme to number by (as opposed to // implicit numbering by incrementing the items during creation @@ -371,7 +374,9 @@ void ARRAY_TOOL::onDialogClosed( wxCloseEvent& aEvent ) } } - if( !m_isFootprintEditor && m_array_opts->ShouldReannotateFootprints() ) + // Do not reannotate the first item, or it will skip its own numbering and + // the array annotations will shift by one cell. + if( will_reannotate && ptN != arraySize - 1 ) { m_toolMgr->GetTool()->ReannotateDuplicates( items_for_this_block, all_added_items );