diff --git a/eeschema/sim/sim_serde.cpp b/eeschema/sim/sim_serde.cpp index 163c08db1e..e5c4e20e24 100644 --- a/eeschema/sim/sim_serde.cpp +++ b/eeschema/sim/sim_serde.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace SIM_SERDE_PARSER @@ -111,14 +112,27 @@ std::string SIM_SERDE::GeneratePins() const { std::string result; - for( int i = 0; i < m_model.GetPinCount(); ++i ) - { - const SIM_MODEL::PIN& pin = m_model.GetPin( i ); + std::vector> pins = m_model.GetPins(); + + // m_model.GetPins() returns pins in the order they appear in the model, but the keys in the + // key=value pairs we create here are symbol pin numbers, so we sort the pins so that they are + // ordered by the latter instead. + std::sort( pins.begin(), pins.end(), + []( const SIM_MODEL::PIN& lhs, const SIM_MODEL::PIN& rhs ) + { + return StrNumCmp( lhs.symbolPinNumber, rhs.symbolPinNumber, true ) < 0; + } ); + bool isFirst = true; + + for( const SIM_MODEL::PIN& pin : pins ) + { if( pin.symbolPinNumber != "" ) { - if( i != 0 ) + if( !isFirst ) result.append( " " ); + else + isFirst = false; result.append( fmt::format( "{}={}", pin.symbolPinNumber, pin.name ) ); }