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 DESIGN_BLOCK_LIB_TABLE FP_LIB_TABLE SYMBOL_LIB_TABLE DESIGN_BLOCK_LIB_TABLE_GRID 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.
 
virtual void Format (OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
 Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
 
 LIB_TABLE (LIB_TABLE *aFallBackTable=nullptr, std::unique_ptr< LIB_TABLE_IO > aTableIo=nullptr)
 Build a library table by pre-pending this table fragment in front of aFallBackTable.
 
virtual ~LIB_TABLE ()
 
bool operator== (const LIB_TABLE &r) const
 Compares this table against another.
 
bool operator!= (const LIB_TABLE &r) const
 
unsigned GetCount () const
 Get the number of rows contained in the table.
 
LIB_TABLE_ROWAt (unsigned aIndex)
 Get the 'n'th LIB_TABLE_ROW object.
 
const LIB_TABLE_ROWAt (unsigned aIndex) const
 Get the 'n'th LIB_TABLE_ROW object.
 
bool IsEmpty (bool aIncludeFallback=true)
 Return true if the table is empty.
 
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.
 
bool HasLibraryWithPath (const wxString &aPath) const
 Test for the existence of aPath in the library table.
 
std::vector< wxString > GetLogicalLibs ()
 Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
 
wxString GetFullURI (const wxString &aLibNickname, bool aExpandEnvVars=true) const
 Return the full URI of the library mapped to aLibNickname.
 
bool InsertRow (LIB_TABLE_ROW *aRow, bool doReplace=false)
 Adds aRow if it does not already exist or if doReplace is true.
 
bool RemoveRow (const LIB_TABLE_ROW *aRow)
 Removes a row from the table and frees the pointer.
 
bool ReplaceRow (size_t aIndex, LIB_TABLE_ROW *aRow)
 Replaces the Nth row with the given new row.
 
bool ChangeRowOrder (size_t aIndex, int aOffset)
 Moves a row within the table.
 
void TransferRows (LIB_TABLE_ROWS &aRowsList)
 Takes ownership of another list of rows; the original list will be freed.
 
const LIB_TABLE_ROWFindRowByURI (const wxString &aURI)
 
void Load (const wxString &aFileName)
 Load the library table using the path defined by aFileName aFallBackTable.
 
void Save (const wxString &aFileName) const
 Write this library table to aFileName in s-expression form.
 
int GetVersion () const
 Returns the version number (0 if unset)
 
virtual PROJECT::ELEM ProjectElementType ()=0
 

Static Public Member Functions

static std::map< std::string, UTF8 > * ParseOptions (const std::string &aOptionsList)
 Parses aOptionsList and places the result into a #PROPERTIES object which is returned.
 
static UTF8 FormatOptions (const std::map< std::string, UTF8 > *aProperties)
 Returns a list of options from the aProperties parameter.
 

Protected Member Functions

void clear ()
 
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.
 
bool doInsertRow (LIB_TABLE_ROW *aRow, bool doReplace=false)
 Performs the mechanics of inserting a row, but without locking or reindexing.
 
bool migrate ()
 Updates the env vars from older version of KiCad, provided they do not currently resolve to anything.
 
void reindex ()
 

Protected Attributes

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

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

Constructor & Destructor Documentation

◆ LIB_TABLE()

LIB_TABLE::LIB_TABLE ( LIB_TABLE aFallBackTable = nullptr,
std::unique_ptr< LIB_TABLE_IO aTableIo = 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.
aTableIois the I/O object to use for the table data. nullptr means use the default file-based I/O.

Definition at line 166 of file lib_table_base.cpp.

References m_io.

◆ ~LIB_TABLE()

LIB_TABLE::~LIB_TABLE ( )
virtual

Definition at line 180 of file lib_table_base.cpp.

Member Function Documentation

◆ At() [1/2]

LIB_TABLE_ROW & LIB_TABLE::At ( unsigned  aIndex)
inline

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

◆ 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 435 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()

void LIB_TABLE::clear ( )
protected

Definition at line 186 of file lib_table_base.cpp.

References m_rows, and m_rowsMap.

Referenced by Load(), DESIGN_BLOCK_LIB_TABLE::LoadGlobalTable(), and TransferRows().

◆ doInsertRow()

bool LIB_TABLE::doInsertRow ( LIB_TABLE_ROW aRow,
bool  doReplace = false 
)
protected

Performs the mechanics of inserting a row, but without locking or reindexing.

Definition at line 361 of file lib_table_base.cpp.

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

Referenced by InsertRow(), SYMBOL_LIB_TABLE::Parse(), DESIGN_BLOCK_LIB_TABLE::Parse(), and FP_LIB_TABLE::Parse().

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

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

Referenced by SYMBOL_LIB_TABLE::FindRow(), DESIGN_BLOCK_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 293 of file lib_table_base.cpp.

References m_fallBack, m_io, 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, DESIGN_BLOCK_LIB_TABLE, and FP_LIB_TABLE.

Referenced by Save().

◆ FormatOptions()

UTF8 LIB_TABLE::FormatOptions ( const std::map< std::string, UTF8 > *  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 606 of file lib_table_base.cpp.

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

Referenced by DIALOG_PLUGIN_OPTIONS::TransferDataFromWindow().

◆ GetCount()

◆ 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 202 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 585 of file lib_table_base.h.

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

References m_rows.

Referenced by PCM_DESIGN_BLOCK_LIB_TRAVERSER::OnDir(), 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 350 of file lib_table_base.cpp.

References doInsertRow(), m_mutex, and reindex().

Referenced by SCH_EDIT_FRAME::AddDesignBlockLibrary(), SYMBOL_LIBRARY_MANAGER::addLibrary(), PCB_BASE_EDIT_FRAME::AddLibrary(), SYMBOL_EDIT_FRAME::addLibTableEntry(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), SCH_IO_ALTIUM::LoadSchematicFile(), SCH_IO_CADSTAR_ARCHIVE::LoadSchematicFile(), SCH_IO_EAGLE::LoadSchematicFile(), SCH_IO_EASYEDAPRO::LoadSchematicFile(), SCH_EDIT_FRAME::LoadSheetFromFile(), PCM_DESIGN_BLOCK_LIB_TRAVERSER::OnDir(), PCM_FP_LIB_TRAVERSER::OnDir(), PCM_SYM_LIB_TRAVERSER::OnFile(), PCB_EDIT_FRAME::OpenProjectFiles(), 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 193 of file lib_table_base.cpp.

References IsEmpty(), m_fallBack, and m_rows.

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

◆ Load()

◆ 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 479 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 420 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 404 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, DESIGN_BLOCK_LIB_TABLE, and FP_LIB_TABLE.

Referenced by Load().

◆ ParseOptions()

std::map< std::string, UTF8 > * 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 541 of file lib_table_base.cpp.

References name, and OPT_SEP.

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

◆ ProjectElementType()

virtual PROJECT::ELEM PROJECT::_ELEM::ProjectElementType ( )
pure virtualinherited

◆ reindex()

void LIB_TABLE::reindex ( )
protected

Definition at line 467 of file lib_table_base.cpp.

References m_rows, and m_rowsMap.

Referenced by ChangeRowOrder(), doInsertRow(), InsertRow(), Load(), 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 383 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(), DESIGN_BLOCK_LIB_TABLE::LoadGlobalTable(), 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 420 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 456 of file lib_table_base.cpp.

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

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

Member Data Documentation

◆ m_fallBack

LIB_TABLE* LIB_TABLE::m_fallBack
protected

Definition at line 628 of file lib_table_base.h.

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

◆ m_io

std::unique_ptr<LIB_TABLE_IO> LIB_TABLE::m_io
protected

Definition at line 626 of file lib_table_base.h.

Referenced by FindRowByURI(), LIB_TABLE(), Load(), and Save().

◆ m_mutex

std::shared_mutex LIB_TABLE::m_mutex
mutableprotected

Mutex to protect access to the rows vector.

Definition at line 642 of file lib_table_base.h.

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

◆ m_rows

LIB_TABLE_ROWS LIB_TABLE::m_rows
protected

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

Referenced by clear(), doInsertRow(), findRow(), reindex(), RemoveRow(), and ReplaceRow().

◆ m_version

int LIB_TABLE::m_version
mutableprotected

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