KiCad PCB EDA Suite
FP_LIB_TABLE Class Reference

#include <fp_lib_table.h>

Inheritance diagram for FP_LIB_TABLE:
LIB_TABLE PROJECT::_ELEM FP_LIB_TABLE_GRID

Public Types

enum  SAVE_T { SAVE_OK , SAVE_SKIPPED }
 The set of return values from FootprintSave() below. More...
 

Public Member Functions

KICAD_T Type () override
 
virtual void Parse (LIB_TABLE_LEXER *aLexer) override
 Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objects. More...
 
virtual void Format (OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
 Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel. More...
 
 FP_LIB_TABLE (FP_LIB_TABLE *aFallBackTable=nullptr)
 Build a footprint library table by pre-pending this table fragment in front of aFallBackTable. More...
 
bool operator== (const FP_LIB_TABLE &aFpTable) const
 
bool operator!= (const FP_LIB_TABLE &r) const
 
const FP_LIB_TABLE_ROWFindRow (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 fragment. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aNickname, bool aBestEfforts)
 Return a list of footprint names contained within the library given by aNickname. More...
 
long long GenerateTimestamp (const wxString *aNickname)
 Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname, or all libraries if aNickname is NULL. More...
 
void PrefetchLib (const wxString &aNickname)
 If possible, prefetches the specified library (e.g. More...
 
FOOTPRINTFootprintLoad (const wxString &aNickname, const wxString &aFootprintName, bool aKeepUUID=false)
 Load a footprint having aFootprintName from the library given by aNickname. More...
 
bool FootprintExists (const wxString &aNickname, const wxString &aFootprintName)
 Indicates whether or not the given footprint already exists in the given library. More...
 
const FOOTPRINTGetEnumeratedFootprint (const wxString &aNickname, const wxString &aFootprintName)
 A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. More...
 
SAVE_T FootprintSave (const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
 Write aFootprint to an existing library given by aNickname. More...
 
void FootprintDelete (const wxString &aNickname, const wxString &aFootprintName)
 Delete the aFootprintName from the library given by aNickname. More...
 
bool IsFootprintLibWritable (const wxString &aNickname)
 Return true if the library given by aNickname is writable. More...
 
void FootprintLibDelete (const wxString &aNickname)
 
void FootprintLibCreate (const wxString &aNickname)
 
FOOTPRINTFootprintLoadWithOptionalNickname (const LIB_ID &aFootprintId, bool aKeepUUID=false)
 Load a footprint having aFootprintId with possibly an empty nickname. More...
 
void Clear ()
 Delete all rows. More...
 
bool operator== (const LIB_TABLE &r) const
 Compares this table against another. More...
 
bool operator!= (const LIB_TABLE &r) const
 
unsigned GetCount () const
 Get the number of rows contained in the table. More...
 
LIB_TABLE_ROWAt (unsigned aIndex)
 Get the 'n'th LIB_TABLE_ROW object. More...
 
const LIB_TABLE_ROWAt (unsigned aIndex) const
 Get the 'n'th LIB_TABLE_ROW object. More...
 
bool IsEmpty (bool aIncludeFallback=true)
 Return true if the table is empty. More...
 
const wxString GetDescription (const wxString &aNickname)
 
bool HasLibrary (const wxString &aNickname, bool aCheckEnabled=false) const
 Test for the existence of aNickname in the library table. More...
 
bool HasLibraryWithPath (const wxString &aPath) const
 Test for the existence of aPath in the library table. More...
 
std::vector< wxString > GetLogicalLibs ()
 Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE. More...
 
wxString GetFullURI (const wxString &aLibNickname, bool aExpandEnvVars=true) const
 Return the full URI of the library mapped to aLibNickname. More...
 
bool InsertRow (LIB_TABLE_ROW *aRow, bool doReplace=false)
 Adds aRow if it does not already exist or if doReplace is true. More...
 
bool RemoveRow (const LIB_TABLE_ROW *aRow)
 Removes a row from the table. More...
 
const LIB_TABLE_ROWFindRowByURI (const wxString &aURI)
 
void Load (const wxString &aFileName)
 Load the library table using the path defined by aFileName aFallBackTable. More...
 
void Save (const wxString &aFileName) const
 Write this library table to aFileName in s-expression form. More...
 

Static Public Member Functions

static bool LoadGlobalTable (FP_LIB_TABLE &aTable)
 Load the global footprint library table into aTable. More...
 
static wxString GetGlobalTableFileName ()
 
static const wxString GlobalPathEnvVariableName ()
 Return the name of the environment variable used to hold the directory of locally installed "KiCad sponsored" system footprint libraries. More...
 
static STRING_UTF8_MAPParseOptions (const std::string &aOptionsList)
 Parses aOptionsList and places the result into a #PROPERTIES object which is returned. More...
 
static UTF8 FormatOptions (const STRING_UTF8_MAP *aProperties)
 Returns a list of options from the aProperties parameter. More...
 

Protected Types

typedef std::map< wxString, int > INDEX
 this is a non-owning index into the LIB_TABLE_ROWS table More...
 
typedef INDEX::iterator INDEX_ITER
 
typedef INDEX::const_iterator INDEX_CITER
 
typedef INDEX::value_type INDEX_VALUE
 

Protected Member Functions

LIB_TABLE_ROWfindRow (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, else NULL. More...
 
void reindex ()
 
void ensureIndex ()
 

Protected Attributes

LIB_TABLE_ROWS rows
 
INDEX nickIndex
 this particular key is the nickName within each row. More...
 
LIB_TABLEfallBack
 
std::mutex m_nickIndexMutex
 Mutex to protect access to the nickIndex variable. More...
 

Friends

class FP_LIB_TABLE_GRID
 

Detailed Description

Definition at line 96 of file fp_lib_table.h.

Member Typedef Documentation

◆ INDEX

typedef std::map<wxString,int> LIB_TABLE::INDEX
protectedinherited

this is a non-owning index into the LIB_TABLE_ROWS table

Definition at line 561 of file lib_table_base.h.

◆ INDEX_CITER

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protectedinherited

Definition at line 563 of file lib_table_base.h.

◆ INDEX_ITER

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protectedinherited

Definition at line 562 of file lib_table_base.h.

◆ INDEX_VALUE

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protectedinherited

Definition at line 564 of file lib_table_base.h.

Member Enumeration Documentation

◆ SAVE_T

The set of return values from FootprintSave() below.

Enumerator
SAVE_OK 
SAVE_SKIPPED 

Definition at line 198 of file fp_lib_table.h.

199 {
200 SAVE_OK,
202 };

Constructor & Destructor Documentation

◆ FP_LIB_TABLE()

FP_LIB_TABLE::FP_LIB_TABLE ( FP_LIB_TABLE aFallBackTable = nullptr)

Build a footprint library table by pre-pending this table fragment in front of aFallBackTable.

Loading of this table fragment is done by using Parse().

Parameters
aFallBackTableis another FP_LIB_TABLE which is searched only when a row is not found in this table. No ownership is taken of aFallBackTable.

Definition at line 67 of file fp_lib_table.cpp.

67 :
68 LIB_TABLE( aFallBackTable )
69{
70 // not copying fall back, simply search aFallBackTable separately
71 // if "nickName not found".
72}
LIB_TABLE(LIB_TABLE *aFallBackTable=nullptr)
Build a library table by pre-pending this table fragment in front of aFallBackTable.

Member Function Documentation

◆ At() [1/2]

LIB_TABLE_ROW & LIB_TABLE::At ( unsigned  aIndex)
inlineinherited

Get the 'n'th LIB_TABLE_ROW object.

Parameters
aIndexindex of row (must exist: from 0 to GetCount() - 1)
Returns
reference to the row

Definition at line 386 of file lib_table_base.h.

387 {
388 return rows[aIndex];
389 }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Referenced by LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), SYMBOL_GRID_TRICKS::paste_text(), FP_GRID_TRICKS::paste_text(), and PCB::IFACE::SaveFileAs().

◆ At() [2/2]

const LIB_TABLE_ROW & LIB_TABLE::At ( unsigned  aIndex) const
inlineinherited

Get the 'n'th LIB_TABLE_ROW object.

Parameters
aIndexindex of row (must exist: from 0 to GetCount() - 1)
Returns
reference to the row

Definition at line 394 of file lib_table_base.h.

395 {
396 return rows[aIndex];
397 }

References LIB_TABLE::rows.

◆ Clear()

void LIB_TABLE::Clear ( )
inlineinherited

Delete all rows.

Definition at line 341 of file lib_table_base.h.

342 {
343 std::lock_guard<std::mutex> lock( m_nickIndexMutex );
344
345 rows.clear();
346 nickIndex.clear();
347 }
std::mutex m_nickIndexMutex
Mutex to protect access to the nickIndex variable.
INDEX nickIndex
this particular key is the nickName within each row.

References LIB_TABLE::m_nickIndexMutex, LIB_TABLE::nickIndex, and LIB_TABLE::rows.

Referenced by PANEL_SYM_LIB_TABLE::TransferDataFromWindow(), and PANEL_FP_LIB_TABLE::TransferDataFromWindow().

◆ ensureIndex()

void LIB_TABLE::ensureIndex ( )
inlineprotectedinherited

Definition at line 544 of file lib_table_base.h.

545 {
546 // The dialog lib table editor may not maintain the nickIndex.
547 // Lazy indexing may be required. To handle lazy indexing, we must enforce
548 // that "nickIndex" is either empty or accurate, but never inaccurate.
549 if( !nickIndex.size() )
550 reindex();
551 }
void reindex()

References LIB_TABLE::nickIndex, and LIB_TABLE::reindex().

Referenced by LIB_TABLE::findRow(), LIB_TABLE::FindRowByURI(), and LIB_TABLE::InsertRow().

◆ FindRow()

const FP_LIB_TABLE_ROW * FP_LIB_TABLE::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 fragment.

If aCheckIfEnabled is true, the library will be ignored even if it is disabled. Otherwise, the row found will be returned even if entry is disabled.

The PLUGIN is loaded and attached to the "plugin" field of the FP_LIB_TABLE_ROW if not already loaded.

Parameters
aNickNameis the name of library nickname to find.
aCheckIfEnabledis the flag to check if the library found is enabled.
Returns
the library NickName if found.
Exceptions
IO_ERRORif aNickName cannot be found.

Definition at line 293 of file fp_lib_table.cpp.

294{
295 // Do not optimize this code. Is done this way specifically to fix a runtime
296 // error with clang 4.0.1.
297 LIB_TABLE_ROW* ltrow = findRow( aNickname, aCheckIfEnabled );
298 FP_LIB_TABLE_ROW* row = dynamic_cast< FP_LIB_TABLE_ROW* >( ltrow );
299
300 if( !row )
301 {
302 wxString msg = wxString::Format( _( "fp-lib-table files contain no library named '%s'." ),
303 aNickname );
304
305 THROW_IO_ERROR( msg );
306 }
307
308 // We've been 'lazy' up until now, but it cannot be deferred any longer,
309 // instantiate a PLUGIN of the proper kind if it is not already in this
310 // FP_LIB_TABLE_ROW.
311 if( !row->plugin )
312 row->setPlugin( IO_MGR::PluginFind( row->type ) );
313
314 return row;
315}
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
Definition: fp_lib_table.h:41
void setPlugin(PLUGIN *aPlugin)
Definition: fp_lib_table.h:84
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:91
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
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,...
#define _(s)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References _, LIB_TABLE::findRow(), Format(), FP_LIB_TABLE_ROW::plugin, IO_MGR::PluginFind(), FP_LIB_TABLE_ROW::setPlugin(), THROW_IO_ERROR, and FP_LIB_TABLE_ROW::type.

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), EXPORTER_STEP::composePCB(), FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), FOOTPRINT_EDIT_FRAME::DuplicateFootprint(), EXPORTER_PCB_VRML::ExportVrmlFootprint(), FootprintDelete(), FootprintEnumerate(), FootprintExists(), FootprintLibCreate(), FootprintLibDelete(), FootprintLoad(), FootprintSave(), GenerateTimestamp(), GetEnumeratedFootprint(), FP_TREE_SYNCHRONIZING_ADAPTER::GetValue(), idf_export_footprint(), IsFootprintLibWritable(), RENDER_3D_RAYTRACE::load3DModels(), RENDER_3D_OPENGL::load3dModels(), LoadGlobalTable(), PrefetchLib(), DRC_TEST_PROVIDER_LIBRARY_PARITY::Run(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), FOOTPRINT_VIEWER_FRAME::UpdateTitle(), and PANEL_FP_PROPERTIES_3D_MODEL::validateModelExists().

◆ findRow()

LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname,
bool  aCheckIfEnabled = false 
) const
protectedinherited

Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment, else NULL.

Parameters
aNicknameis the name of the library table entry to find.
aCheckIfEnabledis a flag to check if the library table entry is enabled.
Returns
a pointer to the LIB_TABLE_ROW found.

Definition at line 196 of file lib_table_base.cpp.

197{
198 LIB_TABLE_ROW* row = nullptr;
199 LIB_TABLE* cur = (LIB_TABLE*) this;
200
201 do
202 {
203 cur->ensureIndex();
204
205 for( const std::pair<const wxString, int>& entry : cur->nickIndex )
206 {
207 if( entry.first == aNickName )
208 {
209 row = &cur->rows[entry.second];
210
211 if( !aCheckIfEnabled || row->GetIsEnabled() )
212 return row;
213 }
214 }
215
216 // Repeat, this time looking for names that were "fixed" by legacy versions because
217 // the old eeschema file format didn't support spaces in tokens.
218 for( const std::pair<const wxString, int>& entry : cur->nickIndex )
219 {
220 wxString legacyLibName = entry.first;
221 legacyLibName.Replace( " ", "_" );
222
223 if( legacyLibName == aNickName )
224 {
225 row = &cur->rows[entry.second];
226
227 if( !aCheckIfEnabled || row->GetIsEnabled() )
228 return row;
229 }
230 }
231
232 // not found, search fall back table(s), if any
233 } while( ( cur = cur->fallBack ) != nullptr );
234
235 return nullptr; // not found
236}
bool GetIsEnabled() const
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
LIB_TABLE * fallBack
void ensureIndex()

