KiCad PCB EDA Suite
ARRAY_AXIS Class Reference

Class that contains information about a single array axis and the numbering of items along that axis. More...

#include <array_axis.h>

Public Types

enum  NUMBERING_TYPE { NUMBERING_NUMERIC = 0, NUMBERING_HEX, NUMBERING_ALPHA_NO_IOSQXZ, NUMBERING_ALPHA_FULL }
 

Public Member Functions

 ARRAY_AXIS ()
 
const wxString & GetAlphabet () const
 Get the alphabet for the current numbering scheme. More...
 
void SetAxisType (NUMBERING_TYPE aType)
 Set the axis numbering type. More...
 
bool SetOffset (const wxString &aOffsetName)
 Set the axis start (as a string, which should decode to a valid index in the alphabet) More...
 
void SetOffset (int aOffset)
 Set the start offset for the series (e.g. More...
 
int GetOffset () const
 Get the numbering offset for the axis. More...
 
void SetStep (int aStep)
 Set the skip between consecutive numbers (useful when doing a partial array, e.g. More...
 
wxString GetItemNumber (int n) const
 Get the position number (name) for the n'th axis point. More...
 

Private Member Functions

OPT< int > getNumberingOffset (const wxString &str) const
 Get the numbering offset for a given numbering string. More...
 

Private Attributes

NUMBERING_TYPE m_type
 
int m_offset
 Skip every 'n' numbers. More...
 
int m_step
 

Detailed Description

Class that contains information about a single array axis and the numbering of items along that axis.

For example, a rectangular grid has two axes, X and Y, but a circular array has only one, that runs around the circle.

Definition at line 38 of file array_axis.h.

Member Enumeration Documentation

◆ NUMBERING_TYPE

Enumerator
NUMBERING_NUMERIC 

Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...

NUMBERING_HEX 
NUMBERING_ALPHA_NO_IOSQXZ 

Alphabet, excluding IOSQXZ

                            Per ASME Y14.35M-1997 sec. 5.2 (previously MIL-STD-100 sec. 406.5)
                            as these can be confused with numerals and are often not used
                            for pin numbering on BGAs, etc
NUMBERING_ALPHA_FULL 

Full 26-character alphabet.

Definition at line 41 of file array_axis.h.

Constructor & Destructor Documentation

◆ ARRAY_AXIS()

ARRAY_AXIS::ARRAY_AXIS ( )

Definition at line 38 of file array_axis.cpp.

38  : m_type( NUMBERING_TYPE::NUMBERING_NUMERIC ), m_offset( 0 ), m_step( 1 )
39 {
40 }
NUMBERING_TYPE m_type
Definition: array_axis.h:112
int m_offset
Skip every 'n' numbers.
Definition: array_axis.h:113

Member Function Documentation

◆ GetAlphabet()

const wxString & ARRAY_AXIS::GetAlphabet ( ) const

Get the alphabet for the current numbering scheme.

Parameters
typethe numbering scheme
Returns
the alphabet (as a string)

Definition at line 43 of file array_axis.cpp.

44 {
45  static const wxString alphaNumeric = "0123456789";
46  static const wxString alphaHex = "0123456789ABCDEF";
47  static const wxString alphaFull = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
48  static const wxString alphaNoIOSQXZ = "ABCDEFGHJKLMNPRTUVWY";
49 
50  switch( m_type )
51  {
52  default:
53  case NUMBERING_NUMERIC:
54  return alphaNumeric;
55  case NUMBERING_HEX:
56  return alphaHex;
58  return alphaNoIOSQXZ;
60  return alphaFull;
61  }
62 }
Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
Definition: array_axis.h:43
NUMBERING_TYPE m_type
Definition: array_axis.h:112
Full 26-character alphabet.
Definition: array_axis.h:51

References m_type, NUMBERING_ALPHA_FULL, NUMBERING_ALPHA_NO_IOSQXZ, NUMBERING_HEX, and NUMBERING_NUMERIC.

Referenced by GetItemNumber(), getNumberingOffset(), and validateAxisOptions().

◆ GetItemNumber()

wxString ARRAY_AXIS::GetItemNumber ( int  n) const

Get the position number (name) for the n'th axis point.

Parameters
narray point index, from 0
Returns
the point's name

Definition at line 133 of file array_axis.cpp.

134 {
135  wxString itemNum;
136  const wxString& alphabet = GetAlphabet();
137 
138  const bool nonUnitColsStartAt0 = schemeNonUnitColsStartAt0( m_type );
139 
140  bool firstRound = true;
141  int radix = alphabet.Length();
142 
143  n = m_offset + m_step * n;
144 
145  do
146  {
147  int modN = n % radix;
148 
149  if( nonUnitColsStartAt0 && !firstRound )
150  modN--; // Start the "tens/hundreds/etc column" at "Ax", not "Bx"
151 
152  itemNum.insert( 0, 1, alphabet[modN] );
153 
154  n /= radix;
155  firstRound = false;
156  } while( n );
157 
158  return itemNum;
159 }
static bool schemeNonUnitColsStartAt0(ARRAY_AXIS::NUMBERING_TYPE type)
Definition: array_axis.cpp:31
NUMBERING_TYPE m_type
Definition: array_axis.h:112
int m_offset
Skip every 'n' numbers.
Definition: array_axis.h:113
const wxString & GetAlphabet() const
Get the alphabet for the current numbering scheme.
Definition: array_axis.cpp:43

References GetAlphabet(), m_offset, m_step, m_type, and schemeNonUnitColsStartAt0().

Referenced by ARRAY_GRID_OPTIONS::GetItemNumber(), and ARRAY_CIRCULAR_OPTIONS::GetItemNumber().

◆ getNumberingOffset()

OPT< int > ARRAY_AXIS::getNumberingOffset ( const wxString &  str) const
private

Get the numbering offset for a given numbering string.

Parameters
stra numbering string, say "B" or "5"
Returns
the offset, if found, else empty

Definition at line 65 of file array_axis.cpp.

66 {
67  if( str.length() == 0 )
68  return OPT<int>{};
69 
70  const wxString& alphabet = GetAlphabet();
71 
72  int offset = 0;
73  const int radix = alphabet.length();
74 
75  for( unsigned i = 0; i < str.length(); i++ )
76  {
77  int chIndex = alphabet.Find( str[i], false );
78 
79  if( chIndex == wxNOT_FOUND )
80  return OPT<int>{};
81 
82  const bool start0 = schemeNonUnitColsStartAt0( m_type );
83 
84  // eg "AA" is actually index 27, not 26
85  if( start0 && i < str.length() - 1 )
86  chIndex++;
87 
88  offset *= radix;
89  offset += chIndex;
90  }
91 
92  return OPT<int>{ offset };
93 }
static bool schemeNonUnitColsStartAt0(ARRAY_AXIS::NUMBERING_TYPE type)
Definition: array_axis.cpp:31
NUMBERING_TYPE m_type
Definition: array_axis.h:112
const string & str
Definition: json11.cpp:648
size_t i
Definition: json11.cpp:649
boost::optional< T > OPT
Definition: optional.h:7
const wxString & GetAlphabet() const
Get the alphabet for the current numbering scheme.
Definition: array_axis.cpp:43

References GetAlphabet(), i, m_type, schemeNonUnitColsStartAt0(), and str.

Referenced by SetOffset().

◆ GetOffset()

int ARRAY_AXIS::GetOffset ( ) const

Get the numbering offset for the axis.

Returns
the current offset

Definition at line 121 of file array_axis.cpp.

122 {
123  return m_offset;
124 }
int m_offset
Skip every 'n' numbers.
Definition: array_axis.h:113

References m_offset.

◆ SetAxisType()

void ARRAY_AXIS::SetAxisType ( NUMBERING_TYPE  aType)

Set the axis numbering type.

Definition at line 96 of file array_axis.cpp.

97 {
98  m_type = aType;
99 }
NUMBERING_TYPE m_type
Definition: array_axis.h:112

References m_type.

Referenced by validateAxisOptions().

◆ SetOffset() [1/2]

bool ARRAY_AXIS::SetOffset ( const wxString &  aOffsetName)

Set the axis start (as a string, which should decode to a valid index in the alphabet)

Definition at line 102 of file array_axis.cpp.

103 {
104  OPT<int> offset = getNumberingOffset( aOffsetName );
105 
106  // The string does not decode to a valid offset
107  if( !offset )
108  return false;
109 
110  SetOffset( *offset );
111  return true;
112 }
OPT< int > getNumberingOffset(const wxString &str) const
Get the numbering offset for a given numbering string.
Definition: array_axis.cpp:65
bool SetOffset(const wxString &aOffsetName)
Set the axis start (as a string, which should decode to a valid index in the alphabet)
Definition: array_axis.cpp:102
boost::optional< T > OPT
Definition: optional.h:7

References getNumberingOffset().

Referenced by validateAxisOptions().

◆ SetOffset() [2/2]

void ARRAY_AXIS::SetOffset ( int  aOffset)

Set the start offset for the series (e.g.

0 to start at 0/A, 4 to start at 4/E).

Parameters
aOffsetoffset of the first item in the

Definition at line 115 of file array_axis.cpp.

116 {
117  m_offset = aOffset;
118 }
int m_offset
Skip every 'n' numbers.
Definition: array_axis.h:113

References m_offset.

◆ SetStep()

void ARRAY_AXIS::SetStep ( int  aStep)

Set the skip between consecutive numbers (useful when doing a partial array, e.g.

only one side of a connector)

Definition at line 127 of file array_axis.cpp.

128 {
129  m_step = aStep;
130 }

References m_step.

Referenced by validateAxisOptions().

Member Data Documentation

◆ m_offset

int ARRAY_AXIS::m_offset
private

Skip every 'n' numbers.

Definition at line 113 of file array_axis.h.

Referenced by GetItemNumber(), GetOffset(), and SetOffset().

◆ m_step

int ARRAY_AXIS::m_step
private

Definition at line 116 of file array_axis.h.

Referenced by GetItemNumber(), and SetStep().

◆ m_type

NUMBERING_TYPE ARRAY_AXIS::m_type
private

Definition at line 112 of file array_axis.h.

Referenced by GetAlphabet(), GetItemNumber(), getNumberingOffset(), and SetAxisType().


The documentation for this class was generated from the following files: