30 #include <lib_table_lexer.h> 42 using namespace LIB_TABLE_T;
80 if( in->CurTok() != T_fp_lib_table )
84 if( ( tok = in->NextTok() ) != T_fp_lib_table )
85 in->Expecting( T_fp_lib_table );
88 while( ( tok = in->NextTok() ) != T_RIGHT )
90 std::unique_ptr<FP_LIB_TABLE_ROW> row = std::make_unique<FP_LIB_TABLE_ROW>();
93 in->Expecting( T_RIGHT );
96 in->Expecting( T_LEFT );
99 int lineNum = in->CurLineNumber();
101 if( ( tok = in->NextTok() ) != T_lib )
102 in->Expecting( T_lib );
107 if( ( tok = in->NextTok() ) != T_name )
108 in->Expecting( T_name );
110 in->NeedSYMBOLorNUMBER();
112 row->SetNickName( in->FromUTF8() );
118 bool sawType =
false;
119 bool sawOpts =
false;
120 bool sawDesc =
false;
122 bool sawDisabled =
false;
124 while( ( tok = in->NextTok() ) != T_RIGHT )
127 in->Unexpected( T_EOF );
130 in->Expecting( T_LEFT );
132 tok = in->NeedSYMBOLorNUMBER();
138 in->Duplicate( tok );
140 in->NeedSYMBOLorNUMBER();
141 row->SetFullURI( in->FromUTF8() );
146 in->Duplicate( tok );
148 in->NeedSYMBOLorNUMBER();
149 row->SetType( in->FromUTF8() );
154 in->Duplicate( tok );
156 in->NeedSYMBOLorNUMBER();
157 row->SetOptions( in->FromUTF8() );
162 in->Duplicate( tok );
164 in->NeedSYMBOLorNUMBER();
165 row->SetDescr( in->FromUTF8() );
170 in->Duplicate( tok );
172 row->SetEnabled(
false );
176 in->Unexpected( tok );
183 in->Expecting( T_type );
186 in->Expecting( T_uri );
192 wxString nickname = row->GetNickName();
201 "footprint library table file line %d." ),
205 if( !errMsg.IsEmpty() )
212 if( !errMsg.IsEmpty() )
219 if(
rows.size() == aFpTable.
rows.size() )
221 for(
unsigned i = 0; i <
rows.size(); ++i )
236 aOutput->
Print( aIndentLevel,
"(fp_lib_table\n" );
239 it->Format( aOutput, aIndentLevel+1 );
241 aOutput->
Print( aIndentLevel,
")\n" );
253 wxCHECK( row && row->
plugin, hash );
256 wxHashTable::MakeKey( *aNickname );
263 wxCHECK2( row && row->
plugin,
continue );
266 wxHashTable::MakeKey( nickname );
278 row->
plugin->FootprintEnumerate( aFootprintNames, row->
GetFullURI(
true ), aBestEfforts,
300 wxString msg =
wxString::Format(
_(
"fp-lib-table files contain no library named '%s'." ),
317 const wxString& aFootprintName )
341 const wxString& aFootprintName )
346 return row->
plugin->GetEnumeratedFootprint( row->
GetFullURI(
true ), aFootprintName,
358 return row->
plugin->FootprintExists( row->
GetFullURI(
true ), aFootprintName,
369 const wxString& aFootprintName,
bool aKeepUUID )
384 const FOOTPRINT* aFootprint,
bool aOverwrite )
396 std::unique_ptr<FOOTPRINT> footprint( row->
plugin->FootprintLoad( row->
GetFullURI(
true ),
400 if( footprint.get() )
414 return row->
plugin->FootprintDelete( row->
GetFullURI(
true ), aFootprintName,
449 if( nickname.size() )
460 for(
unsigned i = 0; i < nicks.size(); ++i )
477 return wxT(
"KICAD6_FOOTPRINT_DIR" );
483 bool tableExists =
true;
486 if( !fn.FileExists() )
490 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
502 wxString templatePath =
503 Pgm().GetLocalEnvVariables().at( wxT(
"KICAD6_TEMPLATE_DIR" ) ).GetValue();
505 if( !templatePath.IsEmpty() )
511 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
515 emptyTable.
Save( fn.GetFullPath() );
519 aTable.
Load( fn.GetFullPath() );
532 return fn.GetFullPath();
void setPlugin(PLUGIN *aPlugin)
static const wxChar global_tbl_name[]
bool IsFootprintLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
const UTF8 & GetLibItemName() const
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
FOOTPRINT * FootprintLoadWithOptionalNickname(const LIB_ID &aFootprintId, bool aKeepUUID=false)
Load a footprint having aFootprintId with possibly an empty nickname.
FOOTPRINT * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName, bool aKeepUUID=false)
Load a footprint having aFootprintName from the library given by aNickname.
System directories search utilities.
Look for files in a number of paths.
A logical library item identifier and consists of various portions much like a URI.
void FootprintLibDelete(const wxString &aNickname)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
bool operator==(const LIB_TABLE_ROW &r) const
static void setLibNickname(FOOTPRINT *aModule, const wxString &aNickname, const wxString &aFootprintName)
long long GenerateTimestamp(const wxString *aNickname)
Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname,...
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...
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname, bool aBestEfforts)
Return a list of footprint names contained within the library given by aNickname.
const wxString & GetNickName() const
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
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...
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
static PCB_FILE_T EnumFromStr(const wxString &aFileType)
Return the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
void PrefetchLib(const wxString &aNickname)
If possible, prefetches the specified library (e.g.
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.
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,...
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
const FOOTPRINT * GetEnumeratedFootprint(const wxString &aNickname, const wxString &aFootprintName)
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
bool operator==(const FP_LIB_TABLE &aFpTable) const
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.
SAVE_T
The set of return values from FootprintSave() below.
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
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...
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
A base class that BOARD loading and saving plugins should derive from.
SAVE_T FootprintSave(const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
Write aFootprint to an existing library given by aNickname.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
void SetType(const wxString &aType) override
Change the type represented by this row.
std::string::size_type size() const
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Delete the aFootprintName from the library given by aNickname.
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
#define THROW_IO_ERROR(msg)
bool operator==(const FP_LIB_TABLE_ROW &aRow) const
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Indicates whether or not the given footprint already exists in the given library.
static wxString GetGlobalTableFileName()
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
S-expression Pcbnew file format.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.