From 1fd555ce0ed84749f11f4b357e2216b747928a07 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 21 Aug 2021 18:59:14 +0100 Subject: [PATCH] Added code to map footprint lib nicknames when exporting. This is particularly useful when you import (for instance) an Altium board and then save the footprints out to a new library. Fixes https://gitlab.com/kicad/code/kicad/issues/6345 --- pcbnew/footprint_libraries_utils.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 1813b6f4f4..da8c9c0235 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -686,6 +686,9 @@ void PCB_EDIT_FRAME::ExportFootprintsToLibrary( bool aStoreInNewLib, const wxStr if( !nickname ) // Aborted return; + bool map = IsOK( this, wxString::Format( _( "Update footprints on board to refer to %s?" ), + nickname ) ); + prj.SetRString( PROJECT::PCB_LIB_NICKNAME, nickname ); for( FOOTPRINT* footprint : GetBoard()->Footprints() ) @@ -708,6 +711,13 @@ void PCB_EDIT_FRAME::ExportFootprintsToLibrary( bool aStoreInNewLib, const wxStr { DisplayError( this, ioe.What() ); } + + if( map ) + { + LIB_ID id = footprint->GetFPID(); + id.SetLibNickname( nickname ); + footprint->SetFPID( id ); + } } } else @@ -722,6 +732,17 @@ void PCB_EDIT_FRAME::ExportFootprintsToLibrary( bool aStoreInNewLib, const wxStr if( aLibPath ) *aLibPath = libPath; + wxString libNickname; + bool map = IsOK( this, _( "Update footprints on board to refer to new library?" ) ); + + if( map ) + { + const LIB_TABLE_ROW* row = Prj().PcbFootprintLibs()->FindRowByURI( libPath ); + + if( row ) + libNickname = row->GetNickName(); + } + IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP; PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) ); @@ -743,6 +764,13 @@ void PCB_EDIT_FRAME::ExportFootprintsToLibrary( bool aStoreInNewLib, const wxStr { DisplayError( this, ioe.What() ); } + + if( map ) + { + LIB_ID id = footprint->GetFPID(); + id.SetLibNickname( libNickname ); + footprint->SetFPID( id ); + } } } }