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.

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