KiCad PCB EDA Suite
SYMBOL_LIB_TABLE_GRID Class Reference

Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object. More...

Inheritance diagram for SYMBOL_LIB_TABLE_GRID:
LIB_TABLE_GRID SYMBOL_LIB_TABLE LIB_TABLE PROJECT::_ELEM

Public Types

enum  SAVE_T { SAVE_OK, SAVE_SKIPPED }
 The set of return values from SaveSymbol() below. More...
 

Public Member Functions

 SYMBOL_LIB_TABLE_GRID (const SYMBOL_LIB_TABLE &aTableToEdit)
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetValue (int aRow, int aCol) override
 
bool GetValueAsBool (int aRow, int aCol) override
 
void SetValue (int aRow, int aCol, const wxString &aValue) override
 
void SetValueAsBool (int aRow, int aCol, bool aValue) override
 
bool IsEmptyCell (int aRow, int aCol) override
 
bool InsertRows (size_t aPos=0, size_t aNumRows=1) override
 
bool AppendRows (size_t aNumRows=1) override
 
bool DeleteRows (size_t aPos, size_t aNumRows) override
 
wxString GetColLabelValue (int aCol) override
 
bool ContainsNickname (const wxString &aNickname)
 
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_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_ALIAS * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
 
LIB_ALIASLoadSymbol (const wxString &aNickname, const wxString &aAliasName)
 Load a LIB_ALIAS having aAliasName from the library given by aNickname. More...
 
