From 4acff58c7a8a0b2480a3f7689349508fdb386c74 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 2 Nov 2021 20:06:37 +0000 Subject: [PATCH] Implement a forced ordering for LIB_ITEMs until we have UUIDs. (Once we read/write the UUIDs, we should just compare the type and then the UUID like we do for SCH_ITEMs.) --- eeschema/lib_item.cpp | 6 +++++ .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 24 +++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/eeschema/lib_item.cpp b/eeschema/lib_item.cpp index 23a26a9cbd..c3d132b050 100644 --- a/eeschema/lib_item.cpp +++ b/eeschema/lib_item.cpp @@ -82,12 +82,18 @@ int LIB_ITEM::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareF bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const { + if( Type() != aOther.Type() ) + return false; + return compare( aOther ) == 0; } bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const { + if( Type() != aOther.Type() ) + return Type() < aOther.Type(); + return ( compare( aOther ) < 0 ); } diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index cba7ce0589..b3d378640e 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -764,10 +764,14 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet ) } // Enforce item ordering - auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) - { - return *a < *b; - }; + auto cmp = + []( const SCH_ITEM* a, const SCH_ITEM* b ) + { + if( a->Type() != b->Type() ) + return a->Type() < b->Type(); + + return a->m_Uuid < b->m_Uuid; + }; std::multiset save_map( cmp ); @@ -1822,7 +1826,19 @@ void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& a aFormatter.Print( aNestLevel + 1, "(symbol %s_%d_%d\"\n", name.c_str(), unit.m_unit, unit.m_convert ); + // Enforce item ordering + auto cmp = + []( const LIB_ITEM* a, const LIB_ITEM* b ) + { + return *a < *b; + }; + + std::multiset save_map( cmp ); + for( LIB_ITEM* item : unit.m_items ) + save_map.insert( item ); + + for( LIB_ITEM* item : save_map ) saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 ); aFormatter.Print( aNestLevel + 1, ")\n" );