KiCad PCB EDA Suite
LIB_TABLE Class Referenceabstract

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

#include <lib_table_base.h>

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

Public Member Functions

virtual void Parse (LIB_TABLE_LEXER *aLexer)=0
 Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objects. More...
 
virtual void Format (OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
 Generate the table in s-expression format to aOutput with an indention level of aIndentLevel. More...
 
 LIB_TABLE (LIB_TABLE *aFallBackTable=nullptr)
 Build a library table by pre-pending this table fragment in front of aFallBackTable. More...
 
virtual ~LIB_TABLE ()
 
void Clear ()
 Delete all rows. More...
 
bool operator== (const LIB_TABLE &r) const
 Compares this table against another. More...
 
bool operator!= (const LIB_TABLE &r) const
 
unsigned GetCount () const
 Get the number of rows contained in the table. More...
 
LIB_TABLE_ROWAt (unsigned aIndex)
 Get the 'n'th LIB_TABLE_ROW object. More...
 
const LIB_TABLE_ROWAt (unsigned aIndex) const
 Get the 'n'th LIB_TABLE_ROW object. More...
 
bool IsEmpty (bool aIncludeFallback=true)
 Return true if the table is empty. More...
 
const wxString GetDescription (const wxString &aNickname)
 
bool HasLibrary (const wxString &aNickname, bool aCheckEnabled=false) const
 Test for the existence of aNickname in the library table. More...
 
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...
 
virtual KICAD_T Type ()=0
 

Static Public Member Functions

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 const wxString ExpandSubstitutions (const wxString &aString)
 Replaces any environment variable references with their values and is here to fully embellish the TABLE_ROW::uri in a platform independent way. More...
 

Protected Types

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

Protected Member Functions

LIB_TABLE_ROWfindRow (const wxString &aNickname) 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
 

Friends

class PANEL_FP_LIB_TABLE
 
class LIB_TABLE_GRID
 

Detailed Description

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

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

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

The Library Type can be one of:

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

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

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

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

Author
Wayne Stambaugh

Definition at line 266 of file lib_table_base.h.

Member Typedef Documentation

◆ INDEX

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

this is a non-owning index into the LIB_TABLE_ROWS table

Definition at line 523 of file lib_table_base.h.

◆ INDEX_CITER

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protected

Definition at line 525 of file lib_table_base.h.

◆ INDEX_ITER

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protected

Definition at line 524 of file lib_table_base.h.

◆ INDEX_VALUE

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protected

Definition at line 526 of file lib_table_base.h.

Constructor & Destructor Documentation

◆ LIB_TABLE()

LIB_TABLE::LIB_TABLE ( LIB_TABLE aFallBackTable = nullptr)

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

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

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

Definition at line 229 of file lib_table_base.cpp.

229  :
230  fallBack( aFallBackTable )
231 {
232  // not copying fall back, simply search aFallBackTable separately
233  // if "nickName not found".
234 }
LIB_TABLE * fallBack

◆ ~LIB_TABLE()

LIB_TABLE::~LIB_TABLE ( )
virtual

Definition at line 237 of file lib_table_base.cpp.

238 {
239  // *fallBack is not owned here.
240 }

Member Function Documentation

◆ At() [1/2]

LIB_TABLE_ROW& LIB_TABLE::At ( unsigned  aIndex)
inline

Get the 'n'th LIB_TABLE_ROW object.

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

Definition at line 355 of file lib_table_base.h.

356  {
357  return rows[aIndex];
358  }
LIB_TABLE_ROWS rows

References rows.

Referenced by SYMBOL_GRID_TRICKS::paste_text(), and FP_GRID_TRICKS::paste_text().

◆ At() [2/2]

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

Get the 'n'th LIB_TABLE_ROW object.

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

Definition at line 363 of file lib_table_base.h.

364  {
365  return rows[aIndex];
366  }
LIB_TABLE_ROWS rows

References rows.

◆ Clear()

void LIB_TABLE::Clear ( )
inline

Delete all rows.

Definition at line 312 of file lib_table_base.h.

313  {
314  rows.clear();
315  nickIndex.clear();
316  }
LIB_TABLE_ROWS rows
INDEX nickIndex
this particular key is the nickName within each row.

References nickIndex, and rows.

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

◆ ensureIndex()

void LIB_TABLE::ensureIndex ( )
inlineprotected

Definition at line 511 of file lib_table_base.h.

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

References nickIndex, and reindex().

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

◆ ExpandSubstitutions()

const wxString LIB_TABLE::ExpandSubstitutions ( const wxString &  aString)
static

Replaces any environment variable references with their values and is here to fully embellish the TABLE_ROW::uri in a platform independent way.

This enables library tables to have platform dependent environment variables in them, allowing for a uniform table across platforms.

Definition at line 554 of file lib_table_base.cpp.

555 {
556  return ExpandEnvVarSubstitutions( aString );
557 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Replace any environment variable references with their values.
Definition: common.cpp:454

References ExpandEnvVarSubstitutions().

Referenced by GITHUB_PLUGIN::cacheLib(), LIB_TABLE_ROW::GetFullURI(), and LIB_TABLE_ROW::SetFullURI().

◆ findRow() [1/2]

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

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

Definition at line 291 of file lib_table_base.cpp.

292 {
293  LIB_TABLE* cur = (LIB_TABLE*) this;
294 
295  do
296  {
297  cur->ensureIndex();
298 
299  INDEX_CITER it = cur->nickIndex.find( aNickName );
300 
301  if( it != cur->nickIndex.end() )
302  {
303  return &cur->rows[it->second]; // found
304  }
305 
306  // not found, search fall back table(s), if any
307  } while( ( cur = cur->fallBack ) != 0 );
308 
309  return nullptr; // not found
310 }
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 ensureIndex(), fallBack, nickIndex, and rows.

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

◆ findRow() [2/2]

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

Definition at line 313 of file lib_table_base.cpp.

314 {
315  LIB_TABLE* cur = (LIB_TABLE*) this;
316 
317  do
318  {
319  cur->ensureIndex();
320 
321  INDEX_ITER it = cur->nickIndex.find( aNickName );
322 
323  if( it != cur->nickIndex.end() )
324  {
325  return &cur->rows[it->second]; // found
326  }
327 
328  // not found, search fall back table(s), if any
329  } while( ( cur = cur->fallBack ) != 0 );
330 
331  return nullptr; // not found
332 }
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 ensureIndex(), fallBack, nickIndex, and rows.

◆ FindRowByURI()

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

Definition at line 335 of file lib_table_base.cpp.

336 {
337  LIB_TABLE* cur = this;
338 
339  do
340  {
341  cur->ensureIndex();
342 
343  for( unsigned i = 0; i < cur->rows.size(); i++ )
344  {
345  wxString tmp = cur->rows[i].GetFullURI( true );
346 
347  if( tmp.Find( "://" ) != wxNOT_FOUND )
348  {
349  if( tmp == aURI )
350  return &cur->rows[i]; // found as URI
351  }
352  else
353  {
354  wxFileName fn = aURI;
355 
356  // This will also test if the file is a symlink so if we are comparing
357  // a symlink to the same real file, the comparison will be true. See
358  // wxFileName::SameAs() in the wxWidgets source.
359  if( fn == wxFileName( tmp ) )
360  return &cur->rows[i]; // found as full path and file name
361  }
362  }
363 
364  // not found, search fall back table(s), if any
365  } while( ( cur = cur->fallBack ) != 0 );
366 
367  return nullptr; // not found
368 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
size_t i
Definition: json11.cpp:649
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

References ensureIndex(), fallBack, i, and rows.

Referenced by FOOTPRINT_EDIT_FRAME::KiwayMailIn(), and LIB_EDIT_FRAME::KiwayMailIn().

◆ Format()

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

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.

Implemented in SYMBOL_LIB_TABLE, and FP_LIB_TABLE.

Referenced by Save().

◆ FormatOptions()

UTF8 LIB_TABLE::FormatOptions ( const PROPERTIES aProperties)
static

Returns a list of options from the aProperties parameter.

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

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

Definition at line 516 of file lib_table_base.cpp.

517 {
518  UTF8 ret;
519 
520  if( aProperties )
521  {
522  for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
523  {
524  const std::string& name = it->first;
525 
526  const UTF8& value = it->second;
527 
528  if( ret.size() )
529  ret += OPT_SEP;
530 
531  ret += name;
532 
533  // the separation between name and value is '='
534  if( value.size() )
535  {
536  ret += '=';
537 
538  for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
539  {
540  // escape any separator in the value.
541  if( *si == OPT_SEP )
542  ret += '\\';
543 
544  ret += *si;
545  }
546  }
547  }
548  }
549 
550  return ret;
551 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
const char * name
Definition: DXF_plotter.cpp:61
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
inline

Get the number of rows contained in the table.

Definition at line 345 of file lib_table_base.h.

346  {
347  return rows.size();
348  }
LIB_TABLE_ROWS rows

References rows.

Referenced by FP_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount(), SYMBOL_GRID_TRICKS::paste_text(), and FP_GRID_TRICKS::paste_text().

◆ GetDescription()

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

Definition at line 252 of file lib_table_base.cpp.

253 {
254  // use "no exception" form of find row:
255  const LIB_TABLE_ROW* row = findRow( aNickname );
256 
257  if( row )
258  return row->GetDescr();
259  else
260  return wxEmptyString;
261 }
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 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

Return the full URI of the library mapped to aLibNickname.

Definition at line 278 of file lib_table_base.cpp.

279 {
280  const LIB_TABLE_ROW* row = findRow( aNickname );
281 
282  wxString retv;
283 
284  if( row )
285  retv = row->GetFullURI( aExpandEnvVars );
286 
287  return retv;
288 }
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 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().

◆ GetLogicalLibs()

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

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

Definition at line 371 of file lib_table_base.cpp.

372 {
373  // Only return unique logical library names. Use std::set::insert() to
374  // quietly reject any duplicates, which can happen when encountering a duplicate
375  // nickname from one of the fall back table(s).
376 
377  std::set< wxString > unique;
378  std::vector< wxString > ret;
379  const LIB_TABLE* cur = this;
380 
381  do
382  {
383  for( LIB_TABLE_ROWS_CITER it = cur->rows.begin(); it!=cur->rows.end(); ++it )
384  {
385  if( it->GetIsEnabled() )
386  {
387  unique.insert( it->GetNickName() );
388  }
389  }
390 
391  } while( ( cur = cur->fallBack ) != 0 );
392 
393  ret.reserve( unique.size() );
394 
395  // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
396  for( std::set< wxString >::const_iterator it = unique.begin(); it!=unique.end(); ++it )
397  {
398  ret.push_back( *it );
399  }
400 
401  // We want to allow case-sensitive duplicates but sort by case-insensitive ordering
402  std::sort( ret.begin(), ret.end(), []( const wxString& lhs, const wxString& rhs )
403  {
404  return lhs.CmpNoCase( rhs ) < 0;
405  } );
406 
407  return ret;
408 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
YYCODETYPE lhs
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

References fallBack, numEval::lhs, and rows.

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FP_LIB_TABLE::GenerateTimestamp(), SYMBOL_LIB_TABLE::GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), SYMBOL_LIB_TABLE::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().

◆ HasLibrary()

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

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

265 {
266  const LIB_TABLE_ROW* row = findRow( aNickname );
267 
268  if( row == nullptr )
269  return false;
270 
271  if( aCheckEnabled && !row->GetIsEnabled() )
272  return false;
273 
274  return true;
275 }
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 findRow(), and LIB_TABLE_ROW::GetIsEnabled().

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

◆ InsertRow()

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

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

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

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

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

Definition at line 411 of file lib_table_base.cpp.

412 {
413  ensureIndex();
414 
415  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
416 
417  if( it == nickIndex.end() )
418  {
419  rows.push_back( aRow );
420  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
421  return true;
422  }
423 
424  if( doReplace )
425  {
426  rows.replace( it->second, aRow );
427  return true;
428  }
429 
430  return false;
431 }
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 ensureIndex(), LIB_TABLE_ROW::GetNickName(), nickIndex, and rows.

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

◆ IsEmpty()

bool LIB_TABLE::IsEmpty ( bool  aIncludeFallback = true)

Return true if the table is empty.

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

Definition at line 243 of file lib_table_base.cpp.

244 {
245  if( !aIncludeFallback || !fallBack )
246  return rows.empty();
247 
248  return rows.empty() && fallBack->IsEmpty( true );
249 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.

References fallBack, IsEmpty(), and rows.

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

◆ Load()

void LIB_TABLE::Load ( const wxString &  aFileName)

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

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

Definition at line 434 of file lib_table_base.cpp.

436 {
437  // It's OK if footprint library tables are missing.
438  if( wxFileName::IsFileReadable( aFileName ) )
439  {
440  FILE_LINE_READER reader( aFileName );
441  LIB_TABLE_LEXER lexer( &reader );
442 
443  Parse( &lexer );
444  }
445 }
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
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 Parse().

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

◆ operator!=()

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

Definition at line 340 of file lib_table_base.h.

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

◆ operator==()

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

Compares this table against another.

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

Definition at line 324 of file lib_table_base.h.

325  {
326  if( rows.size() == r.rows.size() )
327  {
328  unsigned i;
329 
330  for( i = 0; i < rows.size() && rows[i] == r.rows[i]; ++i )
331  ;
332 
333  if( i == rows.size() )
334  return true;
335  }
336 
337  return false;
338  }
LIB_TABLE_ROWS rows
size_t i
Definition: json11.cpp:649

References i, and rows.

◆ Parse()

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

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

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

Implemented in SYMBOL_LIB_TABLE, and FP_LIB_TABLE.

Referenced by Load().

◆ ParseOptions()

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

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

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

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

Definition at line 455 of file lib_table_base.cpp.

456 {
457  if( aOptionsList.size() )
458  {
459  const char* cp = &aOptionsList[0];
460  const char* end = cp + aOptionsList.size();
461 
462  PROPERTIES props;
463  std::string pair;
464 
465  // Parse all name=value pairs
466  while( cp < end )
467  {
468  pair.clear();
469 
470  // Skip leading white space.
471  while( cp < end && isspace( *cp ) )
472  ++cp;
473 
474  // Find the end of pair/field
475  while( cp < end )
476  {
477  if( *cp == '\\' && cp + 1 < end && cp[1] == OPT_SEP )
478  {
479  ++cp; // skip the escape
480  pair += *cp++; // add the separator
481  }
482  else if( *cp == OPT_SEP )
483  {
484  ++cp; // skip the separator
485  break; // process the pair
486  }
487  else
488  pair += *cp++;
489  }
490 
491  // stash the pair
492  if( pair.size() )
493  {
494  // first equals sign separates 'name' and 'value'.
495  size_t eqNdx = pair.find( '=' );
496 
497  if( eqNdx != pair.npos )
498  {
499  std::string name = pair.substr( 0, eqNdx );
500  std::string value = pair.substr( eqNdx + 1 );
501  props[name] = value;
502  }
503  else
504  props[pair] = ""; // property is present, but with no value.
505  }
506  }
507 
508  if( props.size() )
509  return new PROPERTIES( props );
510  }
511 
512  return nullptr;
513 }
std::vector< PROPERTY > PROPERTIES
Definition: specctra.h:184
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
const char * name
Definition: DXF_plotter.cpp:61
#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 ( )
inlineprotected

Definition at line 503 of file lib_table_base.h.

504  {
505  nickIndex.clear();
506 
507  for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
508  nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
509  }
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 nickIndex, and rows.

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

◆ RemoveRow()

bool LIB_TABLE::RemoveRow ( LIB_TABLE_ROW aRow)
inline

Removes a row from the table.

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

Definition at line 422 of file lib_table_base.h.

423  {
424  for( auto iter = rows.begin(); iter != rows.end(); ++iter )
425  {
426  if( *iter == *aRow )
427  {
428  rows.erase( iter, iter + 1 );
429  return true;
430  }
431  }
432  return false;
433  }
LIB_TABLE_ROWS rows

References rows.

Referenced by LIB_MANAGER::addLibrary().

◆ Save()

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

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

Parameters
aFileNameis the name of the file to write to.

Definition at line 448 of file lib_table_base.cpp.

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

References Format().

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

◆ Type()

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

Friends And Related Function Documentation

◆ LIB_TABLE_GRID

friend class LIB_TABLE_GRID
friend

Definition at line 269 of file lib_table_base.h.

◆ PANEL_FP_LIB_TABLE

friend class PANEL_FP_LIB_TABLE
friend

Definition at line 268 of file lib_table_base.h.

Member Data Documentation

◆ fallBack

LIB_TABLE* LIB_TABLE::fallBack
protected

Definition at line 531 of file lib_table_base.h.

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

◆ nickIndex

INDEX LIB_TABLE::nickIndex
protected

this particular key is the nickName within each row.

Definition at line 529 of file lib_table_base.h.

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

◆ rows


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