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.

892 lines
34 KiB

14 years ago
8 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
11 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
18 years ago
18 years ago
14 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
14 years ago
14 years ago
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 wanadoo.fr
  5. * Copyright (C) 1992-2018 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_pad.h
  26. * @brief Pad object description
  27. */
  28. #ifndef PAD_H_
  29. #define PAD_H_
  30. #include <pcbnew.h>
  31. #include <class_board_item.h>
  32. #include <board_connected_item.h>
  33. #include <pad_shapes.h>
  34. #include <geometry/shape_poly_set.h>
  35. #include <config_params.h> // PARAM_CFG_ARRAY
  36. #include "zones.h"
  37. class DRAWSEGMENT;
  38. enum CUST_PAD_SHAPE_IN_ZONE
  39. {
  40. CUST_PAD_SHAPE_IN_ZONE_OUTLINE,
  41. CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL
  42. };
  43. class LINE_READER;
  44. class EDA_3D_CANVAS;
  45. class EDA_DRAW_PANEL;
  46. class MODULE;
  47. class EDGE_MODULE;
  48. class TRACK;
  49. class MSG_PANEL_INFO;
  50. namespace KIGFX
  51. {
  52. class VIEW;
  53. }
  54. // Helper class to store parameters used to draw a pad
  55. class PAD_DRAWINFO
  56. {
  57. public:
  58. EDA_DRAW_PANEL* m_DrawPanel; // the EDA_DRAW_PANEL used to draw a PAD ; can be null
  59. GR_DRAWMODE m_DrawMode; // the draw mode
  60. COLOR4D m_Color; // color used to draw the pad shape , from pad layers and
  61. // visible layers
  62. COLOR4D m_HoleColor; // color used to draw the pad hole
  63. COLOR4D m_NPHoleColor; // color used to draw a pad Not Plated hole
  64. COLOR4D m_NoNetMarkColor; // color used to draw a mark on pads having no net
  65. int m_PadClearance; // clearance value, used to draw the pad area outlines
  66. wxSize m_Mask_margin; // margin, used to draw solder paste when only one layer is shown
  67. bool m_Display_padnum; // true to show pad number
  68. bool m_Display_netname; // true to show net name
  69. bool m_ShowPadFilled; // true to show pad as solid area, false to show pas in
  70. // sketch mode
  71. bool m_ShowNCMark; // true to show pad not connected mark
  72. bool m_ShowNotPlatedHole; // true when the pad hole in not plated, to draw a specific
  73. // pad shape
  74. bool m_IsPrinting; // true to print, false to display on screen.
  75. wxPoint m_Offset; // general draw offset
  76. PAD_DRAWINFO();
  77. };
  78. /** Helper class to handle a primitive (basic shape: polygon, segment, circle or arc)
  79. * to build a custom pad full shape from a set of primitives
  80. */
  81. class PAD_CS_PRIMITIVE
  82. {
  83. public:
  84. STROKE_T m_Shape; /// S_SEGMENT, S_ARC, S_CIRCLE, S_POLYGON only (same as DRAWSEGMENT)
  85. int m_Thickness; /// thickness of segment or outline
  86. /// For filled S_CIRCLE shape, thickness = 0.
  87. // if thickness is not = 0 S_CIRCLE shape is a ring
  88. int m_Radius; /// radius of a circle
  89. double m_ArcAngle; /// angle of an arc, from its starting point, in 0.1 deg
  90. wxPoint m_Start; /// is also the center of the circle and arc
  91. wxPoint m_End; /// is also the start point of the arc
  92. std::vector<wxPoint> m_Poly;
  93. PAD_CS_PRIMITIVE( STROKE_T aShape ):
  94. m_Shape( aShape ), m_Thickness( 0 ), m_Radius( 0 ), m_ArcAngle( 0 )
  95. {
  96. }
  97. // Accessors (helpers for arc and circle shapes)
  98. wxPoint GetCenter() { return m_Start; } /// returns the center of a circle or arc
  99. wxPoint GetArcStart() { return m_End; } /// returns the start point of an arc
  100. // Geometric transform
  101. /** Move the primitive
  102. * @param aMoveVector is the deplacement vector
  103. */
  104. void Move( wxPoint aMoveVector );
  105. /** Export the PAD_CS_PRIMITIVE parameters to a DRAWSEGMENT
  106. * useful to draw a primitive shape
  107. * @param aTarget is the DRAWSEGMENT to initialize
  108. */
  109. void ExportTo( DRAWSEGMENT* aTarget );
  110. /** Export the PAD_CS_PRIMITIVE parameters to a EDGE_MODULE
  111. * useful to convert a primitive shape to a EDGE_MODULE shape for editing in footprint editor
  112. * @param aTarget is the EDGE_MODULE to initialize
  113. */
  114. void ExportTo( EDGE_MODULE* aTarget );
  115. };
  116. class D_PAD : public BOARD_CONNECTED_ITEM
  117. {
  118. public:
  119. static int m_PadSketchModePenSize; ///< Pen size used to draw pads in sketch mode
  120. ///< (mode used to print pads on silkscreen layer)
  121. public:
  122. D_PAD( MODULE* parent );
  123. // Do not create a copy constructor & operator=.
  124. // The ones generated by the compiler are adequate.
  125. /* Default layers used for pads, according to the pad type.
  126. * this is default values only, they can be changed for a given pad
  127. */
  128. static LSET StandardMask(); ///< layer set for a through hole pad
  129. static LSET SMDMask(); ///< layer set for a SMD pad on Front layer
  130. static LSET ConnSMDMask(); ///< layer set for a SMD pad on Front layer
  131. ///< used for edge board connectors
  132. static LSET UnplatedHoleMask(); ///< layer set for a mechanical unplated through hole pad
  133. static LSET ApertureMask(); ///< layer set for an aperture pad
  134. static inline bool ClassOf( const EDA_ITEM* aItem )
  135. {
  136. return aItem && PCB_PAD_T == aItem->Type();
  137. }
  138. D_PAD* Next() const { return static_cast<D_PAD*>( Pnext ); }
  139. MODULE* GetParent() const { return (MODULE*) m_Parent; }
  140. /**
  141. * Imports the pad settings from aMasterPad.
  142. * The result is "this" has the same settinds (sizes, shapes ... )
  143. * as aMasterPad
  144. * @param aMasterPad = the template pad
  145. */
  146. void ImportSettingsFromMaster( const D_PAD& aMasterPad );
  147. /**
  148. * @return true if the pad has a footprint parent flipped
  149. * (on the back/bottom layer)
  150. */
  151. bool IsFlipped() const;
  152. /**
  153. * Set the pad name (sometimes called pad number, although
  154. * it can be an array reference like AA12).
  155. */
  156. void SetName( const wxString& aName )
  157. {
  158. m_name = aName;
  159. }
  160. /**
  161. * @return the pad name
  162. */
  163. const wxString& GetName() const
  164. {
  165. return m_name;
  166. }
  167. /**
  168. * Function IncrementPadName
  169. *
  170. * Increments the pad name to the next available name in the module.
  171. *
  172. * @param aSkipUnconnectable skips any pads that are not connectable (for example NPTH)
  173. * @param aFillSequenceGaps if true, the next reference in a sequence
  174. * like A1,A3,A4 will be A2. If false, it will be A5.
  175. * @return pad name incremented
  176. */
  177. bool IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps );
  178. bool PadNameEqual( const D_PAD* other ) const
  179. {
  180. return m_name == other->m_name; // hide tricks behind sensible API
  181. }
  182. /**
  183. * Function GetShape
  184. * @return the shape of this pad.
  185. */
  186. PAD_SHAPE_T GetShape() const { return m_padShape; }
  187. void SetShape( PAD_SHAPE_T aShape ) { m_padShape = aShape; m_boundingRadius = -1; }
  188. void SetPosition( const wxPoint& aPos ) override { m_Pos = aPos; }
  189. const wxPoint GetPosition() const override { return m_Pos; }
  190. /**
  191. * Function GetAnchorPadShape
  192. * @return the shape of the anchor pad shape, for custom shaped pads.
  193. */
  194. PAD_SHAPE_T GetAnchorPadShape() const { return m_anchorPadShape; }
  195. /**
  196. * @return the option for the custom pad shape to use as clearance area
  197. * in copper zones
  198. */
  199. CUST_PAD_SHAPE_IN_ZONE GetCustomShapeInZoneOpt() const
  200. {
  201. return m_customShapeClearanceArea;
  202. }
  203. /**
  204. * Set the option for the custom pad shape to use as clearance area
  205. * in copper zones
  206. * @param aOption is the clearance area shape CUST_PAD_SHAPE_IN_ZONE option
  207. */
  208. void SetCustomShapeInZoneOpt( CUST_PAD_SHAPE_IN_ZONE aOption )
  209. {
  210. m_customShapeClearanceArea = aOption;
  211. }
  212. /**
  213. * Function SetAnchorPadShape
  214. * Set the shape of the anchor pad for custm shped pads.
  215. * @param the shape of the anchor pad shape( currently, only
  216. * PAD_SHAPE_RECT or PAD_SHAPE_CIRCLE.
  217. */
  218. void SetAnchorPadShape( PAD_SHAPE_T aShape )
  219. {
  220. m_anchorPadShape = ( aShape == PAD_SHAPE_RECT ) ? PAD_SHAPE_RECT : PAD_SHAPE_CIRCLE;
  221. m_boundingRadius = -1;
  222. }
  223. void SetY( int y ) { m_Pos.y = y; }
  224. void SetX( int x ) { m_Pos.x = x; }
  225. void SetPos0( const wxPoint& aPos ) { m_Pos0 = aPos; }
  226. const wxPoint& GetPos0() const { return m_Pos0; }
  227. void SetY0( int y ) { m_Pos0.y = y; }
  228. void SetX0( int x ) { m_Pos0.x = x; }
  229. void SetSize( const wxSize& aSize ) { m_Size = aSize; m_boundingRadius = -1; }
  230. const wxSize& GetSize() const { return m_Size; }
  231. void SetDelta( const wxSize& aSize ) { m_DeltaSize = aSize; m_boundingRadius = -1; }
  232. const wxSize& GetDelta() const { return m_DeltaSize; }
  233. void SetDrillSize( const wxSize& aSize ) { m_Drill = aSize; }
  234. const wxSize& GetDrillSize() const { return m_Drill; }
  235. void SetOffset( const wxPoint& aOffset ) { m_Offset = aOffset; }
  236. const wxPoint& GetOffset() const { return m_Offset; }
  237. /**
  238. * Has meaning only for free shape pads.
  239. * add a free shape to the shape list.
  240. * the shape can be
  241. * a polygon (outline can have a thickness)
  242. * a thick segment
  243. * a filled circle or ring ( if thickness == 0, this is a filled circle, else a ring)
  244. * a arc
  245. */
  246. void AddPrimitive( const SHAPE_POLY_SET& aPoly, int aThickness ); ///< add a polygonal basic shape
  247. void AddPrimitive( const std::vector<wxPoint>& aPoly, int aThickness ); ///< add a polygonal basic shape
  248. void AddPrimitive( wxPoint aStart, wxPoint aEnd, int aThickness ); ///< segment basic shape
  249. void AddPrimitive( wxPoint aCenter, int aRadius, int aThickness ); ///< ring or circle basic shape
  250. void AddPrimitive( wxPoint aCenter, wxPoint aStart,
  251. int aArcAngle, int aThickness ); ///< arc basic shape
  252. bool GetBestAnchorPosition( VECTOR2I& aPos );
  253. /**
  254. * Merge all basic shapes, converted to a polygon in one polygon,
  255. * in m_customShapeAsPolygon
  256. * @return true if OK, false in there is more than one polygon
  257. * in m_customShapeAsPolygon
  258. * @param aMergedPolygon = the SHAPE_POLY_SET to fill.
  259. * if NULL, m_customShapeAsPolygon is the target
  260. * @param aCircleToSegmentsCount = number of segment to approximate a circle
  261. * (default = 32)
  262. * Note: The corners coordinates are relative to the pad position, orientation 0,
  263. */
  264. bool MergePrimitivesAsPolygon( SHAPE_POLY_SET * aMergedPolygon = NULL,
  265. int aCircleToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF );
  266. /**
  267. * clear the basic shapes list
  268. */
  269. void DeletePrimitivesList();
  270. /**
  271. * When created, the corners coordinates are relative to the pad position, orientation 0,
  272. * in m_customShapeAsPolygon
  273. * CustomShapeAsPolygonToBoardPosition transform these coordinates to actual
  274. * (board) coordinates
  275. * @param aMergedPolygon = the corners coordinates, relative to aPosition and
  276. * rotated by aRotation
  277. * @param aPosition = the position of the shape (usually the pad shape, but
  278. * not always, when moving the pad)
  279. * @param aRotation = the rotation of the shape (usually the pad rotation, but
  280. * not always, in DRC)
  281. */
  282. void CustomShapeAsPolygonToBoardPosition( SHAPE_POLY_SET * aMergedPolygon,
  283. wxPoint aPosition, double aRotation ) const;
  284. /**
  285. * Accessor to the basic shape list
  286. */
  287. const std::vector<PAD_CS_PRIMITIVE>& GetPrimitives() const { return m_basicShapes; }
  288. /**
  289. * Accessor to the custom shape as one polygon
  290. */
  291. const SHAPE_POLY_SET& GetCustomShapeAsPolygon() const { return m_customShapeAsPolygon; }
  292. void Flip( const wxPoint& aCentre ) override;
  293. /**
  294. * Flip the basic shapes, in custom pads
  295. */
  296. void FlipPrimitives();
  297. /**
  298. * Mirror the primitives about a coordinate
  299. *
  300. * @param aX the x coordinate about which to mirror
  301. */
  302. void MirrorXPrimitives( int aX );
  303. /**
  304. * Import to the basic shape list
  305. * @return true if OK, false if issues
  306. * (more than one polygon to build the polygon shape list)
  307. */
  308. bool SetPrimitives( const std::vector<PAD_CS_PRIMITIVE>& aPrimitivesList );
  309. /**
  310. * Add to the basic shape list
  311. * @return true if OK, false if issues
  312. * (more than one polygon to build the polygon shape list)
  313. */
  314. bool AddPrimitives( const std::vector<PAD_CS_PRIMITIVE>& aPrimitivesList );
  315. /**
  316. * Function SetOrientation
  317. * sets the rotation angle of the pad.
  318. * @param aAngle is tenths of degrees, but will soon be degrees. If it is
  319. * outside of 0 - 3600, then it will be normalized before being saved.
  320. */
  321. void SetOrientation( double aAngle );
  322. /**
  323. * Set orientation in degrees
  324. */
  325. void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation*10.0 ); }
  326. /**
  327. * Function GetOrientation
  328. * returns the rotation angle of the pad in tenths of degrees, but soon degrees.
  329. */
  330. double GetOrientation() const { return m_Orient; }
  331. double GetOrientationDegrees() const { return m_Orient/10.0; }
  332. double GetOrientationRadians() const { return m_Orient*M_PI/1800; }
  333. void SetDrillShape( PAD_DRILL_SHAPE_T aDrillShape )
  334. { m_drillShape = aDrillShape; }
  335. PAD_DRILL_SHAPE_T GetDrillShape() const { return m_drillShape; }
  336. /**
  337. * Function GetOblongDrillGeometry calculates the start point, end point and width
  338. * of an equivalent segment which have the same position and width as the hole
  339. * Usefull to plot/draw oblong holes like segments with rounded ends
  340. * used in draw and plot functions
  341. * @param aStartPoint = first point of the equivalent segment, relative to the pad position.
  342. * @param aEndPoint = second point of the equivalent segment, relative to the pad position.
  343. * @param aWidth = width equivalent segment.
  344. */
  345. void GetOblongDrillGeometry( wxPoint& aStartPoint, wxPoint& aEndPoint, int& aWidth ) const;
  346. void SetLayerSet( LSET aLayerMask ) { m_layerMask = aLayerMask; }
  347. LSET GetLayerSet() const override { return m_layerMask; }
  348. void SetAttribute( PAD_ATTR_T aAttribute );
  349. PAD_ATTR_T GetAttribute() const { return m_Attribute; }
  350. // We don't currently have an attribute for APERTURE, and adding one will change the file
  351. // format, so for now just infer a copper-less pad to be an APERTURE pad.
  352. bool IsAperturePad() const { return ( m_layerMask & LSET::AllCuMask() ).none(); }
  353. void SetPadToDieLength( int aLength ) { m_LengthPadToDie = aLength; }
  354. int GetPadToDieLength() const { return m_LengthPadToDie; }
  355. int GetLocalSolderMaskMargin() const { return m_LocalSolderMaskMargin; }
  356. void SetLocalSolderMaskMargin( int aMargin ) { m_LocalSolderMaskMargin = aMargin; }
  357. int GetLocalClearance() const { return m_LocalClearance; }
  358. void SetLocalClearance( int aClearance ) { m_LocalClearance = aClearance; }
  359. int GetLocalSolderPasteMargin() const { return m_LocalSolderPasteMargin; }
  360. void SetLocalSolderPasteMargin( int aMargin ) { m_LocalSolderPasteMargin = aMargin; }
  361. double GetLocalSolderPasteMarginRatio() const { return m_LocalSolderPasteMarginRatio; }
  362. void SetLocalSolderPasteMarginRatio( double aRatio ) { m_LocalSolderPasteMarginRatio = aRatio; }
  363. /**
  364. * Function TransformShapeWithClearanceToPolygon
  365. * Convert the pad shape to a closed polygon
  366. * Used in filling zones calculations
  367. * Circles and arcs are approximated by segments
  368. * @param aCornerBuffer = a buffer to store the polygon
  369. * @param aClearanceValue = the clearance around the pad
  370. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  371. * @param aCorrectionFactor = the correction to apply to circles radius to keep
  372. * clearance when the circle is approximated by segment bigger or equal
  373. * to the real clearance value (usually near from 1.0)
  374. * @param ignoreLineWidth = used for edge cut items where the line width is only
  375. * for visualization
  376. */
  377. void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  378. int aClearanceValue,
  379. int aCircleToSegmentsCount,
  380. double aCorrectionFactor,
  381. bool ignoreLineWidth = false ) const override;
  382. /**
  383. * Function GetClearance
  384. * returns the clearance in internal units. If \a aItem is not NULL then the
  385. * returned clearance is the greater of this object's clearance and
  386. * aItem's clearance. If \a aItem is NULL, then this objects clearance
  387. * is returned.
  388. * @param aItem is another BOARD_CONNECTED_ITEM or NULL
  389. * @return int - the clearance in internal units.
  390. */
  391. int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const override;
  392. // Mask margins handling:
  393. /**
  394. * Function GetSolderMaskMargin
  395. * @return the margin for the solder mask layer
  396. * usually > 0 (mask shape bigger than pad
  397. * For pads also on copper layers, the value (used to build a default shape) is
  398. * 1 - the local value
  399. * 2 - if 0, the parent footprint value
  400. * 3 - if 0, the global value
  401. * For pads NOT on copper layers, the value is the local value because there is
  402. * not default shape to build
  403. */
  404. int GetSolderMaskMargin() const;
  405. /**
  406. * Function GetSolderPasteMargin
  407. * @return the margin for the solder mask layer
  408. * usually < 0 (mask shape smaller than pad)
  409. * because the margin can be dependent on the pad size, the margin has a x and a y value
  410. *
  411. * For pads also on copper layers, the value (used to build a default shape) is
  412. * 1 - the local value
  413. * 2 - if 0, the parent footprint value
  414. * 3 - if 0, the global value
  415. *
  416. * For pads NOT on copper layers, the value is the local value because there is
  417. * not default shape to build
  418. */
  419. wxSize GetSolderPasteMargin() const;
  420. void SetZoneConnection( ZoneConnection aType ) { m_ZoneConnection = aType; }
  421. ZoneConnection GetZoneConnection() const;
  422. void SetThermalWidth( int aWidth ) { m_ThermalWidth = aWidth; }
  423. int GetThermalWidth() const;
  424. void SetThermalGap( int aGap ) { m_ThermalGap = aGap; }
  425. int GetThermalGap() const;
  426. /* drawing functions */
  427. void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  428. GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ) override;
  429. /**
  430. * Function DrawShape
  431. * basic function to draw a pad.
  432. * <p>
  433. * This function is used by Draw after calculation of parameters (color, ) final
  434. * orientation transforms are set. It can also be called to draw a pad on any panel
  435. * even if this panel is not a EDA_DRAW_PANEL for instance on a wxPanel inside the
  436. * pad editor.
  437. * </p>
  438. */
  439. void DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo );
  440. /**
  441. * Function BuildPadPolygon
  442. * Has meaning only for polygonal pads (trapezoid and rectangular)
  443. * Build the Corner list of the polygonal shape,
  444. * depending on shape, extra size (clearance ...) and orientation
  445. * @param aCoord = a buffer to fill (4 corners).
  446. * @param aInflateValue = wxSize: the clearance or margin value. value > 0:
  447. * inflate, < 0 deflate
  448. * @param aRotation = full rotation of the polygon
  449. */
  450. void BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, double aRotation ) const;
  451. /**
  452. * Function GetRoundRectCornerRadius
  453. * Has meaning only for rounded rect pads
  454. * @return The radius of the rounded corners for this pad.
  455. */
  456. int GetRoundRectCornerRadius() const
  457. {
  458. return GetRoundRectCornerRadius( m_Size );
  459. }
  460. /**
  461. * Helper function GetRoundRectCornerRadius
  462. * Has meaning only for rounded rect pads
  463. * Returns the radius of the rounded corners of a rectangle
  464. * size aSize, using others setting of the pad
  465. * @param aSize = size of the of the round rect. Usually the pad size
  466. * but can be the size of the pad on solder mask or solder paste
  467. * @return The radius of the rounded corners for this pad size.
  468. */
  469. int GetRoundRectCornerRadius( const wxSize& aSize ) const;
  470. /**
  471. * Set the rounded rectangle radius ratio based on a given radius
  472. * @param aRadius = desired radius of curvature
  473. */
  474. void SetRoundRectCornerRadius( double aRadius );
  475. /**
  476. * Function BuildPadShapePolygon
  477. * Build the Corner list of the polygonal shape,
  478. * depending on shape, extra size (clearance ...) pad and orientation
  479. * This function is similar to TransformShapeWithClearanceToPolygon,
  480. * but the difference is BuildPadShapePolygon creates a polygon shape exactly
  481. * similar to pad shape, which a size inflated by aInflateValue
  482. * and TransformShapeWithClearanceToPolygon creates a more complex shape (for instance
  483. * a rectangular pad is converted in a rectangulr shape with ronded corners)
  484. * @param aCornerBuffer = a buffer to fill.
  485. * @param aInflateValue = the clearance or margin value.
  486. * value > 0: inflate, < 0 deflate, = 0 : no change
  487. * the clearance can have different values for x and y directions
  488. * (relative to the pad)
  489. * @param aSegmentsPerCircle = number of segments to approximate a circle
  490. * (used for round and oblong shapes only (16 to 32 is a good value)
  491. * @param aCorrectionFactor = the correction to apply to circles radius to keep
  492. * the pad size/clearance when the arcs are approximated by segments
  493. */
  494. void BuildPadShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
  495. wxSize aInflateValue, int aSegmentsPerCircle,
  496. double aCorrectionFactor ) const;
  497. /**
  498. * Function BuildPadDrillShapePolygon
  499. * Build the Corner list of the polygonal drill shape,
  500. * depending on shape pad hole and orientation
  501. * @param aCornerBuffer = a buffer to fill.
  502. * @param aInflateValue = the clearance or margin value.
  503. * value > 0: inflate, < 0 deflate, = 0 : no change
  504. * @param aSegmentsPerCircle = number of segments to approximate a circle
  505. * (used for round and oblong shapes only(16 to 32 is a good value)
  506. * @return false if the pad has no hole, true otherwise
  507. */
  508. bool BuildPadDrillShapePolygon( SHAPE_POLY_SET& aCornerBuffer,
  509. int aInflateValue, int aSegmentsPerCircle ) const;
  510. /**
  511. * Function BuildSegmentFromOvalShape
  512. * Has meaning only for OVAL (and ROUND) pads
  513. * Build an equivalent segment having the same shape as the OVAL shape,
  514. * Useful in draw function and in DRC and HitTest functions,
  515. * because segments are already well handled by track tests
  516. * @param aSegStart = the starting point of the equivalent segment relative to the shape
  517. * position.
  518. * @param aSegEnd = the ending point of the equivalent segment, relative to the shape position
  519. * @param aRotation = full rotation of the segment
  520. * @param aRotation = full rotation of the segment
  521. * @param aMargin = a margin around the shape (for instance mask margin)
  522. * @return the width of the segment
  523. */
  524. int BuildSegmentFromOvalShape( wxPoint& aSegStart, wxPoint& aSegEnd,
  525. double aRotation, const wxSize& aMargin ) const;
  526. /**
  527. * Function GetBoundingRadius
  528. * returns the radius of a minimum sized circle which fully encloses this pad.
  529. * The center is the pad position
  530. */
  531. int GetBoundingRadius() const
  532. {
  533. // Any member function which would affect this calculation should set
  534. // m_boundingRadius to -1 to re-trigger the calculation from here.
  535. // Currently that is only m_Size, m_DeltaSize, and m_padShape accessors.
  536. if( m_boundingRadius == -1 )
  537. {
  538. m_boundingRadius = boundingRadius();
  539. }
  540. return m_boundingRadius;
  541. }
  542. wxPoint ShapePos() const;
  543. /**
  544. * has meaning only for rounded rect pads
  545. * @return the scaling factor between the smaller Y or Y size and the radius
  546. * of the rounded corners.
  547. * Cannot be > 0.5
  548. * the normalized IPC-7351C value is 0.25
  549. */
  550. double GetRoundRectRadiusRatio() const
  551. {
  552. return m_padRoundRectRadiusScale;
  553. }
  554. /**
  555. * has meaning only for rounded rect pads
  556. * Set the scaling factor between the smaller Y or Y size and the radius
  557. * of the rounded corners.
  558. * Cannot be < 0.5 and obviously must be > 0
  559. * the normalized IPC-7351C value is 0.25
  560. */
  561. void SetRoundRectRadiusRatio( double aRadiusScale )
  562. {
  563. if( aRadiusScale < 0.0 )
  564. aRadiusScale = 0.0;
  565. m_padRoundRectRadiusScale = std::min( aRadiusScale, 0.5 );
  566. }
  567. /**
  568. * Function GetSubRatsnest
  569. * @return int - the netcode
  570. */
  571. int GetSubRatsnest() const { return m_SubRatsnest; }
  572. void SetSubRatsnest( int aSubRatsnest ) { m_SubRatsnest = aSubRatsnest; }
  573. void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
  574. bool IsOnLayer( PCB_LAYER_ID aLayer ) const override
  575. {
  576. return m_layerMask[aLayer];
  577. }
  578. bool HitTest( const wxPoint& aPosition ) const override;
  579. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  580. wxString GetClass() const override
  581. {
  582. return wxT( "PAD" );
  583. }
  584. // Virtual function:
  585. const EDA_RECT GetBoundingBox() const override;
  586. ///> Set absolute coordinates.
  587. void SetDrawCoord();
  588. //todo: Remove SetLocalCoord along with m_pos
  589. ///> Set relative coordinates.
  590. void SetLocalCoord();
  591. /**
  592. * Function Compare
  593. * compares two pads and return 0 if they are equal.
  594. * @return int - <0 if left less than right, 0 if equal, >0 if left greater than right.
  595. */
  596. static int Compare( const D_PAD* padref, const D_PAD* padcmp );
  597. void Move( const wxPoint& aMoveVector ) override
  598. {
  599. m_Pos += aMoveVector;
  600. SetLocalCoord();
  601. }
  602. void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
  603. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  604. BITMAP_DEF GetMenuImage() const override;
  605. /**
  606. * Function ShowPadShape
  607. * @return the name of the shape
  608. */
  609. wxString ShowPadShape() const;
  610. /**
  611. * Function ShowPadAttr
  612. * @return the name of the pad type (attribute) : STD, SMD ...
  613. */
  614. wxString ShowPadAttr() const;
  615. /**
  616. * Function AppendConfigs
  617. * appends to @a aResult the configuration setting accessors which will later
  618. * allow reading or writing of configuration file information directly into
  619. * this object.
  620. */
  621. void AppendConfigs( PARAM_CFG_ARRAY* aResult );
  622. EDA_ITEM* Clone() const override;
  623. /**
  624. * same as Clone, but returns a D_PAD item.
  625. * Useful mainly for pythons scripts, because Clone (virtual function)
  626. * returns an EDA_ITEM.
  627. */
  628. D_PAD* Duplicate() const
  629. {
  630. return (D_PAD*) Clone();
  631. }
  632. /**
  633. * A pad whose hole is the same size as the pad is a NPTH. However, if the user
  634. * fails to mark this correctly then the pad will become invisible on the board.
  635. * This check allows us to special-case this error-condition.
  636. */
  637. bool PadShouldBeNPTH() const;
  638. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  639. virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  640. virtual const BOX2I ViewBBox() const override;
  641. /**
  642. * Function CopyNetlistSettings
  643. * copies the netlist settings to \a aPad, and the net name.
  644. * Used to copy some pad parameters when replacing a footprint by an other
  645. * footprint when reading a netlist, or in exchange footprint dialog
  646. *
  647. * The netlist settings are all of the #D_PAD settings not define by a #D_PAD in
  648. * a netlist.
  649. * The copied settings are the net name and optionally include local clearance, etc.
  650. * The pad physical geometry settings are not copied.
  651. *
  652. * @param aPad is the #D_PAD to copy the settings to.
  653. * @param aCopyLocalSettings = false to copy only the net name
  654. * true to also copy local prms
  655. */
  656. void CopyNetlistSettings( D_PAD* aPad, bool aCopyLocalSettings );
  657. virtual void SwapData( BOARD_ITEM* aImage ) override;
  658. #if defined(DEBUG)
  659. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  660. #endif
  661. private:
  662. /**
  663. * Function boundingRadius
  664. * returns a calculated radius of a bounding circle for this pad.
  665. */
  666. int boundingRadius() const;
  667. bool buildCustomPadPolygon( SHAPE_POLY_SET* aMergedPolygon,
  668. int aCircleToSegmentsCount );
  669. private: // Private variable members:
  670. // Actually computed and cached on demand by the accessor
  671. mutable int m_boundingRadius; ///< radius of the circle containing the pad shape
  672. wxString m_name;
  673. // TODO: Remove m_Pos from Pad or make private. View positions calculated from m_Pos0
  674. wxPoint m_Pos; ///< pad Position on board
  675. PAD_SHAPE_T m_padShape; ///< Shape: PAD_SHAPE_CIRCLE, PAD_SHAPE_RECT,
  676. ///< PAD_SHAPE_OVAL, PAD_SHAPE_TRAPEZOID,
  677. ///< PAD_SHAPE_ROUNDRECT, PAD_SHAPE_POLYGON
  678. /** for free shape pads: a list of basic shapes,
  679. * in local coordinates, orient 0, coordinates relative to m_Pos
  680. * They are expected to define only one copper area.
  681. */
  682. std::vector<PAD_CS_PRIMITIVE> m_basicShapes;
  683. /** for free shape pads: the set of basic shapes, merged as one polygon,
  684. * in local coordinates, orient 0, coordinates relative to m_Pos
  685. */
  686. SHAPE_POLY_SET m_customShapeAsPolygon;
  687. /**
  688. * How to build the custom shape in zone, to create the clearance area:
  689. * CUST_PAD_SHAPE_IN_ZONE_OUTLINE = use pad shape
  690. * CUST_PAD_SHAPE_IN_ZONE_CONVEXHULL = use the convex hull of the pad shape
  691. * other values are currently reserved
  692. */
  693. CUST_PAD_SHAPE_IN_ZONE m_customShapeClearanceArea;
  694. int m_SubRatsnest; ///< variable used in rats nest computations
  695. ///< handle subnet (block) number in ratsnest connection
  696. wxSize m_Drill; ///< Drill diam (drill shape = PAD_CIRCLE) or drill size
  697. ///< (shape = OVAL) for drill shape = PAD_CIRCLE, drill
  698. ///< diam = m_Drill.x
  699. wxSize m_Size; ///< X and Y size ( relative to orient 0)
  700. PAD_DRILL_SHAPE_T m_drillShape; ///< PAD_DRILL_SHAPE_CIRCLE, PAD_DRILL_SHAPE_OBLONG
  701. double m_padRoundRectRadiusScale; ///< scaling factor from smallest m_Size coord
  702. ///< to corner radius, default 0.25
  703. PAD_SHAPE_T m_anchorPadShape; ///< for custom shaped pads: shape of pad anchor,
  704. ///< PAD_SHAPE_RECT, PAD_SHAPE_CIRCLE
  705. /**
  706. * m_Offset is useful only for oblong and rect pads (it can be used for other
  707. * shapes, but without any interest).
  708. * This is the offset between the pad hole and the pad shape (you must
  709. * understand here pad shape = copper area around the hole)
  710. * Most of cases, the hole is the center of the shape (m_Offset = 0).
  711. * But some board designers use oblong/rect pads with a hole moved to one of the
  712. * oblong/rect pad shape ends.
  713. * In all cases the pad position is the pad hole.
  714. * The physical shape position (used to draw it for instance) is pad
  715. * position (m_Pos) + m_Offset.
  716. * D_PAD::ShapePos() returns the physical shape position according to
  717. * the offset and the pad rotation.
  718. */
  719. wxPoint m_Offset;
  720. LSET m_layerMask; ///< Bitwise layer :1= copper layer, 15= cmp,
  721. ///< 2..14 = internal layers
  722. ///< 16 .. 31 = technical layers
  723. wxSize m_DeltaSize; ///< delta on rectangular shapes
  724. wxPoint m_Pos0; ///< Initial Pad position (i.e. pad position relative to the
  725. ///< module anchor, orientation 0)
  726. PAD_ATTR_T m_Attribute; ///< PAD_ATTRIB_NORMAL, PAD_ATTRIB_SMD,
  727. ///< PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED
  728. double m_Orient; ///< in 1/10 degrees
  729. int m_LengthPadToDie; ///< Length net from pad to die, inside the package
  730. /// Local clearance. When null, the module default value is used.
  731. /// when the module default value is null, the netclass value is used
  732. /// Usually the local clearance is null
  733. int m_LocalClearance;
  734. /// Local mask margins: when 0, the parent footprint design values are used
  735. int m_LocalSolderMaskMargin; ///< Local solder mask margin
  736. int m_LocalSolderPasteMargin; ///< Local solder paste margin absolute value
  737. double m_LocalSolderPasteMarginRatio; ///< Local solder mask margin ratio value of pad size
  738. ///< The final margin is the sum of these 2 values
  739. /// how the connection to zone is made: no connection, thermal relief ...
  740. ZoneConnection m_ZoneConnection;
  741. int m_ThermalWidth;
  742. int m_ThermalGap;
  743. };
  744. #endif // PAD_H_