KiCad PCB EDA Suite
FP_LIB_TABLE Class Reference

#include <fp_lib_table.h>

Inheritance diagram for FP_LIB_TABLE:
LIB_TABLE PROJECT::_ELEM FP_LIB_TABLE_GRID

Public Types

enum  SAVE_T { SAVE_OK, SAVE_SKIPPED }
 Enum SAVE_T is the set of return values from FootprintSave() below. More...
 

Public Member Functions

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...
 
 FP_LIB_TABLE (FP_LIB_TABLE *aFallBackTable=NULL)
 Constructor FP_LIB_TABLE. More...
 
bool operator== (const FP_LIB_TABLE &aFpTable) const
 
bool operator!= (const FP_LIB_TABLE &r) const
 
const FP_LIB_TABLE_ROWFindRow (const wxString &aNickName)
 Function FindRow. More...
 
void FootprintEnumerate (wxArrayString &aFootprintNames, const wxString &aNickname)
 Return a list of footprint names contained within the library given by aNickname. More...
 
void PrefetchLib (const wxString &aNickname)
 Function PrefetchLib If possible, prefetches the specified library (e.g. More...
 
MODULEFootprintLoad (const wxString &aNickname, const wxString &aFootprintName)
 Function FootprintLoad. More...
 
SAVE_T FootprintSave (const wxString &aNickname, const MODULE *aFootprint, bool aOverwrite=true)
 Function FootprintSave. More...
 
void FootprintDelete (const wxString &aNickname, const wxString &aFootprintName)
 Function FootprintDelete. More...
 
bool IsFootprintLibWritable (const wxString &aNickname)
 Function IsFootprintLibWritable. More...
 
void FootprintLibDelete (const wxString &aNickname)
 
void FootprintLibCreate (const wxString &aNickname)
 
MODULEFootprintLoadWithOptionalNickname (const LIB_ID &aFootprintId)
 Function FootprintLoadWithOptionalNickname loads a footprint having aFootprintId with possibly an empty 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)
 Return true if the table is empty. More...
 
const wxString GetDescription (const wxString &aNickname)
 
bool HasLibrary (const wxString &aNickname) 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...
 
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...
 
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 (FP_LIB_TABLE &aTable)
 Function LoadGlobalTable loads the global footprint library table into aTable. More...
 
static wxString GetGlobalTableFileName ()
 Function GetGlobalTableFileName. More...
 
static const wxString GlobalPathEnvVariableName ()
 Function GlobalPathEnvVarVariableName. More...
 
static PROPERTIESParseOptions (const std::string &aOptionsList)
 Parses aOptionsList and places the result into a PROPERTIES object which is returned. More...
 
static UTF8 FormatOptions (const PROPERTIES *aProperties)
 Returns a list of options from the aProperties parameter. More...
 
static const wxString ExpandSubstitutions (const wxString &aString)
 Replaces any environment variable references with their values and is here to fully embellish the TABLE_ROW::uri in a platform independent way. More...
 

Protected Types

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

Protected Member Functions

LIB_TABLE_ROWfindRow (const wxString &aNickname) const
 Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment, else NULL. More...
 
LIB_TABLE_ROWfindRow (const wxString &aNickname)
 
void reindex ()
 
void ensureIndex ()
 

Protected Attributes

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

Friends

class FP_LIB_TABLE_GRID
 

Detailed Description

Definition at line 103 of file fp_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 488 of file lib_table_base.h.

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protectedinherited

Definition at line 490 of file lib_table_base.h.

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protectedinherited

Definition at line 489 of file lib_table_base.h.

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protectedinherited

Definition at line 491 of file lib_table_base.h.

Member Enumeration Documentation

Enum SAVE_T is the set of return values from FootprintSave() below.

Enumerator
SAVE_OK 
SAVE_SKIPPED 

Definition at line 187 of file fp_lib_table.h.

Constructor & Destructor Documentation

FP_LIB_TABLE::FP_LIB_TABLE ( FP_LIB_TABLE aFallBackTable = NULL)

Constructor FP_LIB_TABLE.

builds a footprint 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 FP_LIB_TABLE which is searched only when a row is not found in this table. No ownership is taken of aFallBackTable.

Definition at line 59 of file fp_lib_table.cpp.

59  :
60  LIB_TABLE( aFallBackTable )
61 {
62  // not copying fall back, simply search aFallBackTable separately
63  // if "nickName not found".
64 }
LIB_TABLE(LIB_TABLE *aFallBackTable=NULL)
Build a library table by pre-pending this table fragment in front of aFallBackTable.

Member Function Documentation

LIB_TABLE_ROW* LIB_TABLE::At ( int  aIndex)
inlineinherited

Definition at line 338 of file lib_table_base.h.

References LIB_TABLE::rows.

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

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

Delete all rows.

Definition at line 312 of file lib_table_base.h.

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

Referenced by DIALOG_FP_LIB_TABLE::onOKButtonClick(), and DIALOG_SYMBOL_LIB_TABLE::TransferDataFromWindow().

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

Definition at line 476 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().

477  {
478  // The dialog lib table editor may not maintain the nickIndex.
479  // Lazy indexing may be required. To handle lazy indexing, we must enforce
480  // that "nickIndex" is either empty or accurate, but never inaccurate.
481  if( !nickIndex.size() )
482  reindex();
483  }
void reindex()
INDEX nickIndex
this particular key is the nickName within each row.
const wxString LIB_TABLE::ExpandSubstitutions ( const wxString &  aString)
staticinherited

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

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

Definition at line 567 of file lib_table_base.cpp.

References ExpandEnvVarSubstitutions().

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

568 {
569  return ExpandEnvVarSubstitutions( aString );
570 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Function ExpandEnvVarSubstitutions replaces any environment variable references with their values...
Definition: common.cpp:254
const FP_LIB_TABLE_ROW * FP_LIB_TABLE::FindRow ( const wxString &  aNickName)

Function FindRow.

returns an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table fragment. The PLUGIN is loaded and attached to the "plugin" field of the FP_LIB_TABLE_ROW if not already loaded.

Exceptions
IO_ERRORif aNickName cannot be found.

Definition at line 255 of file fp_lib_table.cpp.

References LIB_TABLE::findRow(), Format(), GetChars(), FP_LIB_TABLE_ROW::plugin, IO_MGR::PluginFind(), FP_LIB_TABLE_ROW::setPlugin(), THROW_IO_ERROR, and FP_LIB_TABLE_ROW::type.

Referenced by FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary(), FootprintDelete(), FootprintEnumerate(), FootprintLibCreate(), FootprintLibDelete(), FootprintLoad(), FootprintSave(), FOOTPRINT_EDIT_FRAME::getLibPath(), IsFootprintLibWritable(), PrefetchLib(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), FOOTPRINT_VIEWER_FRAME::UpdateTitle(), and FOOTPRINT_EDIT_FRAME::updateTitle().

256 {
257  FP_LIB_TABLE_ROW* row = dynamic_cast< FP_LIB_TABLE_ROW* >( findRow( aNickname ) );
258 
259  if( !row )
260  {
261  wxString msg = wxString::Format(
262  _( "fp-lib-table files contain no library with nickname '%s'" ),
263  GetChars( aNickname ) );
264 
265  THROW_IO_ERROR( msg );
266  }
267 
268  // We've been 'lazy' up until now, but it cannot be deferred any longer,
269  // instantiate a PLUGIN of the proper kind if it is not already in this
270  // FP_LIB_TABLE_ROW.
271  if( !row->plugin )
272  row->setPlugin( IO_MGR::PluginFind( row->type ) );
273 
274  return row;
275 }
void setPlugin(PLUGIN *aPlugin)
Definition: fp_lib_table.h:93
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment...
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
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname) const
protectedinherited

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

Definition at line 284 of file lib_table_base.cpp.

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

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

285 {
286  LIB_TABLE* cur = (LIB_TABLE*) this;
287 
288  do
289  {
290  cur->ensureIndex();
291 
292  INDEX_CITER it = cur->nickIndex.find( aNickName );
293 
294  if( it != cur->nickIndex.end() )
295  {
296  return &cur->rows[it->second]; // found
297  }
298 
299  // not found, search fall back table(s), if any
300  } while( ( cur = cur->fallBack ) != 0 );
301 
302  return NULL; // not found
303 }
void ensureIndex()
INDEX::const_iterator INDEX_CITER
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
INDEX nickIndex
this particular key is the nickName within each row.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname)
protectedinherited

Definition at line 306 of file lib_table_base.cpp.

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

307 {
308  LIB_TABLE* cur = (LIB_TABLE*) this;
309 
310  do
311  {
312  cur->ensureIndex();
313 
314  INDEX_ITER it = cur->nickIndex.find( aNickName );
315 
316  if( it != cur->nickIndex.end() )
317  {
318  return &cur->rows[it->second]; // found
319  }
320 
321  // not found, search fall back table(s), if any
322  } while( ( cur = cur->fallBack ) != 0 );
323 
324  return NULL; // not found
325 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
INDEX::iterator INDEX_ITER
INDEX nickIndex
this particular key is the nickName within each row.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
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 328 of file lib_table_base.cpp.

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

329 {
330  LIB_TABLE* cur = this;
331 
332  do
333  {
334  cur->ensureIndex();
335 
336  for( unsigned i = 0; i < cur->rows.size(); i++ )
337  {
338  wxString uri = cur->rows[i].GetFullURI( true );
339 
340  if( wxFileName::GetPathSeparator() == wxChar( '\\' ) && uri.Find( wxChar( '/' ) ) >= 0 )
341  uri.Replace( "/", "\\" );
342 
343  if( (wxFileName::IsCaseSensitive() && uri == aURI)
344  || (!wxFileName::IsCaseSensitive() && uri.Upper() == aURI.Upper() ) )
345  {
346  return &cur->rows[i]; // found
347  }
348  }
349 
350  // not found, search fall back table(s), if any
351  } while( ( cur = cur->fallBack ) != 0 );
352 
353  return NULL; // not found
354 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
void FP_LIB_TABLE::FootprintDelete ( const wxString &  aNickname,
const wxString &  aFootprintName 
)

Function FootprintDelete.

deletes the aFootprintName from the library given by aNickname.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW.
aFootprintNameis the name of a footprint 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 335 of file fp_lib_table.cpp.

References FindRow(), PLUGIN::FootprintDelete(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

Referenced by FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary().

336 {
337  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
338  wxASSERT( (PLUGIN*) row->plugin );
339  return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName,
340  row->GetProperties() );
341 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_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...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
virtual void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintDelete deletes aFootprintName from the library at aLibraryPath. ...
Definition: plugin.cpp:92
void FP_LIB_TABLE::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aNickname 
)

Return a list of footprint names contained within the library given by aNickname.

Parameters
aFootprintNamesis the list to fill with the footprint names found in aNickname
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW.
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Definition at line 238 of file fp_lib_table.cpp.

References FindRow(), PLUGIN::FootprintEnumerate(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

Referenced by guessNickname(), and FOOTPRINT_LIST_IMPL::JoinWorkers().

239 {
240  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
241  wxASSERT( (PLUGIN*) row->plugin );
242  row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ),
243  row->GetProperties() );
244 }
virtual void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Return a list of footprint names contained within the library at aLibraryPath.
Definition: plugin.cpp:61
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_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...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
void FP_LIB_TABLE::FootprintLibCreate ( const wxString &  aNickname)

Definition at line 360 of file fp_lib_table.cpp.

References FindRow(), PLUGIN::FootprintLibCreate(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

361 {
362  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
363  wxASSERT( (PLUGIN*) row->plugin );
364  row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() );
365 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_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...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
Definition: plugin.cpp:99
void FP_LIB_TABLE::FootprintLibDelete ( const wxString &  aNickname)

Definition at line 352 of file fp_lib_table.cpp.

References FindRow(), PLUGIN::FootprintLibDelete(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), and FP_LIB_TABLE_ROW::plugin.

353 {
354  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
355  wxASSERT( (PLUGIN*) row->plugin );
356  row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() );
357 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_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...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.
Definition: plugin.cpp:106
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
MODULE * FP_LIB_TABLE::FootprintLoad ( const wxString &  aNickname,
const wxString &  aFootprintName 
)

Function FootprintLoad.

loads a footprint having aFootprintName from the library given by aNickname.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW
aFootprintNameis the name of the footprint to load.
Returns
MODULE* - if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.

Definition at line 278 of file fp_lib_table.cpp.

References FindRow(), PLUGIN::FootprintLoad(), MODULE::GetFPID(), LIB_TABLE_ROW::GetFullURI(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetProperties(), FP_LIB_TABLE_ROW::plugin, LIB_ID::SetLibNickname(), UTF8::size(), and UTF8::wx_str().

Referenced by FootprintLoadWithOptionalNickname(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FOOTPRINT_INFO_IMPL::load(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), and FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint().

279 {
280  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
281  wxASSERT( (PLUGIN*) row->plugin );
282 
283  MODULE* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName,
284  row->GetProperties() );
285 
286  // The library cannot know its own name, because it might have been renamed or moved.
287  // Therefore footprints cannot know their own library nickname when residing in
288  // a footprint library.
289  // Only at this API layer can we tell the footprint about its actual library nickname.
290  if( ret )
291  {
292  // remove "const"-ness, I really do want to set nickname without
293  // having to copy the LIB_ID and its two strings, twice each.
294  LIB_ID& fpid = (LIB_ID&) ret->GetFPID();
295 
296  // Catch any misbehaving plugin, which should be setting internal footprint name properly:
297  wxASSERT( aFootprintName == fpid.GetLibItemName().wx_str() );
298 
299  // and clearing nickname
300  wxASSERT( !fpid.GetLibNickname().size() );
301 
302  fpid.SetLibNickname( row->GetNickName() );
303  }
304 
305  return ret;
306 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
std::string::size_type size() const
Definition: utf8.h:115
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...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
const LIB_ID & GetFPID() const
Definition: class_module.h:184
wxString wx_str() const
Definition: utf8.cpp:48
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:76
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:219
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
const wxString & GetNickName() const
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:98
MODULE * FP_LIB_TABLE::FootprintLoadWithOptionalNickname ( const LIB_ID aFootprintId)

Function FootprintLoadWithOptionalNickname loads a footprint having aFootprintId with possibly an empty nickname.

Parameters
aFootprintIdthe [nickname] & footprint name of the footprint to load.
Returns
MODULE* - if found caller owns it, else NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aFootprintName cannot be found.
PARSE_ERRORif aFootprintId is not parsed OK.

Definition at line 368 of file fp_lib_table.cpp.

References FootprintLoad(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), and LIB_TABLE::GetLogicalLibs().

Referenced by PCB_BASE_FRAME::loadFootprint(), and FP_LOADER_THREAD::ProcessEntry().

369 {
370  wxString nickname = aFootprintId.GetLibNickname();
371  wxString fpname = aFootprintId.GetLibItemName();
372 
373  if( nickname.size() )
374  {
375  return FootprintLoad( nickname, fpname );
376  }
377 
378  // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
379  else
380  {
381  std::vector<wxString> nicks = GetLogicalLibs();
382 
383  // Search each library going through libraries alphabetically.
384  for( unsigned i = 0; i < nicks.size(); ++i )
385  {
386  // FootprintLoad() returns NULL on not found, does not throw exception
387  // unless there's an IO_ERROR.
388  MODULE* ret = FootprintLoad( nicks[i], fpname );
389 
390  if( ret )
391  return ret;
392  }
393 
394  return NULL;
395  }
396 }
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:98
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE...
FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave ( const wxString &  aNickname,
const MODULE aFootprint,
bool  aOverwrite = true 
)

Function FootprintSave.

will write aFootprint to an existing library given by aNickname. If a footprint by the same name already exists, it is replaced.

Parameters
aNicknameis a locator for the "library", it is a "name" in LIB_TABLE_ROW
aFootprintis what to store in the library. The caller continues to own the footprint after this call.
aOverwritewhen true means overwrite any existing footprint 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.

Definition at line 309 of file fp_lib_table.cpp.

References FindRow(), PLUGIN::FootprintLoad(), PLUGIN::FootprintSave(), MODULE::GetFPID(), LIB_TABLE_ROW::GetFullURI(), LIB_ID::GetLibItemName(), LIB_TABLE_ROW::GetProperties(), FP_LIB_TABLE_ROW::plugin, SAVE_OK, and SAVE_SKIPPED.

Referenced by PCB_EDIT_FRAME::ArchiveModulesOnBoard(), and FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary().

311 {
312  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
313  wxASSERT( (PLUGIN*) row->plugin );
314 
315  if( !aOverwrite )
316  {
317  // Try loading the footprint to see if it already exists, caller wants overwrite
318  // protection, which is atypical, not the default.
319 
320  wxString fpname = aFootprint->GetFPID().GetLibItemName();
321 
322  std::unique_ptr<MODULE> footprint( row->plugin->FootprintLoad( row->GetFullURI( true ),
323  fpname, row->GetProperties() ) );
324 
325  if( footprint.get() )
326  return SAVE_SKIPPED;
327  }
328 
329  row->plugin->FootprintSave( row->GetFullURI( true ), aFootprint, row->GetProperties() );
330 
331  return SAVE_OK;
332 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
virtual void FootprintSave(const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL)
Function FootprintSave will write aModule to an existing library located at aLibraryPath.
Definition: plugin.cpp:85
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...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
const LIB_ID & GetFPID() const
Definition: class_module.h:184
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:76
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
void FP_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 227 of file fp_lib_table.cpp.

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

Referenced by FOOTPRINT_ASYNC_LOADER::IsSameTable(), PCB_EDIT_FRAME::Process_Config(), FOOTPRINT_EDIT_FRAME::ProcessPreferences(), and FOOTPRINT_ASYNC_LOADER::Start().

228 {
229  aOutput->Print( aIndentLevel, "(fp_lib_table\n" );
230 
231  for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
232  it->Format( aOutput, aIndentLevel+1 );
233 
234  aOutput->Print( aIndentLevel, ")\n" );
235 }
LIB_TABLE_ROWS rows
LIB_TABLE_ROWS::const_iterator LIB_TABLE_ROWS_CITER
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
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 529 of file lib_table_base.cpp.

References UTF8::begin(), UTF8::end(), name, OPT_SEP, and UTF8::size().

Referenced by DIALOG_FP_PLUGIN_OPTIONS::makeResult().

530 {
531  UTF8 ret;
532 
533  if( aProperties )
534  {
535  for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
536  {
537  const std::string& name = it->first;
538 
539  const UTF8& value = it->second;
540 
541  if( ret.size() )
542  ret += OPT_SEP;
543 
544  ret += name;
545 
546  // the separation between name and value is '='
547  if( value.size() )
548  {
549  ret += '=';
550 
551  for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
552  {
553  // escape any separator in the value.
554  if( *si == OPT_SEP )
555  ret += '\\';
556 
557  ret += *si;
558  }
559  }
560  }
561  }
562 
563  return ret;
564 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
std::string::size_type size() const
Definition: utf8.h:115
std::string::const_iterator end() const
Definition: utf8.h:190
std::string::const_iterator begin() const
Definition: utf8.h:189
const char * name
#define OPT_SEP
options separator character
int LIB_TABLE::GetCount ( )
inlineinherited

Definition at line 336 of file lib_table_base.h.

References LIB_TABLE::rows.

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

336 { return rows.size(); }
LIB_TABLE_ROWS rows
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 251 of file lib_table_base.cpp.

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

Referenced by PCB_BASE_FRAME::SelectLibrary().

252 {
253  // use "no exception" form of find row:
254  const LIB_TABLE_ROW* row = findRow( aNickname );
255 
256  if( row )
257  return row->GetDescr();
258  else
259  return wxEmptyString;
260 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment...
const wxString & GetDescr() const
Return the description of the library referenced by this row.
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 435 of file lib_table_base.cpp.

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

436 {
437  const LIB_TABLE* cur = this;
438 
439  do
440  {
441  for( unsigned i = 0; i < cur->rows.size(); i++ )
442  {
443  wxString uri = cur->rows[i].GetFullURI( false );
444 
445  int start = uri.Find( "${" );
446 
447  if( start == wxNOT_FOUND )
448  continue;
449 
450  int end = uri.Find( '}' );
451 
452  if( end == wxNOT_FOUND || end < start+2 )
453  continue;
454 
455  wxString envVar = uri.Mid( start+2, end - (start+2) );
456 
457  if( aEnvVars.Index( envVar, false ) == wxNOT_FOUND )
458  aEnvVars.Add( envVar );
459  }
460 
461  // not found, search fall back table(s), if any
462  } while( ( cur = cur->fallBack ) != 0 );
463 
464  return aEnvVars.GetCount();
465 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
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 271 of file lib_table_base.cpp.

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

Referenced by SCH_EDIT_FRAME::AppendSchematic(), LIB_MANAGER::IsLibraryReadOnly(), and NETLIST_EXPORTER_GENERIC::makeLibraries().

272 {
273  const LIB_TABLE_ROW* row = findRow( aNickname );
274 
275  wxString retv;
276 
277  if( row )
278  retv = row->GetFullURI( aExpandEnvVars );
279 
280  return retv;
281 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment...
wxString FP_LIB_TABLE::GetGlobalTableFileName ( )
static

Function GetGlobalTableFileName.

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

Definition at line 439 of file fp_lib_table.cpp.

References GetKicadConfigPath(), and global_tbl_name.

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

440 {
441  wxFileName fn;
442 
443  fn.SetPath( GetKicadConfigPath() );
444  fn.SetName( global_tbl_name );
445 
446  return fn.GetFullPath();
447 }
static const wxChar global_tbl_name[]
wxString GetKicadConfigPath()
Function GetKicadConfigPath.
Definition: common.cpp:217
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 357 of file lib_table_base.cpp.

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

Referenced by CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), FootprintLoadWithOptionalNickname(), LIB_MANAGER::GetLibraryNames(), SYMBOL_LIB_TABLE::GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), FOOTPRINT_VIEWER_FRAME::OnActivate(), LIB_VIEW_FRAME::OnSelectSymbol(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), SCH_BASE_FRAME::SelectComponentFromLibrary(), PCB_BASE_FRAME::SelectLibrary(), and FOOTPRINT_LIST_IMPL::StartWorkers().

358 {
359  // Only return unique logical library names. Use std::set::insert() to
360  // quietly reject any duplicates, which can happen when encountering a duplicate
361  // nickname from one of the fall back table(s).
362 
363  std::set< wxString > unique;
364  std::vector< wxString > ret;
365  const LIB_TABLE* cur = this;
366 
367  do
368  {
369  for( LIB_TABLE_ROWS_CITER it = cur->rows.begin(); it!=cur->rows.end(); ++it )
370  {
371  if( it->GetIsEnabled() )
372  {
373  unique.insert( it->GetNickName() );
374  }
375  }
376 
377  } while( ( cur = cur->fallBack ) != 0 );
378 
379  ret.reserve( unique.size() );
380 
381  // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
382  for( std::set< wxString >::const_iterator it = unique.begin(); it!=unique.end(); ++it )
383  {
384  ret.push_back( *it );
385  }
386 
387  return ret;
388 }
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.
const wxString FP_LIB_TABLE::GlobalPathEnvVariableName ( )
static

Function GlobalPathEnvVarVariableName.

returns the name of the environment variable used to hold the directory of locally installed "KiCad sponsored" system footprint libraries. These can be either legacy or pretty 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 399 of file fp_lib_table.cpp.

Referenced by WIZARD_FPLIB_TABLE::LIBRARY::GetAutoPath(), DIALOG_CONFIG_EQUFILES::Init(), DIALOG_FP_LIB_TABLE::populateEnvironReadOnlyTable(), and WIZARD_FPLIB_TABLE::WIZARD_FPLIB_TABLE().

400 {
401  return "KISYSMOD";
402 }
bool LIB_TABLE::HasLibrary ( const wxString &  aNickname) const
inherited

Test for the existence of aNickname in the library table.

Returns
true if a library aNickname exists in the table.

Definition at line 263 of file lib_table_base.cpp.

References LIB_TABLE::findRow().

Referenced by SCH_EDIT_FRAME::AppendSchematic(), LIB_MANAGER::LibraryExists(), SCH_EAGLE_PLUGIN::Load(), NETLIST_EXPORTER_GENERIC::makeLibraries(), SCH_BASE_FRAME::SelectComponentFromLibrary(), and SCH_COMPONENT::SetLibId().

264 {
265  const LIB_TABLE_ROW* row = findRow( aNickname );
266 
267  return row != nullptr;
268 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
LIB_TABLE_ROW * findRow(const wxString &aNickname) const
Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment...
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 391 of file lib_table_base.cpp.

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

Referenced by LIB_MANAGER::addLibrary(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), InvokeFootprintWizard(), SCH_EAGLE_PLUGIN::Load(), Parse(), and SYMBOL_LIB_TABLE::Parse().

392 {
393  ensureIndex();
394 
395  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
396 
397  if( it == nickIndex.end() )
398  {
399  rows.push_back( aRow );
400  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
401  return true;
402  }
403 
404  if( doReplace )
405  {
406  rows.replace( it->second, aRow );
407  return true;
408  }
409 
410  return false;
411 }
void ensureIndex()
INDEX::const_iterator INDEX_CITER
LIB_TABLE_ROWS rows
INDEX::value_type INDEX_VALUE
const wxString & GetNickName() const
INDEX nickIndex
this particular key is the nickName within each row.
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 242 of file lib_table_base.cpp.

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

Referenced by SCH_EDIT_FRAME::AppendSchematic(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), LIB_TABLE::IsEmpty(), PCB_EDIT_FRAME::LoadFootprints(), and FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib().

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

Function IsFootprintLibWritable.

returns true if the library given by aNickname is writable. (Often system libraries are read only because of where they are installed.)

Exceptions
IO_ERRORif no library at aLibraryPath exists.

Definition at line 344 of file fp_lib_table.cpp.

References FindRow(), LIB_TABLE_ROW::GetFullURI(), PLUGIN::IsFootprintLibWritable(), and FP_LIB_TABLE_ROW::plugin.

Referenced by FOOTPRINT_EDIT_FRAME::updateTitle().

345 {
346  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
347  wxASSERT( (PLUGIN*) row->plugin );
348  return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) );
349 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
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...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: plugin.cpp:114
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
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 414 of file lib_table_base.cpp.

References LIB_TABLE::Parse().

Referenced by SCH_EDIT_FRAME::AppendSchematic(), LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), PROJECT::PcbFootprintLibs(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

416 {
417  // It's OK if footprint library tables are missing.
418  if( wxFileName::IsFileReadable( aFileName ) )
419  {
420  FILE_LINE_READER reader( aFileName );
421  LIB_TABLE_LEXER lexer( &reader );
422 
423  Parse( &lexer );
424  }
425 }
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
virtual void Parse(LIB_TABLE_LEXER *aLexer)=0
Parse the LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW object...
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 FP_LIB_TABLE::LoadGlobalTable ( FP_LIB_TABLE aTable)
static

Function LoadGlobalTable loads the global footprint 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 FP_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 footprint library table.

Definition at line 405 of file fp_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 CV::IFACE::OnKifaceStart(), and PCB::IFACE::OnKifaceStart().

406 {
407  bool tableExists = true;
408  wxFileName fn = GetGlobalTableFileName();
409 
410  if( !fn.FileExists() )
411  {
412  tableExists = false;
413 
414  if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
415  {
416  THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
417  GetChars( fn.GetPath() ) ) );
418  }
419 
420  // Attempt to copy the default global file table from the KiCad
421  // template folder to the user's home configuration path.
422  wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name );
423 
424  // The fallback is to create an empty global footprint table for the user to populate.
425  if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
426  {
427  FP_LIB_TABLE emptyTable;
428 
429  emptyTable.Save( fn.GetFullPath() );
430  }
431  }
432 
433  aTable.Load( fn.GetFullPath() );
434 
435  return tableExists;
436 }
static const wxChar global_tbl_name[]
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
Write this library table to aFileName in s-expression form.
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
bool FP_LIB_TABLE::operator!= ( const FP_LIB_TABLE r) const
inline

Definition at line 128 of file fp_lib_table.h.

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

Definition at line 334 of file lib_table_base.h.

334 { return !( *this == r ); }
bool FP_LIB_TABLE::operator== ( const FP_LIB_TABLE aFpTable) const

Definition at line 210 of file fp_lib_table.cpp.

References LIB_TABLE::rows.

211 {
212  if( rows.size() == aFpTable.rows.size() )
213  {
214  for( unsigned i = 0; i < rows.size(); ++i )
215  {
216  if( (FP_LIB_TABLE_ROW&)rows[i] != (FP_LIB_TABLE_ROW&)aFpTable.rows[i] )
217  return false;
218  }
219 
220  return true;
221  }
222 
223  return false;
224 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
LIB_TABLE_ROWS rows
bool LIB_TABLE::operator== ( const LIB_TABLE r) const
inlineinherited

Definition at line 318 of file lib_table_base.h.

References LIB_TABLE::rows.

319  {
320  if( rows.size() == r.rows.size() )
321  {
322  unsigned i;
323 
324  for( i = 0; i < rows.size() && rows[i] == r.rows[i]; ++i )
325  ;
326 
327  if( i == rows.size() )
328  return true;
329  }
330 
331  return false;
332  }
LIB_TABLE_ROWS rows
void FP_LIB_TABLE::Parse ( LIB_TABLE_LEXER aLexer)
overridevirtual

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

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

Implements LIB_TABLE.

Definition at line 67 of file fp_lib_table.cpp.

References DSNLEXER::CurLineNumber(), 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, LIB_TABLE_T::T_disabled, DSN::T_EOF, FP_LIB_TABLE_T::T_fp_lib_table, DSN::T_LEFT, FP_LIB_TABLE_T::T_lib, TLIB_T::T_name, FP_LIB_TABLE_T::T_options, DSN::T_RIGHT, DSN::T_type, FP_LIB_TABLE_T::T_uri, THROW_IO_ERROR, and DSNLEXER::Unexpected().

Referenced by FP_GRID_TRICKS::paste_text().

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

469 {
470  if( aOptionsList.size() )
471  {
472  const char* cp = &aOptionsList[0];
473  const char* end = cp + aOptionsList.size();
474 
475  PROPERTIES props;
476  std::string pair;
477 
478  // Parse all name=value pairs
479  while( cp < end )
480  {
481  pair.clear();
482 
483  // Skip leading white space.
484  while( cp < end && isspace( *cp ) )
485  ++cp;
486 
487  // Find the end of pair/field
488  while( cp < end )
489  {
490  if( *cp == '\\' && cp + 1 < end && cp[1] == OPT_SEP )
491  {
492  ++cp; // skip the escape
493  pair += *cp++; // add the separator
494  }
495  else if( *cp == OPT_SEP )
496  {
497  ++cp; // skip the separator
498  break; // process the pair
499  }
500  else
501  pair += *cp++;
502  }
503 
504  // stash the pair
505  if( pair.size() )
506  {
507  // first equals sign separates 'name' and 'value'.
508  size_t eqNdx = pair.find( '=' );
509 
510  if( eqNdx != pair.npos )
511  {
512  std::string name = pair.substr( 0, eqNdx );
513  std::string value = pair.substr( eqNdx + 1 );
514  props[name] = value;
515  }
516  else
517  props[pair] = ""; // property is present, but with no value.
518  }
519  }
520 
521  if( props.size() )
522  return new PROPERTIES( props );
523  }
524 
525  return NULL;
526 }
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 FP_LIB_TABLE::PrefetchLib ( const wxString &  aNickname)

Function PrefetchLib If possible, prefetches the specified library (e.g.

performing downloads). Does not parse. Threadsafe.

This is a no-op for libraries that cannot be prefetched.

Parameters
aNicknameis a locator for the library; it is a name in LIB_TABLE_ROW.
Exceptions
IO_ERRORif there is an error prefetching the library.

Definition at line 247 of file fp_lib_table.cpp.

References FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetProperties(), FP_LIB_TABLE_ROW::plugin, and PLUGIN::PrefetchLib().

Referenced by FOOTPRINT_LIST_IMPL::loader_job().

248 {
249  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
250  wxASSERT( (PLUGIN*) row->plugin );
251  row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() );
252 }
virtual void PrefetchLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function PrefetchLib If possible, prefetches the specified library (e.g.
Definition: plugin.cpp:69
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_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...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:265
void LIB_TABLE::reindex ( )
inlineprotectedinherited

Definition at line 468 of file lib_table_base.h.

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

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

469  {
470  nickIndex.clear();
471 
472  for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
473  nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
474  }
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

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

Parameters
aFileNameis the name of the file to write to.

Definition at line 428 of file lib_table_base.cpp.

References LIB_TABLE::Format().

Referenced by LoadGlobalTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), CVPCB_MAINFRAME::OnEditFootprintLibraryTable(), PCB_EDIT_FRAME::Process_Config(), FOOTPRINT_EDIT_FRAME::ProcessPreferences(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

429 {
430  FILE_OUTPUTFORMATTER sf( aFileName );
431  Format( &sf, 0 );
432 }
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

Friends And Related Function Documentation

friend class FP_LIB_TABLE_GRID
friend

Definition at line 105 of file fp_lib_table.h.

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