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.

119 lines
3.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 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. NUMBERING_ALPHA_NO_IOSQXZ, /*!< Alphabet, excluding IOSQXZ
  43. *
  44. * Per ASME Y14.35M-1997 sec. 5.2 (previously MIL-STD-100 sec. 406.5)
  45. * as these can be confused with numerals and are often not used
  46. * for pin numbering on BGAs, etc
  47. */
  48. NUMBERING_ALPHA_FULL, ///< Full 26-character alphabet
  49. };
  50. ARRAY_AXIS();
  51. /**
  52. * Get the alphabet for the current numbering scheme.
  53. * @param type the numbering scheme
  54. * @return the alphabet (as a string)
  55. */
  56. const wxString& GetAlphabet() const;
  57. /**
  58. * Set the axis numbering type
  59. */
  60. void SetAxisType( NUMBERING_TYPE aType );
  61. /**
  62. * Set the axis start (as a string, which should decode to a valid index
  63. * in the alphabet)
  64. */
  65. bool SetOffset( const wxString& aOffsetName );
  66. /**
  67. * Set the start offset for the series (e.g. 0 to start at 0/A, 4 to start
  68. * at 4/E).
  69. *
  70. * @param aOffset offset of the first item in the
  71. */
  72. void SetOffset( int aOffset );
  73. /**
  74. * Get the numbering offset for the axis
  75. *
  76. * @return the current offset
  77. */
  78. int GetOffset() const;
  79. /**
  80. * Set the skip between consecutive numbers (useful when doing a partial
  81. * array, e.g. only one side of a connector)
  82. */
  83. void SetStep( int aStep );
  84. /**
  85. * Get the position number (name) for the n'th axis point
  86. *
  87. * @param n array point index, from 0
  88. * @return the point's name
  89. */
  90. wxString GetItemNumber( int n ) const;
  91. private:
  92. /**
  93. * Get the numbering offset for a given numbering string
  94. *
  95. * @param str a numbering string, say "B" or "5"
  96. * @return the offset, if found, else empty
  97. */
  98. std::optional<int> getNumberingOffset( const wxString& str ) const;
  99. NUMBERING_TYPE m_type;
  100. int m_offset;
  101. ///< Skip every 'n' numbers
  102. int m_step;
  103. };
  104. #endif // ARRAY_AXIS__H