diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 71be7dfdec..114f082f94 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -93,7 +93,7 @@ PART_LIB::~PART_LIB() } -void PART_LIB::GetEntryNames( wxArrayString& aNames ) +void PART_LIB::GetAliasNames( wxArrayString& aNames ) { for( LIB_ALIAS_MAP::iterator it = m_amap.begin(); it!=m_amap.end(); it++ ) { @@ -149,15 +149,6 @@ LIB_ALIAS* PART_LIB::FindAlias( const wxString& aName ) } -LIB_ALIAS* PART_LIB::GetFirstEntry() -{ - if( m_amap.size() ) - return m_amap.begin()->second; - else - return NULL; -} - - LIB_PART* PART_LIB::FindPart( const wxString& aName ) { #if 0 && defined(DEBUG) @@ -249,7 +240,7 @@ bool PART_LIB::AddPart( LIB_PART* aPart ) wxString aliasname = my_part->m_aliases[i]->GetName(); if( LIB_ALIAS* alias = FindAlias( aliasname ) ) - RemoveEntry( alias ); + RemoveAlias( alias ); m_amap[ aliasname ] = my_part->m_aliases[i]; } @@ -261,7 +252,7 @@ bool PART_LIB::AddPart( LIB_PART* aPart ) } -LIB_ALIAS* PART_LIB::RemoveEntry( LIB_ALIAS* aEntry ) +LIB_ALIAS* PART_LIB::RemoveAlias( LIB_ALIAS* aEntry ) { wxCHECK_MSG( aEntry != NULL, NULL, wxT( "NULL pointer cannot be removed from library." ) ); @@ -312,7 +303,7 @@ LIB_PART* PART_LIB::ReplacePart( LIB_PART* aOldPart, LIB_PART* aNewPart ) /* Remove the old root component. The component will automatically be deleted * when all it's aliases are deleted. Do not place any code that accesses * aOldPart inside this loop that gets evaluated after the last alias is - * removed in RemoveEntry(). Failure to heed this warning will result in a + * removed in RemoveAlias(). Failure to heed this warning will result in a * segfault. */ size_t i = aOldPart->m_aliases.size(); @@ -320,7 +311,7 @@ LIB_PART* PART_LIB::ReplacePart( LIB_PART* aOldPart, LIB_PART* aNewPart ) while( i > 0 ) { i -= 1; - RemoveEntry( aOldPart->m_aliases[ i ] ); + RemoveAlias( aOldPart->m_aliases[ i ] ); } LIB_PART* my_part = new LIB_PART( *aNewPart, this ); @@ -859,7 +850,7 @@ LIB_PART* PART_LIBS::FindLibPart( const wxString& aPartName, const wxString& aLi } -LIB_ALIAS* PART_LIBS::FindLibraryEntry( const wxString& aEntryName, const wxString& aLibraryName ) +LIB_ALIAS* PART_LIBS::FindLibraryAlias( const wxString& aEntryName, const wxString& aLibraryName ) { LIB_ALIAS* entry = NULL; @@ -890,24 +881,17 @@ void PART_LIBS::FindLibraryNearEntries( std::vector& aCandidates, if( !!aLibraryName && lib.GetName() != aLibraryName ) continue; - LIB_ALIAS* entry = lib.GetFirstEntry(); + wxArrayString aliasNames; - if( ! entry ) + lib.GetAliasNames( aliasNames ); + + if( aliasNames.IsEmpty() ) continue; - wxString first_entry_name = entry->GetName(); - wxString entry_name = first_entry_name; - - for( ;; ) + for( size_t i = 0; i < aliasNames.size(); i++ ) { - if( entry_name.CmpNoCase( aEntryName ) == 0 ) - aCandidates.push_back( entry ); - - entry = lib.GetNextEntry( entry_name ); - entry_name = entry->GetName(); - - if( first_entry_name == entry_name ) - break; + if( aliasNames[i].CmpNoCase( aEntryName ) == 0 ) + aCandidates.push_back( lib.FindAlias( aliasNames[i] ) ); } } } diff --git a/eeschema/class_library.h b/eeschema/class_library.h index 95c94515af..7f98c90ba5 100644 --- a/eeschema/class_library.h +++ b/eeschema/class_library.h @@ -233,8 +233,6 @@ public: */ void RemoveLibrary( const wxString& aName ); - void RemoveAllLibraries() { clear(); } - /** * Function LoadAllLibraries * loads all of the project's libraries into this container, which should @@ -301,18 +299,9 @@ public: * @param aLibraryName - Name of the library to search. * @return The entry object if found, otherwise NULL. */ - LIB_ALIAS* FindLibraryEntry( const wxString& aEntryName, + LIB_ALIAS* FindLibraryAlias( const wxString& aEntryName, const wxString& aLibraryName = wxEmptyString ); - /** - * Function FindLibraryEntries - * searches all libraries in the list for an entry, returns all matches. - * - * @param aEntryName - Name of entry to search for (case sensitive). - * @param aEntries - a std::vector to store entries - */ - // void FindLibraryEntries( const wxString& aEntryName, std::vector& aEntries ); - /** * Function FindLibraryNearEntries * Searches all libraries in the list for an entry, using a case insensitive comparison. @@ -436,7 +425,7 @@ public: * * @param aNames - String array to place entry names into. */ - void GetEntryNames( wxArrayString& aNames ); + void GetAliasNames( wxArrayString& aNames ); /** * Load a string array with the names of entries of type POWER in this library. @@ -509,7 +498,7 @@ public: * @param aEntry - Entry to remove from library. * @return The next entry in the library or NULL if the library is empty. */ - LIB_ALIAS* RemoveEntry( LIB_ALIAS* aEntry ); + LIB_ALIAS* RemoveAlias( LIB_ALIAS* aEntry ); /** * Replace an existing part entry in the library. @@ -520,13 +509,6 @@ public: */ LIB_PART* ReplacePart( LIB_PART* aOldPart, LIB_PART* aNewPart ); - /** - * Return the first entry in the library. - * - * @return The first entry or NULL if the library has no entries. - */ - LIB_ALIAS* GetFirstEntry(); - /** * Find next library entry by \a aName. * @@ -583,18 +565,6 @@ public: } - /** - * Function SetFileName - * sets the part library file name. - * - * @param aFileName - New library file name. - */ - void SetFileName( const wxString& aFileName ) - { - if( aFileName != fileName.GetFullName() ) - fileName = aFileName; - } - /** * Function LoadLibrary * allocates and loads a part library file. diff --git a/eeschema/component_tree_search_container.cpp b/eeschema/component_tree_search_container.cpp index 01cc334153..8159568731 100644 --- a/eeschema/component_tree_search_container.cpp +++ b/eeschema/component_tree_search_container.cpp @@ -141,7 +141,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddLibrary( PART_LIB& aLib ) if( m_filter == CMP_FILTER_POWER ) aLib.GetEntryTypePowerNames( all_aliases ); else - aLib.GetEntryNames( all_aliases ); + aLib.GetAliasNames( all_aliases ); AddAliasList( aLib.GetName(), all_aliases, &aLib ); @@ -164,7 +164,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddAliasList( const wxString& aNodeName, if( aOptionalLib ) a = aOptionalLib->FindAlias( aName ); else - a = m_libs->FindLibraryEntry( aName, wxEmptyString ); + a = m_libs->FindLibraryAlias( aName, wxEmptyString ); if( a == NULL ) continue; diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index fcb93de9d6..66d17b3fca 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -352,7 +352,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions() { PART_LIBS* libs = Prj().SchLibs(); - if( libs->FindLibraryEntry( newname ) == NULL ) + if( libs->FindLibraryAlias( newname ) == NULL ) { wxString msg = wxString::Format( _( "Component '%s' not found!" ), GetChars( newname ) ); diff --git a/eeschema/lib_export.cpp b/eeschema/lib_export.cpp index 6de8ff910a..ede7bd9ea2 100644 --- a/eeschema/lib_export.cpp +++ b/eeschema/lib_export.cpp @@ -78,18 +78,20 @@ void LIB_EDIT_FRAME::OnImportPart( wxCommandEvent& event ) return; } - LIB_ALIAS* entry = lib->GetFirstEntry(); + wxArrayString aliasNames; - if( !entry ) + lib->GetAliasNames( aliasNames ); + + if( aliasNames.IsEmpty() ) { - wxString msg = wxString::Format( _( - "Part library file '%s' is empty." ), - GetChars( fn.GetFullPath() ) - ); + wxString msg = wxString::Format( _( "Part library file '%s' is empty." ), + GetChars( fn.GetFullPath() ) ); DisplayError( this, msg ); return; } + LIB_ALIAS* entry = lib->FindAlias( aliasNames[0] ); + if( LoadOneLibraryPartAux( entry, lib.get() ) ) { DisplayLibInfos(); diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index f65cbbb993..aac007c2e9 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -147,7 +147,7 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) { // Not found in the active library: search inside the full list // (can happen when using Viewlib to load a component) - libEntry = Prj().SchLibs()->FindLibraryEntry( cmp_name ); + libEntry = Prj().SchLibs()->FindLibraryAlias( cmp_name ); if( libEntry ) { @@ -527,7 +527,7 @@ void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event ) } } - lib->GetEntryNames( nameList ); + lib->GetAliasNames( nameList ); if( nameList.IsEmpty() ) { @@ -567,7 +567,7 @@ void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event ) if( !part || !part->HasAlias( libEntry->GetName() ) ) { - lib->RemoveEntry( libEntry ); + lib->RemoveAlias( libEntry ); return; } @@ -581,7 +581,7 @@ void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event ) return; } - LIB_ALIAS* nextEntry = lib->RemoveEntry( libEntry ); + LIB_ALIAS* nextEntry = lib->RemoveAlias( libEntry ); if( nextEntry != NULL ) { diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index 526b562890..b99e025f1a 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -357,7 +357,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, PART_LIBS* } wxString msg; - LIB_ALIAS* libEntry = aLibs->FindLibraryEntry( Component->GetPartName() ); + LIB_ALIAS* libEntry = aLibs->FindLibraryAlias( Component->GetPartName() ); if( !Component->GetFlags() ) { @@ -412,7 +412,7 @@ void AddMenusForEditComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, PART_L wxString msg; LIB_PART* part = NULL; - LIB_ALIAS* libEntry = aLibs->FindLibraryEntry( Component->GetPartName() ); + LIB_ALIAS* libEntry = aLibs->FindLibraryAlias( Component->GetPartName() ); if( libEntry ) part = libEntry->GetPart(); diff --git a/eeschema/project_rescue.cpp b/eeschema/project_rescue.cpp index 4e06ce8b92..a4399af6c4 100644 --- a/eeschema/project_rescue.cpp +++ b/eeschema/project_rescue.cpp @@ -251,7 +251,7 @@ public: { wxString part_name( each_component->GetPartName() ); - LIB_ALIAS* case_sensitive_match = aRescuer.GetLibs()->FindLibraryEntry( part_name ); + LIB_ALIAS* case_sensitive_match = aRescuer.GetLibs()->FindLibraryAlias( part_name ); std::vector case_insensitive_matches; aRescuer.GetLibs()->FindLibraryNearEntries( case_insensitive_matches, part_name ); diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 64df7eecdc..d60c513dd8 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -299,7 +299,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) { if( PART_LIBS* libs = Prj().SchLibs() ) { - LIB_ALIAS* entry = libs->FindLibraryEntry( ( (SCH_COMPONENT*) item )->GetPartName() ); + LIB_ALIAS* entry = libs->FindLibraryAlias( ( (SCH_COMPONENT*) item )->GetPartName() ); if( entry && !!entry->GetDocFileName() ) { diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index ee6d031ea2..da5cdb9a8f 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -1172,7 +1172,7 @@ void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) { if( PART_LIBS* libs = Prj().SchLibs() ) { - LIB_ALIAS* entry = libs->FindLibraryEntry( component->GetPartName() ); + LIB_ALIAS* entry = libs->FindLibraryAlias( component->GetPartName() ); if( !entry ) // Should not occur return; diff --git a/eeschema/selpart.cpp b/eeschema/selpart.cpp index b0b36297b6..5ed2975f06 100644 --- a/eeschema/selpart.cpp +++ b/eeschema/selpart.cpp @@ -44,7 +44,7 @@ static void DisplayCmpDocAndKeywords( wxString& aName, void* aData ) wxASSERT( libs ); - LIB_ALIAS* part = libs->FindLibraryEntry( aName ); + LIB_ALIAS* part = libs->FindLibraryAlias( aName ); if( !part ) return; @@ -120,7 +120,7 @@ bool SCH_BASE_FRAME::DisplayListComponentsInLib( PART_LIB* aLibrary, if( aLibrary == NULL ) return false; - aLibrary->GetEntryNames( nameList ); + aLibrary->GetAliasNames( nameList ); wxArrayString headers; headers.Add( wxT("Component") ); diff --git a/eeschema/symbedit.cpp b/eeschema/symbedit.cpp index 0a1d6b6a05..bbd1209a3a 100644 --- a/eeschema/symbedit.cpp +++ b/eeschema/symbedit.cpp @@ -109,7 +109,13 @@ void LIB_EDIT_FRAME::LoadOneSymbol() wxMessageBox( msg, _( "Warning" ), wxOK | wxICON_EXCLAMATION, this ); } - LIB_PART* first = lib->GetFirstEntry()->GetPart(); + wxArrayString aliasNames; + + lib->GetAliasNames( aliasNames ); + + wxCHECK_RET( !aliasNames.IsEmpty(), "No aliases found in library " + filename ); + + LIB_PART* first = lib->FindAlias( aliasNames[0] )->GetPart(); LIB_ITEMS& drawList = first->GetDrawItemList(); for( LIB_ITEM& item : drawList ) diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index d2f4039c8f..d1966fa29c 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -406,7 +406,7 @@ void LIB_VIEW_FRAME::ReCreateListCmp() if( m_listPowerCmpOnly ) lib->GetEntryTypePowerNames( nameList ); else - lib->GetEntryNames( nameList ); + lib->GetAliasNames( nameList ); m_cmpList->Append( nameList ); diff --git a/eeschema/viewlibs.cpp b/eeschema/viewlibs.cpp index 7491975b5f..dfb228bc5a 100644 --- a/eeschema/viewlibs.cpp +++ b/eeschema/viewlibs.cpp @@ -72,7 +72,7 @@ void LIB_VIEW_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_LIBVIEW_VIEWDOC: - entry = Prj().SchLibs()->FindLibraryEntry( m_entryName, m_libraryName ); + entry = Prj().SchLibs()->FindLibraryAlias( m_entryName, m_libraryName ); if( entry && !entry->GetDocFileName().IsEmpty() ) { @@ -253,7 +253,7 @@ void LIB_VIEW_FRAME::ViewOneLibraryContent( PART_LIB* Lib, int Flag ) void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) { - LIB_ALIAS* entry = Prj().SchLibs()->FindLibraryEntry( m_entryName, m_libraryName ); + LIB_ALIAS* entry = Prj().SchLibs()->FindLibraryAlias( m_entryName, m_libraryName ); if( !entry ) return;