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 Types

enum  LIB_ID_TYPE { ID_SCH, ID_PCB }
 

Types of library identifiers

More...
 

Public Member Functions

 LIB_ID ()
 
 LIB_ID (const wxString &aLibName, const wxString &aLibItemName, 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, LIB_ID_TYPE aType, 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
 
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
 
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 &aLibNickname, const UTF8 &aLibItemName, const UTF8 &aRevision="")
 
static int HasIllegalChars (const UTF8 &aLibItemName, LIB_ID_TYPE aType)
 Examine aLibItemName for invalid LIB_ID item name characters. More...
 
static UTF8 FixIllegalChars (const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
 Replace illegal LIB_ID item name characters with underscores '_'. More...
 
static unsigned FindIllegalLibNicknameChar (const UTF8 &aNickname, LIB_ID_TYPE aType)
 Looks for characters that are illegal in library nicknames. More...
 

Static Protected Member Functions

static bool isLegalChar (unsigned aUniChar, LIB_ID_TYPE aType)
 Tests whether a unicode character is a legal LIB_ID item name character. More...
 
static bool isLegalLibNicknameChar (unsigned aUniChar, LIB_ID_TYPE aType)
 Tests whether a unicode character is a legal LIB_ID library nickname character. More...
 

Protected Attributes

UTF8 nickname
 The nickname of the library or empty. More...
 
UTF8 item_name
 The name of the entry in the logical library. More...
 
UTF8 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.

Member Enumeration Documentation

Types of library identifiers

Enumerator
ID_SCH 
ID_PCB 

Definition at line 56 of file lib_id.h.

Constructor & Destructor Documentation

LIB_ID::LIB_ID ( )
inline

Definition at line 58 of file lib_id.h.

References Parse().

58 {}
LIB_ID::LIB_ID ( const wxString &  aLibName,
const wxString &  aLibItemName,
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
aLibNameis the library nickname used to look up the library item in the LIB_TABLE.
aLibItemNameis 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  nickname( aLibName ),
187  item_name( aLibItemName ),
188  revision( aRevision )
189 {
190 }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:269

Member Function Documentation

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.

References UTF8::clear(), item_name, nickname, and revision.

Referenced by IsLegacy(), and Parse().

115 {
116  nickname.clear();
117  item_name.clear();
118  revision.clear();
119 }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:269
void clear()
Definition: utf8.h:113
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 316 of file lib_id.cpp.

References UTF8::compare(), item_name, nickname, and revision.

Referenced by empty(), operator<(), operator==(), and operator>().

317 {
318  // Don't bother comparing the same object.
319  if( this == &aLibId )
320  return 0;
321 
322  int retv = nickname.compare( aLibId.nickname );
323 
324  if( retv != 0 )
325  return retv;
326 
327  retv = item_name.compare( aLibId.item_name );
328 
329  if( retv != 0 )
330  return retv;
331 
332  return revision.compare( aLibId.revision );
333 }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
int compare(const std::string &s) const
Definition: utf8.h:116
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:269
bool LIB_ID::empty ( ) const
inline
Returns
a boolean true value if the LIB_ID is empty. Otherwise return false.

Definition at line 186 of file lib_id.h.

References compare(), UTF8::empty(), item_name, nickname, and revision.

Referenced by BOARD_NETLIST_UPDATER::addNewComponent(), CVPCB_MAINFRAME::AutomaticFootprintMatching(), CMP_READER::Load(), PCB_EDIT_FRAME::LoadFootprints(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), BOARD_NETLIST_UPDATER::replaceComponent(), BOARD::ReplaceNetlist(), COMPONENT::SetFPID(), DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser(), CVPCB_MAINFRAME::ToFirstNA(), and CVPCB_MAINFRAME::ToPreviousNA().

186 { return nickname.empty() && item_name.empty() && revision.empty(); }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
bool empty() const
Definition: utf8.h:108
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:269
unsigned LIB_ID::FindIllegalLibNicknameChar ( const UTF8 aNickname,
LIB_ID_TYPE  aType 
)
static

Looks for characters that are illegal in library nicknames.

Parameters
aNicknameis the logical library name to be tested.
aTypeis the library identifier type
Returns
Invalid character found in the name or 0 is the name is valid.

Definition at line 398 of file lib_id.cpp.

References isLegalLibNicknameChar().

Referenced by operator!=(), PANEL_SYM_LIB_TABLE::verifyTables(), and PANEL_FP_LIB_TABLE::verifyTables().

399 {
400  for( unsigned ch : aNickname )
401  {
402  if( !isLegalLibNicknameChar( ch, aType ) )
403  return ch;
404  }
405 
406  return 0;
407 }
static bool isLegalLibNicknameChar(unsigned aUniChar, LIB_ID_TYPE aType)
Tests whether a unicode character is a legal LIB_ID library nickname character.
Definition: lib_id.cpp:410
UTF8 LIB_ID::FixIllegalChars ( const UTF8 aLibItemName,
LIB_ID_TYPE  aType,
bool  aLib = false 
)
static

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

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

Definition at line 352 of file lib_id.cpp.

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

Referenced by PANEL_SYM_LIB_TABLE::browseLibrariesHandler(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), LIB_EDIT_FRAME::EditField(), find_component(), RESCUE_CACHE_CANDIDATE::FindRescues(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SCH_EAGLE_PLUGIN::fixSymbolName(), SCH_EAGLE_PLUGIN::getLibName(), SCH_LEGACY_PLUGIN_CACHE::loadDocs(), operator!=(), Parse(), LIB_ALIAS::SetName(), and LIB_PART::SetName().

353 {
354  UTF8 fixedName;
355 
356  for( UTF8::uni_iter chIt = aLibItemName.ubegin(); chIt < aLibItemName.uend(); ++chIt )
357  {
358  auto ch = *chIt;
359  if( aLib )
360  fixedName += isLegalLibNicknameChar( ch, aType ) ? ch : '_';
361  else
362  fixedName += isLegalChar( ch, aType ) ? ch : '_';
363  }
364 
365  return fixedName;
366 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
static bool isLegalLibNicknameChar(unsigned aUniChar, LIB_ID_TYPE aType)
Tests whether a unicode character is a legal LIB_ID library nickname character.
Definition: lib_id.cpp:410
static bool isLegalChar(unsigned aUniChar, LIB_ID_TYPE aType)
Tests whether a unicode character is a legal LIB_ID item name character.
Definition: lib_id.cpp:369
uni_iter ubegin() const
Function ubegin returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:285
class uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded ...
Definition: utf8.h:207
uni_iter uend() const
Function uend returns a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:294
UTF8 LIB_ID::Format ( ) const
Returns
the fully formatted text of the LIB_ID in a UTF8 string.

Definition at line 237 of file lib_id.cpp.

References item_name, nickname, revision, and UTF8::size().

Referenced by BOARD_NETLIST_UPDATER::addNewComponent(), CVPCB_MAINFRAME::BuildCmpListBox(), CMP_CANDIDATE::CMP_CANDIDATE(), CreateDevicesSection(), CreateShapesSection(), DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS(), FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint(), PART_LIB::FindAlias(), PART_LIB::FindPart(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), PCB_IO::format(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), MODULE::GetMsgPanelInfo(), GetRevision(), SCH_COMPONENT::GetScreenCoord(), GetUniStringLibId(), SCH_EDIT_FRAME::importFile(), isLegalLibNicknameChar(), PCB_BASE_FRAME::loadFootprint(), PCB_BASE_FRAME::LoadFootprint(), PCB_EDIT_FRAME::LoadFootprints(), DSN::SPECCTRA_DB::makeIMAGE(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction(), DIALOG_EXCHANGE_FOOTPRINTS::processModule(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), CVPCB_MAINFRAME::refreshAfterComponentSearch(), BOARD_NETLIST_UPDATER::replaceComponent(), BOARD::ReplaceNetlist(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), SCH_COMPONENT::Resolve(), SCH_LEGACY_PLUGIN::saveComponent(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), SCH_COMPONENT::SetLibId(), DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser(), CVPCB_MAINFRAME::SetNewPkg(), BOARD_NETLIST_UPDATER::testConnectivity(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataToWindow(), DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataToWindow(), BOARD_NETLIST_UPDATER::UpdateNetlist(), LIB_EDIT_FRAME::updateTitle(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

238 {
239  UTF8 ret;
240 
241  if( nickname.size() )
242  {
243  ret += nickname;
244  ret += ':';
245  }
246 
247  ret += item_name;
248 
249  if( revision.size() )
250  {
251  ret += '/';
252  ret += revision;
253  }
254 
255  return ret;
256 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
std::string::size_type size() const
Definition: utf8.h:115
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:269
UTF8 LIB_ID::Format ( const UTF8 aLibNickname,
const UTF8 aLibItemName,
const UTF8 aRevision = "" 
)
static
Returns
a string in the proper format as an LIB_ID for a combination of aLibNickname, aLibItemName, and aRevision.
Exceptions
PARSE_ERRORif any of the pieces are illegal.

Definition at line 273 of file lib_id.cpp.

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

274 {
275  UTF8 ret;
276  int offset;
277 
278  if( aLogicalLib.size() )
279  {
280  offset = okLogical( aLogicalLib );
281 
282  if( offset != -1 )
283  {
284  THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ),
285  wxString::FromUTF8( aLogicalLib.c_str() ),
286  aLogicalLib.c_str(), 0, offset );
287  }
288 
289  ret += aLogicalLib;
290  ret += ':';
291  }
292 
293  ret += aLibItemName; // TODO: Add validity test.
294 
295  if( aRevision.size() )
296  {
297  offset = okRevision( aRevision );
298 
299  if( offset != -1 )
300  {
301  THROW_PARSE_ERROR( _( "Illegal character found in revision" ),
302  wxString::FromUTF8( aRevision.c_str() ),
303  aRevision.c_str(),
304  0,
305  offset );
306  }
307 
308  ret += '/';
309  ret += aRevision;
310  }
311 
312  return ret;
313 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
static int okLogical(const UTF8 &aField)
Definition: lib_id.cpp:86
std::string::size_type size() const
Definition: utf8.h:115
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
const char * c_str() const
Definition: utf8.h:107
static int okRevision(const UTF8 &aField)
Definition: lib_id.cpp:94
const UTF8& LIB_ID::GetLibItemName ( ) const
inline
Returns
the library item name, i.e. footprintName, in UTF8.

Definition at line 114 of file lib_id.h.

References item_name.

Referenced by FOOTPRINT_EDIT_FRAME::AddModuleToBoard(), SCH_REFERENCE::CompareLibName(), FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), PCB_EDIT_FRAME::DoGenFootprintsPositionFile(), PCB_EDIT_FRAME::Exchange_Module(), FOOTPRINT_EDIT_FRAME::Export_Module(), LIB_TREE_MODEL_ADAPTER::FindItem(), PART_LIBS::FindLibPart(), PART_LIBS::FindLibraryAlias(), 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(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), FOOTPRINT_LIST::GetModuleInfo(), LIB_EDIT_FRAME::getTargetPart(), FP_TREE_SYNCHRONIZING_ADAPTER::GetValue(), guessNickname(), PCB_EDIT_FRAME::importFile(), LIB_EDIT_FRAME::isCurrentPart(), isLegalLibNicknameChar(), LIB_EDIT_FRAME::LoadComponentAndSelectLib(), PCB_EDIT_FRAME::LoadFootprints(), LEGACY_PLUGIN::loadMODULE(), LEGACY_PLUGIN::loadMODULE_EDGE(), LEGACY_PLUGIN::loadPAD(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), NETLIST_EXPORTER_GENERIC::makeComponents(), DIALOG_EDIT_COMPONENTS_LIBID::onClickOrphansButton(), LIB_EDIT_FRAME::OnCopyCutPart(), LIB_EDIT_FRAME::OnEditPart(), LIB_EDIT_FRAME::OnPasteDuplicatePart(), LIB_EDIT_FRAME::OnRemovePart(), LIB_EDIT_FRAME::OnRevert(), LIB_EDIT_FRAME::OnSave(), LIB_EDIT_FRAME::OnSaveAs(), LIB_EDIT_FRAME::OnUpdateRevert(), LIB_EDIT_FRAME::OnUpdateSave(), FOOTPRINT_EDIT_FRAME::OnUpdateSaveAs(), LIB_EDIT_FRAME::OnUpdateSaveAs(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction(), DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), CVPCB_MAINFRAME::ReadSchematicNetlist(), PCB_EDIT_FRAME::RecreateBOMFileFromBoard(), DIALOG_SYMBOL_REMAP::remapSymbolsToLibTable(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), BOARD::ReplaceNetlist(), LIB_EDIT_FRAME::saveCurrentPart(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), FOOTPRINT_EDIT_FRAME::saveFootprintInLibrary(), LIB_EDIT_FRAME::savePartAs(), SYMBOL_LIB_TABLE::SaveSymbol(), SchGetLibAlias(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint(), SCH_COMPONENT::SetLibId(), setLibNickname(), FOOTPRINTS_LISTBOX::SetSelectedFootprint(), LIB_TREE::setState(), DIALOG_CHOOSE_COMPONENT::ShowFootprintFor(), FOOTPRINT_VIEWER_FRAME::ShowModal(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow(), and FOOTPRINT_EDIT_FRAME::updateTitle().

114 { return item_name; }
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
UTF8 LIB_ID::GetLibItemNameAndRev ( ) const

Definition at line 259 of file lib_id.cpp.

References revision, and UTF8::size().

Referenced by GetRevision().

260 {
261  UTF8 ret;
262 
263  if( revision.size() )
264  {
265  ret += '/';
266  ret += revision;
267  }
268 
269  return ret;
270 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
std::string::size_type size() const
Definition: utf8.h:115
const UTF8& LIB_ID::GetLibNickname ( ) const
inline

Return the logical library name portion of a LIB_ID.

Definition at line 97 of file lib_id.h.

References nickname, and SetLibNickname().

Referenced by SCH_SCREENS::ChangeSymbolLibNickname(), FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), LIB_TREE_MODEL_ADAPTER::FindItem(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), SCH_SCREENS::GetLibNicknames(), LIB_PART::GetLibraryName(), FOOTPRINT_EDIT_FRAME::GetLoadedFPID(), FOOTPRINT_LIST::GetModuleInfo(), SCH_COMPONENT::GetMsgPanelInfo(), FOOTPRINT_EDIT_FRAME::getTargetFPID(), LIB_EDIT_FRAME::getTargetLib(), LIB_EDIT_FRAME::getTargetLibId(), LIB_EDIT_FRAME::getTargetPart(), guessNickname(), SCH_SCREENS::HasNoFullyDefinedLibIds(), LIB_EDIT_FRAME::isCurrentPart(), isLegalLibNicknameChar(), LIB_EDIT_FRAME::LoadComponentAndSelectLib(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), NETLIST_EXPORTER_GENERIC::makeLibParts(), LIB_EDIT_FRAME::OnCopyCutPart(), LIB_EDIT_FRAME::OnEditPart(), LIB_EDIT_FRAME::OnPasteDuplicatePart(), LIB_EDIT_FRAME::OnRemovePart(), LIB_EDIT_FRAME::OnRevert(), LIB_EDIT_FRAME::OnSave(), LIB_EDIT_FRAME::OnSaveAs(), LIB_EDIT_FRAME::OnUpdateRevert(), LIB_EDIT_FRAME::OnUpdateSave(), FOOTPRINT_EDIT_FRAME::OnUpdateSaveAs(), LIB_EDIT_FRAME::OnUpdateSaveAs(), DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), DIALOG_SYMBOL_REMAP::remapSymbolsToLibTable(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), SCH_COMPONENT::Resolve(), LIB_EDIT_FRAME::saveCurrentPart(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), LIB_EDIT_FRAME::savePartAs(), SchGetLibAlias(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint(), SCH_COMPONENT::SetLibId(), setLibNickname(), FOOTPRINTS_LISTBOX::SetSelectedFootprint(), LIB_TREE::setState(), DIALOG_CHOOSE_COMPONENT::ShowFootprintFor(), FOOTPRINT_VIEWER_FRAME::ShowModal(), LIB_TREE_NODE_LIB_ID::Update(), and FOOTPRINT_EDIT_FRAME::updateTitle().

98  {
99  return nickname;
100  }
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:269
const UTF8& LIB_ID::GetRevision ( ) const
inline

Definition at line 134 of file lib_id.h.

References Format(), GetLibItemNameAndRev(), and revision.

Referenced by isLegalLibNicknameChar().

134 { return revision; }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
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. Equivalent to Format().wx_str(), but more explicit when building a Unicode string in messages.

Definition at line 148 of file lib_id.h.

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

Referenced by SCH_EDIT_FRAME::CreateArchiveLibrary(), CMP_CANDIDATE::GetStringLibId(), and DISPLAY_FOOTPRINTS_FRAME::InitDisplay().

149  {
150  return Format().wx_str();
151  }
wxString wx_str() const
Definition: utf8.cpp:51
UTF8 Format() const
Definition: lib_id.cpp:237
const wxString LIB_ID::GetUniStringLibItemName ( ) const
inline
Returns
the library item name, i.e. footprintName in a wxString (UTF16 or 32). useful to display messages in dialogs Equivalent to item_name.wx_str(), but more explicit when building a Unicode string in messages.

Definition at line 121 of file lib_id.h.

References item_name, SetLibItemName(), SetRevision(), and UTF8::wx_str().

Referenced by SCH_EDIT_FRAME::CreateArchiveLibrary(), and LIB_EDIT_FRAME::OnRemovePart().

121 { return item_name.wx_str(); }
wxString wx_str() const
Definition: utf8.cpp:51
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
int LIB_ID::HasIllegalChars ( const UTF8 aLibItemName,
LIB_ID_TYPE  aType 
)
static

Examine aLibItemName for invalid LIB_ID item name characters.

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

Definition at line 336 of file lib_id.cpp.

References isLegalChar().

Referenced by RESCUE_CACHE_CANDIDATE::FindRescues(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), operator!=(), and Parse().

337 {
338  int offset = 0;
339 
340  for( auto ch : aLibItemName )
341  {
342  if( !isLegalChar( ch, aType ) )
343  return offset;
344  else
345  ++offset;
346  }
347 
348  return -1;
349 }
static bool isLegalChar(unsigned aUniChar, LIB_ID_TYPE aType)
Tests whether a unicode character is a legal LIB_ID item name character.
Definition: lib_id.cpp:369
bool LIB_ID::IsLegacy ( ) const
inline
Returns
true if the LIB_ID only has the item_name name defined.

Definition at line 176 of file lib_id.h.

References clear(), UTF8::empty(), item_name, nickname, and revision.

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

176 { return nickname.empty() && !item_name.empty() && revision.empty(); }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
bool empty() const
Definition: utf8.h:108
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:269
bool LIB_ID::isLegalChar ( unsigned  aUniChar,
LIB_ID_TYPE  aType 
)
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 not allowed in symbol library nicknames since they are not quoted in the symbol library 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 369 of file lib_id.cpp.

References ID_PCB, and ID_SCH.

Referenced by FixIllegalChars(), HasIllegalChars(), and operator!=().

370 {
371  bool const space_allowed = ( aType == ID_PCB );
372  bool const illegal_filename_chars_allowed = ( aType == ID_SCH );
373 
374  if( aUniChar < ' ' )
375  return false;
376 
377  switch( aUniChar )
378  {
379  case ':':
380  case '/':
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 }
bool LIB_ID::isLegalLibNicknameChar ( unsigned  aUniChar,
LIB_ID_TYPE  aType 
)
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.

References UTF8::c_str(), Format(), GetLibItemName(), GetLibNickname(), GetRevision(), i, ID_SCH, and main().

Referenced by FindIllegalLibNicknameChar(), FixIllegalChars(), and operator!=().

411 {
412  bool const space_allowed = ( aType != ID_SCH );
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 }
bool LIB_ID::IsValid ( ) const
inline
Returns
true is the LIB_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.

Definition at line 171 of file lib_id.h.

References UTF8::empty(), item_name, and nickname.

Referenced by FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), PCB_EDIT_FRAME::LoadFootprints(), DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected(), DIALOG_CHOOSE_COMPONENT::OnComponentSelected(), CVPCB_MAINFRAME::OnSelectComponent(), DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector(), DIALOG_EXCHANGE_FOOTPRINTS::processMatchingModules(), SCH_COMPONENT::Resolve(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), SCH_BASE_FRAME::SelectComponentFromLibTree(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser(), DIALOG_CHOOSE_COMPONENT::ShowFootprint(), FOOTPRINT_VIEWER_FRAME::ShowModal(), LIB_TREE_MODEL_ADAPTER::ShowPreselect(), LIB_EDIT_FRAME::SyncLibraries(), FOOTPRINT_EDIT_FRAME::SyncLibraryTree(), and FOOTPRINT_EDIT_FRAME::updateTitle().

171 { return !nickname.empty() && !item_name.empty(); }
bool empty() const
Definition: utf8.h:108
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:269
bool LIB_ID::operator!= ( const LIB_ID aLibId) const
inline

Definition at line 201 of file lib_id.h.

References FindIllegalLibNicknameChar(), FixIllegalChars(), HasIllegalChars(), isLegalChar(), and isLegalLibNicknameChar().

201 { return !(*this == aLibId); }
bool LIB_ID::operator< ( const LIB_ID aLibId) const
inline

Definition at line 198 of file lib_id.h.

References compare().

198 { 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:316
bool LIB_ID::operator== ( const LIB_ID aLibId) const
inline

Definition at line 200 of file lib_id.h.

References compare().

200 { 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:316
bool LIB_ID::operator> ( const LIB_ID aLibId) const
inline

Definition at line 199 of file lib_id.h.

References compare().

199 { 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:316
int LIB_ID::Parse ( const UTF8 aId,
LIB_ID_TYPE  aType,
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.
aTypeindicates the LIB_ID type for type-specific parsing (such as allowed chars).
aFixindicates invalid chars should be replaced with '_'.
Returns
int - 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.

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

Referenced by PCAD2KICAD::PCB_MODULE::AddToBoard(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FOOTPRINT_LIST::GetModuleInfo(), SCH_EDIT_FRAME::importFile(), DIALOG_EXCHANGE_FOOTPRINTS::isMatch(), LIB_ID(), CMP_READER::Load(), LEGACY_PLUGIN::loadAllSections(), SCH_LEGACY_PLUGIN::loadComponent(), EAGLE_PLUGIN::makeModule(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnBrowseLibrary(), DIALOG_EDIT_COMPONENTS_LIBID::onClickOrphansButton(), KICAD_NETLIST_PARSER::parseComponent(), PCB_PARSER::parseMODULE_unchecked(), DIALOG_EXCHANGE_FOOTPRINTS::processMatchingModules(), DIALOG_EDIT_COMPONENTS_LIBID::revertChanges(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), CVPCB_MAINFRAME::SetNewPkg(), DIALOG_CHOOSE_COMPONENT::ShowFootprint(), FOOTPRINT_VIEWER_FRAME::ShowModal(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow(), DIALOG_EDIT_COMPONENTS_LIBID::TransferDataFromWindow(), and DIALOG_EDIT_COMPONENTS_LIBID::validateLibIds().

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  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  //=====<nickname>==========================================
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, aType, false );
172  else
173  offset = HasIllegalChars( fpname, aType );
174 
175  if( offset > -1 )
176  return offset;
177 
178  SetLibItemName( fpname );
179 
180  return -1;
181 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
static constexpr std::string::size_type npos
Definition: utf8.h:155
const char * EndsWithRev(const char *start, const char *tail, char separator)
Definition: lib_id.cpp:41
UTF8 revision
The revision of the entry.
Definition: lib_id.h:271
std::string substr(size_t pos=0, size_t len=npos) const
Definition: utf8.h:182
static int HasIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:336
std::string::size_type size() const
Definition: utf8.h:115
std::string::size_type find(char c) const
Definition: utf8.h:110
std::string::size_type length() const
Definition: utf8.h:114
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:206
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
const char * c_str() const
Definition: utf8.h:107
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores &#39;_&#39;.
Definition: lib_id.cpp:352
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 206 of file lib_id.cpp.

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

Referenced by SCH_BASE_FRAME::DisplayListComponentsInLib(), FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint(), LIB_ALIAS::GetLibId(), GetUniStringLibItemName(), 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(), SCH_COMPONENT::SCH_COMPONENT(), LIB_PART::SetName(), LIB_EDIT_FRAME::SyncLibraries(), FOOTPRINT_EDIT_FRAME::SyncLibraryTree(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataFromWindow(), and RESCUER::UndoRescues().

207 {
208  int separation = int( aLibItemName.find_first_of( "/" ) );
209 
210  if( aTestForRev && separation != -1 )
211  {
212  item_name = aLibItemName.substr( 0, separation-1 );
213  return separation;
214  }
215  else
216  {
217  item_name = aLibItemName;
218  }
219 
220  return -1;
221 }
std::string substr(size_t pos=0, size_t len=npos) const
Definition: utf8.h:182
std::string::size_type find_first_of(const std::string &str, std::string::size_type pos=0) const
Definition: utf8.h:122
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:270
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.

References nickname, and okLogical().

Referenced by SCH_SCREENS::ChangeSymbolLibNickname(), FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList(), LIB_MANAGER::LIB_BUFFER::CreateBuffer(), FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint(), FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), GetLibNickname(), 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(), Parse(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), FOOTPRINT_EDIT_FRAME::restoreLastFootprint(), setLibNickname(), and LIB_TREE_NODE_LIB_ID::Update().

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

Definition at line 224 of file lib_id.cpp.

References okRevision(), and revision.

Referenced by GetUniStringLibItemName().

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

Member Data Documentation

UTF8 LIB_ID::item_name
protected

The name of the entry in the logical library.

Definition at line 270 of file lib_id.h.

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

UTF8 LIB_ID::nickname
protected

The nickname of the library or empty.

Definition at line 269 of file lib_id.h.

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

UTF8 LIB_ID::revision
protected

The revision of the entry.

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