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-2010 KiCad Developers, see change_log.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 <base_struct.h>
  32. #include <gal/color4d.h>
  33. #include <geometry/shape_poly_set.h>
  34. using KIGFX::COLOR4D;
  35. class wxDC;
  36. class GERBER_DRAW_ITEM;
  37. /**
  38. * Enum APERTURE_T
  39. * is the set of all gerber aperture types allowed, according to page 16 of
  40. * http://gerbv.sourceforge.net/docs/rs274xrevd_e.pdf
  41. */
  42. enum APERTURE_T {
  43. APT_CIRCLE = 'C', // Flashed shape: Circle with or without hole
  44. APT_RECT = 'R', // Flashed shape: Rectangle with or without hole
  45. APT_OVAL = '0', // Flashed shape: Oval with or without hole
  46. APT_POLYGON = 'P', // Flashed shape: Regular polygon (3 to 12 edges)
  47. // with or without hole. Can be rotated
  48. APT_MACRO = 'M' // Complex shape given by a macro definition (see AM_PRIMITIVE_ID)
  49. };
  50. // In aperture definition, round, oval and rectangular flashed shapes
  51. // can have a hole (round or rectangular)
  52. // this option is stored in .m_DrillShape D_CODE member
  53. enum APERTURE_DEF_HOLETYPE {
  54. APT_DEF_NO_HOLE = 0,
  55. APT_DEF_ROUND_HOLE,
  56. APT_DEF_RECT_HOLE
  57. };
  58. /* define min and max values for D Codes values.
  59. * note: values >= 0 and < FIRST_DCODE can be used for special purposes
  60. */
  61. #define FIRST_DCODE 10
  62. #define LAST_DCODE 10000
  63. #define TOOLS_MAX_COUNT (LAST_DCODE + 1)
  64. struct APERTURE_MACRO;
  65. /**
  66. * D_CODE
  67. * holds a gerber DCODE (also called Aperture) definition.
  68. */
  69. class D_CODE
  70. {
  71. private:
  72. APERTURE_MACRO* m_Macro; ///< no ownership, points to
  73. // GERBER.m_aperture_macros element
  74. /**
  75. * parameters used only when this D_CODE holds a reference to an aperture
  76. * macro, and these parameters would customize the macro.
  77. */
  78. std::vector<double> m_am_params;
  79. public:
  80. wxSize m_Size; ///< Horizontal and vertical dimensions.
  81. APERTURE_T m_Shape; ///< shape ( Line, rectangle, circle , oval .. )
  82. int m_Num_Dcode; ///< D code value ( >= 10 )
  83. wxSize m_Drill; ///< dimension of the hole (if any) (draill file)
  84. APERTURE_DEF_HOLETYPE m_DrillShape; ///< shape of the hole (0 = no hole, round = 1, rect = 2) */
  85. double m_Rotation; ///< shape rotation in degrees
  86. int m_EdgesCount; ///< in aperture definition Polygon only:
  87. ///< number of edges for the polygon
  88. bool m_InUse; ///< false if the aperure (previously defined)
  89. ///< is not used to draw something
  90. bool m_Defined; ///< false if the aperture is not defined in the header
  91. wxString m_AperFunction; ///< the aperture attribute (created by a %TA.AperFunction command)
  92. ///< attached to the D_CODE
  93. SHAPE_POLY_SET m_Polygon; /* Polygon used to draw APT_POLYGON shape and some other
  94. * complex shapes which are converted to polygon
  95. * (shapes with hole )
  96. */
  97. public:
  98. D_CODE( int num_dcode );
  99. ~D_CODE();
  100. void Clear_D_CODE_Data();
  101. /**
  102. * AppendParam()
  103. * Add a parameter to the D_CODE parameter list.
  104. * used to customize the corresponding aperture macro
  105. */
  106. void AppendParam( double aValue )
  107. {
  108. m_am_params.push_back( aValue );
  109. }
  110. /**
  111. * GetParamCount()
  112. * Returns the number of parameters stored in parameter list.
  113. */
  114. unsigned GetParamCount() const
  115. {
  116. return m_am_params.size();
  117. }
  118. /**
  119. * GetParam()
  120. * Returns a parameter stored in parameter list.
  121. * @param aIdx = index of parameter
  122. */
  123. double GetParam( unsigned aIdx ) const
  124. {
  125. wxASSERT( aIdx <= m_am_params.size() );
  126. if( aIdx <= m_am_params.size() )
  127. return m_am_params[aIdx - 1];
  128. else
  129. return 0;
  130. }
  131. void SetMacro( APERTURE_MACRO* aMacro )
  132. {
  133. m_Macro = aMacro;
  134. }
  135. APERTURE_MACRO* GetMacro() const { return m_Macro; }
  136. /**
  137. * Function ShowApertureType
  138. * returns a character string telling what type of aperture type \a aType is.
  139. * @param aType The aperture type to show.
  140. */
  141. static const wxChar* ShowApertureType( APERTURE_T aType );
  142. /**
  143. * Function DrawFlashedShape
  144. * Draw the dcode shape for flashed items.
  145. * When an item is flashed, the DCode shape is the shape of the item
  146. * @param aParent = the GERBER_DRAW_ITEM being drawn
  147. * @param aClipBox = DC clip box (NULL is no clip)
  148. * @param aDC = device context
  149. * @param aColor = the normal color to use
  150. * @param aShapePos = the actual shape position
  151. * @param aFilledShape = true to draw in filled mode, false to draw in sketch mode
  152. */
  153. void DrawFlashedShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox,
  154. wxDC* aDC, COLOR4D aColor,
  155. wxPoint aShapePos, bool aFilledShape );
  156. /**
  157. * Function DrawFlashedPolygon
  158. * a helper function used to draw the polygon stored ion m_PolyCorners
  159. * Draw some Apertures shapes when they are defined as filled polygons.
  160. * APT_POLYGON is always a polygon, but some complex shapes are also converted to
  161. * polygons (shapes with holes, some rotated shapes)
  162. * @param aParent = the GERBER_DRAW_ITEM being drawn
  163. * @param aClipBox = DC clip box (NULL is no clip)
  164. * @param aDC = device context
  165. * @param aColor = the normal color to use
  166. * @param aFilled = true to draw in filled mode, false to draw in sketch mode
  167. * @param aPosition = the actual shape position
  168. */
  169. void DrawFlashedPolygon( GERBER_DRAW_ITEM* aParent,
  170. EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor,
  171. bool aFilled, const wxPoint& aPosition );
  172. /**
  173. * Function ConvertShapeToPolygon
  174. * convert a shape to an equivalent polygon.
  175. * Arcs and circles are approximated by segments
  176. * Useful when a shape is not a graphic primitive (shape with hole,
  177. * rotated shape ... ) and cannot be easily drawn.
  178. */
  179. void ConvertShapeToPolygon();
  180. /**
  181. * Function GetShapeDim
  182. * calculates a value that can be used to evaluate the size of text
  183. * when displaying the D-Code of an item
  184. * due to the complexity of some shapes,
  185. * one cannot calculate the "size" of a shape (only a bounding box)
  186. * but here, the "dimension" of the shape is the diameter of the primitive
  187. * or for lines the width of the line if the shape is a line
  188. * @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
  189. * @return a dimension, or -1 if no dim to calculate
  190. */
  191. int GetShapeDim( GERBER_DRAW_ITEM* aParent );
  192. };
  193. #endif // ifndef _DCODE_H_