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 UTF8 &aId)
 Takes aId string and parses it. More...
 
 LIB_ID (const wxString &aId)
 
 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)
 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
 
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
 
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 bool HasIllegalChars (const UTF8 &aLibItemName)
 Examine aLibItemName for invalid LIB_ID item name characters. More...
 
static UTF8 FixIllegalChars (const UTF8 &aLibItemName)
 Replace illegal LIB_ID item name characters with underscores '_'. 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.

Constructor & Destructor Documentation

LIB_ID::LIB_ID ( )
inline

Definition at line 55 of file lib_id.h.

55 {}
LIB_ID::LIB_ID ( const UTF8 aId)

Takes aId string and parses it.

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 a string to be parsed into the LIB_ID object.

Definition at line 178 of file lib_id.cpp.

References UTF8::c_str(), Parse(), and THROW_PARSE_ERROR.

179 {
180  int offset = Parse( aId );
181 
182  if( offset != -1 )
183  {
184  THROW_PARSE_ERROR( _( "Illegal character found in LIB_ID string" ),
185  wxString::FromUTF8( aId.c_str() ),
186  aId.c_str(),
187  0,
188  offset );
189  }
190 }
int Parse(const UTF8 &aId)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
const char * c_str() const
Definition: utf8.h:107
LIB_ID::LIB_ID ( const wxString &  aId)

Definition at line 193 of file lib_id.cpp.

References Parse(), and THROW_PARSE_ERROR.

