From 864c152a5beccd99db16351677497356d2eb3ea9 Mon Sep 17 00:00:00 2001 From: Russell Oliver Date: Sun, 4 Feb 2018 21:47:37 +1100 Subject: [PATCH] Add converted footprint library to library table during Eagle project. --- pcbnew/files.cpp | 44 +++++++++++++++++++++++++++- pcbnew/footprint_libraries_utils.cpp | 5 +++- pcbnew/pcb_edit_frame.h | 2 +- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index a92e13e4ae..a0d1012017 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -879,7 +879,49 @@ bool PCB_EDIT_FRAME::ImportFile( const wxString& aFileName, int aFileType ) GetBoard()->SetFileName( newfilename.GetFullPath() ); UpdateTitle(); - ArchiveModulesOnBoard( true, newfilename.GetName() ); + wxString newLibPath; + ArchiveModulesOnBoard( true, newfilename.GetName(), &newLibPath ); + + if( newLibPath.Length()>0 ) + { + FP_LIB_TABLE* prjlibtable = Prj().PcbFootprintLibs(); + const wxString& project_env = PROJECT_VAR_NAME; + wxString rel_path; + wxString env_path; + + wxGetEnv( project_env, &env_path ); + + wxString result( newLibPath ); + rel_path = result.Replace( env_path, wxString( "$(" + project_env + ")" ) ) ? result : "" ; + + if( !rel_path.IsEmpty() ) newLibPath = rel_path; + + FP_LIB_TABLE_ROW* row = new FP_LIB_TABLE_ROW( newfilename.GetName(), + newLibPath, + wxT( "KiCad" ), + wxEmptyString ); // options + prjlibtable->InsertRow( row ); + } + + if( !GetBoard()->GetFileName().IsEmpty() ) + { + wxString tblName = Prj().FootprintLibTblName(); + + try + { + Prj().PcbFootprintLibs()->Save( tblName ); + } + catch( const IO_ERROR& ioe ) + { + wxString msg = wxString::Format( _( + "Error occurred saving project specific footprint library " + "table:\n\n%s" ), + GetChars( ioe.What() ) + ); + wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR ); + } + } + return true; } diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index b75162ef02..5a51c1e803 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -588,7 +588,7 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary() } -void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName ) +void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath ) { if( GetBoard()->m_Modules == NULL ) { @@ -634,6 +634,9 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& if( libPath.IsEmpty() ) // Aborted return; + + if( aLibPath ) *aLibPath = libPath; + IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP; PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) ); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 8ad8ca0aeb..8b53d9570e 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -938,7 +938,7 @@ public: * optional library name to create, stops dialog call. * must be called with aStoreInNewLib as true */ - void ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName = wxEmptyString ); + void ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName = wxEmptyString , wxString* aLibPath = NULL ); /** * Function RecreateBOMFileFromBoard