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.)
This commit is contained in:
Jeff Young 2021-11-02 20:06:37 +00:00
parent 522359ccbf
commit 4acff58c7a
2 changed files with 26 additions and 4 deletions

View File

@ -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 bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
{ {
if( Type() != aOther.Type() )
return false;
return compare( aOther ) == 0; return compare( aOther ) == 0;
} }
bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const
{ {
if( Type() != aOther.Type() )
return Type() < aOther.Type();
return ( compare( aOther ) < 0 ); return ( compare( aOther ) < 0 );
} }

View File

@ -764,9 +764,13 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet )
} }
// Enforce item ordering // Enforce item ordering
auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) auto cmp =
[]( const SCH_ITEM* a, const SCH_ITEM* b )
{ {
return *a < *b; if( a->Type() != b->Type() )
return a->Type() < b->Type();
return a->m_Uuid < b->m_Uuid;
}; };
std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp ); std::multiset<SCH_ITEM*, decltype( cmp )> 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", aFormatter.Print( aNestLevel + 1, "(symbol %s_%d_%d\"\n",
name.c_str(), unit.m_unit, unit.m_convert ); 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<LIB_ITEM*, decltype( cmp )> save_map( cmp );
for( LIB_ITEM* item : unit.m_items ) for( LIB_ITEM* item : unit.m_items )
save_map.insert( item );
for( LIB_ITEM* item : save_map )
saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 ); saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 );
aFormatter.Print( aNestLevel + 1, ")\n" ); aFormatter.Print( aNestLevel + 1, ")\n" );