LIB_ALIASLoadSymbol (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...
 
void DeleteAlias (const wxString &aNickname, const wxString &aAliasName)
 Delete aAliasName from the library at aLibraryPath. More...
 
bool IsSymbolLibWritable (const wxString &aNickname)
 Return true if the library given by aNickname is writable. More...
 
void DeleteSymbolLib (const wxString &aNickname)
 
void CreateSymbolLib (const wxString &aNickname)
 
LIB_ALIASLoadSymbolWithOptionalNickname (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 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...
 

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_ROWat (size_t aIndex) override
 
size_t size () const override
 
LIB_TABLE_ROWmakeNewRow () override
 
LIB_TABLE_ROWS_ITER begin () override
 
LIB_TABLE_ROWS_ITER insert (LIB_TABLE_ROWS_ITER aIterator, LIB_TABLE_ROW *aRow) override
 
void push_back (LIB_TABLE_ROW *aRow) override
 
LIB_TABLE_ROWS_ITER erase (LIB_TABLE_ROWS_ITER aFirst, LIB_TABLE_ROWS_ITER aLast) override
 
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 SYMBOL_GRID_TRICKS
 

Detailed Description

Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.

Definition at line 49 of file panel_sym_lib_table.cpp.

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

◆ INDEX_CITER

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protectedinherited

Definition at line 525 of file lib_table_base.h.

◆ INDEX_ITER

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protectedinherited

Definition at line 524 of file lib_table_base.h.

◆ INDEX_VALUE

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protectedinherited

Definition at line 526 of file lib_table_base.h.

Member Enumeration Documentation

◆ SAVE_T

enum SYMBOL_LIB_TABLE::SAVE_T
inherited

The set of return values from SaveSymbol() below.

Enumerator
SAVE_OK 
SAVE_SKIPPED 

Definition at line 186 of file symbol_lib_table.h.

Constructor & Destructor Documentation

◆ SYMBOL_LIB_TABLE_GRID()

SYMBOL_LIB_TABLE_GRID::SYMBOL_LIB_TABLE_GRID ( const SYMBOL_LIB_TABLE aTableToEdit)
inline

Definition at line 79 of file panel_sym_lib_table.cpp.

80  {
81  rows = aTableToEdit.rows;
82  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Member Function Documentation

◆ AppendRows()

bool LIB_TABLE_GRID::AppendRows ( size_t  aNumRows = 1)
inlineoverrideinherited

Definition at line 145 of file lib_table_grid.h.

146  {
147  // do not modify aNumRows, original value needed for wxGridTableMessage below
148  for( int i = aNumRows; i; --i )
149  push_back( makeNewRow() );
150 
151  if( GetView() )
152  {
153  wxGridTableMessage msg( this,
154  wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
155  aNumRows );
156 
157  GetView()->ProcessTableMessage( msg );
158  }
159 
160  return true;
161  }
virtual LIB_TABLE_ROW * makeNewRow()=0
virtual void push_back(LIB_TABLE_ROW *aRow)=0
size_t i
Definition: json11.cpp:597

References i, LIB_TABLE_GRID::makeNewRow(), and LIB_TABLE_GRID::push_back().

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

◆ at()

LIB_TABLE_ROW* SYMBOL_LIB_TABLE_GRID::at ( size_t  aIndex)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 54 of file panel_sym_lib_table.cpp.

54 { return &rows.at( aIndex ); }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

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

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

References LIB_TABLE::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
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 363 of file lib_table_base.h.

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

References LIB_TABLE::rows.

◆ begin()

LIB_TABLE_ROWS_ITER SYMBOL_LIB_TABLE_GRID::begin ( )
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 63 of file panel_sym_lib_table.cpp.

63 { return rows.begin(); }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ Clear()

void LIB_TABLE::Clear ( )
inlineinherited

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 LIB_TABLE::nickIndex, and LIB_TABLE::rows.

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

◆ ContainsNickname()

bool LIB_TABLE_GRID::ContainsNickname ( const wxString &  aNickname)
inlineinherited

Definition at line 203 of file lib_table_grid.h.

204  {
205  for( size_t i = 0; i < size(); ++i )
206  {
207  LIB_TABLE_ROW* row = at( i );
208 
209  if( row->GetNickName() == aNickname )
210  return true;
211  }
212  return false;
213  }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
virtual LIB_TABLE_ROW * at(size_t aIndex)=0
const wxString & GetNickName() const
virtual size_t size() const =0
size_t i
Definition: json11.cpp:597

References LIB_TABLE_GRID::at(), LIB_TABLE_ROW::GetNickName(), i, and LIB_TABLE_GRID::size().

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

◆ CreateSymbolLib()

void SYMBOL_LIB_TABLE::CreateSymbolLib ( const wxString &  aNickname)
inherited

Definition at line 423 of file symbol_lib_table.cpp.

424 {
425  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
426  wxCHECK( row && row->plugin, /* void */ );
427  row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() );
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...
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 SYMBOL_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and SYMBOL_LIB_TABLE_ROW::plugin.

Referenced by LIB_MANAGER::addLibrary().

◆ DeleteAlias()

void SYMBOL_LIB_TABLE::DeleteAlias ( const wxString &  aNickname,
const wxString &  aAliasName 
)
inherited

Delete aAliasName from the library at aLibraryPath.

If aAliasName refers the the root LIB_PART object, the part is renamed to the next or previous LIB_ALIAS in the LIB_PART if one exists. If the LIB_ALIAS is the last alias referring to the root LIB_PART, the LIB_PART is also removed from the library.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW
aAliasNameis the name of a LIB_ALIAS to delete from the specified library.
Exceptions
IO_ERRORif there is a problem finding the alias or the library or deleting it.

Definition at line 398 of file symbol_lib_table.cpp.

399 {
400  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
401  wxCHECK( row && row->plugin, /* void */ );
402  return row->plugin->DeleteAlias( row->GetFullURI( true ), aAliasName,
403  row->GetProperties() );
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...
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 SYMBOL_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and SYMBOL_LIB_TABLE_ROW::plugin.

◆ DeleteRows()

bool LIB_TABLE_GRID::DeleteRows ( size_t  aPos,
size_t  aNumRows 
)
inlineoverrideinherited

Definition at line 163 of file lib_table_grid.h.

164  {
165  // aPos may be a large positive, e.g. size_t(-1), and the sum of
166  // aPos+aNumRows may wrap here, so both ends of the range are tested.
167  if( aPos < size() && aPos + aNumRows <= size() )
168  {
169  LIB_TABLE_ROWS_ITER start = begin() + aPos;
170  erase( start, start + aNumRows );
171  if( GetView() )
172  {
173  wxGridTableMessage msg( this,
174  wxGRIDTABLE_NOTIFY_ROWS_DELETED,
175  aPos,
176  aNumRows );
177 
178  GetView()->ProcessTableMessage( msg );
179  }
180  return true;
181  }
182 
183  return false;
184  }
virtual LIB_TABLE_ROWS_ITER begin()=0
virtual size_t size() const =0
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
virtual LIB_TABLE_ROWS_ITER erase(LIB_TABLE_ROWS_ITER aFirst, LIB_TABLE_ROWS_ITER aLast)=0

References LIB_TABLE_GRID::begin(), LIB_TABLE_GRID::erase(), and LIB_TABLE_GRID::size().

◆ DeleteSymbol()

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

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

390 {
391  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
392  wxCHECK( row && row->plugin, /* void */ );
393  return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName,
394  row->GetProperties() );
395 }
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 SYMBOL_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and SYMBOL_LIB_TABLE_ROW::plugin.

◆ DeleteSymbolLib()

void SYMBOL_LIB_TABLE::DeleteSymbolLib ( const wxString &  aNickname)
inherited

Definition at line 415 of file symbol_lib_table.cpp.

416 {
417  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
418  wxCHECK( row && row->plugin, /* void */ );
419  row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() );
420 }
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 SYMBOL_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and SYMBOL_LIB_TABLE_ROW::plugin.

◆ ensureIndex()

void LIB_TABLE::ensureIndex ( )
inlineprotectedinherited

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 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 
)
inherited

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

266 {
267  SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
268  wxCHECK( row && row->plugin, /* void */ );
269 
270  wxString options = row->GetOptions();
271 
272  if( aPowerSymbolsOnly )
273  row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
274 
275  row->plugin->EnumerateSymbolLib( aAliasNames, row->GetFullURI( true ), row->GetProperties() );
276 
277  if( aPowerSymbolsOnly )
278  row->SetOptions( options );
279 }
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 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 SYMBOL_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetOptions(), LIB_TABLE_ROW::GetProperties(), SYMBOL_LIB_TABLE_ROW::plugin, SYMBOL_LIB_TABLE::PropPowerSymsOnly, and LIB_TABLE_ROW::SetOptions().

Referenced by LIB_MANAGER::getOriginalParts().

◆ erase()

LIB_TABLE_ROWS_ITER SYMBOL_LIB_TABLE_GRID::erase ( LIB_TABLE_ROWS_ITER  aFirst,
LIB_TABLE_ROWS_ITER  aLast 
)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 72 of file panel_sym_lib_table.cpp.

73  {
74  return rows.erase( aFirst, aLast );
75  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ ExpandSubstitutions()

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

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:458

References ExpandEnvVarSubstitutions().

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

◆ FindRow()

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

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

284 {
285  SYMBOL_LIB_TABLE_ROW* row = dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname ) );
286 
287  if( !row )
288  {
289  wxString msg = wxString::Format(
290  _( "sym-lib-table files contain no library with nickname \"%s\"" ),
291  GetChars( aNickname ) );
292 
293  THROW_IO_ERROR( msg );
294  }
295 
296  // We've been 'lazy' up until now, but it cannot be deferred any longer,
297  // instantiate a PLUGIN of the proper kind if it is not already in this
298  // SYMBOL_LIB_TABLE_ROW.
299  if( !row->plugin )
300  row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) );
301 
302  return row;
303 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
#define THROW_IO_ERROR(msg)
void setPlugin(SCH_PLUGIN *aPlugin)
#define _(s)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
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:205
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(), Format(), GetChars(), SYMBOL_LIB_TABLE_ROW::plugin, SYMBOL_LIB_TABLE_ROW::setPlugin(), THROW_IO_ERROR, and SYMBOL_LIB_TABLE_ROW::type.

Referenced by SYMBOL_LIB_TABLE::CreateSymbolLib(), SYMBOL_LIB_TABLE::DeleteAlias(), SYMBOL_LIB_TABLE::DeleteSymbol(), SYMBOL_LIB_TABLE::DeleteSymbolLib(), SYMBOL_LIB_TABLE::EnumerateSymbolLib(), LIB_MANAGER::GetLibrary(), SYMBOL_LIB_TABLE::GetModifyHash(), SYMBOL_LIB_TABLE::IsSymbolLibWritable(), SCH_EDIT_FRAME::LoadSheetFromFile(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_LIB_TABLE::LoadSymbolLib(), and SYMBOL_LIB_TABLE::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 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 LIB_TABLE::ensureIndex(), LIB_TABLE::fallBack, LIB_TABLE::nickIndex, and LIB_TABLE::rows.

Referenced by FP_LIB_TABLE::FindRow(), SYMBOL_LIB_TABLE::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 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 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 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:597
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

References LIB_TABLE::ensureIndex(), LIB_TABLE::fallBack, i, 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
overridevirtualinherited

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

228 {
229  aOutput->Print( aIndentLevel, "(sym_lib_table\n" );
230 
231  for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
232  {
233  it->Format( aOutput, aIndentLevel+1 );
234  }
235 
236  aOutput->Print( aIndentLevel, ")\n" );
237 }
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:404

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

Referenced by DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), 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 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().

◆ GetColLabelValue()

wxString LIB_TABLE_GRID::GetColLabelValue ( int  aCol)
inlineoverrideinherited

Definition at line 186 of file lib_table_grid.h.

187  {
188  switch( aCol )
189  {
190  case COL_NICKNAME: return _( "Nickname" );
191  case COL_URI: return _( "Library Path" );
192 
193  // keep this "Plugin Type" text fairly long so column is sized wide enough
194  case COL_TYPE: return _( "Plugin Type" );
195  case COL_OPTIONS: return _( "Options" );
196  case COL_DESCR: return _( "Description" );
197  case COL_ENABLED: return _( "Active" );
198 
199  default: return wxEmptyString;
200  }
201  }
#define _(s)

References _, COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, and COL_URI.

◆ GetCount()

unsigned LIB_TABLE::GetCount ( ) const
inlineinherited

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 LIB_TABLE::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)
inherited
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 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 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 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 ( )
staticinherited

Fetch the global symbol library table file name.

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

Definition at line 512 of file symbol_lib_table.cpp.

513 {
514  wxFileName fn;
515 
516  fn.SetPath( GetKicadConfigPath() );
517  fn.SetName( global_tbl_name );
518 
519  return fn.GetFullPath();
520 }
static const wxString global_tbl_name("sym-lib-table")
wxString GetKicadConfigPath()
Return the user configuration path used to store KiCad's configuration files.
Definition: common.cpp:267

References GetKicadConfigPath(), and global_tbl_name().

Referenced by DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::GetGlobalTableFileName(), InvokeSchEditSymbolLibTable(), SYMBOL_LIB_TABLE::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 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 LIB_TABLE::fallBack, numEval::lhs, 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(), 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().

◆ GetModifyHash()

int SYMBOL_LIB_TABLE::GetModifyHash ( )
inherited

Definition at line 240 of file symbol_lib_table.cpp.

241 {
242  int hash = 0;
243  std::vector< wxString > libNames = GetLogicalLibs();
244 
245  for( const auto& libName : libNames )
246  {
247  const SYMBOL_LIB_TABLE_ROW* row = FindRow( libName );
248 
249  if( !row || !row->plugin )
250  {
251  wxFAIL;
252  continue;
253  }
254 
255  hash += row->plugin->GetModifyHash();
256  }
257 
258  hash += m_modifyHash;
259 
260  return hash;
261 }
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 SYMBOL_LIB_TABLE::FindRow(), LIB_TABLE::GetLogicalLibs(), SYMBOL_LIB_TABLE::m_modifyHash, and SYMBOL_LIB_TABLE_ROW::plugin.

Referenced by LIB_MANAGER::GetHash(), LIB_MANAGER::Sync(), and SCH_SCREEN::UpdateSymbolLinks().

◆ GetNumberCols()

int LIB_TABLE_GRID::GetNumberCols ( )
inlineoverrideinherited

Definition at line 55 of file lib_table_grid.h.

55 { return COL_COUNT; }

References COL_COUNT.

◆ GetNumberRows()

int LIB_TABLE_GRID::GetNumberRows ( )
inlineoverrideinherited

Definition at line 53 of file lib_table_grid.h.

53 { return (int) size(); }
virtual size_t size() const =0

References LIB_TABLE_GRID::size().

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

◆ GetSymbolLibTableFileName()

◆ GetValue()

wxString LIB_TABLE_GRID::GetValue ( int  aRow,
int  aCol 
)
inlineoverrideinherited

Definition at line 57 of file lib_table_grid.h.

58  {
59  if( aRow < (int) size() )
60  {
61  const LIB_TABLE_ROW* r = at( (size_t) aRow );
62 
63  switch( aCol )
64  {
65  case COL_NICKNAME: return r->GetNickName();
66  case COL_URI: return r->GetFullURI();
67  case COL_TYPE: return r->GetType();
68  case COL_OPTIONS: return r->GetOptions();
69  case COL_DESCR: return r->GetDescr();
70  // Render a boolean value as its text equivalent
71  case COL_ENABLED: return r->GetIsEnabled() ? wxT( "1" ) : wxT( "0" );
72  default:
73  ; // fall thru to wxEmptyString
74  }
75  }
76 
77  return wxEmptyString;
78  }
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
virtual LIB_TABLE_ROW * at(size_t aIndex)=0
virtual const wxString GetType() const =0
Return the type of library represented by this row.
const wxString & GetDescr() const
Return the description of the library referenced by this row.
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const wxString & GetNickName() const
bool GetIsEnabled() const
virtual size_t size() const =0

References LIB_TABLE_GRID::at(), COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, LIB_TABLE_ROW::GetDescr(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetIsEnabled(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetOptions(), LIB_TABLE_ROW::GetType(), and LIB_TABLE_GRID::size().

Referenced by LIB_TABLE_GRID::IsEmptyCell().

◆ GetValueAsBool()

bool LIB_TABLE_GRID::GetValueAsBool ( int  aRow,
int  aCol 
)
inlineoverrideinherited

Definition at line 80 of file lib_table_grid.h.

81  {
82  if( aRow < (int) size() && aCol == COL_ENABLED )
83  return at( (size_t) aRow )->GetIsEnabled();
84  else
85  return false;
86  }
virtual LIB_TABLE_ROW * at(size_t aIndex)=0
bool GetIsEnabled() const
virtual size_t size() const =0

References LIB_TABLE_GRID::at(), COL_ENABLED, LIB_TABLE_ROW::GetIsEnabled(), and LIB_TABLE_GRID::size().

◆ GlobalPathEnvVariableName()

const wxString SYMBOL_LIB_TABLE::GlobalPathEnvVariableName ( )
staticinherited

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

463 {
464  return "KICAD_SYMBOL_DIR";
465 }

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

◆ insert()

LIB_TABLE_ROWS_ITER SYMBOL_LIB_TABLE_GRID::insert ( LIB_TABLE_ROWS_ITER  aIterator,
LIB_TABLE_ROW aRow 
)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 65 of file panel_sym_lib_table.cpp.

66  {
67  return rows.insert( aIterator, aRow );
68  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ 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 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 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(), SCH_EAGLE_PLUGIN::Load(), FP_LIB_TABLE::Parse(), and SYMBOL_LIB_TABLE::Parse().

◆ InsertRows()

bool LIB_TABLE_GRID::InsertRows ( size_t  aPos = 0,
size_t  aNumRows = 1 
)
inlineoverrideinherited

Definition at line 119 of file lib_table_grid.h.

120  {
121  if( aPos < size() )
122  {
123  for( size_t i = 0; i < aNumRows; i++ )
124  {
125  insert( begin() + i, makeNewRow() );
126  }
127 
128  // use the (wxGridStringTable) source Luke.
129  if( GetView() )
130  {
131  wxGridTableMessage msg( this,
132  wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
133  aPos,
134  aNumRows );
135 
136  GetView()->ProcessTableMessage( msg );
137  }
138 
139  return true;
140  }
141 
142  return false;
143  }
virtual LIB_TABLE_ROWS_ITER insert(LIB_TABLE_ROWS_ITER aIterator, LIB_TABLE_ROW *aRow)=0
virtual LIB_TABLE_ROW * makeNewRow()=0
virtual LIB_TABLE_ROWS_ITER begin()=0
virtual size_t size() const =0
size_t i
Definition: json11.cpp:597

References LIB_TABLE_GRID::begin(), i, LIB_TABLE_GRID::insert(), LIB_TABLE_GRID::makeNewRow(), and LIB_TABLE_GRID::size().

◆ 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 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 LIB_TABLE::fallBack, LIB_TABLE::IsEmpty(), and LIB_TABLE::rows.

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

◆ IsEmptyCell()

bool LIB_TABLE_GRID::IsEmptyCell ( int  aRow,
int  aCol 
)
inlineoverrideinherited

Definition at line 114 of file lib_table_grid.h.

115  {
116  return !GetValue( aRow, aCol );
117  }
wxString GetValue(int aRow, int aCol) override

References LIB_TABLE_GRID::GetValue().

◆ IsSymbolLibWritable()

bool SYMBOL_LIB_TABLE::IsSymbolLibWritable ( const wxString &  aNickname)
inherited

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

408 {
409  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
410  wxCHECK( row && row->plugin, false );
411  return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) );
412 }
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 SYMBOL_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), and SYMBOL_LIB_TABLE_ROW::plugin.

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

◆ LoadGlobalTable()

bool SYMBOL_LIB_TABLE::LoadGlobalTable ( SYMBOL_LIB_TABLE aTable)
staticinherited

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

469 {
470  bool tableExists = true;
471  wxFileName fn = GetGlobalTableFileName();
472 
473  if( !fn.FileExists() )
474  {
475  tableExists = false;
476 
477  if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
478  {
479  THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path \"%s\"." ),
480  GetChars( fn.GetPath() ) ) );
481  }
482 
483  // Attempt to copy the default global file table from the KiCad
484  // template folder to the user's home configuration path.
485  SEARCH_STACK ss;
486 
487  SystemDirsAppend( &ss );
488 
489  wxString templatePath =
490  Pgm().GetLocalEnvVariables().at( wxT( "KICAD_TEMPLATE_DIR" ) ).GetValue();
491 
492  if( !templatePath.IsEmpty() )
493  ss.AddPaths( templatePath, 0 );
494 
495  wxString fileName = ss.FindValidPath( global_tbl_name );
496 
497  // The fallback is to create an empty global symbol table for the user to populate.
498  if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
499  {
500  SYMBOL_LIB_TABLE emptyTable;
501 
502  emptyTable.Save( fn.GetFullPath() );
503  }
504  }
505 
506  aTable.Load( fn.GetFullPath() );
507 
508  return tableExists;
509 }
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:73
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
static const wxString global_tbl_name("sym-lib-table")
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
#define THROW_IO_ERROR(msg)
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
VTBL_ENTRY const ENV_VAR_MAP & GetLocalEnvVariables() const
Definition: pgm_base.h:325
#define _(s)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
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:205
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
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(), GetChars(), SYMBOL_LIB_TABLE::GetGlobalTableFileName(), PGM_BASE::GetLocalEnvVariables(), 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_ALIAS * SYMBOL_LIB_TABLE::LoadSymbol ( const wxString &  aNickname,
const wxString &  aAliasName 
)
inherited

Load a LIB_ALIAS having aAliasName from the library given by aNickname.

The actual symbol can be retreaved from the LIB_ALIAS::GetPart() method.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW
aAliasNameis the name of the LIB_ALIAS to load.
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 aAliasName cannot be found.

Definition at line 337 of file symbol_lib_table.cpp.

338 {
339  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
340  wxCHECK( row && row->plugin, nullptr );
341 
342  LIB_ALIAS* ret = row->plugin->LoadSymbol( row->GetFullURI( true ), aAliasName,
343  row->GetProperties() );
344 
345  // The library cannot know its own name, because it might have been renamed or moved.
346  // Therefore footprints cannot know their own library nickname when residing in
347  // a symbol library.
348  // Only at this API layer can we tell the symbol about its actual library nickname.
349  if( ret )
350  {
351  // remove "const"-ness, I really do want to set nickname without
352  // having to copy the LIB_ID and its two strings, twice each.
353  LIB_ID& id = (LIB_ID&) ret->GetPart()->GetLibId();
354 
355  id.SetLibNickname( row->GetNickName() );
356  }
357 
358  return ret;
359 }
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...
Part library alias object definition.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
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
const LIB_ID & GetLibId() const
LIB_PART * GetPart() const
Get the shared LIB_PART.
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).

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

Referenced by FOOTPRINT_INFO_GENERATOR::GenerateHtml(), LIB_MANAGER::GetAlias(), LIB_MANAGER::GetBufferedPart(), LIB_MANAGER::getOriginalParts(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), LIB_MANAGER::PartExists(), SCH_COMPONENT::Resolve(), SchGetLibAlias(), and SCH_COMPONENT::SetLibId().

◆ LoadSymbol() [2/2]

LIB_ALIAS* SYMBOL_LIB_TABLE::LoadSymbol ( const LIB_ID aLibId)
inlineinherited

Definition at line 178 of file symbol_lib_table.h.

179  {
180  return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
181  }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
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 SYMBOL_LIB_TABLE::LoadSymbol().

◆ LoadSymbolLib()

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

Definition at line 306 of file symbol_lib_table.cpp.

308 {
309  SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
310  wxCHECK( row && row->plugin, /* void */ );
311 
312  wxString options = row->GetOptions();
313 
314  if( aPowerSymbolsOnly )
315  row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly );
316 
317  row->plugin->EnumerateSymbolLib( aAliasList, row->GetFullURI( true ), row->GetProperties() );
318 
319  if( aPowerSymbolsOnly )
320  row->SetOptions( options );
321 
322  // The library cannot know its own name, because it might have been renamed or moved.
323  // Therefore footprints cannot know their own library nickname when residing in
324  // a symbol library.
325  // Only at this API layer can we tell the symbol about its actual library nickname.
326  for( LIB_ALIAS* alias : aAliasList )
327  {
328  // remove "const"-ness, I really do want to set nickname without
329  // having to copy the LIB_ID and its two strings, twice each.
330  LIB_ID& id = (LIB_ID&) alias->GetPart()->GetLibId();
331 
332  id.SetLibNickname( row->GetNickName() );
333  }
334 }
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...
Part library alias object definition.
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...
const wxString & GetNickName() const
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 SYMBOL_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetOptions(), LIB_TABLE_ROW::GetProperties(), SYMBOL_LIB_TABLE_ROW::plugin, SYMBOL_LIB_TABLE::PropPowerSymsOnly, LIB_ID::SetLibNickname(), and LIB_TABLE_ROW::SetOptions().

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), and LIB_MANAGER::GetAliases().

◆ LoadSymbolWithOptionalNickname()

LIB_ALIAS * SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname ( const LIB_ID aId)
inherited

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

432 {
433  wxString nickname = aLibId.GetLibNickname();
434  wxString name = aLibId.GetLibItemName();
435 
436  if( nickname.size() )
437  {
438  return LoadSymbol( nickname, name );
439  }
440 
441  // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
442  else
443  {
444  std::vector<wxString> nicks = GetLogicalLibs();
445 
446  // Search each library going through libraries alphabetically.
447  for( unsigned i = 0; i < nicks.size(); ++i )
448  {
449  // FootprintLoad() returns NULL on not found, does not throw exception
450  // unless there's an IO_ERROR.
451  LIB_ALIAS* ret = LoadSymbol( nicks[i], name );
452 
453  if( ret )
454  return ret;
455  }
456 
457  return NULL;
458  }
459 }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
Part library alias object definition.
const char * name
Definition: DXF_plotter.cpp:61
size_t i
Definition: json11.cpp:597
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(), i, SYMBOL_LIB_TABLE::LoadSymbol(), and name.

◆ makeNewRow()

LIB_TABLE_ROW* SYMBOL_LIB_TABLE_GRID::makeNewRow ( )
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 58 of file panel_sym_lib_table.cpp.

59  {
60  return dynamic_cast< LIB_TABLE_ROW* >( new SYMBOL_LIB_TABLE_ROW );
61  }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...

◆ operator!=()

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

Definition at line 340 of file lib_table_base.h.

340 { 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 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:597

References i, and LIB_TABLE::rows.

◆ Parse()

void SYMBOL_LIB_TABLE::Parse ( LIB_TABLE_LEXER *  aLexer)
overridevirtualinherited

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

86 {
87  T tok;
88  wxString errMsg; // to collect error messages
89 
90  // This table may be nested within a larger s-expression, or not.
91  // Allow for parser of that optional containing s-epression to have looked ahead.
92  if( in->CurTok() != T_sym_lib_table )
93  {
94  in->NeedLEFT();
95  if( ( tok = in->NextTok() ) != T_sym_lib_table )
96  in->Expecting( T_sym_lib_table );
97  }
98 
99  while( ( tok = in->NextTok() ) != T_RIGHT )
100  {
101  std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row( new SYMBOL_LIB_TABLE_ROW );
102 
103  if( tok == T_EOF )
104  in->Expecting( T_RIGHT );
105 
106  if( tok != T_LEFT )
107  in->Expecting( T_LEFT );
108 
109  // in case there is a "row integrity" error, tell where later.
110  int lineNum = in->CurLineNumber();
111 
112  if( ( tok = in->NextTok() ) != T_lib )
113  in->Expecting( T_lib );
114 
115  // (name NICKNAME)
116  in->NeedLEFT();
117 
118  if( ( tok = in->NextTok() ) != T_name )
119  in->Expecting( T_name );
120 
121  in->NeedSYMBOLorNUMBER();
122 
123  row->SetNickName( in->FromUTF8() );
124 
125  in->NeedRIGHT();
126 
127  // After (name), remaining (lib) elements are order independent, and in
128  // some cases optional.
129  bool sawType = false;
130  bool sawOpts = false;
131  bool sawDesc = false;
132  bool sawUri = false;
133  bool sawDisabled = false;
134 
135  while( ( tok = in->NextTok() ) != T_RIGHT )
136  {
137  if( tok == T_EOF )
138  in->Unexpected( T_EOF );
139 
140  if( tok != T_LEFT )
141  in->Expecting( T_LEFT );
142 
143  tok = in->NeedSYMBOLorNUMBER();
144 
145  switch( tok )
146  {
147  case T_uri:
148  if( sawUri )
149  in->Duplicate( tok );
150  sawUri = true;
151  in->NeedSYMBOLorNUMBER();
152  row->SetFullURI( in->FromUTF8() );
153  break;
154 
155  case T_type:
156  if( sawType )
157  in->Duplicate( tok );
158  sawType = true;
159  in->NeedSYMBOLorNUMBER();
160  row->SetType( in->FromUTF8() );
161  break;
162 
163  case T_options:
164  if( sawOpts )
165  in->Duplicate( tok );
166  sawOpts = true;
167  in->NeedSYMBOLorNUMBER();
168  row->SetOptions( in->FromUTF8() );
169  break;
170 
171  case T_descr:
172  if( sawDesc )
173  in->Duplicate( tok );
174  sawDesc = true;
175  in->NeedSYMBOLorNUMBER();
176  row->SetDescr( in->FromUTF8() );
177  break;
178 
179  case T_disabled:
180  if( sawDisabled )
181  in->Duplicate( tok );
182  sawDisabled = true;
183  row->SetEnabled( false );
184  break;
185 
186  default:
187  in->Unexpected( tok );
188  }
189 
190  in->NeedRIGHT();
191  }
192 
193  if( !sawType )
194  in->Expecting( T_type );
195 
196  if( !sawUri )
197  in->Expecting( T_uri );
198 
199  // all nickNames within this table fragment must be unique, so we do not
200  // use doReplace in InsertRow(). (However a fallBack table can have a
201  // conflicting nickName and ours will supercede that one since in
202  // FindLib() we search this table before any fall back.)
203  wxString nickname = row->GetNickName(); // store it to be able to used it
204  // after row deletion if an error occurs
205  LIB_TABLE_ROW* tmp = row.release();
206 
207  if( !InsertRow( tmp ) )
208  {
209  delete tmp; // The table did not take ownership of the row.
210 
211  wxString msg = wxString::Format(
212  _( "Duplicate library nickname \"%s\" found in symbol library "
213  "table file line %d" ), GetChars( nickname ), lineNum );
214 
215  if( !errMsg.IsEmpty() )
216  errMsg << '\n';
217 
218  errMsg << msg;
219  }
220  }
221 
222  if( !errMsg.IsEmpty() )
223  THROW_IO_ERROR( errMsg );
224 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
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.
#define THROW_IO_ERROR(msg)
#define _(s)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
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:205

References _, Format(), GetChars(), 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 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().

◆ push_back()

void SYMBOL_LIB_TABLE_GRID::push_back ( LIB_TABLE_ROW aRow)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 70 of file panel_sym_lib_table.cpp.

70 { rows.push_back( aRow ); }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ reindex()

void LIB_TABLE::reindex ( )
inlineprotectedinherited

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 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 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 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 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 LIB_TABLE::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().

◆ SaveSymbol()

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

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

364 {
365  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
366  wxCHECK( row && row->plugin, SAVE_SKIPPED );
367 
368  if( !aOverwrite )
369  {
370  // Try loading the footprint to see if it already exists, caller wants overwrite
371  // protection, which is atypical, not the default.
372 
373  wxString name = aSymbol->GetLibId().GetLibItemName();
374 
375  std::unique_ptr< LIB_ALIAS > symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
376  name,
377  row->GetProperties() ) );
378 
379  if( symbol.get() )
380  return SAVE_SKIPPED;
381  }
382 
383  row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
384 
385  return SAVE_OK;
386 }
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...
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 LIB_ID & GetLibId() const
const char * name
Definition: DXF_plotter.cpp:61
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

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

