Allow lowercase letters for array tool pin numbering

The ARRAY_AXIS class now accepts lowercase letters (a-z) as input for
alphabetic numbering schemes and preserves that case in the output.
This allows users to create pin numbers like a1, b1, c1 which are
commonly used in DIN 41612 and other backplane connectors.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22787
This commit is contained in:
Seth Hillbrand
2026-01-19 15:02:54 -08:00
parent 3b3d640eed
commit 56b8309525
3 changed files with 94 additions and 3 deletions
+32 -3
View File
@@ -37,7 +37,11 @@ static bool schemeNonUnitColsStartAt0( ARRAY_AXIS::NUMBERING_TYPE type )
}
ARRAY_AXIS::ARRAY_AXIS() : m_type( NUMBERING_TYPE::NUMBERING_NUMERIC ), m_offset( 0 ), m_step( 1 )
ARRAY_AXIS::ARRAY_AXIS() :
m_type( NUMBERING_TYPE::NUMBERING_NUMERIC ),
m_offset( 0 ),
m_step( 1 ),
m_useLowercase( false )
{
}
@@ -76,7 +80,14 @@ std::optional<int> ARRAY_AXIS::getNumberingOffset( const wxString& str ) const
for( unsigned i = 0; i < str.length(); i++ )
{
int chIndex = alphabet.Find( str[i], false );
wxUniChar ch = str[i];
// For alphabetic types, convert to uppercase for lookup since our alphabets
// are defined with uppercase letters. This allows users to enter lowercase.
if( !TypeIsNumeric( m_type ) && ch >= 'a' && ch <= 'z' )
ch = ch - 'a' + 'A';
int chIndex = alphabet.Find( ch, false );
if( chIndex == wxNOT_FOUND )
return std::optional<int>{};
@@ -109,6 +120,18 @@ bool ARRAY_AXIS::SetOffset( const wxString& aOffsetName )
if( !offset )
return false;
// For alphabetic types, check if the user entered lowercase letters.
// If so, we'll output lowercase letters as well.
if( !TypeIsNumeric( m_type ) && !aOffsetName.IsEmpty() )
{
wxUniChar firstChar = aOffsetName[0];
m_useLowercase = ( firstChar >= 'a' && firstChar <= 'z' );
}
else
{
m_useLowercase = false;
}
SetOffset( *offset );
return true;
}
@@ -139,5 +162,11 @@ wxString ARRAY_AXIS::GetItemNumber( int n ) const
n = m_offset + m_step * n;
return AlphabeticFromIndex( n, alphabet, nonUnitColsStartAt0 );
wxString result = AlphabeticFromIndex( n, alphabet, nonUnitColsStartAt0 );
// If the user entered a lowercase starting value, output lowercase letters
if( m_useLowercase )
result = result.Lower();
return result;
}
+3
View File
@@ -125,6 +125,9 @@ private:
/// Skip every 'n' numbers.
int m_step;
/// Output lowercase letters when true (for alphabetic types).
bool m_useLowercase;
};
#endif // ARRAY_AXIS__H
+59
View File
@@ -105,6 +105,32 @@ BOOST_AUTO_TEST_CASE( ValidOffsets )
false,
0,
},
// Lowercase alphabetical input should be accepted and map to same offset as uppercase
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_FULL,
"a",
true,
0,
},
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_FULL,
"xy",
true,
648,
},
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_NO_IOSQXZ,
"a",
true,
0,
},
// Hex lowercase should NOT be accepted (hex only allows uppercase A-F)
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_HEX,
"a0",
false,
0,
},
};
// clang-format on
@@ -187,6 +213,39 @@ static const std::vector<ARRAY_AXIS_NAMING_CASE> axis_name_cases = {
6,
{ "11", "13", "15", "17", "19", "21" },
},
{
// Test lowercase alphabetical input produces lowercase output
"Alpha lowercase",
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_FULL,
"a",
1,
},
3,
{ "a", "b", "c" },
},
{
// Test lowercase alphabetical with 2nd col
"Alpha lowercase 2nd col",
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_FULL,
"y",
1,
},
4,
{ "y", "z", "aa", "ab" },
},
{
// Test lowercase no-IOSQXZ alphabet
"Alpha no IOSQXZ lowercase",
{
ARRAY_AXIS::NUMBERING_TYPE::NUMBERING_ALPHA_NO_IOSQXZ,
"a",
1,
},
5,
{ "a", "b", "c", "d", "e" },
},
};
// clang-format on