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, bool aCheckIfEnabled=false)
 Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table fragment. More...
 
int GetModifyHash ()
 
void EnumerateSymbolLib (const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
 Return a list of symbol alias names contained within the library given by aNickname. More...
 
void LoadSymbolLib (std::vector< LIB_PART * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
 
LIB_PARTLoadSymbol (const wxString &aNickname, const wxString &aName)
 Load a LIB_PART having aName from the library given by aNickname. More...
 
LIB_PARTLoadSymbol (const LIB_ID &aLibId)
 
SAVE_T SaveSymbol (const wxString &aNickname, const LIB_PART *aSymbol, bool aOverwrite=true)
 Write aSymbol to an existing library given by aNickname. More...
 
void DeleteSymbol (const wxString &aNickname, const wxString &aSymbolName)
 Deletes the aSymbolName from the library given by aNickname. More...
 
bool IsSymbolLibWritable (const wxString &aNickname)
 Return true if the library given by aNickname is writable. More...
 
bool IsSymbolLibLoaded (const wxString &aNickname)
 Return true if the library given by aNickname was successfully loaded. More...
 
void DeleteSymbolLib (const wxString &aNickname)
 
void CreateSymbolLib (const wxString &aNickname)
 
LIB_PARTLoadSymbolWithOptionalNickname (const LIB_ID &aId)
 Load a LIB_PART having aFootprintId with possibly an empty library nickname. More...
 
void Clear ()
 Delete all rows. More...
 
bool operator== (const LIB_TABLE &r) const
 Compares this table against another. More...
 
bool operator!= (const LIB_TABLE &r) const
 
unsigned GetCount () const
 Get the number of rows contained in the table. More...
 
LIB_TABLE_ROWAt (unsigned aIndex)
 Get the 'n'th LIB_TABLE_ROW object. More...
 
const LIB_TABLE_ROWAt (unsigned aIndex) const
 Get the 'n'th LIB_TABLE_ROW object. More...
 
bool IsEmpty (bool aIncludeFallback=true)
 Return true if the table is empty. More...
 
const wxString GetDescription (const wxString &aNickname)
 
bool HasLibrary (const wxString &aNickname, bool aCheckEnabled=false) const
 Test for the existence of aNickname in the library table. More...
 
std::vector< wxString > GetLogicalLibs ()
 Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE. More...
 
wxString GetFullURI (const wxString &aLibNickname, bool aExpandEnvVars=true) const
 Return the full URI of the library mapped to aLibNickname. More...
 
bool InsertRow (LIB_TABLE_ROW *aRow, bool doReplace=false)
 Adds aRow if it does not already exist or if doReplace is true. More...
 
bool RemoveRow (LIB_TABLE_ROW *aRow)
 Removes a row from the table. More...
 
const LIB_TABLE_ROWFindRowByURI (const wxString &aURI)
 
void Load (const wxString &aFileName)
 Load the library table using the path defined by aFileName aFallBackTable. More...
 
void Save (const wxString &aFileName) const
 Write this library table to aFileName in s-expression form. More...
 

Static Public Member Functions

static bool LoadGlobalTable (SYMBOL_LIB_TABLE &aTable)
 Load the global symbol library table into aTable. More...
 
static wxString GetGlobalTableFileName ()
 Fetch the global symbol library table file name. More...
 
static const wxString GlobalPathEnvVariableName ()
 Return the name of the environment variable used to hold the directory of locally installed "KiCad sponsored" system symbol libraries. More...
 
static SYMBOL_LIB_TABLEGetGlobalLibTable ()
 
static const wxString & GetSymbolLibTableFileName ()
 
static PROPERTIESParseOptions (const std::string &aOptionsList)
 Parses aOptionsList and places the result into a PROPERTIES object which is returned. More...
 
static UTF8 FormatOptions (const PROPERTIES *aProperties)
 Returns a list of options from the aProperties parameter. More...
 

Static Public Attributes

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

Protected Types

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

Protected Member Functions

LIB_TABLE_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, bool aCheckIfEnabled=false) const
 Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment, else NULL. More...
 
void reindex ()
 
void ensureIndex ()
 

Protected Attributes

LIB_TABLE_ROWS rows
 
INDEX nickIndex
 this particular key is the nickName within each row. More...
 
LIB_TABLEfallBack
 
std::recursive_mutex m_nickIndexMutex
 Mutex to protect access to the nickIndex variable. More...
 

Friends

class SYMBOL_GRID_TRICKS
 

Detailed Description

Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.

Definition at line 78 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 534 of file lib_table_base.h.

◆ INDEX_CITER

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protectedinherited

Definition at line 536 of file lib_table_base.h.

◆ INDEX_ITER

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protectedinherited

Definition at line 535 of file lib_table_base.h.

◆ INDEX_VALUE

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protectedinherited

Definition at line 537 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 182 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 108 of file panel_sym_lib_table.cpp.

109  {
110  rows = aTableToEdit.rows;
111  }
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, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, aNumRows );
154  GetView()->ProcessTableMessage( msg );
155  }
156 
157  return true;
158  }
virtual LIB_TABLE_ROW * makeNewRow()=0
virtual void push_back(LIB_TABLE_ROW *aRow)=0

References 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 83 of file panel_sym_lib_table.cpp.

83 { 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 365 of file lib_table_base.h.

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

References LIB_TABLE::rows.

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

◆ At() [2/2]

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

Get the 'n'th LIB_TABLE_ROW object.

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

Definition at line 373 of file lib_table_base.h.

374  {
375  return rows[aIndex];
376  }
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 92 of file panel_sym_lib_table.cpp.

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

References LIB_TABLE::rows.

◆ Clear()

void LIB_TABLE::Clear ( )
inlineinherited

Delete all rows.

Definition at line 320 of file lib_table_base.h.

321  {
322  std::lock_guard<std::recursive_mutex> lock( m_nickIndexMutex );
323 
324  rows.clear();
325  nickIndex.clear();
326  }
LIB_TABLE_ROWS rows
std::recursive_mutex m_nickIndexMutex
Mutex to protect access to the nickIndex variable.
INDEX nickIndex
this particular key is the nickName within each row.

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

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

◆ ContainsNickname()

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

Definition at line 196 of file lib_table_grid.h.

197  {
198  for( size_t i = 0; i < size(); ++i )
199  {
200  LIB_TABLE_ROW* row = at( i );
201 
202  if( row->GetNickName() == aNickname )
203  return true;
204  }
205  return false;
206  }
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

References LIB_TABLE_GRID::at(), LIB_TABLE_ROW::GetNickName(), 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 450 of file symbol_lib_table.cpp.

451 {
452  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
453  wxCHECK( row && row->plugin, /* void */ );
454  row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() );
455 }
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).
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...

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

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary().

◆ DeleteRows()

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

Definition at line 160 of file lib_table_grid.h.

161  {
162  // aPos may be a large positive, e.g. size_t(-1), and the sum of
163  // aPos+aNumRows may wrap here, so both ends of the range are tested.
164  if( aPos < size() && aPos + aNumRows <= size() )
165  {
166  LIB_TABLE_ROWS_ITER start = begin() + aPos;
167  erase( start, start + aNumRows );
168  if( GetView() )
169  {
170  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPos, aNumRows );
171  GetView()->ProcessTableMessage( msg );
172  }
173  return true;
174  }
175 
176  return false;
177  }
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 418 of file symbol_lib_table.cpp.

419 {
420  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
421  wxCHECK( row && row->plugin, /* void */ );
422  return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName,
423  row->GetProperties() );
424 }
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).
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...

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

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

◆ DeleteSymbolLib()

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

Definition at line 442 of file symbol_lib_table.cpp.

443 {
444  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
445  wxCHECK( row && row->plugin, /* void */ );
446  row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() );
447 }
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).
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...

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

516  {
517  std::lock_guard<std::recursive_mutex> lock( m_nickIndexMutex );
518 
519  // The dialog lib table editor may not maintain the nickIndex.
520  // Lazy indexing may be required. To handle lazy indexing, we must enforce
521  // that "nickIndex" is either empty or accurate, but never inaccurate.
522  if( !nickIndex.size() )
523  reindex();
524  }
void reindex()
std::recursive_mutex m_nickIndexMutex
Mutex to protect access to the nickIndex variable.
INDEX nickIndex
this particular key is the nickName within each row.

References LIB_TABLE::m_nickIndexMutex, LIB_TABLE::nickIndex, and LIB_TABLE::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 282 of file symbol_lib_table.cpp.

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

Referenced by SYMBOL_LIBRARY_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 101 of file panel_sym_lib_table.cpp.

102  {
103  return rows.erase( aFirst, aLast );
104  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ FindRow()

SYMBOL_LIB_TABLE_ROW * SYMBOL_LIB_TABLE::FindRow ( const wxString &  aNickName,
bool  aCheckIfEnabled = false 
)
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.
aCheckIfEnabledis a flag to verify if the table entry is enabled or disabled.
Returns
the row found or NULL if aNickName was not found.

Definition at line 302 of file symbol_lib_table.cpp.

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

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

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

◆ findRow()

LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname,
bool  aCheckIfEnabled = false 
) const
protectedinherited

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

Parameters
aNicknameis the name of the library table entry to find.
aCheckIfEnabledis a flag to check if the library table entry is enabled.
Returns
a pointer to the LIB_TABLE_ROW found.

Definition at line 183 of file lib_table_base.cpp.

184 {
185  LIB_TABLE_ROW* row = nullptr;
186  LIB_TABLE* cur = (LIB_TABLE*) this;
187 
188  std::lock_guard<std::recursive_mutex> lock( m_nickIndexMutex );
189 
190  do
191  {
192  cur->ensureIndex();
193 
194  for( const std::pair<const wxString, int>& entry : cur->nickIndex )
195  {
196  if( entry.first == aNickName )
197  {
198  row = &cur->rows[entry.second];
199 
200  if( !aCheckIfEnabled || ( aCheckIfEnabled && row->GetIsEnabled() ) )
201  return row;
202  }
203  }
204 
205  // Repeat, this time looking for names that were "fixed" by legacy versions because
206  // the old eeschema file format didn't support spaces in tokens.
207  for( const std::pair<const wxString, int>& entry : cur->nickIndex )
208  {
209  wxString legacyLibName = entry.first;
210  legacyLibName.Replace( " ", "_" );
211 
212  if( legacyLibName == aNickName )
213  {
214  row = &cur->rows[entry.second];
215 
216  if( !aCheckIfEnabled || ( aCheckIfEnabled && row->GetIsEnabled() ) )
217  return row;
218  }
219  }
220 
221  // not found, search fall back table(s), if any
222  } while( ( cur = cur->fallBack ) != 0 );
223 
224  return nullptr; // not found
225 }
void ensureIndex()
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
bool GetIsEnabled() const
std::recursive_mutex m_nickIndexMutex
Mutex to protect access to the nickIndex variable.
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_ROW::GetIsEnabled(), LIB_TABLE::m_nickIndexMutex, 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().

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

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

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

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

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

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

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

◆ FormatOptions()

UTF8 LIB_TABLE::FormatOptions ( const PROPERTIES aProperties)
staticinherited

Returns a list of options from the aProperties parameter.

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

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

Definition at line 411 of file lib_table_base.cpp.

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

180  {
181  switch( aCol )
182  {
183  case COL_NICKNAME: return _( "Nickname" );
184  case COL_URI: return _( "Library Path" );
185 
186  // keep this "Plugin Type" text fairly long so column is sized wide enough
187  case COL_TYPE: return _( "Plugin Type" );
188  case COL_OPTIONS: return _( "Options" );
189  case COL_DESCR: return _( "Description" );
190  case COL_ENABLED: return _( "Active" );
191 
192  default: return wxEmptyString;
193  }
194  }
#define _(s)
Definition: 3d_actions.cpp:33

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

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

References LIB_TABLE::rows.

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

◆ GetDescription()

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

Definition at line 147 of file lib_table_base.cpp.

148 {
149  // Use "no exception" form of find row and ignore disabled flag.
150  const LIB_TABLE_ROW* row = findRow( aNickname );
151 
152  if( row )
153  return row->GetDescr();
154  else
155  return wxEmptyString;
156 }
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, bool aCheckIfEnabled=false) 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::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), SYMBOL_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 170 of file lib_table_base.cpp.

171 {
172  const LIB_TABLE_ROW* row = findRow( aNickname, true );
173 
174  wxString retv;
175 
176  if( row )
177  retv = row->GetFullURI( aExpandEnvVars );
178 
179  return retv;
180 }
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, bool aCheckIfEnabled=false) 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_XML::makeLibraries(), and FOOTPRINT_EDITOR_CONTROL::SaveAs().

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

540 {
541  wxFileName fn;
542 
544  fn.SetName( global_tbl_name );
545 
546  return fn.GetFullPath();
547 }
static const wxString global_tbl_name("sym-lib-table")
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.

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

Referenced by SYMBOL_EDIT_FRAME::addLibTableEntry(), DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::GetGlobalTableFileName(), InvokeSchEditSymbolLibTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), SCH::IFACE::OnKifaceStart(), SYMBOL_EDIT_FRAME::replaceLibTableEntry(), SCH_BASE_FRAME::saveSymbolLibTables(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ GetLogicalLibs()

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

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

Definition at line 264 of file lib_table_base.cpp.

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

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

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), CVPCB_MAINFRAME::BuildLibrariesListBox(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FP_LIB_TABLE::GenerateTimestamp(), GetFootprintLibraries(), SYMBOL_LIBRARY_MANAGER::GetLibraryCount(), SYMBOL_LIB_TABLE::GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), FOOTPRINT_VIEWER_FRAME::OnActivate(), SYMBOL_VIEWER_FRAME::OnSelectSymbol(), SCH_BASE_FRAME::PickSymbolFromLibTree(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), SYMBOL_EDIT_FRAME::savePartAs(), PCB_BASE_FRAME::SelectLibrary(), FOOTPRINT_LIST_IMPL::startWorkers(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ GetModifyHash()

int SYMBOL_LIB_TABLE::GetModifyHash ( )
inherited

Definition at line 258 of file symbol_lib_table.cpp.

259 {
260  int hash = 0;
261  std::vector< wxString > libNames = GetLogicalLibs();
262 
263  for( const auto& libName : libNames )
264  {
265  const SYMBOL_LIB_TABLE_ROW* row = FindRow( libName, true );
266 
267  if( !row || !row->plugin )
268  {
269  wxFAIL;
270  continue;
271  }
272 
273  hash += row->plugin->GetModifyHash();
274  }
275 
276  hash += m_modifyHash;
277 
278  return hash;
279 }
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()
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
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 SYMBOL_LIBRARY_MANAGER::GetHash(), and SYMBOL_LIBRARY_MANAGER::Sync().

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

490 {
491  return "KICAD6_SYMBOL_DIR";
492 }

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

160 {
161  const LIB_TABLE_ROW* row = findRow( aNickname, aCheckEnabled );
162 
163  if( row == nullptr )
164  return false;
165 
166  return true;
167 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
LIB_TABLE_ROW * findRow(const wxString &aNickname, bool aCheckIfEnabled=false) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment,...

References LIB_TABLE::findRow().

Referenced by SYMBOL_EDIT_FRAME::addLibTableEntry(), CVPCB_MAINFRAME::DisplayStatus(), FOOTPRINT_EDIT_FRAME::KiwayMailIn(), SYMBOL_EDIT_FRAME::KiwayMailIn(), SYMBOL_LIBRARY_MANAGER::LibraryExists(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), SCH_ALTIUM_PLUGIN::Load(), SCH_EAGLE_PLUGIN::Load(), SCH_EDIT_FRAME::LoadSheetFromFile(), NETLIST_EXPORTER_XML::makeLibraries(), SCH_BASE_FRAME::PickSymbolFromLibTree(), SYMBOL_VIEWER_FRAME::ShowModal(), FOOTPRINT_VIEWER_FRAME::ShowModal(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), ERC_TESTER::TestLibSymbolIssues(), and SCH_SCREEN::UpdateSymbolLinks().

◆ 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 94 of file panel_sym_lib_table.cpp.

95  {
96  return rows.insert( aIterator, aRow );
97  }
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 304 of file lib_table_base.cpp.

305 {
306  std::lock_guard<std::recursive_mutex> lock( m_nickIndexMutex );
307 
308  ensureIndex();
309 
310  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
311 
312  if( it == nickIndex.end() )
313  {
314  rows.push_back( aRow );
315  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
316  return true;
317  }
318 
319  if( doReplace )
320  {
321  rows.replace( it->second, aRow );
322  return true;
323  }
324 
325  return false;
326 }
void ensureIndex()
INDEX::const_iterator INDEX_CITER
LIB_TABLE_ROWS rows
INDEX::value_type INDEX_VALUE
const wxString & GetNickName() const
std::recursive_mutex m_nickIndexMutex
Mutex to protect access to the nickIndex variable.
INDEX nickIndex
this particular key is the nickName within each row.

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

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), SYMBOL_LIBRARY_MANAGER::addLibrary(), SYMBOL_EDIT_FRAME::addLibTableEntry(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), LIB_TABLE_TEST_FIXTURE::LIB_TABLE_TEST_FIXTURE(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), SCH_ALTIUM_PLUGIN::Load(), SCH_EAGLE_PLUGIN::Load(), PCB_EDIT_FRAME::OpenProjectFiles(), 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

References LIB_TABLE_GRID::begin(), 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 138 of file lib_table_base.cpp.

139 {
140  if( !aIncludeFallback || !fallBack )
141  return rows.empty();
142 
143  return rows.empty() && fallBack->IsEmpty( true );
144 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.

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

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

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

◆ IsSymbolLibLoaded()

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

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

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

Definition at line 434 of file symbol_lib_table.cpp.

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

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

Referenced by SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded().

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

428 {
429  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
430  wxCHECK( row && row->plugin, false );
431  return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) );
432 }
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...
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...

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

Referenced by SYMBOL_LIBRARY_MANAGER::IsLibraryReadOnly().

◆ Load()

void LIB_TABLE::Load ( const wxString &  aFileName)
inherited

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

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

Definition at line 329 of file lib_table_base.cpp.

331 {
332  // It's OK if footprint library tables are missing.
333  if( wxFileName::IsFileReadable( aFileName ) )
334  {
335  FILE_LINE_READER reader( aFileName );
336  LIB_TABLE_LEXER lexer( &reader );
337 
338  Parse( &lexer );
339  }
340 }
A LINE_READER that reads from an open file.
Definition: richio.h:172
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(), SCH::IFACE::SaveFileAs(), DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ LoadGlobalTable()

bool SYMBOL_LIB_TABLE::LoadGlobalTable ( SYMBOL_LIB_TABLE aTable)
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 495 of file symbol_lib_table.cpp.

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

References _, SEARCH_STACK::AddPaths(), SEARCH_STACK::FindValidPath(), Format(), SYMBOL_LIB_TABLE::GetGlobalTableFileName(), global_tbl_name(), LIB_TABLE::Load(), Pgm(), LIB_TABLE::Save(), SystemDirsAppend(), and THROW_IO_ERROR.

Referenced by SCH::IFACE::OnKifaceStart(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ LoadSymbol() [1/2]

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

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

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

Definition at line 352 of file symbol_lib_table.cpp.

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

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

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

◆ LoadSymbol() [2/2]

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

Definition at line 174 of file symbol_lib_table.h.

175  {
176  return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
177  }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:106
LIB_PART * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_PART having aName from the library given by aNickname.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:92

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

◆ LoadSymbolLib()

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

Definition at line 320 of file symbol_lib_table.cpp.

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

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

◆ LoadSymbolWithOptionalNickname()

LIB_PART * 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 458 of file symbol_lib_table.cpp.

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

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

◆ makeNewRow()

LIB_TABLE_ROW* SYMBOL_LIB_TABLE_GRID::makeNewRow ( )
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 87 of file panel_sym_lib_table.cpp.

88  {
89  return dynamic_cast< LIB_TABLE_ROW* >( new SYMBOL_LIB_TABLE_ROW );
90  }
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 350 of file lib_table_base.h.

350 { 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 334 of file lib_table_base.h.

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

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

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

References _, Format(), LIB_TABLE::InsertRow(), and THROW_IO_ERROR.

Referenced by SYMBOL_GRID_TRICKS::paste_text().

◆ ParseOptions()

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

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

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

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

Definition at line 350 of file lib_table_base.cpp.

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

References name, and OPT_SEP.

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

◆ push_back()

void SYMBOL_LIB_TABLE_GRID::push_back ( LIB_TABLE_ROW aRow)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 99 of file panel_sym_lib_table.cpp.

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

References LIB_TABLE::rows.

◆ reindex()

void LIB_TABLE::reindex ( )
inlineprotectedinherited

Definition at line 505 of file lib_table_base.h.

506  {
507  std::lock_guard<std::recursive_mutex> lock( m_nickIndexMutex );
508 
509  nickIndex.clear();
510 
511  for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
512  nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
513  }
LIB_TABLE_ROWS rows
INDEX::value_type INDEX_VALUE
LIB_TABLE_ROWS::iterator LIB_TABLE_ROWS_ITER
std::recursive_mutex m_nickIndexMutex
Mutex to protect access to the nickIndex variable.
INDEX nickIndex
this particular key is the nickName within each row.

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

Referenced by 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 432 of file lib_table_base.h.

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

References LIB_TABLE::rows.

Referenced by SYMBOL_LIBRARY_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 343 of file lib_table_base.cpp.

344 {
345  FILE_OUTPUTFORMATTER sf( aFileName );
346  Format( &sf, 0 );
347 }
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
Used for text file output.
Definition: richio.h:453

References LIB_TABLE::Format().

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), SYMBOL_EDIT_FRAME::addLibTableEntry(), InvokePcbLibTableEditor(), InvokeSchEditSymbolLibTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), PCB_EDIT_FRAME::OpenProjectFiles(), SYMBOL_EDIT_FRAME::replaceLibTableEntry(), SCH::IFACE::SaveFileAs(), SCH_BASE_FRAME::saveSymbolLibTables(), DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ SaveSymbol()

SYMBOL_LIB_TABLE::SAVE_T SYMBOL_LIB_TABLE::SaveSymbol ( const wxString &  aNickname,
const LIB_PART aSymbol,
bool  aOverwrite = true 
)
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 because libraries cannot have duplicate alias names. It is the responsibility of the caller to check the library for conflicts before saving.

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

Definition at line 381 of file symbol_lib_table.cpp.

383 {
384  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
385  wxCHECK( row && row->plugin, SAVE_SKIPPED );
386 
387  if( !row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) ) )
388  return SAVE_SKIPPED;
389 
390  if( !aOverwrite )
391  {
392  // Try loading the footprint to see if it already exists, caller wants overwrite
393  // protection, which is atypical, not the default.
394 
395  wxString name = aSymbol->GetLibId().GetLibItemName();
396 
397  std::unique_ptr< LIB_PART > symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
398  name,
399  row->GetProperties() ) );
400 
401  if( symbol.get() )
402  return SAVE_SKIPPED;
403  }
404 
405  try
406  {
407  row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
408  }
409  catch( const IO_ERROR& )
410  {
411  return SAVE_SKIPPED;
412  }
413 
414  return SAVE_OK;
415 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:106
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
LIB_ID GetLibId() const override
Definition: lib_symbol.h:131
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
const char * name
Definition: DXF_plotter.cpp:59
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75

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

85 { 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 112 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 80 of file panel_sym_lib_table.cpp.

Member Data Documentation

◆ fallBack

LIB_TABLE* LIB_TABLE::fallBack
protectedinherited

◆ m_nickIndexMutex

std::recursive_mutex LIB_TABLE::m_nickIndexMutex
mutableprotectedinherited

Mutex to protect access to the nickIndex variable.

Definition at line 545 of file lib_table_base.h.

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

◆ nickIndex

INDEX LIB_TABLE::nickIndex
protectedinherited

this particular key is the nickName within each row.

Definition at line 540 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 115 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: