You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef ARRAY_AXIS__H
  24. #define ARRAY_AXIS__H
  25. #include <kicommon.h>
  26. #include <optional>
  27. #include <wx/string.h>
  28. /**
  29. * Class that contains information about a single array axis and the numbering
  30. * of items along that axis.
  31. *
  32. * For example, a rectangular grid has two axes, X and Y, but a circular array
  33. * has only one, that runs around the circle.
  34. */
  35. class KICOMMON_API ARRAY_AXIS
  36. {
  37. public:
  38. enum NUMBERING_TYPE
  39. {
  40. NUMBERING_NUMERIC = 0, ///< Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
  41. NUMBERING_HEX,
  42. /**
  43. * Alphabet, excluding IOSQXZ
  44. *
  45. * Per ASME Y14.35M-1997 sec. 5.2 (previously MIL-STD-100 sec. 406.5) as these can be
  46. * confused with numerals and are often not used for pin numbering on BGAs, etc.
  47. */
  48. NUMBERING_ALPHA_NO_IOSQXZ,
  49. NUMBERING_ALPHA_FULL, ///< Full 26-character alphabet
  50. };
  51. /**
  52. * Check if a numbering type is a numeric type.
  53. */
  54. static bool TypeIsNumeric( NUMBERING_TYPE type )
  55. {
  56. return type == NUMBERING_NUMERIC || type == NUMBERING_HEX;
  57. };
  58. ARRAY_AXIS();
  59. /**
  60. * Get the alphabet for the current numbering scheme.
  61. * @param type the numbering scheme.
  62. * @return the alphabet (as a string).
  63. */
  64. const wxString& GetAlphabet() const;
  65. /**
  66. * Set the axis numbering type.
  67. */
  68. void SetAxisType( NUMBERING_TYPE aType );
  69. /**
  70. * Set the axis start (as a string, which should decode to a valid index
  71. * in the alphabet),
  72. */
  73. bool SetOffset( const wxString& aOffsetName );
  74. /**
  75. * Set the start offset for the series (e.g. 0 to start at 0/A, 4 to start
  76. * at 4/E).
  77. *
  78. * @param aOffset offset of the first item in the.
  79. */
  80. void SetOffset( int aOffset );
  81. /**
  82. * Get the numbering offset for the axis
  83. *
  84. * @return the current offset.
  85. */
  86. int GetOffset() const;
  87. /**
  88. * Set the skip between consecutive numbers (useful when doing a partial
  89. * array, e.g. only one side of a connector).
  90. */
  91. void SetStep( int aStep );
  92. /**
  93. * Get the position number (name) for the n'th axis point
  94. *
  95. * @param n array point index, from 0.
  96. * @return the point's name.
  97. */
  98. wxString GetItemNumber( int n ) const;
  99. private:
  100. /**
  101. * Get the numbering offset for a given numbering string
  102. *
  103. * @param str is a numbering string, say "B" or "5".
  104. * @return the offset, if found, else empty.
  105. */
  106. std::optional<int> getNumberingOffset( const wxString& str ) const;
  107. NUMBERING_TYPE m_type;
  108. int m_offset;
  109. /// Skip every 'n' numbers.
  110. int m_step;
  111. };
  112. #endif // ARRAY_AXIS__H