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.

1815 lines
57 KiB

14 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
14 years ago
5 years ago
5 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
5 years ago
18 years ago
18 years ago
18 years ago
5 years ago
18 years ago
14 years ago
18 years ago
18 years ago
5 years ago
5 years ago
5 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
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
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
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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 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) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <base_units.h>
  26. #include <bitmaps.h>
  27. #include <core/mirror.h>
  28. #include <math/util.h> // for KiROUND
  29. #include <eda_draw_frame.h>
  30. #include <geometry/shape_circle.h>
  31. #include <geometry/shape_segment.h>
  32. #include <geometry/shape_simple.h>
  33. #include <geometry/shape_rect.h>
  34. #include <geometry/shape_compound.h>
  35. #include <geometry/shape_null.h>
  36. #include <string_utils.h>
  37. #include <i18n_utility.h>
  38. #include <view/view.h>
  39. #include <board.h>
  40. #include <board_connected_item.h>
  41. #include <board_design_settings.h>
  42. #include <footprint.h>
  43. #include <pad.h>
  44. #include <pcb_shape.h>
  45. #include <connectivity/connectivity_data.h>
  46. #include <eda_units.h>
  47. #include <convert_basic_shapes_to_polygon.h>
  48. #include <widgets/msgpanel.h>
  49. #include <pcb_painter.h>
  50. #include <wx/log.h>
  51. #include <memory>
  52. #include <macros.h>
  53. #include "kiface_base.h"
  54. #include "pcbnew_settings.h"
  55. using KIGFX::PCB_PAINTER;
  56. using KIGFX::PCB_RENDER_SETTINGS;
  57. PAD::PAD( FOOTPRINT* parent ) :
  58. BOARD_CONNECTED_ITEM( parent, PCB_PAD_T )
  59. {
  60. m_size.x = m_size.y = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 60 ); // Default pad size 60 mils.
  61. m_drill.x = m_drill.y = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 30 ); // Default drill size 30 mils.
  62. m_orient = ANGLE_0;
  63. m_lengthPadToDie = 0;
  64. if( m_parent && m_parent->Type() == PCB_FOOTPRINT_T )
  65. m_pos = GetParent()->GetPosition();
  66. SetShape( PAD_SHAPE::CIRCLE ); // Default pad shape is PAD_CIRCLE.
  67. SetAnchorPadShape( PAD_SHAPE::CIRCLE ); // Default shape for custom shaped pads
  68. // is PAD_CIRCLE.
  69. SetDrillShape( PAD_DRILL_SHAPE_CIRCLE ); // Default pad drill shape is a circle.
  70. m_attribute = PAD_ATTRIB::PTH; // Default pad type is plated through hole
  71. SetProperty( PAD_PROP::NONE ); // no special fabrication property
  72. m_localClearance = 0;
  73. m_localSolderMaskMargin = 0;
  74. m_localSolderPasteMargin = 0;
  75. m_localSolderPasteMarginRatio = 0.0;
  76. // Parameters for round rect only:
  77. m_roundedCornerScale = 0.25; // from IPC-7351C standard
  78. // Parameters for chamfered rect only:
  79. m_chamferScale = 0.2; // Size of chamfer: ratio of smallest of X,Y size
  80. m_chamferPositions = RECT_NO_CHAMFER; // No chamfered corner
  81. m_zoneConnection = ZONE_CONNECTION::INHERITED; // Use parent setting by default
  82. m_thermalSpokeWidth = 0; // Use parent setting by default
  83. m_thermalSpokeAngle = ANGLE_45; // Default for circular pads
  84. m_thermalGap = 0; // Use parent setting by default
  85. m_customShapeClearanceArea = CUST_PAD_SHAPE_IN_ZONE_OUTLINE;
  86. // Set layers mask to default for a standard thru hole pad.
  87. m_layerMask = PTHMask();
  88. SetSubRatsnest( 0 ); // used in ratsnest calculations
  89. SetDirty();
  90. m_effectiveBoundingRadius = 0;
  91. m_removeUnconnectedLayer = false;
  92. m_keepTopBottomLayer = true;
  93. for( size_t ii = 0; ii < arrayDim( m_zoneLayerConnections ); ++ii )
  94. m_zoneLayerConnections[ ii ] = ZLC_UNCONNECTED;
  95. }
  96. PAD::PAD( const PAD& aOther ) :
  97. BOARD_CONNECTED_ITEM( aOther.GetParent(), PCB_PAD_T )
  98. {
  99. PAD::operator=( aOther );
  100. const_cast<KIID&>( m_Uuid ) = aOther.m_Uuid;
  101. }
  102. PAD& PAD::operator=( const PAD &aOther )
  103. {
  104. BOARD_CONNECTED_ITEM::operator=( aOther );
  105. ImportSettingsFrom( aOther );
  106. SetPadToDieLength( aOther.GetPadToDieLength() );
  107. SetPosition( aOther.GetPosition() );
  108. SetPos0( aOther.GetPos0() );
  109. SetNumber( aOther.GetNumber() );
  110. SetPinType( aOther.GetPinType() );
  111. SetPinFunction( aOther.GetPinFunction() );
  112. SetSubRatsnest( aOther.GetSubRatsnest() );
  113. m_effectiveBoundingRadius = aOther.m_effectiveBoundingRadius;
  114. m_removeUnconnectedLayer = aOther.m_removeUnconnectedLayer;
  115. m_keepTopBottomLayer = aOther.m_keepTopBottomLayer;
  116. return *this;
  117. }
  118. bool PAD::CanHaveNumber() const
  119. {
  120. // Aperture pads don't get a number
  121. if( IsAperturePad() )
  122. return false;
  123. // NPTH pads don't get numbers
  124. if( GetAttribute() == PAD_ATTRIB::NPTH )
  125. return false;
  126. return true;
  127. }
  128. bool PAD::IsLocked() const
  129. {
  130. if( GetParent() && GetParent()->IsLocked() )
  131. return true;
  132. return BOARD_ITEM::IsLocked();
  133. };
  134. bool PAD::IsNoConnectPad() const
  135. {
  136. return GetShortNetname().StartsWith( wxT( "unconnected-(" ) )
  137. && ( m_pinType == wxT( "no_connect" ) || m_pinType.EndsWith( wxT( "+no_connect" ) ) );
  138. }
  139. bool PAD::IsFreePad() const
  140. {
  141. return GetShortNetname().StartsWith( wxT( "unconnected-(" ) )
  142. && m_pinType == wxT( "free" );
  143. }
  144. LSET PAD::PTHMask()
  145. {
  146. static LSET saved = LSET::AllCuMask() | LSET( 2, F_Mask, B_Mask );
  147. return saved;
  148. }
  149. LSET PAD::SMDMask()
  150. {
  151. static LSET saved( 3, F_Cu, F_Paste, F_Mask );
  152. return saved;
  153. }
  154. LSET PAD::ConnSMDMask()
  155. {
  156. static LSET saved( 2, F_Cu, F_Mask );
  157. return saved;
  158. }
  159. LSET PAD::UnplatedHoleMask()
  160. {
  161. static LSET saved = LSET( 4, F_Cu, B_Cu, F_Mask, B_Mask );
  162. return saved;
  163. }
  164. LSET PAD::ApertureMask()
  165. {
  166. static LSET saved( 1, F_Paste );
  167. return saved;
  168. }
  169. bool PAD::IsFlipped() const
  170. {
  171. FOOTPRINT* parent = GetParent();
  172. return ( parent && parent->GetLayer() == B_Cu );
  173. }
  174. PCB_LAYER_ID PAD::GetLayer() const
  175. {
  176. return BOARD_ITEM::GetLayer();
  177. }
  178. PCB_LAYER_ID PAD::GetPrincipalLayer() const
  179. {
  180. if( m_attribute == PAD_ATTRIB::SMD || m_attribute == PAD_ATTRIB::CONN || GetLayerSet().none() )
  181. return m_layer;
  182. else
  183. return GetLayerSet().Seq().front();
  184. }
  185. bool PAD::FlashLayer( LSET aLayers ) const
  186. {
  187. for( PCB_LAYER_ID layer : aLayers.Seq() )
  188. {
  189. if( FlashLayer( layer ) )
  190. return true;
  191. }
  192. return false;
  193. }
  194. bool PAD::FlashLayer( int aLayer ) const
  195. {
  196. if( aLayer != UNDEFINED_LAYER && !IsOnLayer( static_cast<PCB_LAYER_ID>( aLayer ) ) )
  197. return false;
  198. if( aLayer == UNDEFINED_LAYER )
  199. return true;
  200. if( GetAttribute() == PAD_ATTRIB::NPTH && IsCopperLayer( aLayer ) )
  201. {
  202. if( GetShape() == PAD_SHAPE::CIRCLE && GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
  203. {
  204. if( GetOffset() == VECTOR2I( 0, 0 ) && GetDrillSize().x >= GetSize().x )
  205. return false;
  206. }
  207. else if( GetShape() == PAD_SHAPE::OVAL && GetDrillShape() == PAD_DRILL_SHAPE_OBLONG )
  208. {
  209. if( GetOffset() == VECTOR2I( 0, 0 )
  210. && GetDrillSize().x >= GetSize().x && GetDrillSize().y >= GetSize().y )
  211. {
  212. return false;
  213. }
  214. }
  215. }
  216. if( LSET::FrontBoardTechMask().test( aLayer ) )
  217. aLayer = F_Cu;
  218. else if( LSET::BackBoardTechMask().test( aLayer ) )
  219. aLayer = B_Cu;
  220. if( GetAttribute() == PAD_ATTRIB::PTH && IsCopperLayer( aLayer ) )
  221. {
  222. /// Heat sink pads always get copper
  223. if( GetProperty() == PAD_PROP::HEATSINK )
  224. return true;
  225. if( !m_removeUnconnectedLayer )
  226. return true;
  227. // Plated through hole pads need copper on the top/bottom layers for proper soldering
  228. // Unless the user has removed them in the pad dialog
  229. if( m_keepTopBottomLayer && ( aLayer == F_Cu || aLayer == B_Cu ) )
  230. return true;
  231. if( const BOARD* board = GetBoard() )
  232. {
  233. // Must be static to keep from raising its ugly head in performance profiles
  234. static std::initializer_list<KICAD_T> types = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
  235. PCB_PAD_T };
  236. // Only the highest priority zone that a via interacts with on any given layer gets
  237. // to determine if it is connected or not. This keeps us from deciding it's not
  238. // flashed when filling the first zone, and then later having another zone connect to
  239. // it, causing it to become flashed, resulting in the first zone having insufficient
  240. // clearance.
  241. // See https://gitlab.com/kicad/code/kicad/-/issues/11299.
  242. if( m_zoneLayerConnections[ aLayer ] == ZLC_CONNECTED )
  243. return true;
  244. return board->GetConnectivity()->IsConnectedOnLayer( this, aLayer, types );
  245. }
  246. }
  247. return true;
  248. }
  249. int PAD::GetRoundRectCornerRadius() const
  250. {
  251. return KiROUND( std::min( m_size.x, m_size.y ) * m_roundedCornerScale );
  252. }
  253. void PAD::SetRoundRectCornerRadius( double aRadius )
  254. {
  255. int min_r = std::min( m_size.x, m_size.y );
  256. if( min_r > 0 )
  257. SetRoundRectRadiusRatio( aRadius / min_r );
  258. }
  259. void PAD::SetRoundRectRadiusRatio( double aRadiusScale )
  260. {
  261. m_roundedCornerScale = std::max( 0.0, std::min( aRadiusScale, 0.5 ) );
  262. SetDirty();
  263. }
  264. void PAD::SetChamferRectRatio( double aChamferScale )
  265. {
  266. m_chamferScale = std::max( 0.0, std::min( aChamferScale, 0.5 ) );
  267. SetDirty();
  268. }
  269. const std::shared_ptr<SHAPE_POLY_SET>& PAD::GetEffectivePolygon() const
  270. {
  271. if( m_polyDirty )
  272. BuildEffectivePolygon();
  273. return m_effectivePolygon;
  274. }
  275. std::shared_ptr<SHAPE> PAD::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING flashPTHPads ) const
  276. {
  277. if( aLayer == Edge_Cuts )
  278. {
  279. if( GetAttribute() == PAD_ATTRIB::PTH || GetAttribute() == PAD_ATTRIB::NPTH )
  280. return GetEffectiveHoleShape();
  281. else
  282. return std::make_shared<SHAPE_NULL>();
  283. }
  284. if( GetAttribute() == PAD_ATTRIB::PTH )
  285. {
  286. bool flash;
  287. if( flashPTHPads == FLASHING::NEVER_FLASHED )
  288. flash = false;
  289. else if( flashPTHPads == FLASHING::ALWAYS_FLASHED )
  290. flash = true;
  291. else
  292. flash = FlashLayer( aLayer );
  293. if( !flash )
  294. {
  295. if( GetAttribute() == PAD_ATTRIB::PTH )
  296. return GetEffectiveHoleShape();
  297. else
  298. return std::make_shared<SHAPE_NULL>();
  299. }
  300. }
  301. if( m_shapesDirty )
  302. BuildEffectiveShapes( aLayer );
  303. return m_effectiveShape;
  304. }
  305. std::shared_ptr<SHAPE_SEGMENT> PAD::GetEffectiveHoleShape() const
  306. {
  307. if( m_shapesDirty )
  308. BuildEffectiveShapes( UNDEFINED_LAYER );
  309. return m_effectiveHoleShape;
  310. }
  311. int PAD::GetBoundingRadius() const
  312. {
  313. if( m_polyDirty )
  314. BuildEffectivePolygon();
  315. return m_effectiveBoundingRadius;
  316. }
  317. void PAD::BuildEffectiveShapes( PCB_LAYER_ID aLayer ) const
  318. {
  319. std::lock_guard<std::mutex> RAII_lock( m_shapesBuildingLock );
  320. // If we had to wait for the lock then we were probably waiting for someone else to
  321. // finish rebuilding the shapes. So check to see if they're clean now.
  322. if( !m_shapesDirty )
  323. return;
  324. const BOARD* board = GetBoard();
  325. int maxError = board ? board->GetDesignSettings().m_MaxError : ARC_HIGH_DEF;
  326. m_effectiveShape = std::make_shared<SHAPE_COMPOUND>();
  327. m_effectiveHoleShape = nullptr;
  328. auto add = [this]( SHAPE* aShape )
  329. {
  330. m_effectiveShape->AddShape( aShape );
  331. };
  332. VECTOR2I shapePos = ShapePos(); // Fetch only once; rotation involves trig
  333. PAD_SHAPE effectiveShape = GetShape();
  334. if( GetShape() == PAD_SHAPE::CUSTOM )
  335. effectiveShape = GetAnchorPadShape();
  336. switch( effectiveShape )
  337. {
  338. case PAD_SHAPE::CIRCLE:
  339. add( new SHAPE_CIRCLE( shapePos, m_size.x / 2 ) );
  340. break;
  341. case PAD_SHAPE::OVAL:
  342. if( m_size.x == m_size.y ) // the oval pad is in fact a circle
  343. {
  344. add( new SHAPE_CIRCLE( shapePos, m_size.x / 2 ) );
  345. }
  346. else
  347. {
  348. VECTOR2I half_size = m_size / 2;
  349. int half_width = std::min( half_size.x, half_size.y );
  350. VECTOR2I half_len( half_size.x - half_width, half_size.y - half_width );
  351. RotatePoint( half_len, m_orient );
  352. add( new SHAPE_SEGMENT( shapePos - half_len, shapePos + half_len, half_width * 2 ) );
  353. }
  354. break;
  355. case PAD_SHAPE::RECT:
  356. case PAD_SHAPE::TRAPEZOID:
  357. case PAD_SHAPE::ROUNDRECT:
  358. {
  359. int r = ( effectiveShape == PAD_SHAPE::ROUNDRECT ) ? GetRoundRectCornerRadius() : 0;
  360. VECTOR2I half_size( m_size.x / 2, m_size.y / 2 );
  361. VECTOR2I trap_delta( 0, 0 );
  362. if( r )
  363. {
  364. half_size -= VECTOR2I( r, r );
  365. // Avoid degenerated shapes (0 length segments) that always create issues
  366. // For roundrect pad very near a circle, use only a circle
  367. const int min_len = pcbIUScale.mmToIU( 0.0001);
  368. if( half_size.x < min_len && half_size.y < min_len )
  369. {
  370. add( new SHAPE_CIRCLE( shapePos, r ) );
  371. break;
  372. }
  373. }
  374. else if( effectiveShape == PAD_SHAPE::TRAPEZOID )
  375. {
  376. trap_delta = m_deltaSize / 2;
  377. }
  378. SHAPE_LINE_CHAIN corners;
  379. corners.Append( -half_size.x - trap_delta.y, half_size.y + trap_delta.x );
  380. corners.Append( half_size.x + trap_delta.y, half_size.y - trap_delta.x );
  381. corners.Append( half_size.x - trap_delta.y, -half_size.y + trap_delta.x );
  382. corners.Append( -half_size.x + trap_delta.y, -half_size.y - trap_delta.x );
  383. corners.Rotate( m_orient );
  384. corners.Move( shapePos );
  385. // GAL renders rectangles faster than 4-point polygons so it's worth checking if our
  386. // body shape is a rectangle.
  387. if( corners.PointCount() == 4
  388. &&
  389. ( ( corners.CPoint( 0 ).y == corners.CPoint( 1 ).y
  390. && corners.CPoint( 1 ).x == corners.CPoint( 2 ).x
  391. && corners.CPoint( 2 ).y == corners.CPoint( 3 ).y
  392. && corners.CPoint( 3 ).x == corners.CPoint( 0 ).x )
  393. ||
  394. ( corners.CPoint( 0 ).x == corners.CPoint( 1 ).x
  395. && corners.CPoint( 1 ).y == corners.CPoint( 2 ).y
  396. && corners.CPoint( 2 ).x == corners.CPoint( 3 ).x
  397. && corners.CPoint( 3 ).y == corners.CPoint( 0 ).y )
  398. )
  399. )
  400. {
  401. int width = std::abs( corners.CPoint( 2 ).x - corners.CPoint( 0 ).x );
  402. int height = std::abs( corners.CPoint( 2 ).y - corners.CPoint( 0 ).y );
  403. VECTOR2I pos( std::min( corners.CPoint( 2 ).x, corners.CPoint( 0 ).x ),
  404. std::min( corners.CPoint( 2 ).y, corners.CPoint( 0 ).y ) );
  405. add( new SHAPE_RECT( pos, width, height ) );
  406. }
  407. else
  408. {
  409. add( new SHAPE_SIMPLE( corners ) );
  410. }
  411. if( r )
  412. {
  413. add( new SHAPE_SEGMENT( corners.CPoint( 0 ), corners.CPoint( 1 ), r * 2 ) );
  414. add( new SHAPE_SEGMENT( corners.CPoint( 1 ), corners.CPoint( 2 ), r * 2 ) );
  415. add( new SHAPE_SEGMENT( corners.CPoint( 2 ), corners.CPoint( 3 ), r * 2 ) );
  416. add( new SHAPE_SEGMENT( corners.CPoint( 3 ), corners.CPoint( 0 ), r * 2 ) );
  417. }
  418. }
  419. break;
  420. case PAD_SHAPE::CHAMFERED_RECT:
  421. {
  422. SHAPE_POLY_SET outline;
  423. TransformRoundChamferedRectToPolygon( outline, shapePos, GetSize(), m_orient,
  424. GetRoundRectCornerRadius(), GetChamferRectRatio(),
  425. GetChamferPositions(), 0, maxError, ERROR_INSIDE );
  426. add( new SHAPE_SIMPLE( outline.COutline( 0 ) ) );
  427. }
  428. break;
  429. default:
  430. wxFAIL_MSG( wxT( "PAD::buildEffectiveShapes: Unsupported pad shape: " )
  431. + PAD_SHAPE_T_asString( effectiveShape ) );
  432. break;
  433. }
  434. if( GetShape() == PAD_SHAPE::CUSTOM )
  435. {
  436. for( const std::shared_ptr<PCB_SHAPE>& primitive : m_editPrimitives )
  437. {
  438. for( SHAPE* shape : primitive->MakeEffectiveShapes() )
  439. {
  440. shape->Rotate( m_orient );
  441. shape->Move( shapePos );
  442. add( shape );
  443. }
  444. }
  445. }
  446. m_effectiveBoundingBox = m_effectiveShape->BBox();
  447. // Hole shape
  448. VECTOR2I half_size = m_drill / 2;
  449. int half_width = std::min( half_size.x, half_size.y );
  450. VECTOR2I half_len( half_size.x - half_width, half_size.y - half_width );
  451. RotatePoint( half_len, m_orient );
  452. m_effectiveHoleShape = std::make_shared<SHAPE_SEGMENT>( m_pos - half_len, m_pos + half_len,
  453. half_width * 2 );
  454. m_effectiveBoundingBox.Merge( m_effectiveHoleShape->BBox() );
  455. // All done
  456. m_shapesDirty = false;
  457. }
  458. void PAD::BuildEffectivePolygon() const
  459. {
  460. std::lock_guard<std::mutex> RAII_lock( m_polyBuildingLock );
  461. // If we had to wait for the lock then we were probably waiting for someone else to
  462. // finish rebuilding the shapes. So check to see if they're clean now.
  463. if( !m_polyDirty )
  464. return;
  465. const BOARD* board = GetBoard();
  466. int maxError = board ? board->GetDesignSettings().m_MaxError : ARC_HIGH_DEF;
  467. // Polygon
  468. m_effectivePolygon = std::make_shared<SHAPE_POLY_SET>();
  469. TransformShapeToPolygon( *m_effectivePolygon, UNDEFINED_LAYER, 0, maxError, ERROR_INSIDE );
  470. // Bounding radius
  471. //
  472. // PADSTACKS TODO: these will both need to cycle through all layers to get the largest
  473. // values....
  474. m_effectiveBoundingRadius = 0;
  475. for( int cnt = 0; cnt < m_effectivePolygon->OutlineCount(); ++cnt )
  476. {
  477. const SHAPE_LINE_CHAIN& poly = m_effectivePolygon->COutline( cnt );
  478. for( int ii = 0; ii < poly.PointCount(); ++ii )
  479. {
  480. int dist = KiROUND( ( poly.CPoint( ii ) - m_pos ).EuclideanNorm() );
  481. m_effectiveBoundingRadius = std::max( m_effectiveBoundingRadius, dist );
  482. }
  483. }
  484. // All done
  485. m_polyDirty = false;
  486. }
  487. const BOX2I PAD::GetBoundingBox() const
  488. {
  489. if( m_shapesDirty )
  490. BuildEffectiveShapes( UNDEFINED_LAYER );
  491. return m_effectiveBoundingBox;
  492. }
  493. void PAD::SetDrawCoord()
  494. {
  495. FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( m_parent );
  496. m_pos = m_pos0;
  497. if( parentFootprint == nullptr )
  498. return;
  499. RotatePoint( &m_pos.x, &m_pos.y, parentFootprint->GetOrientation() );
  500. m_pos += parentFootprint->GetPosition();
  501. SetDirty();
  502. }
  503. void PAD::SetLocalCoord()
  504. {
  505. FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( m_parent );
  506. if( parentFootprint == nullptr )
  507. {
  508. m_pos0 = m_pos;
  509. return;
  510. }
  511. m_pos0 = m_pos - parentFootprint->GetPosition();
  512. RotatePoint( &m_pos0.x, &m_pos0.y, -parentFootprint->GetOrientation() );
  513. }
  514. void PAD::SetAttribute( PAD_ATTRIB aAttribute )
  515. {
  516. m_attribute = aAttribute;
  517. if( aAttribute == PAD_ATTRIB::SMD )
  518. m_drill = VECTOR2I( 0, 0 );
  519. SetDirty();
  520. }
  521. void PAD::SetProperty( PAD_PROP aProperty )
  522. {
  523. m_property = aProperty;
  524. SetDirty();
  525. }
  526. void PAD::SetOrientation( const EDA_ANGLE& aAngle )
  527. {
  528. m_orient = aAngle;
  529. m_orient.Normalize();
  530. SetDirty();
  531. }
  532. void PAD::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
  533. {
  534. if( aFlipLeftRight )
  535. {
  536. MIRROR( m_pos.x, aCentre.x );
  537. MIRROR( m_pos0.x, 0 );
  538. MIRROR( m_offset.x, 0 );
  539. MIRROR( m_deltaSize.x, 0 );
  540. }
  541. else
  542. {
  543. MIRROR( m_pos.y, aCentre.y );
  544. MIRROR( m_pos0.y, 0 );
  545. MIRROR( m_offset.y, 0 );
  546. MIRROR( m_deltaSize.y, 0 );
  547. }
  548. SetOrientation( -GetOrientation() );
  549. auto mirrorBitFlags = []( int& aBitfield, int a, int b )
  550. {
  551. bool temp = aBitfield & a;
  552. if( aBitfield & b )
  553. aBitfield |= a;
  554. else
  555. aBitfield &= ~a;
  556. if( temp )
  557. aBitfield |= b;
  558. else
  559. aBitfield &= ~b;
  560. };
  561. if( aFlipLeftRight )
  562. {
  563. mirrorBitFlags( m_chamferPositions, RECT_CHAMFER_TOP_LEFT, RECT_CHAMFER_TOP_RIGHT );
  564. mirrorBitFlags( m_chamferPositions, RECT_CHAMFER_BOTTOM_LEFT, RECT_CHAMFER_BOTTOM_RIGHT );
  565. }
  566. else
  567. {
  568. mirrorBitFlags( m_chamferPositions, RECT_CHAMFER_TOP_LEFT, RECT_CHAMFER_BOTTOM_LEFT );
  569. mirrorBitFlags( m_chamferPositions, RECT_CHAMFER_TOP_RIGHT, RECT_CHAMFER_BOTTOM_RIGHT );
  570. }
  571. // flip pads layers
  572. // PADS items are currently on all copper layers, or
  573. // currently, only on Front or Back layers.
  574. // So the copper layers count is not taken in account
  575. SetLayerSet( FlipLayerMask( m_layerMask ) );
  576. // Flip the basic shapes, in custom pads
  577. FlipPrimitives( aFlipLeftRight );
  578. SetDirty();
  579. }
  580. void PAD::FlipPrimitives( bool aFlipLeftRight )
  581. {
  582. for( std::shared_ptr<PCB_SHAPE>& primitive : m_editPrimitives )
  583. primitive->Flip( VECTOR2I( 0, 0 ), aFlipLeftRight );
  584. SetDirty();
  585. }
  586. VECTOR2I PAD::ShapePos() const
  587. {
  588. if( m_offset.x == 0 && m_offset.y == 0 )
  589. return m_pos;
  590. VECTOR2I loc_offset = m_offset;
  591. RotatePoint( loc_offset, m_orient );
  592. VECTOR2I shape_pos = m_pos + loc_offset;
  593. return shape_pos;
  594. }
  595. int PAD::GetLocalClearanceOverrides( wxString* aSource ) const
  596. {
  597. // A pad can have specific clearance that overrides its NETCLASS clearance value
  598. if( GetLocalClearance() )
  599. return GetLocalClearance( aSource );
  600. // A footprint can have a specific clearance value
  601. if( GetParent() && GetParent()->GetLocalClearance() )
  602. return GetParent()->GetLocalClearance( aSource );
  603. return 0;
  604. }
  605. int PAD::GetLocalClearance( wxString* aSource ) const
  606. {
  607. if( aSource )
  608. *aSource = _( "pad" );
  609. return m_localClearance;
  610. }
  611. int PAD::GetOwnClearance( PCB_LAYER_ID aLayer, wxString* aSource ) const
  612. {
  613. DRC_CONSTRAINT c;
  614. if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
  615. {
  616. BOARD_DESIGN_SETTINGS& bds = GetBoard()->GetDesignSettings();
  617. if( GetAttribute() == PAD_ATTRIB::NPTH )
  618. c = bds.m_DRCEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, this, nullptr, aLayer );
  619. else
  620. c = bds.m_DRCEngine->EvalRules( CLEARANCE_CONSTRAINT, this, nullptr, aLayer );
  621. }
  622. if( c.Value().HasMin() )
  623. {
  624. if( aSource )
  625. *aSource = c.GetName();
  626. return c.Value().Min();
  627. }
  628. return 0;
  629. }
  630. int PAD::GetSolderMaskExpansion() const
  631. {
  632. // The pad inherits the margin only to calculate a default shape,
  633. // therefore only if it is also a copper layer
  634. // Pads defined only on mask layers (and perhaps on other tech layers) use the shape
  635. // defined by the pad settings only
  636. bool isOnCopperLayer = ( m_layerMask & LSET::AllCuMask() ).any();
  637. if( !isOnCopperLayer )
  638. return 0;
  639. int margin = m_localSolderMaskMargin;
  640. FOOTPRINT* parentFootprint = GetParent();
  641. if( parentFootprint )
  642. {
  643. if( margin == 0 )
  644. {
  645. if( parentFootprint->GetLocalSolderMaskMargin() )
  646. margin = parentFootprint->GetLocalSolderMaskMargin();
  647. }
  648. if( margin == 0 )
  649. {
  650. const BOARD* brd = GetBoard();
  651. if( brd )
  652. margin = brd->GetDesignSettings().m_SolderMaskExpansion;
  653. }
  654. }
  655. // ensure mask have a size always >= 0
  656. if( margin < 0 )
  657. {
  658. int minsize = -std::min( m_size.x, m_size.y ) / 2;
  659. if( margin < minsize )
  660. margin = minsize;
  661. }
  662. return margin;
  663. }
  664. VECTOR2I PAD::GetSolderPasteMargin() const
  665. {
  666. // The pad inherits the margin only to calculate a default shape,
  667. // therefore only if it is also a copper layer.
  668. // Pads defined only on mask layers (and perhaps on other tech layers) use the shape
  669. // defined by the pad settings only
  670. bool isOnCopperLayer = ( m_layerMask & LSET::AllCuMask() ).any();
  671. if( !isOnCopperLayer )
  672. return VECTOR2I( 0, 0 );
  673. int margin = m_localSolderPasteMargin;
  674. double mratio = m_localSolderPasteMarginRatio;
  675. FOOTPRINT* parentFootprint = GetParent();
  676. if( parentFootprint )
  677. {
  678. if( margin == 0 )
  679. margin = parentFootprint->GetLocalSolderPasteMargin();
  680. auto brd = GetBoard();
  681. if( margin == 0 && brd )
  682. margin = brd->GetDesignSettings().m_SolderPasteMargin;
  683. if( mratio == 0.0 )
  684. mratio = parentFootprint->GetLocalSolderPasteMarginRatio();
  685. if( mratio == 0.0 && brd )
  686. {
  687. mratio = brd->GetDesignSettings().m_SolderPasteMarginRatio;
  688. }
  689. }
  690. VECTOR2I pad_margin;
  691. pad_margin.x = margin + KiROUND( m_size.x * mratio );
  692. pad_margin.y = margin + KiROUND( m_size.y * mratio );
  693. // ensure mask have a size always >= 0
  694. if( pad_margin.x < -m_size.x / 2 )
  695. pad_margin.x = -m_size.x / 2;
  696. if( pad_margin.y < -m_size.y / 2 )
  697. pad_margin.y = -m_size.y / 2;
  698. return pad_margin;
  699. }
  700. ZONE_CONNECTION PAD::GetLocalZoneConnectionOverride( wxString* aSource ) const
  701. {
  702. if( m_zoneConnection != ZONE_CONNECTION::INHERITED && aSource )
  703. *aSource = _( "pad" );
  704. return m_zoneConnection;
  705. }
  706. int PAD::GetLocalSpokeWidthOverride( wxString* aSource ) const
  707. {
  708. if( m_thermalSpokeWidth > 0 && aSource )
  709. *aSource = _( "pad" );
  710. return m_thermalSpokeWidth;
  711. }
  712. int PAD::GetLocalThermalGapOverride( wxString* aSource ) const
  713. {
  714. if( m_thermalGap > 0 && aSource )
  715. *aSource = _( "pad" );
  716. return m_thermalGap;
  717. }
  718. void PAD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
  719. {
  720. wxString msg;
  721. FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( m_parent );
  722. if( aFrame->GetName() == PCB_EDIT_FRAME_NAME )
  723. {
  724. if( parentFootprint )
  725. aList.emplace_back( _( "Footprint" ), parentFootprint->GetReference() );
  726. }
  727. aList.emplace_back( _( "Pad" ), m_number );
  728. if( !GetPinFunction().IsEmpty() )
  729. aList.emplace_back( _( "Pin Name" ), GetPinFunction() );
  730. if( !GetPinType().IsEmpty() )
  731. aList.emplace_back( _( "Pin Type" ), GetPinType() );
  732. if( aFrame->GetName() == PCB_EDIT_FRAME_NAME )
  733. {
  734. aList.emplace_back( _( "Net" ), UnescapeString( GetNetname() ) );
  735. aList.emplace_back( _( "Resolved Netclass" ),
  736. UnescapeString( GetEffectiveNetClass()->GetName() ) );
  737. if( IsLocked() )
  738. aList.emplace_back( _( "Status" ), _( "Locked" ) );
  739. }
  740. if( GetAttribute() == PAD_ATTRIB::SMD || GetAttribute() == PAD_ATTRIB::CONN )
  741. aList.emplace_back( _( "Layer" ), layerMaskDescribe() );
  742. // Show the pad shape, attribute and property
  743. wxString props = ShowPadAttr();
  744. if( GetProperty() != PAD_PROP::NONE )
  745. props += ',';
  746. switch( GetProperty() )
  747. {
  748. case PAD_PROP::NONE: break;
  749. case PAD_PROP::BGA: props += _( "BGA" ); break;
  750. case PAD_PROP::FIDUCIAL_GLBL: props += _( "Fiducial global" ); break;
  751. case PAD_PROP::FIDUCIAL_LOCAL: props += _( "Fiducial local" ); break;
  752. case PAD_PROP::TESTPOINT: props += _( "Test point" ); break;
  753. case PAD_PROP::HEATSINK: props += _( "Heat sink" ); break;
  754. case PAD_PROP::CASTELLATED: props += _( "Castellated" ); break;
  755. }
  756. aList.emplace_back( ShowPadShape(), props );
  757. if( ( GetShape() == PAD_SHAPE::CIRCLE || GetShape() == PAD_SHAPE::OVAL )
  758. && m_size.x == m_size.y )
  759. {
  760. aList.emplace_back( _( "Diameter" ), aFrame->MessageTextFromValue( m_size.x ) );
  761. }
  762. else
  763. {
  764. aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( m_size.x ) );
  765. aList.emplace_back( _( "Height" ), aFrame->MessageTextFromValue( m_size.y ) );
  766. }
  767. EDA_ANGLE fp_orient = parentFootprint ? parentFootprint->GetOrientation() : ANGLE_0;
  768. EDA_ANGLE pad_orient = GetOrientation() - fp_orient;
  769. pad_orient.Normalize180();
  770. if( !fp_orient.IsZero() )
  771. msg.Printf( wxT( "%g(+ %g)" ), pad_orient.AsDegrees(), fp_orient.AsDegrees() );
  772. else
  773. msg.Printf( wxT( "%g" ), GetOrientation().AsDegrees() );
  774. aList.emplace_back( _( "Rotation" ), msg );
  775. if( GetPadToDieLength() )
  776. {
  777. aList.emplace_back( _( "Length in Package" ),
  778. aFrame->MessageTextFromValue( GetPadToDieLength() ) );
  779. }
  780. if( m_drill.x > 0 || m_drill.y > 0 )
  781. {
  782. if( GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
  783. {
  784. aList.emplace_back( _( "Hole" ),
  785. wxString::Format( wxT( "%s" ),
  786. aFrame->MessageTextFromValue( m_drill.x ) ) );
  787. }
  788. else
  789. {
  790. aList.emplace_back( _( "Hole X / Y" ),
  791. wxString::Format( wxT( "%s / %s" ),
  792. aFrame->MessageTextFromValue( m_drill.x ),
  793. aFrame->MessageTextFromValue( m_drill.y ) ) );
  794. }
  795. }
  796. wxString source;
  797. int clearance = GetOwnClearance( UNDEFINED_LAYER, &source );
  798. if( !source.IsEmpty() )
  799. {
  800. aList.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
  801. aFrame->MessageTextFromValue( clearance ) ),
  802. wxString::Format( _( "(from %s)" ),
  803. source ) );
  804. }
  805. #if 0
  806. // useful for debug only
  807. aList.emplace_back( wxT( "UUID" ), m_Uuid.AsString() );
  808. #endif
  809. }
  810. bool PAD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
  811. {
  812. VECTOR2I delta = aPosition - GetPosition();
  813. int boundingRadius = GetBoundingRadius() + aAccuracy;
  814. if( delta.SquaredEuclideanNorm() > SEG::Square( boundingRadius ) )
  815. return false;
  816. return GetEffectivePolygon()->Contains( aPosition, -1, aAccuracy );
  817. }
  818. bool PAD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
  819. {
  820. BOX2I arect = aRect;
  821. arect.Normalize();
  822. arect.Inflate( aAccuracy );
  823. BOX2I bbox = GetBoundingBox();
  824. if( aContained )
  825. {
  826. return arect.Contains( bbox );
  827. }
  828. else
  829. {
  830. // Fast test: if aRect is outside the polygon bounding box,
  831. // rectangles cannot intersect
  832. if( !arect.Intersects( bbox ) )
  833. return false;
  834. const std::shared_ptr<SHAPE_POLY_SET>& poly = GetEffectivePolygon();
  835. int count = poly->TotalVertices();
  836. for( int ii = 0; ii < count; ii++ )
  837. {
  838. VECTOR2I vertex = poly->CVertex( ii );
  839. VECTOR2I vertexNext = poly->CVertex( ( ii + 1 ) % count );
  840. // Test if the point is within aRect
  841. if( arect.Contains( vertex ) )
  842. return true;
  843. // Test if this edge intersects aRect
  844. if( arect.Intersects( vertex, vertexNext ) )
  845. return true;
  846. }
  847. return false;
  848. }
  849. }
  850. int PAD::Compare( const PAD* aPadRef, const PAD* aPadCmp )
  851. {
  852. int diff;
  853. if( ( diff = static_cast<int>( aPadRef->GetShape() ) -
  854. static_cast<int>( aPadCmp->GetShape() ) ) != 0 )
  855. return diff;
  856. if( ( diff = static_cast<int>( aPadRef->m_attribute ) -
  857. static_cast<int>( aPadCmp->m_attribute ) ) != 0 )
  858. return diff;
  859. if( ( diff = aPadRef->m_drillShape - aPadCmp->m_drillShape ) != 0 )
  860. return diff;
  861. if( ( diff = aPadRef->m_drill.x - aPadCmp->m_drill.x ) != 0 )
  862. return diff;
  863. if( ( diff = aPadRef->m_drill.y - aPadCmp->m_drill.y ) != 0 )
  864. return diff;
  865. if( ( diff = aPadRef->m_size.x - aPadCmp->m_size.x ) != 0 )
  866. return diff;
  867. if( ( diff = aPadRef->m_size.y - aPadCmp->m_size.y ) != 0 )
  868. return diff;
  869. if( ( diff = aPadRef->m_offset.x - aPadCmp->m_offset.x ) != 0 )
  870. return diff;
  871. if( ( diff = aPadRef->m_offset.y - aPadCmp->m_offset.y ) != 0 )
  872. return diff;
  873. if( ( diff = aPadRef->m_deltaSize.x - aPadCmp->m_deltaSize.x ) != 0 )
  874. return diff;
  875. if( ( diff = aPadRef->m_deltaSize.y - aPadCmp->m_deltaSize.y ) != 0 )
  876. return diff;
  877. if( ( diff = aPadRef->m_roundedCornerScale - aPadCmp->m_roundedCornerScale ) != 0 )
  878. return diff;
  879. if( ( diff = aPadRef->m_chamferPositions - aPadCmp->m_chamferPositions ) != 0 )
  880. return diff;
  881. if( ( diff = aPadRef->m_chamferScale - aPadCmp->m_chamferScale ) != 0 )
  882. return diff;
  883. if( ( diff = static_cast<int>( aPadRef->m_editPrimitives.size() ) -
  884. static_cast<int>( aPadCmp->m_editPrimitives.size() ) ) != 0 )
  885. return diff;
  886. // @todo: Compare custom pad primitives for pads that have the same number of primitives
  887. // here. Currently there is no compare function for PCB_SHAPE objects.
  888. // Dick: specctra_export needs this
  889. // Lorenzo: gencad also needs it to implement padstacks!
  890. #if __cplusplus >= 201103L
  891. long long d = aPadRef->m_layerMask.to_ullong() - aPadCmp->m_layerMask.to_ullong();
  892. if( d < 0 )
  893. return -1;
  894. else if( d > 0 )
  895. return 1;
  896. return 0;
  897. #else
  898. // these strings are not typically constructed, since we don't get here often.
  899. std::string s1 = aPadRef->m_layerMask.to_string();
  900. std::string s2 = aPadCmp->m_layerMask.to_string();
  901. return s1.compare( s2 );
  902. #endif
  903. }
  904. void PAD::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
  905. {
  906. RotatePoint( m_pos, aRotCentre, aAngle );
  907. m_orient += aAngle;
  908. m_orient.Normalize();
  909. SetLocalCoord();
  910. SetDirty();
  911. }
  912. wxString PAD::ShowPadShape() const
  913. {
  914. switch( GetShape() )
  915. {
  916. case PAD_SHAPE::CIRCLE: return _( "Circle" );
  917. case PAD_SHAPE::OVAL: return _( "Oval" );
  918. case PAD_SHAPE::RECT: return _( "Rect" );
  919. case PAD_SHAPE::TRAPEZOID: return _( "Trap" );
  920. case PAD_SHAPE::ROUNDRECT: return _( "Roundrect" );
  921. case PAD_SHAPE::CHAMFERED_RECT: return _( "Chamferedrect" );
  922. case PAD_SHAPE::CUSTOM: return _( "CustomShape" );
  923. default: return wxT( "???" );
  924. }
  925. }
  926. wxString PAD::ShowPadAttr() const
  927. {
  928. switch( GetAttribute() )
  929. {
  930. case PAD_ATTRIB::PTH: return _( "PTH" );
  931. case PAD_ATTRIB::SMD: return _( "SMD" );
  932. case PAD_ATTRIB::CONN: return _( "Conn" );
  933. case PAD_ATTRIB::NPTH: return _( "NPTH" );
  934. default: return wxT( "???" );
  935. }
  936. }
  937. wxString PAD::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
  938. {
  939. if( GetNumber().IsEmpty() )
  940. {
  941. if( GetAttribute() == PAD_ATTRIB::SMD || GetAttribute() == PAD_ATTRIB::CONN )
  942. {
  943. return wxString::Format( _( "Pad %s of %s on %s" ),
  944. GetNetnameMsg(),
  945. GetParent()->GetReference(),
  946. layerMaskDescribe() );
  947. }
  948. else if( GetAttribute() == PAD_ATTRIB::NPTH )
  949. {
  950. return wxString::Format( _( "NPTH pad of %s" ), GetParent()->GetReference() );
  951. }
  952. else
  953. {
  954. return wxString::Format( _( "PTH pad %s of %s" ),
  955. GetNetnameMsg(),
  956. GetParent()->GetReference() );
  957. }
  958. }
  959. else
  960. {
  961. if( GetAttribute() == PAD_ATTRIB::SMD || GetAttribute() == PAD_ATTRIB::CONN )
  962. {
  963. return wxString::Format( _( "Pad %s %s of %s on %s" ),
  964. GetNumber(),
  965. GetNetnameMsg(),
  966. GetParent()->GetReference(),
  967. layerMaskDescribe() );
  968. }
  969. else if( GetAttribute() == PAD_ATTRIB::NPTH )
  970. {
  971. return wxString::Format( _( "NPTH of %s" ), GetParent()->GetReference() );
  972. }
  973. else
  974. {
  975. return wxString::Format( _( "PTH pad %s %s of %s" ),
  976. GetNumber(),
  977. GetNetnameMsg(),
  978. GetParent()->GetReference() );
  979. }
  980. }
  981. }
  982. BITMAPS PAD::GetMenuImage() const
  983. {
  984. return BITMAPS::pad;
  985. }
  986. EDA_ITEM* PAD::Clone() const
  987. {
  988. return new PAD( *this );
  989. }
  990. void PAD::ViewGetLayers( int aLayers[], int& aCount ) const
  991. {
  992. aCount = 0;
  993. // These 2 types of pads contain a hole
  994. if( m_attribute == PAD_ATTRIB::PTH )
  995. {
  996. aLayers[aCount++] = LAYER_PAD_PLATEDHOLES;
  997. aLayers[aCount++] = LAYER_PAD_HOLEWALLS;
  998. }
  999. if( m_attribute == PAD_ATTRIB::NPTH )
  1000. aLayers[aCount++] = LAYER_NON_PLATEDHOLES;
  1001. if( IsOnLayer( F_Cu ) && IsOnLayer( B_Cu ) )
  1002. {
  1003. // Multi layer pad
  1004. aLayers[aCount++] = LAYER_PADS_TH;
  1005. aLayers[aCount++] = LAYER_PAD_NETNAMES;
  1006. }
  1007. else if( IsOnLayer( F_Cu ) )
  1008. {
  1009. aLayers[aCount++] = LAYER_PAD_FR;
  1010. // Is this a PTH pad that has only front copper? If so, we need to also display the
  1011. // net name on the PTH netname layer so that it isn't blocked by the drill hole.
  1012. if( m_attribute == PAD_ATTRIB::PTH )
  1013. aLayers[aCount++] = LAYER_PAD_NETNAMES;
  1014. else
  1015. aLayers[aCount++] = LAYER_PAD_FR_NETNAMES;
  1016. }
  1017. else if( IsOnLayer( B_Cu ) )
  1018. {
  1019. aLayers[aCount++] = LAYER_PAD_BK;
  1020. // Is this a PTH pad that has only back copper? If so, we need to also display the
  1021. // net name on the PTH netname layer so that it isn't blocked by the drill hole.
  1022. if( m_attribute == PAD_ATTRIB::PTH )
  1023. aLayers[aCount++] = LAYER_PAD_NETNAMES;
  1024. else
  1025. aLayers[aCount++] = LAYER_PAD_BK_NETNAMES;
  1026. }
  1027. else
  1028. {
  1029. // Internal layers only. (Not yet supported in GUI, but is being used by Python
  1030. // footprint generators and will be needed anyway once pad stacks are supported.)
  1031. for ( int internal = In1_Cu; internal < In30_Cu; ++internal )
  1032. {
  1033. if( IsOnLayer( (PCB_LAYER_ID) internal ) )
  1034. aLayers[aCount++] = internal;
  1035. }
  1036. }
  1037. // Check non-copper layers. This list should include all the layers that the
  1038. // footprint editor allows a pad to be placed on.
  1039. static const PCB_LAYER_ID layers_mech[] = { F_Mask, B_Mask, F_Paste, B_Paste,
  1040. F_Adhes, B_Adhes, F_SilkS, B_SilkS, Dwgs_User, Eco1_User, Eco2_User };
  1041. for( PCB_LAYER_ID each_layer : layers_mech )
  1042. {
  1043. if( IsOnLayer( each_layer ) )
  1044. aLayers[aCount++] = each_layer;
  1045. }
  1046. #ifdef DEBUG
  1047. if( aCount == 0 ) // Should not occur
  1048. {
  1049. wxString msg;
  1050. msg.Printf( wxT( "footprint %s, pad %s: could not find valid layer for pad" ),
  1051. GetParent() ? GetParent()->GetReference() : wxT( "<null>" ),
  1052. GetNumber().IsEmpty() ? wxT( "(unnumbered)" ) : GetNumber() );
  1053. wxLogDebug( msg );
  1054. }
  1055. #endif
  1056. }
  1057. double PAD::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
  1058. {
  1059. constexpr double HIDE = std::numeric_limits<double>::max();
  1060. PCB_PAINTER* painter = static_cast<PCB_PAINTER*>( aView->GetPainter() );
  1061. PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
  1062. const BOARD* board = GetBoard();
  1063. // Meta control for hiding all pads
  1064. if( !aView->IsLayerVisible( LAYER_PADS ) )
  1065. return HIDE;
  1066. // Handle Render tab switches
  1067. if( ( GetAttribute() == PAD_ATTRIB::PTH || GetAttribute() == PAD_ATTRIB::NPTH )
  1068. && !aView->IsLayerVisible( LAYER_PADS_TH ) )
  1069. {
  1070. return HIDE;
  1071. }
  1072. if( !IsFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) )
  1073. return HIDE;
  1074. if( IsFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) )
  1075. return HIDE;
  1076. if( IsFrontLayer( (PCB_LAYER_ID) aLayer ) && !aView->IsLayerVisible( LAYER_PAD_FR ) )
  1077. return HIDE;
  1078. if( IsBackLayer( (PCB_LAYER_ID) aLayer ) && !aView->IsLayerVisible( LAYER_PAD_BK ) )
  1079. return HIDE;
  1080. LSET visible = board->GetVisibleLayers() & board->GetEnabledLayers();
  1081. if( IsHoleLayer( aLayer ) )
  1082. {
  1083. if( !( visible & LSET::PhysicalLayersMask() ).any() )
  1084. return HIDE;
  1085. }
  1086. else if( IsNetnameLayer( aLayer ) )
  1087. {
  1088. if( renderSettings->GetHighContrast() )
  1089. {
  1090. // Hide netnames unless pad is flashed to a high-contrast layer
  1091. if( !FlashLayer( renderSettings->GetPrimaryHighContrastLayer() ) )
  1092. return HIDE;
  1093. }
  1094. else
  1095. {
  1096. // Hide netnames unless pad is flashed to a visible layer
  1097. if( !FlashLayer( visible ) )
  1098. return HIDE;
  1099. }
  1100. // Netnames will be shown only if zoom is appropriate
  1101. int divisor = std::min( GetBoundingBox().GetWidth(), GetBoundingBox().GetHeight() );
  1102. // Pad sizes can be zero briefly when someone is typing a number like "0.5" in the pad
  1103. // properties dialog
  1104. if( divisor == 0 )
  1105. return HIDE;
  1106. return ( double ) pcbIUScale.mmToIU( 5 ) / divisor;
  1107. }
  1108. // Passed all tests; show.
  1109. return 0.0;
  1110. }
  1111. const BOX2I PAD::ViewBBox() const
  1112. {
  1113. // Bounding box includes soldermask too. Remember mask and/or paste margins can be < 0
  1114. int solderMaskMargin = std::max( GetSolderMaskExpansion(), 0 );
  1115. VECTOR2I solderPasteMargin = VECTOR2D( GetSolderPasteMargin() );
  1116. BOX2I bbox = GetBoundingBox();
  1117. int clearance = 0;
  1118. // If we're drawing clearance lines then get the biggest possible clearance
  1119. if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
  1120. {
  1121. if( cfg && cfg->m_Display.m_PadClearance && GetBoard() )
  1122. clearance = GetBoard()->GetDesignSettings().GetBiggestClearanceValue();
  1123. }
  1124. // Look for the biggest possible bounding box
  1125. int xMargin = std::max( solderMaskMargin, solderPasteMargin.x ) + clearance;
  1126. int yMargin = std::max( solderMaskMargin, solderPasteMargin.y ) + clearance;
  1127. return BOX2I( VECTOR2I( bbox.GetOrigin() ) - VECTOR2I( xMargin, yMargin ),
  1128. VECTOR2I( bbox.GetSize() ) + VECTOR2I( 2 * xMargin, 2 * yMargin ) );
  1129. }
  1130. FOOTPRINT* PAD::GetParent() const
  1131. {
  1132. return dyn_cast<FOOTPRINT*>( m_parent );
  1133. }
  1134. void PAD::ImportSettingsFrom( const PAD& aMasterPad )
  1135. {
  1136. SetShape( aMasterPad.GetShape() );
  1137. SetLayerSet( aMasterPad.GetLayerSet() );
  1138. SetAttribute( aMasterPad.GetAttribute() );
  1139. SetProperty( aMasterPad.GetProperty() );
  1140. // I am not sure the m_LengthPadToDie should be imported, because this is a parameter
  1141. // really specific to a given pad (JPC).
  1142. #if 0
  1143. SetPadToDieLength( aMasterPad.GetPadToDieLength() );
  1144. #endif
  1145. // The pad orientation, for historical reasons is the pad rotation + parent rotation.
  1146. EDA_ANGLE pad_rot = aMasterPad.GetOrientation();
  1147. if( aMasterPad.GetParent() )
  1148. pad_rot -= aMasterPad.GetParent()->GetOrientation();
  1149. if( GetParent() )
  1150. pad_rot += GetParent()->GetOrientation();
  1151. SetOrientation( pad_rot );
  1152. SetRemoveUnconnected( aMasterPad.GetRemoveUnconnected() );
  1153. SetKeepTopBottom( aMasterPad.GetKeepTopBottom() );
  1154. SetSize( aMasterPad.GetSize() );
  1155. SetDelta( VECTOR2I( 0, 0 ) );
  1156. SetOffset( aMasterPad.GetOffset() );
  1157. SetDrillSize( aMasterPad.GetDrillSize() );
  1158. SetDrillShape( aMasterPad.GetDrillShape() );
  1159. SetRoundRectRadiusRatio( aMasterPad.GetRoundRectRadiusRatio() );
  1160. SetChamferRectRatio( aMasterPad.GetChamferRectRatio() );
  1161. SetChamferPositions( aMasterPad.GetChamferPositions() );
  1162. switch( aMasterPad.GetShape() )
  1163. {
  1164. case PAD_SHAPE::TRAPEZOID:
  1165. SetDelta( aMasterPad.GetDelta() );
  1166. break;
  1167. case PAD_SHAPE::CIRCLE:
  1168. // ensure size.y == size.x
  1169. SetSize( VECTOR2I( GetSize().x, GetSize().x ) );
  1170. break;
  1171. default:
  1172. ;
  1173. }
  1174. switch( aMasterPad.GetAttribute() )
  1175. {
  1176. case PAD_ATTRIB::SMD:
  1177. case PAD_ATTRIB::CONN:
  1178. // These pads do not have a hole (they are expected to be on one external copper layer)
  1179. SetDrillSize( VECTOR2I( 0, 0 ) );
  1180. break;
  1181. default:
  1182. ;
  1183. }
  1184. // copy also local settings:
  1185. SetLocalClearance( aMasterPad.GetLocalClearance() );
  1186. SetLocalSolderMaskMargin( aMasterPad.GetLocalSolderMaskMargin() );
  1187. SetLocalSolderPasteMargin( aMasterPad.GetLocalSolderPasteMargin() );
  1188. SetLocalSolderPasteMarginRatio( aMasterPad.GetLocalSolderPasteMarginRatio() );
  1189. SetZoneConnection( aMasterPad.GetZoneConnection() );
  1190. SetThermalSpokeWidth( aMasterPad.GetThermalSpokeWidth() );
  1191. SetThermalSpokeAngle( aMasterPad.GetThermalSpokeAngle() );
  1192. SetThermalGap( aMasterPad.GetThermalGap() );
  1193. SetCustomShapeInZoneOpt( aMasterPad.GetCustomShapeInZoneOpt() );
  1194. // Add or remove custom pad shapes:
  1195. ReplacePrimitives( aMasterPad.GetPrimitives() );
  1196. SetAnchorPadShape( aMasterPad.GetAnchorPadShape() );
  1197. SetDirty();
  1198. }
  1199. void PAD::swapData( BOARD_ITEM* aImage )
  1200. {
  1201. assert( aImage->Type() == PCB_PAD_T );
  1202. std::swap( *this, *static_cast<PAD*>( aImage ) );
  1203. }
  1204. bool PAD::TransformHoleToPolygon( SHAPE_POLY_SET& aBuffer, int aClearance, int aError,
  1205. ERROR_LOC aErrorLoc ) const
  1206. {
  1207. VECTOR2I drillsize = GetDrillSize();
  1208. if( !drillsize.x || !drillsize.y )
  1209. return false;
  1210. std::shared_ptr<SHAPE_SEGMENT> slot = GetEffectiveHoleShape();
  1211. TransformOvalToPolygon( aBuffer, slot->GetSeg().A, slot->GetSeg().B,
  1212. slot->GetWidth() + aClearance * 2, aError, aErrorLoc );
  1213. return true;
  1214. }
  1215. void PAD::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  1216. int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth ) const
  1217. {
  1218. wxASSERT_MSG( !ignoreLineWidth, wxT( "IgnoreLineWidth has no meaning for pads." ) );
  1219. // minimal segment count to approximate a circle to create the polygonal pad shape
  1220. // This minimal value is mainly for very small pads, like SM0402.
  1221. // Most of time pads are using the segment count given by aError value.
  1222. const int pad_min_seg_per_circle_count = 16;
  1223. int dx = m_size.x / 2;
  1224. int dy = m_size.y / 2;
  1225. VECTOR2I padShapePos = ShapePos(); // Note: for pad having a shape offset, the pad
  1226. // position is NOT the shape position
  1227. switch( GetShape() )
  1228. {
  1229. case PAD_SHAPE::CIRCLE:
  1230. case PAD_SHAPE::OVAL:
  1231. // Note: dx == dy is not guaranteed for circle pads in legacy boards
  1232. if( dx == dy || ( GetShape() == PAD_SHAPE::CIRCLE ) )
  1233. {
  1234. TransformCircleToPolygon( aBuffer, padShapePos, dx + aClearance, aError, aErrorLoc,
  1235. pad_min_seg_per_circle_count );
  1236. }
  1237. else
  1238. {
  1239. int half_width = std::min( dx, dy );
  1240. VECTOR2I delta( dx - half_width, dy - half_width );
  1241. RotatePoint( delta, m_orient );
  1242. TransformOvalToPolygon( aBuffer, padShapePos - delta, padShapePos + delta,
  1243. ( half_width + aClearance ) * 2, aError, aErrorLoc,
  1244. pad_min_seg_per_circle_count );
  1245. }
  1246. break;
  1247. case PAD_SHAPE::TRAPEZOID:
  1248. case PAD_SHAPE::RECT:
  1249. {
  1250. int ddx = GetShape() == PAD_SHAPE::TRAPEZOID ? m_deltaSize.x / 2 : 0;
  1251. int ddy = GetShape() == PAD_SHAPE::TRAPEZOID ? m_deltaSize.y / 2 : 0;
  1252. SHAPE_POLY_SET outline;
  1253. TransformTrapezoidToPolygon( outline, padShapePos, m_size, m_orient, ddx, ddy, aClearance,
  1254. aError, aErrorLoc );
  1255. aBuffer.Append( outline );
  1256. break;
  1257. }
  1258. case PAD_SHAPE::CHAMFERED_RECT:
  1259. case PAD_SHAPE::ROUNDRECT:
  1260. {
  1261. bool doChamfer = GetShape() == PAD_SHAPE::CHAMFERED_RECT;
  1262. SHAPE_POLY_SET outline;
  1263. TransformRoundChamferedRectToPolygon( outline, padShapePos, m_size, m_orient,
  1264. GetRoundRectCornerRadius(),
  1265. doChamfer ? GetChamferRectRatio() : 0,
  1266. doChamfer ? GetChamferPositions() : 0,
  1267. aClearance, aError, aErrorLoc );
  1268. aBuffer.Append( outline );
  1269. break;
  1270. }
  1271. case PAD_SHAPE::CUSTOM:
  1272. {
  1273. SHAPE_POLY_SET outline;
  1274. MergePrimitivesAsPolygon( &outline, aErrorLoc );
  1275. outline.Rotate( m_orient );
  1276. outline.Move( VECTOR2I( m_pos ) );
  1277. if( aClearance )
  1278. {
  1279. int numSegs = std::max( GetArcToSegmentCount( aClearance, aError, FULL_CIRCLE ),
  1280. pad_min_seg_per_circle_count );
  1281. int clearance = aClearance;
  1282. if( aErrorLoc == ERROR_OUTSIDE )
  1283. {
  1284. int actual_error = CircleToEndSegmentDeltaRadius( clearance, numSegs );
  1285. clearance += GetCircleToPolyCorrection( actual_error );
  1286. }
  1287. outline.Inflate( clearance, numSegs );
  1288. outline.Simplify( SHAPE_POLY_SET::PM_FAST );
  1289. outline.Fracture( SHAPE_POLY_SET::PM_FAST );
  1290. }
  1291. aBuffer.Append( outline );
  1292. break;
  1293. }
  1294. default:
  1295. wxFAIL_MSG( wxT( "PAD::TransformShapeToPolygon no implementation for " )
  1296. + PAD_SHAPE_T_asString( GetShape() ) );
  1297. break;
  1298. }
  1299. }
  1300. wxString PAD::GetParentAsString() const
  1301. {
  1302. if( FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( m_parent ) )
  1303. return fp->GetReference();
  1304. return m_parent->m_Uuid.AsString();
  1305. }
  1306. static struct PAD_DESC
  1307. {
  1308. PAD_DESC()
  1309. {
  1310. ENUM_MAP<PAD_ATTRIB>::Instance()
  1311. .Map( PAD_ATTRIB::PTH, _HKI( "Through-hole" ) )
  1312. .Map( PAD_ATTRIB::SMD, _HKI( "SMD" ) )
  1313. .Map( PAD_ATTRIB::CONN, _HKI( "Edge connector" ) )
  1314. .Map( PAD_ATTRIB::NPTH, _HKI( "NPTH, mechanical" ) );
  1315. ENUM_MAP<PAD_SHAPE>::Instance()
  1316. .Map( PAD_SHAPE::CIRCLE, _HKI( "Circle" ) )
  1317. .Map( PAD_SHAPE::RECT, _HKI( "Rectangle" ) )
  1318. .Map( PAD_SHAPE::OVAL, _HKI( "Oval" ) )
  1319. .Map( PAD_SHAPE::TRAPEZOID, _HKI( "Trapezoid" ) )
  1320. .Map( PAD_SHAPE::ROUNDRECT, _HKI( "Rounded rectangle" ) )
  1321. .Map( PAD_SHAPE::CHAMFERED_RECT, _HKI( "Chamfered rectangle" ) )
  1322. .Map( PAD_SHAPE::CUSTOM, _HKI( "Custom" ) );
  1323. ENUM_MAP<PAD_PROP>::Instance()
  1324. .Map( PAD_PROP::NONE, _HKI( "None" ) )
  1325. .Map( PAD_PROP::BGA, _HKI( "BGA pad" ) )
  1326. .Map( PAD_PROP::FIDUCIAL_GLBL, _HKI( "Fiducial, global to board" ) )
  1327. .Map( PAD_PROP::FIDUCIAL_LOCAL, _HKI( "Fiducial, local to footprint" ) )
  1328. .Map( PAD_PROP::TESTPOINT, _HKI( "Test point pad" ) )
  1329. .Map( PAD_PROP::HEATSINK, _HKI( "Heatsink pad" ) )
  1330. .Map( PAD_PROP::CASTELLATED, _HKI( "Castellated pad" ) );
  1331. ENUM_MAP<ZONE_CONNECTION>& zcMap = ENUM_MAP<ZONE_CONNECTION>::Instance();
  1332. if( zcMap.Choices().GetCount() == 0 )
  1333. {
  1334. zcMap.Undefined( ZONE_CONNECTION::INHERITED );
  1335. zcMap.Map( ZONE_CONNECTION::INHERITED, _HKI( "Inherited" ) )
  1336. .Map( ZONE_CONNECTION::NONE, _HKI( "None" ) )
  1337. .Map( ZONE_CONNECTION::THERMAL, _HKI( "Thermal reliefs" ) )
  1338. .Map( ZONE_CONNECTION::FULL, _HKI( "Solid" ) )
  1339. .Map( ZONE_CONNECTION::THT_THERMAL, _HKI( "Thermal reliefs for PTH" ) );
  1340. }
  1341. PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
  1342. REGISTER_TYPE( PAD );
  1343. propMgr.InheritsAfter( TYPE_HASH( PAD ), TYPE_HASH( BOARD_CONNECTED_ITEM ) );
  1344. propMgr.Mask( TYPE_HASH( PAD ), TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ) );
  1345. propMgr.AddProperty( new PROPERTY<PAD, double>( _HKI( "Orientation" ),
  1346. &PAD::SetOrientationDegrees, &PAD::GetOrientationDegrees,
  1347. PROPERTY_DISPLAY::PT_DEGREE ) );
  1348. const wxString groupPad = _( "Pad Properties" );
  1349. auto padType = new PROPERTY_ENUM<PAD, PAD_ATTRIB>( _HKI( "Pad Type" ),
  1350. &PAD::SetAttribute, &PAD::GetAttribute );
  1351. propMgr.AddProperty( padType, groupPad );
  1352. auto shape = new PROPERTY_ENUM<PAD, PAD_SHAPE>( _HKI( "Shape" ),
  1353. &PAD::SetShape, &PAD::GetShape );
  1354. propMgr.AddProperty( shape, groupPad );
  1355. propMgr.AddProperty( new PROPERTY<PAD, wxString>( _HKI( "Parent" ),
  1356. NO_SETTER( PAD, wxString ), &PAD::GetParentAsString ), groupPad );
  1357. propMgr.AddProperty( new PROPERTY<PAD, wxString>( _HKI( "Pad Number" ),
  1358. &PAD::SetNumber, &PAD::GetNumber ), groupPad);
  1359. propMgr.AddProperty( new PROPERTY<PAD, wxString>( _HKI( "Pin Name" ),
  1360. NO_SETTER( PAD, wxString ), &PAD::GetPinFunction ), groupPad );
  1361. propMgr.AddProperty( new PROPERTY<PAD, wxString>( _HKI( "Pin Type" ),
  1362. NO_SETTER( PAD, wxString ), &PAD::GetPinType ), groupPad);
  1363. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Size X" ),
  1364. &PAD::SetSizeX, &PAD::GetSizeX,
  1365. PROPERTY_DISPLAY::PT_SIZE ), groupPad );
  1366. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Size Y" ),
  1367. &PAD::SetSizeY, &PAD::GetSizeY,
  1368. PROPERTY_DISPLAY::PT_SIZE ), groupPad );
  1369. auto roundRadiusRatio = new PROPERTY<PAD, double>( _HKI( "Round Radius Ratio" ),
  1370. &PAD::SetRoundRectRadiusRatio, &PAD::GetRoundRectRadiusRatio );
  1371. roundRadiusRatio->SetAvailableFunc(
  1372. [=]( INSPECTABLE* aItem ) -> bool
  1373. {
  1374. return aItem->Get( shape ) == static_cast<int>( PAD_SHAPE::ROUNDRECT );
  1375. } );
  1376. propMgr.AddProperty( roundRadiusRatio, groupPad );
  1377. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Hole Size X" ),
  1378. &PAD::SetDrillSizeX, &PAD::GetDrillSizeX,
  1379. PROPERTY_DISPLAY::PT_SIZE ), groupPad );
  1380. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Hole Size Y" ),
  1381. &PAD::SetDrillSizeY, &PAD::GetDrillSizeY,
  1382. PROPERTY_DISPLAY::PT_SIZE ), groupPad );
  1383. propMgr.AddProperty( new PROPERTY_ENUM<PAD, PAD_PROP>( _HKI( "Fabrication Property" ),
  1384. &PAD::SetProperty, &PAD::GetProperty ), groupPad );
  1385. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Pad To Die Length" ),
  1386. &PAD::SetPadToDieLength, &PAD::GetPadToDieLength,
  1387. PROPERTY_DISPLAY::PT_SIZE ), groupPad );
  1388. const wxString groupOverrides = _( "Overrides" );
  1389. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Clearance Override" ),
  1390. &PAD::SetLocalClearance, &PAD::GetLocalClearance,
  1391. PROPERTY_DISPLAY::PT_SIZE ), groupOverrides );
  1392. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Soldermask Margin Override" ),
  1393. &PAD::SetLocalSolderMaskMargin, &PAD::GetLocalSolderMaskMargin,
  1394. PROPERTY_DISPLAY::PT_SIZE ), groupOverrides );
  1395. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Solderpaste Margin Override" ),
  1396. &PAD::SetLocalSolderPasteMargin, &PAD::GetLocalSolderPasteMargin,
  1397. PROPERTY_DISPLAY::PT_SIZE ), groupOverrides );
  1398. propMgr.AddProperty( new PROPERTY<PAD, double>( _HKI( "Solderpaste Margin Ratio Override" ),
  1399. &PAD::SetLocalSolderPasteMarginRatio, &PAD::GetLocalSolderPasteMarginRatio ),
  1400. groupOverrides );
  1401. propMgr.AddProperty( new PROPERTY_ENUM<PAD, ZONE_CONNECTION>(
  1402. _HKI( "Zone Connection Style" ),
  1403. &PAD::SetZoneConnection, &PAD::GetZoneConnection ), groupOverrides );
  1404. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Thermal Relief Spoke Width" ),
  1405. &PAD::SetThermalSpokeWidth, &PAD::GetThermalSpokeWidth,
  1406. PROPERTY_DISPLAY::PT_SIZE ), groupOverrides );
  1407. propMgr.AddProperty( new PROPERTY<PAD, double>( _HKI( "Thermal Relief Spoke Angle" ),
  1408. &PAD::SetThermalSpokeAngleDegrees, &PAD::GetThermalSpokeAngleDegrees,
  1409. PROPERTY_DISPLAY::PT_DEGREE ), groupOverrides );
  1410. propMgr.AddProperty( new PROPERTY<PAD, int>( _HKI( "Thermal Relief Gap" ),
  1411. &PAD::SetThermalGap, &PAD::GetThermalGap,
  1412. PROPERTY_DISPLAY::PT_SIZE ), groupOverrides );
  1413. // TODO delta, drill shape offset, layer set
  1414. }
  1415. } _PAD_DESC;
  1416. ENUM_TO_WXANY( PAD_ATTRIB );
  1417. ENUM_TO_WXANY( PAD_SHAPE );
  1418. ENUM_TO_WXANY( PAD_PROP );