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.

178 lines
5.1 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 PCBNEW_ARRAY_OPTIONS__H
  24. #define PCBNEW_ARRAY_OPTIONS__H
  25. #include <math/vector2d.h>
  26. #include <array_axis.h>
  27. /**
  28. * Options that govern the setup of an "array" of multiple item.
  29. * The base #ARRAY_OPTIONS do not encode a specific geometry or numbering
  30. * method, this is done by derived classes.
  31. */
  32. class ARRAY_OPTIONS
  33. {
  34. public:
  35. enum ARRAY_TYPE_T
  36. {
  37. ARRAY_GRID, ///< A grid (x*y) array
  38. ARRAY_CIRCULAR, ///< A circular array
  39. };
  40. ARRAY_OPTIONS( ARRAY_TYPE_T aType )
  41. : m_type( aType ), m_shouldNumber( false ), m_numberingStartIsSpecified( false )
  42. {
  43. }
  44. virtual ~ARRAY_OPTIONS(){};
  45. /**
  46. * Transform applied to an object by this array
  47. */
  48. struct TRANSFORM
  49. {
  50. VECTOR2I m_offset;
  51. double m_rotation; // in degrees
  52. };
  53. /**
  54. * Get the transform of the n-th point in the array
  55. * @param aN the index of the array point (0 is the original point)
  56. * @param aPos the existing item position
  57. * @return a transform (an offset and a rotation)
  58. */
  59. virtual TRANSFORM GetTransform( int aN, const VECTOR2I& aPos ) const = 0;
  60. /**
  61. * The number of points in this array
  62. */
  63. virtual int GetArraySize() const = 0;
  64. /**
  65. * Get the position number (name) for the n'th array point
  66. * @param n array point index, from 0 to GetArraySize() - 1
  67. * @return the point's name
  68. */
  69. virtual wxString GetItemNumber( int n ) const = 0;
  70. /*!
  71. * @return are the items in this array numbered, or are all the
  72. * items numbered the same?
  73. */
  74. bool ShouldNumberItems() const
  75. {
  76. return m_shouldNumber;
  77. }
  78. void SetShouldNumber( bool aShouldNumber )
  79. {
  80. m_shouldNumber = aShouldNumber;
  81. }
  82. /*!
  83. * @return is the numbering is enabled and should start at a point
  84. * specified in these options or is it implicit according to the calling
  85. * code?
  86. */
  87. bool GetNumberingStartIsSpecified() const
  88. {
  89. return m_shouldNumber && m_numberingStartIsSpecified;
  90. }
  91. void SetNumberingStartIsSpecified( bool aIsSpecified )
  92. {
  93. m_numberingStartIsSpecified = aIsSpecified;
  94. }
  95. protected:
  96. ARRAY_TYPE_T m_type;
  97. /// True if this array numbers the new items
  98. bool m_shouldNumber;
  99. /// True if this array's number starts from the preset point
  100. /// False if the array numbering starts from some externally provided point
  101. bool m_numberingStartIsSpecified;
  102. };
  103. struct ARRAY_GRID_OPTIONS : public ARRAY_OPTIONS
  104. {
  105. ARRAY_GRID_OPTIONS()
  106. : ARRAY_OPTIONS( ARRAY_GRID ),
  107. m_nx( 0 ),
  108. m_ny( 0 ),
  109. m_horizontalThenVertical( true ),
  110. m_reverseNumberingAlternate( false ),
  111. m_stagger( 0 ),
  112. m_stagger_rows( true ),
  113. m_2dArrayNumbering( false )
  114. {
  115. }
  116. long m_nx, m_ny;
  117. bool m_horizontalThenVertical, m_reverseNumberingAlternate;
  118. VECTOR2I m_delta;
  119. VECTOR2I m_offset;
  120. long m_stagger;
  121. bool m_stagger_rows;
  122. bool m_2dArrayNumbering;
  123. ARRAY_AXIS m_pri_axis, m_sec_axis;
  124. TRANSFORM GetTransform( int aN, const VECTOR2I& aPos ) const override;
  125. int GetArraySize() const override;
  126. wxString GetItemNumber( int n ) const override;
  127. private:
  128. VECTOR2I getGridCoords( int n ) const;
  129. };
  130. struct ARRAY_CIRCULAR_OPTIONS : public ARRAY_OPTIONS
  131. {
  132. ARRAY_CIRCULAR_OPTIONS()
  133. : ARRAY_OPTIONS( ARRAY_CIRCULAR ),
  134. m_nPts( 0 ),
  135. m_angle( 0.0f ),
  136. m_rotateItems( false )
  137. {
  138. }
  139. /// number of point in the array
  140. long m_nPts;
  141. /// angle between points, or 0 for each point separated by this value (decideg)
  142. double m_angle;
  143. VECTOR2I m_centre;
  144. bool m_rotateItems;
  145. ARRAY_AXIS m_axis;
  146. TRANSFORM GetTransform( int aN, const VECTOR2I& aPos ) const override;
  147. int GetArraySize() const override;
  148. wxString GetItemNumber( int n ) const override;
  149. };
  150. #endif // PCBNEW_ARRAY_OPTIONS__H