Unify LIB_IDs now that both are stored in sexpr files.

Fixes https://gitlab.com/kicad/code/kicad/issues/6764
This commit is contained in:
Jeff Young 2020-12-17 23:32:23 +00:00
parent c4117c1ecf
commit bb232e6ac6
42 changed files with 177 additions and 207 deletions

View File

@ -62,7 +62,7 @@ FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aFootprintName
LIB_ID fpid; LIB_ID fpid;
wxCHECK_MSG( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) < 0, NULL, wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, NULL,
wxString::Format( wxT( "\"%s\" is not a valid LIB_ID." ), aFootprintName ) ); wxString::Format( wxT( "\"%s\" is not a valid LIB_ID." ), aFootprintName ) );
return GetFootprintInfo( fpid.GetLibNickname(), fpid.GetLibItemName() ); return GetFootprintInfo( fpid.GetLibNickname(), fpid.GetLibItemName() );

View File

@ -113,13 +113,13 @@ static int okRevision( const UTF8& aField )
void LIB_ID::clear() void LIB_ID::clear()
{ {
nickname.clear(); m_libraryName.clear();
item_name.clear(); m_itemName.clear();
revision.clear(); m_revision.clear();
} }
int LIB_ID::Parse( const UTF8& aId, LIB_ID_TYPE aType, bool aFix ) int LIB_ID::Parse( const UTF8& aId, bool aFix )
{ {
clear(); clear();
@ -129,14 +129,14 @@ int LIB_ID::Parse( const UTF8& aId, LIB_ID_TYPE aType, bool aFix )
size_t partNdx; size_t partNdx;
int offset = -1; int offset = -1;
//=====<revision>========================================= //=====<revision>=====================================
// in a LIB_ID like discret:R3/rev4 // in a LIB_ID like discret:R3/rev4
if( rev ) if( rev )
{ {
revNdx = rev - buffer; revNdx = rev - buffer;
// no need to check revision, EndsWithRev did that. // no need to check revision, EndsWithRev did that.
revision = aId.substr( revNdx ); m_revision = aId.substr( revNdx );
--revNdx; // back up to omit the '/' which precedes the rev --revNdx; // back up to omit the '/' which precedes the rev
} }
else else
@ -144,7 +144,7 @@ int LIB_ID::Parse( const UTF8& aId, LIB_ID_TYPE aType, bool aFix )
revNdx = aId.size(); revNdx = aId.size();
} }
//=====<nickname>========================================== //=====<name>=========================================
if( ( partNdx = aId.find( ':' ) ) != aId.npos ) if( ( partNdx = aId.find( ':' ) ) != aId.npos )
{ {
offset = SetLibNickname( aId.substr( 0, partNdx ) ); offset = SetLibNickname( aId.substr( 0, partNdx ) );
@ -168,9 +168,9 @@ int LIB_ID::Parse( const UTF8& aId, LIB_ID_TYPE aType, bool aFix )
// Be sure the item name is valid. // Be sure the item name is valid.
// Some chars can be found in legacy files converted files from other EDA tools. // Some chars can be found in legacy files converted files from other EDA tools.
if( aFix ) if( aFix )
fpname = FixIllegalChars( fpname, aType, false ); fpname = FixIllegalChars( fpname, false );
else else
offset = HasIllegalChars( fpname, aType ); offset = HasIllegalChars( fpname );
if( offset > -1 ) if( offset > -1 )
return offset; return offset;
@ -181,11 +181,11 @@ int LIB_ID::Parse( const UTF8& aId, LIB_ID_TYPE aType, bool aFix )
} }
LIB_ID::LIB_ID( const wxString& aLibName, const wxString& aLibItemName, LIB_ID::LIB_ID( const wxString& aLibraryName, const wxString& aItemName,
const wxString& aRevision ) : const wxString& aRevision ) :
nickname( aLibName ), m_libraryName( aLibraryName ),
item_name( aLibItemName ), m_itemName( aItemName ),
revision( aRevision ) m_revision( aRevision )
{ {
} }
@ -195,9 +195,7 @@ int LIB_ID::SetLibNickname( const UTF8& aLogical )
int offset = okLogical( aLogical ); int offset = okLogical( aLogical );
if( offset == -1 ) if( offset == -1 )
{ m_libraryName = aLogical;
nickname = aLogical;
}
return offset; return offset;
} }
@ -209,12 +207,12 @@ int LIB_ID::SetLibItemName( const UTF8& aLibItemName, bool aTestForRev )
if( aTestForRev && separation != -1 ) if( aTestForRev && separation != -1 )
{ {
item_name = aLibItemName.substr( 0, separation-1 ); m_itemName = aLibItemName.substr( 0, separation-1 );
return separation; return separation;
} }
else else
{ {
item_name = aLibItemName; m_itemName = aLibItemName;
} }
return -1; return -1;
@ -226,9 +224,7 @@ int LIB_ID::SetRevision( const UTF8& aRevision )
int offset = okRevision( aRevision ); int offset = okRevision( aRevision );
if( offset == -1 ) if( offset == -1 )
{ m_revision = aRevision;
revision = aRevision;
}
return offset; return offset;
} }
@ -238,18 +234,18 @@ UTF8 LIB_ID::Format() const
{ {
UTF8 ret; UTF8 ret;
if( nickname.size() ) if( m_libraryName.size() )
{ {
ret += nickname; ret += m_libraryName;
ret += ':'; ret += ':';
} }
ret += item_name; ret += m_itemName;
if( revision.size() ) if( m_revision.size() )
{ {
ret += '/'; ret += '/';
ret += revision; ret += m_revision;
} }
return ret; return ret;
@ -258,35 +254,34 @@ UTF8 LIB_ID::Format() const
UTF8 LIB_ID::GetLibItemNameAndRev() const UTF8 LIB_ID::GetLibItemNameAndRev() const
{ {
UTF8 ret = item_name; UTF8 ret = m_itemName;
if( revision.size() ) if( m_revision.size() )
{ {
ret += '/'; ret += '/';
ret += revision; ret += m_revision;
} }
return ret; return ret;
} }
UTF8 LIB_ID::Format( const UTF8& aLogicalLib, const UTF8& aLibItemName, const UTF8& aRevision ) UTF8 LIB_ID::Format( const UTF8& aLibraryName, const UTF8& aLibItemName, const UTF8& aRevision )
{ {
UTF8 ret; UTF8 ret;
int offset; int offset;
if( aLogicalLib.size() ) if( aLibraryName.size() )
{ {
offset = okLogical( aLogicalLib ); offset = okLogical( aLibraryName );
if( offset != -1 ) if( offset != -1 )
{ {
THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ), THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ),
wxString::FromUTF8( aLogicalLib.c_str() ), wxString::FromUTF8( aLibraryName.c_str() ), aLibraryName.c_str(), 0, offset );
aLogicalLib.c_str(), 0, offset );
} }
ret += aLogicalLib; ret += aLibraryName;
ret += ':'; ret += ':';
} }
@ -319,27 +314,27 @@ int LIB_ID::compare( const LIB_ID& aLibId ) const
if( this == &aLibId ) if( this == &aLibId )
return 0; return 0;
int retv = nickname.compare( aLibId.nickname ); int retv = m_libraryName.compare( aLibId.m_libraryName );
if( retv != 0 ) if( retv != 0 )
return retv; return retv;
retv = item_name.compare( aLibId.item_name ); retv = m_itemName.compare( aLibId.m_itemName );
if( retv != 0 ) if( retv != 0 )
return retv; return retv;
return revision.compare( aLibId.revision ); return m_revision.compare( aLibId.m_revision );
} }
int LIB_ID::HasIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType ) int LIB_ID::HasIllegalChars( const UTF8& aLibItemName )
{ {
int offset = 0; int offset = 0;
for( auto ch : aLibItemName ) for( auto ch : aLibItemName )
{ {
if( !isLegalChar( ch, aType ) ) if( !isLegalChar( ch ) )
return offset; return offset;
else else
++offset; ++offset;
@ -349,7 +344,7 @@ int LIB_ID::HasIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType )
} }
UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType, bool aLib ) UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, bool aLib )
{ {
UTF8 fixedName; UTF8 fixedName;
@ -357,19 +352,19 @@ UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType, bool
{ {
auto ch = *chIt; auto ch = *chIt;
if( aLib ) if( aLib )
fixedName += isLegalLibNicknameChar( ch, aType ) ? ch : '_'; fixedName += isLegalLibraryNameChar( ch ) ? ch : '_';
else else
fixedName += isLegalChar( ch, aType ) ? ch : '_'; fixedName += isLegalChar( ch ) ? ch : '_';
} }
return fixedName; return fixedName;
} }
bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType ) bool LIB_ID::isLegalChar( unsigned aUniChar )
{ {
bool const space_allowed = ( aType == ID_PCB ); bool const space_allowed = true;
bool const illegal_filename_chars_allowed = ( aType == ID_SCH ); bool const illegal_filename_chars_allowed = false;
if( aUniChar < ' ' ) if( aUniChar < ' ' )
return false; return false;
@ -400,11 +395,11 @@ bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType )
} }
unsigned LIB_ID::FindIllegalLibNicknameChar( const UTF8& aNickname, LIB_ID_TYPE aType ) unsigned LIB_ID::FindIllegalLibraryNameChar( const UTF8& aLibraryName )
{ {
for( unsigned ch : aNickname ) for( unsigned ch : aLibraryName )
{ {
if( !isLegalLibNicknameChar( ch, aType ) ) if( !isLegalLibraryNameChar( ch ) )
return ch; return ch;
} }
@ -412,9 +407,9 @@ unsigned LIB_ID::FindIllegalLibNicknameChar( const UTF8& aNickname, LIB_ID_TYPE
} }
bool LIB_ID::isLegalLibNicknameChar( unsigned aUniChar, LIB_ID_TYPE aType ) bool LIB_ID::isLegalLibraryNameChar( unsigned aUniChar )
{ {
bool const space_allowed = ( aType != ID_SCH ); bool const space_allowed = true;
if( aUniChar < ' ' ) if( aUniChar < ' ' )
return false; return false;
@ -453,7 +448,7 @@ void LIB_ID::Test()
LIB_ID lpid( lpids[i] ); // parse LIB_ID lpid( lpids[i] ); // parse
// format // format
printf( "input:'%s' full:'%s' nickname: %s item_name:'%s' rev:'%s'\n", printf( "input:'%s' full:'%s' nickname: %s m_itemName:'%s' rev:'%s'\n",
lpids[i], lpids[i],
lpid.Format().c_str(), lpid.Format().c_str(),
lpid.GetLibNickname().c_str(), lpid.GetLibNickname().c_str(),

View File

@ -25,16 +25,12 @@
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/uri.h>
#include <set> #include <set>
#include <common.h> #include <common.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <lib_table_base.h> #include <lib_table_base.h>
#include <lib_table_lexer.h> #include <lib_table_lexer.h>
#include <macros.h> #include <macros.h>
#include <settings/app_settings.h>
#define OPT_SEP '|' ///< options separator character #define OPT_SEP '|' ///< options separator character
@ -195,33 +191,21 @@ LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName ) const
{ {
cur->ensureIndex(); cur->ensureIndex();
INDEX_CITER it = cur->nickIndex.find( aNickName ); for( const std::pair<const wxString, int>& entry : cur->nickIndex )
if( it != cur->nickIndex.end() )
{ {
return &cur->rows[it->second]; // found if( entry.first == aNickName )
return &cur->rows[entry.second ];
} }
// not found, search fall back table(s), if any // Repeat, this time looking for names that were "fixed" by legacy versions because
} while( ( cur = cur->fallBack ) != 0 ); // the old eeschema file format didn't support spaces in tokens.
for( const std::pair<const wxString, int>& entry : cur->nickIndex )
return nullptr; // not found
}
LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName )
{
LIB_TABLE* cur = (LIB_TABLE*) this;
do
{
cur->ensureIndex();
INDEX_ITER it = cur->nickIndex.find( aNickName );
if( it != cur->nickIndex.end() )
{ {
return &cur->rows[it->second]; // found wxString legacyLibName = entry.first;
legacyLibName.Replace( " ", "_" );
if( legacyLibName == aNickName )
return &cur->rows[entry.second ];
} }
// not found, search fall back table(s), if any // not found, search fall back table(s), if any

View File

@ -29,7 +29,7 @@
#include <lib_id.h> #include <lib_id.h>
LIB_ID AltiumToKiCadLibID( LIB_ID::LIB_ID_TYPE aType, wxString aLibName, wxString aLibReference ) LIB_ID AltiumToKiCadLibID( wxString aLibName, wxString aLibReference )
{ {
ReplaceIllegalFileNameChars( aLibName, '_' ); ReplaceIllegalFileNameChars( aLibName, '_' );
ReplaceIllegalFileNameChars( aLibReference, '_' ); ReplaceIllegalFileNameChars( aLibReference, '_' );
@ -37,7 +37,7 @@ LIB_ID AltiumToKiCadLibID( LIB_ID::LIB_ID_TYPE aType, wxString aLibName, wxStrin
wxString key = !aLibName.empty() ? ( aLibName + ":" + aLibReference ) : aLibReference; wxString key = !aLibName.empty() ? ( aLibName + ":" + aLibReference ) : aLibReference;
LIB_ID libId; LIB_ID libId;
libId.Parse( key, aType, true ); libId.Parse( key, true );
return libId; return libId;
} }

View File

@ -297,7 +297,7 @@ bool LIB_ID_VALIDATOR::Validate( wxWindow *aParent )
{ {
msg = _( "Entry contains leading white space." ); msg = _( "Entry contains leading white space." );
} }
else if( dummy.Parse( val, m_idType ) != -1 || !dummy.IsValid() ) // Is valid LIB_ID. else if( dummy.Parse( val ) != -1 || !dummy.IsValid() ) // Is valid LIB_ID.
{ {
msg.Printf( _( "\"%s\" is not a valid library identifier format." ), val ); msg.Printf( _( "\"%s\" is not a valid library identifier format." ), val );
} }

View File

@ -51,8 +51,8 @@ public:
unsigned int aComponentIndex, wxString aNewFootprint, wxString aOldFootprint = "" ) : unsigned int aComponentIndex, wxString aNewFootprint, wxString aOldFootprint = "" ) :
m_componentIndex( aComponentIndex ) m_componentIndex( aComponentIndex )
{ {
m_newFootprint.Parse( aNewFootprint, LIB_ID::ID_PCB ); m_newFootprint.Parse( aNewFootprint );
m_oldFootprint.Parse( aOldFootprint, LIB_ID::ID_PCB ); m_oldFootprint.Parse( aOldFootprint );
} }
/** /**

View File

@ -374,7 +374,7 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam
FOOTPRINT* footprint = NULL; FOOTPRINT* footprint = NULL;
LIB_ID fpid; LIB_ID fpid;
if( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) >= 0 ) if( fpid.Parse( aFootprintName ) >= 0 )
{ {
aReporter.Report( wxString::Format( _( "Footprint ID \"%s\" is not valid." ), aReporter.Report( wxString::Format( _( "Footprint ID \"%s\" is not valid." ),
aFootprintName ), aFootprintName ),

View File

@ -61,7 +61,7 @@ int CVPCB_ASSOCIATION_TOOL::CopyAssoc( const TOOL_EVENT& aEvent )
switch( copyControl ) switch( copyControl )
{ {
case CVPCB_MAINFRAME::CONTROL_FOOTPRINT: case CVPCB_MAINFRAME::CONTROL_FOOTPRINT:
fpid.Parse( m_frame->GetSelectedFootprint(), LIB_ID::ID_PCB ); fpid.Parse( m_frame->GetSelectedFootprint() );
break; break;
case CVPCB_MAINFRAME::CONTROL_COMPONENT: case CVPCB_MAINFRAME::CONTROL_COMPONENT:
@ -163,7 +163,7 @@ int CVPCB_ASSOCIATION_TOOL::PasteAssoc( const TOOL_EVENT& aEvent )
return 0; return 0;
} }
if( fpid.Parse( data.GetText(), LIB_ID::ID_PCB ) >= 0 ) if( fpid.Parse( data.GetText() ) >= 0 )
return 0; return 0;
// Assign the fpid to the selections // Assign the fpid to the selections
@ -205,7 +205,7 @@ int CVPCB_ASSOCIATION_TOOL::Associate( const TOOL_EVENT& aEvent )
// Get the currently selected footprint // Get the currently selected footprint
LIB_ID fpid; LIB_ID fpid;
wxString fp = m_frame->GetSelectedFootprint(); wxString fp = m_frame->GetSelectedFootprint();
fpid.Parse( fp, LIB_ID::ID_PCB ); fpid.Parse( fp );
// Ignore the action if the footprint is empty (nothing selected) // Ignore the action if the footprint is empty (nothing selected)
if( fpid.empty() ) if( fpid.empty() )

View File

@ -309,7 +309,7 @@ wxString LIB_PART::GetUnitReference( int aUnit )
void LIB_PART::SetName( const wxString& aName ) void LIB_PART::SetName( const wxString& aName )
{ {
wxString validatedName = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH ); wxString validatedName = LIB_ID::FixIllegalChars( aName );
m_name = validatedName; m_name = validatedName;
m_libId.SetLibItemName( validatedName, false ); m_libId.SetLibItemName( validatedName, false );

View File

@ -286,7 +286,7 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList()
{ {
LIB_ID newId; LIB_ID newId;
newId.Parse( m_newId->GetValue(), LIB_ID::ID_SCH ); newId.Parse( m_newId->GetValue() );
if( newId.IsValid() ) if( newId.IsValid() )
{ {
@ -384,7 +384,7 @@ bool DIALOG_CHANGE_SYMBOLS::isMatch( SCH_COMPONENT* aSymbol, SCH_SHEET_PATH* aIn
} }
else if( m_matchById ) else if( m_matchById )
{ {
id.Parse( m_specifiedId->GetValue(), LIB_ID::ID_SCH ); id.Parse( m_specifiedId->GetValue() );
return aSymbol->GetLibId() == id; return aSymbol->GetLibId() == id;
} }
@ -405,7 +405,7 @@ bool DIALOG_CHANGE_SYMBOLS::processMatchingSymbols()
if( m_mode == MODE::CHANGE ) if( m_mode == MODE::CHANGE )
{ {
newId.Parse( m_newId->GetValue(), LIB_ID::ID_SCH ); newId.Parse( m_newId->GetValue() );
if( !newId.IsValid() ) if( !newId.IsValid() )
return false; return false;

View File

@ -426,7 +426,7 @@ void DIALOG_CHOOSE_SYMBOL::ShowFootprint( wxString const& aName )
{ {
LIB_ID lib_id; LIB_ID lib_id;
if( lib_id.Parse( aName, LIB_ID::ID_PCB ) == -1 && lib_id.IsValid() ) if( lib_id.Parse( aName ) == -1 && lib_id.IsValid() )
{ {
m_fp_preview->ClearStatus(); m_fp_preview->ClearStatus();
m_fp_preview->CacheFootprint( lib_id ); m_fp_preview->CacheFootprint( lib_id );

View File

@ -541,7 +541,7 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::validateLibIds()
// a new lib id is found. validate this new value // a new lib id is found. validate this new value
LIB_ID id; LIB_ID id;
id.Parse( new_libid, LIB_ID::ID_SCH ); id.Parse( new_libid );
if( !id.IsValid() ) if( !id.IsValid() )
{ {
@ -589,7 +589,7 @@ void DIALOG_EDIT_COMPONENTS_LIBID::onClickOrphansButton( wxCommandEvent& event )
int grid_row_idx = orphanRow; //row index in m_grid for the current item int grid_row_idx = orphanRow; //row index in m_grid for the current item
LIB_ID curr_libid; LIB_ID curr_libid;
curr_libid.Parse( orphanLibid, LIB_ID::ID_SCH, true ); curr_libid.Parse( orphanLibid, true );
wxString symbName = curr_libid.GetLibItemName(); wxString symbName = curr_libid.GetLibItemName();
// number of full LIB_ID candidates (because we search for a symbol name // number of full LIB_ID candidates (because we search for a symbol name
// inside all avaiable libraries, perhaps the same symbol name can be found // inside all avaiable libraries, perhaps the same symbol name can be found
@ -674,17 +674,16 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow )
0, 0, false ); 0, 0, false );
#else #else
// Use library viewer to choose a symbol // Use library viewer to choose a symbol
LIB_ID aPreselectedLibid; LIB_ID preselected;
wxString current = m_grid->GetCellValue( aRow, COL_NEW_LIBID ); wxString current = m_grid->GetCellValue( aRow, COL_NEW_LIBID );
if( current.IsEmpty() ) if( current.IsEmpty() )
current = m_grid->GetCellValue( aRow, COL_CURR_LIBID ); current = m_grid->GetCellValue( aRow, COL_CURR_LIBID );
if( !current.IsEmpty() ) if( !current.IsEmpty() )
aPreselectedLibid.Parse( current, LIB_ID::ID_SCH, true ); preselected.Parse( current, true );
PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibBrowser( this, NULL, aPreselectedLibid, PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibBrowser( this, NULL, preselected, 0, 0 );
0, 0 );
#endif #endif
if( sel.LibId.empty() ) // command aborted if( sel.LibId.empty() ) // command aborted
@ -721,7 +720,7 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::TransferDataFromWindow()
// A new lib id is found and was already validated. // A new lib id is found and was already validated.
LIB_ID id; LIB_ID id;
id.Parse( new_libid, LIB_ID::ID_SCH, true ); id.Parse( new_libid, true );
for( CMP_CANDIDATE& cmp : m_components ) for( CMP_CANDIDATE& cmp : m_components )
{ {

View File

@ -329,7 +329,7 @@ bool PANEL_SYM_LIB_TABLE::verifyTables()
// button. // button.
model->DeleteRows( r, 1 ); model->DeleteRows( r, 1 );
} }
else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_SCH ) ) ) else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
{ {
wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ), wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ),
illegalCh, illegalCh,
@ -470,7 +470,7 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
{ {
wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file; wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file;
wxFileName fn( filePath ); wxFileName fn( filePath );
wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_SCH ); wxString nickname = LIB_ID::FixIllegalChars( fn.GetName() );
bool doAdd = true; bool doAdd = true;
if( cur_model()->ContainsNickname( nickname ) ) if( cur_model()->ContainsNickname( nickname ) )

View File

@ -56,7 +56,7 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a
m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ), m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ),
m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), REFERENCE_FIELD ), m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), REFERENCE_FIELD ),
m_valueValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), VALUE_FIELD ), m_valueValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), VALUE_FIELD ),
m_libIdValidator( LIB_ID::ID_PCB ), m_libIdValidator(),
m_urlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ), m_urlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ), m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME ) m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME )
@ -76,7 +76,7 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a
m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ), m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ),
m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETNAME_V ), m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETNAME_V ),
m_valueValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), VALUE_FIELD ), m_valueValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), VALUE_FIELD ),
m_libIdValidator( LIB_ID::ID_PCB ), m_libIdValidator(),
m_urlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ), m_urlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ), m_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ),
m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME_V ) m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME_V )

View File

@ -970,7 +970,7 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType )
if( !fpField->GetText().IsEmpty() ) if( !fpField->GetText().IsEmpty() )
{ {
LIB_ID fpId; LIB_ID fpId;
fpId.Parse( fpField->GetText(), LIB_ID::ID_SCH, true ); fpId.Parse( fpField->GetText(), true );
fpId.SetLibNickname( newfilename.GetName() ); fpId.SetLibNickname( newfilename.GetName() );
fpField->SetText( fpId.Format() ); fpField->SetText( fpId.Format() );
} }

View File

@ -73,7 +73,7 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibBrowser( wxTopLevelWindow* aParen
{ {
LIB_ID id; LIB_ID id;
if( id.Parse( symbol, LIB_ID::ID_SCH ) == -1 ) if( id.Parse( symbol ) == -1 )
sel.LibId = id; sel.LibId = id;
sel.Unit = viewlibFrame->GetUnit(); sel.Unit = viewlibFrame->GetUnit();

View File

@ -373,24 +373,24 @@ bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent )
LIB_TABLE* libTable = Prj().SchSymbolLibTable(); LIB_TABLE* libTable = Prj().SchSymbolLibTable();
LIB_ID libid; LIB_ID libid;
libid.Parse( *aSymbol, LIB_ID::ID_SCH, true ); libid.Parse( *aSymbol, true );
if( libid.IsValid() ) if( libid.IsValid() )
{ {
wxString nickname = libid.GetLibNickname(); wxString libName = libid.GetLibNickname();
if( !libTable->HasLibrary( libid.GetLibNickname(), false ) ) if( !libTable->HasLibrary( libid.GetLibNickname(), false ) )
{ {
msg.sprintf( _( "The current configuration does not include a library with the\n" msg.Printf( _( "The current configuration does not include the library '%s'.\n"
"nickname \"%s\". Use Manage Symbol Libraries\n" "Use Manage Symbol Libraries to edit the configuration." ),
"to edit the configuration." ), nickname ); libName );
DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg ); DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
} }
else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) ) else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) )
{ {
msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n" msg.Printf( _( "The library '%s' is not enabled in the current configuration.\n"
"in the current configuration. Use Manage Symbol Libraries to\n" "Use Manage Symbol Libraries to edit the configuration." ),
"edit the configuration." ), nickname ); libName );
DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg ); DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg );
} }
else else

View File

@ -89,7 +89,7 @@ static void get_components( SCHEMATIC* aSchematic, std::vector<SCH_COMPONENT*>&
static LIB_PART* find_component( const wxString& aName, PART_LIBS* aLibs, bool aCached ) static LIB_PART* find_component( const wxString& aName, PART_LIBS* aLibs, bool aCached )
{ {
LIB_PART *part = NULL; LIB_PART *part = NULL;
wxString new_name = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH ); wxString new_name = LIB_ID::FixIllegalChars( aName );
for( PART_LIB& each_lib : *aLibs ) for( PART_LIB& each_lib : *aLibs )
{ {
@ -149,7 +149,7 @@ void RESCUE_CASE_CANDIDATE::FindRescues( RESCUER& aRescuer,
for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) ) for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
{ {
part_name = each_component->GetLibId().GetLibItemName(); part_name = each_component->GetLibId().GetLibItemName();
search_name = LIB_ID::FixIllegalChars( part_name, LIB_ID::ID_SCH ); search_name = LIB_ID::FixIllegalChars( part_name );
if( last_part_name != part_name ) if( last_part_name != part_name )
{ {
@ -254,7 +254,7 @@ void RESCUE_CACHE_CANDIDATE::FindRescues( RESCUER& aRescuer,
for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) ) for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) )
{ {
part_name = each_component->GetLibId().GetLibItemName(); part_name = each_component->GetLibId().GetLibItemName();
search_name = LIB_ID::FixIllegalChars( part_name, LIB_ID::ID_SCH ); search_name = LIB_ID::FixIllegalChars( part_name );
if( old_part_name != part_name ) if( old_part_name != part_name )
{ {
@ -416,7 +416,7 @@ void RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(
} }
// Test whether there is a conflict or if the symbol can only be found in the cache. // Test whether there is a conflict or if the symbol can only be found in the cache.
if( LIB_ID::HasIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH ) == -1 ) if( LIB_ID::HasIllegalChars( part_id.GetLibItemName() ) == -1 )
{ {
if( cache_match && lib_match && if( cache_match && lib_match &&
!cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) ) !cache_match->PinsConflictWith( *lib_match, true, true, true, true, false ) )
@ -427,7 +427,7 @@ void RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(
} }
// Fix illegal LIB_ID name characters. // Fix illegal LIB_ID name characters.
wxString new_name = LIB_ID::FixIllegalChars( part_id.GetLibItemName(), LIB_ID::ID_SCH ); wxString new_name = LIB_ID::FixIllegalChars( part_id.GetLibItemName() );
// Differentiate symbol name in the rescue library by appending the symbol library // Differentiate symbol name in the rescue library by appending the symbol library
// table nickname to the symbol name to prevent name clashes in the rescue library. // table nickname to the symbol name to prevent name clashes in the rescue library.

View File

@ -136,7 +136,7 @@ wxString SCH_ALTIUM_PLUGIN::getLibName()
m_libName = "noname"; m_libName = "noname";
m_libName += "-altium-import"; m_libName += "-altium-import";
m_libName = LIB_ID::FixIllegalChars( m_libName, LIB_ID::ID_SCH, true ); m_libName = LIB_ID::FixIllegalChars( m_libName, true );
} }
return m_libName; return m_libName;
@ -495,7 +495,7 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int aIndex,
elem.orientation, elem.orientation,
elem.isMirrored ? "_mirrored" : "", elem.isMirrored ? "_mirrored" : "",
elem.libreference ); elem.libreference );
LIB_ID libId = AltiumToKiCadLibID( LIB_ID::ID_SCH, getLibName(), name ); LIB_ID libId = AltiumToKiCadLibID( getLibName(), name );
LIB_PART* kpart = new LIB_PART( wxEmptyString ); LIB_PART* kpart = new LIB_PART( wxEmptyString );
kpart->SetName( name ); kpart->SetName( name );
@ -1555,7 +1555,7 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map<wxString, wxString>& aPro
{ {
ASCH_POWER_PORT elem( aProperties ); ASCH_POWER_PORT elem( aProperties );
LIB_ID libId = AltiumToKiCadLibID( LIB_ID::ID_SCH, getLibName(), elem.text ); LIB_ID libId = AltiumToKiCadLibID( getLibName(), elem.text );
LIB_PART* kpart = nullptr; LIB_PART* kpart = nullptr;

View File

@ -377,7 +377,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
//KiCad requires parts to be named the same as the net: //KiCad requires parts to be named the same as the net:
wxString partName = sym.SymbolVariant.Reference; wxString partName = sym.SymbolVariant.Reference;
partName = LIB_ID::FixIllegalChars( partName, LIB_ID::ID_SCH ); partName = LIB_ID::FixIllegalChars( partName );
if( mPowerSymLibMap.find( symID ) == mPowerSymLibMap.end() if( mPowerSymLibMap.find( symID ) == mPowerSymLibMap.end()
|| mPowerSymLibMap.at( symID )->GetName() != partName ) || mPowerSymLibMap.at( symID )->GetName() != partName )

View File

@ -102,7 +102,7 @@ SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::Load( const wxString& aFileName, SCHEMATI
libName = "noname"; libName = "noname";
libName += "-cadstar-import"; libName += "-cadstar-import";
libName = LIB_ID::FixIllegalChars( libName, LIB_ID::ID_SCH, true ); libName = LIB_ID::FixIllegalChars( libName, true );
wxFileName libFileName( wxFileName libFileName(
aSchematic->Prj().GetProjectPath(), libName, KiCadSymbolLibFileExtension ); aSchematic->Prj().GetProjectPath(), libName, KiCadSymbolLibFileExtension );

View File

@ -149,7 +149,7 @@ wxString SCH_EAGLE_PLUGIN::getLibName()
m_libName = "noname"; m_libName = "noname";
m_libName += "-eagle-import"; m_libName += "-eagle-import";
m_libName = LIB_ID::FixIllegalChars( m_libName, LIB_ID::ID_SCH, true ); m_libName = LIB_ID::FixIllegalChars( m_libName, true );
} }
return m_libName; return m_libName;
@ -2605,7 +2605,7 @@ void SCH_EAGLE_PLUGIN::addImplicitConnections(
wxString SCH_EAGLE_PLUGIN::fixSymbolName( const wxString& aName ) wxString SCH_EAGLE_PLUGIN::fixSymbolName( const wxString& aName )
{ {
wxString ret = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH ); wxString ret = LIB_ID::FixIllegalChars( aName );
return ret; return ret;
} }

View File

@ -149,7 +149,7 @@ LIB_PART* SCH_SEXPR_PARSER::ParseSymbol( LIB_PART_MAP& aSymbolLibMap, int aFileV
LIB_ID id; LIB_ID id;
if( id.Parse( name, LIB_ID::ID_SCH ) >= 0 ) if( id.Parse( name ) >= 0 )
{ {
error.Printf( _( "Invalid library identifier in\nfile: \"%s\"\nline: %d\noffset: %d" ), error.Printf( _( "Invalid library identifier in\nfile: \"%s\"\nline: %d\noffset: %d" ),
CurSource().c_str(), CurLineNumber(), CurOffset() ); CurSource().c_str(), CurLineNumber(), CurOffset() );
@ -2162,7 +2162,7 @@ SCH_COMPONENT* SCH_SEXPR_PARSER::parseSchematicSymbol()
LIB_ID libId; LIB_ID libId;
if( libId.Parse( FromUTF8(), LIB_ID::ID_SCH ) >= 0 ) if( libId.Parse( FromUTF8() ) >= 0 )
{ {
error.Printf( _( "Invalid symbol library ID in\nfile: \"%s\"\nline: %d\n" error.Printf( _( "Invalid symbol library ID in\nfile: \"%s\"\nline: %d\n"
"offset: %d" ), "offset: %d" ),

View File

@ -1529,7 +1529,7 @@ void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFo
LIB_ID unitId; LIB_ID unitId;
wxCHECK2( unitId.Parse( aLibName, LIB_ID::ID_SCH ) < 0, /* do nothing */ ); wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ );
unitName = unitId.GetLibItemName(); unitName = unitId.GetLibItemName();
} }

