KiCad PCB EDA Suite
class_pad.cpp
Go to the documentation of this file.
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-2018 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 
31 #include <fctsys.h>
32 #include <PolyLine.h>
33 #include <trigo.h>
34 #include <macros.h>
35 #include <msgpanel.h>
36 #include <base_units.h>
37 #include <bitmaps.h>
38 
39 #include <view/view.h>
40 #include <pcbnew.h>
41 
42 #include <class_board.h>
43 #include <class_module.h>
45 #include <convert_to_biu.h>
47 
48 
55 static wxString LayerMaskDescribe( const BOARD* aBoard, LSET aMask );
56 
57 int D_PAD::m_PadSketchModePenSize = 0; // Pen size used to draw pads in sketch mode
58 
59 D_PAD::D_PAD( MODULE* parent ) :
61 {
62  m_Size.x = m_Size.y = Mils2iu( 60 ); // Default pad size 60 mils.
63  m_Drill.x = m_Drill.y = Mils2iu( 30 ); // Default drill size 30 mils.
64  m_Orient = 0; // Pad rotation in 1/10 degrees.
65  m_LengthPadToDie = 0;
66 
67  if( m_Parent && m_Parent->Type() == PCB_MODULE_T )
68  {
70  }
71 
72  SetShape( PAD_SHAPE_CIRCLE ); // Default pad shape is PAD_CIRCLE.
73  SetAnchorPadShape( PAD_SHAPE_CIRCLE ); // Default shape for custom shaped pads
74  // is PAD_CIRCLE.
75  SetDrillShape( PAD_DRILL_SHAPE_CIRCLE ); // Default pad drill shape is a circle.
76  m_Attribute = PAD_ATTRIB_STANDARD; // Default pad type is NORMAL (thru hole)
77  m_LocalClearance = 0;
81  // Parameters for round rect only:
82  m_padRoundRectRadiusScale = 0.25; // from IPC-7351C standard
83 
84  m_ZoneConnection = PAD_ZONE_CONN_INHERITED; // Use parent setting by default
85  m_ThermalWidth = 0; // Use parent setting by default
86  m_ThermalGap = 0; // Use parent setting by default
87 
89 
90  // Set layers mask to default for a standard thru hole pad.
92 
93  SetSubRatsnest( 0 ); // used in ratsnest calculations
94 
95  m_boundingRadius = -1;
96 }
97 
98 
100 {
101  static LSET saved = LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask );
102  return saved;
103 }
104 
105 
107 {
108  static LSET saved( 3, F_Cu, F_Paste, F_Mask );
109  return saved;
110 }
111 
112 
114 {
115  static LSET saved( 2, F_Cu, F_Mask );
116  return saved;
117 }
118 
119 
121 {
122  static LSET saved = LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask );
123  return saved;
124 }
125 
126 bool D_PAD::IsFlipped() const
127 {
128  if( GetParent() && GetParent()->GetLayer() == B_Cu )
129  return true;
130  return false;
131 }
132 
134 {
135  int x, y;
136  int radius;
137 
138  switch( GetShape() )
139  {
140  case PAD_SHAPE_CIRCLE:
141  radius = m_Size.x / 2;
142  break;
143 
144  case PAD_SHAPE_OVAL:
145  radius = std::max( m_Size.x, m_Size.y ) / 2;
146  break;
147 
148  case PAD_SHAPE_RECT:
149  radius = 1 + KiROUND( EuclideanNorm( m_Size ) / 2 );
150  break;
151 
152  case PAD_SHAPE_TRAPEZOID:
153  x = m_Size.x + std::abs( m_DeltaSize.y ); // Remember: m_DeltaSize.y is the m_Size.x change
154  y = m_Size.y + std::abs( m_DeltaSize.x ); // Remember: m_DeltaSize.x is the m_Size.y change
155  radius = 1 + KiROUND( hypot( x, y ) / 2 );
156  break;
157 
158  case PAD_SHAPE_ROUNDRECT:
159  radius = GetRoundRectCornerRadius();
160  x = m_Size.x >> 1;
161  y = m_Size.y >> 1;
162  radius += 1 + KiROUND( EuclideanNorm( wxSize( x - radius, y - radius )));
163  break;
164 
165  case PAD_SHAPE_CUSTOM:
166  radius = 0;
167 
168  for( int cnt = 0; cnt < m_customShapeAsPolygon.OutlineCount(); ++cnt )
169  {
170  const SHAPE_LINE_CHAIN& poly = m_customShapeAsPolygon.COutline( cnt );
171  for( int ii = 0; ii < poly.PointCount(); ++ii )
172  {
173  int dist = KiROUND( poly.CPoint( ii ).EuclideanNorm() );
174  radius = std::max( radius, dist );
175  }
176  }
177 
178  radius += 1;
179  break;
180 
181  default:
182  radius = 0;
183  }
184 
185  return radius;
186 }
187 
188 
189 int D_PAD::GetRoundRectCornerRadius( const wxSize& aSize ) const
190 {
191  // radius of rounded corners, usually 25% of shorter pad edge for now
192  int r = aSize.x > aSize.y ? aSize.y : aSize.x;
193  r = int( r * m_padRoundRectRadiusScale );
194 
195  return r;
196 }
197 
198 
200 {
201  EDA_RECT area;
202  wxPoint quadrant1, quadrant2, quadrant3, quadrant4;
203  int x, y, r, dx, dy;
204 
205  wxPoint center = ShapePos();
206  wxPoint endPoint;
207 
208  EDA_RECT endRect;
209 
210  switch( GetShape() )
211  {
212  case PAD_SHAPE_CIRCLE:
213  area.SetOrigin( center );
214  area.Inflate( m_Size.x / 2 );
215  break;
216 
217  case PAD_SHAPE_OVAL:
218  /* To get the BoundingBox of an oval pad:
219  * a) If the pad is ROUND, see method for PAD_SHAPE_CIRCLE above
220  * OTHERWISE:
221  * b) Construct EDA_RECT for portion between circular ends
222  * c) Rotate that EDA_RECT
223  * d) Add the circular ends to the EDA_RECT
224  */
225 
226  // Test if the shape is circular
227  if( m_Size.x == m_Size.y )
228  {
229  area.SetOrigin( center );
230  area.Inflate( m_Size.x / 2 );
231  break;
232  }
233 
234  if( m_Size.x > m_Size.y )
235  {
236  // Pad is horizontal
237  dx = ( m_Size.x - m_Size.y ) / 2;
238  dy = m_Size.y / 2;
239 
240  // Location of end-points
241  x = dx;
242  y = 0;
243  r = dy;
244  }
245  else
246  {
247  // Pad is vertical
248  dx = m_Size.x / 2;
249  dy = ( m_Size.y - m_Size.x ) / 2;
250 
251  x = 0;
252  y = dy;
253  r = dx;
254  }
255 
256  // Construct the center rectangle and rotate
257  area.SetOrigin( center );
258  area.Inflate( dx, dy );
259  area = area.GetBoundingBoxRotated( center, m_Orient );
260 
261  endPoint = wxPoint( x, y );
262  RotatePoint( &endPoint, m_Orient );
263 
264  // Add points at each quadrant of circular regions
265  endRect.SetOrigin( center + endPoint );
266  endRect.Inflate( r );
267 
268  area.Merge( endRect );
269 
270  endRect.SetSize( 0, 0 );
271  endRect.SetOrigin( center - endPoint );
272  endRect.Inflate( r );
273 
274  area.Merge( endRect );
275 
276  break;
277 
278  case PAD_SHAPE_RECT:
279  case PAD_SHAPE_ROUNDRECT:
280  // Use two opposite corners and track their rotation
281  // (use symmetry for other points)
282  quadrant1.x = m_Size.x/2;
283  quadrant1.y = m_Size.y/2;
284  quadrant2.x = -m_Size.x/2;
285  quadrant2.y = m_Size.y/2;
286 
287  RotatePoint( &quadrant1, m_Orient );
288  RotatePoint( &quadrant2, m_Orient );
289  dx = std::max( std::abs( quadrant1.x ) , std::abs( quadrant2.x ) );
290  dy = std::max( std::abs( quadrant1.y ) , std::abs( quadrant2.y ) );
291 
292  // Set the bbox
293  area.SetOrigin( ShapePos() );
294  area.Inflate( dx, dy );
295  break;
296 
297  case PAD_SHAPE_TRAPEZOID:
298  // Use the four corners and track their rotation
299  // (Trapezoids will not be symmetric)
300 
301  quadrant1.x = (m_Size.x + m_DeltaSize.y)/2;
302  quadrant1.y = (m_Size.y - m_DeltaSize.x)/2;
303 
304  quadrant2.x = -(m_Size.x + m_DeltaSize.y)/2;
305  quadrant2.y = (m_Size.y + m_DeltaSize.x)/2;
306 
307  quadrant3.x = -(m_Size.x - m_DeltaSize.y)/2;
308  quadrant3.y = -(m_Size.y + m_DeltaSize.x)/2;
309 
310  quadrant4.x = (m_Size.x - m_DeltaSize.y)/2;
311  quadrant4.y = -(m_Size.y - m_DeltaSize.x)/2;
312 
313  RotatePoint( &quadrant1, m_Orient );
314  RotatePoint( &quadrant2, m_Orient );
315  RotatePoint( &quadrant3, m_Orient );
316  RotatePoint( &quadrant4, m_Orient );
317 
318  x = std::min( quadrant1.x, std::min( quadrant2.x, std::min( quadrant3.x, quadrant4.x) ) );
319  y = std::min( quadrant1.y, std::min( quadrant2.y, std::min( quadrant3.y, quadrant4.y) ) );
320  dx = std::max( quadrant1.x, std::max( quadrant2.x, std::max( quadrant3.x, quadrant4.x) ) );
321  dy = std::max( quadrant1.y, std::max( quadrant2.y, std::max( quadrant3.y, quadrant4.y) ) );
322 
323  area.SetOrigin( ShapePos().x + x, ShapePos().y + y );
324  area.SetSize( dx-x, dy-y );
325  break;
326 
327  case PAD_SHAPE_CUSTOM:
328  {
330  // Move shape to actual position
332  quadrant1 = m_Pos;
333  quadrant2 = m_Pos;
334 
335  for( int cnt = 0; cnt < polySet.OutlineCount(); ++cnt )
336  {
337  const SHAPE_LINE_CHAIN& poly = polySet.COutline( cnt );
338 
339  for( int ii = 0; ii < poly.PointCount(); ++ii )
340  {
341  quadrant1.x = std::min( quadrant1.x, poly.CPoint( ii ).x );
342  quadrant1.y = std::min( quadrant1.y, poly.CPoint( ii ).y );
343  quadrant2.x = std::max( quadrant2.x, poly.CPoint( ii ).x );
344  quadrant2.y = std::max( quadrant2.y, poly.CPoint( ii ).y );
345  }
346  }
347 
348  area.SetOrigin( quadrant1 );
349  area.SetEnd( quadrant2 );
350  }
351  break;
352 
353  default:
354  break;
355  }
356 
357  return area;
358 }
359 
360 
362 {
363  MODULE* module = (MODULE*) m_Parent;
364 
365  m_Pos = m_Pos0;
366 
367  if( module == NULL )
368  return;
369 
370  double angle = module->GetOrientation();
371 
372  RotatePoint( &m_Pos.x, &m_Pos.y, angle );
373  m_Pos += module->GetPosition();
374 }
375 
376 
378 {
379  MODULE* module = (MODULE*) m_Parent;
380 
381  if( module == NULL )
382  {
383  m_Pos0 = m_Pos;
384  return;
385  }
386 
387  m_Pos0 = m_Pos - module->GetPosition();
388  RotatePoint( &m_Pos0.x, &m_Pos0.y, -module->GetOrientation() );
389 }
390 
391 
392 void D_PAD::SetAttribute( PAD_ATTR_T aAttribute )
393 {
394  m_Attribute = aAttribute;
395 
396  if( aAttribute == PAD_ATTRIB_SMD )
397  m_Drill = wxSize( 0, 0 );
398 }
399 
400 
401 void D_PAD::SetOrientation( double aAngle )
402 {
403  NORMALIZE_ANGLE_POS( aAngle );
404  m_Orient = aAngle;
405 }
406 
407 
408 void D_PAD::Flip( const wxPoint& aCentre )
409 {
410  int y = GetPosition().y;
411  MIRROR( y, aCentre.y ); // invert about x axis.
412  SetY( y );
413 
414  MIRROR( m_Pos0.y, 0 );
415  MIRROR( m_Offset.y, 0 );
416  MIRROR( m_DeltaSize.y, 0 );
417 
419 
420  // flip pads layers
421  // PADS items are currently on all copper layers, or
422  // currently, only on Front or Back layers.
423  // So the copper layers count is not taken in account
425 
426  // Flip the basic shapes, in custom pads
427  FlipPrimitives();
428 
429  // m_boundingRadius = -1; the shape has not been changed
430 }
431 
432 
433 // Flip the basic shapes, in custom pads
435 {
436  // Flip custom shapes
437  for( unsigned ii = 0; ii < m_basicShapes.size(); ++ii )
438  {
439  PAD_CS_PRIMITIVE& primitive = m_basicShapes[ii];
440 
441  MIRROR( primitive.m_Start.y, 0 );
442  MIRROR( primitive.m_End.y, 0 );
443  primitive.m_ArcAngle = -primitive.m_ArcAngle;
444 
445  switch( primitive.m_Shape )
446  {
447  case S_POLYGON: // polygon
448  for( unsigned jj = 0; jj < primitive.m_Poly.size(); jj++ )
449  MIRROR( primitive.m_Poly[jj].y, 0 );
450  break;
451 
452  default:
453  break;
454  }
455  }
456 
457  // Flip local coordinates in merged Polygon
458  for( int cnt = 0; cnt < m_customShapeAsPolygon.OutlineCount(); ++cnt )
459  {
461 
462  for( int ii = 0; ii < poly.PointCount(); ++ii )
463  MIRROR( poly.Point( ii ).y, 0 );
464  }
465 }
466 
467 
469 {
470  // Parameters stored in config are only significant parameters
471  // for a template.
472  // So not all parameters are stored, just few.
473  aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadDrill" ),
474  &m_Drill.x,
475  Millimeter2iu( 0.6 ),
476  Millimeter2iu( 0.1 ), Millimeter2iu( 10.0 ),
477  NULL, MM_PER_IU ) );
478 
479  aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadDrillOvalY" ),
480  &m_Drill.y,
481  Millimeter2iu( 0.6 ),
482  Millimeter2iu( 0.1 ), Millimeter2iu( 10.0 ),
483  NULL, MM_PER_IU ) );
484 
485  aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadSizeH" ),
486  &m_Size.x,
487  Millimeter2iu( 1.4 ),
488  Millimeter2iu( 0.1 ), Millimeter2iu( 20.0 ),
489  NULL, MM_PER_IU ) );
490 
491  aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadSizeV" ),
492  &m_Size.y,
493  Millimeter2iu( 1.4 ),
494  Millimeter2iu( 0.1 ), Millimeter2iu( 20.0 ),
495  NULL, MM_PER_IU ) );
496 }
497 
498 
499 // Returns the position of the pad.
501 {
502  if( m_Offset.x == 0 && m_Offset.y == 0 )
503  return m_Pos;
504 
505  wxPoint loc_offset = m_Offset;
506 
507  RotatePoint( &loc_offset, m_Orient );
508 
509  wxPoint shape_pos = m_Pos + loc_offset;
510 
511  return shape_pos;
512 }
513 
514 
515 bool D_PAD::IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps )
516 {
517  bool skip = aSkipUnconnectable && ( GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED );
518 
519  if( !skip )
520  SetName( GetParent()->GetNextPadName( aFillSequenceGaps ) );
521 
522  return !skip;
523 }
524 
525 
526 void D_PAD::CopyNetlistSettings( D_PAD* aPad, bool aCopyLocalSettings )
527 {
528  // Don't do anything foolish like trying to copy to yourself.
529  wxCHECK_RET( aPad != NULL && aPad != this, wxT( "Cannot copy to NULL or yourself." ) );
530 
531  aPad->SetNetCode( GetNetCode() );
532 
533  if( aCopyLocalSettings )
534  {
541  aPad->SetThermalGap( m_ThermalGap );
542  }
543 }
544 
545 
547 {
548  // A pad can have specific clearance parameters that
549  // overrides its NETCLASS clearance value
550  int clearance = m_LocalClearance;
551 
552  if( clearance == 0 )
553  {
554  // If local clearance is 0, use the parent footprint clearance value
555  if( GetParent() && GetParent()->GetLocalClearance() )
556  clearance = GetParent()->GetLocalClearance();
557  }
558 
559  if( clearance == 0 ) // If the parent footprint clearance value = 0, use NETCLASS value
560  return BOARD_CONNECTED_ITEM::GetClearance( aItem );
561 
562  // We have a specific clearance.
563  // if aItem, return the biggest clearance
564  if( aItem )
565  {
566  int hisClearance = aItem->GetClearance();
567  return std::max( hisClearance, clearance );
568  }
569 
570  // Return the specific clearance.
571  return clearance;
572 }
573 
574 
575 // Mask margins handling:
576 
578 {
579  // The pad inherits the margin only to calculate a default shape,
580  // therefore only if it is also a copper layer
581  // Pads defined only on mask layers (and perhaps on other tech layers) use the shape
582  // defined by the pad settings only
583  bool isOnCopperLayer = ( m_layerMask & LSET::AllCuMask() ).any();
584 
585  if( !isOnCopperLayer )
586  return 0;
587 
588  int margin = m_LocalSolderMaskMargin;
589 
590  MODULE* module = GetParent();
591 
592  if( module )
593  {
594  if( margin == 0 )
595  {
596  if( module->GetLocalSolderMaskMargin() )
597  margin = module->GetLocalSolderMaskMargin();
598  }
599 
600  if( margin == 0 )
601  {
602  BOARD* brd = GetBoard();
603  margin = brd->GetDesignSettings().m_SolderMaskMargin;
604  }
605  }
606 
607  // ensure mask have a size always >= 0
608  if( margin < 0 )
609  {
610  int minsize = -std::min( m_Size.x, m_Size.y ) / 2;
611 
612  if( margin < minsize )
613  margin = minsize;
614  }
615 
616  return margin;
617 }
618 
619 
621 {
622  // The pad inherits the margin only to calculate a default shape,
623  // therefore only if it is also a copper layer.
624  // Pads defined only on mask layers (and perhaps on other tech layers) use the shape
625  // defined by the pad settings only
626  bool isOnCopperLayer = ( m_layerMask & LSET::AllCuMask() ).any();
627 
628  if( !isOnCopperLayer )
629  return wxSize( 0, 0 );
630 
631  int margin = m_LocalSolderPasteMargin;
632  double mratio = m_LocalSolderPasteMarginRatio;
633 
634  MODULE* module = GetParent();
635 
636  if( module )
637  {
638  if( margin == 0 )
639  margin = module->GetLocalSolderPasteMargin();
640 
641  BOARD * brd = GetBoard();
642 
643  if( margin == 0 )
644  margin = brd->GetDesignSettings().m_SolderPasteMargin;
645 
646  if( mratio == 0.0 )
647  mratio = module->GetLocalSolderPasteMarginRatio();
648 
649  if( mratio == 0.0 )
650  {
652  }
653  }
654 
655  wxSize pad_margin;
656  pad_margin.x = margin + KiROUND( m_Size.x * mratio );
657  pad_margin.y = margin + KiROUND( m_Size.y * mratio );
658 
659  // ensure mask have a size always >= 0
660  if( pad_margin.x < -m_Size.x / 2 )
661  pad_margin.x = -m_Size.x / 2;
662 
663  if( pad_margin.y < -m_Size.y / 2 )
664  pad_margin.y = -m_Size.y / 2;
665 
666  return pad_margin;
667 }
668 
669 
671 {
672  MODULE* module = GetParent();
673 
674  if( m_ZoneConnection == PAD_ZONE_CONN_INHERITED && module )
675  return module->GetZoneConnection();
676  else
677  return m_ZoneConnection;
678 }
679 
680 
682 {
683  MODULE* module = GetParent();
684 
685  if( m_ThermalWidth == 0 && module )
686  return module->GetThermalWidth();
687  else
688  return m_ThermalWidth;
689 }
690 
691 
693 {
694  MODULE* module = GetParent();
695 
696  if( m_ThermalGap == 0 && module )
697  return module->GetThermalGap();
698  else
699  return m_ThermalGap;
700 }
701 
702 
703 void D_PAD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM>& aList )
704 {
705  MODULE* module;
706  wxString Line;
707  BOARD* board;
708 
709  module = (MODULE*) m_Parent;
710 
711  if( module )
712  {
713  aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), module->GetReference(), DARKCYAN ) );
714  aList.push_back( MSG_PANEL_ITEM( _( "Pad" ), m_name, BROWN ) );
715  }
716 
717  aList.push_back( MSG_PANEL_ITEM( _( "Net" ), GetNetname(), DARKCYAN ) );
718 
719  board = GetBoard();
720 
721  aList.push_back( MSG_PANEL_ITEM( _( "Layer" ),
722  LayerMaskDescribe( board, m_layerMask ), DARKGREEN ) );
723 
724  aList.push_back( MSG_PANEL_ITEM( ShowPadShape(), ShowPadAttr(), DARKGREEN ) );
725 
726  Line = ::CoordinateToString( m_Size.x );
727  aList.push_back( MSG_PANEL_ITEM( _( "Width" ), Line, RED ) );
728 
729  Line = ::CoordinateToString( m_Size.y );
730  aList.push_back( MSG_PANEL_ITEM( _( "Height" ), Line, RED ) );
731 
732  Line = ::CoordinateToString( (unsigned) m_Drill.x );
733 
735  {
736  aList.push_back( MSG_PANEL_ITEM( _( "Drill" ), Line, RED ) );
737  }
738  else
739  {
740  Line = ::CoordinateToString( (unsigned) m_Drill.x );
741  wxString msg;
742  msg = ::CoordinateToString( (unsigned) m_Drill.y );
743  Line += wxT( "/" ) + msg;
744  aList.push_back( MSG_PANEL_ITEM( _( "Drill X / Y" ), Line, RED ) );
745  }
746 
747  double module_orient_degrees = module ? module->GetOrientationDegrees() : 0;
748 
749  if( module_orient_degrees != 0.0 )
750  Line.Printf( wxT( "%3.1f(+%3.1f)" ),
751  GetOrientationDegrees() - module_orient_degrees,
752  module_orient_degrees );
753  else
754  Line.Printf( wxT( "%3.1f" ), GetOrientationDegrees() );
755 
756  aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), Line, LIGHTBLUE ) );
757 
758  Line = ::CoordinateToString( m_Pos.x ) + wxT( ", " ) + ::CoordinateToString( m_Pos.y );
759  aList.push_back( MSG_PANEL_ITEM( _( "Position" ), Line, LIGHTBLUE ) );
760 
761  if( GetPadToDieLength() )
762  {
764  aList.push_back( MSG_PANEL_ITEM( _( "Length in package" ), Line, CYAN ) );
765  }
766 }
767 
768 
770  wxPoint& aEndPoint, int& aWidth ) const
771 {
772  // calculates the start point, end point and width
773  // of an equivalent segment which have the same position and width as the hole
774  int delta_cx, delta_cy;
775 
776  wxSize halfsize = GetDrillSize();
777  halfsize.x /= 2;
778  halfsize.y /= 2;
779 
780  if( m_Drill.x > m_Drill.y ) // horizontal
781  {
782  delta_cx = halfsize.x - halfsize.y;
783  delta_cy = 0;
784  aWidth = m_Drill.y;
785  }
786  else // vertical
787  {
788  delta_cx = 0;
789  delta_cy = halfsize.y - halfsize.x;
790  aWidth = m_Drill.x;
791  }
792 
793  RotatePoint( &delta_cx, &delta_cy, m_Orient );
794 
795  aStartPoint.x = delta_cx;
796  aStartPoint.y = delta_cy;
797 
798  aEndPoint.x = - delta_cx;
799  aEndPoint.y = - delta_cy;
800 }
801 
802 
803 bool D_PAD::HitTest( const wxPoint& aPosition ) const
804 {
805  int dx, dy;
806 
807  wxPoint shape_pos = ShapePos();
808 
809  wxPoint delta = aPosition - shape_pos;
810 
811  // first test: a test point must be inside a minimum sized bounding circle.
812  int radius = GetBoundingRadius();
813 
814  if( ( abs( delta.x ) > radius ) || ( abs( delta.y ) > radius ) )
815  return false;
816 
817  dx = m_Size.x >> 1; // dx also is the radius for rounded pads
818  dy = m_Size.y >> 1;
819 
820  switch( GetShape() )
821  {
822  case PAD_SHAPE_CIRCLE:
823  if( KiROUND( EuclideanNorm( delta ) ) <= dx )
824  return true;
825 
826  break;
827 
828  case PAD_SHAPE_TRAPEZOID:
829  {
830  wxPoint poly[4];
831  BuildPadPolygon( poly, wxSize(0,0), 0 );
832  RotatePoint( &delta, -m_Orient );
833 
834  return TestPointInsidePolygon( poly, 4, delta );
835  }
836 
837  case PAD_SHAPE_OVAL:
838  {
839  RotatePoint( &delta, -m_Orient );
840  // An oval pad has the same shape as a segment with rounded ends
841  // After rotation, the test point is relative to an horizontal pad
842  int dist;
843  wxPoint offset;
844  if( dy > dx ) // shape is a vertical oval
845  {
846  offset.y = dy - dx;
847  dist = dx;
848  }
849  else //if( dy <= dx ) shape is an horizontal oval
850  {
851  offset.x = dy - dx;
852  dist = dy;
853  }
854  return TestSegmentHit( delta, - offset, offset, dist );
855  }
856  break;
857 
858  case PAD_SHAPE_RECT:
859  RotatePoint( &delta, -m_Orient );
860 
861  if( (abs( delta.x ) <= dx ) && (abs( delta.y ) <= dy) )
862  return true;
863 
864  break;
865 
866  case PAD_SHAPE_ROUNDRECT:
867  {
868  // Check for hit in polygon
869  SHAPE_POLY_SET outline;
870  const int segmentToCircleCount = 32;
872  GetRoundRectCornerRadius(), segmentToCircleCount );
873 
874  const SHAPE_LINE_CHAIN &poly = outline.COutline( 0 );
875  return TestPointInsidePolygon( (const wxPoint*)&poly.CPoint(0), poly.PointCount(), delta );
876  }
877  break;
878 
879  case PAD_SHAPE_CUSTOM:
880  // Check for hit in polygon
881  RotatePoint( &delta, -m_Orient );
882 
884  {
886  return TestPointInsidePolygon( (const wxPoint*)&poly.CPoint(0), poly.PointCount(), delta );
887  }
888  break;
889  }
890 
891  return false;
892 }
893 
894 
895 bool D_PAD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
896 {
897  EDA_RECT arect = aRect;
898  arect.Normalize();
899  arect.Inflate( aAccuracy );
900 
901  wxPoint shapePos = ShapePos();
902 
903  EDA_RECT shapeRect;
904 
905  int r;
906 
907  EDA_RECT bb = GetBoundingBox();
908 
909  wxPoint endCenter;
910  int radius;
911 
912  if( !arect.Intersects( bb ) )
913  return false;
914 
915  // This covers total containment for all test cases
916  if( arect.Contains( bb ) )
917  return true;
918 
919  switch( GetShape() )
920  {
921  case PAD_SHAPE_CIRCLE:
922  return arect.IntersectsCircle( GetPosition(), GetBoundingRadius() );
923 
924  case PAD_SHAPE_RECT:
925  shapeRect.SetOrigin( shapePos );
926  shapeRect.Inflate( m_Size.x / 2, m_Size.y / 2 );
927  return arect.Intersects( shapeRect, m_Orient );
928 
929  case PAD_SHAPE_OVAL:
930  // Circlular test if dimensions are equal
931  if( m_Size.x == m_Size.y )
932  return arect.IntersectsCircle( shapePos, GetBoundingRadius() );
933 
934  shapeRect.SetOrigin( shapePos );
935 
936  // Horizontal dimension is greater
937  if( m_Size.x > m_Size.y )
938  {
939  radius = m_Size.y / 2;
940 
941  shapeRect.Inflate( m_Size.x / 2 - radius, radius );
942 
943  endCenter = wxPoint( m_Size.x / 2 - radius, 0 );
944  RotatePoint( &endCenter, m_Orient );
945 
946  // Test circular ends
947  if( arect.IntersectsCircle( shapePos + endCenter, radius ) ||
948  arect.IntersectsCircle( shapePos - endCenter, radius ) )
949  {
950  return true;
951  }
952  }
953  else
954  {
955  radius = m_Size.x / 2;
956 
957  shapeRect.Inflate( radius, m_Size.y / 2 - radius );
958 
959  endCenter = wxPoint( 0, m_Size.y / 2 - radius );
960  RotatePoint( &endCenter, m_Orient );
961 
962  // Test circular ends
963  if( arect.IntersectsCircle( shapePos + endCenter, radius ) ||
964  arect.IntersectsCircle( shapePos - endCenter, radius ) )
965  {
966  return true;
967  }
968  }
969 
970  // Test rectangular portion between rounded ends
971  if( arect.Intersects( shapeRect, m_Orient ) )
972  {
973  return true;
974  }
975 
976  break;
977 
978  case PAD_SHAPE_TRAPEZOID:
979  /* Trapezoid intersection tests:
980  * A) Any points of rect inside trapezoid
981  * B) Any points of trapezoid inside rect
982  * C) Any sides of trapezoid cross rect
983  */
984  {
985 
986  wxPoint poly[4];
987  BuildPadPolygon( poly, wxSize( 0, 0 ), 0 );
988 
989  wxPoint corners[4];
990 
991  corners[0] = wxPoint( arect.GetLeft(), arect.GetTop() );
992  corners[1] = wxPoint( arect.GetRight(), arect.GetTop() );
993  corners[2] = wxPoint( arect.GetRight(), arect.GetBottom() );
994  corners[3] = wxPoint( arect.GetLeft(), arect.GetBottom() );
995 
996  for( int i=0; i<4; i++ )
997  {
998  RotatePoint( &poly[i], m_Orient );
999  poly[i] += shapePos;
1000  }
1001 
1002  for( int ii=0; ii<4; ii++ )
1003  {
1004  if( TestPointInsidePolygon( poly, 4, corners[ii] ) )
1005  {
1006  return true;
1007  }
1008 
1009  if( arect.Contains( poly[ii] ) )
1010  {
1011  return true;
1012  }
1013 
1014  if( arect.Intersects( poly[ii], poly[(ii+1) % 4] ) )
1015  {
1016  return true;
1017  }
1018  }
1019 
1020  return false;
1021  }
1022 
1023  case PAD_SHAPE_ROUNDRECT:
1024  /* RoundRect intersection can be broken up into simple tests:
1025  * a) Test intersection of horizontal rect
1026  * b) Test intersection of vertical rect
1027  * c) Test intersection of each corner
1028  */
1029 
1030 
1032 
1033  /* Test A - intersection of horizontal rect */
1034  shapeRect.SetSize( 0, 0 );
1035  shapeRect.SetOrigin( shapePos );
1036  shapeRect.Inflate( m_Size.x / 2, m_Size.y / 2 - r );
1037 
1038  // Short-circuit test for zero width or height
1039  if( shapeRect.GetWidth() > 0 && shapeRect.GetHeight() > 0 &&
1040  arect.Intersects( shapeRect, m_Orient ) )
1041  {
1042  return true;
1043  }
1044 
1045  /* Test B - intersection of vertical rect */
1046  shapeRect.SetSize( 0, 0 );
1047  shapeRect.SetOrigin( shapePos );
1048  shapeRect.Inflate( m_Size.x / 2 - r, m_Size.y / 2 );
1049 
1050  // Short-circuit test for zero width or height
1051  if( shapeRect.GetWidth() > 0 && shapeRect.GetHeight() > 0 &&
1052  arect.Intersects( shapeRect, m_Orient ) )
1053  {
1054  return true;
1055  }
1056 
1057  /* Test C - intersection of each corner */
1058 
1059  endCenter = wxPoint( m_Size.x / 2 - r, m_Size.y / 2 - r );
1060  RotatePoint( &endCenter, m_Orient );
1061 
1062  if( arect.IntersectsCircle( shapePos + endCenter, r ) ||
1063  arect.IntersectsCircle( shapePos - endCenter, r ) )
1064  {
1065  return true;
1066  }
1067 
1068  endCenter = wxPoint( m_Size.x / 2 - r, -m_Size.y / 2 + r );
1069  RotatePoint( &endCenter, m_Orient );
1070 
1071  if( arect.IntersectsCircle( shapePos + endCenter, r ) ||
1072  arect.IntersectsCircle( shapePos - endCenter, r ) )
1073  {
1074  return true;
1075  }
1076 
1077  break;
1078 
1079  default:
1080  break;
1081  }
1082 
1083  return false;
1084 }
1085 
1086 int D_PAD::Compare( const D_PAD* padref, const D_PAD* padcmp )
1087 {
1088  int diff;
1089 
1090  if( ( diff = padref->GetShape() - padcmp->GetShape() ) != 0 )
1091  return diff;
1092 
1093  if( ( diff = padref->GetDrillShape() - padcmp->GetDrillShape() ) != 0)
1094  return diff;
1095 
1096  if( ( diff = padref->m_Drill.x - padcmp->m_Drill.x ) != 0 )
1097  return diff;
1098 
1099  if( ( diff = padref->m_Drill.y - padcmp->m_Drill.y ) != 0 )
1100  return diff;
1101 
1102  if( ( diff = padref->m_Size.x - padcmp->m_Size.x ) != 0 )
1103  return diff;
1104 
1105  if( ( diff = padref->m_Size.y - padcmp->m_Size.y ) != 0 )
1106  return diff;
1107 
1108  if( ( diff = padref->m_Offset.x - padcmp->m_Offset.x ) != 0 )
1109  return diff;
1110 
1111  if( ( diff = padref->m_Offset.y - padcmp->m_Offset.y ) != 0 )
1112  return diff;
1113 
1114  if( ( diff = padref->m_DeltaSize.x - padcmp->m_DeltaSize.x ) != 0 )
1115  return diff;
1116 
1117  if( ( diff = padref->m_DeltaSize.y - padcmp->m_DeltaSize.y ) != 0 )
1118  return diff;
1119 
1120 // TODO: test custom shapes
1121 
1122  // Dick: specctra_export needs this
1123  // Lorenzo: gencad also needs it to implement padstacks!
1124 
1125 #if __cplusplus >= 201103L
1126  long long d = padref->m_layerMask.to_ullong() - padcmp->m_layerMask.to_ullong();
1127  if( d < 0 )
1128  return -1;
1129  else if( d > 0 )
1130  return 1;
1131 
1132  return 0;
1133 #else
1134  // these strings are not typically constructed, since we don't get here often.
1135  std::string s1 = padref->m_layerMask.to_string();
1136  std::string s2 = padcmp->m_layerMask.to_string();
1137  return s1.compare( s2 );
1138 #endif
1139 }
1140 
1141 
1142 void D_PAD::Rotate( const wxPoint& aRotCentre, double aAngle )
1143 {
1144  RotatePoint( &m_Pos, aRotCentre, aAngle );
1145 
1146  m_Orient = NormalizeAngle360Min( m_Orient + aAngle );
1147 
1148  SetLocalCoord();
1149 }
1150 
1151 
1152 wxString D_PAD::ShowPadShape() const
1153 {
1154  switch( GetShape() )
1155  {
1156  case PAD_SHAPE_CIRCLE:
1157  return _( "Circle" );
1158 
1159  case PAD_SHAPE_OVAL:
1160  return _( "Oval" );
1161 
1162  case PAD_SHAPE_RECT:
1163  return _( "Rect" );
1164 
1165  case PAD_SHAPE_TRAPEZOID:
1166  return _( "Trap" );
1167 
1168  case PAD_SHAPE_ROUNDRECT:
1169  return _( "Roundrect" );
1170 
1171  case PAD_SHAPE_CUSTOM:
1172  return _( "CustomShape" );
1173 
1174  default:
1175  return wxT( "???" );
1176  }
1177 }
1178 
1179 
1180 wxString D_PAD::ShowPadAttr() const
1181 {
1182  switch( GetAttribute() )
1183  {
1184  case PAD_ATTRIB_STANDARD:
1185  return _( "Std" );
1186 
1187  case PAD_ATTRIB_SMD:
1188  return _( "SMD" );
1189 
1190  case PAD_ATTRIB_CONN:
1191  return _( "Conn" );
1192 
1194  return _( "Not Plated" );
1195 
1196  default:
1197  return wxT( "???" );
1198  }
1199 }
1200 
1201 
1203 {
1204  wxString text;
1205  wxString padlayers( LayerMaskDescribe( GetBoard(), m_layerMask ) );
1206  wxString padname( GetName() );
1207 
1208  if( padname.IsEmpty() )
1209  {
1210  text.Printf( _( "Pad on %s of %s" ),
1211  GetChars( padlayers ),
1212  GetChars(GetParent()->GetReference() ) );
1213  }
1214  else
1215  {
1216  text.Printf( _( "Pad %s on %s of %s" ),
1217  GetChars(GetName() ), GetChars( padlayers ),
1218  GetChars(GetParent()->GetReference() ) );
1219  }
1220 
1221  return text;
1222 }
1223 
1224 
1226 {
1227  return pad_xpm;
1228 }
1229 
1230 
1232 {
1233  return new D_PAD( *this );
1234 }
1235 
1236 
1238 {
1239  return( m_Attribute == PAD_ATTRIB_STANDARD
1240  && m_Drill.x >= m_Size.x && m_Drill.y >= m_Size.y );
1241 }
1242 
1243 
1244 void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const
1245 {
1246  aCount = 0;
1247 
1248  // These 2 types of pads contain a hole
1250  aLayers[aCount++] = LAYER_PADS_PLATEDHOLES;
1251 
1253  aLayers[aCount++] = LAYER_NON_PLATEDHOLES;
1254 
1255  if( IsOnLayer( F_Cu ) && IsOnLayer( B_Cu ) )
1256  {
1257  // Multi layer pad
1258  aLayers[aCount++] = LAYER_PADS_TH;
1259  aLayers[aCount++] = LAYER_PADS_NETNAMES;
1260  }
1261  else if( IsOnLayer( F_Cu ) )
1262  {
1263  aLayers[aCount++] = LAYER_PAD_FR;
1264  aLayers[aCount++] = LAYER_PAD_FR_NETNAMES;
1265  }
1266  else if( IsOnLayer( B_Cu ) )
1267  {
1268  aLayers[aCount++] = LAYER_PAD_BK;
1269  aLayers[aCount++] = LAYER_PAD_BK_NETNAMES;
1270  }
1271 
1272  // Check non-copper layers. This list should include all the layers that the
1273  // footprint editor allows a pad to be placed on.
1274  static const PCB_LAYER_ID layers_mech[] = { F_Mask, B_Mask, F_Paste, B_Paste,
1276 
1277  for( PCB_LAYER_ID each_layer : layers_mech )
1278  {
1279  if( IsOnLayer( each_layer ) )
1280  aLayers[aCount++] = each_layer;
1281  }
1282 
1283 #ifdef __WXDEBUG__
1284  if( aCount == 0 ) // Should not occur
1285  {
1286  wxString msg;
1287  msg.Printf( wxT( "footprint %s, pad %s: could not find valid layer for pad" ),
1288  GetParent() ? GetParent()->GetReference() : "<null>",
1289  GetName().IsEmpty() ? "(unnamed)" : GetName() );
1290  wxLogWarning( msg );
1291  }
1292 #endif
1293 }
1294 
1295 
1296 unsigned int D_PAD::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
1297 {
1298  const int HIDE = std::numeric_limits<unsigned int>::max();
1299  BOARD* board = GetBoard();
1300 
1301  // Handle Render tab switches
1303  && !aView->IsLayerVisible( LAYER_PADS_TH ) )
1304  return HIDE;
1305 
1306  if( !IsFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) )
1307  return HIDE;
1308 
1309  if( IsFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) )
1310  return HIDE;
1311 
1312  if( IsFrontLayer( ( PCB_LAYER_ID )aLayer ) && !aView->IsLayerVisible( LAYER_PAD_FR ) )
1313  return HIDE;
1314 
1315  if( IsBackLayer( ( PCB_LAYER_ID )aLayer ) && !aView->IsLayerVisible( LAYER_PAD_BK ) )
1316  return HIDE;
1317 
1318  // Only draw the pad if at least one of the layers it crosses is being displayed
1319  if( board && !( board->GetVisibleLayers() & GetLayerSet() ).any() )
1320  return HIDE;
1321 
1322  // Netnames will be shown only if zoom is appropriate
1323  if( IsNetnameLayer( aLayer ) )
1324  {
1325  int divisor = std::max( m_Size.x, m_Size.y );
1326 
1327  // Pad sizes can be zero briefly when someone is typing a number like "0.5"
1328  // in the pad properties dialog
1329  if( divisor == 0 )
1330  return HIDE;
1331 
1332  return ( Millimeter2iu( 100 ) / divisor );
1333  }
1334 
1335  // Other layers are shown without any conditions
1336  return 0;
1337 }
1338 
1339 
1340 const BOX2I D_PAD::ViewBBox() const
1341 {
1342  // Bounding box includes soldermask too
1343  int solderMaskMargin = GetSolderMaskMargin();
1344  VECTOR2I solderPasteMargin = VECTOR2D( GetSolderPasteMargin() );
1345  EDA_RECT bbox = GetBoundingBox();
1346 
1347  // Look for the biggest possible bounding box
1348  int xMargin = std::max( solderMaskMargin, solderPasteMargin.x );
1349  int yMargin = std::max( solderMaskMargin, solderPasteMargin.y );
1350 
1351  return BOX2I( VECTOR2I( bbox.GetOrigin() ) - VECTOR2I( xMargin, yMargin ),
1352  VECTOR2I( bbox.GetSize() ) + VECTOR2I( 2 * xMargin, 2 * yMargin ) );
1353 }
1354 
1355 
1356 wxString LayerMaskDescribe( const BOARD *aBoard, LSET aMask )
1357 {
1358  // Try the single or no- layer case (easy)
1359  PCB_LAYER_ID layer = aMask.ExtractLayer();
1360 
1361  switch( (int) layer )
1362  {
1363  case UNSELECTED_LAYER:
1364  return _( "No layers" );
1365 
1366  case UNDEFINED_LAYER:
1367  break;
1368 
1369  default:
1370  return aBoard->GetLayerName( layer );
1371  }
1372 
1373  // Try to be smart and useful, starting with outer copper
1374  // (which are more important than internal ones)
1375  wxString layerInfo;
1376 
1377  if( aMask[F_Cu] )
1378  AccumulateDescription( layerInfo, aBoard->GetLayerName( F_Cu ) );
1379 
1380  if( aMask[B_Cu] )
1381  AccumulateDescription( layerInfo, aBoard->GetLayerName( B_Cu ) );
1382 
1383  if( ( aMask & LSET::InternalCuMask() ).any() )
1384  AccumulateDescription( layerInfo, _("Internal" ) );
1385 
1386  if( ( aMask & LSET::AllNonCuMask() ).any() )
1387  AccumulateDescription( layerInfo, _("Non-copper" ) );
1388 
1389  return layerInfo;
1390 }
1391 
1392 
1393 void D_PAD::ImportSettingsFromMaster( const D_PAD& aMasterPad )
1394 {
1395  SetShape( aMasterPad.GetShape() );
1396  SetLayerSet( aMasterPad.GetLayerSet() );
1397  SetAttribute( aMasterPad.GetAttribute() );
1398 
1399  // The pad orientation, for historical reasons is the
1400  // pad rotation + parent rotation.
1401  // So we have to manage this parent rotation
1402  double pad_rot = aMasterPad.GetOrientation();
1403 
1404  if( aMasterPad.GetParent() )
1405  pad_rot -= aMasterPad.GetParent()->GetOrientation();
1406 
1407  if( GetParent() )
1408  pad_rot += GetParent()->GetOrientation();
1409 
1410  SetOrientation( pad_rot );
1411 
1412  SetSize( aMasterPad.GetSize() );
1413  SetDelta( wxSize( 0, 0 ) );
1414  SetOffset( aMasterPad.GetOffset() );
1415  SetDrillSize( aMasterPad.GetDrillSize() );
1416  SetDrillShape( aMasterPad.GetDrillShape() );
1418 
1419  switch( aMasterPad.GetShape() )
1420  {
1421  case PAD_SHAPE_TRAPEZOID:
1422  SetDelta( aMasterPad.GetDelta() );
1423  break;
1424 
1425  case PAD_SHAPE_CIRCLE:
1426  // ensure size.y == size.x
1427  SetSize( wxSize( GetSize().x, GetSize().x ) );
1428  break;
1429 
1430  default:
1431  ;
1432  }
1433 
1434  switch( aMasterPad.GetAttribute() )
1435  {
1436  case PAD_ATTRIB_SMD:
1437  case PAD_ATTRIB_CONN:
1438  // These pads do not have hole (they are expected to be only on one
1439  // external copper layer)
1440  SetDrillSize( wxSize( 0, 0 ) );
1441  break;
1442 
1443  default:
1444  ;
1445  }
1446 
1447  // Add or remove custom pad shapes:
1448  SetPrimitives( aMasterPad.GetPrimitives() );
1449  SetAnchorPadShape( aMasterPad.GetAnchorPadShape() );
1451 }
1452 
1454 {
1455  assert( aImage->Type() == PCB_PAD_T );
1456 
1457  std::swap( *((MODULE*) this), *((MODULE*) aImage) );
1458 }
int m_LocalClearance
Local clearance.
Definition: class_pad.h:854
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
int m_ThermalGap
Definition: class_pad.h:867
bool MergePrimitivesAsPolygon(SHAPE_POLY_SET *aMergedPolygon=NULL, int aCircleToSegmentsCount=32)
Merge all basic shapes, converted to a polygon in one polygon, in m_customShapeAsPolygon.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:673
int m_LocalSolderMaskMargin
Local mask margins: when 0, the parent footprint design values are used.
Definition: class_pad.h:858
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: class_pad.cpp:1225
wxString CoordinateToString(int aValue, bool aConvertToMils)
Function CoordinateToString is a helper to convert the integer coordinate aValue to a string in inche...
Definition: base_units.cpp:118
bool IncrementPadName(bool aSkipUnconnectable, bool aFillSequenceGaps)
Function IncrementPadName.
Definition: class_pad.cpp:515
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
static int m_PadSketchModePenSize
Pen size used to draw pads in sketch mode (mode used to print pads on silkscreen layer) ...
Definition: class_pad.h:137
int m_SolderMaskMargin
Solder mask margin.
double m_padRoundRectRadiusScale
scaling factor from smallest m_Size coord to corner radius, default 0.25
Definition: class_pad.h:814
A list of parameters type.
int m_boundingRadius
radius of the circle containing the pad shape
Definition: class_pad.h:774
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: class_pad.cpp:1231
BOX2< VECTOR2I > BOX2I
Definition: box2.h:468
PAD_SHAPE_T GetAnchorPadShape() const
Function GetAnchorPadShape.
Definition: class_pad.h:226
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:179
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount)
Calculate the mask layer when flipping a footprint BACK and FRONT copper layers, mask, paste, solder layers are swapped internal layers are flipped only if the copper layers count is known.
Definition: lset.cpp:518
std::vector< PAD_CS_PRIMITIVE > m_basicShapes
for free shape pads: a list of basic shapes, in local coordinates, orient 0, coordinates relative to ...
Definition: class_pad.h:788
const std::vector< PAD_CS_PRIMITIVE > & GetPrimitives() const
Accessor to the basic shape list.
Definition: class_pad.h:336
int GetThermalGap() const
Definition: class_module.h:222
static LSET StandardMask()
layer set for a through hole pad
Definition: class_pad.cpp:99
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: class_pad.cpp:1202
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect...
void FlipPrimitives()
Flip the basic shapes, in custom pads.
Definition: class_pad.cpp:434
PNG memory record (file in memory).
Definition: bitmap_types.h:41
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:405
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: class_pad.cpp:803
int GetLeft() const
Definition: eda_rect.h:120
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:106
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
int m_SolderPasteMargin
Solder paste margin absolute value.
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Definition: class_pad.cpp:1142
PAD_ATTR_T
Enum PAD_ATTR_T is the set of pad shapes, used with D_PAD::{Set,Get}Attribute() The double name is fo...
Definition: pad_shapes.h:58
int m_LocalSolderPasteMargin
Local solder paste margin absolute value.
Definition: class_pad.h:859
multilayer pads, usually with holes
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible() Returns information about visibility of a particular layer.
Definition: view.h:404
Implementation of conversion functions that require both schematic and board internal units...
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
Definition: class_pad.cpp:120
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
int GetLocalClearance() const
Definition: class_module.h:206
const wxSize GetSize() const
Definition: eda_rect.h:101
void BuildPadPolygon(wxPoint aCoord[4], wxSize aInflateValue, double aRotation) const
Function BuildPadPolygon Has meaning only for polygonal pads (trapezoid and rectangular) Build the Co...
static LSET SMDMask()
layer set for a SMD pad on Front layer
Definition: class_pad.cpp:106
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
int PointCount() const
Function PointCount()
bool Contains(const wxPoint &aPoint) const
Function Contains.
handle color for not plated holes (holes, not pads)
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it&#39;s a back layer.
bool IntersectsCircle(const wxPoint &aCenter, const int aRadius) const
Function IntersectsCircle tests for a common area between a circle and this rectangle.
int GetPadToDieLength() const
Definition: class_pad.h:408
Class BOARD to handle a board.
D_PAD(MODULE *parent)
Definition: class_pad.cpp:59
void TransformRoundRectToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double aRotation, int aCornerRadius, int aCircleToSegmentsCount)
Function TransformRoundRectToPolygon convert a rectangle with rounded corners to a polygon Convert ar...
int GetRoundRectCornerRadius() const
Function GetRoundRectCornerRadius Has meaning only for rounded rect pads.
Definition: class_pad.h:524
wxPoint m_Start
angle of an arc, from its starting point, in 0.1 deg
Definition: class_pad.h:100
ZoneConnection
How pads are covered by copper in zone.
Definition: zones.h:55
polygon (not yet used for tracks, but could be in microwave apps)
static LSET AllNonCuMask()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:696
wxSize m_Size
X and Y size ( relative to orient 0)
Definition: class_pad.h:810
MODULE * GetParent() const
Definition: class_pad.h:162
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:61
static const int dist[10][10]
Definition: dist.cpp:57
show modules on back
int GetHeight() const
Definition: eda_rect.h:118
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
int boundingRadius() const
Function boundingRadius returns a calculated radius of a bounding circle for this pad...
Definition: class_pad.cpp:133
wxString ShowPadAttr() const
Function ShowPadAttr.
Definition: class_pad.cpp:1180
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:388
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void SetSubRatsnest(int aSubRatsnest)
Definition: class_pad.h:646
void SetDrillSize(const wxSize &aSize)
Definition: class_pad.h:274
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
ZoneConnection GetZoneConnection() const
Definition: class_module.h:216
int OutlineCount() const
Returns the number of outlines in the set
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:241
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
void SetRoundRectRadiusRatio(double aRadiusScale)
has meaning only for rounded rect pads Set the scaling factor between the smaller Y or Y size and the...
Definition: class_pad.h:633
static wxString GetNextPadName(wxString aPadName)
Compute the &#39;next&#39; pad number for autoincrement aPadName is the last pad name used.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
#define abs(a)
Definition: auxiliary.h:84
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
Configuration parameter - Integer Class with unit conversion.
smd pads, back layer
double GetLocalSolderPasteMarginRatio() const
Definition: class_module.h:212
static const int delta[8][2]
Definition: solve.cpp:112
void SetLocalCoord()
Set relative coordinates.
Definition: class_pad.cpp:377
This file contains miscellaneous commonly used macros and functions.
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:612
show modules on front
void MIRROR(T &aPoint, const T &aMirrorRef)
Definition: macros.h:111
class MODULE, a footprint
Definition: typeinfo.h:89
void SetAnchorPadShape(PAD_SHAPE_T aShape)
Function SetAnchorPadShape Set the shape of the anchor pad for custm shped pads.
Definition: class_pad.h:253
PCB_LAYER_ID
A quick note on layer IDs:
wxString m_name
Definition: class_pad.h:776
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers. ...
Definition: class_pad.cpp:1340
Class LSET is a set of PCB_LAYER_IDs.
bool TestPointInsidePolygon(const CPOLYGONS_LIST &aPolysList, int aIdxstart, int aIdxend, int aRefx, int aRefy)
Function TestPointInsidePolygon test if a point is inside or outside a polygon.
void CustomShapeAsPolygonToBoardPosition(SHAPE_POLY_SET *aMergedPolygon, wxPoint aPosition, double aRotation) const
When created, the corners coordinates are relative to the pad position, orientation 0...
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:294
std::vector< wxPoint > m_Poly
is also the start point of the arc
Definition: class_pad.h:102
double GetOrientationDegrees() const
Definition: class_module.h:188
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
void SetZoneConnection(ZoneConnection aType)
Definition: class_pad.h:482
void SetName(const wxString &aName)
Set the pad name (sometimes called pad number, although it can be an array reference like AA12)...
Definition: class_pad.h:182
int GetBoundingRadius() const
Function GetBoundingRadius returns the radius of a minimum sized circle which fully encloses this pad...
Definition: class_pad.h:599
double GetOrientation() const
Definition: class_module.h:187
Class SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
int GetSolderMaskMargin() const
Function GetSolderMaskMargin.
Definition: class_pad.cpp:577
void SetEnd(int x, int y)
Definition: eda_rect.h:134
static int Compare(const D_PAD *padref, const D_PAD *padcmp)
Function Compare compares two pads and return 0 if they are equal.
Definition: class_pad.cpp:1086
const EDA_RECT GetBoundingBoxRotated(wxPoint aRotCenter, double aAngle)
Function GetBoundingBoxRotated.
Helper class to handle a primitive (basic shape: polygon, segment, circle or arc) to build a custom p...
Definition: class_pad.h:91
ZoneConnection GetZoneConnection() const
Definition: class_pad.cpp:670
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:402
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
Definition: colors.h:59
CUST_PAD_SHAPE_IN_ZONE m_customShapeClearanceArea
How to build the custom shape in zone, to create the clearance area: CUST_PAD_SHAPE_IN_ZONE_OUTLINE =...
Definition: class_pad.h:801
int GetThermalWidth() const
Definition: class_pad.cpp:681
int GetThermalGap() const
Definition: class_pad.cpp:692
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:633
void SetThermalWidth(int aWidth)
Definition: class_pad.h:485
const wxSize & GetSize() const
Definition: class_pad.h:269
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:535
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
const wxString & GetName() const
Definition: class_pad.h:190
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
int m_ThermalWidth
Definition: class_pad.h:866
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on...
Definition: class_pad.cpp:1244
Definition: colors.h:60
SHAPE_POLY_SET m_customShapeAsPolygon
for free shape pads: the set of basic shapes, merged as one polygon, in local coordinates, orient 0, coordinates relative to m_Pos
Definition: class_pad.h:793
int GetBottom() const
Definition: eda_rect.h:122
void ImportSettingsFromMaster(const D_PAD &aMasterPad)
Imports the pad settings from aMasterPad.
Definition: class_pad.cpp:1393
virtual unsigned int ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
Definition: class_pad.cpp:1296
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const
Function GetClearance returns the clearance in internal units.
int GetLocalSolderMaskMargin() const
Definition: class_module.h:203
void SetDrawCoord()
Set absolute coordinates.
Definition: class_pad.cpp:361
int GetRight() const
Definition: eda_rect.h:119
wxSize m_DeltaSize
delta on rectangular shapes
Definition: class_pad.h:840
wxPoint m_End
is also the center of the circle and arc
Definition: class_pad.h:101
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:62
STROKE_T m_Shape
Definition: class_pad.h:94
void SetAttribute(PAD_ATTR_T aAttribute)
Definition: class_pad.cpp:392
bool IsFlipped() const
Definition: class_pad.cpp:126
int GetLocalClearance() const
Definition: class_pad.h:413
void SetLocalClearance(int aClearance)
Definition: class_pad.h:414
int GetLocalSolderPasteMargin() const
Definition: class_module.h:209
void SetLocalSolderPasteMarginRatio(double aRatio)
Definition: class_pad.h:420
int GetNetCode() const
Function GetNetCode.
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it&#39;s a front layer.
void Normalize()
Function Normalize ensures that the height ant width are positive.
LSET m_layerMask
Bitwise layer :1= copper layer, 15= cmp, 2..14 = internal layers 16 .
Definition: class_pad.h:836
void AccumulateDescription(wxString &aDesc, const wxString &aItem)
Utility to build comma separated lists in messages.
Definition: macros.h:65
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
Definition: class_pad.cpp:1453
void SetSize(const wxSize &size)
Definition: eda_rect.h:126
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
void SetLayerSet(LSET aLayerMask)
Definition: class_pad.h:401
void SetY(int y)
Definition: class_pad.h:259
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
smd pads, front layer
const wxString & GetNetname() const
Function GetNetname.
double GetRoundRectRadiusRatio() const
has meaning only for rounded rect pads
Definition: class_pad.h:621
void SetDrillShape(PAD_DRILL_SHAPE_T aDrillShape)
Definition: class_pad.h:386
wxPoint m_Pos0
Initial Pad position (i.e.
Definition: class_pad.h:842
void GetOblongDrillGeometry(wxPoint &aStartPoint, wxPoint &aEndPoint, int &aWidth) const
Function GetOblongDrillGeometry calculates the start point, end point and width of an equivalent segm...
Definition: class_pad.cpp:769
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:458
void SetLocalSolderMaskMargin(int aMargin)
Definition: class_pad.h:411
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
Definition: class_pad.cpp:408
Class SHAPE_LINE_CHAIN.
int m_LengthPadToDie
Length net from pad to die, inside the package.
Definition: class_pad.h:849
wxString ShowPadShape() const
Function ShowPadShape.
Definition: class_pad.cpp:1152
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
size_t i
Definition: json11.cpp:597
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:382
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
const wxSize & GetDelta() const
Definition: class_pad.h:272
Usual pad.
Definition: pad_shapes.h:60
wxSize GetSolderPasteMargin() const
Function GetSolderPasteMargin.
Definition: class_pad.cpp:620
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
int GetWidth() const
Definition: eda_rect.h:117
int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
Definition: class_pad.cpp:546
void SetShape(PAD_SHAPE_T aShape)
Definition: class_pad.h:217
wxPoint ShapePos() const
Definition: class_pad.cpp:500
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:401
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
PAD_ATTR_T m_Attribute
PAD_ATTRIB_NORMAL, PAD_ATTRIB_SMD, PAD_ATTRIB_CONN, PAD_ATTRIB_HOLE_NOT_PLATED.
Definition: class_pad.h:845
VECTOR2I & Point(int aIndex)
Function Point()
void SetLocalSolderPasteMargin(int aMargin)
Definition: class_pad.h:417
static LSET ConnSMDMask()
layer set for a SMD pad on Front layer used for edge board connectors
Definition: class_pad.cpp:113
wxSize m_Drill
Drill diam (drill shape = PAD_CIRCLE) or drill size (shape = OVAL) for drill shape = PAD_CIRCLE...
Definition: class_pad.h:806
Module description (excepted pads)
double m_Orient
in 1/10 degrees
Definition: class_pad.h:847
double m_LocalSolderPasteMarginRatio
Local solder mask margin ratio value of pad size The final margin is the sum of these 2 values...
Definition: class_pad.h:861
wxPoint m_Offset
m_Offset is useful only for oblong and rect pads (it can be used for other shapes, but without any interest).
Definition: class_pad.h:834
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
Class VIEW.
Definition: view.h:58
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:122
double m_SolderPasteMarginRatio
Solder pask margin ratio value of pad size The final margin is the sum of these 2 values...
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: class_pad.h:650
const wxPoint GetPosition() const override
Definition: class_pad.h:220
T NormalizeAngle360Min(T Angle)
Normalize angle to be > -360.0 and < 360.0 Angle equal to -360 or +360 are set to 0...
Definition: trigo.h:222
Message panel definition file.
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:277
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void SetThermalGap(int aGap)
Definition: class_pad.h:488
bool PadShouldBeNPTH() const
A pad whose hole is the same size as the pad is a NPTH.
Definition: class_pad.cpp:1237
const wxPoint GetPosition() const override
Definition: class_module.h:182
double GetOrientationDegrees() const
Definition: class_pad.h:383
bool SetPrimitives(const std::vector< PAD_CS_PRIMITIVE > &aPrimitivesList)
Import to the basic shape list.
void CopyNetlistSettings(D_PAD *aPad, bool aCopyLocalSettings)
Function CopyNetlistSettings copies the netlist settings to aPad, and the net name.
Definition: class_pad.cpp:526
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: class_pad.cpp:199
const wxPoint & GetOffset() const
Definition: class_pad.h:278
static wxString LayerMaskDescribe(const BOARD *aBoard, LSET aMask)
Helper function Return a string (to be shown to the user) describing a layer mask.
Definition: class_pad.cpp:1356
double m_ArcAngle
radius of a circle
Definition: class_pad.h:99
int GetThermalWidth() const
Definition: class_module.h:219
Additional netnames layers (not associated with a PCB layer)
ZoneConnection m_ZoneConnection
how the connection to zone is made: no connection, thermal relief ...
Definition: class_pad.h:864
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:271
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
bool IsNetnameLayer(LAYER_NUM aLayer)
Function IsNetnameLayer tests whether a layer is a netname layer.
#define min(a, b)
Definition: auxiliary.h:85
wxPoint m_Pos
pad Position on board
Definition: class_pad.h:778
void AppendConfigs(PARAM_CFG_ARRAY *aResult)
Function AppendConfigs appends to aResult the configuration setting accessors which will later allow ...
Definition: class_pad.cpp:468
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
Definition: class_pad.cpp:703
Definition: colors.h:62
int GetTop() const
Definition: eda_rect.h:121