From bb232e6ac6db07919540a28b346a36e68b2f6566 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 17 Dec 2020 23:32:23 +0000 Subject: [PATCH] Unify LIB_IDs now that both are stored in sexpr files. Fixes https://gitlab.com/kicad/code/kicad/issues/6764 --- common/footprint_info.cpp | 2 +- common/lib_id.cpp | 99 +++++++++---------- common/lib_table_base.cpp | 38 +++---- common/plugins/altium/altium_parser_utils.h | 4 +- common/validators.cpp | 2 +- cvpcb/cvpcb_association.h | 4 +- cvpcb/display_footprints_frame.cpp | 2 +- cvpcb/tools/cvpcb_association_tool.cpp | 6 +- eeschema/class_libentry.cpp | 2 +- eeschema/dialogs/dialog_change_symbols.cpp | 6 +- eeschema/dialogs/dialog_choose_symbol.cpp | 2 +- .../dialogs/dialog_edit_components_libid.cpp | 13 ++- eeschema/dialogs/panel_sym_lib_table.cpp | 4 +- eeschema/fields_grid_table.cpp | 4 +- eeschema/files-io.cpp | 2 +- eeschema/getpart.cpp | 2 +- eeschema/lib_view_frame.cpp | 18 ++-- eeschema/project_rescue.cpp | 10 +- .../sch_plugins/altium/sch_altium_plugin.cpp | 6 +- .../cadstar/cadstar_sch_archive_loader.cpp | 2 +- .../cadstar/cadstar_sch_archive_plugin.cpp | 2 +- .../sch_plugins/eagle/sch_eagle_plugin.cpp | 4 +- .../sch_plugins/kicad/sch_sexpr_parser.cpp | 4 +- .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 2 +- .../sch_plugins/legacy/sch_legacy_plugin.cpp | 4 +- eeschema/symbol_editor/symbol_edit_frame.cpp | 10 +- eeschema/tools/symbol_editor_edit_tool.cpp | 2 +- include/lib_id.h | 72 +++++++------- include/lib_table_base.h | 2 - include/validators.h | 8 +- pcbnew/dialogs/dialog_exchange_footprints.cpp | 4 +- pcbnew/dialogs/panel_fp_lib_table.cpp | 4 +- pcbnew/footprint_viewer_frame.cpp | 20 ++-- pcbnew/load_select_footprint.cpp | 2 +- .../netlist_reader/kicad_netlist_reader.cpp | 2 +- pcbnew/netlist_reader/netlist_reader.cpp | 2 +- pcbnew/plugins/altium/altium_pcb.cpp | 2 +- .../cadstar/cadstar_pcb_archive_loader.cpp | 2 +- pcbnew/plugins/eagle/eagle_plugin.cpp | 2 +- pcbnew/plugins/kicad/pcb_parser.cpp | 2 +- pcbnew/plugins/legacy/legacy_plugin.cpp | 2 +- pcbnew/plugins/pcad/pcb_footprint.cpp | 2 +- 42 files changed, 177 insertions(+), 207 deletions(-) diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index b109a37f82..381e4af3bf 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -62,7 +62,7 @@ FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aFootprintName 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 ) ); return GetFootprintInfo( fpid.GetLibNickname(), fpid.GetLibItemName() ); diff --git a/common/lib_id.cpp b/common/lib_id.cpp index 9c6bfb5d55..c032073e0f 100644 --- a/common/lib_id.cpp +++ b/common/lib_id.cpp @@ -113,13 +113,13 @@ static int okRevision( const UTF8& aField ) void LIB_ID::clear() { - nickname.clear(); - item_name.clear(); - revision.clear(); + m_libraryName.clear(); + m_itemName.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(); @@ -129,14 +129,14 @@ int LIB_ID::Parse( const UTF8& aId, LIB_ID_TYPE aType, bool aFix ) size_t partNdx; int offset = -1; - //============================================== + //========================================== // in a LIB_ID like discret:R3/rev4 if( rev ) { revNdx = rev - buffer; // 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 } else @@ -144,7 +144,7 @@ int LIB_ID::Parse( const UTF8& aId, LIB_ID_TYPE aType, bool aFix ) revNdx = aId.size(); } - //=============================================== + //============================================== if( ( partNdx = aId.find( ':' ) ) != aId.npos ) { 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. // Some chars can be found in legacy files converted files from other EDA tools. if( aFix ) - fpname = FixIllegalChars( fpname, aType, false ); + fpname = FixIllegalChars( fpname, false ); else - offset = HasIllegalChars( fpname, aType ); + offset = HasIllegalChars( fpname ); if( offset > -1 ) 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 ) : - nickname( aLibName ), - item_name( aLibItemName ), - revision( aRevision ) + m_libraryName( aLibraryName ), + m_itemName( aItemName ), + m_revision( aRevision ) { } @@ -195,9 +195,7 @@ int LIB_ID::SetLibNickname( const UTF8& aLogical ) int offset = okLogical( aLogical ); if( offset == -1 ) - { - nickname = aLogical; - } + m_libraryName = aLogical; return offset; } @@ -209,12 +207,12 @@ int LIB_ID::SetLibItemName( const UTF8& aLibItemName, bool aTestForRev ) if( aTestForRev && separation != -1 ) { - item_name = aLibItemName.substr( 0, separation-1 ); + m_itemName = aLibItemName.substr( 0, separation-1 ); return separation; } else { - item_name = aLibItemName; + m_itemName = aLibItemName; } return -1; @@ -226,9 +224,7 @@ int LIB_ID::SetRevision( const UTF8& aRevision ) int offset = okRevision( aRevision ); if( offset == -1 ) - { - revision = aRevision; - } + m_revision = aRevision; return offset; } @@ -238,18 +234,18 @@ UTF8 LIB_ID::Format() const { UTF8 ret; - if( nickname.size() ) + if( m_libraryName.size() ) { - ret += nickname; + ret += m_libraryName; ret += ':'; } - ret += item_name; + ret += m_itemName; - if( revision.size() ) + if( m_revision.size() ) { ret += '/'; - ret += revision; + ret += m_revision; } return ret; @@ -258,35 +254,34 @@ UTF8 LIB_ID::Format() const UTF8 LIB_ID::GetLibItemNameAndRev() const { - UTF8 ret = item_name; + UTF8 ret = m_itemName; - if( revision.size() ) + if( m_revision.size() ) { ret += '/'; - ret += revision; + ret += m_revision; } 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; int offset; - if( aLogicalLib.size() ) + if( aLibraryName.size() ) { - offset = okLogical( aLogicalLib ); + offset = okLogical( aLibraryName ); if( offset != -1 ) { THROW_PARSE_ERROR( _( "Illegal character found in logical library name" ), - wxString::FromUTF8( aLogicalLib.c_str() ), - aLogicalLib.c_str(), 0, offset ); + wxString::FromUTF8( aLibraryName.c_str() ), aLibraryName.c_str(), 0, offset ); } - ret += aLogicalLib; + ret += aLibraryName; ret += ':'; } @@ -319,27 +314,27 @@ int LIB_ID::compare( const LIB_ID& aLibId ) const if( this == &aLibId ) return 0; - int retv = nickname.compare( aLibId.nickname ); + int retv = m_libraryName.compare( aLibId.m_libraryName ); if( retv != 0 ) return retv; - retv = item_name.compare( aLibId.item_name ); + retv = m_itemName.compare( aLibId.m_itemName ); if( retv != 0 ) 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; for( auto ch : aLibItemName ) { - if( !isLegalChar( ch, aType ) ) + if( !isLegalChar( ch ) ) return offset; else ++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; @@ -357,19 +352,19 @@ UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType, bool { auto ch = *chIt; if( aLib ) - fixedName += isLegalLibNicknameChar( ch, aType ) ? ch : '_'; + fixedName += isLegalLibraryNameChar( ch ) ? ch : '_'; else - fixedName += isLegalChar( ch, aType ) ? ch : '_'; + fixedName += isLegalChar( ch ) ? ch : '_'; } 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 illegal_filename_chars_allowed = ( aType == ID_SCH ); + bool const space_allowed = true; + bool const illegal_filename_chars_allowed = false; if( aUniChar < ' ' ) 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; } @@ -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 < ' ' ) return false; @@ -453,7 +448,7 @@ void LIB_ID::Test() LIB_ID lpid( lpids[i] ); // parse // 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], lpid.Format().c_str(), lpid.GetLibNickname().c_str(), diff --git a/common/lib_table_base.cpp b/common/lib_table_base.cpp index 4b987489b2..d569c36dd7 100644 --- a/common/lib_table_base.cpp +++ b/common/lib_table_base.cpp @@ -25,16 +25,12 @@ #include -#include - #include - #include #include #include #include #include -#include #define OPT_SEP '|' ///< options separator character @@ -195,33 +191,21 @@ LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName ) const { cur->ensureIndex(); - INDEX_CITER it = cur->nickIndex.find( aNickName ); - - if( it != cur->nickIndex.end() ) + for( const std::pair& entry : cur->nickIndex ) { - return &cur->rows[it->second]; // found + if( entry.first == aNickName ) + return &cur->rows[entry.second ]; } - // not found, search fall back table(s), if any - } while( ( cur = cur->fallBack ) != 0 ); - - 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() ) + // Repeat, this time looking for names that were "fixed" by legacy versions because + // the old eeschema file format didn't support spaces in tokens. + for( const std::pair& entry : cur->nickIndex ) { - 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 diff --git a/common/plugins/altium/altium_parser_utils.h b/common/plugins/altium/altium_parser_utils.h index 51ac5ae4ad..a9290c0b06 100644 --- a/common/plugins/altium/altium_parser_utils.h +++ b/common/plugins/altium/altium_parser_utils.h @@ -29,7 +29,7 @@ #include -LIB_ID AltiumToKiCadLibID( LIB_ID::LIB_ID_TYPE aType, wxString aLibName, wxString aLibReference ) +LIB_ID AltiumToKiCadLibID( wxString aLibName, wxString aLibReference ) { ReplaceIllegalFileNameChars( aLibName, '_' ); 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; LIB_ID libId; - libId.Parse( key, aType, true ); + libId.Parse( key, true ); return libId; } diff --git a/common/validators.cpp b/common/validators.cpp index 1699465b07..e6bd59275f 100644 --- a/common/validators.cpp +++ b/common/validators.cpp @@ -297,7 +297,7 @@ bool LIB_ID_VALIDATOR::Validate( wxWindow *aParent ) { 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 ); } diff --git a/cvpcb/cvpcb_association.h b/cvpcb/cvpcb_association.h index e9978d5d96..c47f6cdb54 100644 --- a/cvpcb/cvpcb_association.h +++ b/cvpcb/cvpcb_association.h @@ -51,8 +51,8 @@ public: unsigned int aComponentIndex, wxString aNewFootprint, wxString aOldFootprint = "" ) : m_componentIndex( aComponentIndex ) { - m_newFootprint.Parse( aNewFootprint, LIB_ID::ID_PCB ); - m_oldFootprint.Parse( aOldFootprint, LIB_ID::ID_PCB ); + m_newFootprint.Parse( aNewFootprint ); + m_oldFootprint.Parse( aOldFootprint ); } /** diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 840b1ae356..d0f1d7486b 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -374,7 +374,7 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam FOOTPRINT* footprint = NULL; 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." ), aFootprintName ), diff --git a/cvpcb/tools/cvpcb_association_tool.cpp b/cvpcb/tools/cvpcb_association_tool.cpp index a8e76177b7..28226a7e7c 100644 --- a/cvpcb/tools/cvpcb_association_tool.cpp +++ b/cvpcb/tools/cvpcb_association_tool.cpp @@ -61,7 +61,7 @@ int CVPCB_ASSOCIATION_TOOL::CopyAssoc( const TOOL_EVENT& aEvent ) switch( copyControl ) { case CVPCB_MAINFRAME::CONTROL_FOOTPRINT: - fpid.Parse( m_frame->GetSelectedFootprint(), LIB_ID::ID_PCB ); + fpid.Parse( m_frame->GetSelectedFootprint() ); break; case CVPCB_MAINFRAME::CONTROL_COMPONENT: @@ -163,7 +163,7 @@ int CVPCB_ASSOCIATION_TOOL::PasteAssoc( const TOOL_EVENT& aEvent ) return 0; } - if( fpid.Parse( data.GetText(), LIB_ID::ID_PCB ) >= 0 ) + if( fpid.Parse( data.GetText() ) >= 0 ) return 0; // Assign the fpid to the selections @@ -205,7 +205,7 @@ int CVPCB_ASSOCIATION_TOOL::Associate( const TOOL_EVENT& aEvent ) // Get the currently selected footprint LIB_ID fpid; 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) if( fpid.empty() ) diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 4435967bf1..359e7ca484 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -309,7 +309,7 @@ wxString LIB_PART::GetUnitReference( int aUnit ) 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_libId.SetLibItemName( validatedName, false ); diff --git a/eeschema/dialogs/dialog_change_symbols.cpp b/eeschema/dialogs/dialog_change_symbols.cpp index 8615ba35ca..697ff4a56c 100644 --- a/eeschema/dialogs/dialog_change_symbols.cpp +++ b/eeschema/dialogs/dialog_change_symbols.cpp @@ -286,7 +286,7 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList() { LIB_ID newId; - newId.Parse( m_newId->GetValue(), LIB_ID::ID_SCH ); + newId.Parse( m_newId->GetValue() ); if( newId.IsValid() ) { @@ -384,7 +384,7 @@ bool DIALOG_CHANGE_SYMBOLS::isMatch( SCH_COMPONENT* aSymbol, SCH_SHEET_PATH* aIn } else if( m_matchById ) { - id.Parse( m_specifiedId->GetValue(), LIB_ID::ID_SCH ); + id.Parse( m_specifiedId->GetValue() ); return aSymbol->GetLibId() == id; } @@ -405,7 +405,7 @@ bool DIALOG_CHANGE_SYMBOLS::processMatchingSymbols() if( m_mode == MODE::CHANGE ) { - newId.Parse( m_newId->GetValue(), LIB_ID::ID_SCH ); + newId.Parse( m_newId->GetValue() ); if( !newId.IsValid() ) return false; diff --git a/eeschema/dialogs/dialog_choose_symbol.cpp b/eeschema/dialogs/dialog_choose_symbol.cpp index 2fe5dda7d7..8046c333c4 100644 --- a/eeschema/dialogs/dialog_choose_symbol.cpp +++ b/eeschema/dialogs/dialog_choose_symbol.cpp @@ -426,7 +426,7 @@ void DIALOG_CHOOSE_SYMBOL::ShowFootprint( wxString const& aName ) { 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->CacheFootprint( lib_id ); diff --git a/eeschema/dialogs/dialog_edit_components_libid.cpp b/eeschema/dialogs/dialog_edit_components_libid.cpp index 428d191bca..f4d34a9812 100644 --- a/eeschema/dialogs/dialog_edit_components_libid.cpp +++ b/eeschema/dialogs/dialog_edit_components_libid.cpp @@ -541,7 +541,7 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::validateLibIds() // a new lib id is found. validate this new value LIB_ID id; - id.Parse( new_libid, LIB_ID::ID_SCH ); + id.Parse( new_libid ); 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 LIB_ID curr_libid; - curr_libid.Parse( orphanLibid, LIB_ID::ID_SCH, true ); + curr_libid.Parse( orphanLibid, true ); wxString symbName = curr_libid.GetLibItemName(); // 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 @@ -674,17 +674,16 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::setLibIdByBrowser( int aRow ) 0, 0, false ); #else // Use library viewer to choose a symbol - LIB_ID aPreselectedLibid; + LIB_ID preselected; wxString current = m_grid->GetCellValue( aRow, COL_NEW_LIBID ); if( current.IsEmpty() ) current = m_grid->GetCellValue( aRow, COL_CURR_LIBID ); if( !current.IsEmpty() ) - aPreselectedLibid.Parse( current, LIB_ID::ID_SCH, true ); + preselected.Parse( current, true ); - PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibBrowser( this, NULL, aPreselectedLibid, - 0, 0 ); + PICKED_SYMBOL sel = GetParent()->PickSymbolFromLibBrowser( this, NULL, preselected, 0, 0 ); #endif 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. LIB_ID id; - id.Parse( new_libid, LIB_ID::ID_SCH, true ); + id.Parse( new_libid, true ); for( CMP_CANDIDATE& cmp : m_components ) { diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index e4491c909c..385079e231 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -329,7 +329,7 @@ bool PANEL_SYM_LIB_TABLE::verifyTables() // button. 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\"" ), illegalCh, @@ -470,7 +470,7 @@ void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) { wxString filePath = dlg.GetDirectory() + wxFileName::GetPathSeparator() + file; wxFileName fn( filePath ); - wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_SCH ); + wxString nickname = LIB_ID::FixIllegalChars( fn.GetName() ); bool doAdd = true; if( cur_model()->ContainsNickname( nickname ) ) diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index a8cdd91f96..ce33b2c6a8 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -56,7 +56,7 @@ FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ), m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), REFERENCE_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_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ), m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME ) @@ -76,7 +76,7 @@ FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a m_fieldNameValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_NAME ), m_referenceValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETNAME_V ), 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_nonUrlValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), FIELD_VALUE ), m_filepathValidator( aFrame->IsType( FRAME_SCH_SYMBOL_EDITOR ), SHEETFILENAME_V ) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 581a85a080..56e4399161 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -970,7 +970,7 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) if( !fpField->GetText().IsEmpty() ) { LIB_ID fpId; - fpId.Parse( fpField->GetText(), LIB_ID::ID_SCH, true ); + fpId.Parse( fpField->GetText(), true ); fpId.SetLibNickname( newfilename.GetName() ); fpField->SetText( fpId.Format() ); } diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 801fc3482a..a8ff90ef9e 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -73,7 +73,7 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibBrowser( wxTopLevelWindow* aParen { LIB_ID id; - if( id.Parse( symbol, LIB_ID::ID_SCH ) == -1 ) + if( id.Parse( symbol ) == -1 ) sel.LibId = id; sel.Unit = viewlibFrame->GetUnit(); diff --git a/eeschema/lib_view_frame.cpp b/eeschema/lib_view_frame.cpp index 0beaa25426..2d753a69b2 100644 --- a/eeschema/lib_view_frame.cpp +++ b/eeschema/lib_view_frame.cpp @@ -373,24 +373,24 @@ bool LIB_VIEW_FRAME::ShowModal( wxString* aSymbol, wxWindow* aParent ) LIB_TABLE* libTable = Prj().SchSymbolLibTable(); LIB_ID libid; - libid.Parse( *aSymbol, LIB_ID::ID_SCH, true ); + libid.Parse( *aSymbol, true ); if( libid.IsValid() ) { - wxString nickname = libid.GetLibNickname(); + wxString libName = libid.GetLibNickname(); if( !libTable->HasLibrary( libid.GetLibNickname(), false ) ) { - msg.sprintf( _( "The current configuration does not include a library with the\n" - "nickname \"%s\". Use Manage Symbol Libraries\n" - "to edit the configuration." ), nickname ); - DisplayErrorMessage( aParent, _( "Symbol library not found." ), msg ); + msg.Printf( _( "The current configuration does not include the library '%s'.\n" + "Use Manage Symbol Libraries to edit the configuration." ), + libName ); + DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg ); } else if ( !libTable->HasLibrary( libid.GetLibNickname(), true ) ) { - msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n" - "in the current configuration. Use Manage Symbol Libraries to\n" - "edit the configuration." ), nickname ); + msg.Printf( _( "The library '%s' is not enabled in the current configuration.\n" + "Use Manage Symbol Libraries to edit the configuration." ), + libName ); DisplayErrorMessage( aParent, _( "Symbol library not enabled." ), msg ); } else diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index cae39fd165..a5fed90355 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -89,7 +89,7 @@ static void get_components( SCHEMATIC* aSchematic, std::vector& static LIB_PART* find_component( const wxString& aName, PART_LIBS* aLibs, bool aCached ) { 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 ) { @@ -149,7 +149,7 @@ void RESCUE_CASE_CANDIDATE::FindRescues( RESCUER& aRescuer, for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) ) { 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 ) { @@ -254,7 +254,7 @@ void RESCUE_CACHE_CANDIDATE::FindRescues( RESCUER& aRescuer, for( SCH_COMPONENT* each_component : *( aRescuer.GetComponents() ) ) { 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 ) { @@ -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. - 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 && !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. - 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 // table nickname to the symbol name to prevent name clashes in the rescue library. diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 60e80c6f4d..ea716036f6 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -136,7 +136,7 @@ wxString SCH_ALTIUM_PLUGIN::getLibName() m_libName = "noname"; 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; @@ -495,7 +495,7 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int aIndex, elem.orientation, elem.isMirrored ? "_mirrored" : "", 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 ); kpart->SetName( name ); @@ -1555,7 +1555,7 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map& aPro { 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; diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 5d6ea19607..7038af3279 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -377,7 +377,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances() //KiCad requires parts to be named the same as the net: 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() || mPowerSymLibMap.at( symID )->GetName() != partName ) diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp index a13d8eb033..82603faa1a 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_plugin.cpp @@ -102,7 +102,7 @@ SCH_SHEET* CADSTAR_SCH_ARCHIVE_PLUGIN::Load( const wxString& aFileName, SCHEMATI libName = "noname"; libName += "-cadstar-import"; - libName = LIB_ID::FixIllegalChars( libName, LIB_ID::ID_SCH, true ); + libName = LIB_ID::FixIllegalChars( libName, true ); wxFileName libFileName( aSchematic->Prj().GetProjectPath(), libName, KiCadSymbolLibFileExtension ); diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index 2f500e62ff..180a65074e 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -149,7 +149,7 @@ wxString SCH_EAGLE_PLUGIN::getLibName() m_libName = "noname"; 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; @@ -2605,7 +2605,7 @@ void SCH_EAGLE_PLUGIN::addImplicitConnections( 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; } diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 26995e5ffe..8be983c156 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -149,7 +149,7 @@ LIB_PART* SCH_SEXPR_PARSER::ParseSymbol( LIB_PART_MAP& aSymbolLibMap, int aFileV 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" ), CurSource().c_str(), CurLineNumber(), CurOffset() ); @@ -2162,7 +2162,7 @@ SCH_COMPONENT* SCH_SEXPR_PARSER::parseSchematicSymbol() 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" "offset: %d" ), diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 217d4b7cdd..d33300f4d4 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -1529,7 +1529,7 @@ void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( LIB_PART* aSymbol, OUTPUTFORMATTER& aFo LIB_ID unitId; - wxCHECK2( unitId.Parse( aLibName, LIB_ID::ID_SCH ) < 0, /* do nothing */ ); + wxCHECK2( unitId.Parse( aLibName ) < 0, /* do nothing */ ); unitName = unitId.GetLibItemName(); } diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index a6df31b8f7..c1bd40727a 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -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 // that contained '/' and ':' characters. if( m_version > 3 ) - libId.Parse( libName, LIB_ID::ID_SCH, true ); + libId.Parse( libName, true ); else libId.SetLibItemName( libName, false ); @@ -2687,7 +2687,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadDocs() aliasName = wxString::FromUTF8( line ); 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 ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index dfd00caf71..2fa3bcc7cd 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -1160,8 +1160,8 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) if( !libTableRow ) { - msg.Printf( _( "The current configuration does not include the symbol library\n" - "\"%s\".\nUse Manage Symbol Libraries to edit the configuration." ), + msg.Printf( _( "The current configuration does not include the library '%s'.\n" + "Use Manage Symbol Libraries to edit the configuration." ), libFileName ); DisplayErrorMessage( this, _( "Library not found in symbol library table." ), msg ); break; @@ -1171,9 +1171,9 @@ void SYMBOL_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) if( !libTable->HasLibrary( libNickname, true ) ) { - msg.Printf( _( "The library with the nickname \"%s\" is not enabled\n" - "in the current configuration. Use Manage Symbol Libraries to\n" - "edit the configuration." ), libNickname ); + msg.Printf( _( "The library '%s' is not enabled in the current configuration.\n" + "Use Manage Symbol Libraries to edit the configuration." ), + libNickname ); DisplayErrorMessage( this, _( "Symbol library not enabled." ), msg ); break; } diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp index 40a95c27bb..5610db1dec 100644 --- a/eeschema/tools/symbol_editor_edit_tool.cpp +++ b/eeschema/tools/symbol_editor_edit_tool.cpp @@ -508,7 +508,7 @@ void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField ) if( dlg.ShowQuasiModal() != wxID_OK ) 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() ); bool renamed = aField->GetId() == VALUE_FIELD && newFieldValue != oldFieldValue; diff --git a/include/lib_id.h b/include/lib_id.h index 48d9ec8ff1..53176e6651 100644 --- a/include/lib_id.h +++ b/include/lib_id.h @@ -51,10 +51,6 @@ class LIB_ID { public: - - ///> Types of library identifiers - enum LIB_ID_TYPE { ID_SCH, ID_PCB }; - LIB_ID() {} // 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 * 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 aLibItemName is the name of the library item which is not parsed by the standard + * @param aLibraryName is the library name used to look up the library item in the #LIB_TABLE. + * @param aItemName is the name of the library item which is not parsed by the standard * LIB_ID::Parse() function. * @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 ); /** @@ -83,21 +79,17 @@ public: * e.g.: "ttl:7400" * * @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 '_'. * * @return int - minus 1 (i.e. -1) means success, >= 0 indicates the character offset into * 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. */ - const UTF8& GetLibNickname() const - { - return nickname; - } + const UTF8& GetLibNickname() const { return m_libraryName; } /** * 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. */ - 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). * 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 @@ -131,7 +123,7 @@ public: int SetRevision( const UTF8& aRevision ); - const UTF8& GetRevision() const { return revision; } + const UTF8& GetRevision() const { return m_revision; } UTF8 GetLibItemNameAndRev() const; @@ -152,11 +144,11 @@ public: /** * @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. */ - static UTF8 Format( const UTF8& aLibNickname, const UTF8& aLibItemName, + static UTF8 Format( const UTF8& aLibraryName, const UTF8& aLibItemName, 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 * 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. @@ -183,7 +181,10 @@ public: /** * @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 @@ -204,29 +205,26 @@ public: * Examine \a aLibItemName for invalid #LIB_ID item name 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. */ - 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 '_'. * * @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 * @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. * - * @param aNickname is the logical library name to be tested. - * @param aType is the library identifier type + * @param aLibraryName is the logical library name to be tested. * @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: /** @@ -241,8 +239,8 @@ protected: * schematic or symbol library file formats. * - Spaces are allowed in footprint library nicknames as they are quoted in the * footprint library table file format. - * - Spaces are not allowed in symbol library nicknames since they are not quoted in - * the symbol library file format. + * - 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 @@ -252,7 +250,7 @@ protected: * @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use * 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 @@ -260,11 +258,11 @@ protected: * @note @a aUniChar is expected to be a 32 bit unicode character, not a UTF8 char, that use * 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 item_name; ///< The name of the entry in the logical library. - UTF8 revision; ///< The revision of the entry. + UTF8 m_libraryName; ///< The nickname of the library or empty. + UTF8 m_itemName; ///< The name of the entry in the logical library. + UTF8 m_revision; ///< The revision of the entry. }; diff --git a/include/lib_table_base.h b/include/lib_table_base.h index 6914845fb0..9a2835c9f4 100644 --- a/include/lib_table_base.h +++ b/include/lib_table_base.h @@ -500,8 +500,6 @@ protected: */ LIB_TABLE_ROW* findRow( const wxString& aNickname ) const; - LIB_TABLE_ROW* findRow( const wxString& aNickname ); - void reindex() { nickIndex.clear(); diff --git a/include/validators.h b/include/validators.h index ec1cff061f..013b98b3ad 100644 --- a/include/validators.h +++ b/include/validators.h @@ -176,9 +176,8 @@ public: * @param aLibIdType is the type of #LIB_ID object 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 ) : - wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ), - m_idType( aLibIdType ) + LIB_ID_VALIDATOR( wxString* aValue = NULL ) : + wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ) { SetCharExcludes( "\r\n\t" ); } @@ -189,9 +188,6 @@ public: } bool Validate( wxWindow* aParent ) override; - -protected: - LIB_ID::LIB_ID_TYPE m_idType; }; diff --git a/pcbnew/dialogs/dialog_exchange_footprints.cpp b/pcbnew/dialogs/dialog_exchange_footprints.cpp index 9aa6fa6734..17aedecdf6 100644 --- a/pcbnew/dialogs/dialog_exchange_footprints.cpp +++ b/pcbnew/dialogs/dialog_exchange_footprints.cpp @@ -192,7 +192,7 @@ bool DIALOG_EXCHANGE_FOOTPRINTS::isMatch( FOOTPRINT* aFootprint ) case ID_MATCH_FP_VAL: return WildCompareString( m_specifiedValue->GetValue(), aFootprint->GetValue(), false ); case ID_MATCH_FP_ID: - specifiedID.Parse( m_specifiedID->GetValue(), LIB_ID::ID_PCB ); + specifiedID.Parse( m_specifiedID->GetValue() ); return aFootprint->GetFPID() == specifiedID; default: return false; // just to quiet compiler warnings.... @@ -326,7 +326,7 @@ bool DIALOG_EXCHANGE_FOOTPRINTS::processMatchingFootprints() if( !m_updateMode ) { - newFPID.Parse( m_newID->GetValue(), LIB_ID::ID_PCB ); + newFPID.Parse( m_newID->GetValue() ); if( !newFPID.IsValid() ) return false; diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index 66961a5cae..3c6e386232 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -532,7 +532,7 @@ bool PANEL_FP_LIB_TABLE::verifyTables() // button. 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\"" ), illegalCh, @@ -847,7 +847,7 @@ void PANEL_FP_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) for( const auto& filePath : files ) { wxFileName fn( filePath ); - wxString nickname = LIB_ID::FixIllegalChars( fn.GetName(), LIB_ID::ID_PCB ); + wxString nickname = LIB_ID::FixIllegalChars( fn.GetName() ); bool doAdd = true; if( cur_model()->ContainsNickname( nickname ) ) diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 10a25ea512..55ec550626 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -902,32 +902,32 @@ bool FOOTPRINT_VIEWER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent LIB_TABLE* fpTable = Prj().PcbFootprintLibs(); LIB_ID fpid; - fpid.Parse( *aFootprint, LIB_ID::ID_PCB, true ); + fpid.Parse( *aFootprint, true ); if( fpid.IsValid() ) { - wxString nickname = fpid.GetLibNickname(); + wxString libraryName = fpid.GetLibNickname(); if( !fpTable->HasLibrary( fpid.GetLibNickname(), false ) ) { - msg.sprintf( _( "The current configuration does not include a library with the\n" - "nickname \"%s\". Use Manage Footprint Libraries\n" - "to edit the configuration." ), nickname ); + msg.sprintf( _( "The current configuration does not include library '%s'. Use " + "Manage Footprint Libraries to edit the configuration." ), + libraryName ); DisplayErrorMessage( aParent, _( "Footprint library not found." ), msg ); } else if ( !fpTable->HasLibrary( fpid.GetLibNickname(), true ) ) { - msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n" - "in the current configuration. Use Manage Footprint Libraries to\n" - "edit the configuration." ), nickname ); + msg.sprintf( _( "Library '%s' is not enabled in the current configuration. Use " + "Manage Footprint Libraries to edit the configuration." ), + libraryName ); DisplayErrorMessage( aParent, _( "Footprint library not enabled." ), msg ); } else { // Update last selection: - setCurNickname( nickname ); + setCurNickname( libraryName ); setCurFootprintName( fpid.GetLibItemName() ); - m_libList->SetStringSelection( nickname ); + m_libList->SetStringSelection( libraryName ); } } } diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index a1297d96d4..df155666cd 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -253,7 +253,7 @@ FOOTPRINT* PCB_BASE_FRAME::SelectFootprintFromLibTree( LIB_ID aPreselect ) if( footprintName.IsEmpty() ) // Cancel command return NULL; else - fpid.Parse( footprintName, LIB_ID::ID_PCB ); + fpid.Parse( footprintName ); } else { diff --git a/pcbnew/netlist_reader/kicad_netlist_reader.cpp b/pcbnew/netlist_reader/kicad_netlist_reader.cpp index 5f3f813ead..f378113f61 100644 --- a/pcbnew/netlist_reader/kicad_netlist_reader.cpp +++ b/pcbnew/netlist_reader/kicad_netlist_reader.cpp @@ -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; error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ), diff --git a/pcbnew/netlist_reader/netlist_reader.cpp b/pcbnew/netlist_reader/netlist_reader.cpp index 0afa2fd1af..485de7cec5 100644 --- a/pcbnew/netlist_reader/netlist_reader.cpp +++ b/pcbnew/netlist_reader/netlist_reader.cpp @@ -175,7 +175,7 @@ bool CMP_READER::Load( NETLIST* aNetlist ) { 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; error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d" ), diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp index 94f7fa18a7..2181e0beba 100644 --- a/pcbnew/plugins/altium/altium_pcb.cpp +++ b/pcbnew/plugins/altium/altium_pcb.cpp @@ -752,7 +752,7 @@ void ALTIUM_PCB::ParseComponents6Data( const CFB::CompoundFileReader& aReader, m_board->Add( footprint, ADD_MODE::APPEND ); 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 ); diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index 93a23c3601..7e3076e9d1 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -613,7 +613,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadComponentLibrary() footprint->SetPosition( getKiCadPoint( component.Origin ) ); LIB_ID libID; - libID.Parse( fpName, LIB_ID::LIB_ID_TYPE::ID_PCB, true ); + libID.Parse( fpName, true ); footprint->SetFPID( libID ); loadLibraryFigures( component, footprint ); diff --git a/pcbnew/plugins/eagle/eagle_plugin.cpp b/pcbnew/plugins/eagle/eagle_plugin.cpp index daa00b25da..0c197ebe3c 100644 --- a/pcbnew/plugins/eagle/eagle_plugin.cpp +++ b/pcbnew/plugins/eagle/eagle_plugin.cpp @@ -1537,7 +1537,7 @@ FOOTPRINT* EAGLE_PLUGIN::makeFootprint( wxXmlNode* aPackage, const wxString& aPk std::unique_ptr m = std::make_unique( m_board ); LIB_ID fpID; - fpID.Parse( aPkgName, LIB_ID::ID_PCB, true ); + fpID.Parse( aPkgName, true ); m->SetFPID( fpID ); // Get the first package item and iterate diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index a693817e02..00e466c6ac 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -2860,7 +2860,7 @@ FOOTPRINT* PCB_PARSER::parseFOOTPRINT_unchecked( wxArrayString* aInitialComments name = FromUTF8(); - if( !name.IsEmpty() && fpid.Parse( name, LIB_ID::ID_PCB, true ) >= 0 ) + if( !name.IsEmpty() && fpid.Parse( name, true ) >= 0 ) { wxString error; error.Printf( _( "Invalid footprint ID in\nfile: \"%s\"\nline: %d\noffset: %d" ), diff --git a/pcbnew/plugins/legacy/legacy_plugin.cpp b/pcbnew/plugins/legacy/legacy_plugin.cpp index 8a14a09570..70a13bc1f0 100644 --- a/pcbnew/plugins/legacy/legacy_plugin.cpp +++ b/pcbnew/plugins/legacy/legacy_plugin.cpp @@ -435,7 +435,7 @@ void LEGACY_PLUGIN::loadAllSections( bool doAppend ) ReplaceIllegalFileNameChars( &fpName ); if( !fpName.empty() ) - fpid.Parse( fpName, LIB_ID::ID_PCB, true ); + fpid.Parse( fpName, true ); footprint->SetFPID( fpid ); diff --git a/pcbnew/plugins/pcad/pcb_footprint.cpp b/pcbnew/plugins/pcad/pcb_footprint.cpp index a741e05dd9..f822cce29e 100644 --- a/pcbnew/plugins/pcad/pcb_footprint.cpp +++ b/pcbnew/plugins/pcad/pcb_footprint.cpp @@ -510,7 +510,7 @@ void PCB_FOOTPRINT::AddToBoard() footprint->SetLastEditTime( 0 ); LIB_ID fpID; - fpID.Parse( m_compRef, LIB_ID::ID_PCB, true ); + fpID.Parse( m_compRef, true ); footprint->SetFPID( fpID ); // reference text