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 indention level of aIndentLevel. More...
 
 SYMBOL_LIB_TABLE (SYMBOL_LIB_TABLE *aFallBackTable=NULL)
 Build a symbol library table by pre-pending this table fragment in front of aFallBackTable. More...
 
SYMBOL_LIB_TABLE_ROWFindRow (const wxString &aNickName)
 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_PART * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
 
LIB_PARTLoadSymbol (const wxString &aNickname, const wxString &aName)
 Load a LIB_PART having aName from the library given by aNickname. More...
 
LIB_PARTLoadSymbol (const LIB_ID &aLibId)
 
SAVE_T SaveSymbol (const wxString &aNickname, const LIB_PART *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_PARTLoadSymbolWithOptionalNickname (const LIB_ID &aId)
 Load a LIB_PART 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...
 
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 (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) const
 Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment, else NULL. More...
 
LIB_TABLE_ROWfindRow (const wxString &aNickname)
 
void reindex ()
 
void ensureIndex ()
 

Protected Attributes

LIB_TABLE_ROWS rows
 
INDEX nickIndex
 this particular key is the nickName within each row. More...
 
LIB_TABLEfallBack
 

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

◆ INDEX_CITER

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protectedinherited

Definition at line 527 of file lib_table_base.h.

◆ INDEX_ITER

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protectedinherited

Definition at line 526 of file lib_table_base.h.

◆ INDEX_VALUE

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protectedinherited

Definition at line 528 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 193 of file symbol_lib_table.h.

Constructor & Destructor Documentation

◆ SYMBOL_LIB_TABLE()

SYMBOL_LIB_TABLE::SYMBOL_LIB_TABLE ( SYMBOL_LIB_TABLE aFallBackTable = NULL)

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

88  :
89  LIB_TABLE( aFallBackTable )
90 {
91  // not copying fall back, simply search aFallBackTable separately
92  // if "nickName not found".
93 }
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 366 of file lib_table_base.h.

367  {
368  return rows[aIndex];
369  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Referenced by SYMBOL_GRID_TRICKS::paste_text(), FP_GRID_TRICKS::paste_text(), and SCH::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 374 of file lib_table_base.h.

375  {
376  return rows[aIndex];
377  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ Clear()

void LIB_TABLE::Clear ( )
inlineinherited

Delete all rows.

Definition at line 323 of file lib_table_base.h.

324  {
325  rows.clear();
326  nickIndex.clear();
327  }
LIB_TABLE_ROWS rows
INDEX nickIndex
this particular key is the nickName within each row.

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

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

◆ CreateSymbolLib()

void SYMBOL_LIB_TABLE::CreateSymbolLib ( const wxString &  aNickname)

Definition at line 439 of file symbol_lib_table.cpp.

440 {
441  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
442  wxCHECK( row && row->plugin, /* void */ );
443  row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() );
444 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

Referenced by LIB_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 407 of file symbol_lib_table.cpp.

408 {
409  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
410  wxCHECK( row && row->plugin, /* void */ );
411  return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName,
412  row->GetProperties() );
413 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

◆ DeleteSymbolLib()

void SYMBOL_LIB_TABLE::DeleteSymbolLib ( const wxString &  aNickname)

Definition at line 431 of file symbol_lib_table.cpp.

432 {
433  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
434  wxCHECK( row && row->plugin, /* void */ );
435  row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() );
436 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

◆ ensureIndex()

void LIB_TABLE::ensureIndex ( )
inlineprotectedinherited

Definition at line 513 of file lib_table_base.h.

514  {
515  // The dialog lib table editor may not maintain the nickIndex.
516  // Lazy indexing may be required. To handle lazy indexing, we must enforce
517  // that "nickIndex" is either empty or accurate, but never inaccurate.
518  if( !nickIndex.size() )
519  reindex();
520  }
void reindex()
INDEX nickIndex
this particular key is the nickName within each row.

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

283 {
284  SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
285  wxCHECK( row && row->plugin, /* void */ );
286 
287  wxString options = row->GetOptions();
288 
289  if( aPowerSymbolsOnly )
290  row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
291 
292  row->SetLoaded( false );
293  row->plugin->EnumerateSymbolLib( aAliasNames, row->GetFullURI( true ), row->GetProperties() );
294  row->SetLoaded( true );
295 
296  if( aPowerSymbolsOnly )
297  row->SetOptions( options );
298 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
void SetLoaded(bool aLoaded)
Mark the row as being a loaded library.
void SetOptions(const wxString &aOptions)
Change the library options strings.
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
static const char * PropPowerSymsOnly

References 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 LIB_MANAGER::getOriginalParts().

◆ FindRow()

SYMBOL_LIB_TABLE_ROW * SYMBOL_LIB_TABLE::FindRow ( const wxString &  aNickName)

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.
Returns
the row found or NULL if aNickName was not found.
Exceptions
IO_ERRORif aNickName cannot be found.

Definition at line 301 of file symbol_lib_table.cpp.

303 {
304  SYMBOL_LIB_TABLE_ROW* row = dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname ) );
305 
306  if( !row )
307  return nullptr;
308 
309  // We've been 'lazy' up until now, but it cannot be deferred any longer,
310  // instantiate a PLUGIN of the proper kind if it is not already in this
311  // SYMBOL_LIB_TABLE_ROW.
312  if( !row->plugin )
313  row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) );
314 
315  return row;
316 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
void setPlugin(SCH_PLUGIN *aPlugin)
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment,...

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

Referenced by CreateSymbolLib(), DeleteSymbol(), DeleteSymbolLib(), EnumerateSymbolLib(), LIB_MANAGER::GetLibrary(), GetModifyHash(), IsSymbolLibLoaded(), IsSymbolLibWritable(), SCH_EDIT_FRAME::LoadSheetFromFile(), LoadSymbol(), LoadSymbolLib(), and SaveSymbol().

◆ findRow() [1/2]

LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname) const
protectedinherited

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

