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.

118 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 <core/optional.h>
  26. #include <wx/string.h>
  27. /**
  28. * Class that contains information about a single array axis and the numbering
  29. * of items along that axis.
  30. *
  31. * For example, a rectangular grid has two axes, X and Y, but a circular array
  32. * has only one, that runs around the circle.
  33. */
  34. class ARRAY_AXIS
  35. {
  36. public:
  37. enum NUMBERING_TYPE
  38. {
  39. NUMBERING_NUMERIC = 0, ///< Arabic numerals: 0,1,2,3,4,5,6,7,8,9,10,11...
  40. NUMBERING_HEX,
  41. NUMBERING_ALPHA_NO_IOSQXZ, /*!< Alphabet, excluding IOSQXZ
  42. *
  43. * Per ASME Y14.35M-1997 sec. 5.2 (previously MIL-STD-100 sec. 406.5)
  44. * as these can be confused with numerals and are often not used
  45. * for pin numbering on BGAs, etc
  46. */
  47. NUMBERING_ALPHA_FULL, ///< Full 26-character alphabet
  48. };
  49. ARRAY_AXIS();
  50. /**
  51. * Get the alphabet for the current numbering scheme.
  52. * @param type the numbering scheme
  53. * @return the alphabet (as a string)
  54. */
  55. const wxString& GetAlphabet() const;
  56. /**
  57. * Set the axis numbering type
  58. */
  59. void SetAxisType( NUMBERING_TYPE aType );
  60. /**
  61. * Set the axis start (as a string, which should decode to a valid index
  62. * in the alphabet)
  63. */
  64. bool SetOffset( const wxString& aOffsetName );
  65. /**
  66. * Set the start offset for the series (e.g. 0 to start at 0/A, 4 to start
  67. * at 4/E).
  68. *
  69. * @param aOffset offset of the first item in the
  70. */
  71. void SetOffset( int aOffset );
  72. /**
  73. * Get the numbering offset for the axis
  74. *
  75. * @return the current offset
  76. */
  77. int GetOffset() const;
  78. /**
  79. * Set the skip between consecutive numbers (useful when doing a partial
  80. * array, e.g. only one side of a connector)
  81. */
  82. void SetStep( int aStep );
  83. /**
  84. * Get the position number (name) for the n'th axis point
  85. *
  86. * @param n array point index, from 0
  87. * @return the point's name
  88. */
  89. wxString GetItemNumber( int n ) const;
  90. private:
  91. /**
  92. * Get the numbering offset for a given numbering string
  93. *
  94. * @param str a numbering string, say "B" or "5"
  95. * @return the offset, if found, else empty
  96. */
  97. OPT<int> getNumberingOffset( const wxString& str ) const;
  98. NUMBERING_TYPE m_type;
  99. int m_offset;
  100. ///< Skip every 'n' numbers
  101. int m_step;
  102. };
  103. #endif // ARRAY_AXIS__H