Fix perpetual footprint change notifications for legacy FPIDs
When schematic symbols have footprint fields without library name prefixes
(e.g., "DGG56" instead of "Package_SO:DGG56"), the netlist updater's FPID
comparison always fails against the board's fully qualified FPIDs, causing
"Update PCB from Schematic" to perpetually report footprint changes that
can never be resolved.
Match by item name only when the schematic-side FPID has no library
nickname (legacy format), and warn the user to add the library prefix.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/22958
(cherry picked from commit c28dd5d4a9)
This commit is contained in:
@@ -1292,6 +1292,31 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
|
||||
EscapeHTML( component->GetFPID().Format().wx_str() ) );
|
||||
m_reporter->Report( msg, RPT_SEVERITY_INFO );
|
||||
|
||||
const LIB_ID& compFpid = component->GetFPID();
|
||||
|
||||
if( compFpid.IsLegacy() )
|
||||
{
|
||||
msg.Printf( _( "Warning: %s footprint '%s' is missing a library name. "
|
||||
"Use the full 'Library:Footprint' format to avoid repeated update "
|
||||
"notifications." ),
|
||||
component->GetReference(),
|
||||
EscapeHTML( compFpid.Format().wx_str() ) );
|
||||
m_reporter->Report( msg, RPT_SEVERITY_WARNING );
|
||||
++m_warningCount;
|
||||
}
|
||||
|
||||
// When the schematic-side FPID has no library nickname (legacy format like
|
||||
// "DGG56" instead of "Package_SO:DGG56"), matching should compare only the
|
||||
// footprint item name. Otherwise the board footprint (which always has a library
|
||||
// nickname) will never match, causing perpetual "change footprint" notifications.
|
||||
auto fpidMatches = [&]( const LIB_ID& aBoardFpid, const LIB_ID& aExpectedFpid ) -> bool
|
||||
{
|
||||
if( aExpectedFpid.IsLegacy() )
|
||||
return aBoardFpid.GetLibItemName() == aExpectedFpid.GetLibItemName();
|
||||
|
||||
return aBoardFpid == aExpectedFpid;
|
||||
};
|
||||
|
||||
int matchCount = 0;
|
||||
|
||||
for( FOOTPRINT* footprint : m_board->Footprints() )
|
||||
@@ -1321,7 +1346,7 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist )
|
||||
{
|
||||
FOOTPRINT* tmp = footprint;
|
||||
|
||||
if( m_replaceFootprints && component->GetFPID() != footprint->GetFPID() )
|
||||
if( m_replaceFootprints && !fpidMatches( footprint->GetFPID(), compFpid ) )
|
||||
tmp = replaceFootprint( aNetlist, footprint, component );
|
||||
|
||||
if( !tmp )
|
||||
|
||||
@@ -199,7 +199,22 @@ void PCB_EDIT_FRAME::LoadFootprints( NETLIST& aNetlist, REPORTER& aReporter )
|
||||
else
|
||||
fpOnBoard = m_pcb->FindFootprintByReference( component->GetReference() );
|
||||
|
||||
bool footprintMisMatch = fpOnBoard && fpOnBoard->GetFPID() != component->GetFPID();
|
||||
// When the schematic-side FPID has no library nickname (legacy format), match
|
||||
// only by item name so we don't flag a mismatch against a fully qualified board FPID.
|
||||
bool footprintMisMatch = false;
|
||||
|
||||
if( fpOnBoard )
|
||||
{
|
||||
if( component->GetFPID().IsLegacy() )
|
||||
{
|
||||
footprintMisMatch =
|
||||
fpOnBoard->GetFPID().GetLibItemName() != component->GetFPID().GetLibItemName();
|
||||
}
|
||||
else
|
||||
{
|
||||
footprintMisMatch = fpOnBoard->GetFPID() != component->GetFPID();
|
||||
}
|
||||
}
|
||||
|
||||
if( footprintMisMatch && !aNetlist.GetReplaceFootprints() )
|
||||
{
|
||||
|
||||
@@ -46,6 +46,7 @@ set( QA_COMMON_SRCS
|
||||
test_kicad_stroke_font.cpp
|
||||
test_kiid.cpp
|
||||
test_layer_ids.cpp
|
||||
test_lib_id.cpp
|
||||
test_layer_range.cpp
|
||||
test_lset.cpp
|
||||
test_property.cpp
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <lib_id.h>
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( LibId )
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ParseFullyQualified )
|
||||
{
|
||||
LIB_ID id;
|
||||
BOOST_CHECK( id.Parse( "Package_SO:DGG56" ) == -1 );
|
||||
BOOST_CHECK_EQUAL( id.GetLibNickname(), "Package_SO" );
|
||||
BOOST_CHECK_EQUAL( id.GetLibItemName(), "DGG56" );
|
||||
BOOST_CHECK( id.IsValid() );
|
||||
BOOST_CHECK( !id.IsLegacy() );
|
||||
BOOST_CHECK( !id.empty() );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ParseLegacy )
|
||||
{
|
||||
LIB_ID id;
|
||||
BOOST_CHECK( id.Parse( "DGG56" ) == -1 );
|
||||
BOOST_CHECK( id.GetLibNickname().empty() );
|
||||
BOOST_CHECK_EQUAL( id.GetLibItemName(), "DGG56" );
|
||||
BOOST_CHECK( !id.IsValid() );
|
||||
BOOST_CHECK( id.IsLegacy() );
|
||||
BOOST_CHECK( !id.empty() );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( EqualityFullyQualified )
|
||||
{
|
||||
LIB_ID a( wxT( "Package_SO" ), wxT( "DGG56" ) );
|
||||
LIB_ID b( wxT( "Package_SO" ), wxT( "DGG56" ) );
|
||||
LIB_ID c( wxT( "OtherLib" ), wxT( "DGG56" ) );
|
||||
|
||||
BOOST_CHECK( a == b );
|
||||
BOOST_CHECK( a != c );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( EqualityLegacyVsFullyQualified )
|
||||
{
|
||||
LIB_ID legacy;
|
||||
legacy.Parse( "DGG56" );
|
||||
|
||||
LIB_ID qualified( wxT( "Package_SO" ), wxT( "DGG56" ) );
|
||||
|
||||
// Standard equality requires both library and item name to match
|
||||
BOOST_CHECK( legacy != qualified );
|
||||
|
||||
// Legacy matching (item name only) should match when we explicitly compare just item names
|
||||
BOOST_CHECK( legacy.IsLegacy() );
|
||||
BOOST_CHECK_EQUAL( legacy.GetLibItemName(), qualified.GetLibItemName() );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( FormatRoundTrip )
|
||||
{
|
||||
LIB_ID qualified( wxT( "Package_SO" ), wxT( "DGG56" ) );
|
||||
BOOST_CHECK_EQUAL( qualified.Format().wx_str(), wxString( wxT( "Package_SO:DGG56" ) ) );
|
||||
|
||||
LIB_ID legacy;
|
||||
legacy.Parse( "DGG56" );
|
||||
BOOST_CHECK_EQUAL( legacy.Format().wx_str(), wxString( wxT( "DGG56" ) ) );
|
||||
|
||||
// Re-parse the formatted strings
|
||||
LIB_ID reparsed;
|
||||
reparsed.Parse( qualified.Format() );
|
||||
BOOST_CHECK( reparsed == qualified );
|
||||
|
||||
LIB_ID reparsedLegacy;
|
||||
reparsedLegacy.Parse( legacy.Format() );
|
||||
BOOST_CHECK( reparsedLegacy.IsLegacy() );
|
||||
BOOST_CHECK_EQUAL( reparsedLegacy.GetLibItemName(), legacy.GetLibItemName() );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( EmptyId )
|
||||
{
|
||||
LIB_ID empty;
|
||||
BOOST_CHECK( empty.empty() );
|
||||
BOOST_CHECK( !empty.IsValid() );
|
||||
BOOST_CHECK( !empty.IsLegacy() );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
Reference in New Issue
Block a user