From 7c8e74c156bc1591cffd191f3b11a89e8e5b06d2 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Mon, 2 Oct 2023 10:25:54 -0400 Subject: [PATCH] Fields: fix redundant update messages Fixes: https://gitlab.com/kicad/code/kicad/-/issues/15801 --- pcbnew/footprint.h | 2 ++ .../netlist_reader/board_netlist_updater.cpp | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index 87b3f80613..b0c02512f8 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -591,10 +591,12 @@ public: /// read/write accessors: PCB_FIELD& Value() { return *GetField( VALUE_FIELD ); } PCB_FIELD& Reference() { return *GetField( REFERENCE_FIELD ); } + PCB_FIELD& Footprint() { return *GetField( FOOTPRINT_FIELD ); } /// The const versions to keep the compiler happy. const PCB_FIELD& Value() const { return *GetField( VALUE_FIELD ); } const PCB_FIELD& Reference() const { return *GetField( REFERENCE_FIELD ); } + const PCB_FIELD& Footprint() const { return *GetField( FOOTPRINT_FIELD ); } //---------------------------------------------------------------- diff --git a/pcbnew/netlist_reader/board_netlist_updater.cpp b/pcbnew/netlist_reader/board_netlist_updater.cpp index 844c246194..d1d9d1ee36 100644 --- a/pcbnew/netlist_reader/board_netlist_updater.cpp +++ b/pcbnew/netlist_reader/board_netlist_updater.cpp @@ -315,6 +315,16 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint, m_reporter->Report( msg, RPT_SEVERITY_ACTION ); } + // Test for footprint change. This is controlled by a separate flag, that will output + // its own message if the footprint is changed, so we just set the field here. + if( ( m_replaceFootprints || ( aPcbFootprint->GetAttributes() & FP_JUST_ADDED ) ) + && !m_isDryRun ) + { + aPcbFootprint->Footprint().SetText( + aNetlistComponent + ->GetFields()[TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD )] ); + } + // Test for time stamp change. KIID_PATH new_path = aNetlistComponent->GetPath(); @@ -348,14 +358,21 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint, for( PCB_FIELD* field : aPcbFootprint->GetFields() ) { - // These fields are individually checked above, and are not currently present in (fields) anyway. + // These fields are individually checked above if( field->IsReference() || field->IsValue() || field->IsFootprint() ) continue; fpFieldsAsMap[field->GetName()] = field->GetText(); } - if( fpFieldsAsMap != aNetlistComponent->GetFields() ) + // Remove the ref/value/footprint fields that are individually handled + nlohmann::ordered_map compFields = aNetlistComponent->GetFields(); + compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) ); + compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( VALUE_FIELD ) ); + compFields.erase( TEMPLATE_FIELDNAME::GetDefaultFieldName( FOOTPRINT_FIELD ) ); + + + if( fpFieldsAsMap != compFields ) { if( m_isDryRun ) { @@ -368,7 +385,7 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint, changed = true; // Add or change field value - for( auto& [ name, value ] : aNetlistComponent->GetFields() ) + for( auto& [name, value] : compFields ) { if( aPcbFootprint->HasFieldByName( name ) ) { @@ -404,7 +421,7 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint, if( field->IsMandatoryField() ) continue; - if( aNetlistComponent->GetFields().count( field->GetName() ) == 0 ) + if( compFields.count( field->GetName() ) == 0 ) { aPcbFootprint->RemoveField( field->GetCanonicalName() );