PCB array tool: don't count array source pad as reserving its number

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/20722
This commit is contained in:
John Beard 2025-04-23 23:32:20 +08:00
parent 874fad4846
commit 1b1623885c
4 changed files with 21 additions and 37 deletions

View File

@ -26,7 +26,7 @@
#include <pad.h>
ARRAY_PAD_NUMBER_PROVIDER::ARRAY_PAD_NUMBER_PROVIDER( const FOOTPRINT* aFootprint,
ARRAY_PAD_NUMBER_PROVIDER::ARRAY_PAD_NUMBER_PROVIDER( const std::set<wxString>& aExistingPadNumbers,
const ARRAY_OPTIONS& aArrayOpts )
: m_arrayOpts( aArrayOpts )
{
@ -41,13 +41,7 @@ ARRAY_PAD_NUMBER_PROVIDER::ARRAY_PAD_NUMBER_PROVIDER( const FOOTPRINT* aFootprin
}
else
{
// no footprint, no reserved names either
if( aFootprint )
{
// reserve the name of each existing pad
for( PAD* pad : aFootprint->Pads() )
m_existing_pad_numbers.insert( pad->GetNumber() );
}
m_existing_pad_numbers = aExistingPadNumbers;
}
}

View File

@ -40,7 +40,7 @@ public:
* @param aFootprint the footprint to gather existing numbers from (nullptr for no footprint)
* @param aArrayOpts the array options that provide the candidate numbers
*/
ARRAY_PAD_NUMBER_PROVIDER( const FOOTPRINT* aFootprint, const ARRAY_OPTIONS& aArrayOpts );
ARRAY_PAD_NUMBER_PROVIDER( const std::set<wxString>& aExistingPadNumbers, const ARRAY_OPTIONS& aArrayOpts );
/**
* Get the next available pad name.
@ -61,4 +61,4 @@ private:
int m_current_pad_index;
};
#endif // PCBNEW_ARRAY_PAD_NAME_PROVIDER__H
#endif // PCBNEW_ARRAY_PAD_NAME_PROVIDER__H

View File

@ -130,7 +130,21 @@ void ARRAY_TOOL::onDialogClosed( wxCloseEvent& aEvent )
FOOTPRINT* const fp =
m_isFootprintEditor ? editFrame->GetBoard()->GetFirstFootprint() : nullptr;
ARRAY_PAD_NUMBER_PROVIDER pad_number_provider( fp, *m_array_opts );
// Collect a list of pad numbers that will _not_ be counted as "used"
// when finding the next pad numbers.
// Things that are selected are fair game, as they'll give up their numbers.
// Keeps numbers used by both selected and unselected pads as "reserved".
std::set<wxString> unchangingPadNumbers;
if( fp )
{
for( PAD* pad : fp->Pads() )
{
if( !pad->IsSelected() )
unchangingPadNumbers.insert( pad->GetNumber() );
}
}
ARRAY_PAD_NUMBER_PROVIDER pad_number_provider( unchangingPadNumbers, *m_array_opts );
EDA_ITEMS all_added_items;

View File

@ -30,24 +30,6 @@
#include <footprint.h>
#include <pad.h>
/**
* Make a footprint with a given list of named pads
*/
static std::unique_ptr<FOOTPRINT> FootprintWithPads( const std::vector<wxString> aNames )
{
std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( nullptr );
for( const wxString& name : aNames )
{
std::unique_ptr<PAD> pad = std::make_unique<PAD>( footprint.get() );
pad->SetNumber( name );
footprint->Add( pad.release() );
}
return footprint;
}
/**
* Declare the test suite
@ -58,8 +40,7 @@ BOOST_AUTO_TEST_SUITE( ArrayPadNumberProv )
struct APNP_CASE
{
std::string m_case_name;
bool m_using_footprint;
std::vector<wxString> m_existing_pads;
std::set<wxString> m_existing_pad_numbers;
std::unique_ptr<ARRAY_OPTIONS> m_arr_opts;
std::vector<wxString> m_expected_numbers;
};
@ -82,7 +63,6 @@ std::vector<APNP_CASE> GetFootprintAPNPCases()
cases.push_back( {
"Simple linear, skip some",
true,
{ "1", "3" },
std::move( opts ),
{ "2", "4", "5", "6", "7" },
@ -98,7 +78,6 @@ std::vector<APNP_CASE> GetFootprintAPNPCases()
cases.push_back( {
"Simple linear, no footprint",
false,
{}, // not used
std::move( opts ),
{ "1", "2", "3", "4", "5" },
@ -137,10 +116,7 @@ BOOST_AUTO_TEST_CASE( FootprintCases )
{
std::unique_ptr<FOOTPRINT> footprint;
if( c.m_using_footprint )
footprint = FootprintWithPads( c.m_existing_pads );
ARRAY_PAD_NUMBER_PROVIDER apnp( footprint.get(), *c.m_arr_opts );
ARRAY_PAD_NUMBER_PROVIDER apnp( c.m_existing_pad_numbers, *c.m_arr_opts );
CheckPadNumberProvider( apnp, c.m_expected_numbers );
}