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.

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