◆ SetValue()

void LIB_TABLE_GRID::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
inlineoverrideinherited

Definition at line 88 of file lib_table_grid.h.

89  {
90  if( aRow < (int) size() )
91  {
92  LIB_TABLE_ROW* r = at( (size_t) aRow );
93 
94  switch( aCol )
95  {
96  case COL_NICKNAME: r->SetNickName( aValue ); break;
97  case COL_URI: r->SetFullURI( aValue ); break;
98  case COL_TYPE: r->SetType( aValue ); break;
99  case COL_OPTIONS: r->SetOptions( aValue ); break;
100  case COL_DESCR: r->SetDescr( aValue ); break;
101  case COL_ENABLED:
102  r->SetEnabled( aValue == wxT( "1" ) );
103  break;
104  }
105  }
106  }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
virtual void SetType(const wxString &aType)=0
Change the type of library represented by this row that must be implemented in the derived object to ...
virtual LIB_TABLE_ROW * at(size_t aIndex)=0
void SetEnabled(bool aEnabled=true)
Change the enabled status of this library.
virtual size_t size() const =0
void SetFullURI(const wxString &aFullURI)
Change the full URI for the library.
void SetNickName(const wxString &aNickName)
Change the logical name of this library, useful for an editor.
void SetOptions(const wxString &aOptions)
Change the library options strings.
void SetDescr(const wxString &aDescr)
Change the description of the library referenced by this row.

References LIB_TABLE_GRID::at(), COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, LIB_TABLE_ROW::SetDescr(), LIB_TABLE_ROW::SetEnabled(), LIB_TABLE_ROW::SetFullURI(), LIB_TABLE_ROW::SetNickName(), LIB_TABLE_ROW::SetOptions(), LIB_TABLE_ROW::SetType(), and LIB_TABLE_GRID::size().

◆ SetValueAsBool()

void LIB_TABLE_GRID::SetValueAsBool ( int  aRow,
int  aCol,
bool  aValue 
)
inlineoverrideinherited

Definition at line 108 of file lib_table_grid.h.

109  {
110  if( aRow < (int) size() && aCol == COL_ENABLED )
111  at( (size_t) aRow )->SetEnabled( aValue );
112  }
virtual LIB_TABLE_ROW * at(size_t aIndex)=0
void SetEnabled(bool aEnabled=true)
Change the enabled status of this library.
virtual size_t size() const =0

References LIB_TABLE_GRID::at(), COL_ENABLED, LIB_TABLE_ROW::SetEnabled(), and LIB_TABLE_GRID::size().

◆ size()

size_t SYMBOL_LIB_TABLE_GRID::size ( ) const
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 56 of file panel_sym_lib_table.cpp.

56 { return rows.size(); }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ Type()

KICAD_T SYMBOL_LIB_TABLE::Type ( )
inlineoverridevirtualinherited

Implements PROJECT::_ELEM.

Definition at line 110 of file symbol_lib_table.h.

References SYMBOL_LIB_TABLE_T.

Friends And Related Function Documentation

◆ SYMBOL_GRID_TRICKS

friend class SYMBOL_GRID_TRICKS
friend

Definition at line 51 of file panel_sym_lib_table.cpp.

Member Data Documentation

◆ fallBack

LIB_TABLE* LIB_TABLE::fallBack
protectedinherited

◆ nickIndex

INDEX LIB_TABLE::nickIndex
protectedinherited

this particular key is the nickName within each row.

Definition at line 529 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"
staticinherited

Definition at line 113 of file symbol_lib_table.h.

◆ PropPowerSymsOnly

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

◆ rows


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