KiCad PCB EDA Suite
SYMBOL_LIB_TABLE Class Reference

#include <symbol_lib_table.h>

Inheritance diagram for SYMBOL_LIB_TABLE:
LIB_TABLE PROJECT::_ELEM SYMBOL_LIB_TABLE_GRID

Public Types

enum  SAVE_T { SAVE_OK , SAVE_SKIPPED }
 The set of return values from SaveSymbol() 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...
 
 SYMBOL_LIB_TABLE (SYMBOL_LIB_TABLE *aFallBackTable=nullptr)
 Build a symbol library table by pre-pending this table fragment in front of aFallBackTable. More...
 
SYMBOL_LIB_TABLE_ROWFindRow (const wxString &aNickName, bool aCheckIfEnabled=false)
 Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table fragment. More...
 
int GetModifyHash ()
 
void EnumerateSymbolLib (const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
 Return a list of symbol alias names contained within the library given by aNickname. More...
 
void LoadSymbolLib (std::vector< LIB_SYMBOL * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
 
LIB_SYMBOLLoadSymbol (const wxString &aNickname, const wxString &aName)
 Load a LIB_SYMBOL having aName from the library given by aNickname. More...
 
LIB_SYMBOLLoadSymbol (const LIB_ID &aLibId)
 
SAVE_T SaveSymbol (const wxString &aNickname, const LIB_SYMBOL *aSymbol, bool aOverwrite=true)
 Write aSymbol to an existing library given by aNickname. More...
 
void DeleteSymbol (const wxString &aNickname, const wxString &aSymbolName)
 Deletes the aSymbolName from the library given by aNickname. More...
 
bool IsSymbolLibWritable (const wxString &aNickname)
 Return true if the library given by aNickname is writable. More...
 
bool IsSymbolLibLoaded (const wxString &aNickname)
 Return true if the library given by aNickname was successfully loaded. More...
 
void DeleteSymbolLib (const wxString &aNickname)
 
void CreateSymbolLib (const wxString &aNickname)
 
LIB_SYMBOLLoadSymbolWithOptionalNickname (const LIB_ID &aId)
 Load a LIB_SYMBOL having aFootprintId with possibly an empty library 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 (SYMBOL_LIB_TABLE &aTable)
 Load the global symbol library table into aTable. More...
 
static wxString GetGlobalTableFileName ()
 Fetch the global symbol library table file name. More...
 
static const wxString GlobalPathEnvVariableName ()
 Return the name of the environment variable used to hold the directory of locally installed "KiCad sponsored" system symbol libraries. More...
 
static SYMBOL_LIB_TABLEGetGlobalLibTable ()
 
static const wxString & GetSymbolLibTableFileName ()
 
static PROPERTIESParseOptions (const std::string &aOptionsList)
 Parses aOptionsList and places the result into a PROPERTIES object which is returned. More...
 
static UTF8 FormatOptions (const PROPERTIES *aProperties)
 Returns a list of options from the aProperties parameter. More...
 

Static Public Attributes

static const char * PropPowerSymsOnly = "pwr_sym_only"
 
static const char * PropNonPowerSymsOnly = "non_pwr_sym_only"
 

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...
 

Static Private Attributes

static int m_modifyHash = 1
 helper for GetModifyHash() More...
 

Friends

class SYMBOL_LIB_TABLE_GRID
 
class PANEL_SYM_LIB_TABLE
 

Detailed Description

Definition at line 131 of file symbol_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 SaveSymbol() below.

Enumerator
SAVE_OK 
SAVE_SKIPPED 

Definition at line 204 of file symbol_lib_table.h.

Constructor & Destructor Documentation

◆ SYMBOL_LIB_TABLE()

SYMBOL_LIB_TABLE::SYMBOL_LIB_TABLE ( SYMBOL_LIB_TABLE aFallBackTable = nullptr)

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

Definition at line 102 of file symbol_lib_table.cpp.

102 :
103 LIB_TABLE( aFallBackTable )
104{
105 // not copying fall back, simply search aFallBackTable separately
106 // if "nickName not found".
107}
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 FP_LIB_TABLE::LoadGlobalTable(), 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().

◆ CreateSymbolLib()

void SYMBOL_LIB_TABLE::CreateSymbolLib ( const wxString &  aNickname)

Definition at line 479 of file symbol_lib_table.cpp.

480{
481 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
482 wxCHECK( row && row->plugin, /* void */ );
483 row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() );
484}
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
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...
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:110
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...

References SCH_PLUGIN::CreateSymbolLib(), FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and SYMBOL_LIB_TABLE_ROW::plugin.

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary().

◆ DeleteSymbol()

void SYMBOL_LIB_TABLE::DeleteSymbol ( const wxString &  aNickname,
const wxString &  aSymbolName 
)

Deletes the aSymbolName from the library given by aNickname.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW.
aSymbolNameis the name of a symbol 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 448 of file symbol_lib_table.cpp.

449{
450 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
451 wxCHECK( row && row->plugin, /* void */ );
452 return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName, row->GetProperties() );
453}
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:102

