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.

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