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.

197 lines
7.2 KiB

  1. /*******************************************************************/
  2. /* class_gerber_draw_item.h: definitions relatives to tracks, vias and zones */
  3. /*******************************************************************/
  4. #ifndef CLASS_GERBER_DRAW_ITEM_H
  5. #define CLASS_GERBER_DRAW_ITEM_H
  6. /*
  7. * This program source code file is part of KICAD, a free EDA CAD application.
  8. *
  9. * Copyright (C) 1992-2010 <Jean-Pierre Charras>
  10. * Copyright (C) 1992-2010 Kicad Developers, see change_log.txt for contributors.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version 2
  15. * of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, you may find one here:
  24. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  25. * or you may search the http://www.gnu.org website for the version 2 license,
  26. * or you may write to the Free Software Foundation, Inc.,
  27. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  28. */
  29. #include "base_struct.h"
  30. #include "class_board_item.h"
  31. /* Shapes id for basic shapes ( .m_Shape member ) */
  32. enum Gbr_Basic_Shapes {
  33. GBR_SEGMENT = 0, // usual segment : line with rounded ends
  34. GBR_ARC, // Arcs (with rounded ends)
  35. GBR_CIRCLE, // ring
  36. GBR_POLYGON, // polygonal shape
  37. GBR_SPOT_CIRCLE, // flashed shape: round shape (can have hole)
  38. GBR_SPOT_RECT, // flashed shape: rectangular shape can have hole)
  39. GBR_SPOT_OVAL, // flashed shape: oval shape
  40. GBR_SPOT_POLY, // flashed shape: regulat polygon, 3 to 12 edges
  41. GBR_SPOT_MACRO, // complex shape described by a macro
  42. GBR_LAST // last value for this list
  43. };
  44. /***/
  45. class GERBER_DRAW_ITEM : public BOARD_ITEM
  46. {
  47. // make SetNext() and SetBack() private so that they may not be called from anywhere.
  48. // list management is done on GERBER_DRAW_ITEMs using DLIST<GERBER_DRAW_ITEM> only.
  49. private:
  50. void SetNext( EDA_BaseStruct* aNext ) { Pnext = aNext; }
  51. void SetBack( EDA_BaseStruct* aBack ) { Pback = aBack; }
  52. public:
  53. bool m_UnitsMetric; /* store here the gerber units (inch/mm).
  54. * Used only to calculate aperture macros shapes sizes */
  55. int m_Shape; // Shape and type of this gerber item
  56. wxPoint m_Start; // Line or arc start point or position of the shape
  57. // for flashed items
  58. wxPoint m_End; // Line or arc end point
  59. wxPoint m_ArcCentre; // for arcs only: Centre of arc
  60. std::vector <wxPoint> m_PolyCorners; // list of corners for polygons (G36 to G37 coordinates)
  61. // or for complex shapes which are converted to polygon
  62. wxSize m_Size; // Flashed shapes size of the shape
  63. // Lines : m_Size.x = m_Size.y = line width
  64. bool m_Flashed; // True for flashed items
  65. int m_DCode; // DCode used to draw this item.
  66. // 0 for items that do not use DCodes (polygons)
  67. // or when unknown and normal values are 10 to 999
  68. // values 0 to 9 can be used for special purposes
  69. public:
  70. GERBER_DRAW_ITEM( BOARD_ITEM* aParent );
  71. GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource );
  72. ~GERBER_DRAW_ITEM();
  73. /**
  74. * Function Copy
  75. * will copy this object
  76. * the corresponding type.
  77. * @return - GERBER_DRAW_ITEM*
  78. */
  79. GERBER_DRAW_ITEM* Copy() const;
  80. GERBER_DRAW_ITEM* Next() const { return (GERBER_DRAW_ITEM*) Pnext; }
  81. GERBER_DRAW_ITEM* Back() const { return (GERBER_DRAW_ITEM*) Pback; }
  82. int ReturnMaskLayer()
  83. {
  84. return 1 << m_Layer;
  85. }
  86. /**
  87. * Function Move
  88. * move this object.
  89. * @param const wxPoint& aMoveVector - the move vector for this object.
  90. */
  91. void Move( const wxPoint& aMoveVector );
  92. /**
  93. * Function GetPosition
  94. * returns the position of this object.
  95. * @return const wxPoint& - The position of this object.
  96. */
  97. wxPoint& GetPosition()
  98. {
  99. return m_Start; // it had to be start or end.
  100. }
  101. /**
  102. * Function GetDcodeDescr
  103. * returns the GetDcodeDescr of this object, or NULL.
  104. * @return D_CODE* - a pointer to the DCode description (for flashed items).
  105. */
  106. D_CODE* GetDcodeDescr();
  107. EDA_Rect GetBoundingBox();
  108. /* Display on screen: */
  109. void Draw( WinEDA_DrawPanel* aPanel,
  110. wxDC* aDC,
  111. int aDrawMode,
  112. const wxPoint& aOffset = ZeroOffset );
  113. /** function DrawGbrPoly
  114. * a helper function used id ::Draw to draw the polygon stored ion m_PolyCorners
  115. */
  116. void DrawGbrPoly( EDA_Rect* aClipBox,
  117. wxDC* aDC, int aColor,
  118. const wxPoint& aOffset, bool aFilledShape );
  119. /* divers */
  120. int Shape() const { return m_Shape; }
  121. /**
  122. * Function DisplayInfo
  123. * has knowledge about the frame and how and where to put status information
  124. * about this object into the frame's message panel.
  125. * Is virtual from EDA_BaseStruct.
  126. * Display info about the track segment and the full track length
  127. * @param frame A WinEDA_DrawFrame in which to print status information.
  128. */
  129. void DisplayInfo( WinEDA_DrawFrame* frame );
  130. wxString ShowGBRShape();
  131. /**
  132. * Function HitTest
  133. * tests if the given wxPoint is within the bounds of this object.
  134. * @param refPos A wxPoint to test
  135. * @return bool - true if a hit, else false
  136. */
  137. bool HitTest( const wxPoint& refPos );
  138. /**
  139. * Function HitTest (overlayed)
  140. * tests if the given wxRect intersect this object.
  141. * For now, an ending point must be inside this rect.
  142. * @param refPos A wxPoint to test
  143. * @return bool - true if a hit, else false
  144. */
  145. bool HitTest( EDA_Rect& refArea );
  146. /**
  147. * Function GetClass
  148. * returns the class name.
  149. * @return wxString
  150. */
  151. wxString GetClass() const
  152. {
  153. return wxT( "GERBER_DRAW_ITEM" );
  154. }
  155. bool Save( FILE* aFile ) const;
  156. #if defined(DEBUG)
  157. /**
  158. * Function Show
  159. * is used to output the object tree, currently for debugging only.
  160. * @param nestLevel An aid to prettier tree indenting, and is the level
  161. * of nesting of this object within the overall tree.
  162. * @param os The ostream& to output to.
  163. */
  164. virtual void Show( int nestLevel, std::ostream& os );
  165. #endif
  166. };
  167. #endif /* CLASS_GERBER_DRAW_ITEM_H */