diff --git a/pcbnew/netlist_reader/board_netlist_updater.cpp b/pcbnew/netlist_reader/board_netlist_updater.cpp index ecff4d8f59..844c246194 100644 --- a/pcbnew/netlist_reader/board_netlist_updater.cpp +++ b/pcbnew/netlist_reader/board_netlist_updater.cpp @@ -345,6 +345,7 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint, } nlohmann::ordered_map fpFieldsAsMap; + for( PCB_FIELD* field : aPcbFootprint->GetFields() ) { // These fields are individually checked above, and are not currently present in (fields) anyway. @@ -367,16 +368,19 @@ bool BOARD_NETLIST_UPDATER::updateFootprintParameters( FOOTPRINT* aPcbFootprint, changed = true; // Add or change field value - for( auto pair : aNetlistComponent->GetFields() ) + for( auto& [ name, value ] : aNetlistComponent->GetFields() ) { - if( aPcbFootprint->HasFieldByName( pair.first ) ) - aPcbFootprint->GetFieldByName( pair.first )->SetText( pair.second ); + if( aPcbFootprint->HasFieldByName( name ) ) + { + aPcbFootprint->GetFieldByName( name )->SetText( value ); + } else { - PCB_FIELD* newField = aPcbFootprint->AddField( PCB_FIELD( - aPcbFootprint, aPcbFootprint->GetFieldCount(), pair.first ) ); + int idx = aPcbFootprint->GetFieldCount(); + PCB_FIELD* newField = aPcbFootprint->AddField( PCB_FIELD( aPcbFootprint, idx ) ); - newField->SetText( pair.second ); + newField->SetName( name ); + newField->SetText( value ); newField->SetVisible( false ); newField->SetLayer( aPcbFootprint->GetLayer() == F_Cu ? F_Fab : B_Fab );