References LIB_TABLE::ensureIndex(), LIB_TABLE::fallBack, LIB_TABLE_ROW::GetIsEnabled(), LIB_TABLE::nickIndex, and LIB_TABLE::rows.

Referenced by SYMBOL_LIB_TABLE::FindRow(), FindRow(), LIB_TABLE::GetDescription(), LIB_TABLE::GetFullURI(), and LIB_TABLE::HasLibrary().

◆ FindRowByURI()

const LIB_TABLE_ROW * LIB_TABLE::FindRowByURI ( const wxString &  aURI)
inherited
Returns
a LIB_TABLE_ROW pointer if aURI is found in this table or in any chained fallBack table fragments, else NULL.

Definition at line 239 of file lib_table_base.cpp.

240{
241 LIB_TABLE* cur = this;
242
243 do
244 {
245 cur->ensureIndex();
246
247 for( unsigned i = 0; i < cur->rows.size(); i++ )
248 {
249 wxString tmp = cur->rows[i].GetFullURI( true );
250
251 if( tmp.Find( "://" ) != wxNOT_FOUND )
252 {
253 if( tmp == aURI )
254 return &cur->rows[i]; // found as URI
255 }
256 else
257 {
258 wxFileName fn = aURI;
259
260 // This will also test if the file is a symlink so if we are comparing
261 // a symlink to the same real file, the comparison will be true. See
262 // wxFileName::SameAs() in the wxWidgets source.
263 if( fn == wxFileName( tmp ) )
264 return &cur->rows[i]; // found as full path and file name
265 }
266 }
267
268 // not found, search fall back table(s), if any
269 } while( ( cur = cur->fallBack ) != nullptr );
270
271 return nullptr; // not found
272}

References LIB_TABLE::ensureIndex(), LIB_TABLE::fallBack, and LIB_TABLE::rows.

Referenced by PCB_EDIT_FRAME::ExportFootprintsToLibrary(), SYMBOL_EDIT_FRAME::KiwayMailIn(), and FOOTPRINT_EDIT_FRAME::KiwayMailIn().

◆ FootprintDelete()

void FP_LIB_TABLE::FootprintDelete ( const wxString &  aNickname,
const wxString &  aFootprintName 
)

Delete the aFootprintName from the library given by aNickname.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW.
aFootprintNameis the name of a footprint to delete from the specified library.
Exceptions
IO_ERRORif there is a problem finding the footprint or the library, or deleting it.

Definition at line 412 of file fp_lib_table.cpp.

413{
414 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
415 wxASSERT( (PLUGIN*) row->plugin );
416 return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName,
417 row->GetProperties() );
418}
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...
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...
const STRING_UTF8_MAP * GetProperties() const
Return the constant #PROPERTIES for this library (LIB_TABLE_ROW).
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:270
virtual void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete aFootprintName from the library at aLibraryPath.
Definition: plugin.cpp:114

References FindRow(), PLUGIN::FootprintDelete(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

Referenced by FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), and FOOTPRINT_EDITOR_CONTROL::RenameFootprint().

◆ FootprintEnumerate()

void FP_LIB_TABLE::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aNickname,
bool  aBestEfforts 
)

Return a list of footprint names contained within the library given by aNickname.

Parameters
aFootprintNamesis the list to fill with the footprint names found in aNickname
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW.
aBestEffortsif true, don't throw on errors.
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Definition at line 275 of file fp_lib_table.cpp.

277{
278 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
279 wxASSERT( (PLUGIN*) row->plugin );
280 row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts,
281 row->GetProperties() );
282}
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.
Definition: plugin.cpp:67

References FindRow(), PLUGIN::FootprintEnumerate(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

Referenced by GetFootprints(), guessNickname(), and FOOTPRINT_LIST_IMPL::loadFootprints().

◆ FootprintExists()

bool FP_LIB_TABLE::FootprintExists ( const wxString &  aNickname,
const wxString &  aFootprintName 
)

Indicates whether or not the given footprint already exists in the given library.

Definition at line 353 of file fp_lib_table.cpp.

354{
355 try
356 {
357 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
358 wxASSERT( (PLUGIN*) row->plugin );
359
360 return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName,
361 row->GetProperties() );
362 }
363 catch( ... )
364 {
365 return false;
366 }
367}
virtual bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
Check for the existence of a footprint.
Definition: plugin.cpp:89

