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.

233 lines
8.5 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 The 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 (plot commands)
  58. * Revision I1 permits apertures up to 2^31-1.
  59. */
  60. #define FIRST_DCODE 10
  61. #define LAST_DCODE 0x7FFFFFFF
  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. /**
  72. * @return true if aDcodeValue is valid ( >= FIRST_DCODE. )
  73. * Any value > 0x7FFFFFFF is a negative value for a int and is not acceptable
  74. * and is < FIRST_DCODE.
  75. */
  76. static bool IsValidDcodeValue( int aDcodeValue )
  77. {
  78. return aDcodeValue >= FIRST_DCODE;
  79. }
  80. void Clear_D_CODE_Data();
  81. /**
  82. * Add a parameter to the D_CODE parameter list.
  83. *
  84. * Used to customize the corresponding aperture macro.
  85. */
  86. void AppendParam( double aValue )
  87. {
  88. m_am_params.push_back( aValue );
  89. }
  90. /**
  91. * Return the number of parameters stored in parameter list.
  92. */
  93. unsigned GetParamCount() const
  94. {
  95. return m_am_params.size();
  96. }
  97. /**
  98. * Return a parameter stored in parameter list.
  99. *
  100. * @param aIdx is the index of parameter.
  101. * for n parameters from the Dcode definition, aIdx = 1 .. n, not 0
  102. */
  103. double GetParam( unsigned aIdx ) const
  104. {
  105. wxASSERT( aIdx <= m_am_params.size() );
  106. if( aIdx <= m_am_params.size() )
  107. return m_am_params[aIdx - 1];
  108. else
  109. return 0;
  110. }
  111. void SetMacro( APERTURE_MACRO* aMacro )
  112. {
  113. m_Macro = aMacro;
  114. }
  115. APERTURE_MACRO* GetMacro() const { return m_Macro; }
  116. /**
  117. * Return a character string telling what type of aperture type \a aType is.
  118. *
  119. * @param aType is the aperture type to show.
  120. */
  121. static const wxChar* ShowApertureType( APERTURE_T aType );
  122. /**
  123. * Draw the dcode shape for flashed items.
  124. *
  125. * When an item is flashed, the DCode shape is the shape of the item.
  126. *
  127. * @param aParent is the #GERBER_DRAW_ITEM being drawn.
  128. * @param aDC is the device context.
  129. * @param aColor is the normal color to use.
  130. * @param aShapePos is the actual shape position
  131. * @param aFilledShape set to true to draw in filled mode, false to draw in sketch mode
  132. */
  133. void DrawFlashedShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
  134. const COLOR4D& aColor,
  135. const VECTOR2I& aShapePos, bool aFilledShape );
  136. /**
  137. * A helper function used to draw the polygon stored in m_PolyCorners.
  138. *
  139. * Draw some Apertures shapes when they are defined as filled polygons. APT_POLYGON is
  140. * always a polygon, but some complex shapes are also converted to polygons (shapes with
  141. * holes, some rotated shapes).
  142. *
  143. * @param aParent is the #GERBER_DRAW_ITEM being drawn.
  144. * @param aDC is the device context.
  145. * @param aColor is the normal color to use.
  146. * @param aFilled set to true to draw in filled mode, false to draw in sketch mode.
  147. * @param aPosition is the actual shape position.
  148. */
  149. void DrawFlashedPolygon( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
  150. const COLOR4D& aColor,
  151. bool aFilled, const VECTOR2I& aPosition );
  152. /**
  153. * Convert a shape to an equivalent polygon.
  154. *
  155. * Arcs and circles are approximated by segments. Useful when a shape is not a graphic
  156. * primitive (shape with hole, rotated shape ... ) and cannot be easily drawn.
  157. * @param aParent is the #GERBER_DRAW_ITEM using this DCode.
  158. * Not used in all shapes, used for APT_MACRO
  159. */
  160. void ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent );
  161. /**
  162. * Calculate a value that can be used to evaluate the size of text when displaying the
  163. * D-Code of an item.
  164. *
  165. * Due to the complexity of some shapes, one cannot calculate the "size" of a shape (only
  166. * a bounding box) but here, the "dimension" of the shape is the diameter of the primitive
  167. * or for lines the width of the line if the shape is a line.
  168. *
  169. * @param aParent is the parent GERBER_DRAW_ITEM which is actually drawn.
  170. * @return a dimension, or -1 if no dim to calculate.
  171. */
  172. int GetShapeDim( GERBER_DRAW_ITEM* aParent );
  173. public:
  174. VECTOR2I m_Size; ///< Horizontal and vertical dimensions.
  175. APERTURE_T m_ApertType; ///< Aperture type ( Line, rectangle, circle,
  176. ///< oval poly, macro )
  177. int m_Num_Dcode; ///< D code value ( >= 10 )
  178. VECTOR2I m_Drill; ///< dimension of the hole (if any) (drill file)
  179. APERTURE_DEF_HOLETYPE m_DrillShape; ///< shape of the hole (0 = no hole, round = 1,
  180. ///< rect = 2).
  181. EDA_ANGLE m_Rotation; ///< shape rotation
  182. int m_EdgesCount; ///< in aperture definition Polygon only:
  183. ///< number of edges for the polygon
  184. bool m_InUse; ///< false if the aperture (previously defined)
  185. ///< is not used to draw something
  186. bool m_Defined; ///< false if the aperture is not defined in the header
  187. wxString m_AperFunction; ///< the aperture attribute (created by a
  188. ///< %TA.AperFunction command).
  189. ///< attached to the D_CODE
  190. SHAPE_POLY_SET m_Polygon; /* Polygon used to draw APT_POLYGON shape and some other
  191. * complex shapes which are converted to polygon
  192. * (shapes with hole )
  193. */
  194. private:
  195. APERTURE_MACRO* m_Macro; ///< no ownership, points to GERBER.m_aperture_macros element.
  196. /**
  197. * parameters used only when this D_CODE holds a reference to an aperture
  198. * macro, and these parameters would customize the macro.
  199. */
  200. std::vector<double> m_am_params;
  201. };
  202. #endif // ifndef _DCODE_H_