View File

@ -1510,7 +1510,7 @@ SCH_COMPONENT* SCH_LEGACY_PLUGIN::loadComponent( LINE_READER& aReader )
// parsing the symbol name with LIB_ID::Parse() would break symbol library links // parsing the symbol name with LIB_ID::Parse() would break symbol library links
// that contained '/' and ':' characters. // that contained '/' and ':' characters.
if( m_version > 3 ) if( m_version > 3 )
libId.Parse( libName, LIB_ID::ID_SCH, true ); libId.Parse( libName, true );
else else
libId.SetLibItemName( libName, false ); libId.SetLibItemName( libName, false );
@ -2687,7 +2687,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadDocs()
aliasName = wxString::FromUTF8( line ); aliasName = wxString::FromUTF8( line );
aliasName.Trim(); aliasName.Trim();
aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_SCH ); aliasName = LIB_ID::FixIllegalChars( aliasName );
LIB_PART_MAP::iterator it = m_symbols.find( aliasName ); LIB_PART_MAP::iterator it = m_symbols.find( aliasName );

View File

@ -1160,8 +1160,8 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
if( !libTableRow ) if( !libTableRow )
{ {
msg.Printf( _( "The current configuration does not include the symbol library\n" msg.Printf( _( "The current configuration does not include the library '%s'.\n"
"\"%s\".\nUse Manage Symbol Libraries to edit the configuration." ), "Use Manage Symbol Libraries to edit the configuration." ),
libFileName ); libFileName );
DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg ); DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg );
break; break;
@ -1171,9 +1171,9 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
if( !libTable->HasLibrary( libNickname, true ) ) if( !libTable->HasLibrary( libNickname, true ) )
{ {
msg.Printf( _( "The library with the nickname \"%s\" is not enabled\n" msg.Printf( _( "The library '%s' is not enabled in the current configuration.\n"
"in the current configuration. Use Manage Symbol Libraries to\n" "Use Manage Symbol Libraries to edit the configuration." ),
"edit the configuration." ), libNickname ); libNickname );
DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg ); DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg );
break; break;
} }

View File

@ -508,7 +508,7 @@ void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField )
if( dlg.ShowQuasiModal() != wxID_OK ) if( dlg.ShowQuasiModal() != wxID_OK )
return; return;
wxString newFieldValue = LIB_ID::FixIllegalChars( dlg.GetText(), LIB_ID::ID_SCH ); wxString newFieldValue = LIB_ID::FixIllegalChars( dlg.GetText() );
wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() ); wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() );
bool renamed = aField->GetId() == VALUE_FIELD && newFieldValue != oldFieldValue; bool renamed = aField->GetId() == VALUE_FIELD && newFieldValue != oldFieldValue;

View File

@ -51,10 +51,6 @@
class LIB_ID class LIB_ID
{ {
public: public:
///> Types of library identifiers
enum LIB_ID_TYPE { ID_SCH, ID_PCB };
LIB_ID() {} LIB_ID() {}
// NOTE: don't define any constructors which call Parse() on their arguments. We want it // NOTE: don't define any constructors which call Parse() on their arguments. We want it
@ -66,12 +62,12 @@ public:
* names allowing '/' as a valid character. This was causing the symbol names to * names allowing '/' as a valid character. This was causing the symbol names to
* be truncated at the first occurrence of '/' in the symbol name. * be truncated at the first occurrence of '/' in the symbol name.
* *
* @param aLibName is the library nickname used to look up the library item in the #LIB_TABLE. * @param aLibraryName is the library name used to look up the library item in the #LIB_TABLE.
* @param aLibItemName is the name of the library item which is not parsed by the standard * @param aItemName is the name of the library item which is not parsed by the standard
* LIB_ID::Parse() function. * LIB_ID::Parse() function.
* @param aRevision is the revision of the library item. * @param aRevision is the revision of the library item.
*/ */
LIB_ID( const wxString& aLibName, const wxString& aLibItemName, LIB_ID( const wxString& aLibraryName, const wxString& aItemName,
const wxString& aRevision = wxEmptyString ); const wxString& aRevision = wxEmptyString );
/** /**
@ -83,21 +79,17 @@ public:
* e.g.: "ttl:7400" * e.g.: "ttl:7400"
* *
* @param aId is the string to populate the #LIB_ID object. * @param aId is the string to populate the #LIB_ID object.
* @param aType indicates the LIB_ID type for type-specific parsing (such as allowed chars).
* @param aFix indicates invalid chars should be replaced with '_'. * @param aFix indicates invalid chars should be replaced with '_'.
* *
* @return int - minus 1 (i.e. -1) means success, >= 0 indicates the character offset into * @return int - minus 1 (i.e. -1) means success, >= 0 indicates the character offset into
* aId at which an error was detected. * aId at which an error was detected.
*/ */
int Parse( const UTF8& aId, LIB_ID_TYPE aType, bool aFix = false ); int Parse( const UTF8& aId, bool aFix = false );
/** /**
* Return the logical library name portion of a LIB_ID. * Return the logical library name portion of a LIB_ID.
*/ */
const UTF8& GetLibNickname() const const UTF8& GetLibNickname() const { return m_libraryName; }
{
return nickname;
}
/** /**
* Override the logical library name portion of the LIB_ID to @a aNickname. * Override the logical library name portion of the LIB_ID to @a aNickname.
@ -111,14 +103,14 @@ public:
/** /**
* @return the library item name, i.e. footprintName, in UTF8. * @return the library item name, i.e. footprintName, in UTF8.
*/ */
const UTF8& GetLibItemName() const { return item_name; } const UTF8& GetLibItemName() const { return m_itemName; }
/** /**
* @return the library item name, i.e. footprintName in a wxString (UTF16 or 32). * @return the library item name, i.e. footprintName in a wxString (UTF16 or 32).
* useful to display messages in dialogs * useful to display messages in dialogs
* Equivalent to item_name.wx_str(), but more explicit when building a Unicode string in messages. * Equivalent to m_itemName.wx_str(), but more explicit when building a Unicode string in messages.
*/ */
const wxString GetUniStringLibItemName() const { return item_name.wx_str(); } const wxString GetUniStringLibItemName() const { return m_itemName.wx_str(); }
/** /**
* Override the library item name portion of the LIB_ID to @a aLibItemName * Override the library item name portion of the LIB_ID to @a aLibItemName
@ -131,7 +123,7 @@ public:
int SetRevision( const UTF8& aRevision ); int SetRevision( const UTF8& aRevision );
const UTF8& GetRevision() const { return revision; } const UTF8& GetRevision() const { return m_revision; }
UTF8 GetLibItemNameAndRev() const; UTF8 GetLibItemNameAndRev() const;
@ -152,11 +144,11 @@ public:
/** /**
* @return a string in the proper format as an LIB_ID for a combination of * @return a string in the proper format as an LIB_ID for a combination of
* aLibNickname, aLibItemName, and aRevision. * aLibraryName, aLibItemName, and aRevision.
* *
* @throw PARSE_ERROR if any of the pieces are illegal. * @throw PARSE_ERROR if any of the pieces are illegal.
*/ */
static UTF8 Format( const UTF8& aLibNickname, const UTF8& aLibItemName, static UTF8 Format( const UTF8& aLibraryName, const UTF8& aLibItemName,
const UTF8& aRevision = "" ); const UTF8& aRevision = "" );
/** /**
@ -168,12 +160,18 @@ public:
* @note A return value of true does not indicated that the #LIB_ID is a valid #LIB_TABLE * @note A return value of true does not indicated that the #LIB_ID is a valid #LIB_TABLE
* entry. * entry.
*/ */
bool IsValid() const { return !nickname.empty() && !item_name.empty(); } bool IsValid() const
{
return !m_libraryName.empty() && !m_itemName.empty();
}
/** /**
* @return true if the #LIB_ID only has the #item_name name defined. * @return true if the #LIB_ID only has the #m_itemName name defined.
*/ */
bool IsLegacy() const { return nickname.empty() && !item_name.empty() && revision.empty(); } bool IsLegacy() const
{
return m_libraryName.empty() && !m_itemName.empty() && m_revision.empty();
}
/** /**
* Clear the contents of the library nickname, library entry name, and revision strings. * Clear the contents of the library nickname, library entry name, and revision strings.
@ -183,7 +181,10 @@ public:
/** /**
* @return a boolean true value if the LIB_ID is empty. Otherwise return false. * @return a boolean true value if the LIB_ID is empty. Otherwise return false.
*/ */
bool empty() const { return nickname.empty() && item_name.empty() && revision.empty(); } bool empty() const
{
return m_libraryName.empty() && m_itemName.empty() && m_revision.empty();
}
/** /**
* Compare the contents of LIB_ID objects by performing a std::string comparison of the * Compare the contents of LIB_ID objects by performing a std::string comparison of the
@ -204,29 +205,26 @@ public:
* Examine \a aLibItemName for invalid #LIB_ID item name characters. * Examine \a aLibItemName for invalid #LIB_ID item name characters.
* *
* @param aLibItemName is the #LIB_ID name to test for illegal characters. * @param aLibItemName is the #LIB_ID name to test for illegal characters.
* @param aType is the library identifier type
* @return offset of first illegal character otherwise -1. * @return offset of first illegal character otherwise -1.
*/ */
static int HasIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType ); static int HasIllegalChars( const UTF8& aLibItemName );
/** /**
* Replace illegal #LIB_ID item name characters with underscores '_'. * Replace illegal #LIB_ID item name characters with underscores '_'.
* *
* @param aLibItemName is the #LIB_ID item name to replace illegal characters. * @param aLibItemName is the #LIB_ID item name to replace illegal characters.
* @param aType is the library identifier type
* @param aLib True if we are checking library names, false if we are checking item names * @param aLib True if we are checking library names, false if we are checking item names
* @return the corrected version of \a aLibItemName. * @return the corrected version of \a aLibItemName.
*/ */
static UTF8 FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType, bool aLib = false ); static UTF8 FixIllegalChars( const UTF8& aLibItemName, bool aLib = false );
/** /**
* Looks for characters that are illegal in library nicknames. * Looks for characters that are illegal in library nicknames.
* *
* @param aNickname is the logical library name to be tested. * @param aLibraryName is the logical library name to be tested.
* @param aType is the library identifier type
* @return Invalid character found in the name or 0 is the name is valid. * @return Invalid character found in the name or 0 is the name is valid.
*/ */
static unsigned FindIllegalLibNicknameChar( const UTF8& aNickname, LIB_ID_TYPE aType ); static unsigned FindIllegalLibraryNameChar( const UTF8& aLibraryName );
protected: protected:
/** /**
@ -241,8 +239,8 @@ protected:
* schematic or symbol library file formats. * schematic or symbol library file formats.
* - Spaces are allowed in footprint library nicknames as they are quoted in the * - Spaces are allowed in footprint library nicknames as they are quoted in the
* footprint library table file format. * footprint library table file format.
* - Spaces are not allowed in symbol library nicknames since they are not quoted in * - Spaces are now also allowed in symbol library nicknames since they are quoted in
* the symbol library file format. * the new symbol library sexpr file format.
* - Illegal file name characters are not allowed in footprint names since the file * - Illegal file name characters are not allowed in footprint names since the file
* name is the footprint name. * name is the footprint name.
* - Illegal file name characters except '/' are allowed in symbol names since the * - Illegal file name characters except '/' are allowed in symbol names since the
@ -252,7 +250,7 @@ protected:
* @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use * @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use
* a variable length coding value. * a variable length coding value.
*/ */
static bool isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType ); static bool isLegalChar( unsigned aUniChar );
/** /**
* Tests whether a unicode character is a legal LIB_ID library nickname character * Tests whether a unicode character is a legal LIB_ID library nickname character
@ -260,11 +258,11 @@ protected:
* @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use * @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use
* a variable length coding value. * a variable length coding value.
*/ */
static bool isLegalLibNicknameChar( unsigned aUniChar, LIB_ID_TYPE aType ); static bool isLegalLibraryNameChar( unsigned aUniChar );
UTF8 nickname; ///< The nickname of the library or empty. UTF8 m_libraryName; ///< The nickname of the library or empty.
UTF8 item_name; ///< The name of the entry in the logical library. UTF8 m_itemName; ///< The name of the entry in the logical library.
UTF8 revision; ///< The revision of the entry. UTF8 m_revision; ///< The revision of the entry.
}; };

View File

@ -500,8 +500,6 @@ protected:
*/ */
LIB_TABLE_ROW* findRow( const wxString& aNickname ) const; LIB_TABLE_ROW* findRow( const wxString& aNickname ) const;
LIB_TABLE_ROW* findRow( const wxString& aNickname );
void reindex() void reindex()
{ {
nickIndex.clear(); nickIndex.clear();

View File

@ -176,9 +176,8 @@ public:
* @param aLibIdType is the type of #LIB_ID object to validate. * @param aLibIdType is the type of #LIB_ID object to validate.
* @param aValue is a pointer to a wxString containing the value to validate. * @param aValue is a pointer to a wxString containing the value to validate.
*/ */
LIB_ID_VALIDATOR( LIB_ID::LIB_ID_TYPE aLibIdType, wxString* aValue = NULL ) : LIB_ID_VALIDATOR( wxString* aValue = NULL ) :
wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ), wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
m_idType( aLibIdType )
{ {
SetCharExcludes( "\r\n\t" ); SetCharExcludes( "\r\n\t" );
} }
@ -189,9 +188,6 @@ public:
} }
bool Validate( wxWindow* aParent ) override; bool Validate( wxWindow* aParent ) override;
protected:
LIB_ID::LIB_ID_TYPE m_idType;
}; };

View File

@ -192,7 +192,7 @@ bool DIALOG_EXCHANGE_FOOTPRINTS::isMatch( FOOTPRINT* aFootprint )
case ID_MATCH_FP_VAL: case ID_MATCH_FP_VAL:
return WildCompareString( m_specifiedValue->GetValue(), aFootprint->GetValue(), false ); return WildCompareString( m_specifiedValue->GetValue(), aFootprint->GetValue(), false );
case ID_MATCH_FP_ID: case ID_MATCH_FP_ID:
specifiedID.Parse( m_specifiedID->GetValue(), LIB_ID::ID_PCB ); specifiedID.Parse( m_specifiedID->GetValue() );
return aFootprint->GetFPID() == specifiedID; return aFootprint->GetFPID() == specifiedID;
default: default:
return false; // just to quiet compiler warnings.... return false; // just to quiet compiler warnings....
@ -326,7 +326,7 @@ bool DIALOG_EXCHANGE_FOOTPRINTS::processMatchingFootprints()
if( !m_updateMode ) if( !m_updateMode )
{ {
newFPID.Parse( m_newID->GetValue(), LIB_ID::ID_PCB ); newFPID.Parse( m_newID->GetValue() );
if( !newFPID.IsValid() ) if( !newFPID.IsValid() )
return false; return false;

View File

@ -532,7 +532,7 @@ bool PANEL_FP_LIB_TABLE::verifyTables()
// button. // button.
model->DeleteRows( r, 1 ); model->DeleteRows( r, 1 );
} }
else if( ( illegalCh = LIB_ID::FindIllegalLibNicknameChar( nick, LIB_ID::ID_PCB ) ) ) else if( ( illegalCh = LIB_ID::FindIllegalLibraryNameChar( nick ) ) )
{ {
wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ), wxString msg = wxString::Format( _( "Illegal character '%c' in Nickname: \"%s\"" ),
illegalCh, illegalCh,
@ -847,7 +847,7 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
for( const auto& filePath : files ) for( const auto& filePath : files )
{ {
wxFileName fn( filePath ); wxFileName fn( filePath );
wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_PCB ); wxString nickname = LIB_ID::FixIllegalChars( fn.GetName() );
bool doAdd = true; bool doAdd = true;
if( cur_model()->ContainsNickname( nickname ) ) if( cur_model()->ContainsNickname( nickname ) )

View File

@ -902,32 +902,32 @@ bool FOOTPRINT_VIEWER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent
LIB_TABLE* fpTable = Prj().PcbFootprintLibs(); LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
LIB_ID fpid; LIB_ID fpid;
fpid.Parse( *aFootprint, LIB_ID::ID_PCB, true ); fpid.Parse( *aFootprint, true );
if( fpid.IsValid() ) if( fpid.IsValid() )
{ {
wxString nickname = fpid.GetLibNickname(); wxString libraryName = fpid.GetLibNickname();
if( !fpTable->HasLibrary( fpid.GetLibNickname(), false ) ) if( !fpTable->HasLibrary( fpid.GetLibNickname(), false ) )
{ {
msg.sprintf( _( "The current configuration does not include a library with the\n" msg.sprintf( _( "The current configuration does not include library '%s'. Use "
"nickname \"%s\". Use Manage Footprint Libraries\n" "Manage Footprint Libraries to edit the configuration." ),
"to edit the configuration." ), nickname ); libraryName );
DisplayErrorMessage( aParent, _( "Footprint library not found." ), msg ); DisplayErrorMessage( aParent, _( "Footprint library not found." ), msg );
} }
else if ( !fpTable->HasLibrary( fpid.GetLibNickname(), true ) ) else if ( !fpTable->HasLibrary( fpid.GetLibNickname(), true ) )
{ {
msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n" msg.sprintf( _( "Library '%s' is not enabled in the current configuration. Use "
"in the current configuration. Use Manage Footprint Libraries to\n" "Manage Footprint Libraries to edit the configuration." ),
"edit the configuration." ), nickname ); libraryName );
DisplayErrorMessage( aParent, _( "Footprint library not enabled." ), msg ); DisplayErrorMessage( aParent, _( "Footprint library not enabled." ), msg );
} }
else else
{ {
// Update last selection: // Update last selection:
setCurNickname( nickname ); setCurNickname( libraryName );
setCurFootprintName( fpid.GetLibItemName() ); setCurFootprintName( fpid.GetLibItemName() );
m_libList->SetStringSelection( nickname ); m_libList->SetStringSelection( libraryName );
} }
} }
} }

View File

@ -253,7 +253,7 @@ FOOTPRINT* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect )
if( footprintName.IsEmpty() ) // Cancel command if( footprintName.IsEmpty() ) // Cancel command
return NULL; return NULL;
else else
fpid.Parse( footprintName, LIB_ID::ID_PCB ); fpid.Parse( footprintName );
} }
else else
{ {

View File

@ -418,7 +418,7 @@ void KICAD_NETLIST_PARSER::parseComponent()
} }
} }
if( !footprint.IsEmpty() && fpid.Parse( footprint, LIB_ID::ID_PCB, true ) >= 0 ) if( !footprint.IsEmpty() && fpid.Parse( footprint, true ) >= 0 )
{ {
wxString error; wxString error;
error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ), error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),

View File

@ -175,7 +175,7 @@ bool CMP_READER::Load( NETLIST* aNetlist )
{ {
LIB_ID fpid; LIB_ID fpid;
if( !footprint.IsEmpty() && fpid.Parse( footprint, LIB_ID::ID_PCB, true ) >= 0 ) if( !footprint.IsEmpty() && fpid.Parse( footprint, true ) >= 0 )
{ {
wxString error; wxString error;
error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d" ), error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d" ),

View File

@ -752,7 +752,7 @@ void ALTIUM_PCB::ParseComponents6Data( const CFB::CompoundFileReader& aReader,
m_board->Add( footprint, ADD_MODE::APPEND ); m_board->Add( footprint, ADD_MODE::APPEND );
m_components.emplace_back( footprint ); m_components.emplace_back( footprint );
LIB_ID fpID = AltiumToKiCadLibID(LIB_ID::ID_PCB, elem.sourcefootprintlibrary, elem.sourcelibreference ); LIB_ID fpID = AltiumToKiCadLibID( elem.sourcefootprintlibrary, elem.sourcelibreference );
footprint->SetFPID( fpID ); footprint->SetFPID( fpID );

View File

@ -613,7 +613,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadComponentLibrary()
footprint->SetPosition( getKiCadPoint( component.Origin ) ); footprint->SetPosition( getKiCadPoint( component.Origin ) );
LIB_ID libID; LIB_ID libID;
libID.Parse( fpName, LIB_ID::LIB_ID_TYPE::ID_PCB, true ); libID.Parse( fpName, true );
footprint->SetFPID( libID ); footprint->SetFPID( libID );
loadLibraryFigures( component, footprint ); loadLibraryFigures( component, footprint );

View File

@ -1537,7 +1537,7 @@ FOOTPRINT* EAGLE_PLUGIN::makeFootprint( wxXmlNode* aPackage, const wxString& aPk
std::unique_ptr<FOOTPRINT> m = std::make_unique<FOOTPRINT>( m_board ); std::unique_ptr<FOOTPRINT> m = std::make_unique<FOOTPRINT>( m_board );
LIB_ID fpID; LIB_ID fpID;
fpID.Parse( aPkgName, LIB_ID::ID_PCB, true ); fpID.Parse( aPkgName, true );
m->SetFPID( fpID ); m->SetFPID( fpID );
// Get the first package item and iterate // Get the first package item and iterate

View File

@ -2860,7 +2860,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments
name = FromUTF8(); name = FromUTF8();
if( !name.IsEmpty() && fpid.Parse( name, LIB_ID::ID_PCB, true ) >= 0 ) if( !name.IsEmpty() && fpid.Parse( name, true ) >= 0 )
{ {
wxString error; wxString error;
error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ), error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ),

View File

@ -435,7 +435,7 @@ void LEGACY_PLUGIN::loadAllSections( bool doAppend )
ReplaceIllegalFileNameChars( &fpName ); ReplaceIllegalFileNameChars( &fpName );
if( !fpName.empty() ) if( !fpName.empty() )
fpid.Parse( fpName, LIB_ID::ID_PCB, true ); fpid.Parse( fpName, true );
footprint->SetFPID( fpid ); footprint->SetFPID( fpid );

View File

@ -510,7 +510,7 @@ void PCB_FOOTPRINT::AddToBoard()
footprint->SetLastEditTime( 0 ); footprint->SetLastEditTime( 0 );
LIB_ID fpID; LIB_ID fpID;
fpID.Parse( m_compRef, LIB_ID::ID_PCB, true ); fpID.Parse( m_compRef, true );
footprint->SetFPID( fpID ); footprint->SetFPID( fpID );
// reference text // reference text