References FindRow(), PLUGIN::FootprintExists(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

Referenced by FOOTPRINT_EDIT_FRAME::DuplicateFootprint(), DISPLAY_FOOTPRINTS_FRAME::GetFootprint(), FOOTPRINT_EDITOR_CONTROL::PasteFootprint(), FOOTPRINT_EDITOR_CONTROL::RenameFootprint(), and FOOTPRINT_EDIT_FRAME::SaveFootprintAs().

◆ FootprintLibCreate()

void FP_LIB_TABLE::FootprintLibCreate ( const wxString &  aNickname)

Definition at line 437 of file fp_lib_table.cpp.

438{
439 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
440 wxASSERT( (PLUGIN*) row->plugin );
441 row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() );
442}
virtual void FootprintLibCreate(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty footprint library at aLibraryPath empty.
Definition: plugin.cpp:122

References FindRow(), PLUGIN::FootprintLibCreate(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

◆ FootprintLibDelete()

void FP_LIB_TABLE::FootprintLibDelete ( const wxString &  aNickname)

Definition at line 429 of file fp_lib_table.cpp.

430{
431 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
432 wxASSERT( (PLUGIN*) row->plugin );
433 row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() );
434}
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,...
Definition: plugin.cpp:129

References FindRow(), PLUGIN::FootprintLibDelete(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

◆ FootprintLoad()

FOOTPRINT * FP_LIB_TABLE::FootprintLoad ( const wxString &  aNickname,
const wxString &  aFootprintName,
bool  aKeepUUID = false 
)

Load a footprint having aFootprintName from the library given by aNickname.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW.
aFootprintNameis the name of the footprint to load.
aKeepUUID= true to keep initial items UUID, false to set new UUID normally true if loaded in the footprint editor, false if loaded in the board editor. Used only in kicad_plugin
Returns
the footprint if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.

Definition at line 370 of file fp_lib_table.cpp.

372{
373 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
374 wxASSERT( (PLUGIN*) row->plugin );
375
376 FOOTPRINT* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName,
377 aKeepUUID, row->GetProperties() );
378
379 setLibNickname( ret, row->GetNickName(), aFootprintName );
380
381 return ret;
382}
const wxString & GetNickName() const
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...
Definition: plugin.cpp:97
static void setLibNickname(FOOTPRINT *aModule, const wxString &aNickname, const wxString &aFootprintName)

References FindRow(), PLUGIN::FootprintLoad(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetProperties(), FP_LIB_TABLE_ROW::plugin, and setLibNickname().

Referenced by FootprintLoadWithOptionalNickname(), DRC_TEST_PROVIDER_LIBRARY_PARITY::Run(), and FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint().

◆ FootprintLoadWithOptionalNickname()

FOOTPRINT * FP_LIB_TABLE::FootprintLoadWithOptionalNickname ( const LIB_ID aFootprintId,
bool  aKeepUUID = false 
)

Load a footprint having aFootprintId with possibly an empty nickname.

Parameters
aFootprintIdthe [nickname] and footprint name of the footprint to load.
aKeepUUID= true to keep initial items UUID, false to set new UUID normally true if loaded in the footprint editor, false if loaded in the board editor used only in kicad_plugin
Returns
the FOOTPRINT if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.
PARSE_ERRORif aFootprintId is not parsed OK.

Definition at line 445 of file fp_lib_table.cpp.

447{
448 wxString nickname = aFootprintId.GetLibNickname();
449 wxString fpname = aFootprintId.GetLibItemName();
450
451 if( nickname.size() )
452 {
453 return FootprintLoad( nickname, fpname, aKeepUUID );
454 }
455
456 // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
457 else
458 {
459 std::vector<wxString> nicks = GetLogicalLibs();
460
461 // Search each library going through libraries alphabetically.
462 for( unsigned i = 0; i < nicks.size(); ++i )
463 {
464 // FootprintLoad() returns NULL on not found, does not throw exception
465 // unless there's an IO_ERROR.
466 FOOTPRINT* ret = FootprintLoad( nicks[i], fpname, aKeepUUID );
467
468 if( ret )
469 return ret;
470 }
471
472 return nullptr;
473 }
474}
FOOTPRINT * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName, bool aKeepUUID=false)
Load a footprint having aFootprintName from the library given by aNickname.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:101
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

References FootprintLoad(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), and LIB_TABLE::GetLogicalLibs().

Referenced by PCB_BASE_FRAME::loadFootprint().

◆ FootprintSave()

FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave ( const wxString &  aNickname,
const FOOTPRINT aFootprint,
bool  aOverwrite = true 
)

Write aFootprint to an existing library given by aNickname.

If a footprint by the same name already exists, it is replaced.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW.
aFootprintis what to store in the library. The caller continues to own the footprint after this call.
aOverwritewhen true means overwrite any existing footprint by the same name, else if false means skip the write and return SAVE_SKIPPED.
Returns
SAVE_OK or SAVE_SKIPPED. If error saving, then IO_ERROR is thrown.
Exceptions
IO_ERRORif there is a problem saving.

Definition at line 385 of file fp_lib_table.cpp.

387{
388 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
389 wxASSERT( (PLUGIN*) row->plugin );
390
391 if( !aOverwrite )
392 {
393 // Try loading the footprint to see if it already exists, caller wants overwrite
394 // protection, which is atypical, not the default.
395
396 wxString fpname = aFootprint->GetFPID().GetLibItemName();
397
398 std::unique_ptr<FOOTPRINT> footprint( row->plugin->FootprintLoad( row->GetFullURI( true ),
399 fpname,
400 row->GetProperties() ) );
401
402 if( footprint.get() )
403 return SAVE_SKIPPED;
404 }
405
406 row->plugin->FootprintSave( row->GetFullURI( true ), aFootprint, row->GetProperties() );
407
408 return SAVE_OK;
409}
const LIB_ID & GetFPID() const
Definition: footprint.h:203
virtual void FootprintSave(const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const STRING_UTF8_MAP *aProperties=nullptr)
Write aFootprint to an existing library located at aLibraryPath.
Definition: plugin.cpp:106

References FindRow(), PLUGIN::FootprintLoad(), PLUGIN::FootprintSave(), FOOTPRINT::GetFPID(), LIB_TABLE_ROW::GetFullURI(), LIB_ID::GetLibItemName(), LIB_TABLE_ROW::GetProperties(), FP_LIB_TABLE_ROW::plugin, SAVE_OK, and SAVE_SKIPPED.

Referenced by PCB_EDIT_FRAME::ExportFootprintsToLibrary(), and FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary().

◆ Format()

void FP_LIB_TABLE::Format ( OUTPUTFORMATTER aOutput,
int  aIndentLevel 
) const
overridevirtual

Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.

Parameters
aOutputis the OUTPUTFORMATTER to format the table into.
aIndentLevelis the indentation level (2 spaces) to indent.
Exceptions
IO_ERRORif an I/O error occurs during output.
boost::interprocess::lock_exceptif separate process attempt to access the table.

Implements LIB_TABLE.

Definition at line 236 of file fp_lib_table.cpp.

237{
238 aOutput->Print( aIndentLevel, "(fp_lib_table\n" );
239
240 for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
241 it->Format( aOutput, aIndentLevel+1 );
242
243 aOutput->Print( aIndentLevel, ")\n" );
244}
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER

References OUTPUTFORMATTER::Print(), and LIB_TABLE::rows.

◆ FormatOptions()

UTF8 LIB_TABLE::FormatOptions ( const STRING_UTF8_MAP aProperties)
staticinherited

Returns a list of options from the aProperties parameter.

The name=value pairs will be separated with the '|' character. The =value portion may not be present. You might expect something like "name1=value1|name2=value2|flag_me". Notice that flag_me does not have a value. This is ok.

Parameters
aPropertiesis the PROPERTIES to format or NULL. If NULL the returned string will be empty.

Definition at line 423 of file lib_table_base.cpp.

424{
425 UTF8 ret;
426
427 if( aProperties )
428 {
429 for( STRING_UTF8_MAP::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
430 {
431 const std::string& name = it->first;
432
433 const UTF8& value = it->second;
434
435 if( ret.size() )
436 ret += OPT_SEP;
437
438 ret += name;
439
440 // the separation between name and value is '='
441 if( value.size() )
442 {
443 ret += '=';
444
445 for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
446 {
447 // escape any separator in the value.
448 if( *si == OPT_SEP )
449 ret += '\\';
450
451 ret += *si;
452 }
453 }
454 }
455 }
456
457 return ret;
458}
const char * name
Definition: DXF_plotter.cpp:56
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:71
std::string::const_iterator begin() const
Definition: utf8.h:192
std::string::size_type size() const
Definition: utf8.h:110
std::string::const_iterator end() const
Definition: utf8.h:193
#define OPT_SEP
options separator character

References UTF8::begin(), UTF8::end(), name, OPT_SEP, and UTF8::size().

Referenced by DIALOG_FP_PLUGIN_OPTIONS::TransferDataFromWindow().

◆ GenerateTimestamp()

long long FP_LIB_TABLE::GenerateTimestamp ( const wxString *  aNickname)

Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname, or all libraries if aNickname is NULL.

Definition at line 247 of file fp_lib_table.cpp.

248{
249 long long hash = 0;
250
251 if( aNickname )
252 {
253 const FP_LIB_TABLE_ROW* row = FindRow( *aNickname, true );
254
255 wxCHECK( row && row->plugin, hash );
256
257 return row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) +
258 wxHashTable::MakeKey( *aNickname );
259 }
260
261 for( const wxString& nickname : GetLogicalLibs() )
262 {
263 const FP_LIB_TABLE_ROW* row = FindRow( nickname, true );
264
265 wxCHECK2( row && row->plugin, continue );
266
267 hash += row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) +
268 wxHashTable::MakeKey( nickname );
269 }
270
271 return hash;
272}
virtual long long GetLibraryTimestamp(const wxString &aLibraryPath) const =0
Generate a timestamp representing all the files in the library (including the library directory).

References FindRow(), LIB_TABLE_ROW::GetFullURI(), PLUGIN::GetLibraryTimestamp(), LIB_TABLE::GetLogicalLibs(), and FP_LIB_TABLE_ROW::plugin.

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

◆ GetCount()

unsigned LIB_TABLE::GetCount ( ) const
inlineinherited

◆ GetDescription()

const wxString LIB_TABLE::GetDescription ( const wxString &  aNickname)
inherited
Returns
the library description from aNickname, or an empty string if aNickname does not exist.

Definition at line 148 of file lib_table_base.cpp.

149{
150 // Use "no exception" form of find row and ignore disabled flag.
151 const LIB_TABLE_ROW* row = findRow( aNickname );
152
153 if( row )
154 return row->GetDescr();
155 else
156 return wxEmptyString;
157}
const wxString & GetDescr() const
Return the description of the library referenced by this row.

References LIB_TABLE::findRow(), and LIB_TABLE_ROW::GetDescr().

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), FOOTPRINT_EDIT_FRAME::buildSaveAsDialog(), SYMBOL_EDIT_FRAME::buildSaveAsDialog(), and PCB_BASE_FRAME::SelectLibrary().

◆ GetEnumeratedFootprint()

const FOOTPRINT * FP_LIB_TABLE::GetEnumeratedFootprint ( const wxString &  aNickname,
const wxString &  aFootprintName 
)

A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

The return value is const to allow it to return a reference to a cached item.

Definition at line 342 of file fp_lib_table.cpp.

344{
345 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
346 wxASSERT( (PLUGIN*) row->plugin );
347
348 return row->plugin->GetEnumeratedFootprint( row->GetFullURI( true ), aFootprintName,
349 row->GetProperties() );
350}
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.
Definition: plugin.cpp:80

References FindRow(), PLUGIN::GetEnumeratedFootprint(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

Referenced by FOOTPRINT_PREVIEW_PANEL::DisplayFootprint(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), DISPLAY_FOOTPRINTS_FRAME::GetFootprint(), and FOOTPRINT_INFO_IMPL::load().

◆ GetFullURI()

wxString LIB_TABLE::GetFullURI ( const wxString &  aLibNickname,
bool  aExpandEnvVars = true 
) const
inherited

Return the full URI of the library mapped to aLibNickname.

Definition at line 183 of file lib_table_base.cpp.

184{
185 const LIB_TABLE_ROW* row = findRow( aNickname, true );
186
187 wxString retv;
188
189 if( row )
190 retv = row->GetFullURI( aExpandEnvVars );
191
192 return retv;
193}

References LIB_TABLE::findRow(), and LIB_TABLE_ROW::GetFullURI().

Referenced by CVPCB_MAINFRAME::DisplayStatus(), SCH_EDIT_FRAME::LoadSheetFromFile(), NETLIST_EXPORTER_XML::makeLibraries(), and FOOTPRINT_EDITOR_CONTROL::SaveAs().

◆ GetGlobalTableFileName()

wxString FP_LIB_TABLE::GetGlobalTableFileName ( )
static
Returns
the platform specific global footprint library path and file name.

Definition at line 627 of file fp_lib_table.cpp.

628{
629 wxFileName fn;
630
632 fn.SetName( global_tbl_name );
633
634 return fn.GetFullPath();
635}
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
static const wxChar global_tbl_name[]

References SETTINGS_MANAGER::GetUserSettingsPath(), and global_tbl_name.

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::GetGlobalTableFileName(), InvokePcbLibTableEditor(), LoadGlobalTable(), PCB::IFACE::OnKifaceStart(), and DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ GetLogicalLibs()

std::vector< wxString > LIB_TABLE::GetLogicalLibs ( )
inherited

Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

Definition at line 275 of file lib_table_base.cpp.

276{
277 // Only return unique logical library names. Use std::set::insert() to quietly reject any
278 // duplicates (usually due to encountering a duplicate nickname in a fallback table).
279
280 std::set<wxString> unique;
281 std::vector<wxString> ret;
282 const LIB_TABLE* cur = this;
283
284 do
285 {
286 for( LIB_TABLE_ROWS_CITER it = cur->rows.begin(); it!=cur->rows.end(); ++it )
287 {
288 if( it->GetIsEnabled() )
289 unique.insert( it->GetNickName() );
290 }
291
292 } while( ( cur = cur->fallBack ) != nullptr );
293
294 ret.reserve( unique.size() );
295
296 // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
297 for( std::set< wxString >::const_iterator it = unique.begin(); it!=unique.end(); ++it )
298 ret.push_back( *it );
299
300 // We want to allow case-sensitive duplicates but sort by case-insensitive ordering
301 std::sort( ret.begin(), ret.end(),
302 []( const wxString& lhs, const wxString& rhs )
303 {
304 return StrNumCmp( lhs, rhs, true /* ignore case */ ) < 0;
305 } );
306
307 return ret;
308}

References LIB_TABLE::fallBack, and LIB_TABLE::rows.

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), CVPCB_MAINFRAME::BuildLibrariesListBox(), FOOTPRINT_EDIT_FRAME::buildSaveAsDialog(), SYMBOL_EDIT_FRAME::buildSaveAsDialog(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), FootprintLoadWithOptionalNickname(), GenerateTimestamp(), GetFootprintLibraries(), SYMBOL_LIBRARY_MANAGER::GetLibraryCount(), SYMBOL_LIB_TABLE::GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), FOOTPRINT_VIEWER_FRAME::OnActivate(), SYMBOL_VIEWER_FRAME::OnSelectSymbol(), SCH_BASE_FRAME::PickSymbolFromLibTree(), FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), PCB_BASE_FRAME::SelectLibrary(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ GlobalPathEnvVariableName()

const wxString FP_LIB_TABLE::GlobalPathEnvVariableName ( )
static

Return the name of the environment variable used to hold the directory of locally installed "KiCad sponsored" system footprint libraries.

These can be either legacy or pretty format. The only thing special about this particular environment variable is that it is set automatically by KiCad on program start up, if it is not set already in the environment.

Definition at line 477 of file fp_lib_table.cpp.

478{
479 return "KICAD6_FOOTPRINT_DIR";
480}

Referenced by DIALOG_CONFIG_EQUFILES::Init(), and PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable().

◆ HasLibrary()

◆ HasLibraryWithPath()

bool LIB_TABLE::HasLibraryWithPath ( const wxString &  aPath) const
inherited

Test for the existence of aPath in the library table.

Parameters
aCheckEnabledif true will only return true for enabled libraries
Returns
true if a library aNickname exists in the table.

Definition at line 171 of file lib_table_base.cpp.

172{
173 for( const LIB_TABLE_ROW& row : rows )
174 {
175 if( row.GetFullURI() == aPath )
176 return true;
177 }
178
179 return false;
180}

References LIB_TABLE::rows.

Referenced by PCM_FP_LIB_TRAVERSER::OnDir(), and PCM_SYM_LIB_TRAVERSER::OnFile().

◆ InsertRow()

bool LIB_TABLE::InsertRow ( LIB_TABLE_ROW aRow,
bool  doReplace = false 
)
inherited

Adds aRow if it does not already exist or if doReplace is true.

If doReplace is not true and the key for aRow already exists, the function fails and returns false.

The key for the table is the nickName, and all in this table must be unique.

Parameters
aRowis the new row to insert, or to forcibly add if doReplace is true.
doReplaceif true, means insert regardless of whether aRow's key already exists. If false, then fail if the key already exists.
Returns
bool - true if the operation succeeded.

Definition at line 311 of file lib_table_base.cpp.

312{
313 ensureIndex();
314
315 std::lock_guard<std::mutex> lock( m_nickIndexMutex );
316
317 INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
318
319 aRow->SetParent( this );
320
321 if( it == nickIndex.end() )
322 {
323 rows.push_back( aRow );
324 nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
325 return true;
326 }
327
328 if( doReplace )
329 {
330 rows.replace( it->second, aRow );
331 return true;
332 }
333
334 return false;
335}
void SetParent(LIB_TABLE *aParent)
INDEX::value_type INDEX_VALUE
INDEX::const_iterator INDEX_CITER

References LIB_TABLE::ensureIndex(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE::m_nickIndexMutex, LIB_TABLE::nickIndex, LIB_TABLE::rows, and LIB_TABLE_ROW::SetParent().

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary(), PCB_BASE_EDIT_FRAME::AddLibrary(), SYMBOL_EDIT_FRAME::addLibTableEntry(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), LIB_TABLE_TEST_FIXTURE::LIB_TABLE_TEST_FIXTURE(), SCH_ALTIUM_PLUGIN::Load(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), SCH_EAGLE_PLUGIN::Load(), PCM_FP_LIB_TRAVERSER::OnDir(), PCM_SYM_LIB_TRAVERSER::OnFile(), PCB_EDIT_FRAME::OpenProjectFiles(), SYMBOL_LIB_TABLE::Parse(), and Parse().

◆ IsEmpty()

bool LIB_TABLE::IsEmpty ( bool  aIncludeFallback = true)
inherited

Return true if the table is empty.

Parameters
aIncludeFallbackis used to determine if the fallback table should be included in the test.
Returns
true if the footprint library table is empty.

Definition at line 139 of file lib_table_base.cpp.

140{
141 if( !aIncludeFallback || !fallBack )
142 return rows.empty();
143
144 return rows.empty() && fallBack->IsEmpty( true );
145}
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.

References LIB_TABLE::fallBack, LIB_TABLE::IsEmpty(), and LIB_TABLE::rows.

Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), LIB_TABLE::IsEmpty(), and SCH_EDIT_FRAME::LoadSheetFromFile().

◆ IsFootprintLibWritable()

bool FP_LIB_TABLE::IsFootprintLibWritable ( const wxString &  aNickname)

Return true if the library given by aNickname is writable.

Often system libraries are read only because of where they are installed.

Exceptions
IO_ERRORif no library at aLibraryPath exists.

Definition at line 421 of file fp_lib_table.cpp.

422{
423 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
424 wxASSERT( (PLUGIN*) row->plugin );
425 return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) );
426}
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: plugin.cpp:137

References FindRow(), LIB_TABLE_ROW::GetFullURI(), PLUGIN::IsFootprintLibWritable(), and FP_LIB_TABLE_ROW::plugin.

Referenced by FOOTPRINT_EDIT_FRAME::UpdateTitle().

◆ Load()

void LIB_TABLE::Load ( const wxString &  aFileName)
inherited

Load the library table using the path defined by aFileName aFallBackTable.

Parameters
aFileNamecontains the full path to the s-expression file.
Exceptions
IO_ERRORif an error occurs attempting to load the footprint library table.

Definition at line 338 of file lib_table_base.cpp.

339{
340 // It's OK if footprint library tables are missing.
341 if( wxFileName::IsFileReadable( aFileName ) )
342 {
343 FILE_LINE_READER reader( aFileName );
344 LIB_TABLE_LEXER lexer( &reader );
345
346 Parse( &lexer );
347 }
348}
A LINE_READER that reads from an open file.
Definition: richio.h:173
virtual void Parse(LIB_TABLE_LEXER *aLexer)=0
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...

References LIB_TABLE::Parse().

Referenced by LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), SCH_EDIT_FRAME::LoadSheetFromFile(), PROJECT::PcbFootprintLibs(), PCB::IFACE::SaveFileAs(), DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow(), and DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ LoadGlobalTable()

bool FP_LIB_TABLE::LoadGlobalTable ( FP_LIB_TABLE aTable)
static

Load the global footprint library table into aTable.

This probably should be move into the application object when KiCad is changed to a single process application. This is the least painful solution for the time being.

Parameters
aTablethe FP_LIB_TABLE object to load.
Returns
true if the global library table exists and is loaded properly.
Exceptions
IO_ERRORif an error occurs attempting to load the footprint library table.

Definition at line 544 of file fp_lib_table.cpp.

545{
546 bool tableExists = true;
547 wxFileName fn = GetGlobalTableFileName();
548
549 if( !fn.FileExists() )
550 {
551 tableExists = false;
552
553 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
554 {
555 THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
556 fn.GetPath() ) );
557 }
558
559 // Attempt to copy the default global file table from the KiCad
560 // template folder to the user's home configuration path.
561 SEARCH_STACK ss;
562
563 SystemDirsAppend( &ss );
564
565 wxString templatePath =
566 Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_TEMPLATE_DIR" ) ).GetValue();
567
568 if( !templatePath.IsEmpty() )
569 ss.AddPaths( templatePath, 0 );
570
571 wxString fileName = ss.FindValidPath( global_tbl_name );
572
573 // The fallback is to create an empty global footprint table for the user to populate.
574 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
575 {
576 FP_LIB_TABLE emptyTable;
577
578 emptyTable.Save( fn.GetFullPath() );
579 }
580 }
581
582 aTable.Load( fn.GetFullPath() );
583
584 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
586
587 wxString packagesPath = Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_3RD_PARTY" ) ).GetValue();
588
589 if( settings->m_PcmLibAutoAdd )
590 {
591 // Scan for libraries in PCM packages directory
592
593 wxFileName d( packagesPath, "" );
594 d.AppendDir( "footprints" );
595
596 if( d.DirExists() )
597 {
598 PCM_FP_LIB_TRAVERSER traverser( packagesPath, aTable, settings->m_PcmLibPrefix );
599 wxDir dir( d.GetPath() );
600
601 dir.Traverse( traverser );
602 }
603 }
604
605 if( settings->m_PcmLibAutoRemove )
606 {
607 // Remove PCM libraries that no longer exist
608 std::vector<wxString> to_remove;
609
610 for( size_t i = 0; i < aTable.GetCount(); i++ )
611 {
612 LIB_TABLE_ROW& row = aTable.At( i );
613 wxString path = row.GetFullURI( true );
614
615 if( path.StartsWith( packagesPath ) && !wxDir::Exists( path ) )
616 to_remove.push_back( row.GetNickName() );
617 }
618
619 for( const wxString& nickName : to_remove )
620 aTable.RemoveRow( aTable.FindRow( nickName ) );
621 }
622
623 return tableExists;
624}
static wxString GetGlobalTableFileName()
wxString m_PcmLibPrefix
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
bool RemoveRow(const LIB_TABLE_ROW *aRow)
Removes a row from the table.
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.
Look for files in a number of paths.
Definition: search_stack.h:42
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Append system places to aSearchStack in a platform specific way and pertinent to KiCad programs.

