KiCad PCB EDA Suite
FP_LIB_TABLE_GRID Class Reference

This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object. More...

Inheritance diagram for FP_LIB_TABLE_GRID:
LIB_TABLE_GRID FP_LIB_TABLE LIB_TABLE PROJECT::_ELEM

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

 FP_LIB_TABLE_GRID (const FP_LIB_TABLE &aTableToEdit)
 
int GetNumberRows () override
 
int GetNumberCols () override
 
wxString GetValue (int aRow, int aCol) override
 
bool GetValueAsBool (int aRow, int aCol) override
 
void SetValue (int aRow, int aCol, const wxString &aValue) override
 
void SetValueAsBool (int aRow, int aCol, bool aValue) override
 
bool IsEmptyCell (int aRow, int aCol) override
 
bool InsertRows (size_t aPos=0, size_t aNumRows=1) override
 
bool AppendRows (size_t aNumRows=1) override
 
bool DeleteRows (size_t aPos, size_t aNumRows) override
 
wxString GetColLabelValue (int aCol) override
 
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...
 
bool operator== (const FP_LIB_TABLE &aFpTable) const
 
bool operator== (const LIB_TABLE &r) const
 
bool operator!= (const FP_LIB_TABLE &r) const
 
bool operator!= (const 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...
 
long long GenerateTimestamp (const wxString *aNickname)
 Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname, or all libraries if aNickname is NULL. 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...
 
MODULELoadEnumeratedFootprint (const wxString &aNickname, const wxString &aFootprintName)
 Function LoadEnumeratedFootprint. 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...
 
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_ROWat (size_t aIndex) override
 
size_t size () const override
 
LIB_TABLE_ROWmakeNewRow () override
 
LIB_TABLE_ROWS_ITER begin () override
 
LIB_TABLE_ROWS_ITER insert (LIB_TABLE_ROWS_ITER aIterator, LIB_TABLE_ROW *aRow) override
 
void push_back (LIB_TABLE_ROW *aRow) override
 
LIB_TABLE_ROWS_ITER erase (LIB_TABLE_ROWS_ITER aFirst, LIB_TABLE_ROWS_ITER aLast) override
 
LIB_TABLE_ROWfindRow (const wxString &aNickname) const
 Return a LIB_TABLE_ROW if aNickname is found in this table or in any chained fallBack table fragment, else NULL. More...
 
LIB_TABLE_ROWfindRow (const wxString &aNickname)
 
void reindex ()
 
void ensureIndex ()
 

Protected Attributes

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

Friends

class FP_GRID_TRICKS
 

Detailed Description

This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

Definition at line 54 of file dialog_fp_lib_table.cpp.

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 FP_LIB_TABLE::SAVE_T
inherited

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

Enumerator
SAVE_OK 
SAVE_SKIPPED 

Definition at line 200 of file fp_lib_table.h.

Constructor & Destructor Documentation

FP_LIB_TABLE_GRID::FP_LIB_TABLE_GRID ( const FP_LIB_TABLE aTableToEdit)
inline

Definition at line 84 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

Referenced by DIALOG_FP_LIB_TABLE::DIALOG_FP_LIB_TABLE().

85  {
86  rows = aTableToEdit.rows;
87  }
LIB_TABLE_ROWS rows

Member Function Documentation

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

Definition at line 145 of file lib_table_grid.h.

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

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

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

Implements LIB_TABLE_GRID.

Definition at line 59 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

59 { return &rows.at( aIndex ); }
LIB_TABLE_ROWS rows
LIB_TABLE_ROW* LIB_TABLE::At ( int  aIndex)
inlineinherited

Definition at line 338 of file lib_table_base.h.

References LIB_TABLE_ROW::GetFullURI(), Load(), and Save.

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

338 { return &rows[aIndex]; }
LIB_TABLE_ROWS rows
LIB_TABLE_ROWS_ITER FP_LIB_TABLE_GRID::begin ( )
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 68 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

68 { return rows.begin(); }
LIB_TABLE_ROWS rows
void LIB_TABLE::Clear ( )
inlineinherited

Delete all rows.

Definition at line 312 of file lib_table_base.h.

Referenced by 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.
bool LIB_TABLE_GRID::DeleteRows ( size_t  aPos,
size_t  aNumRows 
)
inlineoverrideinherited

Definition at line 163 of file lib_table_grid.h.

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

Referenced by DIALOG_SYMBOL_LIB_TABLE::verifyTables(), and DIALOG_FP_LIB_TABLE::verifyTables().

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

Definition at line 476 of file lib_table_base.h.

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.
LIB_TABLE_ROWS_ITER FP_LIB_TABLE_GRID::erase ( LIB_TABLE_ROWS_ITER  aFirst,
LIB_TABLE_ROWS_ITER  aLast 
)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 77 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

78  {
79  return rows.erase( aFirst, aLast );
80  }
LIB_TABLE_ROWS rows
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 575 of file lib_table_base.cpp.

References ExpandEnvVarSubstitutions().

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

576 {
577  return ExpandEnvVarSubstitutions( aString );
578 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Function ExpandEnvVarSubstitutions replaces any environment variable references with their values...
Definition: common.cpp:255
const FP_LIB_TABLE_ROW * FP_LIB_TABLE::FindRow ( const wxString &  aNickName)
inherited

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 276 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(), FP_LIB_TABLE::FootprintDelete(), FP_LIB_TABLE::FootprintEnumerate(), FP_LIB_TABLE::FootprintLibCreate(), FP_LIB_TABLE::FootprintLibDelete(), FP_LIB_TABLE::FootprintLoad(), FP_LIB_TABLE::FootprintSave(), FP_LIB_TABLE::GenerateTimestamp(), FOOTPRINT_EDIT_FRAME::getLibPath(), FP_LIB_TABLE::IsFootprintLibWritable(), FP_LIB_TABLE::LoadEnumeratedFootprint(), FP_LIB_TABLE::operator!=(), FP_LIB_TABLE::PrefetchLib(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), FOOTPRINT_VIEWER_FRAME::UpdateTitle(), and FOOTPRINT_EDIT_FRAME::updateTitle().

277 {
278  FP_LIB_TABLE_ROW* row = dynamic_cast< FP_LIB_TABLE_ROW* >( findRow( aNickname ) );
279 
280  if( !row )
281  {
282  wxString msg = wxString::Format(
283  _( "fp-lib-table files contain no library with nickname \"%s\"" ),
284  GetChars( aNickname ) );
285 
286  THROW_IO_ERROR( msg );
287  }
288 
289  // We've been 'lazy' up until now, but it cannot be deferred any longer,
290  // instantiate a PLUGIN of the proper kind if it is not already in this
291  // FP_LIB_TABLE_ROW.
292  if( !row->plugin )
293  row->setPlugin( IO_MGR::PluginFind( row->type ) );
294 
295  return row;
296 }
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 285 of file lib_table_base.cpp.

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

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

286 {
287  LIB_TABLE* cur = (LIB_TABLE*) this;
288 
289  do
290  {
291  cur->ensureIndex();
292 
293  INDEX_CITER it = cur->nickIndex.find( aNickName );
294 
295  if( it != cur->nickIndex.end() )
296  {
297  return &cur->rows[it->second]; // found
298  }
299 
300  // not found, search fall back table(s), if any
301  } while( ( cur = cur->fallBack ) != 0 );
302 
303  return NULL; // not found
304 }
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 307 of file lib_table_base.cpp.

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

308 {
309  LIB_TABLE* cur = (LIB_TABLE*) this;
310 
311  do
312  {
313  cur->ensureIndex();
314 
315  INDEX_ITER it = cur->nickIndex.find( aNickName );
316 
317  if( it != cur->nickIndex.end() )
318  {
319  return &cur->rows[it->second]; // found
320  }
321 
322  // not found, search fall back table(s), if any
323  } while( ( cur = cur->fallBack ) != 0 );
324 
325  return NULL; // not found
326 }
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 329 of file lib_table_base.cpp.

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

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

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 378 of file fp_lib_table.cpp.

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

Referenced by FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary().

379 {
380  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
381  wxASSERT( (PLUGIN*) row->plugin );
382  return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName,
383  row->GetProperties() );
384 }
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:266
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:101
void FP_LIB_TABLE::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aNickname 
)
inherited

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 259 of file fp_lib_table.cpp.

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

