From aae7d94ffd212ec05bb01c7324d194cfb6816b6f Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 25 Aug 2023 08:51:59 -0400 Subject: [PATCH] Remove duplicate references from change symbol dialog. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15480 (cherry picked from commit 1db9febcfe5e2b0ee1155ed78eb1c2e1a7bfe4e4) --- eeschema/dialogs/dialog_change_symbols.cpp | 10 ++++++++++ eeschema/sch_sheet_path.cpp | 11 +++++++++++ eeschema/sch_sheet_path.h | 2 ++ 3 files changed, 23 insertions(+) diff --git a/eeschema/dialogs/dialog_change_symbols.cpp b/eeschema/dialogs/dialog_change_symbols.cpp index 911c335556..7b6f7185d3 100644 --- a/eeschema/dialogs/dialog_change_symbols.cpp +++ b/eeschema/dialogs/dialog_change_symbols.cpp @@ -720,8 +720,18 @@ wxString DIALOG_CHANGE_SYMBOLS::getSymbolReferences( SCH_SYMBOL& aSymbol, const wxString references; LIB_ID oldId = aSymbol.GetLibId(); + SCH_EDIT_FRAME* parent = dynamic_cast< SCH_EDIT_FRAME* >( GetParent() ); + + wxCHECK( parent, msg ); + + SCH_SHEET_LIST sheets = parent->Schematic().GetSheets(); + for( const SCH_SYMBOL_INSTANCE& instance : aSymbol.GetInstanceReferences() ) { + // Only include the symbol instances for the current project. + if( !sheets.HasPath( instance.m_Path ) ) + continue; + if( references.IsEmpty() ) references = instance.m_Reference; else diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index c918b76813..e7214b9405 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -1302,3 +1302,14 @@ int SCH_SHEET_LIST::GetLastVirtualPageNumber() const return lastVirtualPageNumber; } + +bool SCH_SHEET_LIST::HasPath( const KIID_PATH& aPath ) const +{ + for( const SCH_SHEET_PATH& path : *this ) + { + if( path.Path() == aPath ) + return true; + } + + return false; +} diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index b47ba5d3de..048a4d42b6 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -672,6 +672,8 @@ public: void RemoveSymbolInstances( const SCH_SHEET_PATH& aPrefixSheetPath ); + bool HasPath( const KIID_PATH& aPath ) const; + private: SCH_SHEET_PATH m_currentSheetPath; };