KiCad PCB EDA Suite
Loading...
Searching...
No Matches
LIB_TABLE Class Referenceabstract

Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname. More...

#include <lib_table_base.h>

Inheritance diagram for LIB_TABLE:
PROJECT::_ELEM FP_LIB_TABLE SYMBOL_LIB_TABLE TEST_LIB_TABLE FP_LIB_TABLE_GRID SYMBOL_LIB_TABLE_GRID

Public Member Functions

virtual void Parse (LIB_TABLE_LEXER *aLexer)=0
 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 =0
 Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel. More...
 
 LIB_TABLE (LIB_TABLE *aFallBackTable=nullptr)
 Build a library table by pre-pending this table fragment in front of aFallBackTable. More...
 
virtual ~LIB_TABLE ()
 
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 and frees the pointer. More...
 
bool ReplaceRow (size_t aIndex, LIB_TABLE_ROW *aRow)
 Replaces the Nth row with the given new row. More...
 
bool ChangeRowOrder (size_t aIndex, int aOffset)
 Moves a row within the table. More...
 
void TransferRows (LIB_TABLE_ROWS &aRowsList)
 Takes ownership of another list of rows; the original list will be freed. 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...
 
int GetVersion () const
 Returns the version number (0 if unset) More...
 
virtual KICAD_T Type ()=0
 

Static Public Member Functions

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 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...
 
bool migrate ()
 Updates the env vars from older version of KiCad, provided they do not currently resolve to anything. More...
 
void reindex ()
 

Protected Attributes

LIB_TABLEm_fallBack
 
int m_version
 Versioning to handle importing old tables. More...
 
LIB_TABLE_ROWS m_rows
 Owning set of rows. More...
 
std::map< wxString, LIB_TABLE_ROWS_ITERm_rowsMap
 this is a non-owning index into the LIB_TABLE_ROWS table More...
 
std::shared_mutex m_mutex
 Mutex to protect access to the rows vector. More...
 

Detailed Description

Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

This class owns the library table, which is like fstab in concept and maps logical library name to the library URI, type, and options. It is heavily based on the SWEET parser work done by Dick Hollenbeck and can be seen in new/sch_lib_table.h. A library table has the following columns:

  • Logical Library Name (Nickname)
  • Library Type, used to determine which plugin to load to access the library.
  • Library URI. The full URI to the library source, form dependent on Type.
  • Options, used for as yet to be defined information such as user names or passwords

The Library Type can be one of:

  • "file"
  • "ftp"
  • "http"

For now, the Library URI types needed to support the various types can be one of those shown below, which are typical of each type:

  • "file://C:/mylibdir"
  • "ftp://kicad.org/partlib/trunk"
  • "http://kicad.org/partlib"

The library table is built up from several additive entries (table fragments), and the final table is a (conceptual) merging of the table fragments. Two anticipated sources of the entries are a personal table saved in the KiCad configuration and a project resident table that resides in project file. The project footprint table entries are considered a higher priority in the final dynamically assembled library table. An row in the project file contribution to the library table takes precedence over the personal table if there is a collision of logical library names. Otherwise, the entries simply combine without issue to make up the applicable library table.

Author
Wayne Stambaugh

Definition at line 295 of file lib_table_base.h.

Constructor & Destructor Documentation

◆ LIB_TABLE()

LIB_TABLE::LIB_TABLE ( LIB_TABLE aFallBackTable = nullptr)

Build a 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 LIB_TABLE which is searched only when a row is not found in this table. No ownership is taken of aFallBackTable.

Definition at line 116 of file lib_table_base.cpp.

◆ ~LIB_TABLE()

LIB_TABLE::~LIB_TABLE ( )
virtual

Definition at line 124 of file lib_table_base.cpp.

Member Function Documentation

◆ At() [1/2]

LIB_TABLE_ROW & LIB_TABLE::At ( unsigned  aIndex)
inline

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 376 of file lib_table_base.h.

References m_rows.

Referenced by FP_LIB_TABLE::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
inline

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 384 of file lib_table_base.h.

References m_rows.

◆ ChangeRowOrder()

bool LIB_TABLE::ChangeRowOrder ( size_t  aIndex,
int  aOffset 
)

Moves a row within the table.

Parameters
aIndexis the current index of the row to move
aOffsetis the number of positions to move it by in the table
Returns
true if the move resulted in a change

Definition at line 383 of file lib_table_base.cpp.

References m_mutex, m_rows, and reindex().

Referenced by PANEL_SYM_LIB_TABLE::moveDownHandler(), and PANEL_SYM_LIB_TABLE::moveUpHandler().

◆ Clear()

◆ findRow()

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

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 194 of file lib_table_base.cpp.

References LIB_TABLE_ROW::GetIsEnabled(), m_fallBack, m_mutex, and m_rowsMap.

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

◆ FindRowByURI()

const LIB_TABLE_ROW * LIB_TABLE::FindRowByURI ( const wxString &  aURI)
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 237 of file lib_table_base.cpp.

References m_fallBack, and m_rows.

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

◆ Format()

virtual void LIB_TABLE::Format ( OUTPUTFORMATTER aOutput,
int  aIndentLevel 
) const
pure virtual

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.

Implemented in SYMBOL_LIB_TABLE, FP_LIB_TABLE, and TEST_LIB_TABLE.

Referenced by Save().

◆ FormatOptions()

UTF8 LIB_TABLE::FormatOptions ( const STRING_UTF8_MAP aProperties)
static

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 542 of file lib_table_base.cpp.

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

Referenced by DIALOG_PLUGIN_OPTIONS::TransferDataFromWindow().

◆ GetCount()

unsigned LIB_TABLE::GetCount ( ) const
inline

◆ GetDescription()

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

Definition at line 146 of file lib_table_base.cpp.

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

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), SAVE_AS_DIALOG::SAVE_AS_DIALOG(), and PCB_BASE_FRAME::SelectLibrary().

◆ GetFullURI()

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

◆ GetLogicalLibs()

◆ GetVersion()

int LIB_TABLE::GetVersion ( ) const
inline

Returns the version number (0 if unset)

Returns
integer version number read from table

Definition at line 526 of file lib_table_base.h.

References m_version.

◆ HasLibrary()

◆ HasLibraryWithPath()

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

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 169 of file lib_table_base.cpp.

References m_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 
)

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 307 of file lib_table_base.cpp.

References LIB_TABLE_ROW::GetNickName(), m_mutex, m_rows, m_rowsMap, reindex(), 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_IO_ALTIUM::LoadSchematicFile(), SCH_IO_CADSTAR_ARCHIVE::LoadSchematicFile(), SCH_IO_EAGLE::LoadSchematicFile(), SCH_IO_EASYEDAPRO::LoadSchematicFile(), SCH_EDIT_FRAME::LoadSheetFromFile(), PCM_FP_LIB_TRAVERSER::OnDir(), PCM_SYM_LIB_TRAVERSER::OnFile(), PCB_EDIT_FRAME::OpenProjectFiles(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary().

◆ IsEmpty()

bool LIB_TABLE::IsEmpty ( bool  aIncludeFallback = true)

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 137 of file lib_table_base.cpp.

References IsEmpty(), m_fallBack, and m_rows.

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

◆ Load()

void LIB_TABLE::Load ( const wxString &  aFileName)

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 451 of file lib_table_base.cpp.

References m_version, migrate(), Parse(), and Save().

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

◆ migrate()

bool LIB_TABLE::migrate ( )
protected

Updates the env vars from older version of KiCad, provided they do not currently resolve to anything.

Returns
True if the tables were modified

Definition at line 426 of file lib_table_base.cpp.

References m_rows.

Referenced by Load().

◆ operator!=()

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

Definition at line 361 of file lib_table_base.h.

◆ operator==()

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

Compares this table against another.

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

Definition at line 345 of file lib_table_base.h.

References m_rows.

◆ Parse()

virtual void LIB_TABLE::Parse ( LIB_TABLE_LEXER *  aLexer)
pure virtual

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.

Implemented in SYMBOL_LIB_TABLE, FP_LIB_TABLE, and TEST_LIB_TABLE.

Referenced by Load().

◆ ParseOptions()

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

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 477 of file lib_table_base.cpp.

References name, and OPT_SEP.

Referenced by PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries(), PANEL_FP_LIB_TABLE::onMigrateLibraries(), LIB_TABLE_ROW::SetOptions(), and DIALOG_PLUGIN_OPTIONS::TransferDataToWindow().

◆ reindex()

void LIB_TABLE::reindex ( )
protected

Definition at line 414 of file lib_table_base.cpp.

References m_rows, and m_rowsMap.

Referenced by ChangeRowOrder(), InsertRow(), RemoveRow(), ReplaceRow(), and TransferRows().

◆ RemoveRow()

bool LIB_TABLE::RemoveRow ( const LIB_TABLE_ROW aRow)

Removes a row from the table and frees the pointer.

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

Definition at line 331 of file lib_table_base.cpp.

References LIB_TABLE_ROW::GetNickName(), m_mutex, m_rows, m_rowsMap, and reindex().

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

◆ ReplaceRow()

bool LIB_TABLE::ReplaceRow ( size_t  aIndex,
LIB_TABLE_ROW aRow 
)

Replaces the Nth row with the given new row.

Returns
true if successful

Definition at line 368 of file lib_table_base.cpp.

References m_mutex, m_rows, m_rowsMap, and reindex().

Referenced by SYMBOL_GRID_TRICKS::paste_text().

◆ Save()

◆ TransferRows()

void LIB_TABLE::TransferRows ( LIB_TABLE_ROWS aRowsList)

Takes ownership of another list of rows; the original list will be freed.

Definition at line 404 of file lib_table_base.cpp.

References m_mutex, m_rows, and reindex().

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

◆ Type()

virtual KICAD_T PROJECT::_ELEM::Type ( )
pure virtualinherited

Member Data Documentation

◆ m_fallBack

LIB_TABLE* LIB_TABLE::m_fallBack
protected

Definition at line 553 of file lib_table_base.h.

Referenced by findRow(), FindRowByURI(), GetLogicalLibs(), and IsEmpty().

◆ m_mutex

std::shared_mutex LIB_TABLE::m_mutex
mutableprotected

Mutex to protect access to the rows vector.

Definition at line 567 of file lib_table_base.h.

Referenced by ChangeRowOrder(), findRow(), InsertRow(), RemoveRow(), ReplaceRow(), and TransferRows().

◆ m_rows

◆ m_rowsMap

std::map<wxString, LIB_TABLE_ROWS_ITER> LIB_TABLE::m_rowsMap
protected

this is a non-owning index into the LIB_TABLE_ROWS table

Definition at line 564 of file lib_table_base.h.

Referenced by Clear(), findRow(), InsertRow(), reindex(), RemoveRow(), and ReplaceRow().

◆ m_version

int LIB_TABLE::m_version
mutableprotected

Versioning to handle importing old tables.

Definition at line 556 of file lib_table_base.h.

Referenced by SYMBOL_LIB_TABLE::Format(), FP_LIB_TABLE::Format(), GetVersion(), Load(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and Save().


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