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)
 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)
 Override the library item name portion of the LIB_ID to aLibItemName. More...
 
UTF8 GetSubLibraryName () const
 Some LIB_IDs can have a sub-library identifier in addition to a library nickname. More...
 
void SetSubLibraryName (const UTF8 &aName)
 
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. 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. 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)
 
static int HasIllegalChars (const UTF8 &aLibItemName)
 Examine aLibItemName for invalid LIB_ID item name characters. More...
 
static UTF8 FixIllegalChars (const UTF8 &aLibItemName, bool aLib)
 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_subLibraryName
 Optional sub-library name used for grouping within a library. More...
 

Detailed Description

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

It consists of of a dyad of the library nickname and the name of the item in the library 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".

  • "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.
Author
Dick Hollenbeck

Definition at line 48 of file lib_id.h.

Constructor & Destructor Documentation

◆ LIB_ID() [1/2]

LIB_ID::LIB_ID ( )
inline

Definition at line 51 of file lib_id.h.

51{}

◆ LIB_ID() [2/2]

LIB_ID::LIB_ID ( const wxString &  aLibraryName,
const wxString &  aItemName 
)

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.

Definition at line 91 of file lib_id.cpp.

91 :
92 m_libraryName( aLibraryName ),
93 m_itemName( aItemName )
94{
95}
UTF8 m_libraryName
The nickname of the library or empty.
Definition: lib_id.h:264
UTF8 m_itemName
The name of the entry in the logical library.
Definition: lib_id.h:265

Member Function Documentation

◆ clear()

void LIB_ID::clear ( )

Clear the contents of the library nickname, library entry name.

Definition at line 42 of file lib_id.cpp.

43{
47}
UTF8 m_subLibraryName
Optional sub-library name used for grouping within a library.
Definition: lib_id.h:266
void clear()
Definition: utf8.h:108

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

Referenced by FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint(), and 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.

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 159 of file lib_id.cpp.

160{
161 // Don't bother comparing the same object.
162 if( this == &aLibId )
163 return 0;
164
165 int retv = m_libraryName.compare( aLibId.m_libraryName );
166
167 if( retv != 0 )
168 return retv;
169
170 return m_itemName.compare( aLibId.m_itemName );
171}
int compare(const std::string &s) const
Definition: utf8.h:111

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

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

◆ empty()

◆ 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 242 of file lib_id.cpp.

243{
244 for( unsigned ch : aLibraryName )
245 {
246 if( !isLegalLibraryNameChar( ch ) )
247 return ch;
248 }
249
250 return 0;
251}
static bool isLegalLibraryNameChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID library nickname character.
Definition: lib_id.cpp:254

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 
)
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 190 of file lib_id.cpp.

191{
192 UTF8 fixedName;
193
194 for( UTF8::uni_iter chIt = aLibItemName.ubegin(); chIt < aLibItemName.uend(); ++chIt )
195 {
196 auto ch = *chIt;
197 if( aLib )
198 fixedName += isLegalLibraryNameChar( ch ) ? ch : '_';
199 else
200 fixedName += isLegalChar( ch ) ? ch : '_';
201 }
202
203 return fixedName;
204}
static bool isLegalChar(unsigned aUniChar)
Tests whether a Unicode character is a legal LIB_ID item name character.
Definition: lib_id.cpp:207
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:204
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:71
uni_iter uend() const
Return a uni_iter initialized to the end of "this" UTF8 byte sequence.
Definition: utf8.h:287
uni_iter ubegin() const
Returns a uni_iter initialized to the start of "this" UTF8 byte sequence.
Definition: utf8.h:279

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

Referenced by PANEL_FP_LIB_TABLE::browseLibrariesHandler(), PANEL_SYM_LIB_TABLE::browseLibrariesHandler(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SCH_ALTIUM_PLUGIN::getLibName(), SCH_EAGLE_PLUGIN::getLibName(), CADSTAR_SCH_ARCHIVE_PLUGIN::Load(), and Parse().

◆ Format() [1/2]

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

Definition at line 117 of file lib_id.cpp.

118{
119 UTF8 ret;
120
121 if( m_libraryName.size() )
122 {
123 ret += m_libraryName;
124 ret += ':';
125 }
126
127 ret += m_itemName;
128
129 return ret;
130}
std::string::size_type size() const
Definition: utf8.h:110

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

Referenced by FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), SCH_SCREEN::AddLibSymbol(), BOARD_NETLIST_UPDATER::addNewFootprint(), CVPCB_ASSOCIATION_TOOL::Associate(), CVPCB_MAINFRAME::AssociateFootprint(), CVPCB_MAINFRAME::BuildSymbolsListBox(), CreateDevicesSection(), DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS(), DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), SYMBOL_LIB::FindSymbol(), PCB_PLUGIN::format(), SCH_SEXPR_PLUGIN::Format(), COMPONENT::Format(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), FOOTPRINT::GetFPIDAsString(), SCH_SYMBOL::GetSchSymbolLibraryName(), GetUniStringLibId(), DISPLAY_FOOTPRINTS_FRAME::InitDisplay(), PCB_EDIT_FRAME::LoadFootprints(), DSN::SPECCTRA_DB::makeIMAGE(), SCH_ALTIUM_PLUGIN::ParseImplementation(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::PerformAction(), DIALOG_EXCHANGE_FOOTPRINTS::processFootprint(), DIALOG_CHANGE_SYMBOLS::processSymbol(), CVPCB_MAINFRAME::readNetListAndFpFiles(), CVPCB_MAINFRAME::refreshAfterSymbolSearch(), BOARD_NETLIST_UPDATER::replaceFootprint(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::RESCUE_SYMBOL_LIB_TABLE_CANDIDATE(), SCH_LEGACY_PLUGIN::saveSymbol(), SCH_SEXPR_PLUGIN::saveSymbol(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), FOOTPRINTS_LISTBOX::SetSelectedFootprint(), SYMBOL_CANDIDATE::SYMBOL_CANDIDATE(), BOARD_NETLIST_UPDATER::testConnectivity(), DIALOG_SYMBOL_PROPERTIES::TransferDataToWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow(), BOARD_NETLIST_UPDATER::UpdateNetlist(), FOOTPRINT_EDIT_FRAME::UpdateTitle(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

◆ Format() [2/2]

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

Definition at line 133 of file lib_id.cpp.

134{
135 UTF8 ret;
136 int offset;
137
138 if( aLibraryName.size() )
139 {
140 offset = okLogical( aLibraryName );
141
142 if( offset != -1 )
143 {
144 THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ),
145 wxString::FromUTF8( aLibraryName.c_str() ), aLibraryName.c_str(),
146 0, offset );
147 }
148
149 ret += aLibraryName;
150 ret += ':';
151 }
152
153 ret += aLibItemName; // TODO: Add validity test.
154
155 return ret;
156}
const char * c_str() const
Definition: utf8.h:102
#define _(s)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
static int okLogical(const UTF8 &aField)
Definition: lib_id.cpp:34

References _, UTF8::c_str(), okLogical(), 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 101 of file lib_id.h.

101{ return m_itemName; }

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(), FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), FOOTPRINT_PREVIEW_PANEL::DisplayFootprint(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), FOOTPRINT_EDIT_FRAME::DuplicateFootprint(), SYMBOL_EDIT_FRAME::DuplicateSymbol(), SYMBOL_EDITOR_CONTROL::EditSymbol(), PCB_EDIT_FRAME::ExchangeFootprint(), FOOTPRINT_EDIT_FRAME::ExportFootprint(), LIB_TREE_MODEL_ADAPTER::FindItem(), SYMBOL_LIBS::FindLibSymbol(), RESCUE_CASE_CANDIDATE::FindRescues(), RESCUE_CACHE_CANDIDATE::FindRescues(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), PCB_PLUGIN::FootprintSave(), FP_LIB_TABLE::FootprintSave(), PCB_PLUGIN::format(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), PLACE_FILE_EXPORTER::GenPositionData(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::GetActionDescription(), DISPLAY_FOOTPRINTS_FRAME::GetFootprint(), FOOTPRINT_LIST::GetFootprintInfo(), SYMBOL_EDIT_FRAME::getTargetSymbol(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), FP_TREE_SYNCHRONIZING_ADAPTER::GetValue(), guessNickname(), SYMBOL_EDITOR_CONTROL::Init(), FOOTPRINT_EDITOR_CONTROL::Init(), SYMBOL_EDIT_FRAME::IsCurrentSymbol(), LEGACY_PLUGIN::loadFOOTPRINT(), PCB_EDIT_FRAME::LoadFootprints(), LEGACY_PLUGIN::loadFP_SHAPE(), LEGACY_PLUGIN::loadPAD(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_EDIT_FRAME::LoadSymbol(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), NETLIST_EXPORTER_XML::makeSymbols(), DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton(), PCB_EDIT_FRAME::OpenProjectFiles(), EAGLE_PLUGIN::packageText(), 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::remapSymbolsToLibTable(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), FOOTPRINT_EDITOR_CONTROL::RenameFootprint(), SYMBOL_EDITOR_CONTROL::RenameSymbol(), SCH_SYMBOL::ResolveTextVar(), FOOTPRINT::ResolveTextVar(), SYMBOL_EDIT_FRAME::Revert(), DRC_TEST_PROVIDER_LIBRARY_PARITY::Run(), FOOTPRINT_EDITOR_CONTROL::SaveAs(), SYMBOL_EDIT_FRAME::saveCurrentSymbol(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), SYMBOL_LIB_TABLE::SaveSymbol(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), SYMBOL_EDIT_FRAME::saveSymbolAs(), SchGetLibSymbol(), setLibNickname(), LIB_TREE::setState(), SYMBOL_EDIT_FRAME::setupUIConditions(), FOOTPRINT_EDIT_FRAME::setupUIConditions(), DIALOG_CHOOSE_SYMBOL::ShowFootprintFor(), FOOTPRINT_VIEWER_FRAME::ShowModal(), SYMBOL_VIEWER_FRAME::ShowModal(), ERC_TESTER::TestLibSymbolIssues(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow(), PCB_CONTROL::UpdateMessagePanel(), SYMBOL_LIBRARY_MANAGER::UpdateSymbol(), and FOOTPRINT_EDIT_FRAME::UpdateTitle().

◆ GetLibNickname()

const UTF8 & LIB_ID::GetLibNickname ( ) const
inline

Return the logical library name portion of a LIB_ID.

Definition at line 87 of file lib_id.h.

87{ return m_libraryName; }

References m_libraryName.

Referenced by SYMBOL_EDITOR_CONTROL::AddSymbol(), BASIC_FOOTPRINT_INFO::BASIC_FOOTPRINT_INFO(), SCH_SCREENS::ChangeSymbolLibNickname(), FOOTPRINT_EDITOR_CONTROL::CreateFootprint(), FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), FOOTPRINT_PREVIEW_PANEL::DisplayFootprint(), CVPCB_MAINFRAME::DisplayStatus(), SYMBOL_PREVIEW_WIDGET::DisplaySymbol(), FOOTPRINT_EDIT_FRAME::DuplicateFootprint(), SYMBOL_EDIT_FRAME::DuplicateSymbol(), SYMBOL_EDITOR_CONTROL::DuplicateSymbol(), SYMBOL_EDITOR_CONTROL::EditSymbol(), EXPORTER_PCB_VRML::ExportVrmlFootprint(), LIB_TREE_MODEL_ADAPTER::FindItem(), RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(), FP_LIB_TABLE::FootprintLoadWithOptionalNickname(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr(), DISPLAY_FOOTPRINTS_FRAME::GetFootprint(), FOOTPRINT_LIST::GetFootprintInfo(), SCH_SCREENS::GetLibNicknames(), LIB_SYMBOL::GetLibraryName(), FOOTPRINT_EDIT_FRAME::GetLoadedFPID(), SCH_SYMBOL::GetMsgPanelInfo(), SYMBOL_EDIT_FRAME::getTargetLib(), SYMBOL_EDIT_FRAME::getTargetSymbol(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue(), FP_TREE_SYNCHRONIZING_ADAPTER::GetValue(), guessNickname(), SCH_SCREENS::HasNoFullyDefinedLibIds(), idf_export_footprint(), SYMBOL_EDITOR_CONTROL::Init(), FOOTPRINT_EDITOR_CONTROL::Init(), SYMBOL_EDIT_FRAME::IsCurrentSymbol(), SYMBOL_LIB_TABLE::LoadSymbol(), SYMBOL_EDIT_FRAME::LoadSymbol(), SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname(), NETLIST_EXPORTER_XML::makeSymbols(), FOOTPRINT_EDITOR_CONTROL::NewFootprint(), FOOTPRINT_EDITOR_CONTROL::PasteFootprint(), SCH_BASE_FRAME::PickSymbolFromLibBrowser(), SYMBOL_EDITOR_CONTROL::PinLibrary(), FOOTPRINT_EDITOR_CONTROL::PinLibrary(), LIB_TREE_MODEL_ADAPTER::PinLibrary(), DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector(), DIALOG_SYMBOL_REMAP::remapSymbolsToLibTable(), DIALOG_SYMBOL_REMAP::remapSymbolToLibTable(), FOOTPRINT_EDITOR_CONTROL::RenameFootprint(), SYMBOL_EDITOR_CONTROL::RenameSymbol(), SCH_SYMBOL::ResolveTextVar(), FOOTPRINT::ResolveTextVar(), SYMBOL_EDIT_FRAME::Revert(), DRC_TEST_PROVIDER_LIBRARY_PARITY::Run(), SYMBOL_EDIT_FRAME::Save(), FOOTPRINT_EDITOR_CONTROL::SaveAs(), SYMBOL_EDIT_FRAME::saveCurrentSymbol(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), SYMBOL_EDIT_FRAME::SaveLibraryAs(), SYMBOL_EDIT_FRAME::saveSymbolAs(), SchGetLibSymbol(), setLibNickname(), LIB_TREE::setState(), SYMBOL_EDIT_FRAME::setupUIConditions(), DIALOG_CHOOSE_SYMBOL::ShowFootprintFor(), FOOTPRINT_VIEWER_FRAME::ShowModal(), SYMBOL_VIEWER_FRAME::ShowModal(), ERC_TESTER::TestLibSymbolIssues(), SYMBOL_EDITOR_CONTROL::UnpinLibrary(), FOOTPRINT_EDITOR_CONTROL::UnpinLibrary(), LIB_TREE_MODEL_ADAPTER::UnpinLibrary(), LIB_TREE_NODE_LIB_ID::Update(), PCB_CONTROL::UpdateMessagePanel(), FOOTPRINT_EDIT_FRAME::UpdateTitle(), and PANEL_FP_PROPERTIES_3D_MODEL::validateModelExists().

◆ GetSubLibraryName()

UTF8 LIB_ID::GetSubLibraryName ( ) const
inline

Some LIB_IDs can have a sub-library identifier in addition to a library nickname.

This identifier is not part of the canonical LIB_ID and is not written out / parsed. It is only used for internal sorting/grouping, if present.

Returns
the sub-library name for this LIB_ID, if one exists

Definition at line 129 of file lib_id.h.

129{ return m_subLibraryName; }

References m_subLibraryName.

◆ 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 141 of file lib_id.h.

142 {
143 return Format().wx_str();
144 }
UTF8 Format() const
Definition: lib_id.cpp:117
wxString wx_str() const
Definition: utf8.cpp:46

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

Referenced by CVPCB_ASSOCIATION_TOOL::CopyAssoc(), SCH_EDIT_FRAME::CreateArchiveLibrary(), CVPCB_ASSOCIATION_TOOL::CutAssoc(), FOOTPRINT::GetMsgPanelInfo(), and SYMBOL_CANDIDATE::GetStringLibId().

◆ 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 111 of file lib_id.h.

111{ return m_itemName.wx_str(); }

References m_itemName, and UTF8::wx_str().

Referenced by SCH_SCREEN::Append(), and SCH_EDIT_FRAME::CreateArchiveLibrary().

◆ 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 174 of file lib_id.cpp.

175{
176 int offset = 0;
177
178 for( auto& ch : aLibItemName )
179 {
180 if( !isLegalChar( ch ) )
181 return offset;
182 else
183 ++offset;
184 }
185
186 return -1;
187}

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 173 of file lib_id.h.

174 {
175 return m_libraryName.empty() && !m_itemName.empty();
176 }

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

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 207 of file lib_id.cpp.

208{
209 bool const space_allowed = true;
210 bool const illegal_filename_chars_allowed = false;
211
212 if( aUniChar < ' ' )
213 return false;
214
215 // This list of characters is also duplicated in validators.cpp and footprint.cpp
216 // TODO: Unify forbidden character lists - Warning, invalid filename characters are not the same
217 // as invalid LIB_ID characters. We will need to separate the FP filenames from FP names before this
218 // can be unified
219 switch( aUniChar )
220 {
221 case ':':
222 case '\t':
223 case '\n':
224 case '\r':
225 return false;
226
227 case '\\':
228 case '<':
229 case '>':
230 case '"':
231 return illegal_filename_chars_allowed;
232
233 case ' ':
234 return space_allowed;
235
236 default:
237 return true;
238 }
239}

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 254 of file lib_id.cpp.

255{
256 bool const space_allowed = true;
257
258 if( aUniChar < ' ' )
259 return false;
260
261 switch( aUniChar )
262 {
263 case '\\':
264 case ':':
265 return false;
266
267 case ' ':
268 return space_allowed;
269
270 default:
271 return true;
272 }
273}

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.

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 165 of file lib_id.h.

166 {
167 return !m_libraryName.empty() && !m_itemName.empty();
168 }

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(), SYMBOL_EDITOR_CONTROL::DuplicateSymbol(), FOOTPRINT_EDITOR_CONTROL::ExportFootprint(), FOOTPRINT_INFO_GENERATOR::GenerateHtml(), SYMBOL_EDIT_FRAME::getTargetSymbol(), DIALOG_CHOOSE_SYMBOL::OnComponentPreselected(), DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), DIALOG_CHOOSE_SYMBOL::OnComponentSelected(), DIALOG_CHOOSE_FOOTPRINT::OnComponentSelected(), CVPCB_MAINFRAME::OnSelectComponent(), CVPCB_MAINFRAME::onTextFilterChangedTimer(), SCH_BASE_FRAME::PickSymbolFromLibBrowser(), SCH_BASE_FRAME::PickSymbolFromLibTree(), SCH_DRAWING_TOOLS::PlaceSymbol(), 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_CHOOSE_SYMBOL::ShowFootprint(), FOOTPRINT_VIEWER_FRAME::ShowModal(), SYMBOL_VIEWER_FRAME::ShowModal(), LIB_TREE_MODEL_ADAPTER::ShowPreselect(), SYMBOL_EDIT_FRAME::SyncLibraries(), FOOTPRINT_EDIT_FRAME::SyncLibraryTree(), DIALOG_CHANGE_SYMBOLS::updateFieldsList(), and FOOTPRINT_EDIT_FRAME::UpdateTitle().

◆ operator!=()

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

Definition at line 203 of file lib_id.h.

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

◆ operator<()

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

Definition at line 200 of file lib_id.h.

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:159

References compare().

◆ operator==()

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

Definition at line 202 of file lib_id.h.

202{ return this->compare( aLibId ) == 0; }

References compare().

◆ operator>()

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

Definition at line 201 of file lib_id.h.

201{ return this->compare( aLibId ) > 0; }

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 50 of file lib_id.cpp.

51{
52 clear();
53
54 size_t partNdx;
55 int offset = -1;
56
57 //=====<library nickname>=============================
58 if( ( partNdx = aId.find( ':' ) ) != aId.npos )
59 {
60 offset = SetLibNickname( aId.substr( 0, partNdx ) );
61
62 if( offset > -1 )
63 return offset;
64
65 ++partNdx; // skip ':'
66 }
67 else
68 {
69 partNdx = 0;
70 }
71
72 //=====<item name>====================================
73 UTF8 fpname = aId.substr( partNdx );
74
75 // Be sure the item name is valid.
76 // Some chars can be found in legacy files converted files from other EDA tools.
77 if( aFix )
78 fpname = FixIllegalChars( fpname, false );
79 else
80 offset = HasIllegalChars( fpname );
81
82 if( offset > -1 )
83 return offset;
84
85 SetLibItemName( fpname );
86
87 return -1;
88}
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:109
static int HasIllegalChars(const UTF8 &aLibItemName)
Examine aLibItemName for invalid LIB_ID item name characters.
Definition: lib_id.cpp:174
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:98
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:190
void clear()
Clear the contents of the library nickname, library entry name.
Definition: lib_id.cpp:42
static constexpr std::string::size_type npos
Definition: utf8.h:151
std::string::size_type find(char c) const
Definition: utf8.h:105
std::string substr(size_t pos=0, size_t len=npos) const
Definition: utf8.h:178

References clear(), UTF8::find(), FixIllegalChars(), HasIllegalChars(), UTF8::npos, SetLibItemName(), SetLibNickname(), 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(), DIALOG_EXCHANGE_FOOTPRINTS::isMatch(), FOOTPRINT_VIEWER_FRAME::KiwayMailIn(), CMP_READER::Load(), LEGACY_PLUGIN::loadAllSections(), CADSTAR_PCB_ARCHIVE_LOADER::loadComponentLibrary(), FABMASTER::loadFootprints(), SCH_LEGACY_PLUGIN::loadSymbol(), SCH_DATABASE_PLUGIN::loadSymbolFromRow(), EAGLE_PLUGIN::makeFootprint(), DIALOG_EDIT_SYMBOLS_LIBID::onClickOrphansButton(), KICAD_NETLIST_PARSER::parseComponent(), PCB_PARSER::parseFOOTPRINT_unchecked(), SCH_SEXPR_PARSER::parseSchematicSymbol(), SCH_SEXPR_PARSER::ParseSymbol(), CVPCB_ASSOCIATION_TOOL::PasteAssoc(), DIALOG_EXCHANGE_FOOTPRINTS::processMatchingFootprints(), DIALOG_CHANGE_SYMBOLS::processMatchingSymbols(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), FOOTPRINT::SetFPIDAsString(), DIALOG_EDIT_SYMBOLS_LIBID::setLibIdByBrowser(), DIALOG_CHOOSE_SYMBOL::ShowFootprint(), FOOTPRINT_VIEWER_FRAME::ShowModal(), SYMBOL_VIEWER_FRAME::ShowModal(), DIALOG_EDIT_SYMBOLS_LIBID::TransferDataFromWindow(), DIALOG_CHANGE_SYMBOLS::updateFieldsList(), and DIALOG_EDIT_SYMBOLS_LIBID::validateLibIds().

◆ SetLibItemName()

int LIB_ID::SetLibItemName ( const UTF8 aLibItemName)

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 109 of file lib_id.cpp.

110{
111 m_itemName = aLibItemName;
112
113 return -1;
114}

References m_itemName.

Referenced by BOOST_AUTO_TEST_CASE(), LIB_TREE_NODE_LIB_ID::LIB_TREE_NODE_LIB_ID(), LEGACY_NETLIST_READER::loadComponent(), SCH_LEGACY_PLUGIN::loadSymbol(), Parse(), RESCUE_CASE_CANDIDATE::PerformAction(), RESCUE_CACHE_CANDIDATE::PerformAction(), LIB_SYMBOL::SetName(), SYMBOL_EDIT_FRAME::SyncLibraries(), FOOTPRINT_EDIT_FRAME::SyncLibraryTree(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow(), RESCUER::UndoRescues(), and LIB_TREE_NODE_LIB_ID::Update().

◆ SetLibNickname()

int LIB_ID::SetLibNickname ( const UTF8 aNickname)

◆ SetSubLibraryName()

void LIB_ID::SetSubLibraryName ( const UTF8 aName)
inline

Definition at line 130 of file lib_id.h.

130{ m_subLibraryName = aName; }

References m_subLibraryName.

Referenced by SCH_DATABASE_PLUGIN::loadSymbolFromRow().

Member Data Documentation

◆ m_itemName

UTF8 LIB_ID::m_itemName
protected

The name of the entry in the logical library.

Definition at line 265 of file lib_id.h.

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

◆ m_libraryName

UTF8 LIB_ID::m_libraryName
protected

The nickname of the library or empty.

Definition at line 264 of file lib_id.h.

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

◆ m_subLibraryName

UTF8 LIB_ID::m_subLibraryName
protected

Optional sub-library name used for grouping within a library.

Definition at line 266 of file lib_id.h.

Referenced by clear(), GetSubLibraryName(), and SetSubLibraryName().


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