diff --git a/pcbnew/array_pad_number_provider.cpp b/pcbnew/array_pad_number_provider.cpp index 3387893c73..5bb74f331e 100644 --- a/pcbnew/array_pad_number_provider.cpp +++ b/pcbnew/array_pad_number_provider.cpp @@ -26,7 +26,7 @@ #include -ARRAY_PAD_NUMBER_PROVIDER::ARRAY_PAD_NUMBER_PROVIDER( const FOOTPRINT* aFootprint, +ARRAY_PAD_NUMBER_PROVIDER::ARRAY_PAD_NUMBER_PROVIDER( const std::set& 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; } } diff --git a/pcbnew/array_pad_number_provider.h b/pcbnew/array_pad_number_provider.h index 4d76abca24..00269250d2 100644 --- a/pcbnew/array_pad_number_provider.h +++ b/pcbnew/array_pad_number_provider.h @@ -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& 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 \ No newline at end of file +#endif // PCBNEW_ARRAY_PAD_NAME_PROVIDER__H diff --git a/pcbnew/tools/array_tool.cpp b/pcbnew/tools/array_tool.cpp index 25166a72b7..6384a85360 100644 --- a/pcbnew/tools/array_tool.cpp +++ b/pcbnew/tools/array_tool.cpp @@ -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 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; diff --git a/qa/tests/pcbnew/test_array_pad_name_provider.cpp b/qa/tests/pcbnew/test_array_pad_name_provider.cpp index 98209f601a..ba4f2dbc2b 100644 --- a/qa/tests/pcbnew/test_array_pad_name_provider.cpp +++ b/qa/tests/pcbnew/test_array_pad_name_provider.cpp @@ -30,24 +30,6 @@ #include #include -/** - * Make a footprint with a given list of named pads - */ -static std::unique_ptr FootprintWithPads( const std::vector aNames ) -{ - std::unique_ptr footprint = std::make_unique( nullptr ); - - for( const wxString& name : aNames ) - { - std::unique_ptr pad = std::make_unique( 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 m_existing_pads; + std::set m_existing_pad_numbers; std::unique_ptr m_arr_opts; std::vector m_expected_numbers; }; @@ -82,7 +63,6 @@ std::vector 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 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; - 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 ); }