KiCad PCB EDA Suite
ARRAY_GRID_OPTIONS Struct Reference

#include <array_options.h>

Inheritance diagram for ARRAY_GRID_OPTIONS:
ARRAY_OPTIONS

Public Types

enum  ARRAY_TYPE_T { ARRAY_GRID, ARRAY_CIRCULAR }
 

Public Member Functions

 ARRAY_GRID_OPTIONS ()
 
TRANSFORM GetTransform (int aN, const VECTOR2I &aPos) const override
 Get the transform of the n-th point in the array. More...
 
int GetArraySize () const override
 The number of points in this array. More...
 
wxString GetItemNumber (int n) const override
 Get the position number (name) for the n'th array point. More...
 
bool ShouldNumberItems () const
 
void SetShouldNumber (bool aShouldNumber)
 
bool GetNumberingStartIsSpecified () const
 
void SetNumberingStartIsSpecified (bool aIsSpecified)
 

Public Attributes

long m_nx
 
long m_ny
 
bool m_horizontalThenVertical
 
bool m_reverseNumberingAlternate
 
VECTOR2I m_delta
 
VECTOR2I m_offset
 
long m_stagger
 
bool m_stagger_rows
 
bool m_2dArrayNumbering
 
ARRAY_AXIS m_pri_axis
 
ARRAY_AXIS m_sec_axis
 

Protected Attributes

ARRAY_TYPE_T m_type
 
bool m_shouldNumber
 True if this array numbers the new items. More...
 
bool m_numberingStartIsSpecified
 True if this array's number starts from the preset point False if the array numbering starts from some externally provided point. More...
 

Private Member Functions

VECTOR2I getGridCoords (int n) const
 

Detailed Description

Definition at line 123 of file array_options.h.

Member Enumeration Documentation

◆ ARRAY_TYPE_T

Enumerator
ARRAY_GRID 

A grid (x*y) array.

ARRAY_CIRCULAR 

A circular array.

Definition at line 39 of file array_options.h.

40  {
41  ARRAY_GRID,
43  };
A grid (x*y) array.
Definition: array_options.h:41

Constructor & Destructor Documentation

◆ ARRAY_GRID_OPTIONS()

ARRAY_GRID_OPTIONS::ARRAY_GRID_OPTIONS ( )
inline

Definition at line 125 of file array_options.h.

127  m_nx( 0 ),
128  m_ny( 0 ),
129  m_horizontalThenVertical( true ),
131  m_stagger( 0 ),
132  m_stagger_rows( true ),
133  m_2dArrayNumbering( false )
134  {
135  }
ARRAY_OPTIONS(ARRAY_TYPE_T aType)
Definition: array_options.h:45
A grid (x*y) array.
Definition: array_options.h:41
bool m_reverseNumberingAlternate

Member Function Documentation

◆ GetArraySize()

int ARRAY_GRID_OPTIONS::GetArraySize ( ) const
overridevirtual

The number of points in this array.

Implements ARRAY_OPTIONS.

Definition at line 29 of file array_options.cpp.

30 {
31  return m_nx * m_ny;
32 }

References m_nx, and m_ny.

◆ getGridCoords()

VECTOR2I ARRAY_GRID_OPTIONS::getGridCoords ( int  n) const
private

Definition at line 35 of file array_options.cpp.

36 {
37  const int axisSize = m_horizontalThenVertical ? m_nx : m_ny;
38 
39  int x = n % axisSize;
40  int y = n / axisSize;
41 
42  // reverse on this row/col?
43  if( m_reverseNumberingAlternate && ( y % 2 ) )
44  x = axisSize - x - 1;
45 
46  wxPoint coords( x, y );
47 
48  return coords;
49 }
bool m_reverseNumberingAlternate

References m_horizontalThenVertical, m_nx, m_ny, and m_reverseNumberingAlternate.

Referenced by GetItemNumber(), and GetTransform().

◆ GetItemNumber()

