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.

199 lines
5.7 KiB

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