References _, SEARCH_STACK::AddPaths(), LIB_TABLE::At(), FindRow(), Format(), SETTINGS_MANAGER::GetAppSettings(), LIB_TABLE::GetCount(), LIB_TABLE_ROW::GetFullURI(), GetGlobalTableFileName(), LIB_TABLE_ROW::GetNickName(), global_tbl_name, LIB_TABLE::Load(), KICAD_SETTINGS::m_PcmLibAutoAdd, KICAD_SETTINGS::m_PcmLibAutoRemove, KICAD_SETTINGS::m_PcmLibPrefix, path, Pgm(), LIB_TABLE::RemoveRow(), LIB_TABLE::Save(), SystemDirsAppend(), and THROW_IO_ERROR.

Referenced by CV::IFACE::OnKifaceStart(), PCB::IFACE::OnKifaceStart(), and DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ operator!=() [1/2]

bool FP_LIB_TABLE::operator!= ( const FP_LIB_TABLE r) const
inline

Definition at line 117 of file fp_lib_table.h.

117{ return !( *this == r ); }
E_SERIE r
Definition: eserie.cpp:41

References r.

◆ operator!=() [2/2]

bool LIB_TABLE::operator!= ( const LIB_TABLE r) const
inlineinherited

Definition at line 371 of file lib_table_base.h.

371{ return !( *this == r ); }

References r.

◆ operator==() [1/2]

bool FP_LIB_TABLE::operator== ( const FP_LIB_TABLE aFpTable) const

Definition at line 219 of file fp_lib_table.cpp.

220{
221 if( rows.size() == aFpTable.rows.size() )
222 {
223 for( unsigned i = 0; i < rows.size(); ++i )
224 {
225 if( (FP_LIB_TABLE_ROW&)rows[i] != (FP_LIB_TABLE_ROW&)aFpTable.rows[i] )
226 return false;
227 }
228
229 return true;
230 }
231
232 return false;
233}

References LIB_TABLE::rows.

◆ operator==() [2/2]

bool LIB_TABLE::operator== ( const LIB_TABLE r) const
inlineinherited

Compares this table against another.

This compares the row contents against each other. Any fallback tables are not checked.

Definition at line 355 of file lib_table_base.h.

356 {
357 if( rows.size() == r.rows.size() )
358 {
359 unsigned i;
360
361 for( i = 0; i < rows.size() && rows[i] == r.rows[i]; ++i )
362 ;
363
364 if( i == rows.size() )
365 return true;
366 }
367
368 return false;
369 }

References r, and LIB_TABLE::rows.

◆ Parse()

void FP_LIB_TABLE::Parse ( LIB_TABLE_LEXER *  aLexer)
overridevirtual

Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objects.

Parameters
aLexeris the lexer to parse.
Exceptions
IO_ERRORif an I/O error occurs during parsing.
PARSER_ERRORif the lexer format to parse is invalid.
boost::bad_pointerif an any attempt to add an invalid pointer to the boost::ptr_vector.
boost::bad_indexif an index outside the row table bounds is accessed.

Implements LIB_TABLE.

Definition at line 75 of file fp_lib_table.cpp.

76{
77 T tok;
78 wxString errMsg; // to collect error messages
79
80 // This table may be nested within a larger s-expression, or not.
81 // Allow for parser of that optional containing s-epression to have looked ahead.
82 if( in->CurTok() != T_fp_lib_table )
83 {
84 in->NeedLEFT();
85
86 if( ( tok = in->NextTok() ) != T_fp_lib_table )
87 in->Expecting( T_fp_lib_table );
88 }
89
90 while( ( tok = in->NextTok() ) != T_RIGHT )
91 {
92 std::unique_ptr<FP_LIB_TABLE_ROW> row = std::make_unique<FP_LIB_TABLE_ROW>();
93
94 if( tok == T_EOF )
95 in->Expecting( T_RIGHT );
96
97 if( tok != T_LEFT )
98 in->Expecting( T_LEFT );
99
100 // in case there is a "row integrity" error, tell where later.
101 int lineNum = in->CurLineNumber();
102
103 if( ( tok = in->NextTok() ) != T_lib )
104 in->Expecting( T_lib );
105
106 // (name NICKNAME)
107 in->NeedLEFT();
108
109 if( ( tok = in->NextTok() ) != T_name )
110 in->Expecting( T_name );
111
112 in->NeedSYMBOLorNUMBER();
113
114 row->SetNickName( in->FromUTF8() );
115
116 in->NeedRIGHT();
117
118 // After (name), remaining (lib) elements are order independent, and in
119 // some cases optional.
120 bool sawType = false;
121 bool sawOpts = false;
122 bool sawDesc = false;
123 bool sawUri = false;
124 bool sawDisabled = false;
125
126 while( ( tok = in->NextTok() ) != T_RIGHT )
127 {
128 if( tok == T_EOF )
129 in->Unexpected( T_EOF );
130
131 if( tok != T_LEFT )
132 in->Expecting( T_LEFT );
133
134 tok = in->NeedSYMBOLorNUMBER();
135
136 switch( tok )
137 {
138 case T_uri:
139 if( sawUri )
140 in->Duplicate( tok );
141 sawUri = true;
142 in->NeedSYMBOLorNUMBER();
143 row->SetFullURI( in->FromUTF8() );
144 break;
145
146 case T_type:
147 if( sawType )
148 in->Duplicate( tok );
149 sawType = true;
150 in->NeedSYMBOLorNUMBER();
151 row->SetType( in->FromUTF8() );
152 break;
153
154 case T_options:
155 if( sawOpts )
156 in->Duplicate( tok );
157 sawOpts = true;
158 in->NeedSYMBOLorNUMBER();
159 row->SetOptions( in->FromUTF8() );
160 break;
161
162 case T_descr:
163 if( sawDesc )
164 in->Duplicate( tok );
165 sawDesc = true;
166 in->NeedSYMBOLorNUMBER();
167 row->SetDescr( in->FromUTF8() );
168 break;
169
170 case T_disabled:
171 if( sawDisabled )
172 in->Duplicate( tok );
173 sawDisabled = true;
174 row->SetEnabled( false );
175 break;
176
177 default:
178 in->Unexpected( tok );
179 }
180
181 in->NeedRIGHT();
182 }
183
184 if( !sawType )
185 in->Expecting( T_type );
186
187 if( !sawUri )
188 in->Expecting( T_uri );
189
190 // all nickNames within this table fragment must be unique, so we do not
191 // use doReplace in InsertRow(). (However a fallBack table can have a
192 // conflicting nickName and ours will supercede that one since in
193 // FindLib() we search this table before any fall back.)
194 wxString nickname = row->GetNickName(); // store it to be able to used it
195 // after row deletion if an error occurs
196 LIB_TABLE_ROW* tmp = row.release();
197
198 if( !InsertRow( tmp ) )
199 {
200 delete tmp; // The table did not take ownership of the row.
201
202 wxString msg = wxString::Format( _( "Duplicate library nickname '%s' found in "
203 "footprint library table file line %d." ),
204 nickname,
205 lineNum );
206
207 if( !errMsg.IsEmpty() )
208 errMsg << '\n';
209
210 errMsg << msg;
211 }
212 }
213
214 if( !errMsg.IsEmpty() )
215 THROW_IO_ERROR( errMsg );
216}
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.