wxString ARRAY_GRID_OPTIONS::GetItemNumber ( int  n) const
overridevirtual

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

Parameters
narray point index, from 0 to GetArraySize() - 1
Returns
the point's name

Implements ARRAY_OPTIONS.

Definition at line 82 of file array_options.cpp.

83 {
84  wxString itemNum;
85 
86  if( m_2dArrayNumbering )
87  {
88  VECTOR2I coords = getGridCoords( n );
89 
90  itemNum << m_pri_axis.GetItemNumber( coords.x );
91  itemNum << m_sec_axis.GetItemNumber( coords.y );
92  }
93  else
94  {
95  itemNum << m_pri_axis.GetItemNumber( n );
96  }
97 
98  return itemNum;
99 }
wxString GetItemNumber(int n) const
Get the position number (name) for the n'th axis point.
Definition: array_axis.cpp:133
ARRAY_AXIS m_pri_axis
ARRAY_AXIS m_sec_axis
VECTOR2I getGridCoords(int n) const

References getGridCoords(), ARRAY_AXIS::GetItemNumber(), m_2dArrayNumbering, m_pri_axis, m_sec_axis, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ GetNumberingStartIsSpecified()

bool ARRAY_OPTIONS::GetNumberingStartIsSpecified ( ) const
inlineinherited
Returns
is the numbering is enabled and should start at a point specified in these options or is it implicit according to the calling code?

Definition at line 100 of file array_options.h.

101  {
103  }
bool m_numberingStartIsSpecified
True if this array's number starts from the preset point False if the array numbering starts from som...
bool m_shouldNumber
True if this array numbers the new items.

References ARRAY_OPTIONS::m_numberingStartIsSpecified, and ARRAY_OPTIONS::m_shouldNumber.

Referenced by ARRAY_PAD_NAME_PROVIDER::ARRAY_PAD_NAME_PROVIDER().

◆ GetTransform()

ARRAY_OPTIONS::TRANSFORM ARRAY_GRID_OPTIONS::GetTransform ( int  aN,
const VECTOR2I aPos 
) const
overridevirtual

Get the transform of the n-th point in the array.

Parameters
aNthe index of the array point (0 is the original point)
aPosthe existing item position
Returns
a transform (an offset and a rotation)

Implements ARRAY_OPTIONS.

Definition at line 52 of file array_options.cpp.

53 {
54  VECTOR2I point;
55 
56  VECTOR2I coords = getGridCoords( n );
57 
58  // swap axes if needed
60  std::swap( coords.x, coords.y );
61 
62  point.x = coords.x * m_delta.x + coords.y * m_offset.x;
63  point.y = coords.y * m_delta.y + coords.x * m_offset.y;
64 
65  if( std::abs( m_stagger ) > 1 )
66  {
67  const int stagger = std::abs( m_stagger );
68  const bool sr = m_stagger_rows;
69  const int stagger_idx = ( ( sr ? coords.y : coords.x ) % stagger );
70 
71  VECTOR2I stagger_delta( ( sr ? m_delta.x : m_offset.x ), ( sr ? m_offset.y : m_delta.y ) );
72 
73  // Stagger to the left/up if the sign of the stagger is negative
74  point += stagger_delta * copysign( stagger_idx, m_stagger ) / stagger;
75  }
76 
77  // this is already relative to the first array entry
78  return { point, 0.0 };
79 }
#define abs(a)
Definition: auxiliary.h:84
VECTOR2I getGridCoords(int n) const

References abs, getGridCoords(), m_delta, m_horizontalThenVertical, m_offset, m_stagger, m_stagger_rows, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SetNumberingStartIsSpecified()

void ARRAY_OPTIONS::SetNumberingStartIsSpecified ( bool  aIsSpecified)
inlineinherited

Definition at line 105 of file array_options.h.

106  {
107  m_numberingStartIsSpecified = aIsSpecified;
108  }
bool m_numberingStartIsSpecified
True if this array's number starts from the preset point False if the array numbering starts from som...

References ARRAY_OPTIONS::m_numberingStartIsSpecified.

◆ SetShouldNumber()

void ARRAY_OPTIONS::SetShouldNumber ( bool  aShouldNumber)
inlineinherited

Definition at line 90 of file array_options.h.

91  {
92  m_shouldNumber = aShouldNumber;
93  }
bool m_shouldNumber
True if this array numbers the new items.

References ARRAY_OPTIONS::m_shouldNumber.

◆ ShouldNumberItems()

bool ARRAY_OPTIONS::ShouldNumberItems ( ) const
inlineinherited
Returns
are the items in this array numbered, or are all the items numbered the same?

Definition at line 85 of file array_options.h.

86  {
87  return m_shouldNumber;
88  }
bool m_shouldNumber
True if this array numbers the new items.

References ARRAY_OPTIONS::m_shouldNumber.

Member Data Documentation

◆ m_2dArrayNumbering

bool ARRAY_GRID_OPTIONS::m_2dArrayNumbering

Definition at line 143 of file array_options.h.

Referenced by GetItemNumber().

◆ m_delta

VECTOR2I ARRAY_GRID_OPTIONS::m_delta

Definition at line 139 of file array_options.h.

Referenced by GetTransform().

◆ m_horizontalThenVertical

bool ARRAY_GRID_OPTIONS::m_horizontalThenVertical

Definition at line 138 of file array_options.h.

Referenced by getGridCoords(), and GetTransform().

◆ m_numberingStartIsSpecified

bool ARRAY_OPTIONS::m_numberingStartIsSpecified
protectedinherited

True if this array's number starts from the preset point False if the array numbering starts from some externally provided point.

Definition at line 119 of file array_options.h.

Referenced by ARRAY_OPTIONS::GetNumberingStartIsSpecified(), and ARRAY_OPTIONS::SetNumberingStartIsSpecified().

◆ m_nx

long ARRAY_GRID_OPTIONS::m_nx

Definition at line 137 of file array_options.h.

Referenced by GetArraySize(), and getGridCoords().

◆ m_ny

long ARRAY_GRID_OPTIONS::m_ny

Definition at line 137 of file array_options.h.

Referenced by GetArraySize(), and getGridCoords().

◆ m_offset

VECTOR2I ARRAY_GRID_OPTIONS::m_offset

Definition at line 140 of file array_options.h.

Referenced by GetTransform().

◆ m_pri_axis

ARRAY_AXIS ARRAY_GRID_OPTIONS::m_pri_axis

Definition at line 144 of file array_options.h.

Referenced by GetItemNumber().

◆ m_reverseNumberingAlternate

bool ARRAY_GRID_OPTIONS::m_reverseNumberingAlternate

Definition at line 138 of file array_options.h.

Referenced by getGridCoords().

◆ m_sec_axis

ARRAY_AXIS ARRAY_GRID_OPTIONS::m_sec_axis

Definition at line 144 of file array_options.h.

Referenced by GetItemNumber().

◆ m_shouldNumber

bool ARRAY_OPTIONS::m_shouldNumber
protectedinherited

True if this array numbers the new items.

Definition at line 115 of file array_options.h.

Referenced by ARRAY_OPTIONS::GetNumberingStartIsSpecified(), ARRAY_OPTIONS::SetShouldNumber(), and ARRAY_OPTIONS::ShouldNumberItems().

◆ m_stagger

long ARRAY_GRID_OPTIONS::m_stagger

Definition at line 141 of file array_options.h.

Referenced by GetTransform().

◆ m_stagger_rows

bool ARRAY_GRID_OPTIONS::m_stagger_rows

Definition at line 142 of file array_options.h.

Referenced by GetTransform().

◆ m_type

ARRAY_TYPE_T ARRAY_OPTIONS::m_type
protectedinherited

Definition at line 112 of file array_options.h.


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