References SCH_PLUGIN::DeleteSymbol(), FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and SYMBOL_LIB_TABLE_ROW::plugin.

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer().

◆ DeleteSymbolLib()

void SYMBOL_LIB_TABLE::DeleteSymbolLib ( const wxString &  aNickname)

Definition at line 471 of file symbol_lib_table.cpp.

472{
473 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
474 wxCHECK( row && row->plugin, /* void */ );
475 row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() );
476}
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
Delete an existing symbol library and returns true if successful, or if library does not exist return...
Definition: sch_plugin.cpp:117

References SCH_PLUGIN::DeleteSymbolLib(), FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and SYMBOL_LIB_TABLE_ROW::plugin.

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

◆ EnumerateSymbolLib()

void SYMBOL_LIB_TABLE::EnumerateSymbolLib ( const wxString &  aNickname,
wxArrayString &  aAliasNames,
bool  aPowerSymbolsOnly = false 
)

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

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW.
aAliasNamesis a reference to an array for the alias names.
aPowerSymbolsOnlyis a flag to enumerate only power symbols.
Exceptions
IO_ERRORif the library cannot be found or loaded.

Definition at line 305 of file symbol_lib_table.cpp.

307{
308 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
309 wxCHECK( row && row->plugin, /* void */ );
310
311 wxString options = row->GetOptions();
312
313 if( aPowerSymbolsOnly )
314 row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
315
316 row->SetLoaded( false );
317 row->plugin->EnumerateSymbolLib( aAliasNames, row->GetFullURI( true ), row->GetProperties() );
318 row->SetLoaded( true );
319
320 if( aPowerSymbolsOnly )
321 row->SetOptions( options );
322}
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
void SetLoaded(bool aLoaded)
Mark the row as being a loaded library.
void SetOptions(const wxString &aOptions)
Change the library options strings.
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:67
static const char * PropPowerSymsOnly

References SCH_PLUGIN::EnumerateSymbolLib(), FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetOptions(), LIB_TABLE_ROW::GetProperties(), SYMBOL_LIB_TABLE_ROW::plugin, PropPowerSymsOnly, LIB_TABLE_ROW::SetLoaded(), and LIB_TABLE_ROW::SetOptions().

Referenced by SYMBOL_LIBRARY_MANAGER::getOriginalSymbols().

◆ FindRow()

SYMBOL_LIB_TABLE_ROW * SYMBOL_LIB_TABLE::FindRow ( const wxString &  aNickName,
bool  aCheckIfEnabled = false 
)

Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table fragment.

The SCH_PLUGIN is loaded and attached to the "plugin" fieldf the SYMBOL_LIB_TABLE_ROW if not already loaded.

Parameters
aNickNameis the name of the row to find.
aCheckIfEnabledis a flag to verify if the table entry is enabled or disabled.
Returns
the row found or NULL if aNickName was not found.

Definition at line 325 of file symbol_lib_table.cpp.

326{
328 dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname, aCheckIfEnabled ) );
329
330 if( !row )
331 return nullptr;
332
333 // We've been 'lazy' up until now, but it cannot be deferred any longer,
334 // instantiate a PLUGIN of the proper kind if it is not already in this
335 // SYMBOL_LIB_TABLE_ROW.
336 if( !row->plugin )
337 {
338 row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) );
339 row->plugin->SetLibTable( this );
340 }
341
342 return row;
343}
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,...
virtual void SetLibTable(SYMBOL_LIB_TABLE *aTable)
Some library plugins need to have access to their parent library table.
Definition: sch_io_mgr.h:515
void setPlugin(SCH_PLUGIN *aPlugin)

References LIB_TABLE::findRow(), SYMBOL_LIB_TABLE_ROW::plugin, SCH_PLUGIN::SetLibTable(), SYMBOL_LIB_TABLE_ROW::setPlugin(), and SYMBOL_LIB_TABLE_ROW::type.

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), CreateSymbolLib(), DeleteSymbol(), DeleteSymbolLib(), EnumerateSymbolLib(), SYMBOL_LIBRARY_MANAGER::GetLibrary(), GetModifyHash(), IsSymbolLibLoaded(), IsSymbolLibWritable(), LoadGlobalTable(), SCH_EDIT_FRAME::LoadSheetFromFile(), LoadSymbol(), LoadSymbolLib(), SCH_BASE_FRAME::PickSymbolFromLibTree(), SYMBOL_EDIT_FRAME::replaceLibTableEntry(), SaveSymbol(), and ERC_TESTER::TestLibSymbolIssues().

◆ 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}
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
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 FindRow(), FP_LIB_TABLE::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().

◆ Format()

void SYMBOL_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 268 of file symbol_lib_table.cpp.

269{
270 aOutput->Print( aIndentLevel, "(sym_lib_table\n" );
271
272 for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
273 {
274 it->Format( aOutput, aIndentLevel+1 );
275 }
276
277 aOutput->Print( aIndentLevel, ")\n" );
278}
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.

Referenced by DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), SCH_ALTIUM_PLUGIN::Load(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), and SCH_EAGLE_PLUGIN::Load().

◆ FormatOptions()

UTF8 LIB_TABLE::FormatOptions ( const PROPERTIES 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( PROPERTIES::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().

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

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

◆ GetGlobalLibTable()

◆ GetGlobalTableFileName()

wxString SYMBOL_LIB_TABLE::GetGlobalTableFileName ( )
static

Fetch the global symbol library table file name.

Returns
the platform specific global symbol library path and file name.

Definition at line 667 of file symbol_lib_table.cpp.

668{
669 wxFileName fn;
670
672 fn.SetName( global_tbl_name );
673
674 return fn.GetFullPath();
675}
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
static const wxString global_tbl_name("sym-lib-table")

References SETTINGS_MANAGER::GetUserSettingsPath(), and global_tbl_name().

Referenced by SYMBOL_EDIT_FRAME::addLibTableEntry(), DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::GetGlobalTableFileName(), InvokeSchEditSymbolLibTable(), LoadGlobalTable(), SCH::IFACE::OnKifaceStart(), SYMBOL_EDIT_FRAME::replaceLibTableEntry(), SCH_BASE_FRAME::saveSymbolLibTables(), and DIALOG_GLOBAL_SYM_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(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FP_LIB_TABLE::GenerateTimestamp(), GetFootprintLibraries(), SYMBOL_LIBRARY_MANAGER::GetLibraryCount(), GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), 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().

◆ GetModifyHash()

int SYMBOL_LIB_TABLE::GetModifyHash ( )

Definition at line 281 of file symbol_lib_table.cpp.

282{
283 int hash = 0;
284 std::vector< wxString > libNames = GetLogicalLibs();
285
286 for( const auto& libName : libNames )
287 {
288 const SYMBOL_LIB_TABLE_ROW* row = FindRow( libName, true );
289
290 if( !row || !row->plugin )
291 {
292 wxFAIL;
293 continue;
294 }
295
296 hash += row->plugin->GetModifyHash();
297 }
298
299 hash += m_modifyHash;
300
301 return hash;
302}
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
virtual int GetModifyHash() const =0
Return the modification hash from the library cache.
static int m_modifyHash
helper for GetModifyHash()

References FindRow(), LIB_TABLE::GetLogicalLibs(), SCH_PLUGIN::GetModifyHash(), m_modifyHash, and SYMBOL_LIB_TABLE_ROW::plugin.

Referenced by SYMBOL_LIBRARY_MANAGER::GetHash(), and LIB_SYMBOL_LIBRARY_MANAGER::Sync().

◆ GetSymbolLibTableFileName()

◆ GlobalPathEnvVariableName()

const wxString SYMBOL_LIB_TABLE::GlobalPathEnvVariableName ( )
static

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

These can be either legacy or sweet 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 517 of file symbol_lib_table.cpp.

518{
519 return "KICAD6_SYMBOL_DIR";
520}

Referenced by PANEL_SYM_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)
const wxString & GetNickName() const
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(), Parse(), and FP_LIB_TABLE::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().

◆ IsSymbolLibLoaded()

bool SYMBOL_LIB_TABLE::IsSymbolLibLoaded ( const wxString &  aNickname)

Return true if the library given by aNickname was successfully loaded.

Parameters
aNicknameis the library nickname in the symbol library table.
Exceptions
IO_ERRORif no library at aNickname exists.

Definition at line 463 of file symbol_lib_table.cpp.

464{
465 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
466 wxCHECK( row, false );
467 return row->GetIsLoaded();
468}
bool GetIsLoaded() const

References FindRow(), and LIB_TABLE_ROW::GetIsLoaded().

Referenced by SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded().

◆ IsSymbolLibWritable()

bool SYMBOL_LIB_TABLE::IsSymbolLibWritable ( const wxString &  aNickname)

Return true if the library given by aNickname is writable.

It is possible that some symbols libraries are read only because of where they are installed.

Parameters
aNicknameis the library nickname in the symbol library table.
Exceptions
IO_ERRORif no library at aNickname exists.

Definition at line 456 of file symbol_lib_table.cpp.

457{
458 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
459 wxCHECK( row && row->plugin, false );
460 return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) );
461}
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:125

References FindRow(), LIB_TABLE_ROW::GetFullURI(), SCH_PLUGIN::IsSymbolLibWritable(), and SYMBOL_LIB_TABLE_ROW::plugin.

Referenced by SYMBOL_LIBRARY_MANAGER::IsLibraryReadOnly().

◆ 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 FP_LIB_TABLE::LoadGlobalTable(), 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 SYMBOL_LIB_TABLE::LoadGlobalTable ( SYMBOL_LIB_TABLE aTable)
static

Load the global symbol 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 SYMBOL_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 symbol library table.

Definition at line 585 of file symbol_lib_table.cpp.

586{
587 bool tableExists = true;
588 wxFileName fn = GetGlobalTableFileName();
589
590 if( !fn.FileExists() )
591 {
592 tableExists = false;
593
594 if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
595 {
596 THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
597 fn.GetPath() ) );
598 }
599
600 // Attempt to copy the default global file table from the KiCad
601 // template folder to the user's home configuration path.
602 SEARCH_STACK ss;
603
604 SystemDirsAppend( &ss );
605
606 wxString templatePath =
607 Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_TEMPLATE_DIR" ) ).GetValue();
608
609 if( !templatePath.IsEmpty() )
610 ss.AddPaths( templatePath, 0 );
611
612 wxString fileName = ss.FindValidPath( global_tbl_name );
613
614 // The fallback is to create an empty global symbol table for the user to populate.
615 if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
616 {
617 SYMBOL_LIB_TABLE emptyTable;
618
619 emptyTable.Save( fn.GetFullPath() );
620 }
621 }
622
623 aTable.Load( fn.GetFullPath() );
624
625 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
627
628 wxString packagesPath = Pgm().GetLocalEnvVariables().at( wxT( "KICAD6_3RD_PARTY" ) ).GetValue();
629
630 if( settings->m_PcmLibAutoAdd )
631 {
632 // Scan for libraries in PCM packages directory
633 wxFileName d( packagesPath, "" );
634 d.AppendDir( "symbols" );
635
636 if( d.DirExists() )
637 {
638 PCM_SYM_LIB_TRAVERSER traverser( packagesPath, aTable, settings->m_PcmLibPrefix );
639 wxDir dir( d.GetPath() );
640
641 dir.Traverse( traverser );
642 }
643 }
644
645 if( settings->m_PcmLibAutoRemove )
646 {
647 // Remove PCM libraries that no longer exist
648 std::vector<wxString> to_remove;
649
650 for( size_t i = 0; i < aTable.GetCount(); i++ )
651 {
652 LIB_TABLE_ROW& row = aTable.At( i );
653 wxString path = row.GetFullURI( true );
654
655 if( path.StartsWith( packagesPath ) && !wxFile::Exists( path ) )
656 to_remove.push_back( row.GetNickName() );
657 }
658
659 for( const wxString& nickName : to_remove )
660 aTable.RemoveRow( aTable.FindRow( nickName ) );
661 }
662
663 return tableExists;
664}
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,...
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
#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
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 SCH::IFACE::OnKifaceStart(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ LoadSymbol() [1/2]

LIB_SYMBOL * SYMBOL_LIB_TABLE::LoadSymbol ( const LIB_ID aLibId)
inline

Definition at line 196 of file symbol_lib_table.h.

197 {
198 return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
199 }
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
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.

References LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), and LoadSymbol().

◆ LoadSymbol() [2/2]

LIB_SYMBOL * SYMBOL_LIB_TABLE::LoadSymbol ( const wxString &  aNickname,
const wxString &  aName 
)

Load a LIB_SYMBOL having aName from the library given by aNickname.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW
aNameis the name of the LIB_SYMBOL to load.
aFlattenset to true to flatten derived parts.
Returns
the symbol alias if found or NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aNickname cannot be found.

Definition at line 380 of file symbol_lib_table.cpp.

381{
382 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
383
384 if( !row || !row->plugin )
385 return nullptr;
386
387 // If another thread is loading this library at the moment; continue
388 std::unique_lock<std::mutex> lock( row->GetMutex(), std::try_to_lock );
389
390 if( !lock.owns_lock() )
391 return nullptr;
392
393 LIB_SYMBOL* symbol = row->plugin->LoadSymbol( row->GetFullURI( true ), aSymbolName,
394 row->GetProperties() );
395
396 // The library cannot know its own name, because it might have been renamed or moved.
397 // Therefore footprints cannot know their own library nickname when residing in
398 // a symbol library.
399 // Only at this API layer can we tell the symbol about its actual library nickname.
400 if( symbol )
401 {
402 LIB_ID id = symbol->GetLibId();
403
404 id.SetLibNickname( row->GetNickName() );
405 symbol->SetLibId( id );
406 }
407
408 return symbol;
409}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:98
Define a library symbol object.
Definition: lib_symbol.h:98
LIB_ID GetLibId() const override
Definition: lib_symbol.h:139
void SetLibId(const LIB_ID &aLibId)
Definition: lib_symbol.h:140
std::mutex & GetMutex()
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const PROPERTIES *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:85

References FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_SYMBOL::GetLibId(), LIB_TABLE_ROW::GetMutex(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetProperties(), SCH_PLUGIN::LoadSymbol(), SYMBOL_LIB_TABLE_ROW::plugin, LIB_SYMBOL::SetLibId(), and LIB_ID::SetLibNickname().

Referenced by FOOTPRINT_INFO_GENERATOR::GenerateHtml(), SYMBOL_LIBRARY_MANAGER::GetAlias(), SYMBOL_LIBRARY_MANAGER::GetBufferedSymbol(), SYMBOL_LIBRARY_MANAGER::getOriginalSymbols(), SCH_EAGLE_PLUGIN::loadInstance(), LoadSymbol(), SCH_DATABASE_PLUGIN::loadSymbolFromRow(), LoadSymbolWithOptionalNickname(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer(), SchGetLibSymbol(), SYMBOL_LIBRARY_MANAGER::SymbolExists(), and SCH_SCREEN::UpdateSymbolLinks().

◆ LoadSymbolLib()

void SYMBOL_LIB_TABLE::LoadSymbolLib ( std::vector< LIB_SYMBOL * > &  aAliasList,
const wxString &  aNickname,
bool  aPowerSymbolsOnly = false 
)

Definition at line 346 of file symbol_lib_table.cpp.

348{
349 SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
350 wxCHECK( row && row->plugin, /* void */ );
351
352 std::lock_guard<std::mutex> lock( row->GetMutex() );
353
354 wxString options = row->GetOptions();
355
356 if( aPowerSymbolsOnly )
357 row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
358
359 row->SetLoaded( false );
360 row->plugin->EnumerateSymbolLib( aSymbolList, row->GetFullURI( true ), row->GetProperties() );
361 row->SetLoaded( true );
362
363 if( aPowerSymbolsOnly )
364 row->SetOptions( options );
365
366 // The library cannot know its own name, because it might have been renamed or moved.
367 // Therefore footprints cannot know their own library nickname when residing in
368 // a symbol library.
369 // Only at this API layer can we tell the symbol about its actual library nickname.
370 for( LIB_SYMBOL* symbol : aSymbolList )
371 {
372 LIB_ID id = symbol->GetLibId();
373
374 id.SetLibNickname( row->GetNickName() );
375 symbol->SetLibId( id );
376 }
377}

References SCH_PLUGIN::EnumerateSymbolLib(), FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetMutex(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetOptions(), LIB_TABLE_ROW::GetProperties(), SYMBOL_LIB_TABLE_ROW::plugin, PropPowerSymsOnly, LIB_ID::SetLibNickname(), LIB_TABLE_ROW::SetLoaded(), and LIB_TABLE_ROW::SetOptions().

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), SYMBOL_LIBRARY_MANAGER::GetAliases(), and SYMBOL_ASYNC_LOADER::worker().

◆ LoadSymbolWithOptionalNickname()

LIB_SYMBOL * SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname ( const LIB_ID aId)

Load a LIB_SYMBOL having aFootprintId with possibly an empty library nickname.

Parameters
aIdthe library nickname and name of the symbol to load.
Returns
the library symbol if found (the library owns it) or NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aId cannot be found.
PARSE_ERRORif aId is not parsed OK.

Definition at line 487 of file symbol_lib_table.cpp.

488{
489 wxString nickname = aLibId.GetLibNickname();
490 wxString name = aLibId.GetLibItemName();
491
492 if( nickname.size() )
493 {
494 return LoadSymbol( nickname, name );
495 }
496 else
497 {
498 // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
499 std::vector<wxString> nicks = GetLogicalLibs();
500
501 // Search each library going through libraries alphabetically.
502 for( unsigned i = 0; i < nicks.size(); ++i )
503 {
504 // FootprintLoad() returns NULL on not found, does not throw exception
505 // unless there's an IO_ERROR.
506 LIB_SYMBOL* ret = LoadSymbol( nicks[i], name );
507
508 if( ret )
509 return ret;
510 }
511
512 return nullptr;
513 }
514}

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

◆ operator!=()

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

Definition at line 371 of file lib_table_base.h.

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

References r.

◆ operator==()

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 SYMBOL_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 116 of file symbol_lib_table.cpp.

117{
118 T tok;
119 wxString errMsg; // to collect error messages
120
121 // This table may be nested within a larger s-expression, or not.
122 // Allow for parser of that optional containing s-epression to have looked ahead.
123 if( in->CurTok() != T_sym_lib_table )
124 {
125 in->NeedLEFT();
126
127 if( ( tok = in->NextTok() ) != T_sym_lib_table )
128 in->Expecting( T_sym_lib_table );
129 }
130
131 while( ( tok = in->NextTok() ) != T_RIGHT )
132 {
133 std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row = std::make_unique<SYMBOL_LIB_TABLE_ROW>();
134
135 if( tok == T_EOF )
136 in->Expecting( T_RIGHT );
137
138 if( tok != T_LEFT )
139 in->Expecting( T_LEFT );
140
141 // in case there is a "row integrity" error, tell where later.
142 int lineNum = in->CurLineNumber();
143
144 if( ( tok = in->NextTok() ) != T_lib )
145 in->Expecting( T_lib );
146
147 // (name NICKNAME)
148 in->NeedLEFT();
149
150 if( ( tok = in->NextTok() ) != T_name )
151 in->Expecting( T_name );
152
153 in->NeedSYMBOLorNUMBER();
154
155 row->SetNickName( in->FromUTF8() );
156
157 in->NeedRIGHT();
158
159 // After (name), remaining (lib) elements are order independent, and in
160 // some cases optional.
161 bool sawType = false;
162 bool sawOpts = false;
163 bool sawDesc = false;
164 bool sawUri = false;
165 bool sawDisabled = false;
166 bool sawHidden = false;
167
168 while( ( tok = in->NextTok() ) != T_RIGHT )
169 {
170 if( tok == T_EOF )
171 in->Unexpected( T_EOF );
172
173 if( tok != T_LEFT )
174 in->Expecting( T_LEFT );
175
176 tok = in->NeedSYMBOLorNUMBER();
177
178 switch( tok )
179 {
180 case T_uri:
181 if( sawUri )
182 in->Duplicate( tok );
183 sawUri = true;
184 in->NeedSYMBOLorNUMBER();
185 row->SetFullURI( in->FromUTF8() );
186 break;
187
188 case T_type:
189 if( sawType )
190 in->Duplicate( tok );
191 sawType = true;
192 in->NeedSYMBOLorNUMBER();
193 row->SetType( in->FromUTF8() );
194 break;
195
196 case T_options:
197 if( sawOpts )
198 in->Duplicate( tok );
199 sawOpts = true;
200 in->NeedSYMBOLorNUMBER();
201 row->SetOptions( in->FromUTF8() );
202 break;
203
204 case T_descr:
205 if( sawDesc )
206 in->Duplicate( tok );
207 sawDesc = true;
208 in->NeedSYMBOLorNUMBER();
209 row->SetDescr( in->FromUTF8() );
210 break;
211
212 case T_disabled:
213 if( sawDisabled )
214 in->Duplicate( tok );
215 sawDisabled = true;
216 row->SetEnabled( false );
217 break;
218
219 case T_hidden:
220 if( sawHidden )
221 in->Duplicate( tok );
222 sawHidden = true;
223 row->SetVisible( false );
224 break;
225
226 default:
227 in->Unexpected( tok );
228 }
229
230 in->NeedRIGHT();
231 }
232
233 if( !sawType )
234 in->Expecting( T_type );
235
236 if( !sawUri )
237 in->Expecting( T_uri );
238
239 // all nickNames within this table fragment must be unique, so we do not
240 // use doReplace in InsertRow(). (However a fallBack table can have a
241 // conflicting nickName and ours will supercede that one since in
242 // FindLib() we search this table before any fall back.)
243 wxString nickname = row->GetNickName(); // store it to be able to used it
244 // after row deletion if an error occurs
245 LIB_TABLE_ROW* tmp = row.release();
246
247 if( !InsertRow( tmp ) )
248 {
249 delete tmp; // The table did not take ownership of the row.
250
251 wxString msg = wxString::Format( _( "Duplicate library nickname '%s' found in symbol "
252 "library table file line %d" ),
253 nickname,
254 lineNum );
255
256 if( !errMsg.IsEmpty() )
257 errMsg << '\n';
258
259 errMsg << msg;
260 }
261 }
262
263 if( !errMsg.IsEmpty() )
264 THROW_IO_ERROR( errMsg );
265}
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 SYMBOL_GRID_TRICKS::paste_text().

◆ ParseOptions()

PROPERTIES * 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 PROPERTIES 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 PROPERTIES( props );
417 }
418
419 return nullptr;
420}
A name/value tuple with unique names and optional values.
Definition: properties.h:34
std::vector< PROPERTY > PROPERTIES
Definition: specctra.h:192

References name, and OPT_SEP.

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

◆ 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(), FP_LIB_TABLE::LoadGlobalTable(), and 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(), FP_LIB_TABLE::LoadGlobalTable(), 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().

◆ SaveSymbol()

SYMBOL_LIB_TABLE::SAVE_T SYMBOL_LIB_TABLE::SaveSymbol ( const wxString &  aNickname,
const LIB_SYMBOL aSymbol,
bool  aOverwrite = true 
)

Write aSymbol to an existing library given by aNickname.

If a LIB_SYMBOL by the same name already exists or there are any conflicting alias names, the new LIB_SYMBOL will silently overwrite any existing aliases and/or part because libraries cannot have duplicate alias names. It is the responsibility of the caller to check the library for conflicts before saving.

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

Definition at line 412 of file symbol_lib_table.cpp.

414{
415 const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
416 wxCHECK( row && row->plugin, SAVE_SKIPPED );
417
418 if( !row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) ) )
419 return SAVE_SKIPPED;
420
421 if( !aOverwrite )
422 {
423 // Try loading the footprint to see if it already exists, caller wants overwrite
424 // protection, which is atypical, not the default.
425
426 wxString name = aSymbol->GetLibId().GetLibItemName();
427
428 std::unique_ptr<LIB_SYMBOL> symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
429 name, row->GetProperties() ) );
430
431 if( symbol.get() )
432 return SAVE_SKIPPED;
433 }
434
435 try
436 {
437 row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
438 }
439 catch( const IO_ERROR& )
440 {
441 return SAVE_SKIPPED;
442 }
443
444 return SAVE_OK;
445}
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const PROPERTIES *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:94

References FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_SYMBOL::GetLibId(), LIB_ID::GetLibItemName(), LIB_TABLE_ROW::GetProperties(), SCH_PLUGIN::IsSymbolLibWritable(), SCH_PLUGIN::LoadSymbol(), name, SYMBOL_LIB_TABLE_ROW::plugin, SAVE_OK, SAVE_SKIPPED, and SCH_PLUGIN::SaveSymbol().

Referenced by SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer().

◆ Type()

KICAD_T SYMBOL_LIB_TABLE::Type ( )
inlineoverridevirtual

Implements PROJECT::_ELEM.

Definition at line 134 of file symbol_lib_table.h.

134{ return SYMBOL_LIB_TABLE_T; }
@ SYMBOL_LIB_TABLE_T
Definition: typeinfo.h:234

References SYMBOL_LIB_TABLE_T.

Friends And Related Function Documentation

◆ PANEL_SYM_LIB_TABLE

friend class PANEL_SYM_LIB_TABLE
friend

Definition at line 311 of file symbol_lib_table.h.

◆ SYMBOL_LIB_TABLE_GRID

friend class SYMBOL_LIB_TABLE_GRID
friend

Definition at line 310 of file symbol_lib_table.h.

Member Data Documentation

◆ fallBack

LIB_TABLE* LIB_TABLE::fallBack
protectedinherited

◆ m_modifyHash

int SYMBOL_LIB_TABLE::m_modifyHash = 1
staticprivate

helper for GetModifyHash()

Definition at line 313 of file symbol_lib_table.h.

Referenced by GetModifyHash().

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

◆ PropNonPowerSymsOnly

const char * SYMBOL_LIB_TABLE::PropNonPowerSymsOnly = "non_pwr_sym_only"
static

Definition at line 137 of file symbol_lib_table.h.

◆ PropPowerSymsOnly

const char * SYMBOL_LIB_TABLE::PropPowerSymsOnly = "pwr_sym_only"
static

◆ rows


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