References _, Format(), LIB_TABLE::InsertRow(), and THROW_IO_ERROR.

Referenced by FP_GRID_TRICKS::paste_text().

◆ ParseOptions()

STRING_UTF8_MAP * LIB_TABLE::ParseOptions ( const std::string &  aOptionsList)
staticinherited

Parses aOptionsList and places the result into a #PROPERTIES object which is returned.

If the options field is empty, then the returned PROPERTIES will be a NULL pointer.

Typically aOptionsList comes from the "options" field within a LIB_TABLE_ROW and the format is simply a comma separated list of name value pairs. e.g.: [name1[=value1][|name2[=value2]]] etc. When using the UI to create or edit a library table, this formatting is handled for you.

Definition at line 358 of file lib_table_base.cpp.

359{
360 if( aOptionsList.size() )
361 {
362 const char* cp = &aOptionsList[0];
363 const char* end = cp + aOptionsList.size();
364
365 STRING_UTF8_MAP props;
366 std::string pair;
367
368 // Parse all name=value pairs
369 while( cp < end )
370 {
371 pair.clear();
372
373 // Skip leading white space.
374 while( cp < end && isspace( *cp ) )
375 ++cp;
376
377 // Find the end of pair/field
378 while( cp < end )
379 {
380 if( *cp == '\\' && cp + 1 < end && cp[1] == OPT_SEP )
381 {
382 ++cp; // skip the escape
383 pair += *cp++; // add the separator
384 }
385 else if( *cp == OPT_SEP )
386 {
387 ++cp; // skip the separator
388 break; // process the pair
389 }
390 else
391 {
392 pair += *cp++;
393 }
394 }
395
396 // stash the pair
397 if( pair.size() )
398 {
399 // first equals sign separates 'name' and 'value'.
400 size_t eqNdx = pair.find( '=' );
401
402 if( eqNdx != pair.npos )
403 {
404 std::string name = pair.substr( 0, eqNdx );
405 std::string value = pair.substr( eqNdx + 1 );
406 props[name] = value;
407 }
408 else
409 {
410 props[pair] = ""; // property is present, but with no value.
411 }
412 }
413 }
414
415 if( props.size() )
416 return new STRING_UTF8_MAP( props );
417 }
418
419 return nullptr;
420}
A name/value tuple with unique names and optional values.

References name, and OPT_SEP.

Referenced by LIB_TABLE_ROW::SetOptions(), and DIALOG_FP_PLUGIN_OPTIONS::TransferDataToWindow().

◆ PrefetchLib()

void FP_LIB_TABLE::PrefetchLib ( const wxString &  aNickname)

If possible, prefetches the specified library (e.g.

performing downloads). Does not parse. Threadsafe.

This is a no-op for libraries that cannot be prefetched.

Parameters
aNicknameis a locator for the library; it is a name in LIB_TABLE_ROW.
Exceptions
IO_ERRORif there is an error prefetching the library.

Definition at line 285 of file fp_lib_table.cpp.

286{
287 const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
288 wxASSERT( (PLUGIN*) row->plugin );
289 row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() );
290}
virtual void PrefetchLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
If possible, prefetches the specified library (e.g.
Definition: plugin.cpp:75

References FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), FP_LIB_TABLE_ROW::plugin, and PLUGIN::PrefetchLib().

Referenced by FOOTPRINT_LIST_IMPL::loadLibs().

◆ reindex()

void LIB_TABLE::reindex ( )
inlineprotectedinherited

Definition at line 534 of file lib_table_base.h.

535 {
536 std::lock_guard<std::mutex> lock( m_nickIndexMutex );
537
538 nickIndex.clear();
539
540 for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
541 nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
542 }
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER

References LIB_TABLE::m_nickIndexMutex, LIB_TABLE::nickIndex, and LIB_TABLE::rows.

Referenced by LIB_TABLE::ensureIndex(), PANEL_SYM_LIB_TABLE::TransferDataFromWindow(), and PANEL_FP_LIB_TABLE::TransferDataFromWindow().

◆ RemoveRow()

bool LIB_TABLE::RemoveRow ( const LIB_TABLE_ROW aRow)
inlineinherited

Removes a row from the table.

Parameters
aRowis the row to remove
Returns
true if the row was found (and removed)

Definition at line 461 of file lib_table_base.h.

462 {
463 for( auto iter = rows.begin(); iter != rows.end(); ++iter )
464 {
465 if( *iter == *aRow )
466 {
467 rows.erase( iter, iter + 1 );
468 return true;
469 }
470 }
471 return false;
472 }

References LIB_TABLE::rows.

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary(), LoadGlobalTable(), and SYMBOL_LIB_TABLE::LoadGlobalTable().

◆ Save()

void LIB_TABLE::Save ( const wxString &  aFileName) const
inherited

Write this library table to aFileName in s-expression form.

Parameters
aFileNameis the name of the file to write to.

Definition at line 351 of file lib_table_base.cpp.

352{
353 FILE_OUTPUTFORMATTER sf( aFileName );
354 Format( &sf, 0 );
355}
Used for text file output.
Definition: richio.h:457
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.

References LIB_TABLE::Format().

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), SYMBOL_EDIT_FRAME::addLibTableEntry(), InvokePcbLibTableEditor(), InvokeSchEditSymbolLibTable(), LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), PCB_EDIT_FRAME::OpenProjectFiles(), SYMBOL_EDIT_FRAME::replaceLibTableEntry(), PCB::IFACE::SaveFileAs(), SCH_BASE_FRAME::saveSymbolLibTables(), DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow(), and DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ Type()

KICAD_T FP_LIB_TABLE::Type ( )
inlineoverridevirtual

Implements PROJECT::_ELEM.

Definition at line 99 of file fp_lib_table.h.

99{ return FP_LIB_TABLE_T; }
@ FP_LIB_TABLE_T
Definition: typeinfo.h:236

References FP_LIB_TABLE_T.

Referenced by PROJECT::PcbFootprintLibs().

Friends And Related Function Documentation

◆ FP_LIB_TABLE_GRID

friend class FP_LIB_TABLE_GRID
friend

Definition at line 291 of file fp_lib_table.h.

Member Data Documentation

◆ fallBack

LIB_TABLE* LIB_TABLE::fallBack
protectedinherited

◆ m_nickIndexMutex

std::mutex LIB_TABLE::m_nickIndexMutex
mutableprotectedinherited

Mutex to protect access to the nickIndex variable.

Definition at line 572 of file lib_table_base.h.

Referenced by LIB_TABLE::Clear(), LIB_TABLE::InsertRow(), and LIB_TABLE::reindex().

◆ nickIndex

INDEX LIB_TABLE::nickIndex
protectedinherited

this particular key is the nickName within each row.

Definition at line 567 of file lib_table_base.h.

Referenced by LIB_TABLE::Clear(), LIB_TABLE::ensureIndex(), LIB_TABLE::findRow(), LIB_TABLE::InsertRow(), and LIB_TABLE::reindex().

◆ rows


The documentation for this class was generated from the following files: