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.

222 lines
8.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2010 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
  5. * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file dcode.h
  27. */
  28. #ifndef _DCODE_H_
  29. #define _DCODE_H_
  30. #include <vector>
  31. #include <gal/color4d.h>
  32. #include <geometry/shape_poly_set.h>
  33. using KIGFX::COLOR4D;
  34. class wxDC;
  35. class GERBER_DRAW_ITEM;
  36. /**
  37. * The set of all gerber aperture types allowed
  38. * from ADD dcode command, like %ADD11C,0.304800*% to add a DCode number 11, circle shape
  39. */
  40. enum APERTURE_T {
  41. APT_CIRCLE = 'C', // Flashed shape: Circle with or without hole
  42. APT_RECT = 'R', // Flashed shape: Rectangle with or without hole
  43. APT_OVAL = '0', // Flashed shape: Oval with or without hole
  44. APT_POLYGON = 'P', // Flashed shape: Regular polygon (3 to 12 edges)
  45. // with or without hole. Can be rotated
  46. APT_MACRO = 'M' // Complex shape given by a macro definition (see AM_PRIMITIVE_ID)
  47. };
  48. // In aperture definition, round, oval and rectangular flashed shapes
  49. // can have a hole (round or rectangular)
  50. // this option is stored in .m_DrillShape D_CODE member
  51. enum APERTURE_DEF_HOLETYPE {
  52. APT_DEF_NO_HOLE = 0,
  53. APT_DEF_ROUND_HOLE,
  54. APT_DEF_RECT_HOLE
  55. };
  56. /* define min and max values for D Codes values.
  57. * note: values >= 0 and < FIRST_DCODE can be used for special purposes
  58. */
  59. #define FIRST_DCODE 10
  60. #define LAST_DCODE 10000
  61. #define TOOLS_MAX_COUNT (LAST_DCODE + 1)
  62. class APERTURE_MACRO;
  63. /**
  64. * A gerber DCODE (also called Aperture) definition.
  65. */
  66. class D_CODE
  67. {
  68. public:
  69. D_CODE( int num_dcode );
  70. ~D_CODE();
  71. void Clear_D_CODE_Data();
  72. /**
  73. * Add a parameter to the D_CODE parameter list.
  74. *
  75. * Used to customize the corresponding aperture macro.
  76. */
  77. void AppendParam( double aValue )
  78. {
  79. m_am_params.push_back( aValue );
  80. }
  81. /**
  82. * Return the number of parameters stored in parameter list.
  83. */
  84. unsigned GetParamCount() const
  85. {
  86. return m_am_params.size();
  87. }
  88. /**
  89. * Return a parameter stored in parameter list.
  90. *
  91. * @param aIdx is the index of parameter.
  92. * for n parameters from the Dcode definition, aIdx = 1 .. n, not 0
  93. */
  94. double GetParam( unsigned aIdx ) const
  95. {
  96. wxASSERT( aIdx <= m_am_params.size() );
  97. if( aIdx <= m_am_params.size() )
  98. return m_am_params[aIdx - 1];
  99. else
  100. return 0;
  101. }
  102. void SetMacro( APERTURE_MACRO* aMacro )
  103. {
  104. m_Macro = aMacro;
  105. }
  106. APERTURE_MACRO* GetMacro() const { return m_Macro; }
  107. /**
  108. * Return a character string telling what type of aperture type \a aType is.
  109. *
  110. * @param aType is the aperture type to show.
  111. */
  112. static const wxChar* ShowApertureType( APERTURE_T aType );
  113. /**
  114. * Draw the dcode shape for flashed items.
  115. *
  116. * When an item is flashed, the DCode shape is the shape of the item.
  117. *
  118. * @param aParent is the #GERBER_DRAW_ITEM being drawn.
  119. * @param aDC is the device context.
  120. * @param aColor is the normal color to use.
  121. * @param aShapePos is the actual shape position
  122. * @param aFilledShape set to true to draw in filled mode, false to draw in sketch mode
  123. */
  124. void DrawFlashedShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
  125. const COLOR4D& aColor,
  126. const VECTOR2I& aShapePos, bool aFilledShape );
  127. /**
  128. * A helper function used to draw the polygon stored in m_PolyCorners.
  129. *
  130. * Draw some Apertures shapes when they are defined as filled polygons. APT_POLYGON is
  131. * always a polygon, but some complex shapes are also converted to polygons (shapes with
  132. * holes, some rotated shapes).
  133. *
  134. * @param aParent is the #GERBER_DRAW_ITEM being drawn.
  135. * @param aDC is the device context.
  136. * @param aColor is the normal color to use.
  137. * @param aFilled set to true to draw in filled mode, false to draw in sketch mode.
  138. * @param aPosition is the actual shape position.
  139. */
  140. void DrawFlashedPolygon( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
  141. const COLOR4D& aColor,
  142. bool aFilled, const VECTOR2I& aPosition );
  143. /**
  144. * Convert a shape to an equivalent polygon.
  145. *
  146. * Arcs and circles are approximated by segments. Useful when a shape is not a graphic
  147. * primitive (shape with hole, rotated shape ... ) and cannot be easily drawn.
  148. * @param aParent is the #GERBER_DRAW_ITEM using this DCode.
  149. * Not used in all shapes, used for APT_MACRO
  150. */
  151. void ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent );
  152. /**
  153. * Calculate a value that can be used to evaluate the size of text when displaying the
  154. * D-Code of an item.
  155. *
  156. * Due to the complexity of some shapes, one cannot calculate the "size" of a shape (only
  157. * a bounding box) but here, the "dimension" of the shape is the diameter of the primitive
  158. * or for lines the width of the line if the shape is a line.
  159. *
  160. * @param aParent is the parent GERBER_DRAW_ITEM which is actually drawn.
  161. * @return a dimension, or -1 if no dim to calculate.
  162. */
  163. int GetShapeDim( GERBER_DRAW_ITEM* aParent );
  164. public:
  165. VECTOR2I m_Size; ///< Horizontal and vertical dimensions.
  166. APERTURE_T m_ApertType; ///< Aperture type ( Line, rectangle, circle,
  167. ///< oval poly, macro )
  168. int m_Num_Dcode; ///< D code value ( >= 10 )
  169. VECTOR2I m_Drill; ///< dimension of the hole (if any) (drill file)
  170. APERTURE_DEF_HOLETYPE m_DrillShape; ///< shape of the hole (0 = no hole, round = 1,
  171. ///< rect = 2).
  172. EDA_ANGLE m_Rotation; ///< shape rotation
  173. int m_EdgesCount; ///< in aperture definition Polygon only:
  174. ///< number of edges for the polygon
  175. bool m_InUse; ///< false if the aperture (previously defined)
  176. ///< is not used to draw something
  177. bool m_Defined; ///< false if the aperture is not defined in the header
  178. wxString m_AperFunction; ///< the aperture attribute (created by a
  179. ///< %TA.AperFunction command).
  180. ///< attached to the D_CODE
  181. SHAPE_POLY_SET m_Polygon; /* Polygon used to draw APT_POLYGON shape and some other
  182. * complex shapes which are converted to polygon
  183. * (shapes with hole )
  184. */
  185. private:
  186. APERTURE_MACRO* m_Macro; ///< no ownership, points to GERBER.m_aperture_macros element.
  187. /**
  188. * parameters used only when this D_CODE holds a reference to an aperture
  189. * macro, and these parameters would customize the macro.
  190. */
  191. std::vector<double> m_am_params;
  192. };
  193. #endif // ifndef _DCODE_H_