KiCad PCB EDA Suite
LIB_ID Class Reference

A logical library item identifier and consists of various portions much like a URI. More...

#include <lib_id.h>

Public Member Functions

 LIB_ID ()
 
 LIB_ID (const wxString &aLibraryName, const wxString &aItemName, const wxString &aRevision=wxEmptyString)
 This LIB_ID ctor is a special version which ignores the parsing due to symbol names allowing '/' as a valid character. More...
 
int Parse (const UTF8 &aId, bool aFix=false)
 Parse LIB_ID with the information from aId. More...
 
const UTF8GetLibNickname () const
 Return the logical library name portion of a LIB_ID. More...
 
int SetLibNickname (const UTF8 &aNickname)
 Override the logical library name portion of the LIB_ID to aNickname. More...
 
const UTF8GetLibItemName () const
 
const wxString GetUniStringLibItemName () const
 Get strings for display messages in dialogs. More...
 
int SetLibItemName (const UTF8 &aLibItemName, bool aTestForRev=true)
 Override the library item name portion of the LIB_ID to aLibItemName. More...
 
int SetRevision (const UTF8 &aRevision)
 
const UTF8GetRevision () const
 
UTF8 GetLibItemNameAndRev () const
 
UTF8 Format () const
 
wxString GetUniStringLibId () const
 
bool IsValid () const
 Check if this LID_ID is valid. More...
 
bool IsLegacy () const
 
void clear ()
 Clear the contents of the library nickname, library entry name, and revision strings. More...
 
bool empty () const
 
int compare (const LIB_ID &aLibId) const
 Compare the contents of LIB_ID objects by performing a std::string comparison of the library nickname, library entry name, and revision strings respectively. More...
 
bool operator< (const LIB_ID &aLibId) const
 
bool operator > (const LIB_ID &aLibId) const
 
bool operator== (const LIB_ID &aLibId) const
 
bool operator != (const LIB_ID &aLibId) const
 

Static Public Member Functions

static UTF8 Format (const UTF8 &aLibraryName, const UTF8 &aLibItemName, const UTF8 &aRevision="")
 
static int HasIllegalChars (const UTF8 &aLibItemName)
 Examine aLibItemName for invalid LIB_ID item name characters. More...
 
static UTF8 FixIllegalChars (const UTF8 &aLibItemName, bool aLib=false)
 Replace illegal LIB_ID item name characters with underscores '_'. More...
 
static unsigned FindIllegalLibraryNameChar (const UTF8 &aLibraryName)
 Looks for characters that are illegal in library nicknames. More...
 

Static Protected Member Functions

static bool isLegalChar (unsigned aUniChar)
 Tests whether a Unicode character is a legal LIB_ID item name character. More...
 
static bool isLegalLibraryNameChar (unsigned aUniChar)
 Tests whether a Unicode character is a legal LIB_ID library nickname character. More...
 

Protected Attributes

UTF8 m_libraryName
 The nickname of the library or empty. More...
 
UTF8 m_itemName
 The name of the entry in the logical library. More...
 
UTF8 m_revision
 The revision of the entry. More...
 

Detailed Description

A logical library item identifier and consists of various portions much like a URI.

It consists of of triad of the library nickname, the name of the item in the library, and an optional revision of the item. This is a generic library identifier that can be used for any type of library that contains multiple named items such as footprint or symbol libraries.

Example LIB_ID string: "smt:R_0805/rev0".

  • "smt" is the logical library name used to look up library information saved in the LIB_TABLE.
  • "R" is the name of the item within the library.
  • "rev0" is the revision, which is optional. If missing then its delimiter should also not be present. A revision must begin with "rev" and be followed by at least one or more decimal digits.
Author
Dick Hollenbeck

Definition at line 51 of file lib_id.h.

Constructor & Destructor Documentation

◆ LIB_ID() [1/2]

LIB_ID::LIB_ID ( )
inline

Definition at line 54 of file lib_id.h.

54 {}

◆ LIB_ID() [2/2]

LIB_ID::LIB_ID ( const wxString &  aLibraryName,
const wxString &  aItemName,
const wxString &  aRevision = wxEmptyString 
)

This LIB_ID ctor is a special version which ignores the parsing due to symbol names allowing '/' as a valid character.

This was causing the symbol names to be truncated at the first occurrence of '/' in the symbol name.

Parameters
aLibraryNameis the library name used to look up the library item in the LIB_TABLE.
aItemNameis the name of the library item which is not parsed by the standard LIB_ID::Parse() function.
aRevisionis the revision of the library item.

Definition at line 184 of file lib_id.cpp.

185  :
186  m_libraryName( aLibraryName ),
187  m_itemName( aItemName ),
188  m_revision( aRevision )
189 {
190 }
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268

Member Function Documentation

◆ clear()

void LIB_ID::clear ( )

Clear the contents of the library nickname, library entry name, and revision strings.

Definition at line 114 of file lib_id.cpp.

115 {
117  m_itemName.clear();
118  m_revision.clear();
119 }
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268
void clear()
Definition: utf8.h:108

References UTF8::clear(), m_itemName, m_libraryName, and m_revision.

Referenced by Parse().

◆ compare()

int LIB_ID::compare ( const LIB_ID aLibId) const

Compare the contents of LIB_ID objects by performing a std::string comparison of the library nickname, library entry name, and revision strings respectively.

Parameters
aLibIdis the LIB_ID to compare against.
Returns
-1 if less than aLibId, 1 if greater than aLibId, and 0 if equal to aLibId.

Definition at line 311 of file lib_id.cpp.

312 {
313  // Don't bother comparing the same object.
314  if( this == &aLibId )
315  return 0;
316 
317  int retv = m_libraryName.compare( aLibId.m_libraryName );
318 
319  if( retv != 0 )
320  return retv;
321 
322  retv = m_itemName.compare( aLibId.m_itemName );
323 
324  if( retv != 0 )
325  return retv;
326 
327  return m_revision.compare( aLibId.m_revision );
328 }
int compare(const std::string &s) const
Definition: utf8.h:111
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268

References UTF8::compare(), m_itemName, m_libraryName, and m_revision.

Referenced by LIB_PART::Compare(), operator >(), operator<(), and operator==().

◆ empty()

bool LIB_ID::empty ( ) const
inline
Returns
a boolean true value if the LIB_ID is empty. Otherwise return false.

Definition at line 189 of file lib_id.h.

190  {
191  return m_libraryName.empty() && m_itemName.empty() && m_revision.empty();
192  }
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268
bool empty() const
Definition: utf8.h:103

References UTF8::empty(), m_itemName, m_libraryName, and m_revision.

Referenced by BOARD_NETLIST_UPDATER::addNewComponent(), CVPCB_ASSOCIATION_TOOL::Associate(), CVPCB_MAINFRAME::AssociateFootprint(), CVPCB_MAINFRAME::AutomaticFootprintMatching(), CVPCB_MAINFRAME::GetComponentIndices(), CMP_READER::Load(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), BOARD_NETLIST_UPDATER::replaceComponent(), and DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser().

◆ FindIllegalLibraryNameChar()

unsigned LIB_ID::FindIllegalLibraryNameChar ( const UTF8 aLibraryName)
static

Looks for characters that are illegal in library nicknames.

Parameters
aLibraryNameis the logical library name to be tested.
Returns
Invalid character found in the name or 0 is the name is valid.

Definition at line 398 of file lib_id.cpp.

399 {
400  for( unsigned ch : aLibraryName )
401  {
402  if( !isLegalLibraryNameChar( ch ) )
403  return ch;
404  }
405 
406  return 0;
407 }
static bool isLegalLibraryNameChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID library nickname character.
Definition: lib_id.cpp:410

References isLegalLibraryNameChar().

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

◆ FixIllegalChars()

UTF8 LIB_ID::FixIllegalChars ( const UTF8 aLibItemName,
bool  aLib = false 
)
static

Replace illegal LIB_ID item name characters with underscores '_'.

Parameters
aLibItemNameis the LIB_ID item name to replace illegal characters.
aLibTrue if we are checking library names, false if we are checking item names
Returns
the corrected version of aLibItemName.

Definition at line 347 of file lib_id.cpp.

348 {
349  UTF8 fixedName;
350 
351  for( UTF8::uni_iter chIt = aLibItemName.ubegin(); chIt < aLibItemName.uend(); ++chIt )
352  {
353  auto ch = *chIt;
354  if( aLib )
355  fixedName += isLegalLibraryNameChar( ch ) ? ch : '_';
356  else
357  fixedName += isLegalChar( ch ) ? ch : '_';
358  }
359 
360  return fixedName;
361 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:287
static bool isLegalLibraryNameChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID library nickname character.
Definition: lib_id.cpp:410
static bool isLegalChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID item name character.
Definition: lib_id.cpp:364
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:279
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:203

References isLegalChar(), isLegalLibraryNameChar(), UTF8::ubegin(), and UTF8::uend().

Referenced by PANEL_SYM_LIB_TABLE::browseLibrariesHandler(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties(), find_component(), RESCUE_CASE_CANDIDATE::FindRescues(), RESCUE_CACHE_CANDIDATE::FindRescues(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SCH_EAGLE_PLUGIN::fixSymbolName(), SCH_ALTIUM_PLUGIN::getLibName(), SCH_EAGLE_PLUGIN::getLibName(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), SCH_LEGACY_PLUGIN_CACHE::loadDocs(), CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances(), Parse(), and LIB_PART::SetName().

◆ Format() [1/2]

UTF8 LIB_ID::Format ( ) const
Returns
the fully formatted text of the LIB_ID in a UTF8 string.

Definition at line 233 of file lib_id.cpp.

234 {
235  UTF8 ret;
236 
237  if( m_libraryName.size() )
238  {
239  ret += m_libraryName;
240  ret += ':';
241  }
242 
243  ret += m_itemName;
244 
245  if( m_revision.size() )
246  {
247  ret += '/';
248  ret += m_revision;
249  }
250 
251  return ret;
252 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268
std::string::size_type size() const
Definition: utf8.h:110

References m_itemName, m_libraryName, m_revision, and UTF8::size().

Referenced by SCH_SCREEN::AddLibSymbol(), BOARD_NETLIST_UPDATER::addNewComponent(), SCH_SCREEN::Append(), CVPCB_ASSOCIATION_TOOL::Associate(), CVPCB_MAINFRAME::AssociateFootprint(), CVPCB_MAINFRAME::BuildCmpListBox(), CMP_CANDIDATE::CMP_CANDIDATE(), CreateDevicesSection(), DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS(), DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS(), PART_LIB::FindPart(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SCH_SEXPR_PLUGIN::Format(), COMPONENT::Format(), PCB_IO::format(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), FOOTPRINT::GetMsgPanelInfo(), SCH_COMPONENT::GetSchSymbolLibraryName(), GetUniStringLibId(), SCH_EDIT_FRAME::importFile(), PCB_EDIT_FRAME::LoadFootprints(), DSN::SPECCTRA_DB::makeIMAGE(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction(), DIALOG_EXCHANGE_FOOTPRINTS::processFootprint(), DIALOG_CHANGE_SYMBOLS::processSymbol(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), CVPCB_MAINFRAME::refreshAfterComponentSearch(), BOARD_NETLIST_UPDATER::replaceComponent(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), SCH_LEGACY_PLUGIN::saveComponent(), SCH_SEXPR_PLUGIN::saveSymbol(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser(), FOOTPRINTS_LISTBOX::SetSelectedFootprint(), BOARD_NETLIST_UPDATER::testConnectivity(), DIALOG_SYMBOL_PROPERTIES::TransferDataToWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow(), BOARD_NETLIST_UPDATER::UpdateNetlist(), FOOTPRINT_EDIT_FRAME::updateTitle(), SYMBOL_EDIT_FRAME::updateTitle(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

◆ Format() [2/2]

UTF8 LIB_ID::Format ( const UTF8 aLibraryName,
const UTF8 aLibItemName,
const UTF8 aRevision = "" 
)
static
Returns
a string in the proper format as an LIB_ID for a combination of aLibraryName, aLibItemName, and aRevision.
Exceptions
PARSE_ERRORif any of the pieces are illegal.

Definition at line 269 of file lib_id.cpp.

270 {
271  UTF8 ret;
272  int offset;
273 
274  if( aLibraryName.size() )
275  {
276  offset = okLogical( aLibraryName );
277 
278  if( offset != -1 )
279  {
280  THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ),
281  wxString::FromUTF8( aLibraryName.c_str() ), aLibraryName.c_str(), 0, offset );
282  }
283 
284  ret += aLibraryName;
285  ret += ':';
286  }
287 
288  ret += aLibItemName; // TODO: Add validity test.
289 
290  if( aRevision.size() )
291  {
292  offset = okRevision( aRevision );
293 
294  if( offset != -1 )
295  {
296  THROW_PARSE_ERROR( _( "Illegal character found in revision" ),
297  wxString::FromUTF8( aRevision.c_str() ),
298  aRevision.c_str(),
299  0,
300  offset );
301  }
302 
303  ret += '/';
304  ret += aRevision;
305  }
306 
307  return ret;
308 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
static int okLogical(const UTF8 &aField)
Definition: lib_id.cpp:86
const char * c_str() const
Definition: utf8.h:102
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
#define _(s)
Definition: 3d_actions.cpp:33
std::string::size_type size() const
Definition: utf8.h:110
static int okRevision(const UTF8 &aField)
Definition: lib_id.cpp:94

References _, UTF8::c_str(), okLogical(), okRevision(), UTF8::size(), and THROW_PARSE_ERROR.

◆ GetLibItemName()

const UTF8& LIB_ID::GetLibItemName ( ) const
inline
Returns
the library item name, i.e. footprintName, in UTF8.

Definition at line 106 of file lib_id.h.

106 { return m_itemName; }
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268

References m_itemName.

Referenced by FOOTPRINT_EDIT_FRAME::AddFootprintToBoard(), BASIC_FOOTPRINT_INFO::BASIC_FOOTPRINT_INFO(), FOOTPRINT_EDIT_FRAME::canCloseWindow(), FOOTPRINT_EDIT_FRAME::ClearModify(), SCH_REFERENCE::CompareLibName(), SYMBOL_EDIT_FRAME::CopyPartToClipboard(), FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), SYMBOL_EDIT_FRAME::DeletePartFromLibrary(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), SYMBOL_EDIT_FRAME::DuplicatePart(), SYMBOL_EDITOR_CONTROL::EditSymbol(), PCB_EDIT_FRAME::ExchangeFootprint(), FOOTPRINT_EDIT_FRAME::ExportFootprint(), LIB_TREE_MODEL_ADAPTER::FindItem(), PART_LIBS::FindLibPart(), RESCUE_CASE_CANDIDATE::FindRescues(), RESCUE_CACHE_CANDIDATE::FindRescues(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), PCB_IO::FootprintSave(), FP_LIB_TABLE::FootprintSave(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), PLACE_FILE_EXPORTER::GenPositionData(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), DISPLAY_FOOTPRINTS_FRAME::GetFootprint(), FOOTPRINT_LIST::GetFootprintInfo(), SYMBOL_EDIT_FRAME::getTargetPart(), FP_TREE_SYNCHRONIZING_ADAPTER::GetValue(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), guessNickname(), PCB_EDIT_FRAME::importFile(), SYMBOL_EDITOR_CONTROL::Init(), FOOTPRINT_EDITOR_CONTROL::Init(), SYMBOL_EDIT_FRAME::isCurrentPart(), LEGACY_PLUGIN::loadFOOTPRINT(), PCB_EDIT_FRAME::LoadFootprints(), LEGACY_PLUGIN::loadFP_SHAPE(), LEGACY_PLUGIN::loadPAD(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_EDIT_FRAME::LoadSymbolAndSelectLib(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), NETLIST_EXPORTER_XML::makeSymbols(), DIALOG_EDIT_COMPONENTS_LIBID::onClickOrphansButton(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction(), SCH_BASE_FRAME::PickSymbolFromLibBrowser(), DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), CVPCB_MAINFRAME::ReadSchematicNetlist(), PCB_EDIT_FRAME::RecreateBOMFileFromBoard(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), SYMBOL_EDIT_FRAME::Revert(), FOOTPRINT_EDITOR_CONTROL::SaveAs(), SYMBOL_EDIT_FRAME::saveCurrentPart(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), SYMBOL_EDIT_FRAME::savePartAs(), SYMBOL_LIB_TABLE::SaveSymbol(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), SchGetLibPart(), setLibNickname(), LIB_TREE::setState(), FOOTPRINT_EDIT_FRAME::setupUIConditions(), DIALOG_CHOOSE_SYMBOL::ShowFootprintFor(), SYMBOL_VIEWER_FRAME::ShowModal(), FOOTPRINT_VIEWER_FRAME::ShowModal(), ERC_TESTER::TestLibSymbolIssues(), DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow(), SCH_COMPONENT::UpdateFields(), PCB_CONTROL::UpdateMessagePanel(), SYMBOL_LIBRARY_MANAGER::UpdatePart(), and FOOTPRINT_EDIT_FRAME::updateTitle().

◆ GetLibItemNameAndRev()

UTF8 LIB_ID::GetLibItemNameAndRev ( ) const

Definition at line 255 of file lib_id.cpp.

256 {
257  UTF8 ret = m_itemName;
258 
259  if( m_revision.size() )
260  {
261  ret += '/';
262  ret += m_revision;
263  }
264 
265  return ret;
266 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268
std::string::size_type size() const
Definition: utf8.h:110

References m_itemName, m_revision, and UTF8::size().

Referenced by PCB_IO::format().

◆ GetLibNickname()

const UTF8& LIB_ID::GetLibNickname ( ) const
inline

Return the logical library name portion of a LIB_ID.

Definition at line 92 of file lib_id.h.

92 { return m_libraryName; }
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267

References m_libraryName.

Referenced by BASIC_FOOTPRINT_INFO::BASIC_FOOTPRINT_INFO(), SYMBOL_EDIT_FRAME::CopyPartToClipboard(), FOOTPRINT_EDITOR_CONTROL::CreateFootprint(), FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), SYMBOL_EDIT_FRAME::DeletePartFromLibrary(), CVPCB_MAINFRAME::DisplayStatus(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), LIB_TREE_MODEL_ADAPTER::DoAddLibraryNode(), SYMBOL_EDIT_FRAME::DuplicatePart(), SYMBOL_EDITOR_CONTROL::EditSymbol(), LIB_TREE_MODEL_ADAPTER::FindItem(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), DISPLAY_FOOTPRINTS_FRAME::GetFootprint(), FOOTPRINT_LIST::GetFootprintInfo(), SCH_SCREENS::GetLibNicknames(), LIB_PART::GetLibraryName(), FOOTPRINT_EDIT_FRAME::GetLoadedFPID(), SCH_COMPONENT::GetMsgPanelInfo(), SYMBOL_EDIT_FRAME::getTargetLib(), SYMBOL_EDIT_FRAME::getTargetPart(), guessNickname(), SCH_SCREENS::HasNoFullyDefinedLibIds(), SYMBOL_EDITOR_CONTROL::Init(), FOOTPRINT_EDITOR_CONTROL::Init(), SYMBOL_EDIT_FRAME::isCurrentPart(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_EDIT_FRAME::LoadSymbolAndSelectLib(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), FOOTPRINT_EDITOR_CONTROL::NewFootprint(), FOOTPRINT_EDITOR_CONTROL::PasteFootprint(), SCH_BASE_FRAME::PickSymbolFromLibBrowser(), DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), SYMBOL_EDIT_FRAME::Revert(), SYMBOL_EDIT_FRAME::Save(), FOOTPRINT_EDITOR_CONTROL::SaveAs(), SYMBOL_EDIT_FRAME::saveCurrentPart(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), SYMBOL_EDIT_FRAME::SaveLibraryAs(), SYMBOL_EDIT_FRAME::savePartAs(), SchGetLibPart(), setLibNickname(), LIB_TREE::setState(), SYMBOL_EDIT_FRAME::setupUIConditions(), DIALOG_CHOOSE_SYMBOL::ShowFootprintFor(), SYMBOL_VIEWER_FRAME::ShowModal(), FOOTPRINT_VIEWER_FRAME::ShowModal(), ERC_TESTER::TestLibSymbolIssues(), LIB_TREE_NODE_LIB_ID::Update(), PCB_CONTROL::UpdateMessagePanel(), and FOOTPRINT_EDIT_FRAME::updateTitle().

◆ GetRevision()

const UTF8& LIB_ID::GetRevision ( ) const
inline

Definition at line 129 of file lib_id.h.

129 { return m_revision; }
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269

References m_revision.

◆ GetUniStringLibId()

wxString LIB_ID::GetUniStringLibId ( ) const
inline
Returns
the fully formatted text of the LIB_ID in a wxString (UTF16 or UTF32), suitable to display the LIB_ID in dialogs.

Definition at line 142 of file lib_id.h.

143  {
144  return Format().wx_str();
145  }
UTF8 Format() const
Definition: lib_id.cpp:233
wxString wx_str() const
Definition: utf8.cpp:51

References Format(), and UTF8::wx_str().

Referenced by CVPCB_ASSOCIATION_TOOL::CopyAssoc(), CVPCB_ASSOCIATION_TOOL::CutAssoc(), CMP_CANDIDATE::GetStringLibId(), DISPLAY_FOOTPRINTS_FRAME::InitDisplay(), and ERC_TESTER::TestLibSymbolIssues().

◆ GetUniStringLibItemName()

const wxString LIB_ID::GetUniStringLibItemName ( ) const
inline

Get strings for display messages in dialogs.

Equivalent to m_itemName.wx_str(), but more explicit when building a Unicode string in messages.

Returns
the library item name, i.e. footprintName in a wxString (UTF16 or 32).

Definition at line 116 of file lib_id.h.

116 { return m_itemName.wx_str(); }
wxString wx_str() const
Definition: utf8.cpp:51
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268

References m_itemName, and UTF8::wx_str().

Referenced by SYMBOL_EDIT_FRAME::DeletePartFromLibrary().

◆ HasIllegalChars()

int LIB_ID::HasIllegalChars ( const UTF8 aLibItemName)
static

Examine aLibItemName for invalid LIB_ID item name characters.

Parameters
aLibItemNameis the LIB_ID name to test for illegal characters.
Returns
offset of first illegal character otherwise -1.

Definition at line 331 of file lib_id.cpp.

332 {
333  int offset = 0;
334 
335  for( auto ch : aLibItemName )
336  {
337  if( !isLegalChar( ch ) )
338  return offset;
339  else
340  ++offset;
341  }
342 
343  return -1;
344 }
static bool isLegalChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID item name character.
Definition: lib_id.cpp:364

References isLegalChar().

Referenced by RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), and Parse().

◆ IsLegacy()

bool LIB_ID::IsLegacy ( ) const
inline
Returns
true if the LIB_ID only has the m_itemName name defined.

Definition at line 176 of file lib_id.h.

177  {
178  return m_libraryName.empty() && !m_itemName.empty() && m_revision.empty();
179  }
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268
bool empty() const
Definition: utf8.h:103

References UTF8::empty(), m_itemName, m_libraryName, and m_revision.

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

◆ isLegalChar()

bool LIB_ID::isLegalChar ( unsigned  aUniChar)
staticprotected

Tests whether a Unicode character is a legal LIB_ID item name character.

The criteria for legal LIB_ID character is as follows:

  • For both symbol and footprint names, neither '/' or ':' are legal. They are reserved characters used by LIB_ID::Parse.
  • Spaces are allowed in footprint names as they are a legal filename character on all operating systems.
  • Spaces are not allowed in symbol names since symbol names are not quoted in the schematic or symbol library file formats.
  • Spaces are allowed in footprint library nicknames as they are quoted in the footprint library table file format.
  • Spaces are now also allowed in symbol library nicknames since they are quoted in the new symbol library sexpr file format.
  • Illegal file name characters are not allowed in footprint names since the file name is the footprint name.
  • Illegal file name characters except '/' are allowed in symbol names since the name is not the file name.
Note
aUniChar is expected to be a 32 bit Unicode character, not a UTF8 char, that use a variable length coding value.

Definition at line 364 of file lib_id.cpp.

365 {
366  bool const space_allowed = true;
367  bool const illegal_filename_chars_allowed = false;
368 
369  if( aUniChar < ' ' )
370  return false;
371 
372  // This list of characters is also duplicated in validators.cpp and footprint.cpp
373  // TODO: Unify forbidden character lists
374  switch( aUniChar )
375  {
376  case ':':
377  case '/':
378  case '\t':
379  case '\n':
380  case '\r':
381  return false;
382 
383  case '\\':
384  case '<':
385  case '>':
386  case '"':
387  return illegal_filename_chars_allowed;
388 
389  case ' ':
390  return space_allowed;
391 
392  default:
393  return true;
394  }
395 }

Referenced by FixIllegalChars(), and HasIllegalChars().

◆ isLegalLibraryNameChar()

bool LIB_ID::isLegalLibraryNameChar ( unsigned  aUniChar)
staticprotected

Tests whether a Unicode character is a legal LIB_ID library nickname character.

Note
aUniChar is expected to be a 32 bit Unicode character, not a UTF8 char, that use a variable length coding value.

Definition at line 410 of file lib_id.cpp.

411 {
412  bool const space_allowed = true;
413 
414  if( aUniChar < ' ' )
415  return false;
416 
417  switch( aUniChar )
418  {
419  case '\\':
420  case ':':
421  return false;
422 
423  case ' ':
424  return space_allowed;
425 
426  default:
427  return true;
428  }
429 }

Referenced by FindIllegalLibraryNameChar(), and FixIllegalChars().

◆ IsValid()

bool LIB_ID::IsValid ( ) const
inline

Check if this LID_ID is valid.

A valid LIB_ID must have both the library nickname and the library item name defined. The revision field is optional.

Note
A return value of true does not indicated that the LIB_ID is a valid LIB_TABLE entry.
Returns
true is the LIB_ID is valid.

Definition at line 168 of file lib_id.h.

169  {
170  return !m_libraryName.empty() && !m_itemName.empty();
171  }
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268
bool empty() const
Definition: utf8.h:103

References UTF8::empty(), m_itemName, and m_libraryName.

Referenced by SYMBOL_EDITOR_CONTROL::AddSymbolToSchematic(), CVPCB_ASSOCIATION_TOOL::Associate(), CVPCB_MAINFRAME::AssociateFootprint(), CVPCB_ASSOCIATION_TOOL::CopyAssoc(), CVPCB_ASSOCIATION_TOOL::CutAssoc(), FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), FOOTPRINT_EDITOR_CONTROL::ExportFootprint(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), SYMBOL_EDIT_FRAME::getTargetPart(), DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected(), DIALOG_CHOOSE_SYMBOL::OnComponentSelected(), CVPCB_MAINFRAME::OnSelectComponent(), SCH_BASE_FRAME::PickSymbolFromLibBrowser(), SCH_BASE_FRAME::PickSymbolFromLibTree(), SCH_DRAWING_TOOLS::PlaceComponent(), DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector(), DIALOG_EXCHANGE_FOOTPRINTS::processMatchingFootprints(), DIALOG_CHANGE_SYMBOLS::processMatchingSymbols(), DIALOG_CHANGE_SYMBOLS::processSymbol(), SYMBOL_EDIT_FRAME::RegenerateLibraryTree(), FOOTPRINT_EDIT_FRAME::RegenerateLibraryTree(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser(), DIALOG_CHOOSE_SYMBOL::ShowFootprint(), SYMBOL_VIEWER_FRAME::ShowModal(), FOOTPRINT_VIEWER_FRAME::ShowModal(), LIB_TREE_MODEL_ADAPTER::ShowPreselect(), SYMBOL_EDIT_FRAME::SyncLibraries(), DIALOG_CHANGE_SYMBOLS::updateFieldsList(), and FOOTPRINT_EDIT_FRAME::updateTitle().

◆ operator !=()

bool LIB_ID::operator != ( const LIB_ID aLibId) const
inline

Definition at line 206 of file lib_id.h.

206 { return !(*this == aLibId); }

◆ operator >()

bool LIB_ID::operator > ( const LIB_ID aLibId) const
inline

Definition at line 204 of file lib_id.h.

204 { return this->compare( aLibId ) > 0; }
int compare(const LIB_ID &aLibId) const
Compare the contents of LIB_ID objects by performing a std::string comparison of the library nickname...
Definition: lib_id.cpp:311

References compare().

◆ operator<()

bool LIB_ID::operator< ( const LIB_ID aLibId) const
inline

Definition at line 203 of file lib_id.h.

203 { return this->compare( aLibId ) < 0; }
int compare(const LIB_ID &aLibId) const
Compare the contents of LIB_ID objects by performing a std::string comparison of the library nickname...
Definition: lib_id.cpp:311

References compare().

◆ operator==()

bool LIB_ID::operator== ( const LIB_ID aLibId) const
inline

Definition at line 205 of file lib_id.h.

205 { return this->compare( aLibId ) == 0; }
int compare(const LIB_ID &aLibId) const
Compare the contents of LIB_ID objects by performing a std::string comparison of the library nickname...
Definition: lib_id.cpp:311

References compare().

◆ Parse()

int LIB_ID::Parse ( const UTF8 aId,
bool  aFix = false 
)

Parse LIB_ID with the information from aId.

A typical LIB_ID string consists of a library nickname followed by a library item name. e.g.: "smt:R_0805", or e.g.: "mylib:R_0805", or e.g.: "ttl:7400"

Parameters
aIdis the string to populate the LIB_ID object.
aFixindicates invalid chars should be replaced with '_'.
Returns
minus 1 (i.e. -1) means success, >= 0 indicates the character offset into aId at which an error was detected.

Definition at line 122 of file lib_id.cpp.

123 {
124  clear();
125 
126  const char* buffer = aId.c_str();
127  const char* rev = EndsWithRev( buffer, buffer+aId.length(), '/' );
128  size_t revNdx;
129  size_t partNdx;
130  int offset = -1;
131 
132  //=====<revision>=====================================
133  // in a LIB_ID like discret:R3/rev4
134  if( rev )
135  {
136  revNdx = rev - buffer;
137 
138  // no need to check revision, EndsWithRev did that.
139  m_revision = aId.substr( revNdx );
140  --revNdx; // back up to omit the '/' which precedes the rev
141  }
142  else
143  {
144  revNdx = aId.size();
145  }
146 
147  //=====<name>=========================================
148  if( ( partNdx = aId.find( ':' ) ) != aId.npos )
149  {
150  offset = SetLibNickname( aId.substr( 0, partNdx ) );
151 
152  if( offset > -1 )
153  return offset;
154 
155  ++partNdx; // skip ':'
156  }
157  else
158  {
159  partNdx = 0;
160  }
161 
162  //=====<item name>====================================
163  if( partNdx >= revNdx )
164  return partNdx; // Error: no library item name.
165 
166  UTF8 fpname = aId.substr( partNdx, revNdx-partNdx );
167 
168  // Be sure the item name is valid.
169  // Some chars can be found in legacy files converted files from other EDA tools.
170  if( aFix )
171  fpname = FixIllegalChars( fpname, false );
172  else
173  offset = HasIllegalChars( fpname );
174 
175  if( offset > -1 )
176  return offset;
177 
178  SetLibItemName( fpname );
179 
180  return -1;
181 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
static constexpr std::string::size_type npos
Definition: utf8.h:151
const char * EndsWithRev(const char *start, const char *tail, char separator)
Definition: lib_id.cpp:41
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:347
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
const char * c_str() const
Definition: utf8.h:102
std::string::size_type find(char c) const
Definition: utf8.h:105
std::string::size_type length() const
Definition: utf8.h:109
void clear()
Clear the contents of the library nickname, library entry name, and revision strings.
Definition: lib_id.cpp:114
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:204
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
static int HasIllegalChars(const UTF8 &aLibItemName)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:331
std::string substr(size_t pos=0, size_t len=npos) const
Definition: utf8.h:178
std::string::size_type size() const
Definition: utf8.h:110

References UTF8::c_str(), clear(), EndsWithRev(), UTF8::find(), FixIllegalChars(), HasIllegalChars(), UTF8::length(), m_revision, UTF8::npos, SetLibItemName(), SetLibNickname(), UTF8::size(), and UTF8::substr().

Referenced by PCAD2KICAD::PCB_FOOTPRINT::AddToBoard(), AltiumToKiCadLibID(), CVPCB_ASSOCIATION_TOOL::Associate(), CVPCB_ASSOCIATION_TOOL::CopyAssoc(), CVPCB_ASSOCIATION::CVPCB_ASSOCIATION(), DISPLAY_FOOTPRINTS_FRAME::GetFootprint(), FOOTPRINT_LIST::GetFootprintInfo(), SCH_EDIT_FRAME::importFile(), DIALOG_EXCHANGE_FOOTPRINTS::isMatch(), CMP_READER::Load(), LEGACY_PLUGIN::loadAllSections(), SCH_LEGACY_PLUGIN::loadComponent(), CADSTAR_PCB_ARCHIVE_LOADER::loadComponentLibrary(), FABMASTER::loadFootprints(), EAGLE_PLUGIN::makeFootprint(), DIALOG_EDIT_COMPONENTS_LIBID::onClickOrphansButton(), KICAD_NETLIST_PARSER::parseComponent(), PCB_PARSER::parseFOOTPRINT_unchecked(), SCH_SEXPR_PARSER::parseSchematicSymbol(), CVPCB_ASSOCIATION_TOOL::PasteAssoc(), DIALOG_EXCHANGE_FOOTPRINTS::processMatchingFootprints(), DIALOG_CHANGE_SYMBOLS::processMatchingSymbols(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser(), DIALOG_CHOOSE_SYMBOL::ShowFootprint(), SYMBOL_VIEWER_FRAME::ShowModal(), FOOTPRINT_VIEWER_FRAME::ShowModal(), DIALOG_EDIT_COMPONENTS_LIBID::TransferDataFromWindow(), DIALOG_CHANGE_SYMBOLS::updateFieldsList(), and DIALOG_EDIT_COMPONENTS_LIBID::validateLibIds().

◆ SetLibItemName()

int LIB_ID::SetLibItemName ( const UTF8 aLibItemName,
bool  aTestForRev = true 
)

Override the library item name portion of the LIB_ID to aLibItemName.

Returns
int - minus 1 (i.e. -1) means success, >= 0 indicates the character offset into the parameter at which an error was detected, usually because it contained '/'.

Definition at line 204 of file lib_id.cpp.

205 {
206  int separation = int( aLibItemName.find_first_of( "/" ) );
207 
208  if( aTestForRev && separation != -1 )
209  {
210  m_itemName = aLibItemName.substr( 0, separation-1 );
211  return separation;
212  }
213  else
214  {
215  m_itemName = aLibItemName;
216  }
217 
218  return -1;
219 }
std::string::size_type find_first_of(const std::string &str, std::string::size_type pos=0) const
Definition: utf8.h:117
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:268
std::string substr(size_t pos=0, size_t len=npos) const
Definition: utf8.h:178

References UTF8::find_first_of(), m_itemName, and UTF8::substr().

Referenced by BOOST_AUTO_TEST_CASE(), LIB_TREE_NODE_LIB_ID::LIB_TREE_NODE_LIB_ID(), SCH_LEGACY_PLUGIN::loadComponent(), LEGACY_NETLIST_READER::loadComponent(), Parse(), RESCUE_CASE_CANDIDATE::PerformAction(), RESCUE_CACHE_CANDIDATE::PerformAction(), LIB_PART::SetName(), SYMBOL_EDIT_FRAME::SyncLibraries(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataFromWindow(), and RESCUER::UndoRescues().

◆ SetLibNickname()

int LIB_ID::SetLibNickname ( const UTF8 aNickname)

Override the logical library name portion of the LIB_ID to aNickname.

Returns
int - minus 1 (i.e. -1) means success, >= 0 indicates the character offset into the parameter at which an error was detected, usually because it contained '/' or ':'.

Definition at line 193 of file lib_id.cpp.

194 {
195  int offset = okLogical( aLogical );
196 
197  if( offset == -1 )
198  m_libraryName = aLogical;
199 
200  return offset;
201 }
static int okLogical(const UTF8 &aField)
Definition: lib_id.cpp:86
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:267

References m_libraryName, and okLogical().

Referenced by SCH_SCREENS::ChangeSymbolLibNickname(), FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList(), SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::CreateBuffer(), FOOTPRINT_EDITOR_CONTROL::CreateFootprint(), FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), guessNickname(), PCB_EDIT_FRAME::importFile(), SCH_EDIT_FRAME::importFile(), LIB_TREE_NODE_LIB::LIB_TREE_NODE_LIB(), LIB_TREE_NODE_LIB_ID::LIB_TREE_NODE_LIB_ID(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_LIB_TABLE::LoadSymbolLib(), FOOTPRINT_EDITOR_CONTROL::NewFootprint(), Parse(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), FOOTPRINT_EDIT_FRAME::restoreLastFootprint(), setLibNickname(), and LIB_TREE_NODE_LIB_ID::Update().

◆ SetRevision()

int LIB_ID::SetRevision ( const UTF8 aRevision)

Definition at line 222 of file lib_id.cpp.

223 {
224  int offset = okRevision( aRevision );
225 
226  if( offset == -1 )
227  m_revision = aRevision;
228 
229  return offset;
230 }
UTF8 m_revision
The revision of the entry.
Definition: lib_id.h:269
static int okRevision(const UTF8 &aField)
Definition: lib_id.cpp:94

References m_revision, and okRevision().

Member Data Documentation

◆ m_itemName

UTF8 LIB_ID::m_itemName
protected

The name of the entry in the logical library.

Definition at line 268 of file lib_id.h.

Referenced by clear(), compare(), empty(), Format(), GetLibItemName(), GetLibItemNameAndRev(), GetUniStringLibItemName(), IsLegacy(), IsValid(), and SetLibItemName().

◆ m_libraryName

UTF8 LIB_ID::m_libraryName
protected

The nickname of the library or empty.

Definition at line 267 of file lib_id.h.

Referenced by clear(), compare(), empty(), Format(), GetLibNickname(), IsLegacy(), IsValid(), and SetLibNickname().

◆ m_revision

UTF8 LIB_ID::m_revision
protected

The revision of the entry.

Definition at line 269 of file lib_id.h.

Referenced by clear(), compare(), empty(), Format(), GetLibItemNameAndRev(), GetRevision(), IsLegacy(), Parse(), and SetRevision().


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