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
 
void SetValue (int aRow, int aCol, const wxString &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 GenLastModifiedChecksum (const wxString *aNickname)
 Generate a checksum of the last-mod-date of aNickname's directory, or a checksum of all the libraries' directories 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...
 
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 53 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 193 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 83 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

Referenced by DIALOG_FP_LIB_TABLE::DIALOG_FP_LIB_TABLE().

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

Member Function Documentation

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

Definition at line 132 of file lib_table_grid.h.

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

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

133  {
134  // do not modify aNumRows, original value needed for wxGridTableMessage below
135  for( int i = aNumRows; i; --i )
136  push_back( makeNewRow() );
137 
138  if( GetView() )
139  {
140  wxGridTableMessage msg( this,
141  wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
142  aNumRows );
143 
144  GetView()->ProcessTableMessage( msg );
145  }
146 
147  return true;
148  }
virtual LIB_TABLE_ROW * makeNewRow()=0
virtual void push_back(LIB_TABLE_ROW *aRow)=0
LIB_TABLE_ROW* FP_LIB_TABLE_GRID::at ( size_t  aIndex)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 58 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

58 { 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 67 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

67 { 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 150 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().

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

References LIB_TABLE::rows.

77  {
78  return rows.erase( aFirst, aLast );
79  }
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:254
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 277 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::GenLastModifiedChecksum(), FOOTPRINT_EDIT_FRAME::getLibPath(), FP_LIB_TABLE::IsFootprintLibWritable(), FP_LIB_TABLE::operator!=(), FP_LIB_TABLE::PrefetchLib(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), FOOTPRINT_VIEWER_FRAME::UpdateTitle(), and FOOTPRINT_EDIT_FRAME::updateTitle().

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

358 {
359  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
360  wxASSERT( (PLUGIN*) row->plugin );
361  return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName,
362  row->GetProperties() );
363 }
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:92
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 260 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!=().

261 {
262  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
263  wxASSERT( (PLUGIN*) row->plugin );
264  row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ),
265  row->GetProperties() );
266 }
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 382 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.

383 {
384  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
385  wxASSERT( (PLUGIN*) row->plugin );
386  row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() );
387 }
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:99
void FP_LIB_TABLE::FootprintLibDelete ( const wxString &  aNickname)
inherited

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

375 {
376  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
377  wxASSERT( (PLUGIN*) row->plugin );
378  row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() );
379 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.
Definition: plugin.cpp:106
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h: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 300 of file fp_lib_table.cpp.

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

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

301 {
302  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
303  wxASSERT( (PLUGIN*) row->plugin );
304 
305  MODULE* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName,
306  row->GetProperties() );
307 
308  // The library cannot know its own name, because it might have been renamed or moved.
309  // Therefore footprints cannot know their own library nickname when residing in
310  // a footprint library.
311  // Only at this API layer can we tell the footprint about its actual library nickname.
312  if( ret )
313  {
314  // remove "const"-ness, I really do want to set nickname without
315  // having to copy the LIB_ID and its two strings, twice each.
316  LIB_ID& fpid = (LIB_ID&) ret->GetFPID();
317 
318  // Catch any misbehaving plugin, which should be setting internal footprint name properly:
319  wxASSERT( aFootprintName == fpid.GetLibItemName().wx_str() );
320 
321  // and clearing nickname
322  wxASSERT( !fpid.GetLibNickname().size() );
323 
324  fpid.SetLibNickname( row->GetNickName() );
325  }
326 
327  return ret;
328 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
std::string::size_type size() const
Definition: utf8.h:115
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
const LIB_ID & GetFPID() const
Definition: class_module.h:191
wxString wx_str() const
Definition: utf8.cpp:48
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:76
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:219
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
const wxString & GetNickName() const
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:98
MODULE * FP_LIB_TABLE::FootprintLoadWithOptionalNickname ( const LIB_ID aFootprintId)
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 390 of file fp_lib_table.cpp.

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

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

391 {
392  wxString nickname = aFootprintId.GetLibNickname();
393  wxString fpname = aFootprintId.GetLibItemName();
394 
395  if( nickname.size() )
396  {
397  return FootprintLoad( nickname, fpname );
398  }
399 
400  // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
401  else
402  {
403  std::vector<wxString> nicks = GetLogicalLibs();
404 
405  // Search each library going through libraries alphabetically.
406  for( unsigned i = 0; i < nicks.size(); ++i )
407  {
408  // FootprintLoad() returns NULL on not found, does not throw exception
409  // unless there's an IO_ERROR.
410  MODULE* ret = FootprintLoad( nicks[i], fpname );
411 
412  if( ret )
413  return ret;
414  }
415 
416  return NULL;
417  }
418 }
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:98
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE...
FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave ( const wxString &  aNickname,
const MODULE aFootprint,
bool  aOverwrite = true 
)
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 331 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().

333 {
334  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
335  wxASSERT( (PLUGIN*) row->plugin );
336 
337  if( !aOverwrite )
338  {
339  // Try loading the footprint to see if it already exists, caller wants overwrite
340  // protection, which is atypical, not the default.
341 
342  wxString fpname = aFootprint->GetFPID().GetLibItemName();
343 
344  std::unique_ptr<MODULE> footprint( row->plugin->FootprintLoad( row->GetFullURI( true ),
345  fpname, row->GetProperties() ) );
346 
347  if( footprint.get() )
348  return SAVE_SKIPPED;
349  }
350 
351  row->plugin->FootprintSave( row->GetFullURI( true ), aFootprint, row->GetProperties() );
352 
353  return SAVE_OK;
354 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).
virtual void FootprintSave(const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL)
Function FootprintSave will write aModule to an existing library located at aLibraryPath.
Definition: plugin.cpp:85
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
const LIB_ID & GetFPID() const
Definition: class_module.h: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:76
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h: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::GenLastModifiedChecksum ( const wxString *  aNickname)
inherited

Generate a checksum of the last-mod-date of aNickname's directory, or a checksum of all the libraries' directories if aNickname is NULL.

Definition at line 238 of file fp_lib_table.cpp.

References FP_LIB_TABLE::FindRow(), PLUGIN::GetLibModificationTime(), 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->GetLibModificationTime( *aNickname ).GetValue().GetValue();
245  }
246 
247  long long hash = 0;
248 
249  for( wxString const& nickname : GetLogicalLibs() )
250  {
251  const FP_LIB_TABLE_ROW* row = FindRow( nickname );
252  wxASSERT( (PLUGIN*) row->plugin );
253  hash += row->plugin->GetLibModificationTime( nickname ).GetValue().GetValue();
254  }
255 
256  return hash;
257 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
virtual wxDateTime GetLibModificationTime(const wxString &aLibraryPath) const
Return the footprint lib last-mod-time, if available.
Definition: io_mgr.h:359
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 175 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().

176  {
177  switch( aCol )
178  {
179  case COL_NICKNAME: return _( "Nickname" );
180  case COL_URI: return _( "Library Path" );
181 
182  // keep this "Plugin Type" text fairly long so column is sized wide enough
183  case COL_TYPE: return _( "Plugin Type" );
184  case COL_OPTIONS: return _( "Options" );
185  case COL_DESCR: return _( "Description" );
186  case COL_ENABLED: return _( "Active" );
187 
188  default: return wxEmptyString;
189  }
190  }
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, 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
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 461 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().

462 {
463  wxFileName fn;
464 
465  fn.SetPath( GetKicadConfigPath() );
466  fn.SetName( global_tbl_name );
467 
468  return fn.GetFullPath();
469 }
static const wxChar global_tbl_name[]
wxString GetKicadConfigPath()
Function GetKicadConfigPath.
Definition: common.cpp:217
std::vector< wxString > LIB_TABLE::GetLogicalLibs ( )
inherited

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

Definition at line 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::GenLastModifiedChecksum(), 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() ? "1" : "";
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
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 421 of file fp_lib_table.cpp.

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

422 {
423  return "KISYSMOD";
424 }
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 69 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

70  {
71  return rows.insert( aIterator, aRow );
72  }
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 106 of file lib_table_grid.h.

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

107  {
108  if( aPos < size() )
109  {
110  for( size_t i = 0; i < aNumRows; i++ )
111  {
112  insert( begin() + i, makeNewRow() );
113  }
114 
115  // use the (wxGridStringTable) source Luke.
116  if( GetView() )
117  {
118  wxGridTableMessage msg( this,
119  wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
120  aPos,
121  aNumRows );
122 
123  GetView()->ProcessTableMessage( msg );
124  }
125 
126  return true;
127  }
128 
129  return false;
130  }
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
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 101 of file lib_table_grid.h.

References LIB_TABLE_GRID::GetValue().

102  {
103  return !GetValue( aRow, aCol );
104  }
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 366 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().

367 {
368  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
369  wxASSERT( (PLUGIN*) row->plugin );
370  return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) );
371 }
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: plugin.cpp:114
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h: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...
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 427 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().

428 {
429  bool tableExists = true;
430  wxFileName fn = GetGlobalTableFileName();
431 
432  if( !fn.FileExists() )
433  {
434  tableExists = false;
435 
436  if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
437  {
438  THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path \"%s\"." ),
439  GetChars( fn.GetPath() ) ) );
440  }
441 
442  // Attempt to copy the default global file table from the KiCad
443  // template folder to the user's home configuration path.
444  wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name );
445 
446  // The fallback is to create an empty global footprint table for the user to populate.
447  if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
448  {
449  FP_LIB_TABLE emptyTable;
450 
451  emptyTable.Save( fn.GetFullPath() );
452  }
453  }
454 
455  aTable.Load( fn.GetFullPath() );
456 
457  return tableExists;
458 }
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 62 of file dialog_fp_lib_table.cpp.

63  {
64  return dynamic_cast< LIB_TABLE_ROW* >( new FP_LIB_TABLE_ROW );
65  }
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 LIB_TABLE::rows.

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

Definition at line 318 of file lib_table_base.h.

References LIB_TABLE::rows.

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

270 {
271  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
272  wxASSERT( (PLUGIN*) row->plugin );
273  row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() );
274 }
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 74 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

74 { 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 80 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().

81  {
82  if( aRow < (int) size() )
83  {
84  LIB_TABLE_ROW* r = at( (size_t) aRow );
85 
86  switch( aCol )
87  {
88  case COL_NICKNAME: r->SetNickName( aValue ); break;
89  case COL_URI: r->SetFullURI( aValue ); break;
90  case COL_TYPE: r->SetType( aValue ); break;
91  case COL_OPTIONS: r->SetOptions( aValue ); break;
92  case COL_DESCR: r->SetDescr( aValue ); break;
93  case COL_ENABLED:
94  // Any non-empty string will set enabled to true
95  r->SetEnabled( !aValue.IsEmpty() );
96  break;
97  }
98  }
99  }
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.
size_t FP_LIB_TABLE_GRID::size ( ) const
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 60 of file dialog_fp_lib_table.cpp.

References LIB_TABLE::rows.

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

Friends And Related Function Documentation

friend class FP_GRID_TRICKS
friend

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