30#include <lib_table_lexer.h>
45using namespace LIB_TABLE_T;
83 if( in->CurTok() != T_fp_lib_table )
87 if( ( tok = in->NextTok() ) != T_fp_lib_table )
88 in->Expecting( T_fp_lib_table );
91 while( ( tok = in->NextTok() ) != T_RIGHT )
93 std::unique_ptr<FP_LIB_TABLE_ROW> row = std::make_unique<FP_LIB_TABLE_ROW>();
96 in->Expecting( T_RIGHT );
99 in->Expecting( T_LEFT );
102 int lineNum = in->CurLineNumber();
106 if( tok == T_version )
108 in->NeedNUMBER(
"version" );
115 in->Expecting( T_lib );
120 if( ( tok = in->NextTok() ) != T_name )
121 in->Expecting( T_name );
123 in->NeedSYMBOLorNUMBER();
125 row->SetNickName( in->FromUTF8() );
131 bool sawType =
false;
132 bool sawOpts =
false;
133 bool sawDesc =
false;
135 bool sawDisabled =
false;
137 while( ( tok = in->NextTok() ) != T_RIGHT )
140 in->Unexpected( T_EOF );
143 in->Expecting( T_LEFT );
145 tok = in->NeedSYMBOLorNUMBER();
151 in->Duplicate( tok );
153 in->NeedSYMBOLorNUMBER();
154 row->SetFullURI( in->FromUTF8() );
159 in->Duplicate( tok );
161 in->NeedSYMBOLorNUMBER();
162 row->SetType( in->FromUTF8() );
167 in->Duplicate( tok );
169 in->NeedSYMBOLorNUMBER();
170 row->SetOptions( in->FromUTF8() );
175 in->Duplicate( tok );
177 in->NeedSYMBOLorNUMBER();
178 row->SetDescr( in->FromUTF8() );
183 in->Duplicate( tok );
185 row->SetEnabled(
false );
195 in->Unexpected( tok );
202 in->Expecting( T_type );
205 in->Expecting( T_uri );
211 wxString nickname = row->GetNickName();
219 wxString msg = wxString::Format(
_(
"Duplicate library nickname '%s' found in "
220 "footprint library table file line %d." ),
224 if( !errMsg.IsEmpty() )
231 if( !errMsg.IsEmpty() )
240 for(
unsigned i = 0; i <
m_rows.size(); ++i )
255 aOutput->
Print( aIndentLevel,
"(fp_lib_table\n" );
259 it->Format( aOutput, aIndentLevel+1 );
261 aOutput->
Print( aIndentLevel,
")\n" );
273 wxCHECK( row && row->
plugin, hash );
276 wxHashTable::MakeKey( *aNickname );
285 row =
FindRow( nickname,
true );
292 wxCHECK2( row && row->
plugin,
continue );
295 wxHashTable::MakeKey( nickname );
329 wxString msg = wxString::Format(
_(
"fp-lib-table files contain no library named '%s'." ),
345 const wxString& aFootprintName )
369 const wxString& aFootprintName )
397 const wxString& aFootprintName,
bool aKeepUUID )
412 const FOOTPRINT* aFootprint,
bool aOverwrite )
428 if( footprint.get() )
477 if( nickname.size() )
488 for(
unsigned i = 0; i < nicks.size(); ++i )
505 return wxS(
"KICAD7_FOOTPRINT_DIR" );
513 const wxString& aPrefix ) :
518 wxFileName f( aPath, wxS(
"" ) );
522 wxDirTraverseResult
OnFile(
const wxString& aFilePath )
override {
return wxDIR_CONTINUE; }
524 wxDirTraverseResult
OnDir(
const wxString& dirPath )
override
526 wxFileName dir = wxFileName::DirName( dirPath );
530 if( dirPath.EndsWith( wxS(
".pretty" ) ) && dir.GetDirCount() >=
m_prefix_dir_count + 3 )
532 wxArrayString parts = dir.GetDirs();
534 parts.Insert( wxS(
"${KICAD7_3RD_PARTY}" ), 0 );
536 wxString libPath = wxJoin( parts,
'/' );
540 wxString
name = parts.Last().substr( 0, parts.Last().length() - 7 );
548 nickname = wxString::Format( wxS(
"%s%s_%d" ),
m_lib_prefix,
name, increment );
555 _(
"Added by Plugin and Content Manager" ) ) );
559 return wxDIR_CONTINUE;
572 bool tableExists =
true;
575 if( !fn.FileExists() )
579 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
581 THROW_IO_ERROR( wxString::Format(
_(
"Cannot create global library table path '%s'." ),
591 wxString templatePath =
592 Pgm().GetLocalEnvVariables().at( wxT(
"KICAD7_TEMPLATE_DIR" ) ).GetValue();
594 if( !templatePath.IsEmpty() )
600 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(),
false ) )
604 emptyTable.
Save( fn.GetFullPath() );
609 aTable.
Load( fn.GetFullPath() );
614 wxString packagesPath =
Pgm().GetLocalEnvVariables().at( wxT(
"KICAD7_3RD_PARTY" ) ).GetValue();
620 wxFileName d( packagesPath, wxS(
"" ) );
621 d.AppendDir( wxS(
"footprints" ) );
626 wxDir dir( d.GetPath() );
628 dir.Traverse( traverser );
635 std::vector<wxString> to_remove;
637 for(
size_t i = 0; i < aTable.
GetCount(); i++ )
642 if(
path.StartsWith( packagesPath ) && !wxDir::Exists(
path ) )
646 for(
const wxString& nickName : to_remove )
661 return fn.GetFullPath();
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
void SetType(const wxString &aType) override
Change the type represented by this row.
bool operator==(const FP_LIB_TABLE_ROW &aRow) const
void setPlugin(PLUGIN *aPlugin)
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Delete the aFootprintName from the library given by aNickname.
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
bool operator==(const FP_LIB_TABLE &aFpTable) const
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname, bool aBestEfforts)
Return a list of footprint names contained within the library given by aNickname.
void FootprintLibCreate(const wxString &aNickname)
FP_LIB_TABLE(FP_LIB_TABLE *aFallBackTable=nullptr)
Build a footprint library table by pre-pending this table fragment in front of aFallBackTable.
const FOOTPRINT * GetEnumeratedFootprint(const wxString &aNickname, const wxString &aFootprintName)
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
FOOTPRINT * FootprintLoadWithOptionalNickname(const LIB_ID &aFootprintId, bool aKeepUUID=false)
Load a footprint having aFootprintId with possibly an empty nickname.
long long GenerateTimestamp(const wxString *aNickname)
Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname,...
void FootprintLibDelete(const wxString &aNickname)
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Indicates whether or not the given footprint already exists in the given library.
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
bool IsFootprintLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
void PrefetchLib(const wxString &aNickname)
If possible, prefetches the specified library (e.g.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
SAVE_T
The set of return values from FootprintSave() below.
FOOTPRINT * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName, bool aKeepUUID=false)
Load a footprint having aFootprintName from the library given by aNickname.
SAVE_T FootprintSave(const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
Write aFootprint to an existing library given by aNickname.
static wxString GetGlobalTableFileName()
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written,...
@ KICAD_SEXP
S-expression Pcbnew file format.
static PCB_FILE_T EnumFromStr(const wxString &aFileType)
Return the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
A logical library item identifier and consists of various portions much like a URI.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetNickName() const
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
bool operator==(const LIB_TABLE_ROW &r) const
const STRING_UTF8_MAP * GetProperties() const
Return the constant #PROPERTIES for this library (LIB_TABLE_ROW).
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
int m_version
Versioning to handle importing old tables.
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
LIB_TABLE_ROWS m_rows
Owning set of rows.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
bool HasLibraryWithPath(const wxString &aPath) const
Test for the existence of aPath in the library table.
bool RemoveRow(const LIB_TABLE_ROW *aRow)
Removes a row from the table and frees the pointer.
void Clear()
Delete all rows.
unsigned GetCount() const
Get the number of rows contained in the table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
LIB_TABLE_ROW * findRow(const wxString &aNickname, bool aCheckIfEnabled=false) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment,...
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
PCM_FP_LIB_TRAVERSER(const wxString &aPath, FP_LIB_TABLE &aTable, const wxString &aPrefix)
wxDirTraverseResult OnFile(const wxString &aFilePath) override
size_t m_prefix_dir_count
wxDirTraverseResult OnDir(const wxString &dirPath) override
FP_LIB_TABLE & m_lib_table
A base class that BOARD loading and saving plugins should derive from.
virtual const FOOTPRINT * GetEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
virtual void FootprintLibCreate(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty footprint library at aLibraryPath empty.
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Delete an existing footprint library and returns true, or if library does not exist returns false,...
virtual void FootprintSave(const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const STRING_UTF8_MAP *aProperties=nullptr)
Write aFootprint to an existing library located at aLibraryPath.
virtual void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete aFootprintName from the library at aLibraryPath.
virtual bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
Check for the existence of a footprint.
virtual FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const STRING_UTF8_MAP *aProperties=nullptr)
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
virtual long long GetLibraryTimestamp(const wxString &aLibraryPath) const =0
Generate a timestamp representing all the files in the library (including the library directory).
virtual void PrefetchLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
If possible, prefetches the specified library (e.g.
virtual void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const STRING_UTF8_MAP *aProperties=nullptr)
Return a list of footprint names contained within the library at aLibraryPath.
Look for files in a number of paths.
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
std::string::size_type size() const
static const wxChar global_tbl_name[]
static void setLibNickname(FOOTPRINT *aModule, const wxString &aNickname, const wxString &aFootprintName)
#define THROW_IO_ERROR(msg)
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
System directories search utilities.