Referenced by guessNickname(), FOOTPRINT_LIST_IMPL::JoinWorkers(), and FP_LIB_TABLE::operator!=().

260 {
261  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
262  wxASSERT( (PLUGIN*) row->plugin );
263  row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ),
264  row->GetProperties() );
265 }
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:266
void FP_LIB_TABLE::FootprintLibCreate ( const wxString &  aNickname)
inherited

Definition at line 403 of file fp_lib_table.cpp.

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

404 {
405  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
406  wxASSERT( (PLUGIN*) row->plugin );
407  row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() );
408 }
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:266
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
Definition: plugin.cpp:108
void FP_LIB_TABLE::FootprintLibDelete ( const wxString &  aNickname)
inherited

Definition at line 395 of file fp_lib_table.cpp.

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

396 {
397  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
398  wxASSERT( (PLUGIN*) row->plugin );
399  row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() );
400 }
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: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:266
MODULE * FP_LIB_TABLE::FootprintLoad ( const wxString &  aNickname,
const wxString &  aFootprintName 
)
inherited

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 338 of file fp_lib_table.cpp.

References FP_LIB_TABLE::FindRow(), PLUGIN::FootprintLoad(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetProperties(), FP_LIB_TABLE_ROW::plugin, and setLibNickname().

Referenced by FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FP_LIB_TABLE::operator!=(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), and FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint().

339 {
340  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
341  wxASSERT( (PLUGIN*) row->plugin );
342 
343  MODULE* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName,
344  row->GetProperties() );
345 
346  setLibNickname( ret, row->GetNickName(), aFootprintName );
347 
348  return ret;
349 }
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 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:85
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:266
static void setLibNickname(MODULE *aModule, const wxString &aNickname, const wxString &aFootprintName)
MODULE * FP_LIB_TABLE::FootprintLoadWithOptionalNickname ( const LIB_ID aFootprintId)
inherited

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 411 of file fp_lib_table.cpp.

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

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

412 {
413  wxString nickname = aFootprintId.GetLibNickname();
414  wxString fpname = aFootprintId.GetLibItemName();
415 
416  if( nickname.size() )
417  {
418  return FootprintLoad( nickname, fpname );
419  }
420 
421  // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
422  else
423  {
424  std::vector<wxString> nicks = GetLogicalLibs();
425 
426  // Search each library going through libraries alphabetically.
427  for( unsigned i = 0; i < nicks.size(); ++i )
428  {
429  // FootprintLoad() returns NULL on not found, does not throw exception
430  // unless there's an IO_ERROR.
431  MODULE* ret = FootprintLoad( nicks[i], fpname );
432 
433  if( ret )
434  return ret;
435  }
436 
437  return NULL;
438  }
439 }
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
size_t i
Definition: json11.cpp:597
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:101
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 
)
inherited

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 352 of file fp_lib_table.cpp.

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

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

354 {
355  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
356  wxASSERT( (PLUGIN*) row->plugin );
357 
358  if( !aOverwrite )
359  {
360  // Try loading the footprint to see if it already exists, caller wants overwrite
361  // protection, which is atypical, not the default.
362 
363  wxString fpname = aFootprint->GetFPID().GetLibItemName();
364 
365  std::unique_ptr<MODULE> footprint( row->plugin->FootprintLoad( row->GetFullURI( true ),
366  fpname, row->GetProperties() ) );
367 
368  if( footprint.get() )
369  return SAVE_SKIPPED;
370  }
371 
372  row->plugin->FootprintSave( row->GetFullURI( true ), aFootprint, row->GetProperties() );
373 
374  return SAVE_OK;
375 }
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:94
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:191
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:85
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
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:266
void FP_LIB_TABLE::Format ( OUTPUTFORMATTER aOutput,
int  aIndentLevel 
) const
overridevirtualinherited

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

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

Implements LIB_TABLE.

Definition at line 227 of file 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 537 of file lib_table_base.cpp.

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

Referenced by DIALOG_FP_PLUGIN_OPTIONS::makeResult().

538 {
539  UTF8 ret;
540 
541  if( aProperties )
542  {
543  for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
544  {
545  const std::string& name = it->first;
546 
547  const UTF8& value = it->second;
548 
549  if( ret.size() )
550  ret += OPT_SEP;
551 
552  ret += name;
553 
554  // the separation between name and value is '='
555  if( value.size() )
556  {
557  ret += '=';
558 
559  for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
560  {
561  // escape any separator in the value.
562  if( *si == OPT_SEP )
563  ret += '\\';
564 
565  ret += *si;
566  }
567  }
568  }
569  }
570 
571  return ret;
572 }
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:197
std::string::const_iterator begin() const
Definition: utf8.h:196
const char * name
Definition: DXF_plotter.cpp:61
#define OPT_SEP
options separator character
long long FP_LIB_TABLE::GenerateTimestamp ( const wxString *  aNickname)
inherited

Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname, or all libraries if aNickname is NULL.

Definition at line 238 of file fp_lib_table.cpp.

References FP_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), PLUGIN::GetLibraryTimestamp(), LIB_TABLE::GetLogicalLibs(), and FP_LIB_TABLE_ROW::plugin.

Referenced by FOOTPRINT_LIST_IMPL::JoinWorkers(), FP_LIB_TABLE::operator!=(), and FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

239 {
240  if( aNickname )
241  {
242  const FP_LIB_TABLE_ROW* row = FindRow( *aNickname );
243  wxASSERT( (PLUGIN*) row->plugin );
244  return row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) );
245  }
246 
247  long long hash = 0;
248  for( wxString const& nickname : GetLogicalLibs() )
249  {
250  const FP_LIB_TABLE_ROW* row = FindRow( nickname );
251  wxASSERT( (PLUGIN*) row->plugin );
252  hash += row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) );
253  }
254 
255  return hash;
256 }
virtual long long GetLibraryTimestamp(const wxString &aLibraryPath) const =0
Generate a timestamp representing all the files in the library (including the library directory)...
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
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:266
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE...
wxString LIB_TABLE_GRID::GetColLabelValue ( int  aCol)
inlineoverrideinherited

Definition at line 188 of file lib_table_grid.h.

References LIB_TABLE_GRID::at(), LIB_TABLE_GRID::begin(), COL_DESCR, COL_ENABLED, COL_NICKNAME, COL_OPTIONS, COL_TYPE, COL_URI, LIB_TABLE_GRID::erase(), LIB_TABLE_GRID::insert(), LIB_TABLE_GRID::makeNewRow(), LIB_TABLE_GRID::push_back(), and LIB_TABLE_GRID::size().

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

Definition at line 336 of file lib_table_base.h.

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

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

Referenced by CMP_TREE_MODEL_ADAPTER::AddAliasList(), CMP_TREE_MODEL_ADAPTER::AddLibrary(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), and PCB_BASE_FRAME::SelectLibrary().

253 {
254  // use "no exception" form of find row:
255  const LIB_TABLE_ROW* row = findRow( aNickname );
256 
257  if( row )
258  return row->GetDescr();
259  else
260  return wxEmptyString;
261 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
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 443 of file lib_table_base.cpp.

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

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

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

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

273 {
274  const LIB_TABLE_ROW* row = findRow( aNickname );
275 
276  wxString retv;
277 
278  if( row )
279  retv = row->GetFullURI( aExpandEnvVars );
280 
281  return retv;
282 }
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 ( )
staticinherited

Function GetGlobalTableFileName.

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

Definition at line 482 of file fp_lib_table.cpp.

References GetKicadConfigPath(), and global_tbl_name.

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

483 {
484  wxFileName fn;
485 
486  fn.SetPath( GetKicadConfigPath() );
487  fn.SetName( global_tbl_name );
488 
489  return fn.GetFullPath();
490 }
static const wxChar global_tbl_name[]
wxString GetKicadConfigPath()
Function GetKicadConfigPath.
Definition: common.cpp:218
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 365 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(), FP_LIB_TABLE::GenerateTimestamp(), SYMBOL_LIB_TABLE::GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), FOOTPRINT_VIEWER_FRAME::OnActivate(), LIB_VIEW_FRAME::OnSelectSymbol(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), SCH_BASE_FRAME::SelectComponentFromLibrary(), PCB_BASE_FRAME::SelectLibrary(), and FOOTPRINT_LIST_IMPL::StartWorkers().

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

Definition at line 55 of file lib_table_grid.h.

References COL_COUNT.

55 { return COL_COUNT; }
wxString LIB_TABLE_GRID::GetValue ( int  aRow,
int  aCol 
)
inlineoverrideinherited

Definition at line 57 of file lib_table_grid.h.

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

Referenced by LIB_TABLE_GRID::IsEmptyCell(), DIALOG_SYMBOL_LIB_TABLE::populateEnvironReadOnlyTable(), DIALOG_FP_LIB_TABLE::populateEnvironReadOnlyTable(), DIALOG_SYMBOL_LIB_TABLE::verifyTables(), and DIALOG_FP_LIB_TABLE::verifyTables().

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

Definition at line 80 of file lib_table_grid.h.

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

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

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 442 of file fp_lib_table.cpp.

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

443 {
444  return "KISYSMOD";
445 }
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 264 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_COMPONENT::Resolve(), SCH_BASE_FRAME::SelectComponentFromLibrary(), and SCH_COMPONENT::SetLibId().

265 {
266  const LIB_TABLE_ROW* row = findRow( aNickname );
267 
268  return row != nullptr;
269 }
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...
LIB_TABLE_ROWS_ITER FP_LIB_TABLE_GRID::insert ( LIB_TABLE_ROWS_ITER  aIterator,
LIB_TABLE_ROW aRow 
)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 70 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

71  {
72  return rows.insert( aIterator, aRow );
73  }
LIB_TABLE_ROWS rows
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 399 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(), PCB_EDIT_FRAME::importFile(), InvokeFootprintWizard(), SCH_EAGLE_PLUGIN::Load(), FP_LIB_TABLE::Parse(), and SYMBOL_LIB_TABLE::Parse().

400 {
401  ensureIndex();
402 
403  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
404 
405  if( it == nickIndex.end() )
406  {
407  rows.push_back( aRow );
408  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
409  return true;
410  }
411 
412  if( doReplace )
413  {
414  rows.replace( it->second, aRow );
415  return true;
416  }
417 
418  return false;
419 }
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_GRID::InsertRows ( size_t  aPos = 0,
size_t  aNumRows = 1 
)
inlineoverrideinherited

Definition at line 119 of file lib_table_grid.h.

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

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

Return true if the table is empty.

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

Definition at line 243 of file lib_table_base.cpp.

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

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

Definition at line 114 of file lib_table_grid.h.

References LIB_TABLE_GRID::GetValue().

115  {
116  return !GetValue( aRow, aCol );
117  }
wxString GetValue(int aRow, int aCol) override
bool FP_LIB_TABLE::IsFootprintLibWritable ( const wxString &  aNickname)
inherited

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 387 of file fp_lib_table.cpp.

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

Referenced by FOOTPRINT_EDIT_FRAME::updateTitle().

388 {
389  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
390  wxASSERT( (PLUGIN*) row->plugin );
391  return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) );
392 }
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:123
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:266
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 422 of file lib_table_base.cpp.

References LIB_TABLE::Parse().

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

424 {
425  // It's OK if footprint library tables are missing.
426  if( wxFileName::IsFileReadable( aFileName ) )
427  {
428  FILE_LINE_READER reader( aFileName );
429  LIB_TABLE_LEXER lexer( &reader );
430 
431  Parse( &lexer );
432  }
433 }
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
virtual void Parse(LIB_TABLE_LEXER *aLexer)=0
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
MODULE * FP_LIB_TABLE::LoadEnumeratedFootprint ( const wxString &  aNickname,
const wxString &  aFootprintName 
)
inherited

Function LoadEnumeratedFootprint.

a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.

Definition at line 323 of file fp_lib_table.cpp.

References FP_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetFullURI(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_ROW::GetProperties(), PLUGIN::LoadEnumeratedFootprint(), FP_LIB_TABLE_ROW::plugin, and setLibNickname().

Referenced by FOOTPRINT_INFO_IMPL::load(), and FP_LIB_TABLE::operator!=().

325 {
326  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
327  wxASSERT( (PLUGIN*) row->plugin );
328 
329  MODULE* ret = row->plugin->LoadEnumeratedFootprint( row->GetFullURI( true ), aFootprintName,
330  row->GetProperties() );
331 
332  setLibNickname( ret, row->GetNickName(), aFootprintName );
333 
334  return ret;
335 }
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.
const wxString & GetNickName() const
virtual MODULE * LoadEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function LoadEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for ...
Definition: plugin.cpp:76
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
static void setLibNickname(MODULE *aModule, const wxString &aNickname, const wxString &aFootprintName)
bool FP_LIB_TABLE::LoadGlobalTable ( FP_LIB_TABLE aTable)
staticinherited

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 448 of file fp_lib_table.cpp.

References SEARCH_STACK::FindValidPath(), Format(), GetChars(), FP_LIB_TABLE::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().

449 {
450  bool tableExists = true;
451  wxFileName fn = GetGlobalTableFileName();
452 
453  if( !fn.FileExists() )
454  {
455  tableExists = false;
456 
457  if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
458  {
459  THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path \"%s\"." ),
460  GetChars( fn.GetPath() ) ) );
461  }
462 
463  // Attempt to copy the default global file table from the KiCad
464  // template folder to the user's home configuration path.
465  wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name );
466 
467  // The fallback is to create an empty global footprint table for the user to populate.
468  if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
469  {
470  FP_LIB_TABLE emptyTable;
471 
472  emptyTable.Save( fn.GetFullPath() );
473  }
474  }
475 
476  aTable.Load( fn.GetFullPath() );
477 
478  return tableExists;
479 }
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 &#39;non-library&#39; 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.
LIB_TABLE_ROW* FP_LIB_TABLE_GRID::makeNewRow ( )
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 63 of file dialog_fp_lib_table.cpp.

64  {
65  return dynamic_cast< LIB_TABLE_ROW* >( new FP_LIB_TABLE_ROW );
66  }
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 FP_LIB_TABLE::operator!= ( const FP_LIB_TABLE r) const
inlineinherited
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
inherited

Definition at line 210 of file fp_lib_table.cpp.

References i, and 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
size_t i
Definition: json11.cpp:597
bool LIB_TABLE::operator== ( const LIB_TABLE r) const
inlineinherited

Definition at line 318 of file lib_table_base.h.

References i, and 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
size_t i
Definition: json11.cpp:597
void FP_LIB_TABLE::Parse ( LIB_TABLE_LEXER *  aLexer)
overridevirtualinherited

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

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

Implements LIB_TABLE.

Definition at line 67 of file fp_lib_table.cpp.

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

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

477 {
478  if( aOptionsList.size() )
479  {
480  const char* cp = &aOptionsList[0];
481  const char* end = cp + aOptionsList.size();
482 
483  PROPERTIES props;
484  std::string pair;
485 
486  // Parse all name=value pairs
487  while( cp < end )
488  {
489  pair.clear();
490 
491  // Skip leading white space.
492  while( cp < end && isspace( *cp ) )
493  ++cp;
494 
495  // Find the end of pair/field
496  while( cp < end )
497  {
498  if( *cp == '\\' && cp + 1 < end && cp[1] == OPT_SEP )
499  {
500  ++cp; // skip the escape
501  pair += *cp++; // add the separator
502  }
503  else if( *cp == OPT_SEP )
504  {
505  ++cp; // skip the separator
506  break; // process the pair
507  }
508  else
509  pair += *cp++;
510  }
511 
512  // stash the pair
513  if( pair.size() )
514  {
515  // first equals sign separates 'name' and 'value'.
516  size_t eqNdx = pair.find( '=' );
517 
518  if( eqNdx != pair.npos )
519  {
520  std::string name = pair.substr( 0, eqNdx );
521  std::string value = pair.substr( eqNdx + 1 );
522  props[name] = value;
523  }
524  else
525  props[pair] = ""; // property is present, but with no value.
526  }
527  }
528 
529  if( props.size() )
530  return new PROPERTIES( props );
531  }
532 
533  return NULL;
534 }
std::vector< PROPERTY > PROPERTIES
Definition: specctra.h:184
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
const char * name
Definition: DXF_plotter.cpp:61
#define OPT_SEP
options separator character
void FP_LIB_TABLE::PrefetchLib ( const wxString &  aNickname)
inherited

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 268 of file fp_lib_table.cpp.

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

Referenced by FOOTPRINT_LIST_IMPL::loader_job(), and FP_LIB_TABLE::operator!=().

269 {
270  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
271  wxASSERT( (PLUGIN*) row->plugin );
272  row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() );
273 }
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:266
void FP_LIB_TABLE_GRID::push_back ( LIB_TABLE_ROW aRow)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 75 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

75 { rows.push_back( aRow ); }
LIB_TABLE_ROWS rows
void LIB_TABLE::reindex ( )
inlineprotectedinherited

Definition at line 468 of file lib_table_base.h.

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

References LIB_TABLE::Format().

Referenced by PCB_EDIT_FRAME::importFile(), FP_LIB_TABLE::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().

437 {
438  FILE_OUTPUTFORMATTER sf( aFileName );
439  Format( &sf, 0 );
440 }
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
void LIB_TABLE_GRID::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
inlineoverrideinherited

Definition at line 88 of file lib_table_grid.h.

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

Referenced by DIALOG_FP_LIB_TABLE::OnClickLibraryWizard(), DIALOG_SYMBOL_LIB_TABLE::verifyTables(), and DIALOG_FP_LIB_TABLE::verifyTables().

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

Definition at line 108 of file lib_table_grid.h.

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

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

Implements LIB_TABLE_GRID.

Definition at line 61 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

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

Friends And Related Function Documentation

friend class FP_GRID_TRICKS
friend

Definition at line 56 of file dialog_fp_lib_table.cpp.

Referenced by DIALOG_FP_LIB_TABLE::DIALOG_FP_LIB_TABLE().

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::findRow(), and LIB_TABLE::InsertRow().


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