From 2fa05ed245f20140d1f22302696510d9ad981da8 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 21 Jul 2023 09:02:38 -0700 Subject: [PATCH] Sort the bus alias set by name If we place pointers in a set, they are sorted by the pointer value in memory, not the data, so we need a custom comparator Fixes https://gitlab.com/kicad/code/kicad/-/issues/11890 (cherry picked from commit f7f67c6d5397a32ab29db25a6c57ca2bc3e22d77) --- eeschema/dialogs/dialog_label_properties.cpp | 2 +- eeschema/erc.cpp | 2 +- eeschema/sch_screen.h | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/eeschema/dialogs/dialog_label_properties.cpp b/eeschema/dialogs/dialog_label_properties.cpp index 0bdc9c4076..cac61f0b76 100644 --- a/eeschema/dialogs/dialog_label_properties.cpp +++ b/eeschema/dialogs/dialog_label_properties.cpp @@ -291,7 +291,7 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataToWindow() } } - std::set> sheetAliases = screen->GetBusAliases(); + auto& sheetAliases = screen->GetBusAliases(); busAliases.insert( busAliases.end(), sheetAliases.begin(), sheetAliases.end() ); } diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index 760cf7c4e0..8f98d28dd0 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -307,7 +307,7 @@ int ERC_TESTER::TestConflictingBusAliases() for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) { - const std::set< std::shared_ptr > screen_aliases = screen->GetBusAliases(); + const auto& screen_aliases = screen->GetBusAliases(); for( const std::shared_ptr& alias : screen_aliases ) { diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index f1e7e1fce8..665ea9c29e 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -505,9 +505,9 @@ public: } /** - * Return a list of bus aliases defined in this screen + * Return a set of bus aliases defined in this screen */ - std::set< std::shared_ptr > GetBusAliases() const + auto& GetBusAliases() const { return m_aliases; } @@ -571,6 +571,18 @@ private: */ size_t getLibSymbolNameMatches( const SCH_SYMBOL& aSymbol, std::vector& aMatches ); + +/** + * Compare two #BUS_ALIAS objects by name. For sorting in the set. +*/ + struct BusAliasCmp + { + bool operator()( const std::shared_ptr& a, const std::shared_ptr& b ) const + { + return a->GetName() < b->GetName(); + } + }; + public: /** * last value for the zoom level, useful in Eeschema when changing the current displayed @@ -610,7 +622,7 @@ private: bool m_fileExists; /// List of bus aliases stored in this screen. - std::set< std::shared_ptr< BUS_ALIAS > > m_aliases; + std::set< std::shared_ptr< BUS_ALIAS >, BusAliasCmp > m_aliases; /// Library symbols required for this schematic. std::map m_libSymbols;