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
 
bool ContainsNickname (const wxString &aNickname)
 
KICAD_T Type () override
 
virtual void Parse (LIB_TABLE_LEXER *aLexer) override
 Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objects. More...
 
virtual void Format (OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
 Generate the table in s-expression format to aOutput with an indention level of aIndentLevel. More...
 
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...
 
bool FootprintExists (const wxString &aNickname, const wxString &aFootprintName)
 Function FootprintExists. More...
 
const MODULEGetEnumeratedFootprint (const wxString &aNickname, const wxString &aFootprintName)
 Function GetEnumeratedFootprint. 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, bool aCheckEnabled=false) const
 Test for the existence of aNickname in the library table. More...
 
std::vector< wxString > GetLogicalLibs ()
 Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE. More...
 
wxString GetFullURI (const wxString &aLibNickname, bool aExpandEnvVars=true) const
 Return the full URI of the library mapped to aLibNickname. More...
 
bool InsertRow (LIB_TABLE_ROW *aRow, bool doReplace=false)
 Adds aRow if it does not already exist or if doReplace is true. More...
 
const LIB_TABLE_ROWFindRowByURI (const wxString &aURI)
 
void Load (const wxString &aFileName)
 Load the library table using the path defined by aFileName aFallBackTable. More...
 
void Save (const wxString &aFileName) const
 Write this library table to aFileName in s-expression form. More...
 

Static Public Member Functions

static bool LoadGlobalTable (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 PANEL_FP_LIB_TABLE
 
class FP_GRID_TRICKS
 

Detailed Description

This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.

Definition at line 114 of file panel_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 477 of file lib_table_base.h.

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protectedinherited

Definition at line 479 of file lib_table_base.h.

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protectedinherited

Definition at line 478 of file lib_table_base.h.

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protectedinherited

Definition at line 480 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 210 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 145 of file panel_fp_lib_table.cpp.

References LIB_TABLE::rows.

146  {
147  rows = aTableToEdit.rows;
148  }
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 120 of file panel_fp_lib_table.cpp.

References LIB_TABLE::rows.

Referenced by FP_GRID_TRICKS::optionsEditor().

120 { 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 129 of file panel_fp_lib_table.cpp.

References LIB_TABLE::rows.

129 { 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 PANEL_FP_LIB_TABLE::TransferDataFromWindow(), and PANEL_SYM_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::ContainsNickname ( const wxString &  aNickname)
inlineinherited

Definition at line 203 of file lib_table_grid.h.

References LIB_TABLE_GRID::at(), LIB_TABLE_GRID::begin(), LIB_TABLE_GRID::erase(), LIB_TABLE_ROW::GetNickName(), i, LIB_TABLE_GRID::insert(), LIB_TABLE_GRID::makeNewRow(), LIB_TABLE_GRID::push_back(), and LIB_TABLE_GRID::size().

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

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

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

Definition at line 465 of file lib_table_base.h.

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

466  {
467  // The dialog lib table editor may not maintain the nickIndex.
468  // Lazy indexing may be required. To handle lazy indexing, we must enforce
469  // that "nickIndex" is either empty or accurate, but never inaccurate.
470  if( !nickIndex.size() )
471  reindex();
472  }
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 138 of file panel_fp_lib_table.cpp.

References LIB_TABLE::rows.

139  {
140  return rows.erase( aFirst, aLast );
141  }
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 548 of file lib_table_base.cpp.

References ExpandEnvVarSubstitutions().

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

549 {
550  return ExpandEnvVarSubstitutions( aString );
551 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Replace any environment variable references with their values.
Definition: common.cpp:442
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 FP_TREE_MODEL_ADAPTER::AddLibraries(), FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary(), 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(), FP_LIB_TABLE::GetEnumeratedFootprint(), FP_LIB_TABLE::IsFootprintLibWritable(), FP_LIB_TABLE::operator!=(), FP_LIB_TABLE::PrefetchLib(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), and FOOTPRINT_VIEWER_FRAME::UpdateTitle().

277 {
278  // Do not optimize this code. Is done this way specifically to fix a runtime
279  // error with clang 4.0.1.
280  LIB_TABLE_ROW* ltrow = findRow( aNickname );
281  FP_LIB_TABLE_ROW* row = dynamic_cast< FP_LIB_TABLE_ROW* >( ltrow );
282 
283  if( !row )
284  {
285  wxString msg = wxString::Format(
286  _( "fp-lib-table files contain no library with nickname \"%s\"" ),
287  GetChars( aNickname ) );
288 
289  THROW_IO_ERROR( msg );
290  }
291 
292  // We've been 'lazy' up until now, but it cannot be deferred any longer,
293  // instantiate a PLUGIN of the proper kind if it is not already in this
294  // FP_LIB_TABLE_ROW.
295  if( !row->plugin )
296  row->setPlugin( IO_MGR::PluginFind( row->type ) );
297 
298  return row;
299 }
void setPlugin(PLUGIN *aPlugin)
Definition: fp_lib_table.h:93
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
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
#define THROW_IO_ERROR(msg)
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
LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname) const
protectedinherited

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

Definition at line 291 of file lib_table_base.cpp.

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

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

Definition at line 313 of file lib_table_base.cpp.

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

314 {
315  LIB_TABLE* cur = (LIB_TABLE*) this;
316 
317  do
318  {
319  cur->ensureIndex();
320 
321  INDEX_ITER it = cur->nickIndex.find( aNickName );
322 
323  if( it != cur->nickIndex.end() )
324  {
325  return &cur->rows[it->second]; // found
326  }
327 
328  // not found, search fall back table(s), if any
329  } while( ( cur = cur->fallBack ) != 0 );
330 
331  return NULL; // not found
332 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
INDEX::iterator INDEX_ITER
INDEX nickIndex
this particular key is the nickName within each row.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
const LIB_TABLE_ROW * LIB_TABLE::FindRowByURI ( const wxString &  aURI)
inherited
Returns
a LIB_TABLE_ROW pointer if aURI is found in this table or in any chained fallBack table fragments, else NULL.

Definition at line 335 of file lib_table_base.cpp.

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

Referenced by FOOTPRINT_EDIT_FRAME::KiwayMailIn(), and LIB_EDIT_FRAME::KiwayMailIn().

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

392 {
393  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
394  wxASSERT( (PLUGIN*) row->plugin );
395  return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName,
396  row->GetProperties() );
397 }
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:60
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
bool FP_LIB_TABLE::FootprintExists ( const wxString &  aNickname,
const wxString &  aFootprintName 
)
inherited

Function FootprintExists.

indicates whether or not the given footprint already exists in the given library.

Definition at line 337 of file fp_lib_table.cpp.

References FP_LIB_TABLE::FootprintLoad().

Referenced by FP_LIB_TABLE::operator!=(), and FOOTPRINT_EDIT_FRAME::SaveFootprintAs().

338 {
339  try
340  {
341  std::unique_ptr<MODULE> m( FootprintLoad( aNickname, aFootprintName ) );
342  return m.get() != nullptr;
343  }
344  catch( ... )
345  {
346  return false;
347  }
348 }
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
void FP_LIB_TABLE::FootprintLibCreate ( const wxString &  aNickname)
inherited

Definition at line 416 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.

417 {
418  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
419  wxASSERT( (PLUGIN*) row->plugin );
420  row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() );
421 }
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:109
void FP_LIB_TABLE::FootprintLibDelete ( const wxString &  aNickname)
inherited

Definition at line 408 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.

409 {
410  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
411  wxASSERT( (PLUGIN*) row->plugin );
412  row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() );
413 }
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:116
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 351 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::FootprintExists(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FP_LIB_TABLE::operator!=(), and FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint().

352 {
353  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
354  wxASSERT( (PLUGIN*) row->plugin );
355 
356  MODULE* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName,
357  row->GetProperties() );
358 
359  setLibNickname( ret, row->GetNickName(), aFootprintName );
360 
361  return ret;
362 }
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:84
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 424 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().

425 {
426  wxString nickname = aFootprintId.GetLibNickname();
427  wxString fpname = aFootprintId.GetLibItemName();
428 
429  if( nickname.size() )
430  {
431  return FootprintLoad( nickname, fpname );
432  }
433 
434  // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
435  else
436  {
437  std::vector<wxString> nicks = GetLogicalLibs();
438 
439  // Search each library going through libraries alphabetically.
440  for( unsigned i = 0; i < nicks.size(); ++i )
441  {
442  // FootprintLoad() returns NULL on not found, does not throw exception
443  // unless there's an IO_ERROR.
444  MODULE* ret = FootprintLoad( nicks[i], fpname );
445 
446  if( ret )
447  return ret;
448  }
449 
450  return NULL;
451  }
452 }
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
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:97
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 365 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().

367 {
368  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
369  wxASSERT( (PLUGIN*) row->plugin );
370 
371  if( !aOverwrite )
372  {
373  // Try loading the footprint to see if it already exists, caller wants overwrite
374  // protection, which is atypical, not the default.
375 
376  wxString fpname = aFootprint->GetFPID().GetLibItemName();
377 
378  std::unique_ptr<MODULE> footprint( row->plugin->FootprintLoad( row->GetFullURI( true ),
379  fpname, row->GetProperties() ) );
380 
381  if( footprint.get() )
382  return SAVE_SKIPPED;
383  }
384 
385  row->plugin->FootprintSave( row->GetFullURI( true ), aFootprint, row->GetProperties() );
386 
387  return SAVE_OK;
388 }
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:93
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:193
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:84
const UTF8 & GetLibItemName() const
Definition: lib_id.h: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: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::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 510 of file lib_table_base.cpp.

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

Referenced by DIALOG_FP_PLUGIN_OPTIONS::TransferDataFromWindow().

511 {
512  UTF8 ret;
513 
514  if( aProperties )
515  {
516  for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
517  {
518  const std::string& name = it->first;
519 
520  const UTF8& value = it->second;
521 
522  if( ret.size() )
523  ret += OPT_SEP;
524 
525  ret += name;
526 
527  // the separation between name and value is '='
528  if( value.size() )
529  {
530  ret += '=';
531 
532  for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
533  {
534  // escape any separator in the value.
535  if( *si == OPT_SEP )
536  ret += '\\';
537 
538  ret += *si;
539  }
540  }
541  }
542  }
543 
544  return ret;
545 }
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 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 ) ) + wxHashTable::MakeKey( *aNickname );
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 ) ) + wxHashTable::MakeKey( nickname );
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 186 of file lib_table_grid.h.

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

187  {
188  switch( aCol )
189  {
190  case COL_NICKNAME: return _( "Nickname" );
191  case COL_URI: return _( "Library Path" );
192 
193  // keep this "Plugin Type" text fairly long so column is sized wide enough
194  case COL_TYPE: return _( "Plugin Type" );
195  case COL_OPTIONS: return _( "Options" );
196  case COL_DESCR: return _( "Description" );
197  case COL_ENABLED: return _( "Active" );
198 
199  default: return wxEmptyString;
200  }
201  }
int LIB_TABLE::GetCount ( )
inlineinherited
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 SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), LIB_EDIT_FRAME::savePartAs(), 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.
const MODULE * FP_LIB_TABLE::GetEnumeratedFootprint ( const wxString &  aNickname,
const wxString &  aFootprintName 
)
inherited

Function GetEnumeratedFootprint.

a version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management. Return value is const to allow it to return a reference to a cached item.

Definition at line 326 of file fp_lib_table.cpp.

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

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

328 {
329  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
330  wxASSERT( (PLUGIN*) row->plugin );
331 
332  return row->plugin->GetEnumeratedFootprint( row->GetFullURI( true ), aFootprintName,
333  row->GetProperties() );
334 }
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 const MODULE * GetEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function GetEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for m...
Definition: plugin.cpp:75
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
wxString LIB_TABLE::GetFullURI ( const wxString &  aLibNickname,
bool  aExpandEnvVars = true 
) const
inherited

Return the full URI of the library mapped to aLibNickname.

Definition at line 278 of file lib_table_base.cpp.

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

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

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

Function GetGlobalTableFileName.

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

Definition at line 495 of file fp_lib_table.cpp.

References GetKicadConfigPath(), and global_tbl_name.

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), InvokePcbLibTableEditor(), and FP_LIB_TABLE::LoadGlobalTable().

496 {
497  wxFileName fn;
498 
499  fn.SetPath( GetKicadConfigPath() );
500  fn.SetName( global_tbl_name );
501 
502  return fn.GetFullPath();
503 }
static const wxChar global_tbl_name[]
wxString GetKicadConfigPath()
Return the user configuration path used to store KiCad&#39;s configuration files.
Definition: common.cpp:263
std::vector< wxString > LIB_TABLE::GetLogicalLibs ( )
inherited

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

Definition at line 371 of file lib_table_base.cpp.

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

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FP_LIB_TABLE::GenerateTimestamp(), SYMBOL_LIB_TABLE::GetModifyHash(), guessNickname(), CVPCB_MAINFRAME::LoadFootprintFiles(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), FOOTPRINT_VIEWER_FRAME::OnActivate(), LIB_VIEW_FRAME::OnSelectSymbol(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), LIB_EDIT_FRAME::savePartAs(), SCH_BASE_FRAME::SelectComponentFromLibTree(), PCB_BASE_FRAME::SelectLibrary(), FOOTPRINT_LIST_IMPL::StartWorkers(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

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

Definition at line 53 of file lib_table_grid.h.

References LIB_TABLE_GRID::size().

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

53 { return (int) size(); }
virtual size_t size() const =0
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().

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

Referenced by DIALOG_CONFIG_EQUFILES::Init(), and PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable().

456 {
457  return "KISYSMOD";
458 }
bool LIB_TABLE::HasLibrary ( const wxString &  aNickname,
bool  aCheckEnabled = false 
) const
inherited

Test for the existence of aNickname in the library table.

Parameters
aCheckEnabledif true will only return true for enabled libraries
Returns
true if a library aNickname exists in the table.

Definition at line 264 of file lib_table_base.cpp.

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

Referenced by SCH_EDIT_FRAME::AppendSchematic(), FOOTPRINT_EDIT_FRAME::KiwayMailIn(), LIB_EDIT_FRAME::KiwayMailIn(), LIB_MANAGER::LibraryExists(), SCH_EAGLE_PLUGIN::Load(), NETLIST_EXPORTER_GENERIC::makeLibraries(), SCH_COMPONENT::Resolve(), SCH_BASE_FRAME::SelectComponentFromLibTree(), SCH_COMPONENT::SetLibId(), FOOTPRINT_VIEWER_FRAME::ShowModal(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

265 {
266  const LIB_TABLE_ROW* row = findRow( aNickname );
267 
268  if( row == nullptr )
269  return false;
270 
271  if( aCheckEnabled && !row->GetIsEnabled() )
272  return false;
273 
274  return true;
275 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
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 GetIsEnabled() const
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 131 of file panel_fp_lib_table.cpp.

References LIB_TABLE::rows.

132  {
133  return rows.insert( aIterator, aRow );
134  }
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 405 of file lib_table_base.cpp.

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

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), LIB_MANAGER::addLibrary(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), PCB_EDIT_FRAME::importFile(), SCH_EAGLE_PLUGIN::Load(), FP_LIB_TABLE::Parse(), and SYMBOL_LIB_TABLE::Parse().

406 {
407  ensureIndex();
408 
409  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
410 
411  if( it == nickIndex.end() )
412  {
413  rows.push_back( aRow );
414  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
415  return true;
416  }
417 
418  if( doReplace )
419  {
420  rows.replace( it->second, aRow );
421  return true;
422  }
423 
424  return false;
425 }
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(), and PCB_EDIT_FRAME::LoadFootprints().

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

401 {
402  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
403  wxASSERT( (PLUGIN*) row->plugin );
404  return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) );
405 }
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:124
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 428 of file lib_table_base.cpp.

References LIB_TABLE::Parse().

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

430 {
431  // It's OK if footprint library tables are missing.
432  if( wxFileName::IsFileReadable( aFileName ) )
433  {
434  FILE_LINE_READER reader( aFileName );
435  LIB_TABLE_LEXER lexer( &reader );
436 
437  Parse( &lexer );
438  }
439 }
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...
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 461 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().

462 {
463  bool tableExists = true;
464  wxFileName fn = GetGlobalTableFileName();
465 
466  if( !fn.FileExists() )
467  {
468  tableExists = false;
469 
470  if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
471  {
472  THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path \"%s\"." ),
473  GetChars( fn.GetPath() ) ) );
474  }
475 
476  // Attempt to copy the default global file table from the KiCad
477  // template folder to the user's home configuration path.
478  wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name );
479 
480  // The fallback is to create an empty global footprint table for the user to populate.
481  if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
482  {
483  FP_LIB_TABLE emptyTable;
484 
485  emptyTable.Save( fn.GetFullPath() );
486  }
487  }
488 
489  aTable.Load( fn.GetFullPath() );
490 
491  return tableExists;
492 }
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.
#define THROW_IO_ERROR(msg)
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:73
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
LIB_TABLE_ROW* FP_LIB_TABLE_GRID::makeNewRow ( )
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 124 of file panel_fp_lib_table.cpp.

125  {
126  return dynamic_cast< LIB_TABLE_ROW* >( new FP_LIB_TABLE_ROW );
127  }
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 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.
#define THROW_IO_ERROR(msg)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
PROPERTIES * LIB_TABLE::ParseOptions ( const std::string &  aOptionsList)
staticinherited

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

References name, and OPT_SEP.

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

450 {
451  if( aOptionsList.size() )
452  {
453  const char* cp = &aOptionsList[0];
454  const char* end = cp + aOptionsList.size();
455 
456  PROPERTIES props;
457  std::string pair;
458 
459  // Parse all name=value pairs
460  while( cp < end )
461  {
462  pair.clear();
463 
464  // Skip leading white space.
465  while( cp < end && isspace( *cp ) )
466  ++cp;
467 
468  // Find the end of pair/field
469  while( cp < end )
470  {
471  if( *cp == '\\' && cp + 1 < end && cp[1] == OPT_SEP )
472  {
473  ++cp; // skip the escape
474  pair += *cp++; // add the separator
475  }
476  else if( *cp == OPT_SEP )
477  {
478  ++cp; // skip the separator
479  break; // process the pair
480  }
481  else
482  pair += *cp++;
483  }
484 
485  // stash the pair
486  if( pair.size() )
487  {
488  // first equals sign separates 'name' and 'value'.
489  size_t eqNdx = pair.find( '=' );
490 
491  if( eqNdx != pair.npos )
492  {
493  std::string name = pair.substr( 0, eqNdx );
494  std::string value = pair.substr( eqNdx + 1 );
495  props[name] = value;
496  }
497  else
498  props[pair] = ""; // property is present, but with no value.
499  }
500  }
501 
502  if( props.size() )
503  return new PROPERTIES( props );
504  }
505 
506  return NULL;
507 }
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:68
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 136 of file panel_fp_lib_table.cpp.

References LIB_TABLE::rows.

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

Definition at line 457 of file lib_table_base.h.

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

458  {
459  nickIndex.clear();
460 
461  for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
462  nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
463  }
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 442 of file lib_table_base.cpp.

References LIB_TABLE::Format().

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), PCB_EDIT_FRAME::importFile(), InvokePcbLibTableEditor(), InvokeSchEditSymbolLibTable(), SYMBOL_LIB_TABLE::LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), SCH_BASE_FRAME::saveSymbolLibTables(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

443 {
444  FILE_OUTPUTFORMATTER sf( aFileName );
445  Format( &sf, 0 );
446 }
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().

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 122 of file panel_fp_lib_table.cpp.

References LIB_TABLE::rows.

122 { return rows.size(); }
LIB_TABLE_ROWS rows
KICAD_T FP_LIB_TABLE::Type ( )
inlineoverridevirtualinherited

Friends And Related Function Documentation

friend class FP_GRID_TRICKS
friend

Definition at line 117 of file panel_fp_lib_table.cpp.

friend class PANEL_FP_LIB_TABLE
friend

Definition at line 116 of file panel_fp_lib_table.cpp.

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