194 {
195  UTF8 id = aId;
196 
197  int offset = Parse( id );
198 
199  if( offset != -1 )
200  {
201  THROW_PARSE_ERROR( _( "Illegal character found in LIB_ID string" ),
202  aId,
203  id.c_str(),
204  0,
205  offset );
206  }
207 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
int Parse(const UTF8 &aId)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
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 210 of file lib_id.cpp.

211  :
212  nickname( aLibName ),
213  item_name( aLibItemName ),
214  revision( aRevision )
215 {
216 }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:210
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:209
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:208

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

115 {
116  nickname.clear();
117  item_name.clear();
118  revision.clear();
119 }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:210
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:209
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:208
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 342 of file lib_id.cpp.

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

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

343 {
344  // Don't bother comparing the same object.
345  if( this == &aLibId )
346  return 0;
347 
348  int retv = nickname.compare( aLibId.nickname );
349 
350  if( retv != 0 )
351  return retv;
352 
353  retv = item_name.compare( aLibId.item_name );
354 
355  if( retv != 0 )
356  return retv;
357 
358  return revision.compare( aLibId.revision );
359 }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:210
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:209
int compare(const std::string &s) const
Definition: utf8.h:116
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:208
bool LIB_ID::empty ( ) const
inline
Returns
a boolean true value if the LIB_ID is empty. Otherwise return false.

Definition at line 170 of file lib_id.h.

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

Referenced by 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::SetNewPkg(), CVPCB_MAINFRAME::ToFirstNA(), and CVPCB_MAINFRAME::ToPreviousNA().

170 { return nickname.empty() && item_name.empty() && revision.empty(); }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:210
bool empty() const
Definition: utf8.h:108
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:209
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:208
UTF8 LIB_ID::FixIllegalChars ( const UTF8 aLibItemName)
static

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

Parameters
aLibItemNameis the LIB_ID item name to replace illegal characters.
Returns
the corrected version of aLibItemName.

Definition at line 384 of file lib_id.cpp.

Referenced by RESCUE_CACHE_CANDIDATE::FindRescues(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SCH_EAGLE_PLUGIN::loadInstance(), and SCH_EAGLE_PLUGIN::loadLibrary().

385 {
386  UTF8 fixedName;
387 
388  for( auto ch : aLibItemName )
389  {
390 
391  if( !wxIsascii( ch ) )
392  {
393  fixedName += '_';
394  }
395  else
396  {
397  switch( ch )
398  {
399  case '\t':
400  case '\n':
401  case '\r':
402  case ':':
403  case '/':
404  case '\\':
405  fixedName += '_';
406  break;
407 
408  default:
409  fixedName += ch;
410  }
411  }
412  }
413 
414  return fixedName;
415 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
UTF8 LIB_ID::Format ( ) const
Returns
the fully formatted text of the LIB_ID.

Definition at line 263 of file lib_id.cpp.

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

Referenced by BOARD_NETLIST_UPDATER::addNewComponent(), CVPCB_MAINFRAME::BuildCmpListBox(), DIALOG_EXCHANGE_MODULE::change_1_Module(), DIALOG_EXCHANGE_MODULE::changeSameFootprints(), CMP_CANDIDATE::CMP_CANDIDATE(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel(), SCH_EDIT_FRAME::CreateArchiveLibrary(), CreateDevicesSection(), CreateShapesSection(), DIALOG_SCH_EDIT_ONE_FIELD::DIALOG_SCH_EDIT_ONE_FIELD(), FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint(), PART_LIB::FindAlias(), PART_LIB::FindPart(), COMPONENT::Format(), PCB_IO::format(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), MODULE::GetMsgPanelInfo(), CMP_CANDIDATE::GetStringLibId(), DIALOG_EXCHANGE_MODULE::init(), PCB_BASE_FRAME::loadFootprint(), PCB_BASE_FRAME::LoadFootprint(), PCB_EDIT_FRAME::LoadFootprints(), PCB_BASE_FRAME::LoadModuleFromLibrary(), DSN::SPECCTRA_DB::makeIMAGE(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), RecreateCmpFile(), CVPCB_MAINFRAME::refreshAfterComponentSearch(), BOARD_NETLIST_UPDATER::replaceComponent(), BOARD::ReplaceNetlist(), SCH_COMPONENT::Resolve(), SCH_LEGACY_PLUGIN::saveComponent(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), SCH_COMPONENT::SetLibId(), DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser(), CVPCB_MAINFRAME::SetNewPkg(), BOARD_NETLIST_UPDATER::testConnectivity(), and BOARD_NETLIST_UPDATER::UpdateNetlist().

264 {
265  UTF8 ret;
266 
267  if( nickname.size() )
268  {
269  ret += nickname;
270  ret += ':';
271  }
272 
273  ret += item_name;
274 
275  if( revision.size() )
276  {
277  ret += '/';
278  ret += revision;
279  }
280 
281  return ret;
282 }
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:210
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:209
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:208
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 299 of file lib_id.cpp.

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

300 {
301  UTF8 ret;
302  int offset;
303 
304  if( aLogicalLib.size() )
305  {
306  offset = okLogical( aLogicalLib );
307 
308  if( offset != -1 )
309  {
310  THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ),
311  wxString::FromUTF8( aLogicalLib.c_str() ),
312  aLogicalLib.c_str(), 0, offset );
313  }
314 
315  ret += aLogicalLib;
316  ret += ':';
317  }
318 
319  ret += aLibItemName; // TODO: Add validity test.
320 
321  if( aRevision.size() )
322  {
323  offset = okRevision( aRevision );
324 
325  if( offset != -1 )
326  {
327  THROW_PARSE_ERROR( _( "Illegal character found in revision" ),
328  wxString::FromUTF8( aRevision.c_str() ),
329  aRevision.c_str(),
330  0,
331  offset );
332  }
333 
334  ret += '/';
335  ret += aRevision;
336  }
337 
338  return ret;
339 }
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)
Definition: ki_exception.h:133
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.

Definition at line 115 of file lib_id.h.

References item_name.

Referenced by SCH_REFERENCE::CompareLibName(), SCH_EDIT_FRAME::CreateArchiveLibrary(), FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary(), PCB_EDIT_FRAME::DoGenFootprintsPositionFile(), PCB_EDIT_FRAME::Exchange_Module(), FOOTPRINT_EDIT_FRAME::Export_Module(), CMP_TREE_MODEL_ADAPTER_BASE::FindItem(), PART_LIBS::FindLibPart(), PART_LIBS::FindLibraryAlias(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), FP_LIB_TABLE::FootprintLoad(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), PCB_IO::FootprintSave(), FP_LIB_TABLE::FootprintSave(), ALIAS_INFO_GENERATOR::GenerateHtml(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FOOTPRINT_LIST::GetModuleInfo(), LIB_EDIT_FRAME::getTargetPart(), guessNickname(), DIALOG_MODULE_MODULE_EDITOR::initModeditProperties(), 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(), DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick(), LIB_EDIT_FRAME::OnPasteDuplicatePart(), LIB_EDIT_FRAME::OnRemovePart(), LIB_EDIT_FRAME::OnRevertPart(), LIB_EDIT_FRAME::OnSavePart(), LIB_EDIT_FRAME::OnUpdatePartModified(), EAGLE_PLUGIN::packageCircle(), EAGLE_PLUGIN::packagePolygon(), EAGLE_PLUGIN::packageRectangle(), EAGLE_PLUGIN::packageText(), EAGLE_PLUGIN::packageWire(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction(), DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), CVPCB_MAINFRAME::ReadSchematicNetlist(), PCB_EDIT_FRAME::RecreateBOMFileFromBoard(), DIALOG_SYMBOL_REMAP::remapSymbolsToLibTable(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), BOARD::ReplaceNetlist(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), SYMBOL_LIB_TABLE::SaveSymbol(), SchGetLibAlias(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint(), SCH_COMPONENT::SetLibId(), and DIALOG_CHOOSE_COMPONENT::ShowFootprintFor().

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

Definition at line 285 of file lib_id.cpp.

References revision, and UTF8::size().

286 {
287  UTF8 ret;
288 
289  if( revision.size() )
290  {
291  ret += '/';
292  ret += revision;
293  }
294 
295  return ret;
296 }
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:210
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 98 of file lib_id.h.

References nickname.

Referenced by SCH_SCREENS::ChangeSymbolLibNickname(), CMP_TREE_MODEL_ADAPTER_BASE::FindItem(), FP_LIB_TABLE::FootprintLoad(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), ALIAS_INFO_GENERATOR::GenerateHtml(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), SCH_SCREENS::GetLibNicknames(), FOOTPRINT_LIST::GetModuleInfo(), SCH_COMPONENT::GetMsgPanelInfo(), LIB_EDIT_FRAME::getTargetLib(), LIB_EDIT_FRAME::getTargetPart(), guessNickname(), SCH_SCREENS::HasNoFullyDefinedLibIds(), DIALOG_MODULE_MODULE_EDITOR::initModeditProperties(), 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::OnRevertPart(), LIB_EDIT_FRAME::OnSavePart(), LIB_EDIT_FRAME::OnUpdatePartModified(), DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector(), DIALOG_SYMBOL_REMAP::remapSymbolsToLibTable(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), SchGetLibAlias(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint(), SCH_COMPONENT::SetLibId(), and DIALOG_CHOOSE_COMPONENT::ShowFootprintFor().

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

Definition at line 128 of file lib_id.h.

References revision.

128 { return revision; }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:210
bool 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
true if aLibItemName contain illegal characters otherwise false.

Definition at line 362 of file lib_id.cpp.

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

363 {
364  for( auto ch : aLibItemName )
365  {
366  switch( ch )
367  {
368  case '\t':
369  case '\n':
370  case '\r':
371  case ':':
372  case '/':
373  return true;
374  }
375 
376  if( !wxIsascii( ch ) )
377  return true;
378  }
379 
380  return false;
381 }
bool LIB_ID::IsLegacy ( ) const
inline
Returns
true if the LIB_ID only has the item_name name defined.

Definition at line 160 of file lib_id.h.

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

Referenced by CVPCB_MAINFRAME::ReadNetListAndFpFiles().

160 { return nickname.empty() && !item_name.empty() && revision.empty(); }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:210
bool empty() const
Definition: utf8.h:108
UTF8 item_name
The name of the entry in the logical library.
Definition: lib_id.h:209
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:208
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 155 of file lib_id.h.

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

Referenced by ALIAS_INFO_GENERATOR::GenerateHtml(), PCB_EDIT_FRAME::LoadFootprints(), DIALOG_CHOOSE_COMPONENT::OnComponentSelected(), DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector(), SCH_COMPONENT::Resolve(), SCH_BASE_FRAME::SelectComponentFromLibBrowser(), SCH_BASE_FRAME::SelectComponentFromLibrary(), DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser(), COMPONENT_TREE::setState(), DIALOG_CHOOSE_COMPONENT::ShowFootprint(), and CMP_TREE_MODEL_ADAPTER_BASE::ShowPreselect().

155 { 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:209
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:208
bool LIB_ID::operator!= ( const LIB_ID aLibId) const
inline

Definition at line 185 of file lib_id.h.

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

Definition at line 182 of file lib_id.h.

References compare().

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

Definition at line 184 of file lib_id.h.

References compare().

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

Definition at line 183 of file lib_id.h.

References compare().

183 { 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:342
int LIB_ID::Parse ( const UTF8 aId)

Parse LIB_ID with the information from aId.

Parameters
aIdis the string to populate the LIB_ID object.
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(), UTF8::length(), UTF8::npos, ReplaceIllegalFileNameChars(), revision, SetLibItemName(), SetLibNickname(), UTF8::size(), and UTF8::substr().

Referenced by DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FOOTPRINT_LIST::GetModuleInfo(), LIB_ID(), CMP_READER::Load(), SCH_LEGACY_PLUGIN::loadComponent(), PCB_BASE_FRAME::LoadModuleFromLibrary(), KICAD_NETLIST_PARSER::parseComponent(), PCB_PARSER::parseMODULE_unchecked(), DIALOG_EDIT_COMPONENTS_LIBID::revertChanges(), CVPCB_MAINFRAME::SetNewPkg(), DIALOG_CHOOSE_COMPONENT::ShowFootprint(), 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;
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  {
154  return offset;
155  }
156 
157  ++partNdx; // skip ':'
158  }
159  else
160  {
161  partNdx = 0;
162  }
163 
164  //=====<item name>====================================
165  if( partNdx >= revNdx )
166  return partNdx; // Error: no library item name.
167 
168  // Be sure the item name is valid.
169  // Some chars can be found in legacy files converted files from an other EDA tools.
170  std::string fpname = aId.substr( partNdx, revNdx-partNdx );
171  ReplaceIllegalFileNameChars( &fpname, '_' );
172  SetLibItemName( UTF8( fpname ) );
173 
174  return -1;
175 }
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:210
std::string substr(size_t pos=0, size_t len=npos) const
Definition: utf8.h:182
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Function ReplaceIllegalFileNameChars checks aName for illegal file name characters.
Definition: string.cpp:483
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:232
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:219
const char * c_str() const
Definition: utf8.h:107
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 232 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(), SCH_LEGACY_PLUGIN::loadComponent(), LEGACY_NETLIST_READER::loadComponent(), Parse(), RESCUE_CASE_CANDIDATE::PerformAction(), RESCUE_CACHE_CANDIDATE::PerformAction(), SCH_COMPONENT::SCH_COMPONENT(), LIB_PART::SetName(), DIALOG_MODULE_MODULE_EDITOR::TransferDataFromWindow(), and RESCUER::UndoRescues().

233 {
234  int separation = int( aLibItemName.find_first_of( "/" ) );
235 
236  if( aTestForRev && separation != -1 )
237  {
238  item_name = aLibItemName.substr( 0, separation-1 );
239  return separation;
240  }
241  else
242  {
243  item_name = aLibItemName;
244  }
245 
246  return -1;
247 }
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:209
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 219 of file lib_id.cpp.

References nickname, and okLogical().

Referenced by SCH_SCREENS::ChangeSymbolLibNickname(), FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList(), CMP_TREE_NODE_LIB::CMP_TREE_NODE_LIB(), LIB_MANAGER::LIB_BUFFER::CreateBuffer(), EVT_TOOL(), FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint(), FP_LIB_TABLE::FootprintLoad(), guessNickname(), SYMBOL_LIB_TABLE::LoadSymbol(), Parse(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), and LIB_PART::SetLib().

220 {
221  int offset = okLogical( aLogical );
222 
223  if( offset == -1 )
224  {
225  nickname = aLogical;
226  }
227 
228  return offset;
229 }
static int okLogical(const UTF8 &aField)
Definition: lib_id.cpp:86
UTF8 nickname
The nickname of the library or empty.
Definition: lib_id.h:208
int LIB_ID::SetRevision ( const UTF8 aRevision)

Definition at line 250 of file lib_id.cpp.

References okRevision(), and revision.

251 {
252  int offset = okRevision( aRevision );
253 
254  if( offset == -1 )
255  {
256  revision = aRevision;
257  }
258 
259  return offset;
260 }
UTF8 revision
The revision of the entry.
Definition: lib_id.h:210
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 209 of file lib_id.h.

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

UTF8 LIB_ID::nickname
protected

The nickname of the library or empty.

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