23#include <wx/filename.h>
37 const std::vector<wxString>& aLibraries,
40 std::vector<wxString> added;
42 if( aLibraries.empty() )
47 std::optional<LIBRARY_TABLE*> optTable =
50 wxCHECK_MSG( adapter && optTable.has_value(), added,
"Could not load footprint lib table." );
55 for(
const wxString& file : aLibraries )
60 wxFileName fn( file );
63 if( !fn.FileExists() && !wxDirExists( fn.GetFullPath() ) )
70 wxLogTrace(
"KIWAY",
"Unknown file type: %s", fn.GetFullPath() );
76 wxFileName relFn( fn );
77 bool isProjectLocal = !aSourceProjectDir.IsEmpty() && relFn.MakeRelativeTo( aSourceProjectDir )
78 && !relFn.IsAbsolute() && !relFn.GetFullPath().StartsWith( wxS(
".." ) );
85 if( !fn.FileExists() )
88 wxFileName projectFn( projectPath, fn.GetFullName() );
90 if( fn.GetFullPath() != projectFn.GetFullPath() && !projectFn.FileExists()
91 && !wxCopyFile( fn.GetFullPath(), projectFn.GetFullPath(),
false ) )
93 aReporter.
Report( wxString::Format(
_(
"Error copying footprint library '%s'." ), fn.GetFullPath() ),
98 libTableUri = wxS(
"${KIPRJMOD}/" ) + fn.GetFullName();
103 libTableUri = fn.GetFullPath();
106 if( !
table->HasRow( fn.GetName() ) )
110 row.
SetURI( libTableUri );
112 added.emplace_back( fn.GetName() );
121 table->Save().map_error(
124 aReporter.
Report(
_(
"Error saving project library table:\n\n" ) + aError.
message,
135 for(
const wxString& nick : added )
std::optional< LIBRARY_TABLE * > Table(LIBRARY_TABLE_TYPE aType, LIBRARY_TABLE_SCOPE aScope)
Retrieves a given table; creating a new empty project table if a valid project is loaded and the give...
void AbortAsyncLoads()
Abort any async library loading operations in progress.
void LoadProjectTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the project library tables in the given list, or all tables if no list is given
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
PCB_FILE_T
The set of file types that the PCB_IO_MGR knows about, and for which there has been a plugin written,...
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a footprint library's libPath.
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
virtual LIBRARY_MANAGER & GetLibraryManager() const
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
virtual const wxString GetProjectPath() const
Return the full path of the project.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
PGM_BASE & Pgm()
The global program "get" accessor.