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.

220 lines
8.0 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, according to page 16 of
  38. * http://gerbv.sourceforge.net/docs/rs274xrevd_e.pdf
  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. */
  93. double GetParam( unsigned aIdx ) const
  94. {
  95. wxASSERT( aIdx <= m_am_params.size() );
  96. if( aIdx <= m_am_params.size() )
  97. return m_am_params[aIdx - 1];
  98. else
  99. return 0;
  100. }
  101. void SetMacro( APERTURE_MACRO* aMacro )
  102. {
  103. m_Macro = aMacro;
  104. }
  105. APERTURE_MACRO* GetMacro() const { return m_Macro; }
  106. /**
  107. * Return a character string telling what type of aperture type \a aType is.
  108. *
  109. * @param aType is the aperture type to show.
  110. */
  111. static const wxChar* ShowApertureType( APERTURE_T aType );
  112. /**
  113. * Draw the dcode shape for flashed items.
  114. *
  115. * When an item is flashed, the DCode shape is the shape of the item.
  116. *
  117. * @param aParent is the #GERBER_DRAW_ITEM being drawn.
  118. * @param aDC is the device context.
  119. * @param aColor is the normal color to use.
  120. * @param aShapePos is the actual shape position
  121. * @param aFilledShape set to true to draw in filled mode, false to draw in sketch mode
  122. */
  123. void DrawFlashedShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
  124. const COLOR4D& aColor,
  125. const VECTOR2I& aShapePos, bool aFilledShape );
  126. /**
  127. * A helper function used to draw the polygon stored in m_PolyCorners.
  128. *
  129. * Draw some Apertures shapes when they are defined as filled polygons. APT_POLYGON is
  130. * always a polygon, but some complex shapes are also converted to polygons (shapes with
  131. * holes, some rotated shapes).
  132. *
  133. * @param aParent is the #GERBER_DRAW_ITEM being drawn.
  134. * @param aDC is the device context.
  135. * @param aColor is the normal color to use.
  136. * @param aFilled set to true to draw in filled mode, false to draw in sketch mode.
  137. * @param aPosition is the actual shape position.
  138. */
  139. void DrawFlashedPolygon( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
  140. const COLOR4D& aColor,
  141. bool aFilled, const VECTOR2I& aPosition );
  142. /**
  143. * Convert a shape to an equivalent polygon.
  144. *
  145. * Arcs and circles are approximated by segments. Useful when a shape is not a graphic
  146. * primitive (shape with hole, rotated shape ... ) and cannot be easily drawn.
  147. * @param aParent is the #GERBER_DRAW_ITEM using this DCode.
  148. * Not used in all shapes, used for APT_MACRO
  149. */
  150. void ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent );
  151. /**
  152. * Calculate a value that can be used to evaluate the size of text when displaying the
  153. * D-Code of an item.
  154. *
  155. * Due to the complexity of some shapes, one cannot calculate the "size" of a shape (only
  156. * a bounding box) but here, the "dimension" of the shape is the diameter of the primitive
  157. * or for lines the width of the line if the shape is a line.
  158. *
  159. * @param aParent is the parent GERBER_DRAW_ITEM which is actually drawn.
  160. * @return a dimension, or -1 if no dim to calculate.
  161. */
  162. int GetShapeDim( GERBER_DRAW_ITEM* aParent );
  163. public:
  164. wxSize m_Size; ///< Horizontal and vertical dimensions.
  165. APERTURE_T m_Shape; ///< shape ( Line, rectangle, circle , oval .. )
  166. int m_Num_Dcode; ///< D code value ( >= 10 )
  167. wxSize m_Drill; ///< dimension of the hole (if any) (drill file)
  168. APERTURE_DEF_HOLETYPE m_DrillShape; ///< shape of the hole (0 = no hole, round = 1,
  169. ///< rect = 2).
  170. EDA_ANGLE m_Rotation; ///< shape rotation
  171. int m_EdgesCount; ///< in aperture definition Polygon only:
  172. ///< number of edges for the polygon
  173. bool m_InUse; ///< false if the aperture (previously defined)
  174. ///< is not used to draw something
  175. bool m_Defined; ///< false if the aperture is not defined in the header
  176. wxString m_AperFunction; ///< the aperture attribute (created by a
  177. ///< %TA.AperFunction command).
  178. ///< attached to the D_CODE
  179. SHAPE_POLY_SET m_Polygon; /* Polygon used to draw APT_POLYGON shape and some other
  180. * complex shapes which are converted to polygon
  181. * (shapes with hole )
  182. */
  183. private:
  184. APERTURE_MACRO* m_Macro; ///< no ownership, points to GERBER.m_aperture_macros element.
  185. /**
  186. * parameters used only when this D_CODE holds a reference to an aperture
  187. * macro, and these parameters would customize the macro.
  188. */
  189. std::vector<double> m_am_params;
  190. };
  191. #endif // ifndef _DCODE_H_