Definition at line 190 of file lib_table_base.cpp.

191 {
192  LIB_TABLE* cur = (LIB_TABLE*) this;
193 
194  do
195  {
196  cur->ensureIndex();
197 
198  INDEX_CITER it = cur->nickIndex.find( aNickName );
199 
200  if( it != cur->nickIndex.end() )
201  {
202  return &cur->rows[it->second]; // found
203  }
204 
205  // not found, search fall back table(s), if any
206  } while( ( cur = cur->fallBack ) != 0 );
207 
208  return nullptr; // not found
209 }
void ensureIndex()
INDEX::const_iterator INDEX_CITER
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
INDEX nickIndex
this particular key is the nickName within each row.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

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

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

◆ findRow() [2/2]

LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname)
protectedinherited

Definition at line 212 of file lib_table_base.cpp.

213 {
214  LIB_TABLE* cur = (LIB_TABLE*) this;
215 
216  do
217  {
218  cur->ensureIndex();
219 
220  INDEX_ITER it = cur->nickIndex.find( aNickName );
221 
222  if( it != cur->nickIndex.end() )
223  {
224  return &cur->rows[it->second]; // found
225  }
226 
227  // not found, search fall back table(s), if any
228  } while( ( cur = cur->fallBack ) != 0 );
229 
230  return nullptr; // not found
231 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
INDEX::iterator INDEX_ITER
INDEX nickIndex
this particular key is the nickName within each row.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

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

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

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

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

Referenced by FOOTPRINT_EDIT_FRAME::KiwayMailIn(), and LIB_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 indention 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 244 of file symbol_lib_table.cpp.

245 {
246  aOutput->Print( aIndentLevel, "(sym_lib_table\n" );
247 
248  for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
249  {
250  it->Format( aOutput, aIndentLevel+1 );
251  }
252 
253  aOutput->Print( aIndentLevel, ")\n" );
254 }
LIB_TABLE_ROWS rows
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

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

Referenced by DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), SCH_ALTIUM_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 415 of file lib_table_base.cpp.

