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.

314 lines
9.6 KiB

14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wandadoo.fr
  5. * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.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_board_item.h
  26. * @brief Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
  27. */
  28. #ifndef BOARD_ITEM_STRUCT_H
  29. #define BOARD_ITEM_STRUCT_H
  30. #include <base_struct.h>
  31. #include <convert_to_biu.h>
  32. #include <gr_basic.h>
  33. #include <layers_id_colors_and_visibility.h>
  34. class BOARD;
  35. class BOARD_ITEM_CONTAINER;
  36. class SHAPE_POLY_SET;
  37. class PCB_BASE_FRAME;
  38. /**
  39. * Enum STROKE_T
  40. * is the set of shapes for segments (graphic segments and tracks) which are often
  41. * in the .m_Shape member
  42. */
  43. enum STROKE_T
  44. {
  45. S_SEGMENT = 0, ///< usual segment : line with rounded ends
  46. S_RECT, ///< segment with non rounded ends
  47. S_ARC, ///< Arcs (with rounded ends)
  48. S_CIRCLE, ///< ring
  49. S_POLYGON, ///< polygon (not yet used for tracks, but could be in microwave apps)
  50. S_CURVE, ///< Bezier Curve
  51. S_LAST ///< last value for this list
  52. };
  53. /**
  54. * Class BOARD_ITEM
  55. * is a base class for any item which can be embedded within the BOARD
  56. * container class, and therefore instances of derived classes should only be
  57. * found in Pcbnew or other programs that use class BOARD and its contents.
  58. * The corresponding class in Eeschema is SCH_ITEM.
  59. */
  60. class BOARD_ITEM : public EDA_ITEM
  61. {
  62. protected:
  63. PCB_LAYER_ID m_Layer;
  64. static int getNextNumberInSequence( const std::set<int>& aSeq, bool aFillSequenceGaps );
  65. public:
  66. BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
  67. EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
  68. {
  69. }
  70. // Do not create a copy constructor & operator=.
  71. // The ones generated by the compiler are adequate.
  72. virtual const wxPoint GetPosition() const = 0;
  73. /**
  74. * Function GetCenter()
  75. *
  76. * This defaults to the same point as returned by GetPosition(), unless
  77. * overridden
  78. *
  79. * @return centre point of the item
  80. */
  81. virtual const wxPoint GetCenter() const { return GetPosition(); }
  82. virtual void SetPosition( const wxPoint& aPos ) = 0;
  83. /**
  84. * Function IsConnected()
  85. * Returns information if the object is derived from BOARD_CONNECTED_ITEM.
  86. * @return True if the object is of BOARD_CONNECTED_ITEM type, false otherwise.
  87. */
  88. virtual bool IsConnected() const
  89. {
  90. return false;
  91. }
  92. /**
  93. * @return true if the object is on any copper layer, false otherwise.
  94. */
  95. virtual bool IsOnCopperLayer() const
  96. {
  97. return IsCopperLayer( GetLayer() );
  98. }
  99. /**
  100. * A value of wxPoint(0,0) which can be passed to the Draw() functions.
  101. */
  102. static wxPoint ZeroOffset;
  103. BOARD_ITEM_CONTAINER* GetParent() const { return (BOARD_ITEM_CONTAINER*) m_Parent; }
  104. /**
  105. * Function GetLayer
  106. * returns the primary layer this item is on.
  107. */
  108. virtual PCB_LAYER_ID GetLayer() const { return m_Layer; }
  109. /**
  110. * Function GetLayerSet
  111. * returns a "layer mask", which is a bitmap of all layers on which the
  112. * TRACK segment or VIA physically resides.
  113. * @return int - a layer mask, see layers_id_colors_visibility.h.
  114. */
  115. virtual LSET GetLayerSet() const { return LSET( m_Layer ); }
  116. /**
  117. * Function SetLayer
  118. * sets the layer this item is on.
  119. * @param aLayer The layer number.
  120. * is virtual because some items (in fact: class DIMENSION)
  121. * have a slightly different initialization
  122. */
  123. virtual void SetLayer( PCB_LAYER_ID aLayer )
  124. {
  125. // trap any invalid layers, then go find the caller and fix it.
  126. // wxASSERT( unsigned( aLayer ) < unsigned( NB_PCB_LAYERS ) );
  127. m_Layer = aLayer;
  128. }
  129. /**
  130. * Function Print
  131. * BOARD_ITEMs have their own color information.
  132. */
  133. virtual void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset = ZeroOffset ) = 0;
  134. /**
  135. * Swap data between aItem and aImage.
  136. * aItem and aImage should have the same type
  137. * Used in undo redo command to swap values between an item and its copy
  138. * Only values like layer, size .. which are modified by editing are swapped,
  139. * not the pointers like
  140. * Pnext and Pback because aItem is not changed in the linked list
  141. * @param aImage = the item image which contains data to swap
  142. */
  143. virtual void SwapData( BOARD_ITEM* aImage );
  144. /**
  145. * Function IsOnLayer
  146. * tests to see if this object is on the given layer. Is virtual so
  147. * objects like D_PAD, which reside on multiple layers can do their own
  148. * form of testing.
  149. * @param aLayer The layer to test for.
  150. * @return bool - true if on given layer, else false.
  151. */
  152. virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
  153. {
  154. return m_Layer == aLayer;
  155. }
  156. /**
  157. * Function IsTrack
  158. * tests to see if this object is a track or via (or microvia).
  159. * form of testing.
  160. * @return bool - true if a track or via, else false.
  161. */
  162. bool IsTrack() const
  163. {
  164. return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
  165. }
  166. /**
  167. * Function IsLocked
  168. * @return bool - true if the object is locked, else false
  169. */
  170. virtual bool IsLocked() const
  171. {
  172. // only MODULEs & TRACKs can be locked at this time.
  173. return false;
  174. }
  175. /**
  176. * Function SetLocked
  177. * modifies 'lock' status for of the item.
  178. */
  179. virtual void SetLocked( bool aLocked )
  180. {
  181. // only MODULEs & TRACKs can be locked at this time.
  182. }
  183. /**
  184. * Function UnLink
  185. * detaches this object from its owner. This base class implementation
  186. * should work for all derived classes which are held in a DLIST<>.
  187. */
  188. virtual void UnLink();
  189. /**
  190. * Function DeleteStructure
  191. * deletes this object after UnLink()ing it from its owner if it has one.
  192. */
  193. void DeleteStructure();
  194. /**
  195. * Function ShowShape
  196. * converts the enum STROKE_T integer value to a wxString.
  197. */
  198. static wxString ShowShape( STROKE_T aShape );
  199. // Some geometric transforms, that must be rewritten for derived classes
  200. /**
  201. * Function Move
  202. * move this object.
  203. * @param aMoveVector - the move vector for this object.
  204. */
  205. virtual void Move( const wxPoint& aMoveVector )
  206. {
  207. wxFAIL_MSG( wxString::Format( wxT( "virtual BOARD_ITEM::Move called for %s" ),
  208. GetClass() ) );
  209. }
  210. void Move( const VECTOR2I& aMoveVector )
  211. {
  212. Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
  213. }
  214. /**
  215. * Function Rotate
  216. * Rotate this object.
  217. * @param aRotCentre - the rotation point.
  218. * @param aAngle - the rotation angle in 0.1 degree.
  219. */
  220. virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
  221. {
  222. wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
  223. }
  224. void Rotate( const VECTOR2I& aRotCentre, double aAngle )
  225. {
  226. Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
  227. }
  228. /**
  229. * Function Flip
  230. * Flip this object, i.e. change the board side for this object
  231. * @param aCentre - the rotation point.
  232. * @param aFlipLeftRight - mirror across Y axis instead of X (the default)
  233. */
  234. virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight )
  235. {
  236. wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
  237. }
  238. void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  239. {
  240. Flip( wxPoint( aCentre.x, aCentre.y ), aFlipLeftRight );
  241. }
  242. /**
  243. * Function GetBoard
  244. * returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
  245. */
  246. virtual BOARD* GetBoard() const;
  247. /**
  248. * Function GetLayerName
  249. * returns the name of the PCB layer on which the item resides.
  250. *
  251. * @return wxString containing the layer name associated with this item.
  252. */
  253. wxString GetLayerName() const;
  254. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  255. /**
  256. * Function TransformShapeWithClearanceToPolygon
  257. * Convert the item shape to a closed polygon
  258. * Used in filling zones calculations
  259. * Circles and arcs are approximated by segments
  260. * @param aCornerBuffer = a buffer to store the polygon
  261. * @param aClearanceValue = the clearance around the pad
  262. * @param aError = the maximum deviation from true circle
  263. * @param ignoreLineWidth = used for edge cut items where the line width is only
  264. * for visualization
  265. */
  266. virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  267. int aClearanceValue, int aError = ARC_LOW_DEF, bool ignoreLineWidth = false ) const;
  268. };
  269. #endif /* BOARD_ITEM_STRUCT_H */