KiCad PCB EDA Suite
pad_print_functions.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) 2017 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #include <class_board.h>
28 #include <common.h>
30 #include <gr_text.h>
31 #include <fctsys.h>
33 #include <gr_basic.h>
35 #include <pcb_edit_frame.h>
36 #include <pcb_screen.h>
37 #include <pcbnew.h>
38 #include <pcbnew_id.h> // ID_TRACK_BUTT
39 #include <trigo.h>
40 
41 
42 // Helper class to store parameters used to draw a pad
44 {
45  m_Color = BLACK;
46  m_HoleColor = BLACK; // could be DARKGRAY;
49  m_PadClearance = 0;
50  m_Display_padnum = true;
51  m_Display_netname = true;
52  m_ShowPadFilled = true;
53  m_ShowNCMark = true;
54  m_ShowNotPlatedHole = false;
55  m_IsPrinting = false;
56 }
57 
58 
59 void D_PAD::Print( PCB_BASE_FRAME* aFrame, wxDC* aDC, const wxPoint& aOffset )
60 {
61  wxSize mask_margin; // margin (clearance) used for some non copper layers
62 
63  if( m_Flags & DO_NOT_DRAW )
64  return;
65 
66  PAD_DRAWINFO drawInfo;
67 
68  drawInfo.m_Offset = aOffset;
69 
70  /* We can show/hide pads from the layer manager.
71  * options are show/hide pads on front and/or back side of the board
72  * For through pads, we hide them only if both sides are hidden.
73  * smd pads on back are hidden for all layers (copper and technical layers)
74  * on back side of the board
75  * smd pads on front are hidden for all layers (copper and technical layers)
76  * on front side of the board
77  * ECO, edge and Draw layers and not considered
78  */
79 
80  BOARD* brd = GetBoard();
81 
82  const auto& cds = aFrame->Settings().Colors();
83 
84  bool frontVisible = brd->IsElementVisible( LAYER_PAD_FR );
85  bool backVisible = brd->IsElementVisible( LAYER_PAD_BK );
86 
87  if( !frontVisible && !backVisible )
88  return;
89 
90  // If pad is only on front side (no layer on back side)
91  // and if hide front side pads is enabled, do not draw
92  if( !frontVisible && !( m_layerMask & LSET::BackMask() ).any() )
93  return;
94 
95  // If pad is only on back side (no layer on front side)
96  // and if hide back side pads is enabled, do not draw
97  if( !backVisible && !( m_layerMask & LSET::FrontMask() ).any() )
98  return;
99 
100 
101  auto& displ_opts = aFrame->GetDisplayOptions();
102  PCB_SCREEN* screen = aFrame->GetScreen();
103 
104  if( displ_opts.m_DisplayPadFill == SKETCH )
105  drawInfo.m_ShowPadFilled = false;
106  else
107  drawInfo.m_ShowPadFilled = true;
108 
110 
111  if( m_layerMask[F_Cu] )
112  {
113  color = cds.GetItemColor( LAYER_PAD_FR );
114  }
115 
116  if( m_layerMask[B_Cu] )
117  {
118  color = color.LegacyMix( cds.GetItemColor( LAYER_PAD_BK ) );
119  }
120 
121  if( color == BLACK ) // Not on a visible copper layer (i.e. still nothing to show)
122  {
123  // If the pad is on only one tech layer, use the layer color else use DARKGRAY
124  LSET mask_non_copper_layers = m_layerMask & ~LSET::AllCuMask();
125 
126  PCB_LAYER_ID pad_layer = mask_non_copper_layers.ExtractLayer();
127 
128  switch( (int) pad_layer )
129  {
130  case UNDEFINED_LAYER: // More than one layer
131  color = DARKGRAY;
132  break;
133 
134  case UNSELECTED_LAYER: // Shouldn't really happen...
135  break;
136 
137  default:
138  color = cds.GetLayerColor( pad_layer );
139  }
140  }
141 
142  if( ( IsOnLayer( B_Paste ) && brd->IsLayerVisible( B_Paste ) ) ||
143  ( IsOnLayer( F_Paste ) && brd->IsLayerVisible( F_Paste ) ) )
144  {
145  mask_margin = GetSolderPasteMargin();
146  }
147 
148  if( ( IsOnLayer( B_Mask ) && brd->IsLayerVisible( B_Mask ) ) ||
149  ( IsOnLayer( F_Mask ) && brd->IsLayerVisible( F_Mask ) ) )
150  {
151  mask_margin.x = std::max( mask_margin.x, GetSolderMaskMargin() );
152  mask_margin.y = std::max( mask_margin.y, GetSolderMaskMargin() );
153  }
154 
155  bool DisplayIsol = displ_opts.m_DisplayPadIsol;
156 
157  if( !( m_layerMask & LSET::AllCuMask() ).any() )
158  DisplayIsol = false;
159 
162  {
163  drawInfo.m_ShowNotPlatedHole = true;
164  drawInfo.m_NPHoleColor = cds.GetItemColor( LAYER_NON_PLATEDHOLES );
165  }
166  // Don't let pads that *should* be NPTHs get lost
167  else if ( PadShouldBeNPTH() )
168  {
169  drawInfo.m_ShowNotPlatedHole = true;
170  drawInfo.m_NPHoleColor = cds.GetItemColor( LAYER_MOD_TEXT_INVISIBLE );
171  }
172 
173  drawInfo.m_Color = color;
174  drawInfo.m_NoNetMarkColor = cds.GetItemColor( LAYER_NO_CONNECTS );
175  drawInfo.m_Mask_margin = mask_margin;
177  drawInfo.m_IsPrinting = screen->m_IsPrinting;
178  color.a = 0.666;
179 
180  /* Get the pad clearance. This has a meaning only for Pcbnew.
181  * for CvPcb GetClearance() creates debug errors because
182  * there is no net classes so a call to GetClearance() is made only when
183  * needed (never needed in CvPcb)
184  */
185  drawInfo.m_PadClearance = DisplayIsol ? GetClearance() : 0;
186 
187  // Draw the pad number
188  if( !displ_opts.m_DisplayPadNum )
189  drawInfo.m_Display_padnum = false;
190 
191  if( ( displ_opts.m_DisplayNetNamesMode == 0 ) || ( displ_opts.m_DisplayNetNamesMode == 2 ) )
192  drawInfo.m_Display_netname = false;
193 
194  PrintShape( aDC, drawInfo );
195 }
196 
197 
198 void D_PAD::PrintShape( wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
199 {
200  #define SEGCOUNT 32 // number of segments to approximate a circle
201  wxPoint coord[12];
202  double angle = m_Orient;
203  int seg_width;
204 
205  // calculate pad shape position :
206  wxPoint shape_pos = ShapePos() - aDrawInfo.m_Offset;
207 
208  wxSize halfsize = m_Size;
209  halfsize.x >>= 1;
210  halfsize.y >>= 1;
211 
212  switch( GetShape() )
213  {
214  case PAD_SHAPE_CIRCLE:
215  if( aDrawInfo.m_ShowPadFilled )
216  GRFilledCircle( nullptr, aDC, shape_pos.x, shape_pos.y,
217  halfsize.x + aDrawInfo.m_Mask_margin.x, 0,
218  aDrawInfo.m_Color, aDrawInfo.m_Color );
219  else
220  GRCircle( nullptr, aDC, shape_pos.x, shape_pos.y,
221  halfsize.x + aDrawInfo.m_Mask_margin.x,
222  m_PadSketchModePenSize, aDrawInfo.m_Color );
223 
224  if( aDrawInfo.m_PadClearance )
225  {
226  GRCircle( nullptr, aDC, shape_pos.x, shape_pos.y,
227  halfsize.x + aDrawInfo.m_PadClearance, 0, aDrawInfo.m_Color );
228  }
229 
230  break;
231 
232  case PAD_SHAPE_OVAL:
233  {
234  wxPoint segStart, segEnd;
235  seg_width = BuildSegmentFromOvalShape( segStart, segEnd, angle, aDrawInfo.m_Mask_margin );
236  segStart += shape_pos;
237  segEnd += shape_pos;
238 
239  if( aDrawInfo.m_ShowPadFilled )
240  {
241  GRFillCSegm( nullptr, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y, seg_width,
242  aDrawInfo.m_Color );
243  }
244  else
245  {
246  GRCSegm( nullptr, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y, seg_width,
247  m_PadSketchModePenSize, aDrawInfo.m_Color );
248  }
249 
250  // Draw the clearance line
251  if( aDrawInfo.m_PadClearance )
252  {
253  seg_width += 2 * aDrawInfo.m_PadClearance;
254  GRCSegm( nullptr, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y, seg_width,
255  aDrawInfo.m_Color );
256  }
257  }
258  break;
259 
260  case PAD_SHAPE_RECT:
261  case PAD_SHAPE_TRAPEZOID:
262  BuildPadPolygon( coord, aDrawInfo.m_Mask_margin, angle );
263 
264  for( int ii = 0; ii < 4; ii++ )
265  coord[ii] += shape_pos;
266 
267  GRClosedPoly( nullptr, aDC, 4, coord, aDrawInfo.m_ShowPadFilled,
268  aDrawInfo.m_ShowPadFilled ? 0 : m_PadSketchModePenSize,
269  aDrawInfo.m_Color, aDrawInfo.m_Color );
270 
271  if( aDrawInfo.m_PadClearance )
272  {
273  SHAPE_POLY_SET outline;
275 
276  // Draw the polygon: Inflate creates only one convex polygon
277  if( outline.OutlineCount() > 0 )
278  {
279  SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
280 
281  if( poly.PointCount() > 0 )
282  {
283  GRClosedPoly( nullptr, aDC, poly.PointCount(), (wxPoint*)&poly.Point( 0 ),
284  false, 0, aDrawInfo.m_Color, aDrawInfo.m_Color );
285  }
286  }
287  }
288  break;
289 
291  case PAD_SHAPE_ROUNDRECT:
292  {
293  // Use solder[Paste/Mask]size or pad size to build pad shape to draw
294  wxSize size( GetSize() );
295  size += aDrawInfo.m_Mask_margin * 2;
296  int corner_radius = GetRoundRectCornerRadius( size );
297  bool doChamfer = GetShape() == PAD_SHAPE_CHAMFERED_RECT;
298 
299  SHAPE_POLY_SET outline;
300  TransformRoundChamferedRectToPolygon( outline, shape_pos, size, GetOrientation(),
301  corner_radius, GetChamferRectRatio(),
302  doChamfer ? GetChamferPositions() : 0,
303  ARC_HIGH_DEF );
304 
305  // Draw the polygon: Inflate creates only one convex polygon
306  bool filled = aDrawInfo.m_ShowPadFilled;
307 
308  SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
309 
310  GRClosedPoly( nullptr, aDC, poly.PointCount(), (wxPoint*)&poly.Point( 0 ), filled, 0,
311  aDrawInfo.m_Color, aDrawInfo.m_Color );
312 
313  if( aDrawInfo.m_PadClearance )
314  {
315  outline.RemoveAllContours();
316  size = GetSize();
317  size.x += aDrawInfo.m_PadClearance * 2;
318  size.y += aDrawInfo.m_PadClearance * 2;
319  corner_radius = GetRoundRectCornerRadius() + aDrawInfo.m_PadClearance;
320 
321  TransformRoundChamferedRectToPolygon( outline, shape_pos, size, GetOrientation(),
322  corner_radius, GetChamferRectRatio(),
323  doChamfer ? GetChamferPositions() : 0,
324  ARC_HIGH_DEF );
325 
326  // Draw the polygon: Inflate creates only one convex polygon
327  SHAPE_LINE_CHAIN& clearance_poly = outline.Outline( 0 );
328 
329  GRClosedPoly( nullptr, aDC, clearance_poly.PointCount(),
330  (wxPoint*)&clearance_poly.Point( 0 ), false, 0,
331  aDrawInfo.m_Color, aDrawInfo.m_Color );
332  }
333  }
334  break;
335 
336  case PAD_SHAPE_CUSTOM:
337  {
338  // The full shape has 2 items
339  // 1- The anchor pad: a round or rect pad located at pad position
340  // 2- The custom complex shape
341  // Note: The anchor pad shape is containing by the custom complex shape polygon
342  // The anchor pad is shown to help user to see where is the anchor, only in sketch mode
343  // (In filled mode, it is merged with the basic shapes)
344  wxPoint pad_pos = GetPosition() - aDrawInfo.m_Offset;
345 
346  // In sketch mode only: Draw the anchor pad: a round or rect pad
347  if( !aDrawInfo.m_ShowPadFilled )
348  {
350  {
351  wxPoint poly[4];
352  poly[0] = wxPoint( - halfsize.x, - halfsize.y );
353  poly[1] = wxPoint( - halfsize.x, + halfsize.y );
354  poly[2] = wxPoint( + halfsize.x, + halfsize.y );
355  poly[3] = wxPoint( + halfsize.x, - halfsize.y );
356 
357  for( int ii = 0; ii < 4; ++ii )
358  {
359  RotatePoint( &poly[ii], m_Orient );
360  poly[ii] += pad_pos;
361  }
362 
363  GRClosedPoly( nullptr, aDC, 4, poly, false, 0, aDrawInfo.m_Color,
364  aDrawInfo.m_Color );
365  }
366  else
367  {
368  GRCircle( nullptr, aDC, pad_pos.x, pad_pos.y, halfsize.x,
369  m_PadSketchModePenSize, aDrawInfo.m_Color );
370  }
371  }
372 
373  SHAPE_POLY_SET outline; // Will contain the corners in board coordinates
374  outline.Append( m_customShapeAsPolygon );
375  CustomShapeAsPolygonToBoardPosition( &outline, pad_pos, GetOrientation() );
376  SHAPE_LINE_CHAIN* poly;
377 
378  if( aDrawInfo.m_Mask_margin.x )
379  {
380  int numSegs = GetArcToSegmentCount( aDrawInfo.m_Mask_margin.x, ARC_HIGH_DEF, 360.0 );
381  outline.InflateWithLinkedHoles(
382  aDrawInfo.m_Mask_margin.x, numSegs, SHAPE_POLY_SET::PM_FAST );
383  }
384 
385  // Draw the polygon: only one polygon is expected
386  // However we provide a multi polygon shape drawing
387  // ( can happen with CUSTOM pads and negative margins )
388  for( int jj = 0; jj < outline.OutlineCount(); ++jj )
389  {
390  poly = &outline.Outline( jj );
391 
392  GRClosedPoly( nullptr, aDC, poly->PointCount(), (wxPoint*)&poly->Point( 0 ),
393  aDrawInfo.m_ShowPadFilled, 0, aDrawInfo.m_Color, aDrawInfo.m_Color );
394  }
395 
396  if( aDrawInfo.m_PadClearance )
397  {
398  SHAPE_POLY_SET clearance_outline;
399  clearance_outline.Append( outline );
400 
401  int numSegs = GetArcToSegmentCount( aDrawInfo.m_PadClearance, ARC_HIGH_DEF, 360.0 );
402  clearance_outline.InflateWithLinkedHoles(
403  aDrawInfo.m_PadClearance, numSegs, SHAPE_POLY_SET::PM_FAST );
404 
405  for( int jj = 0; jj < clearance_outline.OutlineCount(); ++jj )
406  {
407  poly = &clearance_outline.Outline( jj );
408 
409  if( poly->PointCount() > 0 )
410  {
411  GRClosedPoly( nullptr, aDC, poly->PointCount(), (wxPoint*)&poly->Point( 0 ),
412  false, 0, aDrawInfo.m_Color, aDrawInfo.m_Color );
413  }
414  }
415  }
416 
417  break;
418  }
419  }
420 
421  // Draw the pad hole
422  wxPoint holepos = m_Pos - aDrawInfo.m_Offset;
423  int hole = m_Drill.x >> 1;
424 
425  bool drawhole = hole > 0;
426 
427  if( !aDrawInfo.m_ShowPadFilled && !aDrawInfo.m_ShowNotPlatedHole )
428  drawhole = false;
429 
430  if( drawhole )
431  {
432  bool blackpenstate = false;
433  COLOR4D fillcolor = aDrawInfo.m_ShowNotPlatedHole? aDrawInfo.m_NPHoleColor :
434  aDrawInfo.m_HoleColor;
435  COLOR4D hole_color = fillcolor;
436 
437  fillcolor = COLOR4D::WHITE;
438  blackpenstate = GetGRForceBlackPenState();
439  GRForceBlackPen( false );
440 
441  if( blackpenstate )
442  hole_color = COLOR4D::BLACK;
443 
444  switch( GetDrillShape() )
445  {
447  if( aDC->LogicalToDeviceXRel( hole ) > 1 ) // hole is drawn if hole > 1pixel
448  GRFilledCircle( nullptr, aDC, holepos.x, holepos.y, hole, 0, hole_color, fillcolor );
449  break;
450 
452  {
453  wxPoint drl_start, drl_end;
454  GetOblongDrillGeometry( drl_start, drl_end, seg_width );
455  drl_start += holepos;
456  drl_end += holepos;
457  GRFilledSegment( nullptr, aDC, drl_start, drl_end, seg_width, fillcolor );
458  GRCSegm( nullptr, aDC, drl_start, drl_end, seg_width, hole_color );
459  }
460  break;
461 
462  default:
463  break;
464  }
465 
466  if( aDrawInfo.m_IsPrinting )
467  GRForceBlackPen( blackpenstate );
468  }
469 
470  // Draw "No connect" ( / or \ or cross X ) if necessary
471  if( GetNetCode() == 0 && aDrawInfo.m_ShowNCMark )
472  {
473  int dx0 = std::min( halfsize.x, halfsize.y );
474 
475  if( m_layerMask[F_Cu] ) /* Draw \ */
476  GRLine( nullptr, aDC, holepos.x - dx0, holepos.y - dx0,
477  holepos.x + dx0, holepos.y + dx0, 0, aDrawInfo.m_NoNetMarkColor );
478 
479  if( m_layerMask[B_Cu] ) // Draw /
480  GRLine( nullptr, aDC, holepos.x + dx0, holepos.y - dx0,
481  holepos.x - dx0, holepos.y + dx0, 0, aDrawInfo.m_NoNetMarkColor );
482  }
483 
484  // Draw the pad number
485  if( !aDrawInfo.m_Display_padnum && !aDrawInfo.m_Display_netname )
486  return;
487 
488  wxPoint tpos0 = shape_pos; // Position of the centre of text
489  wxPoint tpos = tpos0;
490  wxSize AreaSize; // size of text area, normalized to AreaSize.y < AreaSize.x
491  wxString shortname;
492  int shortname_len = 0;
493 
494  if( aDrawInfo.m_Display_netname )
495  {
496  shortname = UnescapeString( GetShortNetname() );
497  shortname_len = shortname.Len();
498  }
499 
500  if( GetShape() == PAD_SHAPE_CIRCLE )
501  angle = 0;
502 
503  AreaSize = m_Size;
504 
505  if( m_Size.y > m_Size.x )
506  {
507  angle += 900;
508  AreaSize.x = m_Size.y;
509  AreaSize.y = m_Size.x;
510  }
511 
512  if( shortname_len > 0 ) // if there is a netname, provides room to display this netname
513  {
514  AreaSize.y /= 2; // Text used only the upper area of the
515  // pad. The lower area displays the net name
516  tpos.y -= AreaSize.y / 2;
517  }
518 
519  // Calculate the position of text, that is the middle point of the upper
520  // area of the pad
521  RotatePoint( &tpos, shape_pos, angle );
522 
523  // Draw text with an angle between -90 deg and + 90 deg
524  double t_angle = angle;
525  NORMALIZE_ANGLE_90( t_angle );
526 
527  /* Note: in next calculations, texte size is calculated for 3 or more
528  * chars. Of course, pads numbers and nets names can have less than 3
529  * chars. but after some tries, i found this is gives the best look
530  */
531  constexpr int MIN_CHAR_COUNT = 3;
532 
533  unsigned int tsize;
534 
535  if( aDrawInfo.m_Display_padnum )
536  {
537  int numpad_len = std::max( (int) m_name.Length(), MIN_CHAR_COUNT );
538  tsize = std::min( (int) AreaSize.y, AreaSize.x / numpad_len );
539 
540  if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) // Not drawable when size too small.
541  {
542  // tsize reserve room for marges and segments thickness
543  tsize = ( tsize * 7 ) / 10;
544  GRHaloText( aDC, tpos, aDrawInfo.m_Color, BLACK, WHITE, m_name, t_angle,
545  wxSize( tsize , tsize ), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
546  tsize / 7, false, false );
547 
548  }
549  }
550 
551  // display the short netname, if exists
552  if( shortname_len == 0 )
553  return;
554 
555  shortname_len = std::max( shortname_len, MIN_CHAR_COUNT );
556  tsize = std::min( AreaSize.y, AreaSize.x / shortname_len );
557 
558  if( aDC->LogicalToDeviceXRel( tsize ) >= MIN_TEXT_SIZE ) // Not drawable in size too small.
559  {
560  tpos = tpos0;
561 
562  if( aDrawInfo.m_Display_padnum )
563  tpos.y += AreaSize.y / 2;
564 
565  RotatePoint( &tpos, shape_pos, angle );
566 
567  // tsize reserve room for marges and segments thickness
568  tsize = ( tsize * 7 ) / 10;
569  GRHaloText( aDC, tpos, aDrawInfo.m_Color, BLACK, WHITE, shortname, t_angle,
570  wxSize( tsize, tsize ), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
571  tsize / 7, false, false );
572  }
573 }
574 
575 
583 int D_PAD::BuildSegmentFromOvalShape( wxPoint& aSegStart, wxPoint& aSegEnd, double aRotation,
584  const wxSize& aMargin ) const
585 {
586  int width;
587 
588  if( m_Size.y < m_Size.x ) // Build an horizontal equiv segment
589  {
590  int delta = ( m_Size.x - m_Size.y ) / 2;
591  aSegStart.x = -delta - aMargin.x;
592  aSegStart.y = 0;
593  aSegEnd.x = delta + aMargin.x;
594  aSegEnd.y = 0;
595  width = m_Size.y + ( aMargin.y * 2 );
596  }
597  else // Vertical oval: build a vertical equiv segment
598  {
599  int delta = ( m_Size.y -m_Size.x ) / 2;
600  aSegStart.x = 0;
601  aSegStart.y = -delta - aMargin.y;
602  aSegEnd.x = 0;
603  aSegEnd.y = delta + aMargin.y;
604  width = m_Size.x + ( aMargin.x * 2 );
605  }
606 
607  if( aRotation )
608  {
609  RotatePoint( &aSegStart, aRotation);
610  RotatePoint( &aSegEnd, aRotation);
611  }
612 
613  return width;
614 }
615 
616 
617 void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue,
618  double aRotation ) const
619 {
620  wxSize delta;
621  wxSize halfsize;
622 
623  halfsize.x = m_Size.x >> 1;
624  halfsize.y = m_Size.y >> 1;
625 
626  switch( GetShape() )
627  {
628  case PAD_SHAPE_RECT:
629  // For rectangular shapes, inflate is easy
630  halfsize += aInflateValue;
631 
632  // Verify if do not deflate more than than size
633  // Only possible for inflate negative values.
634  if( halfsize.x < 0 )
635  halfsize.x = 0;
636 
637  if( halfsize.y < 0 )
638  halfsize.y = 0;
639  break;
640 
641  case PAD_SHAPE_TRAPEZOID:
642  // Trapezoidal pad: verify delta values
643  delta.x = ( m_DeltaSize.x >> 1 );
644  delta.y = ( m_DeltaSize.y >> 1 );
645 
646  // be sure delta values are not to large
647  if( (delta.x < 0) && (delta.x <= -halfsize.y) )
648  delta.x = -halfsize.y + 1;
649 
650  if( (delta.x > 0) && (delta.x >= halfsize.y) )
651  delta.x = halfsize.y - 1;
652 
653  if( (delta.y < 0) && (delta.y <= -halfsize.x) )
654  delta.y = -halfsize.x + 1;
655 
656  if( (delta.y > 0) && (delta.y >= halfsize.x) )
657  delta.y = halfsize.x - 1;
658  break;
659 
660  default: // is used only for rect and trap. pads
661  return;
662  }
663 
664  // Build the basic rectangular or trapezoid shape
665  // delta is null for rectangular shapes
666  aCoord[0].x = -halfsize.x - delta.y; // lower left
667  aCoord[0].y = +halfsize.y + delta.x;
668 
669  aCoord[1].x = -halfsize.x + delta.y; // upper left
670  aCoord[1].y = -halfsize.y - delta.x;
671 
672  aCoord[2].x = +halfsize.x - delta.y; // upper right
673  aCoord[2].y = -halfsize.y + delta.x;
674 
675  aCoord[3].x = +halfsize.x + delta.y; // lower right
676  aCoord[3].y = +halfsize.y - delta.x;
677 
678  // Offsetting the trapezoid shape id needed
679  // It is assumed delta.x or/and delta.y == 0
680  if( GetShape() == PAD_SHAPE_TRAPEZOID && (aInflateValue.x != 0 || aInflateValue.y != 0) )
681  {
682  double angle;
683  wxSize corr;
684 
685  if( delta.y ) // lower and upper segment is horizontal
686  {
687  // Calculate angle of left (or right) segment with vertical axis
688  angle = atan2( (double) m_DeltaSize.y, (double) m_Size.y );
689 
690  // left and right sides are moved by aInflateValue.x in their perpendicular direction
691  // We must calculate the corresponding displacement on the horizontal axis
692  // that is delta.x +- corr.x depending on the corner
693  corr.x = KiROUND( tan( angle ) * aInflateValue.x );
694  delta.x = KiROUND( aInflateValue.x / cos( angle ) );
695 
696  // Horizontal sides are moved up and down by aInflateValue.y
697  delta.y = aInflateValue.y;
698 
699  // corr.y = 0 by the constructor
700  }
701  else if( delta.x ) // left and right segment is vertical
702  {
703  // Calculate angle of lower (or upper) segment with horizontal axis
704  angle = atan2( (double) m_DeltaSize.x, (double) m_Size.x );
705 
706  // lower and upper sides are moved by aInflateValue.x in their perpendicular direction
707  // We must calculate the corresponding displacement on the vertical axis
708  // that is delta.y +- corr.y depending on the corner
709  corr.y = KiROUND( tan( angle ) * aInflateValue.y );
710  delta.y = KiROUND( aInflateValue.y / cos( angle ) );
711 
712  // Vertical sides are moved left and right by aInflateValue.x
713  delta.x = aInflateValue.x;
714 
715  // corr.x = 0 by the constructor
716  }
717  else // the trapezoid is a rectangle
718  {
719  delta = aInflateValue; // this pad is rectangular (delta null).
720  }
721 
722  aCoord[0].x += -delta.x - corr.x; // lower left
723  aCoord[0].y += delta.y + corr.y;
724 
725  aCoord[1].x += -delta.x + corr.x; // upper left
726  aCoord[1].y += -delta.y - corr.y;
727 
728  aCoord[2].x += delta.x - corr.x; // upper right
729  aCoord[2].y += -delta.y + corr.y;
730 
731  aCoord[3].x += delta.x + corr.x; // lower right
732  aCoord[3].y += delta.y - corr.y;
733 
734  /* test coordinates and clamp them if the offset correction is too large:
735  * Note: if a coordinate is bad, the other "symmetric" coordinate is bad
736  * So when a bad coordinate is found, the 2 symmetric coordinates
737  * are set to the minimun value (0)
738  */
739 
740  if( aCoord[0].x > 0 ) // lower left x coordinate must be <= 0
741  aCoord[0].x = aCoord[3].x = 0;
742 
743  if( aCoord[1].x > 0 ) // upper left x coordinate must be <= 0
744  aCoord[1].x = aCoord[2].x = 0;
745 
746  if( aCoord[0].y < 0 ) // lower left y coordinate must be >= 0
747  aCoord[0].y = aCoord[1].y = 0;
748 
749  if( aCoord[3].y < 0 ) // lower right y coordinate must be >= 0
750  aCoord[3].y = aCoord[2].y = 0;
751  }
752 
753  if( aRotation )
754  {
755  for( int ii = 0; ii < 4; ii++ )
756  RotatePoint( &aCoord[ii], aRotation );
757  }
758 }
Definition: colors.h:57
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:676
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:143
show a marker on pads with no nets
int GetNetCode() const
Function GetNetCode.
int OutlineCount() const
Returns the number of outlines in the set
bool m_Display_padnum
Definition: class_pad.h:73
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
PAD_SHAPE_T GetAnchorPadShape() const
Function GetAnchorPadShape.
Definition: class_pad.h:231
handle color for not plated holes (holes, not pads)
int BuildSegmentFromOvalShape(wxPoint &aSegStart, wxPoint &aSegEnd, double aRotation, const wxSize &aMargin) const
Function BuildSegmentFromOvalShape Has meaning only for OVAL (and ROUND) pads Build an equivalent seg...
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:825
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aApproxErrorMax, int aMinSegPerCircleCount)
convert a rectangle with rounded corners and/or chamfered corners to a polygon Convert rounded corner...
int color
Definition: DXF_plotter.cpp:62
wxSize m_Size
X and Y size ( relative to orient 0)
Definition: class_pad.h:858
void GRCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, int aPenSize, COLOR4D Color)
Definition: gr_basic.cpp:312
COLOR4D m_NoNetMarkColor
Definition: class_pad.h:70
bool m_ShowNCMark
Definition: class_pad.h:77
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:206
void GRFilledCircle(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int r, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:623
int PointCount() const
Function PointCount()
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use Display options are relative to...
static LSET FrontMask()
Function FrontMask returns a mask holding all technical layers and the external CU layer on front sid...
Definition: lset.cpp:775
void NORMALIZE_ANGLE_90(T &Angle)
Definition: trigo.h:331
void GRClosedPoly(EDA_RECT *ClipBox, wxDC *DC, int n, wxPoint Points[], bool Fill, COLOR4D Color, COLOR4D BgColor)
Function GRClosedPoly draws a closed polygon onto the drawing context aDC and optionally fills and/or...
Definition: gr_basic.cpp:556
bool m_IsPrinting
Definition: class_pad.h:80
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:429
int GetChamferPositions() const
has meaning only for chamfered rect pads
Definition: class_pad.h:693
int GetSolderMaskMargin() const
Function GetSolderMaskMargin.
Definition: class_pad.cpp:627
PCB_LAYER_ID
A quick note on layer IDs:
wxString m_name
Definition: class_pad.h:823
Class LSET is a set of PCB_LAYER_IDs.
void GRForceBlackPen(bool flagforce)
Function GRForceBlackPen.
Definition: gr_basic.cpp:201
Class SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
void GRFillCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color)
Definition: gr_basic.cpp:415
PCB_GENERAL_SETTINGS & Settings()
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:412
double GetChamferRectRatio() const
has meaning only for chamfered rect pads
Definition: class_pad.h:670
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
void Print(PCB_BASE_FRAME *aFrame, wxDC *aDC, const wxPoint &aOffset=ZeroOffset) override
Function Print BOARD_ITEMs have their own color information.
COLOR4D m_HoleColor
Definition: class_pad.h:68
#define MIN_TEXT_SIZE
Definition: gr_text.h:43
a few functions useful in geometry calculations.
void PrintShape(wxDC *aDC, PAD_DRAWINFO &aDrawInfo)
Function PrintShape basic function to print a pad.
bool m_ShowNotPlatedHole
Definition: class_pad.h:78
SHAPE_POLY_SET m_customShapeAsPolygon
for free shape pads: the set of basic shapes, merged as one polygon, in local coordinates,...
Definition: class_pad.h:841
wxSize m_DeltaSize
delta on rectangular shapes
Definition: class_pad.h:891
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:230
int m_PadClearance
Definition: class_pad.h:71
bool m_IsPrinting
Definition: base_screen.h:139
COLORS_DESIGN_SETTINGS & Colors()
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
void BuildPadPolygon(wxPoint aCoord[4], wxSize aInflateValue, double aRotation) const
Function BuildPadPolygon Has meaning only for polygonal pads (trapezoid and rectangular) Build the Co...
LSET m_layerMask
Bitwise layer :1= copper layer, 15= cmp, 2..14 = internal layers 16 .
Definition: class_pad.h:887
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aMaxError=ARC_HIGH_DEF, bool ignoreLineWidth=false) const override
Function TransformShapeWithClearanceToPolygon Convert the pad shape to a closed polygon Used in filli...
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:450
void GRHaloText(wxDC *aDC, const wxPoint &aPos, const COLOR4D aBgColor, COLOR4D aColor1, COLOR4D aColor2, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf, void *aData), void *aCallbackData, PLOTTER *aPlotter)
Draw graphic text with a border, so that it can be read on different backgrounds.
Definition: gr_text.cpp:171
wxPoint m_Offset
Definition: class_pad.h:81
smd pads, front layer
Board layer functions and definitions.
wxSize GetSolderPasteMargin() const
Function GetSolderPasteMargin.
Definition: class_pad.cpp:673
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:615
#define max(a, b)
Definition: auxiliary.h:86
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
Class SHAPE_LINE_CHAIN.
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:406
void CustomShapeAsPolygonToBoardPosition(SHAPE_POLY_SET *aMergedPolygon, wxPoint aPosition, double aRotation) const
When created, the corners coordinates are relative to the pad position, orientation 0,...
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
void GRFilledSegment(EDA_RECT *aClipBox, wxDC *aDC, wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor)
Definition: gr_basic.cpp:423
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:600
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:187
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
wxPoint ShapePos() const
Definition: class_pad.cpp:570
The common library.
void InflateWithLinkedHoles(int aFactor, int aCircleSegmentsCount, POLYGON_MODE aFastMode)
Performs outline inflation/deflation, using round corners.
int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
Definition: class_pad.cpp:596
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static LSET BackMask()
Function BackMask returns a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:782
Definition: colors.h:49
bool m_ShowPadFilled
Definition: class_pad.h:75
int GetRoundRectCornerRadius() const
Function GetRoundRectCornerRadius Has meaning only for rounded rect pads.
Definition: class_pad.h:546
COLOR4D m_NPHoleColor
Definition: class_pad.h:69
COLOR4D m_Color
Definition: class_pad.h:66
VECTOR2I & Point(int aIndex)
Function Point()
wxSize m_Drill
Drill diam (drill shape = PAD_CIRCLE) or drill size (shape = OVAL) for drill shape = PAD_CIRCLE,...
Definition: class_pad.h:854
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:221
Definition: colors.h:45
double m_Orient
in 1/10 degrees
Definition: class_pad.h:898
bool m_Display_netname
Definition: class_pad.h:74
const wxSize & GetSize() const
Definition: class_pad.h:284
bool GetGRForceBlackPenState(void)
Function GetGRForceBlackPenState.
Definition: gr_basic.cpp:211
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:715
const wxPoint GetPosition() const override
Definition: class_pad.h:225
wxSize m_Mask_margin
Definition: class_pad.h:72
Definition: colors.h:68
bool PadShouldBeNPTH() const
A pad whose hole is the same size as the pad is a NPTH.
Definition: class_pad.cpp:1300
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
#define DO_NOT_DRAW
Used to disable draw function.
Definition: base_struct.h:132
const wxString & GetShortNetname() const
Function GetShortNetname.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:114
#define min(a, b)
Definition: auxiliary.h:85
wxPoint m_Pos
pad Position on board
Definition: class_pad.h:826
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39