416 {
417  UTF8 ret;
418 
419  if( aProperties )
420  {
421  for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
422  {
423  const std::string& name = it->first;
424 
425  const UTF8& value = it->second;
426 
427  if( ret.size() )
428  ret += OPT_SEP;
429 
430  ret += name;
431 
432  // the separation between name and value is '='
433  if( value.size() )
434  {
435  ret += '=';
436 
437  for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
438  {
439  // escape any separator in the value.
440  if( *si == OPT_SEP )
441  ret += '\\';
442 
443  ret += *si;
444  }
445  }
446  }
447  }
448 
449  return ret;
450 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
const char * name
Definition: DXF_plotter.cpp:59
std::string::const_iterator end() const
Definition: utf8.h:197
std::string::const_iterator begin() const
Definition: utf8.h:196
std::string::size_type size() const
Definition: utf8.h:115
#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

Get the number of rows contained in the table.

Definition at line 356 of file lib_table_base.h.

357  {
358  return rows.size();
359  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Referenced by BOOST_AUTO_TEST_CASE(), FP_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount(), SYMBOL_GRID_TRICKS::paste_text(), FP_GRID_TRICKS::paste_text(), and SCH::IFACE::SaveFileAs().

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

152 {
153  // use "no exception" form of find row:
154  const LIB_TABLE_ROW* row = findRow( aNickname );
155 
156  if( row )
157  return row->GetDescr();
158  else
159  return wxEmptyString;
160 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetDescr() const
Return the description of the library referenced by this row.
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment,...

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

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), LIB_EDIT_FRAME::savePartAs(), 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 177 of file lib_table_base.cpp.

178 {
179  const LIB_TABLE_ROW* row = findRow( aNickname );
180 
181  wxString retv;
182 
183  if( row )
184  retv = row->GetFullURI( aExpandEnvVars );
185 
186  return retv;
187 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
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...
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment,...

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

Referenced by CVPCB_MAINFRAME::DisplayStatus(), SCH_EDIT_FRAME::LoadSheetFromFile(), NETLIST_EXPORTER_GENERIC::makeLibraries(), and FOOTPRINT_EDIT_FRAME::Process_Special_Functions().

◆ 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 528 of file symbol_lib_table.cpp.

529 {
530  wxFileName fn;
531 
533  fn.SetName( global_tbl_name );
534 
535  return fn.GetFullPath();
536 }
static const wxString global_tbl_name("sym-lib-table")
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.

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

Referenced by DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::GetGlobalTableFileName(), InvokeSchEditSymbolLibTable(), LoadGlobalTable(), SCH::IFACE::OnKifaceStart(), 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 270 of file lib_table_base.cpp.

271 {
272  // Only return unique logical library names. Use std::set::insert() to
273  // quietly reject any duplicates, which can happen when encountering a duplicate
274  // nickname from one of the fall back table(s).
275 
276  std::set< wxString > unique;
277  std::vector< wxString > ret;
278  const LIB_TABLE* cur = this;
279 
280  do
281  {
282  for( LIB_TABLE_ROWS_CITER it = cur->rows.begin(); it!=cur->rows.end(); ++it )
283  {
284  if( it->GetIsEnabled() )
285  {
286  unique.insert( it->GetNickName() );
287  }
288  }
289 
290  } while( ( cur = cur->fallBack ) != 0 );
291 
292  ret.reserve( unique.size() );
293 
294  // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
295  for( std::set< wxString >::const_iterator it = unique.begin(); it!=unique.end(); ++it )
296  {
297  ret.push_back( *it );
298  }
299 
300  // We want to allow case-sensitive duplicates but sort by case-insensitive ordering
301  std::sort( ret.begin(), ret.end(), []( const wxString& lhs, const wxString& rhs )
302  {
303  return lhs.CmpNoCase( rhs ) < 0;
304  } );
305 
306  return ret;
307 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

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

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FP_LIB_TABLE::GenerateTimestamp(), GetFootprintLibraries(), GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), LoadSymbolWithOptionalNickname(), FOOTPRINT_VIEWER_FRAME::OnActivate(), LIB_VIEW_FRAME::OnSelectSymbol(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), LIB_EDIT_FRAME::savePartAs(), SCH_BASE_FRAME::SelectCompFromLibTree(), PCB_BASE_FRAME::SelectLibrary(), FOOTPRINT_LIST_IMPL::StartWorkers(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ GetModifyHash()

int SYMBOL_LIB_TABLE::GetModifyHash ( )

Definition at line 257 of file symbol_lib_table.cpp.

258 {
259  int hash = 0;
260  std::vector< wxString > libNames = GetLogicalLibs();
261 
262  for( const auto& libName : libNames )
263  {
264  const SYMBOL_LIB_TABLE_ROW* row = FindRow( libName );
265 
266  if( !row || !row->plugin )
267  {
268  wxFAIL;
269  continue;
270  }
271 
272  hash += row->plugin->GetModifyHash();
273  }
274 
275  hash += m_modifyHash;
276 
277  return hash;
278 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
static int m_modifyHash
helper for GetModifyHash()
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

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

Referenced by LIB_MANAGER::GetHash(), and LIB_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 478 of file symbol_lib_table.cpp.

479 {
480  return "KICAD_SYMBOL_DIR";
481 }

Referenced by PANEL_SYM_LIB_TABLE::populateEnvironReadOnlyTable().

◆ HasLibrary()

bool LIB_TABLE::HasLibrary ( const wxString &  aNickname,
bool  aCheckEnabled = false 
) const
inherited

Test for the existence of aNickname 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 163 of file lib_table_base.cpp.

164 {
165  const LIB_TABLE_ROW* row = findRow( aNickname );
166 
167  if( row == nullptr )
168  return false;
169 
170  if( aCheckEnabled && !row->GetIsEnabled() )
171  return false;
172 
173  return true;
174 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
bool GetIsEnabled() const
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment,...

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

Referenced by CVPCB_MAINFRAME::DisplayStatus(), InvokeSchEditSymbolLibTable(), FOOTPRINT_EDIT_FRAME::KiwayMailIn(), LIB_EDIT_FRAME::KiwayMailIn(), LIB_MANAGER::LibraryExists(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), SCH_ALTIUM_PLUGIN::Load(), SCH_EAGLE_PLUGIN::Load(), SCH_EDIT_FRAME::LoadSheetFromFile(), NETLIST_EXPORTER_GENERIC::makeLibraries(), SCH_BASE_FRAME::SelectCompFromLibTree(), LIB_VIEW_FRAME::ShowModal(), FOOTPRINT_VIEWER_FRAME::ShowModal(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), and SCH_SCREEN::UpdateSymbolLinks().

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

311 {
312  ensureIndex();
313 
314  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
315 
316  if( it == nickIndex.end() )
317  {
318  rows.push_back( aRow );
319  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
320  return true;
321  }
322 
323  if( doReplace )
324  {
325  rows.replace( it->second, aRow );
326  return true;
327  }
328 
329  return false;
330 }
void ensureIndex()
INDEX::const_iterator INDEX_CITER
LIB_TABLE_ROWS rows
INDEX::value_type INDEX_VALUE
const wxString & GetNickName() const
INDEX nickIndex
this particular key is the nickName within each row.

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

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), LIB_MANAGER::addLibrary(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), PCB_EDIT_FRAME::importFile(), LIB_TABLE_TEST_FIXTURE::LIB_TABLE_TEST_FIXTURE(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), SCH_ALTIUM_PLUGIN::Load(), SCH_EAGLE_PLUGIN::Load(), FP_LIB_TABLE::Parse(), and Parse().

◆ IsEmpty()

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

Return true if the table is empty.

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

Definition at line 142 of file lib_table_base.cpp.

143 {
144  if( !aIncludeFallback || !fallBack )
145  return rows.empty();
146 
147  return rows.empty() && fallBack->IsEmpty( true );
148 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
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(), PCB_EDIT_FRAME::LoadFootprints(), 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 423 of file symbol_lib_table.cpp.

424 {
425  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
426  wxCHECK( row, false );
427  return row->GetIsLoaded();
428 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
bool GetIsLoaded() const

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

Referenced by LIB_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 416 of file symbol_lib_table.cpp.

417 {
418  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
419  wxCHECK( row && row->plugin, false );
420  return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) );
421 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
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...

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

Referenced by LIB_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 333 of file lib_table_base.cpp.

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

References LIB_TABLE::Parse().

Referenced by LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), SCH_EDIT_FRAME::LoadSheetFromFile(), PROJECT::PcbFootprintLibs(), SCH::IFACE::SaveFileAs(), DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow(), and DIALOG_GLOBAL_SYM_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 484 of file symbol_lib_table.cpp.

485 {
486  bool tableExists = true;
487  wxFileName fn = GetGlobalTableFileName();
488 
489  if( !fn.FileExists() )
490  {
491  tableExists = false;
492 
493  if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
494  {
496  _( "Cannot create global library table path \"%s\"." ), fn.GetPath() ) );
497  }
498 
499  // Attempt to copy the default global file table from the KiCad
500  // template folder to the user's home configuration path.
501  SEARCH_STACK ss;
502 
503  SystemDirsAppend( &ss );
504 
505  wxString templatePath =
506  Pgm().GetLocalEnvVariables().at( wxT( "KICAD_TEMPLATE_DIR" ) ).GetValue();
507 
508  if( !templatePath.IsEmpty() )
509  ss.AddPaths( templatePath, 0 );
510 
511  wxString fileName = ss.FindValidPath( global_tbl_name );
512 
513  // The fallback is to create an empty global symbol table for the user to populate.
514  if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
515  {
516  SYMBOL_LIB_TABLE emptyTable;
517 
518  emptyTable.Save( fn.GetFullPath() );
519  }
520  }
521 
522  aTable.Load( fn.GetFullPath() );
523 
524  return tableExists;
525 }
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:73
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
static const wxString global_tbl_name("sym-lib-table")
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
void AddPaths(const wxString &aPaths, int aIndex=-1)
Function AddPaths insert or append path(s)

References _, SEARCH_STACK::AddPaths(), SEARCH_STACK::FindValidPath(), Format(), GetGlobalTableFileName(), global_tbl_name(), LIB_TABLE::Load(), Pgm(), 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_PART * SYMBOL_LIB_TABLE::LoadSymbol ( const wxString &  aNickname,
const wxString &  aName 
)

Load a LIB_PART 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_PART 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 351 of file symbol_lib_table.cpp.

352 {
353  SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
354 
355  if( !row || !row->plugin )
356  return nullptr;
357 
358  LIB_PART* part = row->plugin->LoadSymbol( row->GetFullURI( true ), aSymbolName,
359  row->GetProperties() );
360 
361  if( part == nullptr )
362  return part;
363 
364  // The library cannot know its own name, because it might have been renamed or moved.
365  // Therefore footprints cannot know their own library nickname when residing in
366  // a symbol library.
367  // Only at this API layer can we tell the symbol about its actual library nickname.
368  if( part )
369  {
370  LIB_ID id = part->GetLibId();
371 
372  id.SetLibNickname( row->GetNickName() );
373  part->SetLibId( id );
374  }
375 
376  return part;
377 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
LIB_ID GetLibId() const override
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const wxString & GetNickName() const
Define a library symbol object.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
void SetLibId(const LIB_ID &aLibId)

References FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_PART::GetLibId(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetProperties(), SYMBOL_LIB_TABLE_ROW::plugin, LIB_PART::SetLibId(), and LIB_ID::SetLibNickname().

Referenced by FOOTPRINT_INFO_GENERATOR::GenerateHtml(), LIB_MANAGER::GetAlias(), LIB_MANAGER::GetBufferedPart(), LIB_MANAGER::getOriginalParts(), SCH_EAGLE_PLUGIN::loadInstance(), LoadSymbol(), LoadSymbolWithOptionalNickname(), LIB_MANAGER::PartExists(), LIB_MANAGER::LIB_BUFFER::SaveBuffer(), SchGetLibPart(), and SCH_SCREEN::UpdateSymbolLinks().

◆ LoadSymbol() [2/2]

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

Definition at line 185 of file symbol_lib_table.h.

186  {
187  return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
188  }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_PART * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_PART having aName from the library given by aNickname.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97

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

◆ LoadSymbolLib()

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

Definition at line 319 of file symbol_lib_table.cpp.

321 {
322  SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
323  wxCHECK( row && row->plugin, /* void */ );
324 
325  wxString options = row->GetOptions();
326 
327  if( aPowerSymbolsOnly )
328  row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
329 
330  row->SetLoaded( false );
331  row->plugin->EnumerateSymbolLib( aSymbolList, row->GetFullURI( true ), row->GetProperties() );
332  row->SetLoaded( true );
333 
334  if( aPowerSymbolsOnly )
335  row->SetOptions( options );
336 
337  // The library cannot know its own name, because it might have been renamed or moved.
338  // Therefore footprints cannot know their own library nickname when residing in
339  // a symbol library.
340  // Only at this API layer can we tell the symbol about its actual library nickname.
341  for( LIB_PART* part : aSymbolList )
342  {
343  LIB_ID id = part->GetLibId();
344 
345  id.SetLibNickname( row->GetNickName() );
346  part->SetLibId( id );
347  }
348 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
void SetLoaded(bool aLoaded)
Mark the row as being a loaded library.
const wxString & GetNickName() const
Define a library symbol object.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
void SetOptions(const wxString &aOptions)
Change the library options strings.
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
static const char * PropPowerSymsOnly

References FindRow(), LIB_TABLE_ROW::GetFullURI(), 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(), and LIB_MANAGER::GetAliases().

◆ LoadSymbolWithOptionalNickname()

LIB_PART * SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname ( const LIB_ID aId)

Load a LIB_PART 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 447 of file symbol_lib_table.cpp.

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

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

351 { return !( *this == 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 335 of file lib_table_base.h.

336  {
337  if( rows.size() == r.rows.size() )
338  {
339  unsigned i;
340 
341  for( i = 0; i < rows.size() && rows[i] == r.rows[i]; ++i )
342  ;
343 
344  if( i == rows.size() )
345  return true;
346  }
347 
348  return false;
349  }
LIB_TABLE_ROWS rows

References 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 102 of file symbol_lib_table.cpp.

103 {
104  T tok;
105  wxString errMsg; // to collect error messages
106 
107  // This table may be nested within a larger s-expression, or not.
108  // Allow for parser of that optional containing s-epression to have looked ahead.
109  if( in->CurTok() != T_sym_lib_table )
110  {
111  in->NeedLEFT();
112  if( ( tok = in->NextTok() ) != T_sym_lib_table )
113  in->Expecting( T_sym_lib_table );
114  }
115 
116  while( ( tok = in->NextTok() ) != T_RIGHT )
117  {
118  std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row = std::make_unique<SYMBOL_LIB_TABLE_ROW>();
119 
120  if( tok == T_EOF )
121  in->Expecting( T_RIGHT );
122 
123  if( tok != T_LEFT )
124  in->Expecting( T_LEFT );
125 
126  // in case there is a "row integrity" error, tell where later.
127  int lineNum = in->CurLineNumber();
128 
129  if( ( tok = in->NextTok() ) != T_lib )
130  in->Expecting( T_lib );
131 
132  // (name NICKNAME)
133  in->NeedLEFT();
134 
135  if( ( tok = in->NextTok() ) != T_name )
136  in->Expecting( T_name );
137 
138  in->NeedSYMBOLorNUMBER();
139 
140  row->SetNickName( in->FromUTF8() );
141 
142  in->NeedRIGHT();
143 
144  // After (name), remaining (lib) elements are order independent, and in
145  // some cases optional.
146  bool sawType = false;
147  bool sawOpts = false;
148  bool sawDesc = false;
149  bool sawUri = false;
150  bool sawDisabled = false;
151 
152  while( ( tok = in->NextTok() ) != T_RIGHT )
153  {
154  if( tok == T_EOF )
155  in->Unexpected( T_EOF );
156 
157  if( tok != T_LEFT )
158  in->Expecting( T_LEFT );
159 
160  tok = in->NeedSYMBOLorNUMBER();
161 
162  switch( tok )
163  {
164  case T_uri:
165  if( sawUri )
166  in->Duplicate( tok );
167  sawUri = true;
168  in->NeedSYMBOLorNUMBER();
169  row->SetFullURI( in->FromUTF8() );
170  break;
171 
172  case T_type:
173  if( sawType )
174  in->Duplicate( tok );
175  sawType = true;
176  in->NeedSYMBOLorNUMBER();
177  row->SetType( in->FromUTF8() );
178  break;
179 
180  case T_options:
181  if( sawOpts )
182  in->Duplicate( tok );
183  sawOpts = true;
184  in->NeedSYMBOLorNUMBER();
185  row->SetOptions( in->FromUTF8() );
186  break;
187 
188  case T_descr:
189  if( sawDesc )
190  in->Duplicate( tok );
191  sawDesc = true;
192  in->NeedSYMBOLorNUMBER();
193  row->SetDescr( in->FromUTF8() );
194  break;
195 
196  case T_disabled:
197  if( sawDisabled )
198  in->Duplicate( tok );
199  sawDisabled = true;
200  row->SetEnabled( false );
201  break;
202 
203  default:
204  in->Unexpected( tok );
205  }
206 
207  in->NeedRIGHT();
208  }
209 
210  if( !sawType )
211  in->Expecting( T_type );
212 
213  if( !sawUri )
214  in->Expecting( T_uri );
215 
216  // all nickNames within this table fragment must be unique, so we do not
217  // use doReplace in InsertRow(). (However a fallBack table can have a
218  // conflicting nickName and ours will supercede that one since in
219  // FindLib() we search this table before any fall back.)
220  wxString nickname = row->GetNickName(); // store it to be able to used it
221  // after row deletion if an error occurs
222  LIB_TABLE_ROW* tmp = row.release();
223 
224  if( !InsertRow( tmp ) )
225  {
226  delete tmp; // The table did not take ownership of the row.
227 
228  wxString msg = wxString::Format(
229  _( "Duplicate library nickname \"%s\" found in symbol library "
230  "table file line %d" ), nickname, lineNum );
231 
232  if( !errMsg.IsEmpty() )
233  errMsg << '\n';
234 
235  errMsg << msg;
236  }
237  }
238 
239  if( !errMsg.IsEmpty() )
240  THROW_IO_ERROR( errMsg );
241 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

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

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

506  {
507  nickIndex.clear();
508 
509  for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
510  nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
511  }
LIB_TABLE_ROWS rows
INDEX::value_type INDEX_VALUE
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
INDEX nickIndex
this particular key is the nickName within each row.

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

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

◆ RemoveRow()

bool LIB_TABLE::RemoveRow ( 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 433 of file lib_table_base.h.

434  {
435  for( auto iter = rows.begin(); iter != rows.end(); ++iter )
436  {
437  if( *iter == *aRow )
438  {
439  rows.erase( iter, iter + 1 );
440  return true;
441  }
442  }
443  return false;
444  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Referenced by LIB_MANAGER::addLibrary().

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

348 {
349  FILE_OUTPUTFORMATTER sf( aFileName );
350  Format( &sf, 0 );
351 }
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:493

References LIB_TABLE::Format().

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), PCB_EDIT_FRAME::importFile(), InvokePcbLibTableEditor(), InvokeSchEditSymbolLibTable(), LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), SCH::IFACE::SaveFileAs(), SCH_BASE_FRAME::saveSymbolLibTables(), DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ SaveSymbol()

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

Write aSymbol to an existing library given by aNickname.

If a LIB_PART by the same name already exists or there are any conflicting alias names, the new LIB_PART will silently overwrite any existing aliases and/or part becaue 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 380 of file symbol_lib_table.cpp.

382 {
383  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
384  wxCHECK( row && row->plugin, SAVE_SKIPPED );
385 
386  if( !aOverwrite )
387  {
388  // Try loading the footprint to see if it already exists, caller wants overwrite
389  // protection, which is atypical, not the default.
390 
391  wxString name = aSymbol->GetLibId().GetLibItemName();
392 
393  std::unique_ptr< LIB_PART > symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
394  name,
395  row->GetProperties() ) );
396 
397  if( symbol.get() )
398  return SAVE_SKIPPED;
399  }
400 
401  row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
402 
403  return SAVE_OK;
404 }
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
LIB_ID GetLibId() const override
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const char * name
Definition: DXF_plotter.cpp:59
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

References FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_PART::GetLibId(), LIB_ID::GetLibItemName(), LIB_TABLE_ROW::GetProperties(), name, SYMBOL_LIB_TABLE_ROW::plugin, SAVE_OK, and SAVE_SKIPPED.

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

◆ Type()

KICAD_T SYMBOL_LIB_TABLE::Type ( )
inlineoverridevirtual

Implements PROJECT::_ELEM.

Definition at line 118 of file symbol_lib_table.h.

References SYMBOL_LIB_TABLE_T.

Friends And Related Function Documentation

◆ PANEL_SYM_LIB_TABLE

friend class PANEL_SYM_LIB_TABLE
friend

Definition at line 113 of file symbol_lib_table.h.

◆ SYMBOL_LIB_TABLE_GRID

friend class SYMBOL_LIB_TABLE_GRID
friend

Definition at line 112 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 115 of file symbol_lib_table.h.

Referenced by GetModifyHash().

◆ nickIndex

INDEX LIB_TABLE::nickIndex
protectedinherited

this particular key is the nickName within each row.

Definition at line 531 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 121 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: