KiCad PCB EDA Suite
SYMBOL_LIB_TABLE Class Reference

#include <symbol_lib_table.h>

Inheritance diagram for 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

virtual void Parse (LIB_TABLE_LEXER *aLexer) override
 Function Parse. More...
 
virtual void Format (OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
 Generate the table in s-expression format to aOutput with an indention level of aIndentLevel. More...
 
 SYMBOL_LIB_TABLE (SYMBOL_LIB_TABLE *aFallBackTable=NULL)
 Build a symbol library table by pre-pending this table fragment in front of aFallBackTable. More...
 
const 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...
 
void EnumerateSymbolLib (const wxString &aNickname, wxArrayString &aAliasNames)
 Return a list of symbol alias names contained within the library given by aNickname. More...
 
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
 
bool operator!= (const LIB_TABLE &r) const
 
int GetCount ()
 
LIB_TABLE_ROWAt (int aIndex)
 
bool IsEmpty (bool aIncludeFallback=true)
 Function IsEmpty. More...
 
const wxString GetDescription (const wxString &aNickname)
 Function GetDescription. More...
 
std::vector< wxString > GetLogicalLibs ()
 Function GetLogicalLibs. More...
 
bool InsertRow (LIB_TABLE_ROW *aRow, bool doReplace=false)
 Function InsertRow. More...
 
const LIB_TABLE_ROWFindRowByURI (const wxString &aURI)
 Function FindRowByURI. More...
 
void Load (const wxString &aFileName)
 Function Load. More...
 
void Save (const wxString &aFileName) const
 Function Save. More...
 
size_t GetEnvVars (wxArrayString &aEnvVars) const
 Search the paths all of the LIB_TABLE_ROWS of the LIB_TABLE and add all of the environment variable substitutions to aEnvVars. 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)
 Function ParseOptions. More...
 
static UTF8 FormatOptions (const PROPERTIES *aProperties)
 Function FormatOptions. More...
 
static const wxString ExpandSubstitutions (const wxString &aString)
 Function ExpandSubstitutions. More...
 

Protected Types

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

Protected Member Functions

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

Detailed Description

Definition at line 95 of file symbol_lib_table.h.

Member Typedef Documentation

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

this is a non-owning index into the LIB_TABLE_ROWS table

Definition at line 506 of file lib_table_base.h.

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protectedinherited

Definition at line 508 of file lib_table_base.h.

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protectedinherited

Definition at line 507 of file lib_table_base.h.

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protectedinherited

Definition at line 509 of file lib_table_base.h.

Member Enumeration Documentation

The set of return values from SaveSymbol() below.

Enumerator
SAVE_OK 
SAVE_SKIPPED 

Definition at line 163 of file symbol_lib_table.h.

Constructor & Destructor Documentation

SYMBOL_LIB_TABLE::SYMBOL_LIB_TABLE ( SYMBOL_LIB_TABLE aFallBackTable = NULL)

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

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

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

Definition at line 64 of file symbol_lib_table.cpp.

64  :
65  LIB_TABLE( aFallBackTable )
66 {
67  // not copying fall back, simply search aFallBackTable separately
68  // if "nickName not found".
69 }
LIB_TABLE(LIB_TABLE *aFallBackTable=NULL)
Constructor LIB_TABLE builds a library table by pre-pending this table fragment in front of aFallBack...

Member Function Documentation

LIB_TABLE_ROW* LIB_TABLE::At ( int  aIndex)
inlineinherited

Definition at line 354 of file lib_table_base.h.

References LIB_TABLE::rows.

Referenced by FP_GRID_TRICKS::paste_text().

354 { return &rows[aIndex]; }
LIB_TABLE_ROWS rows
void LIB_TABLE::Clear ( )
inlineinherited

Delete all rows.

Definition at line 328 of file lib_table_base.h.

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

Referenced by DIALOG_FP_LIB_TABLE::onOKButtonClick().

329  {
330  rows.clear();
331  nickIndex.clear();
332  }
LIB_TABLE_ROWS rows
INDEX nickIndex
this particular key is the nickName within each row.
void SYMBOL_LIB_TABLE::CreateSymbolLib ( const wxString &  aNickname)

Definition at line 334 of file symbol_lib_table.cpp.

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

335 {
336  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
337  wxASSERT( (SCH_PLUGIN*) row->plugin );
338  row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() );
339 }
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:134
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const 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 PROPERTIES * GetProperties() const
Function GetProperties.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:184
void SYMBOL_LIB_TABLE::DeleteAlias ( const wxString &  aNickname,
const wxString &  aAliasName 
)

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

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

310 {
311  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
312  wxASSERT( (SCH_PLUGIN*) row->plugin );
313  return row->plugin->DeleteAlias( row->GetFullURI( true ), aAliasName,
314  row->GetProperties() );
315 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const 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 PROPERTIES * GetProperties() const
Function GetProperties.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:184
virtual void DeleteAlias(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Delete aAliasName from the library at aLibraryPath.
Definition: sch_plugin.cpp:118
void SYMBOL_LIB_TABLE::DeleteSymbol ( const wxString &  aNickname,
const wxString &  aSymbolName 
)

Deletes the aSymbolName from the library given by aNickname.

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

Definition at line 300 of file symbol_lib_table.cpp.

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

301 {
302  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
303  wxASSERT( (SCH_PLUGIN*) row->plugin );
304  return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName,
305  row->GetProperties() );
306 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const 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 PROPERTIES * GetProperties() const
Function GetProperties.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:126
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:184
void SYMBOL_LIB_TABLE::DeleteSymbolLib ( const wxString &  aNickname)

Definition at line 326 of file symbol_lib_table.cpp.

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

327 {
328  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
329  wxASSERT( (SCH_PLUGIN*) row->plugin );
330  row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() );
331 }
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Delete an existing symbol library and returns true if successful, or if library does not exist return...
Definition: sch_plugin.cpp:141
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const 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 PROPERTIES * GetProperties() const
Function GetProperties.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:184
void LIB_TABLE::ensureIndex ( )
inlineprotectedinherited

Definition at line 494 of file lib_table_base.h.

References LIB_TABLE::nickIndex, and LIB_TABLE::reindex().

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

495  {
496  // The dialog lib table editor may not maintain the nickIndex.
497  // Lazy indexing may be required. To handle lazy indexing, we must enforce
498  // that "nickIndex" is either empty or accurate, but never inaccurate.
499  if( !nickIndex.size() )
500  reindex();
501  }
void reindex()
INDEX nickIndex
this particular key is the nickName within each row.
void SYMBOL_LIB_TABLE::EnumerateSymbolLib ( const wxString &  aNickname,
wxArrayString &  aAliasNames 
)

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
Exceptions
IO_ERRORif the library cannot be found or loaded.

Definition at line 210 of file symbol_lib_table.cpp.

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

211 {
212  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
213  wxASSERT( (SCH_PLUGIN*) row->plugin );
214  row->plugin->EnumerateSymbolLib( aAliasNames, row->GetFullURI( true ), row->GetProperties() );
215 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const 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 PROPERTIES * GetProperties() const
Function GetProperties.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
virtual void EnumerateSymbolLib(wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Populate a list of LIB_PART alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:83
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:184
const wxString LIB_TABLE::ExpandSubstitutions ( const wxString &  aString)
staticinherited

Function ExpandSubstitutions.

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

References ExpandEnvVarSubstitutions().

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

513 {
514  return ExpandEnvVarSubstitutions( aString );
515 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Function ExpandEnvVarSubstitutions replaces any environment variable references with their values...
Definition: common.cpp:254
const SYMBOL_LIB_TABLE_ROW * SYMBOL_LIB_TABLE::FindRow ( const wxString &  aNickName)

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

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

Parameters
aNickNameis the name of the row to find.
Returns
the row found or NULL if aNickName was not found.
Exceptions
IO_ERRORif aNickName cannot be found.

Definition at line 218 of file symbol_lib_table.cpp.

References SCH_IO_MGR::FindPlugin(), 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 CreateSymbolLib(), DeleteAlias(), DeleteSymbol(), DeleteSymbolLib(), EnumerateSymbolLib(), IsSymbolLibWritable(), LoadSymbol(), and SaveSymbol().

220 {
221  SYMBOL_LIB_TABLE_ROW* row = dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname ) );
222 
223  if( !row )
224  {
225  wxString msg = wxString::Format(
226  _( "sym-lib-table files contain no library with nickname '%s'" ),
227  GetChars( aNickname ) );
228 
229  THROW_IO_ERROR( msg );
230  }
231 
232  // We've been 'lazy' up until now, but it cannot be deferred any longer,
233  // instantiate a PLUGIN of the proper kind if it is not already in this
234  // SYMBOL_LIB_TABLE_ROW.
235  if( !row->plugin )
236  row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) );
237 
238  return row;
239 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
static SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Return a SCH_PLUGIN which the caller can use to import, export, save, or load design documents...
Definition: sch_io_mgr.cpp:48
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void setPlugin(SCH_PLUGIN *aPlugin)
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Function findRow returns a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBa...
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:92
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 * LIB_TABLE::findRow ( const wxString &  aNickname) const
protectedinherited

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

Definition at line 254 of file lib_table_base.cpp.

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

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

255 {
256  LIB_TABLE* cur = (LIB_TABLE*) this;
257 
258  do
259  {
260  cur->ensureIndex();
261 
262  INDEX_CITER it = cur->nickIndex.find( aNickName );
263 
264  if( it != cur->nickIndex.end() )
265  {
266  return &cur->rows[it->second]; // found
267  }
268 
269  // not found, search fall back table(s), if any
270  } while( ( cur = cur->fallBack ) != 0 );
271 
272  return NULL; // not found
273 }
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.
Class LIB_TABLE.
const LIB_TABLE_ROW * LIB_TABLE::FindRowByURI ( const wxString &  aURI)
inherited

Function FindRowByURI.

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

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

277 {
278  LIB_TABLE* cur = this;
279 
280  do
281  {
282  cur->ensureIndex();
283 
284  for( unsigned i = 0; i < cur->rows.size(); i++ )
285  {
286  wxString uri = cur->rows[i].GetFullURI( true );
287 
288  if( wxFileName::GetPathSeparator() == wxChar( '\\' ) && uri.Find( wxChar( '/' ) ) >= 0 )
289  uri.Replace( "/", "\\" );
290 
291  if( (wxFileName::IsCaseSensitive() && uri == aURI)
292  || (!wxFileName::IsCaseSensitive() && uri.Upper() == aURI.Upper() ) )
293  {
294  return &cur->rows[i]; // found
295  }
296  }
297 
298  // not found, search fall back table(s), if any
299  } while( ( cur = cur->fallBack ) != 0 );
300 
301  return NULL; // not found
302 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
Class LIB_TABLE.
void SYMBOL_LIB_TABLE::Format ( OUTPUTFORMATTER aOutput,
int  aIndentLevel 
) const
overridevirtual

Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.

Parameters
aOutputis the OUTPUTFORMATTER to format the table into.
aIndentLevelis the indentation level (2 spaces) to indent.
Exceptions
IO_ERRORif an I/O error occurs during output.
boost::interprocess::lock_exceptif separate process attempt to access the table.

Implements LIB_TABLE.

Definition at line 199 of file symbol_lib_table.cpp.

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

Referenced by DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable().

200 {
201  aOutput->Print( aIndentLevel, "(sym_lib_table\n" );
202 
203  for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
204  it->Format( aOutput, aIndentLevel+1 );
205 
206  aOutput->Print( aIndentLevel, ")\n" );
207 }
LIB_TABLE_ROWS rows
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
UTF8 LIB_TABLE::FormatOptions ( const PROPERTIES aProperties)
staticinherited

Function FormatOptions.

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

References name, and OPT_SEP.

Referenced by DIALOG_FP_PLUGIN_OPTIONS::makeResult().

475 {
476  UTF8 ret;
477 
478  if( aProperties )
479  {
480  for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
481  {
482  const std::string& name = it->first;
483 
484  const UTF8& value = it->second;
485 
486  if( ret.size() )
487  ret += OPT_SEP;
488 
489  ret += name;
490 
491  // the separation between name and value is '='
492  if( value.size() )
493  {
494  ret += '=';
495 
496  for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
497  {
498  // escape any separator in the value.
499  if( *si == OPT_SEP )
500  ret += '\\';
501 
502  ret += *si;
503  }
504  }
505  }
506  }
507 
508  return ret;
509 }
Class UTF8 is an 8 bit std::string that is assuredly encoded in UTF8, and supplies special conversion...
Definition: utf8.h:53
const char * name
#define OPT_SEP
options separator character
int LIB_TABLE::GetCount ( )
inlineinherited

Definition at line 352 of file lib_table_base.h.

References LIB_TABLE::rows.

Referenced by FP_GRID_TRICKS::paste_text().

352 { return rows.size(); }
LIB_TABLE_ROWS rows
const wxString LIB_TABLE::GetDescription ( const wxString &  aNickname)
inherited

Function GetDescription.

Returns
the library description from aNickname, or an empty string if aNickname does not exist.

Definition at line 242 of file lib_table_base.cpp.

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

Referenced by PCB_BASE_FRAME::SelectLibrary().

243 {
244  // use "no exception" form of find row:
245  const LIB_TABLE_ROW* row = findRow( aNickname );
246 
247  if( row )
248  return row->GetDescr();
249  else
250  return wxEmptyString;
251 }
Class LIB_TABLE_ROW.
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Function findRow returns a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBa...
const wxString & GetDescr() const
Function GetDescr.
size_t LIB_TABLE::GetEnvVars ( wxArrayString &  aEnvVars) const
inherited

Search the paths all of the LIB_TABLE_ROWS of the LIB_TABLE and add all of the environment variable substitutions to aEnvVars.

This will only add unique environment variables to the list. Duplicates are ignored.

Parameters
aEnvVarsis the array to load the environment variables.
Returns
the number of unique environment variables found in the table.

Definition at line 380 of file lib_table_base.cpp.

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

381 {
382  const LIB_TABLE* cur = this;
383 
384  do
385  {
386  for( unsigned i = 0; i < cur->rows.size(); i++ )
387  {
388  wxString uri = cur->rows[i].GetFullURI( false );
389 
390  int start = uri.Find( "${" );
391 
392  if( start == wxNOT_FOUND )
393  continue;
394 
395  int end = uri.Find( '}' );
396 
397  if( end == wxNOT_FOUND || end < start+2 )
398  continue;
399 
400  wxString envVar = uri.Mid( start+2, end - (start+2) );
401 
402  if( aEnvVars.Index( envVar, false ) == wxNOT_FOUND )
403  aEnvVars.Add( envVar );
404  }
405 
406  // not found, search fall back table(s), if any
407  } while( ( cur = cur->fallBack ) != 0 );
408 
409  return aEnvVars.GetCount();
410 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
Class LIB_TABLE.
SYMBOL_LIB_TABLE & SYMBOL_LIB_TABLE::GetGlobalLibTable ( )
static

Definition at line 72 of file symbol_lib_table.cpp.

References g_symbolLibraryTable.

Referenced by DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), DIALOG_SYMBOL_REMAP::getLibsNotInGlobalSymbolLibTable(), and SCH::IFACE::OnKifaceStart().

73 {
74  return g_symbolLibraryTable;
75 }
SYMBOL_LIB_TABLE g_symbolLibraryTable
The global symbol library table.
wxString SYMBOL_LIB_TABLE::GetGlobalTableFileName ( )
static

Fetch the global symbol library table file name.

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

Definition at line 413 of file symbol_lib_table.cpp.

References GetKicadConfigPath(), and global_tbl_name().

Referenced by LoadGlobalTable().

414 {
415  wxFileName fn;
416 
417  fn.SetPath( GetKicadConfigPath() );
418  fn.SetName( global_tbl_name );
419 
420  return fn.GetFullPath();
421 }
static const wxString global_tbl_name("sym-lib-table")
wxString GetKicadConfigPath()
Function GetKicadConfigPath.
Definition: common.cpp:217
std::vector< wxString > LIB_TABLE::GetLogicalLibs ( )
inherited

Function GetLogicalLibs.

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

Definition at line 305 of file lib_table_base.cpp.

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

Referenced by CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), LoadSymbolWithOptionalNickname(), FOOTPRINT_VIEWER_FRAME::OnActivate(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), PCB_BASE_FRAME::SelectLibrary(), and FOOTPRINT_LIST_IMPL::StartWorkers().

306 {
307  // Only return unique logical library names. Use std::set::insert() to
308  // quietly reject any duplicates, which can happen when encountering a duplicate
309  // nickname from one of the fall back table(s).
310 
311  std::set< wxString > unique;
312  std::vector< wxString > ret;
313  const LIB_TABLE* cur = this;
314 
315  do
316  {
317  for( LIB_TABLE_ROWS_CITER it = cur->rows.begin(); it!=cur->rows.end(); ++it )
318  {
319  unique.insert( it->GetNickName() );
320  }
321 
322  } while( ( cur = cur->fallBack ) != 0 );
323 
324  ret.reserve( unique.size() );
325 
326  // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
327  for( std::set< wxString >::const_iterator it = unique.begin(); it!=unique.end(); ++it )
328  {
329  ret.push_back( *it );
330  }
331 
332  return ret;
333 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
Class LIB_TABLE.
const wxString & SYMBOL_LIB_TABLE::GetSymbolLibTableFileName ( )
static

Definition at line 424 of file symbol_lib_table.cpp.

References global_tbl_name().

Referenced by DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), and DIALOG_SYMBOL_REMAP::OnRemapSymbols().

425 {
426  return global_tbl_name;
427 }
static const wxString global_tbl_name("sym-lib-table")
const wxString SYMBOL_LIB_TABLE::GlobalPathEnvVariableName ( )
static

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

These can be either legacy or sweet format. The only thing special about this particular environment variable is that it is set automatically by KiCad on program start up, if it is not set already in the environment.

Definition at line 373 of file symbol_lib_table.cpp.

374 {
375  return "KICAD_SYMBOL_DIR";
376 }
bool LIB_TABLE::InsertRow ( LIB_TABLE_ROW aRow,
bool  doReplace = false 
)
inherited

Function InsertRow.

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

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

Referenced by DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), InvokeFootprintWizard(), Parse(), and FP_LIB_TABLE::Parse().

337 {
338  ensureIndex();
339 
340  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
341 
342  if( it == nickIndex.end() )
343  {
344  rows.push_back( aRow );
345  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
346  return true;
347  }
348 
349  if( doReplace )
350  {
351  rows.replace( it->second, aRow );
352  return true;
353  }
354 
355  return false;
356 }
void ensureIndex()
INDEX::const_iterator INDEX_CITER
LIB_TABLE_ROWS rows
INDEX::value_type INDEX_VALUE
const wxString & GetNickName() const
Function GetNickName.
INDEX nickIndex
this particular key is the nickName within each row.
bool LIB_TABLE::IsEmpty ( bool  aIncludeFallback = true)
inherited

Function IsEmpty.

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

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

Referenced by LIB_TABLE::IsEmpty(), PCB_EDIT_FRAME::LoadFootprints(), and FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib().

234 {
235  if( !aIncludeFallback || !fallBack )
236  return rows.empty();
237 
238  return rows.empty() && fallBack->IsEmpty( true );
239 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
bool IsEmpty(bool aIncludeFallback=true)
Function IsEmpty.
bool SYMBOL_LIB_TABLE::IsSymbolLibWritable ( const wxString &  aNickname)

Return true if the library given by aNickname is writable.

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

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

Definition at line 318 of file symbol_lib_table.cpp.

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

319 {
320  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
321  wxASSERT( (SCH_PLUGIN*) row->plugin );
322  return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) );
323 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const 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...
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:184
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:149
void LIB_TABLE::Load ( const wxString &  aFileName)
inherited

Function Load.

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

References LIB_TABLE::Parse().

Referenced by LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), and PROJECT::PcbFootprintLibs().

361 {
362  // It's OK if footprint library tables are missing.
363  if( wxFileName::IsFileReadable( aFileName ) )
364  {
365  FILE_LINE_READER reader( aFileName );
366  LIB_TABLE_LEXER lexer( &reader );
367 
368  Parse( &lexer );
369  }
370 }
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
Function Parse.
Class LIB_TABLE_LEXER is an automatically generated class using the TokenList2DnsLexer.cmake technology, based on keywords provided by file: /home/kicad/workspace/kicad-doxygen/common/lib_table.keywords.
bool SYMBOL_LIB_TABLE::LoadGlobalTable ( SYMBOL_LIB_TABLE aTable)
static

Load the global symbol library table into aTable.

This probably should be move into the application object when KiCad is changed to a single process application. This is the least painful solution for the time being.

Parameters
aTablethe SYMBOL_LIB_TABLE object to load.
Returns
true if the global library table exists and is loaded properly.
Exceptions
IO_ERRORif an error occurs attempting to load the symbol library table.

Definition at line 379 of file symbol_lib_table.cpp.

References SEARCH_STACK::FindValidPath(), Format(), GetChars(), GetGlobalTableFileName(), global_tbl_name(), Kiface(), KIFACE_I::KifaceSearch(), LIB_TABLE::Load(), LIB_TABLE::Save(), and THROW_IO_ERROR.

Referenced by SCH::IFACE::OnKifaceStart().

380 {
381  bool tableExists = true;
382  wxFileName fn = GetGlobalTableFileName();
383 
384  if( !fn.FileExists() )
385  {
386  tableExists = false;
387 
388  if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
389  {
390  THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
391  GetChars( fn.GetPath() ) ) );
392  }
393 
394  // Attempt to copy the default global file table from the KiCad
395  // template folder to the user's home configuration path.
396  wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name );
397 
398  // The fallback is to create an empty global symbol table for the user to populate.
399  if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
400  {
401  SYMBOL_LIB_TABLE emptyTable;
402 
403  emptyTable.Save( fn.GetFullPath() );
404  }
405  }
406 
407  aTable.Load( fn.GetFullPath() );
408 
409  return tableExists;
410 }
static const wxString global_tbl_name("sym-lib-table")
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
Definition: kiface_i.h:127
void Save(const wxString &aFileName) const
Function Save.
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void Load(const wxString &aFileName)
Function Load.
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:92
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
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:71
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
LIB_ALIAS * SYMBOL_LIB_TABLE::LoadSymbol ( const wxString &  aNickname,
const wxString &  aAliasName 
)

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

References FindRow(), FROM_UTF8(), LIB_TABLE_ROW::GetFullURI(), LIB_PART::GetLibId(), LIB_TABLE_ROW::GetNickName(), LIB_ALIAS::GetPart(), LIB_TABLE_ROW::GetProperties(), SCH_PLUGIN::LoadSymbol(), SYMBOL_LIB_TABLE_ROW::plugin, and TO_UTF8.

Referenced by LoadSymbol(), LoadSymbolWithOptionalNickname(), SCH_COMPONENT::Resolve(), and SCH_COMPONENT::SetLibId().

243 {
244  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
245  wxASSERT( (SCH_PLUGIN*) row->plugin );
246 
247  LIB_ALIAS* ret = row->plugin->LoadSymbol( row->GetFullURI( true ), aAliasName,
248  row->GetProperties() );
249 
250  // The library cannot know its own name, because it might have been renamed or moved.
251  // Therefore footprints cannot know their own library nickname when residing in
252  // a symbol library.
253  // Only at this API layer can we tell the symbol about its actual library nickname.
254  if( ret )
255  {
256  // remove "const"-ness, I really do want to set nickname without
257  // having to copy the LIB_ID and its two strings, twice each.
258  LIB_ID& id = (LIB_ID&) ret->GetPart()->GetLibId();
259 
260  // Catch any misbehaving plugin, which should be setting internal alias name properly:
261  wxASSERT( aAliasName == FROM_UTF8( id.GetLibItemName() ) );
262 
263  // and clearing nickname
264  wxASSERT( !id.GetLibNickname().size() );
265 
266  id.SetLibNickname( TO_UTF8( row->GetNickName() ) );
267  }
268 
269  return ret;
270 }
Part library alias object definition.
virtual LIB_ALIAS * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Load a LIB_ALIAS object having aAliasName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:101
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
const 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 PROPERTIES * GetProperties() const
Function GetProperties.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const LIB_ID & GetLibId() const
Class LIB_ID.
Definition: lib_id.h:56
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:184
LIB_PART * GetPart() const
Function GetPart gets the shared LIB_PART.
const wxString & GetNickName() const
Function GetNickName.
LIB_ALIAS* SYMBOL_LIB_TABLE::LoadSymbol ( const LIB_ID aLibId)
inline

Definition at line 155 of file symbol_lib_table.h.

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

156  {
157  return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
158  }
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
Function GetLibItemName.
Definition: lib_id.h:129
const UTF8 & GetLibNickname() const
Function GetLibNickname.
Definition: lib_id.h:108
LIB_ALIAS * SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname ( const LIB_ID aId)

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

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

Definition at line 342 of file symbol_lib_table.cpp.

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

343 {
344  wxString nickname = FROM_UTF8( aLibId.GetLibNickname() );
345  wxString name = FROM_UTF8( aLibId.GetLibItemName() );
346 
347  if( nickname.size() )
348  {
349  return LoadSymbol( nickname, name );
350  }
351 
352  // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
353  else
354  {
355  std::vector<wxString> nicks = GetLogicalLibs();
356 
357  // Search each library going through libraries alphabetically.
358  for( unsigned i = 0; i < nicks.size(); ++i )
359  {
360  // FootprintLoad() returns NULL on not found, does not throw exception
361  // unless there's an IO_ERROR.
362  LIB_ALIAS* ret = LoadSymbol( nicks[i], name );
363 
364  if( ret )
365  return ret;
366  }
367 
368  return NULL;
369  }
370 }
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.
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
const char * name
std::vector< wxString > GetLogicalLibs()
Function GetLogicalLibs.
bool LIB_TABLE::operator!= ( const LIB_TABLE r) const
inlineinherited

Definition at line 350 of file lib_table_base.h.

350 { return !( *this == r ); }
bool LIB_TABLE::operator== ( const LIB_TABLE r) const
inlineinherited

Definition at line 334 of file lib_table_base.h.

References LIB_TABLE::rows.

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
void SYMBOL_LIB_TABLE::Parse ( LIB_TABLE_LEXER aLexer)
overridevirtual

Function Parse.

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

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), LIB_TABLE_LEXER::CurTok(), DSNLEXER::Duplicate(), DSNLEXER::Expecting(), Format(), DSNLEXER::FromUTF8(), GetChars(), LIB_TABLE::InsertRow(), DSNLEXER::NeedLEFT(), DSNLEXER::NeedRIGHT(), LIB_TABLE_LEXER::NeedSYMBOLorNUMBER(), LIB_TABLE_LEXER::NextTok(), FP_LIB_TABLE_T::T_descr, DSN::T_EOF, DSN::T_LEFT, FP_LIB_TABLE_T::T_lib, TLIB_T::T_name, FP_LIB_TABLE_T::T_options, DSN::T_RIGHT, FP_LIB_TABLE_T::T_sym_lib_table, DSN::T_type, FP_LIB_TABLE_T::T_uri, THROW_PARSE_ERROR, and DSNLEXER::Unexpected().

79 {
80  T tok;
81 
82  // This table may be nested within a larger s-expression, or not.
83  // Allow for parser of that optional containing s-epression to have looked ahead.
84  if( in->CurTok() != T_sym_lib_table )
85  {
86  in->NeedLEFT();
87  if( ( tok = in->NextTok() ) != T_sym_lib_table )
88  in->Expecting( T_sym_lib_table );
89  }
90 
91  while( ( tok = in->NextTok() ) != T_RIGHT )
92  {
93  std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row( new SYMBOL_LIB_TABLE_ROW );
94 
95  if( tok == T_EOF )
96  in->Expecting( T_RIGHT );
97 
98  if( tok != T_LEFT )
99  in->Expecting( T_LEFT );
100 
101  // in case there is a "row integrity" error, tell where later.
102  int lineNum = in->CurLineNumber();
103  int offset = in->CurOffset();
104 
105  if( ( tok = in->NextTok() ) != T_lib )
106  in->Expecting( T_lib );
107 
108  // (name NICKNAME)
109  in->NeedLEFT();
110 
111  if( ( tok = in->NextTok() ) != T_name )
112  in->Expecting( T_name );
113 
114  in->NeedSYMBOLorNUMBER();
115 
116  row->SetNickName( in->FromUTF8() );
117 
118  in->NeedRIGHT();
119 
120  // After (name), remaining (lib) elements are order independent, and in
121  // some cases optional.
122  bool sawType = false;
123  bool sawOpts = false;
124  bool sawDesc = false;
125  bool sawUri = false;
126 
127  while( ( tok = in->NextTok() ) != T_RIGHT )
128  {
129  if( tok == T_EOF )
130  in->Unexpected( T_EOF );
131 
132  if( tok != T_LEFT )
133  in->Expecting( T_LEFT );
134 
135  tok = in->NeedSYMBOLorNUMBER();
136 
137  switch( tok )
138  {
139  case T_uri:
140  if( sawUri )
141  in->Duplicate( tok );
142  sawUri = true;
143  in->NeedSYMBOLorNUMBER();
144  row->SetFullURI( in->FromUTF8() );
145  break;
146 
147  case T_type:
148  if( sawType )
149  in->Duplicate( tok );
150  sawType = true;
151  in->NeedSYMBOLorNUMBER();
152  row->SetType( in->FromUTF8() );
153  break;
154 
155  case T_options:
156  if( sawOpts )
157  in->Duplicate( tok );
158  sawOpts = true;
159  in->NeedSYMBOLorNUMBER();
160  row->SetOptions( in->FromUTF8() );
161  break;
162 
163  case T_descr:
164  if( sawDesc )
165  in->Duplicate( tok );
166  sawDesc = true;
167  in->NeedSYMBOLorNUMBER();
168  row->SetDescr( in->FromUTF8() );
169  break;
170 
171  default:
172  in->Unexpected( tok );
173  }
174 
175  in->NeedRIGHT();
176  }
177 
178  if( !sawType )
179  in->Expecting( T_type );
180 
181  if( !sawUri )
182  in->Expecting( T_uri );
183 
184  // all nickNames within this table fragment must be unique, so we do not
185  // use doReplace in InsertRow(). (However a fallBack table can have a
186  // conflicting nickName and ours will supercede that one since in
187  // FindLib() we search this table before any fall back.)
188  if( !InsertRow( row.release() ) )
189  {
190  wxString msg = wxString::Format(
191  _( "'%s' is a duplicate symbol library nickname" ),
192  GetChars( row->GetNickName() ) );
193  THROW_PARSE_ERROR( msg, in->CurSource(), in->CurLine(), lineNum, offset );
194  }
195  }
196 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Function InsertRow.
T
enum T contains all this lexer's tokens.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
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:92
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
PROPERTIES * LIB_TABLE::ParseOptions ( const std::string &  aOptionsList)
staticinherited

Function ParseOptions.

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

References name, and OPT_SEP.

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

414 {
415  if( aOptionsList.size() )
416  {
417  const char* cp = &aOptionsList[0];
418  const char* end = cp + aOptionsList.size();
419 
420  PROPERTIES props;
421  std::string pair;
422 
423  // Parse all name=value pairs
424  while( cp < end )
425  {
426  pair.clear();
427 
428  // Skip leading white space.
429  while( cp < end && isspace( *cp ) )
430  ++cp;
431 
432  // Find the end of pair/field
433  while( cp < end )
434  {
435  if( *cp == '\\' && cp + 1 < end && cp[1] == OPT_SEP )
436  {
437  ++cp; // skip the escape
438  pair += *cp++; // add the separator
439  }
440  else if( *cp == OPT_SEP )
441  {
442  ++cp; // skip the separator
443  break; // process the pair
444  }
445  else
446  pair += *cp++;
447  }
448 
449  // stash the pair
450  if( pair.size() )
451  {
452  // first equals sign separates 'name' and 'value'.
453  size_t eqNdx = pair.find( '=' );
454 
455  if( eqNdx != pair.npos )
456  {
457  std::string name = pair.substr( 0, eqNdx );
458  std::string value = pair.substr( eqNdx + 1 );
459  props[name] = value;
460  }
461  else
462  props[pair] = ""; // property is present, but with no value.
463  }
464  }
465 
466  if( props.size() )
467  return new PROPERTIES( props );
468  }
469 
470  return NULL;
471 }
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
#define OPT_SEP
options separator character
void LIB_TABLE::reindex ( )
inlineprotectedinherited

Definition at line 486 of file lib_table_base.h.

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

Referenced by LIB_TABLE::ensureIndex(), and DIALOG_FP_LIB_TABLE::onOKButtonClick().

487  {
488  nickIndex.clear();
489 
490  for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
491  nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
492  }
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.
void LIB_TABLE::Save ( const wxString &  aFileName) const
inherited

Function Save.

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

Parameters
aFileNameis the name of the file to write to.

Definition at line 373 of file lib_table_base.cpp.

References LIB_TABLE::Format().

Referenced by LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), CVPCB_MAINFRAME::OnEditFootprintLibraryTable(), PCB_EDIT_FRAME::Process_Config(), and FOOTPRINT_EDIT_FRAME::ProcessPreferences().

374 {
375  FILE_OUTPUTFORMATTER sf( aFileName );
376  Format( &sf, 0 );
377 }
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
SYMBOL_LIB_TABLE::SAVE_T SYMBOL_LIB_TABLE::SaveSymbol ( const wxString &  aNickname,
const LIB_PART aSymbol,
bool  aOverwrite = true 
)

Write aSymbol to an existing library given by aNickname.

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

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

Definition at line 273 of file symbol_lib_table.cpp.

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

275 {
276  const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
277  wxASSERT( (SCH_PLUGIN*) row->plugin );
278 
279  if( !aOverwrite )
280  {
281  // Try loading the footprint to see if it already exists, caller wants overwrite
282  // protection, which is atypical, not the default.
283 
284  wxString name = FROM_UTF8( aSymbol->GetLibId().GetLibItemName() );
285 
286  std::unique_ptr< LIB_ALIAS > symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
287  name,
288  row->GetProperties() ) );
289 
290  if( symbol.get() )
291  return SAVE_SKIPPED;
292  }
293 
294  row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
295 
296  return SAVE_OK;
297 }
virtual LIB_ALIAS * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Load a LIB_ALIAS object having aAliasName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:101
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
const 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 PROPERTIES * GetProperties() const
Function GetProperties.
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
const LIB_ID & GetLibId() const
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:184
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
const char * name
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=NULL)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:110

Member Data Documentation

LIB_TABLE* LIB_TABLE::fallBack
protectedinherited
INDEX LIB_TABLE::nickIndex
protectedinherited

this particular key is the nickName within each row.

Definition at line 512 of file lib_table_base.h.

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


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