diff --git a/eeschema/cmp_tree_model_adapter.cpp b/eeschema/cmp_tree_model_adapter.cpp index 6055674a84..5501a73ded 100644 --- a/eeschema/cmp_tree_model_adapter.cpp +++ b/eeschema/cmp_tree_model_adapter.cpp @@ -47,22 +47,22 @@ void CMP_TREE_MODEL_ADAPTER::AddLibrary( wxString const& aLibNickname ) { bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER ); - wxArrayString aliases; + std::vector alias_list; try { - m_libs->EnumerateSymbolLib( aLibNickname, aliases, onlyPowerSymbols ); + m_libs->LoadSymbolLib( alias_list, aLibNickname, onlyPowerSymbols ); } catch( const IO_ERROR& ioe ) { - wxLogError( wxString::Format( _( "Error occurred loading symbol library %s." + wxLogError( wxString::Format( _( "Error occurred loading symbol library %s." "\n\n%s" ), aLibNickname, ioe.What() ) ); return; } - if( aliases.size() > 0 ) + if( alias_list.size() > 0 ) { - AddAliasList( aLibNickname, aliases ); + AddAliasList( aLibNickname, alias_list ); m_tree.AssignIntrinsicRanks(); } } diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 32e001101f..2fa204b9a2 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -310,6 +310,37 @@ SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname ) } +void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector& aAliasList, + const wxString& aNickname, bool aPowerSymbolsOnly ) +{ + SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); + wxCHECK( row && row->plugin, /* void */ ); + + wxString options = row->GetOptions(); + + if( aPowerSymbolsOnly ) + row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly ); + + row->plugin->EnumerateSymbolLib( aAliasList, row->GetFullURI( true ), row->GetProperties() ); + + if( aPowerSymbolsOnly ) + row->SetOptions( options ); + + // The library cannot know its own name, because it might have been renamed or moved. + // Therefore footprints cannot know their own library nickname when residing in + // a symbol library. + // Only at this API layer can we tell the symbol about its actual library nickname. + for( LIB_ALIAS* alias : aAliasList ) + { + // remove "const"-ness, I really do want to set nickname without + // having to copy the LIB_ID and its two strings, twice each. + LIB_ID& id = (LIB_ID&) alias->GetPart()->GetLibId(); + + id.SetLibNickname( row->GetNickName() ); + } +} + + LIB_ALIAS* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxString& aAliasName ) { const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index a2244bafd9..072c510c2a 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -160,6 +160,9 @@ public: void EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames, bool aPowerSymbolsOnly = false ); + void LoadSymbolLib( std::vector& aAliasList, const wxString& aNickname, + bool aPowerSymbolsOnly = false ); + /** * Load a #LIB_ALIAS having @a aAliasName from the library given by @a aNickname. *