From b99bd7633dfde69b177baa2c4c04ec5a473ff44f Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 17 Jan 2023 17:36:05 -0800 Subject: [PATCH] Allow commas, spaces in pad names for net-ties Net tie groups are currently separated by comma. But comma is also an allowed, albeit rare character for pad names. To allow pad names with commas in net tie groups, the group definition must be escaped with a forward slash for commas (and forward slashes). Pad 1,2 Pad 2,3 Net-tie group "1\,2,2\,3" Fixes https://gitlab.com/kicad/code/kicad/issues/13001 --- pcbnew/footprint.cpp | 61 +++++++++++++++++++++++++++++--------------- pcbnew/footprint.h | 2 +- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 6fc7a09825..0e08518a98 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -2288,11 +2288,36 @@ std::map FOOTPRINT::MapPadNumbersToNetTieGroups() const for( size_t ii = 0; ii < m_netTiePadGroups.size(); ++ii ) { - wxStringTokenizer groupParser( m_netTiePadGroups[ ii ], "," ); - std::vector numbersInGroup; + wxString group( m_netTiePadGroups[ ii ] ); + bool esc = false; + wxString pad; - while( groupParser.HasMoreTokens() ) - padNumberToGroupIdxMap[ groupParser.GetNextToken().Trim( false ).Trim( true ) ] = ii; + for( auto ch : group ) + { + if( esc ) + { + esc = false; + pad.Append( ch ); + continue; + } + + switch( static_cast( ch ) ) + { + case '\\': + esc = true; + break; + + case ',': + padNumberToGroupIdxMap[ pad ] = ii; + pad.Clear(); + break; + + default: + pad.Append( ch ); + break; + } + + } } return padNumberToGroupIdxMap; @@ -2582,25 +2607,21 @@ void FOOTPRINT::CheckNetTiePadGroups( const std::function padNumbers; wxString msg; - for( size_t ii = 0; ii < m_netTiePadGroups.size(); ++ii ) + auto ret = MapPadNumbersToNetTieGroups(); + + for( auto [ padNumber, _ ] : ret ) { - wxStringTokenizer groupParser( m_netTiePadGroups[ ii ], "," ); + const PAD* pad = FindPadByNumber( padNumber ); - while( groupParser.HasMoreTokens() ) + if( !pad ) { - wxString padNumber( groupParser.GetNextToken().Trim( false ).Trim( true ) ); - const PAD* pad = FindPadByNumber( padNumber ); - - if( !pad ) - { - msg.Printf( _( "(net-tie pad group contains unknown pad number %s)" ), padNumber ); - aErrorHandler( msg ); - } - else if( !padNumbers.insert( pad->GetNumber() ).second ) - { - msg.Printf( _( "(pad %s appears in more than one net-tie pad group)" ), padNumber ); - aErrorHandler( msg ); - } + msg.Printf( _( "(net-tie pad group contains unknown pad number %s)" ), padNumber ); + aErrorHandler( msg ); + } + else if( !padNumbers.insert( pad->GetNumber() ).second ) + { + msg.Printf( _( "(pad %s appears in more than one net-tie pad group)" ), padNumber ); + aErrorHandler( msg ); } } } diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index f1068a5d7b..349ed104c0 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -282,7 +282,7 @@ public: } /** - * @return a map from pad numbers to net-tie group indicies. If a pad is not a member of + * @return a map from pad numbers to net-tie group indices. If a pad is not a member of * a net-tie group its index will be -1. */ std::map MapPadNumbersToNetTieGroups() const;