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.

309 lines
11 KiB

14 years ago
  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>
  5. * Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file class_gerber_draw_item.h
  26. */
  27. #ifndef CLASS_GERBER_DRAW_ITEM_H
  28. #define CLASS_GERBER_DRAW_ITEM_H
  29. #include <base_struct.h>
  30. #include <dlist.h>
  31. #include <layers_id_colors_and_visibility.h>
  32. #include <gr_basic.h>
  33. class GERBER_IMAGE;
  34. class GBR_LAYOUT;
  35. class D_CODE;
  36. class MSG_PANEL_ITEM;
  37. /* Shapes id for basic shapes ( .m_Shape member ) */
  38. enum Gbr_Basic_Shapes {
  39. GBR_SEGMENT = 0, // usual segment : line with rounded ends
  40. GBR_ARC, // Arcs (with rounded ends)
  41. GBR_CIRCLE, // ring
  42. GBR_POLYGON, // polygonal shape
  43. GBR_SPOT_CIRCLE, // flashed shape: round shape (can have hole)
  44. GBR_SPOT_RECT, // flashed shape: rectangular shape can have hole)
  45. GBR_SPOT_OVAL, // flashed shape: oval shape
  46. GBR_SPOT_POLY, // flashed shape: regular polygon, 3 to 12 edges
  47. GBR_SPOT_MACRO, // complex shape described by a macro
  48. GBR_LAST // last value for this list
  49. };
  50. /***/
  51. class GERBER_DRAW_ITEM : public EDA_ITEM
  52. {
  53. // make SetNext() and SetBack() private so that they may not be called from anywhere.
  54. // list management is done on GERBER_DRAW_ITEMs using DLIST<GERBER_DRAW_ITEM> only.
  55. private:
  56. void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
  57. void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
  58. public:
  59. bool m_UnitsMetric; /* store here the gerber units (inch/mm). Used
  60. * only to calculate aperture macros shapes sizes */
  61. int m_Shape; // Shape and type of this gerber item
  62. wxPoint m_Start; // Line or arc start point or position of the shape
  63. // for flashed items
  64. wxPoint m_End; // Line or arc end point
  65. wxPoint m_ArcCentre; // for arcs only: Centre of arc
  66. std::vector <wxPoint> m_PolyCorners; // list of corners for polygons (G36 to G37 coordinates)
  67. // or for complex shapes which are converted to polygon
  68. wxSize m_Size; // Flashed shapes: size of the shape
  69. // Lines : m_Size.x = m_Size.y = line width
  70. bool m_Flashed; // True for flashed items
  71. int m_DCode; // DCode used to draw this item.
  72. // 0 for items that do not use DCodes (polygons)
  73. // or when unknown and normal values are 10 to 999
  74. // values 0 to 9 can be used for special purposes
  75. GERBER_IMAGE* m_imageParams; /* main GERBER info for this item
  76. * Note: some params stored in this class are common
  77. * to the whole gerber file (i.e) the whole graphic
  78. * layer and some can change when reaging the file,
  79. * so they are stored inside this item there is no
  80. * redundancy for these parameters
  81. */
  82. private:
  83. int m_Layer;
  84. // These values are used to draw this item, according to gerber layers parameters
  85. // Because they can change inside a gerber image, they are stored here
  86. // for each item
  87. bool m_LayerNegative; // true = item in negative Layer
  88. bool m_swapAxis; // false if A = X, B = Y; true if A =Y, B = Y
  89. bool m_mirrorA; // true: mirror / axe A
  90. bool m_mirrorB; // true: mirror / axe B
  91. wxRealPoint m_drawScale; // A and B scaling factor
  92. wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter
  93. double m_lyrRotation; // Fine rotation, from OR parameter, in degrees
  94. public:
  95. GERBER_DRAW_ITEM( GBR_LAYOUT* aParent, GERBER_IMAGE* aGerberparams );
  96. GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource );
  97. ~GERBER_DRAW_ITEM();
  98. /**
  99. * Function Copy
  100. * will copy this object
  101. * the corresponding type.
  102. * @return - GERBER_DRAW_ITEM*
  103. */
  104. GERBER_DRAW_ITEM* Copy() const;
  105. GERBER_DRAW_ITEM* Next() const { return static_cast<GERBER_DRAW_ITEM*>( Pnext ); }
  106. GERBER_DRAW_ITEM* Back() const { return static_cast<GERBER_DRAW_ITEM*>( Pback ); }
  107. /**
  108. * Function GetLayer
  109. * returns the layer this item is on.
  110. */
  111. int GetLayer() const { return m_Layer; }
  112. /**
  113. * Function SetLayer
  114. * sets the layer this item is on.
  115. * @param aLayer The layer number.
  116. * is virtual because some items (in fact: class DIMENSION)
  117. * have a slightly different initialization
  118. */
  119. void SetLayer( int aLayer ) { m_Layer = aLayer; }
  120. bool GetLayerPolarity()
  121. {
  122. return m_LayerNegative;
  123. }
  124. /**
  125. * Function HasNegativeItems
  126. * @return true if this item or at least one shape (when using aperture macros
  127. * must be drawn in background color
  128. * used to optimize screen refresh (when no items are in background color
  129. * refresh can be faster)
  130. */
  131. bool HasNegativeItems();
  132. /**
  133. * Function SetLayerParameters
  134. * Initialize parameters from Image and Layer parameters
  135. * found in the gerber file:
  136. * m_UnitsMetric,
  137. * m_MirrorA, m_MirrorB,
  138. * m_DrawScale, m_DrawOffset
  139. */
  140. void SetLayerParameters();
  141. void SetLayerPolarity( bool aNegative)
  142. {
  143. m_LayerNegative = aNegative;
  144. }
  145. /**
  146. * Function MoveAB
  147. * move this object.
  148. * @param aMoveVector - the move vector for this object.
  149. */
  150. void MoveAB( const wxPoint& aMoveVector );
  151. /**
  152. * Function MoveXY
  153. * move this object.
  154. * @param aMoveVector - the move vector for this object, in XY gerber axis.
  155. */
  156. void MoveXY( const wxPoint& aMoveVector );
  157. /**
  158. * Function GetPosition
  159. * returns the position of this object.
  160. * @return const wxPoint& - The position of this object.
  161. * This function exists mainly to satisfy the virtual GetPosition() in parent class
  162. */
  163. const wxPoint& GetPosition() const { return m_Start; }
  164. void SetPosition( const wxPoint& aPos ) { m_Start = aPos; }
  165. /**
  166. * Function GetABPosition
  167. * returns the image position of aPosition for this object.
  168. * Image position is the value of aPosition, modified by image parameters:
  169. * offsets, axis selection, scale, rotation
  170. * @param aXYPosition = position in X,Y gerber axis
  171. * @return const wxPoint - The given position in plotter A,B axis.
  172. */
  173. wxPoint GetABPosition( const wxPoint& aXYPosition ) const;
  174. /**
  175. * Function GetXYPosition
  176. * returns the image position of aPosition for this object.
  177. * Image position is the value of aPosition, modified by image parameters:
  178. * offsets, axis selection, scale, rotation
  179. * @param aABPosition = position in A,B plotter axis
  180. * @return const wxPoint - The given position in X,Y axis.
  181. */
  182. wxPoint GetXYPosition( const wxPoint& aABPosition ) const;
  183. /**
  184. * Function GetDcodeDescr
  185. * returns the GetDcodeDescr of this object, or NULL.
  186. * @return D_CODE* - a pointer to the DCode description (for flashed items).
  187. */
  188. D_CODE* GetDcodeDescr();
  189. const EDA_RECT GetBoundingBox() const; // Virtual
  190. /* Display on screen: */
  191. void Draw( EDA_DRAW_PANEL* aPanel,
  192. wxDC* aDC,
  193. GR_DRAWMODE aDrawMode,
  194. const wxPoint&aOffset );
  195. /**
  196. * Function ConvertSegmentToPolygon
  197. * convert a line to an equivalent polygon.
  198. * Useful when a line is plotted using a rectangular pen.
  199. * In this case, the usual segment plot function cannot be used
  200. */
  201. void ConvertSegmentToPolygon();
  202. /**
  203. * Function DrawGbrPoly
  204. * a helper function used to draw the polygon stored in m_PolyCorners
  205. */
  206. void DrawGbrPoly( EDA_RECT* aClipBox,
  207. wxDC* aDC, EDA_COLOR_T aColor,
  208. const wxPoint& aOffset, bool aFilledShape );
  209. /* divers */
  210. int Shape() const { return m_Shape; }
  211. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
  212. wxString ShowGBRShape();
  213. /**
  214. * Function HitTest
  215. * tests if the given wxPoint is within the bounds of this object.
  216. * @param aRefPos a wxPoint to test
  217. * @return bool - true if a hit, else false
  218. */
  219. bool HitTest( const wxPoint& aRefPos ) const;
  220. /**
  221. * Function HitTest (overloaded)
  222. * tests if the given wxRect intersect this object.
  223. * For now, an ending point must be inside this rect.
  224. * @param aRefArea a wxPoint to test
  225. * @return bool - true if a hit, else false
  226. */
  227. bool HitTest( const EDA_RECT& aRefArea ) const;
  228. /**
  229. * Function GetClass
  230. * returns the class name.
  231. * @return wxString
  232. */
  233. wxString GetClass() const
  234. {
  235. return wxT( "GERBER_DRAW_ITEM" );
  236. }
  237. /**
  238. * Function Save.
  239. * currently: no nothing, but must be defined to meet requirements
  240. * of the basic class
  241. */
  242. bool Save( FILE* aFile ) const;
  243. /**
  244. * Function UnLink
  245. * detaches this object from its owner.
  246. */
  247. void UnLink()
  248. {
  249. DLIST<GERBER_DRAW_ITEM>* list = (DLIST<GERBER_DRAW_ITEM>*) GetList();
  250. wxASSERT( list );
  251. if( list )
  252. list->Remove( this );
  253. }
  254. /**
  255. * Function DeleteStructure
  256. * deletes this object after UnLink()ing it from its owner.
  257. */
  258. void DeleteStructure()
  259. {
  260. UnLink();
  261. delete this;
  262. }
  263. #if defined(DEBUG)
  264. void Show( int nestLevel, std::ostream& os ) const; // override
  265. #endif
  266. };
  267. #endif /* CLASS_GERBER_DRAW_ITEM_H */