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
 Compares this table against another. More...
 
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, bool aBestEfforts)
 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...
 
unsigned GetCount () const
 Get the number of rows contained in the table. More...
 
LIB_TABLE_ROWAt (unsigned aIndex)
 Get the 'n'th LIB_TABLE_ROW object. More...
 
const LIB_TABLE_ROWAt (unsigned aIndex) const
 Get the 'n'th LIB_TABLE_ROW object. More...
 
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...
 
bool RemoveRow (LIB_TABLE_ROW *aRow)
 Removes a row from the table. 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...
 

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

Member Typedef Documentation

◆ INDEX

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

this is a non-owning index into the LIB_TABLE_ROWS table

Definition at line 510 of file lib_table_base.h.

◆ INDEX_CITER

typedef INDEX::const_iterator LIB_TABLE::INDEX_CITER
protectedinherited

Definition at line 512 of file lib_table_base.h.

◆ INDEX_ITER

typedef INDEX::iterator LIB_TABLE::INDEX_ITER
protectedinherited

Definition at line 511 of file lib_table_base.h.

◆ INDEX_VALUE

typedef INDEX::value_type LIB_TABLE::INDEX_VALUE
protectedinherited

Definition at line 513 of file lib_table_base.h.

Member Enumeration Documentation

◆ SAVE_T

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 212 of file fp_lib_table.h.

Constructor & Destructor Documentation

◆ FP_LIB_TABLE_GRID()

FP_LIB_TABLE_GRID::FP_LIB_TABLE_GRID ( const FP_LIB_TABLE aTableToEdit)
inline

Definition at line 237 of file panel_fp_lib_table.cpp.

238  {
239  rows = aTableToEdit.rows;
240  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Member Function Documentation

◆ AppendRows()

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

Definition at line 145 of file lib_table_grid.h.

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, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, aNumRows );
154  GetView()->ProcessTableMessage( msg );
155  }
156 
157  return true;
158  }
virtual LIB_TABLE_ROW * makeNewRow()=0
virtual void push_back(LIB_TABLE_ROW *aRow)=0

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

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

◆ at()

LIB_TABLE_ROW* FP_LIB_TABLE_GRID::at ( size_t  aIndex)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 212 of file panel_fp_lib_table.cpp.

212 { return &rows.at( aIndex ); }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Referenced by FP_GRID_TRICKS::optionsEditor().

◆ At() [1/2]

LIB_TABLE_ROW& LIB_TABLE::At ( unsigned  aIndex)
inlineinherited

Get the 'n'th LIB_TABLE_ROW object.

Parameters
aIndexindex of row (must exist: from 0 to GetCount() - 1)
Returns
reference to the row

Definition at line 351 of file lib_table_base.h.

352  {
353  return rows[aIndex];
354  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

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

◆ At() [2/2]

const LIB_TABLE_ROW& LIB_TABLE::At ( unsigned  aIndex) const
inlineinherited

Get the 'n'th LIB_TABLE_ROW object.

Parameters
aIndexindex of row (must exist: from 0 to GetCount() - 1)
Returns
reference to the row

Definition at line 359 of file lib_table_base.h.

360  {
361  return rows[aIndex];
362  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ begin()

LIB_TABLE_ROWS_ITER FP_LIB_TABLE_GRID::begin ( )
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 221 of file panel_fp_lib_table.cpp.

221 { return rows.begin(); }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ Clear()

void LIB_TABLE::Clear ( )
inlineinherited

Delete all rows.

Definition at line 308 of file lib_table_base.h.

309  {
310  rows.clear();
311  nickIndex.clear();
312  }
LIB_TABLE_ROWS rows
INDEX nickIndex
this particular key is the nickName within each row.

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

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

◆ ContainsNickname()

bool LIB_TABLE_GRID::ContainsNickname ( const wxString &  aNickname)
inlineinherited

Definition at line 196 of file lib_table_grid.h.

197  {
198  for( size_t i = 0; i < size(); ++i )
199  {
200  LIB_TABLE_ROW* row = at( i );
201 
202  if( row->GetNickName() == aNickname )
203  return true;
204  }
205  return false;
206  }
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 & GetNickName() const
virtual size_t size() const =0

References LIB_TABLE_GRID::at(), LIB_TABLE_ROW::GetNickName(), and LIB_TABLE_GRID::size().

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

◆ DeleteRows()

bool LIB_TABLE_GRID::DeleteRows ( size_t  aPos,
size_t  aNumRows 
)
inlineoverrideinherited

Definition at line 160 of file lib_table_grid.h.

161  {
162  // aPos may be a large positive, e.g. size_t(-1), and the sum of
163  // aPos+aNumRows may wrap here, so both ends of the range are tested.
164  if( aPos < size() && aPos + aNumRows <= size() )
165  {
166  LIB_TABLE_ROWS_ITER start = begin() + aPos;
167  erase( start, start + aNumRows );
168  if( GetView() )
169  {
170  wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aPos, aNumRows );
171  GetView()->ProcessTableMessage( msg );
172  }
173  return true;
174  }
175 
176  return false;
177  }
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

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

◆ ensureIndex()

void LIB_TABLE::ensureIndex ( )
inlineprotectedinherited

Definition at line 498 of file lib_table_base.h.

499  {
500  // The dialog lib table editor may not maintain the nickIndex.
501  // Lazy indexing may be required. To handle lazy indexing, we must enforce
502  // that "nickIndex" is either empty or accurate, but never inaccurate.
503  if( !nickIndex.size() )
504  reindex();
505  }
void reindex()
INDEX nickIndex
this particular key is the nickName within each row.

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

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

◆ erase()

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

231  {
232  return rows.erase( aFirst, aLast );
233  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ FindRow()

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

283 {
284  // Do not optimize this code. Is done this way specifically to fix a runtime
285  // error with clang 4.0.1.
286  LIB_TABLE_ROW* ltrow = findRow( aNickname );
287  FP_LIB_TABLE_ROW* row = dynamic_cast< FP_LIB_TABLE_ROW* >( ltrow );
288 
289  if( !row )
290  {
291  wxString msg = wxString::Format(
292  _( "fp-lib-table files contain no library with nickname \"%s\"" ),
293  GetChars( aNickname ) );
294 
295  THROW_IO_ERROR( msg );
296  }
297 
298  // We've been 'lazy' up until now, but it cannot be deferred any longer,
299  // instantiate a PLUGIN of the proper kind if it is not already in this
300  // FP_LIB_TABLE_ROW.
301  if( !row->plugin )
302  row->setPlugin( IO_MGR::PluginFind( row->type ) );
303 
304  return row;
305 }
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.
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
#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:153
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 _(s)
Definition: 3d_actions.cpp:33
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 PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save,...
Definition: io_mgr.cpp:61

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::FootprintExists(), 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::PrefetchLib(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), and FOOTPRINT_VIEWER_FRAME::UpdateTitle().

◆ findRow() [1/2]

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

192 {
193  LIB_TABLE* cur = (LIB_TABLE*) this;
194 
195  do
196  {
197  cur->ensureIndex();
198 
199  INDEX_CITER it = cur->nickIndex.find( aNickName );
200 
201  if( it != cur->nickIndex.end() )
202  {
203  return &cur->rows[it->second]; // found
204  }
205 
206  // not found, search fall back table(s), if any
207  } while( ( cur = cur->fallBack ) != 0 );
208 
209  return nullptr; // not found
210 }
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.

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

◆ findRow() [2/2]

LIB_TABLE_ROW * LIB_TABLE::findRow ( const wxString &  aNickname)
protectedinherited

Definition at line 213 of file lib_table_base.cpp.

214 {
215  LIB_TABLE* cur = (LIB_TABLE*) this;
216 
217  do
218  {
219  cur->ensureIndex();
220 
221  INDEX_ITER it = cur->nickIndex.find( aNickName );
222 
223  if( it != cur->nickIndex.end() )
224  {
225  return &cur->rows[it->second]; // found
226  }
227 
228  // not found, search fall back table(s), if any
229  } while( ( cur = cur->fallBack ) != 0 );
230 
231  return nullptr; // not found
232 }
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.

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

◆ FindRowByURI()

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

236 {
237  LIB_TABLE* cur = this;
238 
239  do
240  {
241  cur->ensureIndex();
242 
243  for( unsigned i = 0; i < cur->rows.size(); i++ )
244  {
245  wxString tmp = cur->rows[i].GetFullURI( true );
246 
247  if( tmp.Find( "://" ) != wxNOT_FOUND )
248  {
249  if( tmp == aURI )
250  return &cur->rows[i]; // found as URI
251  }
252  else
253  {
254  wxFileName fn = aURI;
255 
256  // This will also test if the file is a symlink so if we are comparing
257  // a symlink to the same real file, the comparison will be true. See
258  // wxFileName::SameAs() in the wxWidgets source.
259  if( fn == wxFileName( tmp ) )
260  return &cur->rows[i]; // found as full path and file name
261  }
262  }
263 
264  // not found, search fall back table(s), if any
265  } while( ( cur = cur->fallBack ) != 0 );
266 
267  return nullptr; // not found
268 }
void ensureIndex()
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.

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

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

◆ FootprintDelete()

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

401 {
402  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
403  wxASSERT( (PLUGIN*) row->plugin );
404  return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName,
405  row->GetProperties() );
406 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

Referenced by FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary().

◆ FootprintEnumerate()

void FP_LIB_TABLE::FootprintEnumerate ( wxArrayString &  aFootprintNames,
const wxString &  aNickname,
bool  aBestEfforts 
)
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.
aBestEffortsif true, don't throw on errors
Exceptions
IO_ERRORif the library cannot be found, or footprint cannot be loaded.

Definition at line 264 of file fp_lib_table.cpp.

266 {
267  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
268  wxASSERT( (PLUGIN*) row->plugin );
269  row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts,
270  row->GetProperties() );
271 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

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

◆ FootprintExists()

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

344 {
345  try
346  {
347  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
348  wxASSERT( (PLUGIN*) row->plugin );
349 
350  return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName,
351  row->GetProperties() );
352  }
353  catch( ... )
354  {
355  return false;
356  }
357 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

Referenced by FOOTPRINT_EDITOR_TOOLS::PasteFootprint(), and FOOTPRINT_EDIT_FRAME::SaveFootprintAs().

◆ FootprintLibCreate()

void FP_LIB_TABLE::FootprintLibCreate ( const wxString &  aNickname)
inherited

Definition at line 425 of file fp_lib_table.cpp.

426 {
427  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
428  wxASSERT( (PLUGIN*) row->plugin );
429  row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() );
430 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

◆ FootprintLibDelete()

void FP_LIB_TABLE::FootprintLibDelete ( const wxString &  aNickname)
inherited

Definition at line 417 of file fp_lib_table.cpp.

418 {
419  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
420  wxASSERT( (PLUGIN*) row->plugin );
421  row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() );
422 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

◆ FootprintLoad()

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

361 {
362  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
363  wxASSERT( (PLUGIN*) row->plugin );
364 
365  MODULE* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName,
366  row->GetProperties() );
367 
368  setLibNickname( ret, row->GetNickName(), aFootprintName );
369 
370  return ret;
371 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 & GetNickName() const
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
static void setLibNickname(MODULE *aModule, const wxString &aNickname, const wxString &aFootprintName)
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

Referenced by FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), and FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint().

◆ FootprintLoadWithOptionalNickname()

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

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

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

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

◆ FootprintSave()

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

376 {
377  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
378  wxASSERT( (PLUGIN*) row->plugin );
379 
380  if( !aOverwrite )
381  {
382  // Try loading the footprint to see if it already exists, caller wants overwrite
383  // protection, which is atypical, not the default.
384 
385  wxString fpname = aFootprint->GetFPID().GetLibItemName();
386 
387  std::unique_ptr<MODULE> footprint( row->plugin->FootprintLoad( row->GetFullURI( true ),
388  fpname, row->GetProperties() ) );
389 
390  if( footprint.get() )
391  return SAVE_SKIPPED;
392  }
393 
394  row->plugin->FootprintSave( row->GetFullURI( true ), aFootprint, row->GetProperties() );
395 
396  return SAVE_OK;
397 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const LIB_ID & GetFPID() const
Definition: class_module.h:225
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

References FP_LIB_TABLE::FindRow(), 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().

◆ Format()

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

233 {
234  aOutput->Print( aIndentLevel, "(fp_lib_table\n" );
235 
236  for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
237  it->Format( aOutput, aIndentLevel+1 );
238 
239  aOutput->Print( aIndentLevel, ")\n" );
240 }
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

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

Referenced by FOOTPRINT_ASYNC_LOADER::Start().

◆ FormatOptions()

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

417 {
418  UTF8 ret;
419 
420  if( aProperties )
421  {
422  for( PROPERTIES::const_iterator it = aProperties->begin(); it != aProperties->end(); ++it )
423  {
424  const std::string& name = it->first;
425 
426  const UTF8& value = it->second;
427 
428  if( ret.size() )
429  ret += OPT_SEP;
430 
431  ret += name;
432 
433  // the separation between name and value is '='
434  if( value.size() )
435  {
436  ret += '=';
437 
438  for( std::string::const_iterator si = value.begin(); si != value.end(); ++si )
439  {
440  // escape any separator in the value.
441  if( *si == OPT_SEP )
442  ret += '\\';
443 
444  ret += *si;
445  }
446  }
447  }
448  }
449 
450  return ret;
451 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
const char * name
Definition: DXF_plotter.cpp:60
std::string::const_iterator end() const
Definition: utf8.h:197
std::string::const_iterator begin() const
Definition: utf8.h:196
std::string::size_type size() const
Definition: utf8.h:115
#define OPT_SEP
options separator character

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

Referenced by DIALOG_FP_PLUGIN_OPTIONS::TransferDataFromWindow().

◆ GenerateTimestamp()

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

244 {
245  if( aNickname )
246  {
247  const FP_LIB_TABLE_ROW* row = FindRow( *aNickname );
248  wxASSERT( (PLUGIN*) row->plugin );
249  return row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) + wxHashTable::MakeKey( *aNickname );
250  }
251 
252  long long hash = 0;
253  for( wxString const& nickname : GetLogicalLibs() )
254  {
255  const FP_LIB_TABLE_ROW* row = FindRow( nickname );
256  wxASSERT( (PLUGIN*) row->plugin );
257  hash += row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) + wxHashTable::MakeKey( nickname );
258  }
259 
260  return hash;
261 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

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

Referenced by FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

◆ GetColLabelValue()

wxString LIB_TABLE_GRID::GetColLabelValue ( int  aCol)
inlineoverrideinherited

Definition at line 179 of file lib_table_grid.h.

180  {
181  switch( aCol )
182  {
183  case COL_NICKNAME: return _( "Nickname" );
184  case COL_URI: return _( "Library Path" );
185 
186  // keep this "Plugin Type" text fairly long so column is sized wide enough
187  case COL_TYPE: return _( "Plugin Type" );
188  case COL_OPTIONS: return _( "Options" );
189  case COL_DESCR: return _( "Description" );
190  case COL_ENABLED: return _( "Active" );
191 
192  default: return wxEmptyString;
193  }
194  }
#define _(s)
Definition: 3d_actions.cpp:33

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

◆ GetCount()

unsigned LIB_TABLE::GetCount ( ) const
inlineinherited

Get the number of rows contained in the table.

Definition at line 341 of file lib_table_base.h.

342  {
343  return rows.size();
344  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Referenced by BOOST_AUTO_TEST_CASE(), FP_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount(), SYMBOL_GRID_TRICKS::paste_text(), and FP_GRID_TRICKS::paste_text().

◆ GetDescription()

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

153 {
154  // use "no exception" form of find row:
155  const LIB_TABLE_ROW* row = findRow( aNickname );
156 
157  if( row )
158  return row->GetDescr();
159  else
160  return wxEmptyString;
161 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
const wxString & GetDescr() const
Return the description of the library referenced by this row.
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,...

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

◆ GetEnumeratedFootprint()

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

334 {
335  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
336  wxASSERT( (PLUGIN*) row->plugin );
337 
338  return row->plugin->GetEnumeratedFootprint( row->GetFullURI( true ), aFootprintName,
339  row->GetProperties() );
340 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

Referenced by FOOTPRINT_INFO_IMPL::load().

◆ GetFullURI()

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

179 {
180  const LIB_TABLE_ROW* row = findRow( aNickname );
181 
182  wxString retv;
183 
184  if( row )
185  retv = row->GetFullURI( aExpandEnvVars );
186 
187  return retv;
188 }
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,...

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

Referenced by CVPCB_MAINFRAME::DisplayStatus(), SCH_EDIT_FRAME::LoadSheetFromFile(), and FOOTPRINT_EDIT_FRAME::Process_Special_Functions().

◆ GetGlobalTableFileName()

wxString FP_LIB_TABLE::GetGlobalTableFileName ( )
staticinherited

Function GetGlobalTableFileName.

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

Definition at line 514 of file fp_lib_table.cpp.

515 {
516  wxFileName fn;
517 
519  fn.SetName( global_tbl_name );
520 
521  return fn.GetFullPath();
522 }
static const wxChar global_tbl_name[]
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.

References SETTINGS_MANAGER::GetUserSettingsPath(), and global_tbl_name.

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::GetGlobalTableFileName(), InvokePcbLibTableEditor(), FP_LIB_TABLE::LoadGlobalTable(), PCB::IFACE::OnKifaceStart(), and DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ GetLogicalLibs()

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

272 {
273  // Only return unique logical library names. Use std::set::insert() to
274  // quietly reject any duplicates, which can happen when encountering a duplicate
275  // nickname from one of the fall back table(s).
276 
277  std::set< wxString > unique;
278  std::vector< wxString > ret;
279  const LIB_TABLE* cur = this;
280 
281  do
282  {
283  for( LIB_TABLE_ROWS_CITER it = cur->rows.begin(); it!=cur->rows.end(); ++it )
284  {
285  if( it->GetIsEnabled() )
286  {
287  unique.insert( it->GetNickName() );
288  }
289  }
290 
291  } while( ( cur = cur->fallBack ) != 0 );
292 
293  ret.reserve( unique.size() );
294 
295  // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
296  for( std::set< wxString >::const_iterator it = unique.begin(); it!=unique.end(); ++it )
297  {
298  ret.push_back( *it );
299  }
300 
301  // We want to allow case-sensitive duplicates but sort by case-insensitive ordering
302  std::sort( ret.begin(), ret.end(), []( const wxString& lhs, const wxString& rhs )
303  {
304  return lhs.CmpNoCase( rhs ) < 0;
305  } );
306 
307  return ret;
308 }
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.

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(), GetFootprintLibraries(), 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::SelectCompFromLibTree(), PCB_BASE_FRAME::SelectLibrary(), FOOTPRINT_LIST_IMPL::StartWorkers(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ GetNumberCols()

int LIB_TABLE_GRID::GetNumberCols ( )
inlineoverrideinherited

Definition at line 55 of file lib_table_grid.h.

55 { return COL_COUNT; }

References COL_COUNT.

◆ GetNumberRows()

int LIB_TABLE_GRID::GetNumberRows ( )
inlineoverrideinherited

Definition at line 53 of file lib_table_grid.h.

53 { return (int) size(); }
virtual size_t size() const =0

References LIB_TABLE_GRID::size().

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

◆ GetValue()

wxString LIB_TABLE_GRID::GetValue ( int  aRow,
int  aCol 
)
inlineoverrideinherited

Definition at line 57 of file lib_table_grid.h.

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  }
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
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 const wxString GetType() const =0
Return the type of library represented by this row.
const wxString & GetDescr() const
Return the description of the library referenced 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 & GetNickName() const
bool GetIsEnabled() const
virtual size_t size() const =0

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

◆ GetValueAsBool()

bool LIB_TABLE_GRID::GetValueAsBool ( int  aRow,
int  aCol 
)
inlineoverrideinherited

Definition at line 80 of file lib_table_grid.h.

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
bool GetIsEnabled() const
virtual size_t size() const =0

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

◆ GlobalPathEnvVariableName()

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

465 {
466  return "KISYSMOD";
467 }

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

◆ HasLibrary()

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

165 {
166  const LIB_TABLE_ROW* row = findRow( aNickname );
167 
168  if( row == nullptr )
169  return false;
170 
171  if( aCheckEnabled && !row->GetIsEnabled() )
172  return false;
173 
174  return true;
175 }
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
bool GetIsEnabled() const
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,...

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

Referenced by CVPCB_MAINFRAME::DisplayStatus(), InvokeSchEditSymbolLibTable(), FOOTPRINT_EDIT_FRAME::KiwayMailIn(), LIB_EDIT_FRAME::KiwayMailIn(), LIB_MANAGER::LibraryExists(), SCH_EAGLE_PLUGIN::Load(), SCH_EDIT_FRAME::LoadSheetFromFile(), SCH_BASE_FRAME::SelectCompFromLibTree(), LIB_VIEW_FRAME::ShowModal(), FOOTPRINT_VIEWER_FRAME::ShowModal(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), and SCH_SCREEN::UpdateSymbolLinks().

◆ insert()

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

224  {
225  return rows.insert( aIterator, aRow );
226  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ InsertRow()

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

312 {
313  ensureIndex();
314 
315  INDEX_CITER it = nickIndex.find( aRow->GetNickName() );
316 
317  if( it == nickIndex.end() )
318  {
319  rows.push_back( aRow );
320  nickIndex.insert( INDEX_VALUE( aRow->GetNickName(), rows.size() - 1 ) );
321  return true;
322  }
323 
324  if( doReplace )
325  {
326  rows.replace( it->second, aRow );
327  return true;
328  }
329 
330  return false;
331 }
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.

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(), LIB_TABLE_TEST_FIXTURE::LIB_TABLE_TEST_FIXTURE(), SCH_EAGLE_PLUGIN::Load(), FP_LIB_TABLE::Parse(), and SYMBOL_LIB_TABLE::Parse().

◆ InsertRows()

bool LIB_TABLE_GRID::InsertRows ( size_t  aPos = 0,
size_t  aNumRows = 1 
)
inlineoverrideinherited

Definition at line 119 of file lib_table_grid.h.

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

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

◆ IsEmpty()

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

144 {
145  if( !aIncludeFallback || !fallBack )
146  return rows.empty();
147 
148  return rows.empty() && fallBack->IsEmpty( true );
149 }
LIB_TABLE_ROWS rows
LIB_TABLE * fallBack
bool IsEmpty(bool aIncludeFallback=true)
Return true if the table is empty.

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

Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), LIB_TABLE::IsEmpty(), PCB_EDIT_FRAME::LoadFootprints(), and SCH_EDIT_FRAME::LoadSheetFromFile().

◆ IsEmptyCell()

bool LIB_TABLE_GRID::IsEmptyCell ( int  aRow,
int  aCol 
)
inlineoverrideinherited

Definition at line 114 of file lib_table_grid.h.

115  {
116  return !GetValue( aRow, aCol );
117  }
wxString GetValue(int aRow, int aCol) override

References LIB_TABLE_GRID::GetValue().

◆ IsFootprintLibWritable()

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

410 {
411  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
412  wxASSERT( (PLUGIN*) row->plugin );
413  return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) );
414 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273

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

Referenced by FOOTPRINT_EDIT_FRAME::updateTitle().

◆ Load()

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

336 {
337  // It's OK if footprint library tables are missing.
338  if( wxFileName::IsFileReadable( aFileName ) )
339  {
340  FILE_LINE_READER reader( aFileName );
341  LIB_TABLE_LEXER lexer( &reader );
342 
343  Parse( &lexer );
344  }
345 }
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...

References LIB_TABLE::Parse().

Referenced by SYMBOL_LIB_TABLE::LoadGlobalTable(), FP_LIB_TABLE::LoadGlobalTable(), SCH_EDIT_FRAME::LoadSheetFromFile(), PROJECT::PcbFootprintLibs(), DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow(), and DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ LoadGlobalTable()

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

471 {
472  bool tableExists = true;
473  wxFileName fn = GetGlobalTableFileName();
474 
475  if( !fn.FileExists() )
476  {
477  tableExists = false;
478 
479  if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
480  {
481  THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path \"%s\"." ),
482  GetChars( fn.GetPath() ) ) );
483  }
484 
485  // Attempt to copy the default global file table from the KiCad
486  // template folder to the user's home configuration path.
487  SEARCH_STACK ss;
488 
489  SystemDirsAppend( &ss );
490 
491  wxString templatePath =
492  Pgm().GetLocalEnvVariables().at( wxT( "KICAD_TEMPLATE_DIR" ) ).GetValue();
493 
494  if( !templatePath.IsEmpty() )
495  ss.AddPaths( templatePath, 0 );
496 
497  wxString fileName = ss.FindValidPath( global_tbl_name );
498 
499  // The fallback is to create an empty global footprint table for the user to populate.
500  if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
501  {
502  FP_LIB_TABLE emptyTable;
503 
504  emptyTable.Save( fn.GetFullPath() );
505  }
506  }
507 
508  aTable.Load( fn.GetFullPath() );
509 
510  return tableExists;
511 }
static const wxChar global_tbl_name[]
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:73
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
void SystemDirsAppend(SEARCH_STACK *aSearchStack)
Function SystemDirsAppend appends system places to aSearchStack in a platform specific way,...
#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:153
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 _(s)
Definition: 3d_actions.cpp:33
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
void AddPaths(const wxString &aPaths, int aIndex=-1)
Function AddPaths insert or append path(s)
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.

References _, SEARCH_STACK::AddPaths(), SEARCH_STACK::FindValidPath(), Format(), GetChars(), FP_LIB_TABLE::GetGlobalTableFileName(), global_tbl_name, LIB_TABLE::Load(), Pgm(), LIB_TABLE::Save(), SystemDirsAppend(), and THROW_IO_ERROR.

Referenced by CV::IFACE::OnKifaceStart(), PCB::IFACE::OnKifaceStart(), and DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ makeNewRow()

LIB_TABLE_ROW* FP_LIB_TABLE_GRID::makeNewRow ( )
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 216 of file panel_fp_lib_table.cpp.

217  {
218  return dynamic_cast< LIB_TABLE_ROW* >( new FP_LIB_TABLE_ROW );
219  }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42

◆ operator!=() [1/2]

bool FP_LIB_TABLE::operator!= ( const FP_LIB_TABLE r) const
inlineinherited

Definition at line 129 of file fp_lib_table.h.

129 { return !( *this == r ); }

◆ operator!=() [2/2]

bool LIB_TABLE::operator!= ( const LIB_TABLE r) const
inlineinherited

Definition at line 336 of file lib_table_base.h.

336 { return !( *this == r ); }

◆ operator==() [1/2]

bool FP_LIB_TABLE::operator== ( const FP_LIB_TABLE aFpTable) const
inherited

Definition at line 215 of file fp_lib_table.cpp.

216 {
217  if( rows.size() == aFpTable.rows.size() )
218  {
219  for( unsigned i = 0; i < rows.size(); ++i )
220  {
221  if( (FP_LIB_TABLE_ROW&)rows[i] != (FP_LIB_TABLE_ROW&)aFpTable.rows[i] )
222  return false;
223  }
224 
225  return true;
226  }
227 
228  return false;
229 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ operator==() [2/2]

bool LIB_TABLE::operator== ( const LIB_TABLE r) const
inlineinherited

Compares this table against another.

This compares the row contents against each other. Any fallback tables are not checked.

Definition at line 320 of file lib_table_base.h.

321  {
322  if( rows.size() == r.rows.size() )
323  {
324  unsigned i;
325 
326  for( i = 0; i < rows.size() && rows[i] == r.rows[i]; ++i )
327  ;
328 
329  if( i == rows.size() )
330  return true;
331  }
332 
333  return false;
334  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ Parse()

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

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

References _, Format(), GetChars(), LIB_TABLE::InsertRow(), DRCRULE_T::T_EOF, DRCRULE_T::T_LEFT, DRCRULE_T::T_name, DRCRULE_T::T_RIGHT, DRCRULE_T::T_type, and THROW_IO_ERROR.

Referenced by FP_GRID_TRICKS::paste_text().

◆ ParseOptions()

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

356 {
357  if( aOptionsList.size() )
358  {
359  const char* cp = &aOptionsList[0];
360  const char* end = cp + aOptionsList.size();
361 
362  PROPERTIES props;
363  std::string pair;
364 
365  // Parse all name=value pairs
366  while( cp < end )
367  {
368  pair.clear();
369 
370  // Skip leading white space.
371  while( cp < end && isspace( *cp ) )
372  ++cp;
373 
374  // Find the end of pair/field
375  while( cp < end )
376  {
377  if( *cp == '\\' && cp + 1 < end && cp[1] == OPT_SEP )
378  {
379  ++cp; // skip the escape
380  pair += *cp++; // add the separator
381  }
382  else if( *cp == OPT_SEP )
383  {
384  ++cp; // skip the separator
385  break; // process the pair
386  }
387  else
388  pair += *cp++;
389  }
390 
391  // stash the pair
392  if( pair.size() )
393  {
394  // first equals sign separates 'name' and 'value'.
395  size_t eqNdx = pair.find( '=' );
396 
397  if( eqNdx != pair.npos )
398  {
399  std::string name = pair.substr( 0, eqNdx );
400  std::string value = pair.substr( eqNdx + 1 );
401  props[name] = value;
402  }
403  else
404  props[pair] = ""; // property is present, but with no value.
405  }
406  }
407 
408  if( props.size() )
409  return new PROPERTIES( props );
410  }
411 
412  return nullptr;
413 }
std::vector< PROPERTY > PROPERTIES
Definition: specctra.h:184
PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
const char * name
Definition: DXF_plotter.cpp:60
#define OPT_SEP
options separator character

References name, and OPT_SEP.

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

◆ PrefetchLib()

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

275 {
276  const FP_LIB_TABLE_ROW* row = FindRow( aNickname );
277  wxASSERT( (PLUGIN*) row->plugin );
278  row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() );
279 }
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
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 FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:273
const PROPERTIES * GetProperties() const
Return the constant PROPERTIES for this library (LIB_TABLE_ROW).

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

Referenced by FOOTPRINT_LIST_IMPL::loader_job().

◆ push_back()

void FP_LIB_TABLE_GRID::push_back ( LIB_TABLE_ROW aRow)
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 228 of file panel_fp_lib_table.cpp.

228 { rows.push_back( aRow ); }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

◆ reindex()

void LIB_TABLE::reindex ( )
inlineprotectedinherited

Definition at line 490 of file lib_table_base.h.

491  {
492  nickIndex.clear();
493 
494  for( LIB_TABLE_ROWS_ITER it = rows.begin(); it != rows.end(); ++it )
495  nickIndex.insert( INDEX_VALUE( it->GetNickName(), it - rows.begin() ) );
496  }
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.

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

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

◆ RemoveRow()

bool LIB_TABLE::RemoveRow ( LIB_TABLE_ROW aRow)
inlineinherited

Removes a row from the table.

Parameters
aRowis the row to remove
Returns
true if the row was found (and removed)

Definition at line 418 of file lib_table_base.h.

419  {
420  for( auto iter = rows.begin(); iter != rows.end(); ++iter )
421  {
422  if( *iter == *aRow )
423  {
424  rows.erase( iter, iter + 1 );
425  return true;
426  }
427  }
428  return false;
429  }
LIB_TABLE_ROWS rows

References LIB_TABLE::rows.

Referenced by LIB_MANAGER::addLibrary().

◆ Save()

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

349 {
350  FILE_OUTPUTFORMATTER sf( aFileName );
351  Format( &sf, 0 );
352 }
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const =0
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492

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(), DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow(), and DIALOG_GLOBAL_FP_LIB_TABLE_CONFIG::TransferDataFromWindow().

◆ SetValue()

void LIB_TABLE_GRID::SetValue ( int  aRow,
int  aCol,
const wxString &  aValue 
)
inlineoverrideinherited

Definition at line 88 of file lib_table_grid.h.

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.

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

◆ SetValueAsBool()

void LIB_TABLE_GRID::SetValueAsBool ( int  aRow,
int  aCol,
bool  aValue 
)
inlineoverrideinherited

Definition at line 108 of file lib_table_grid.h.

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

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

◆ size()

size_t FP_LIB_TABLE_GRID::size ( ) const
inlineoverrideprotectedvirtual

Implements LIB_TABLE_GRID.

Definition at line 214 of file panel_fp_lib_table.cpp.

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

References LIB_TABLE::rows.

◆ Type()

KICAD_T FP_LIB_TABLE::Type ( )
inlineoverridevirtualinherited

Implements PROJECT::_ELEM.

Definition at line 108 of file fp_lib_table.h.

108 { return FP_LIB_TABLE_T; }

References FP_LIB_TABLE_T.

Referenced by PROJECT::PcbFootprintLibs().

Friends And Related Function Documentation

◆ FP_GRID_TRICKS

friend class FP_GRID_TRICKS
friend

Definition at line 209 of file panel_fp_lib_table.cpp.

◆ PANEL_FP_LIB_TABLE

friend class PANEL_FP_LIB_TABLE
friend

Definition at line 208 of file panel_fp_lib_table.cpp.

Member Data Documentation

◆ fallBack

LIB_TABLE* LIB_TABLE::fallBack
protectedinherited

◆ nickIndex

INDEX LIB_TABLE::nickIndex
protectedinherited

this particular key is the nickName within each row.

Definition at line 516 of file lib_table_base.h.

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

◆ rows


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