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
This commit is contained in:
Seth Hillbrand 2023-07-21 09:02:38 -07:00
parent e7af4b86b8
commit f7f67c6d53
3 changed files with 17 additions and 5 deletions

View File

@ -289,7 +289,7 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataToWindow()
} }
} }
std::set<std::shared_ptr<BUS_ALIAS>> sheetAliases = screen->GetBusAliases(); auto& sheetAliases = screen->GetBusAliases();
busAliases.insert( busAliases.end(), sheetAliases.begin(), sheetAliases.end() ); busAliases.insert( busAliases.end(), sheetAliases.begin(), sheetAliases.end() );
} }

View File

@ -302,7 +302,7 @@ int ERC_TESTER::TestConflictingBusAliases()
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() ) for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
{ {
const std::set< std::shared_ptr<BUS_ALIAS> > screen_aliases = screen->GetBusAliases(); const auto& screen_aliases = screen->GetBusAliases();
for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases ) for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
{ {

View File

@ -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<BUS_ALIAS> > GetBusAliases() const auto& GetBusAliases() const
{ {
return m_aliases; return m_aliases;
} }
@ -577,6 +577,18 @@ private:
*/ */
size_t getLibSymbolNameMatches( const SCH_SYMBOL& aSymbol, std::vector<wxString>& aMatches ); size_t getLibSymbolNameMatches( const SCH_SYMBOL& aSymbol, std::vector<wxString>& aMatches );
/**
* Compare two #BUS_ALIAS objects by name. For sorting in the set.
*/
struct BusAliasCmp
{
bool operator()( const std::shared_ptr<BUS_ALIAS>& a, const std::shared_ptr<BUS_ALIAS>& b ) const
{
return a->GetName() < b->GetName();
}
};
public: public:
/** /**
* last value for the zoom level, useful in Eeschema when changing the current displayed * last value for the zoom level, useful in Eeschema when changing the current displayed
@ -616,7 +628,7 @@ private:
bool m_fileExists; bool m_fileExists;
/// List of bus aliases stored in this screen. /// 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. /// Library symbols required for this schematic.
std::map<wxString, LIB_SYMBOL*> m_libSymbols; std::map<wxString, LIB_SYMBOL*> m_libSymbols;