KiCad PCB EDA Suite
board_items_to_polygon_shape_transform.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) 2009-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 /***
26  * @file board_items_to_polygon_shape_transform.cpp
27  * @brief function to convert shapes of items ( pads, tracks... ) to polygons
28  */
29 
30 /* Function to convert pad and track shapes to polygons
31  * Used to fill zones areas and in 3D viewer
32  */
33 #include <vector>
34 
35 #include <fctsys.h>
36 #include <bezier_curves.h>
37 #include <base_units.h> // for IU_PER_MM
38 #include <draw_graphic_text.h>
39 #include <pcbnew.h>
40 #include <pcb_edit_frame.h>
41 #include <trigo.h>
42 #include <class_board.h>
43 #include <class_pad.h>
44 #include <class_track.h>
45 #include <class_drawsegment.h>
46 #include <class_pcb_text.h>
47 #include <class_zone.h>
48 #include <class_module.h>
49 #include <class_edge_mod.h>
52 
53 // A helper struct for the callback function
54 // These variables are parameters used in addTextSegmToPoly.
55 // But addTextSegmToPoly is a call-back function,
56 // so we cannot send them as arguments.
61 };
63 
64 // The max error is the distance between the middle of a segment, and the circle
65 // for circle/arc to segment approximation.
66 // Warning: too small values can create very long calculation time in zone filling
67 // 0.05 to 0.01 mm is a reasonable value
68 double s_error_max = Millimeter2iu( 0.02 );
69 
70 // This is a call back function, used by DrawGraphicText to draw the 3D text shape:
71 static void addTextSegmToPoly( int x0, int y0, int xf, int yf, void* aData )
72 {
73  TSEGM_2_POLY_PRMS* prm = static_cast<TSEGM_2_POLY_PRMS*>( aData );
75  wxPoint( x0, y0), wxPoint( xf, yf ),
77 }
78 
79 
81 {
82  // Number of segments to convert a circle to a polygon
83  const int segcountforcircle = 18;
84  double correctionFactor = GetCircletoPolyCorrectionFactor( segcountforcircle );
85 
86  // convert tracks and vias:
87  for( TRACK* track = m_Track; track != NULL; track = track->Next() )
88  {
89  if( !track->IsOnLayer( aLayer ) )
90  continue;
91 
92  track->TransformShapeWithClearanceToPolygon( aOutlines,
93  0, segcountforcircle, correctionFactor );
94  }
95 
96  // convert pads
97  for( MODULE* module = m_Modules; module != NULL; module = module->Next() )
98  {
99  module->TransformPadsShapesWithClearanceToPolygon( aLayer,
100  aOutlines, 0, segcountforcircle, correctionFactor );
101 
102  // Micro-wave modules may have items on copper layers
103  module->TransformGraphicShapesWithClearanceToPolygonSet( aLayer,
104  aOutlines, 0, segcountforcircle, correctionFactor );
105  }
106 
107  // convert copper zones
108  for( int ii = 0; ii < GetAreaCount(); ii++ )
109  {
110  ZONE_CONTAINER* zone = GetArea( ii );
111  PCB_LAYER_ID zonelayer = zone->GetLayer();
112 
113  if( zonelayer == aLayer )
115  aOutlines, segcountforcircle, correctionFactor );
116  }
117 
118  // convert graphic items on copper layers (texts)
119  for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
120  {
121  if( !item->IsOnLayer( aLayer ) )
122  continue;
123 
124  switch( item->Type() )
125  {
126  case PCB_LINE_T: // should not exist on copper layers
127  ( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon(
128  aOutlines, 0, segcountforcircle, correctionFactor );
129  break;
130 
131  case PCB_TEXT_T:
132  ( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygonSet(
133  aOutlines, 0, segcountforcircle, correctionFactor );
134  break;
135 
136  default:
137  break;
138  }
139  }
140 }
141 
142 
144  SHAPE_POLY_SET& aCornerBuffer,
145  int aInflateValue,
146  int aCircleToSegmentsCount,
147  double aCorrectionFactor,
148  bool aSkipNPTHPadsWihNoCopper ) const
149 {
150  D_PAD* pad = PadsList();
151 
152  wxSize margin;
153  for( ; pad != NULL; pad = pad->Next() )
154  {
155  if( aLayer != UNDEFINED_LAYER && !pad->IsOnLayer(aLayer) )
156  continue;
157 
158  // NPTH pads are not drawn on layers if the shape size and pos is the same
159  // as their hole:
160  if( aSkipNPTHPadsWihNoCopper && pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
161  {
162  if( pad->GetDrillSize() == pad->GetSize() && pad->GetOffset() == wxPoint( 0, 0 ) )
163  {
164  switch( pad->GetShape() )
165  {
166  case PAD_SHAPE_CIRCLE:
167  if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
168  continue;
169  break;
170 
171  case PAD_SHAPE_OVAL:
172  if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
173  continue;
174  break;
175 
176  default:
177  break;
178  }
179  }
180  }
181 
182  switch( aLayer )
183  {
184  case F_Mask:
185  case B_Mask:
186  margin.x = margin.y = pad->GetSolderMaskMargin() + aInflateValue;
187  break;
188 
189  case F_Paste:
190  case B_Paste:
191  margin = pad->GetSolderPasteMargin();
192  margin.x += aInflateValue;
193  margin.y += aInflateValue;
194  break;
195 
196  default:
197  margin.x = margin.y = aInflateValue;
198  break;
199  }
200 
201  pad->BuildPadShapePolygon( aCornerBuffer, margin,
202  aCircleToSegmentsCount, aCorrectionFactor );
203  }
204 }
205 
206 /* generate shapes of graphic items (outlines) on layer aLayer as polygons,
207  * and adds these polygons to aCornerBuffer
208  * aCornerBuffer = the buffer to store polygons
209  * aInflateValue = a value to inflate shapes
210  * aCircleToSegmentsCount = number of segments to approximate a circle
211  * aCorrectionFactor = the correction to apply to the circle radius
212  * to generate the polygon.
213  * if aCorrectionFactor = 1.0, the polygon is inside the circle
214  * the radius of circle approximated by segments is
215  * initial radius * aCorrectionFactor
216  */
218  PCB_LAYER_ID aLayer,
219  SHAPE_POLY_SET& aCornerBuffer,
220  int aInflateValue,
221  int aCircleToSegmentsCount,
222  double aCorrectionFactor,
223  int aCircleToSegmentsCountForTexts,
224  bool aIncludeText ) const
225 {
226  std::vector<TEXTE_MODULE *> texts; // List of TEXTE_MODULE to convert
227  EDGE_MODULE* outline;
228 
229  for( EDA_ITEM* item = GraphicalItemsList(); item != NULL; item = item->Next() )
230  {
231  switch( item->Type() )
232  {
233  case PCB_MODULE_TEXT_T:
234  {
235  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
236 
237  if( ( aLayer != UNDEFINED_LAYER && text->GetLayer() == aLayer )
238  && text->IsVisible() )
239  texts.push_back( text );
240 
241  break;
242  }
243 
244  case PCB_MODULE_EDGE_T:
245  outline = (EDGE_MODULE*) item;
246 
247  if( aLayer != UNDEFINED_LAYER && outline->GetLayer() != aLayer )
248  break;
249 
250  outline->TransformShapeWithClearanceToPolygon( aCornerBuffer, 0,
251  aCircleToSegmentsCount, aCorrectionFactor );
252  break;
253 
254  default:
255  break;
256  }
257  }
258 
259  if( !aIncludeText )
260  return;
261 
262  // Convert texts sur modules
263  if( Reference().GetLayer() == aLayer && Reference().IsVisible() )
264  texts.push_back( &Reference() );
265 
266  if( Value().GetLayer() == aLayer && Value().IsVisible() )
267  texts.push_back( &Value() );
268 
269  prms.m_cornerBuffer = &aCornerBuffer;
270 
271  // To allow optimization of circles approximated by segments,
272  // aCircleToSegmentsCountForTexts, when not 0, is used.
273  // if 0 (default value) the aCircleToSegmentsCount is used
274  prms.m_textCircle2SegmentCount = aCircleToSegmentsCountForTexts ?
275  aCircleToSegmentsCountForTexts : aCircleToSegmentsCount;
276 
277  for( unsigned ii = 0; ii < texts.size(); ii++ )
278  {
279  TEXTE_MODULE *textmod = texts[ii];
280  prms.m_textWidth = textmod->GetThickness() + ( 2 * aInflateValue );
281  wxSize size = textmod->GetTextSize();
282 
283  if( textmod->IsMirrored() )
284  size.x = -size.x;
285 
286  DrawGraphicText( NULL, NULL, textmod->GetTextPos(), BLACK,
287  textmod->GetShownText(), textmod->GetDrawRotation(), size,
288  textmod->GetHorizJustify(), textmod->GetVertJustify(),
289  textmod->GetThickness(), textmod->IsItalic(),
290  true, addTextSegmToPoly, &prms );
291  }
292 
293 }
294 
295 
296 // Same as function TransformGraphicShapesWithClearanceToPolygonSet but
297 // this only render text
299  PCB_LAYER_ID aLayer,
300  SHAPE_POLY_SET& aCornerBuffer,
301  int aInflateValue,
302  int aCircleToSegmentsCount,
303  double aCorrectionFactor,
304  int aCircleToSegmentsCountForTexts ) const
305 {
306  std::vector<TEXTE_MODULE *> texts; // List of TEXTE_MODULE to convert
307 
308  for( EDA_ITEM* item = GraphicalItemsList(); item != NULL; item = item->Next() )
309  {
310  switch( item->Type() )
311  {
312  case PCB_MODULE_TEXT_T:
313  {
314  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
315 
316  if( text->GetLayer() == aLayer && text->IsVisible() )
317  texts.push_back( text );
318 
319  break;
320  }
321 
322  case PCB_MODULE_EDGE_T:
323  // This function does not render this
324  break;
325 
326  default:
327  break;
328  }
329  }
330 
331  // Convert texts sur modules
332  if( Reference().GetLayer() == aLayer && Reference().IsVisible() )
333  texts.push_back( &Reference() );
334 
335  if( Value().GetLayer() == aLayer && Value().IsVisible() )
336  texts.push_back( &Value() );
337 
338  prms.m_cornerBuffer = &aCornerBuffer;
339 
340  // To allow optimization of circles approximated by segments,
341  // aCircleToSegmentsCountForTexts, when not 0, is used.
342  // if 0 (default value) the aCircleToSegmentsCount is used
343  prms.m_textCircle2SegmentCount = aCircleToSegmentsCountForTexts ?
344  aCircleToSegmentsCountForTexts : aCircleToSegmentsCount;
345 
346  for( unsigned ii = 0; ii < texts.size(); ii++ )
347  {
348  TEXTE_MODULE *textmod = texts[ii];
349  prms.m_textWidth = textmod->GetThickness() + ( 2 * aInflateValue );
350  wxSize size = textmod->GetTextSize();
351 
352  if( textmod->IsMirrored() )
353  size.x = -size.x;
354 
355  DrawGraphicText( NULL, NULL, textmod->GetTextPos(), BLACK,
356  textmod->GetShownText(), textmod->GetDrawRotation(), size,
357  textmod->GetHorizJustify(), textmod->GetVertJustify(),
358  textmod->GetThickness(), textmod->IsItalic(),
359  true, addTextSegmToPoly, &prms );
360  }
361 
362 }
363 
364  /* Function TransformSolidAreasShapesToPolygonSet
365  * Convert solid areas full shapes to polygon set
366  * (the full shape is the polygon area with a thick outline)
367  * Used in 3D view
368  * Arcs (ends of segments) are approximated by segments
369  * aCornerBuffer = a buffer to store the polygons
370  * aCircleToSegmentsCount = the number of segments to approximate a circle
371  * aCorrectionFactor = the correction to apply to arcs radius to roughly
372  * keep arc radius when approximated by segments
373  */
375  SHAPE_POLY_SET& aCornerBuffer,
376  int aCircleToSegmentsCount,
377  double aCorrectionFactor ) const
378 {
379  if( GetFilledPolysList().IsEmpty() )
380  return;
381 
382  // add filled areas polygons
383  aCornerBuffer.Append( m_FilledPolysList );
384 
385  // add filled areas outlines, which are drawn with thick lines
386  for( int i = 0; i < m_FilledPolysList.OutlineCount(); i++ )
387  {
388  const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( i );
389 
390  for( int j = 0; j < path.PointCount(); j++ )
391  {
392  const VECTOR2I& a = path.CPoint( j );
393  const VECTOR2I& b = path.CPoint( j + 1 );
394 
395  TransformRoundedEndsSegmentToPolygon( aCornerBuffer, wxPoint( a.x, a.y ), wxPoint( b.x, b.y ),
396  aCircleToSegmentsCount,
397  GetMinThickness() );
398  }
399  }
400 }
401 
411  SHAPE_POLY_SET& aCornerBuffer,
412  int aClearanceValue ) const
413 {
414  // Oh dear. When in UTF-8 mode, wxString puts string iterators in a linked list, and
415  // that linked list is not thread-safe.
416  std::lock_guard<std::mutex> guard( m_mutex );
417 
418  if( GetText().Length() == 0 )
419  return;
420 
421  wxPoint corners[4]; // Buffer of polygon corners
422 
423  EDA_RECT rect = GetTextBox( -1 );
424  rect.Inflate( aClearanceValue );
425  corners[0].x = rect.GetOrigin().x;
426  corners[0].y = rect.GetOrigin().y;
427  corners[1].y = corners[0].y;
428  corners[1].x = rect.GetRight();
429  corners[2].x = corners[1].x;
430  corners[2].y = rect.GetBottom();
431  corners[3].y = corners[2].y;
432  corners[3].x = corners[0].x;
433 
434  aCornerBuffer.NewOutline();
435 
436  for( int ii = 0; ii < 4; ii++ )
437  {
438  // Rotate polygon
439  RotatePoint( &corners[ii].x, &corners[ii].y, GetTextPos().x, GetTextPos().y, GetTextAngle() );
440  aCornerBuffer.Append( corners[ii].x, corners[ii].y );
441  }
442 }
443 
444 
445 /* Function TransformShapeWithClearanceToPolygonSet
446  * Convert the text shape to a set of polygons (one by segment)
447  * Used in filling zones calculations and 3D view
448  * Circles and arcs are approximated by segments
449  * aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
450  * aClearanceValue = the clearance around the text
451  * aCircleToSegmentsCount = the number of segments to approximate a circle
452  * aCorrectionFactor = the correction to apply to circles radius to keep
453  * clearance when the circle is approximated by segment bigger or equal
454  * to the real clearance value (usually near from 1.0)
455  */
456 
458  SHAPE_POLY_SET& aCornerBuffer,
459  int aClearanceValue,
460  int aCircleToSegmentsCount,
461  double aCorrectionFactor ) const
462 {
463  wxSize size = GetTextSize();
464 
465  if( IsMirrored() )
466  size.x = -size.x;
467 
468  prms.m_cornerBuffer = &aCornerBuffer;
469  prms.m_textWidth = GetThickness() + ( 2 * aClearanceValue );
470  prms.m_textCircle2SegmentCount = aCircleToSegmentsCount;
471  COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by DrawGraphicText
472 
473  if( IsMultilineAllowed() )
474  {
475  wxArrayString strings_list;
476  wxStringSplit( GetShownText(), strings_list, '\n' );
477  std::vector<wxPoint> positions;
478  positions.reserve( strings_list.Count() );
479  GetPositionsOfLinesOfMultilineText( positions, strings_list.Count() );
480 
481  for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
482  {
483  wxString txt = strings_list.Item( ii );
484  DrawGraphicText( NULL, NULL, positions[ii], color,
485  txt, GetTextAngle(), size,
486  GetHorizJustify(), GetVertJustify(),
487  GetThickness(), IsItalic(),
488  true, addTextSegmToPoly, &prms );
489  }
490  }
491  else
492  {
493  DrawGraphicText( NULL, NULL, GetTextPos(), color,
494  GetShownText(), GetTextAngle(), size,
495  GetHorizJustify(), GetVertJustify(),
496  GetThickness(), IsItalic(),
497  true, addTextSegmToPoly, &prms );
498  }
499 }
500 
501 
515  int aClearanceValue,
516  int aCircleToSegmentsCount,
517  double aCorrectionFactor ) const
518 {
519  // The full width of the lines to create:
520  int linewidth = m_Width + (2 * aClearanceValue);
521 
522  // Creating a reliable clearance shape for circles and arcs is not so easy, due to
523  // the error created by segment approximation.
524  // for a cicle this is not so hard: create a polygon from a circle slightly bigger:
525  // thickness = linewidth + s_error_max, and radius = initial radius + s_error_max/2
526  // giving a shape with a suitable internal radius and external radius
527  // For an arc this is more tricky: TODO
528  if( m_Shape == S_CIRCLE || m_Shape == S_ARC )
529  {
530  int segCount = GetArcToSegmentCount( GetRadius(), s_error_max, 360.0 );
531 
532  if( segCount > aCircleToSegmentsCount )
533  aCircleToSegmentsCount = segCount;
534  }
535 
536  switch( m_Shape )
537  {
538  case S_CIRCLE:
539  TransformRingToPolygon( aCornerBuffer, GetCenter(), GetRadius() + (s_error_max/2),
540  aCircleToSegmentsCount, linewidth + s_error_max ) ;
541  break;
542 
543  case S_ARC:
544  TransformArcToPolygon( aCornerBuffer, GetCenter(),
545  GetArcStart(), m_Angle,
546  aCircleToSegmentsCount, linewidth );
547  break;
548 
549  case S_SEGMENT:
550  TransformOvalClearanceToPolygon( aCornerBuffer, m_Start, m_End, linewidth,
551  aCircleToSegmentsCount, aCorrectionFactor );
552  break;
553 
554  case S_POLYGON:
555  if( IsPolyShapeValid() )
556  {
557  // The polygon is expected to be a simple polygon
558  // not self intersecting, no hole.
559  MODULE* module = GetParentModule(); // NULL for items not in footprints
560  double orientation = module ? module->GetOrientation() : 0.0;
561  wxPoint offset;
562 
563  if( module )
564  offset = module->GetPosition();
565 
566  // Build the polygon with the actual position and orientation:
567  std::vector< wxPoint> poly;
568  poly = BuildPolyPointsList();
569 
570  for( unsigned ii = 0; ii < poly.size(); ii++ )
571  {
572  RotatePoint( &poly[ii], orientation );
573  poly[ii] += offset;
574  }
575 
576  // Generate polygons for the outline + clearance
577  // This code is compatible with a polygon with holes linked to external outline
578  // by overlapping segments.
579 
580  // Insert the initial polygon:
581  aCornerBuffer.NewOutline();
582 
583  for( unsigned ii = 0; ii < poly.size(); ii++ )
584  aCornerBuffer.Append( poly[ii].x, poly[ii].y );
585 
586  if( linewidth ) // Add thick outlines
587  {
588  wxPoint corner1( poly[poly.size()-1] );
589 
590  for( unsigned ii = 0; ii < poly.size(); ii++ )
591  {
592  wxPoint corner2( poly[ii] );
593 
594  if( corner2 != corner1 )
595  {
597  corner1, corner2, aCircleToSegmentsCount, linewidth );
598  }
599 
600  corner1 = corner2;
601  }
602  }
603  }
604  break;
605 
606  case S_CURVE: // Bezier curve
607  {
608  std::vector<wxPoint> ctrlPoints = { m_Start, m_BezierC1, m_BezierC2, m_End };
609  BEZIER_POLY converter( ctrlPoints );
610  std::vector< wxPoint> poly;
611  converter.GetPoly( poly, m_Width );
612 
613  for( unsigned ii = 1; ii < poly.size(); ii++ )
614  {
616  poly[ii-1], poly[ii], aCircleToSegmentsCount, linewidth );
617  }
618  }
619  break;
620 
621  default:
622  break;
623  }
624 }
625 
626 
640  int aClearanceValue,
641  int aCircleToSegmentsCount,
642  double aCorrectionFactor ) const
643 {
644  switch( Type() )
645  {
646  case PCB_VIA_T:
647  {
648  int radius = (m_Width / 2) + aClearanceValue;
649  radius = KiROUND( radius * aCorrectionFactor );
650  TransformCircleToPolygon( aCornerBuffer, m_Start, radius, aCircleToSegmentsCount );
651  }
652  break;
653 
654  default:
655  TransformOvalClearanceToPolygon( aCornerBuffer, m_Start, m_End,
656  m_Width + ( 2 * aClearanceValue),
657  aCircleToSegmentsCount,
658  aCorrectionFactor );
659  break;
660  }
661 }
662 
663 
664 /* Function TransformShapeWithClearanceToPolygon
665  * Convert the pad shape to a closed polygon
666  * Used in filling zones calculations and 3D view generation
667  * Circles and arcs are approximated by segments
668  * aCornerBuffer = a SHAPE_POLY_SET to store the polygon corners
669  * aClearanceValue = the clearance around the pad
670  * aCircleToSegmentsCount = the number of segments to approximate a circle
671  * aCorrectionFactor = the correction to apply to circles radius to keep
672  * clearance when the circle is approximated by segment bigger or equal
673  * to the real clearance value (usually near from 1.0)
674  */
676  int aClearanceValue,
677  int aCircleToSegmentsCount,
678  double aCorrectionFactor ) const
679 {
680  double angle = m_Orient;
681  int dx = (m_Size.x / 2) + aClearanceValue;
682  int dy = (m_Size.y / 2) + aClearanceValue;
683 
684  wxPoint padShapePos = ShapePos(); /* Note: for pad having a shape offset,
685  * the pad position is NOT the shape position */
686 
687  switch( GetShape() )
688  {
689  case PAD_SHAPE_CIRCLE:
690  dx = KiROUND( dx * aCorrectionFactor );
691  TransformCircleToPolygon( aCornerBuffer, padShapePos, dx,
692  aCircleToSegmentsCount );
693  break;
694 
695  case PAD_SHAPE_OVAL:
696  // An oval pad has the same shape as a segment with rounded ends
697  {
698  int width;
699  wxPoint shape_offset;
700  if( dy > dx ) // Oval pad X/Y ratio for choosing translation axis
701  {
702  shape_offset.y = dy - dx;
703  width = dx * 2;
704  }
705  else //if( dy <= dx )
706  {
707  shape_offset.x = dy - dx;
708  width = dy * 2;
709  }
710 
711  RotatePoint( &shape_offset, angle );
712  wxPoint start = padShapePos - shape_offset;
713  wxPoint end = padShapePos + shape_offset;
714  TransformOvalClearanceToPolygon( aCornerBuffer, start, end, width,
715  aCircleToSegmentsCount, aCorrectionFactor );
716  }
717  break;
718 
719  case PAD_SHAPE_TRAPEZOID:
720  case PAD_SHAPE_RECT:
721  {
722  wxPoint corners[4];
723  BuildPadPolygon( corners, wxSize( 0, 0 ), angle );
724 
725  SHAPE_POLY_SET outline;
726  outline.NewOutline();
727 
728  for( int ii = 0; ii < 4; ii++ )
729  {
730  corners[ii] += padShapePos;
731  outline.Append( corners[ii].x, corners[ii].y );
732  }
733 
734  int rounding_radius = int( aClearanceValue * aCorrectionFactor );
735  outline.Inflate( rounding_radius, aCircleToSegmentsCount );
736 
737  aCornerBuffer.Append( outline );
738  }
739  break;
740 
741  case PAD_SHAPE_ROUNDRECT:
742  {
743  SHAPE_POLY_SET outline;
744  int pad_radius = GetRoundRectCornerRadius();
745  int clearance = int( aClearanceValue * aCorrectionFactor );
746  int rounding_radius = pad_radius + clearance;
747  wxSize shapesize( m_Size );
748  shapesize.x += clearance*2;
749  shapesize.y += clearance*2;
750 
751  TransformRoundRectToPolygon( outline, padShapePos, shapesize, angle,
752  rounding_radius, aCircleToSegmentsCount );
753 
754  aCornerBuffer.Append( outline );
755  }
756  break;
757 
758  case PAD_SHAPE_CUSTOM:
759  {
760  int clearance = KiROUND( aClearanceValue * aCorrectionFactor );
761 
762  SHAPE_POLY_SET outline; // Will contain the corners in board coordinates
763  outline.Append( m_customShapeAsPolygon );
764  CustomShapeAsPolygonToBoardPosition( &outline, GetPosition(), GetOrientation() );
765  outline.Inflate( clearance, aCircleToSegmentsCount );
766  aCornerBuffer.Append( outline );
767  }
768  break;
769  }
770 }
771 
772 
773 
774 /*
775  * Function BuildPadShapePolygon
776  * Build the Corner list of the polygonal shape,
777  * depending on shape, extra size (clearance ...) pad and orientation
778  * Note: for Round and oval pads this function is equivalent to
779  * TransformShapeWithClearanceToPolygon, but not for other shapes
780  */
782  wxSize aInflateValue, int aSegmentsPerCircle,
783  double aCorrectionFactor ) const
784 {
785  wxPoint corners[4];
786  wxPoint padShapePos = ShapePos(); /* Note: for pad having a shape offset,
787  * the pad position is NOT the shape position */
788  switch( GetShape() )
789  {
790  case PAD_SHAPE_CIRCLE:
791  case PAD_SHAPE_OVAL:
792  case PAD_SHAPE_ROUNDRECT:
793  {
794  // We are using TransformShapeWithClearanceToPolygon to build the shape.
795  // Currently, this method uses only the same inflate value for X and Y dirs.
796  // so because here this is not the case, we use a inflated dummy pad to build
797  // the polygonal shape
798  // TODO: remove this dummy pad when TransformShapeWithClearanceToPolygon will use
799  // a wxSize to inflate the pad size
800  D_PAD dummy( *this );
801  dummy.SetSize( GetSize() + aInflateValue + aInflateValue );
802  dummy.TransformShapeWithClearanceToPolygon( aCornerBuffer, 0,
803  aSegmentsPerCircle, aCorrectionFactor );
804  }
805  break;
806 
807  case PAD_SHAPE_TRAPEZOID:
808  case PAD_SHAPE_RECT:
809  aCornerBuffer.NewOutline();
810 
811  BuildPadPolygon( corners, aInflateValue, m_Orient );
812  for( int ii = 0; ii < 4; ii++ )
813  {
814  corners[ii] += padShapePos; // Shift origin to position
815  aCornerBuffer.Append( corners[ii].x, corners[ii].y );
816  }
817 
818  break;
819 
820  case PAD_SHAPE_CUSTOM:
821  // for a custom shape, that is in fact a polygon (with holes), we can use only a inflate value.
822  // so use ( aInflateValue.x + aInflateValue.y ) / 2 as polygon inflate value.
823  // (different values for aInflateValue.x and aInflateValue.y has no sense for a custom pad)
824  TransformShapeWithClearanceToPolygon( aCornerBuffer,
825  ( aInflateValue.x + aInflateValue.y ) / 2,
826  aSegmentsPerCircle, aCorrectionFactor );
827  break;
828  }
829 }
830 
831 /*
832  * Function BuildPadDrillShapePolygon
833  * Build the Corner list of the polygonal drill shape,
834  * depending on shape pad hole and orientation
835  * return false if the pad has no hole, true otherwise
836  */
838  int aInflateValue, int aSegmentsPerCircle ) const
839 {
840  wxSize drillsize = GetDrillSize();
841 
842  if( !drillsize.x || !drillsize.y )
843  return false;
844 
845  if( drillsize.x == drillsize.y ) // usual round hole
846  {
847  TransformCircleToPolygon( aCornerBuffer, GetPosition(),
848  (drillsize.x / 2) + aInflateValue, aSegmentsPerCircle );
849  }
850  else // Oblong hole
851  {
852  wxPoint start, end;
853  int width;
854 
855  GetOblongDrillGeometry( start, end, width );
856 
857  width += aInflateValue * 2;
858 
860  GetPosition() + start, GetPosition() + end, aSegmentsPerCircle, width );
861  }
862 
863  return true;
864 }
865 
880 /* thermal reliefs are created as 4 polygons.
881  * each corner of a polygon if calculated for a pad at position 0, 0, orient 0,
882  * and then moved and rotated acroding to the pad position and orientation
883  */
884 
885 /*
886  * Note 1: polygons are drawm using outlines witk a thickness = aMinThicknessValue
887  * so shapes must take in account this outline thickness
888  *
889  * Note 2:
890  * Trapezoidal pads are not considered here because they are very special case
891  * and are used in microwave applications and they *DO NOT* have a thermal relief that
892  * change the shape by creating stubs and destroy their properties.
893  */
895  const D_PAD& aPad,
896  int aThermalGap,
897  int aCopperThickness,
898  int aMinThicknessValue,
899  int aCircleToSegmentsCount,
900  double aCorrectionFactor,
901  double aThermalRot )
902 {
903  wxPoint corner, corner_end;
904  wxPoint padShapePos = aPad.ShapePos(); // Note: for pad having a shape offset,
905  // the pad position is NOT the shape position
906  wxSize copper_thickness;
907 
908  double delta = 3600.0 / aCircleToSegmentsCount; // rot angle in 0.1 degree
909 
910  /* Keep in account the polygon outline thickness
911  * aThermalGap must be increased by aMinThicknessValue/2 because drawing external outline
912  * with a thickness of aMinThicknessValue will reduce gap by aMinThicknessValue/2
913  */
914  aThermalGap += aMinThicknessValue / 2;
915 
916  /* Keep in account the polygon outline thickness
917  * copper_thickness must be decreased by aMinThicknessValue because drawing outlines
918  * with a thickness of aMinThicknessValue will increase real thickness by aMinThicknessValue
919  */
920  aCopperThickness -= aMinThicknessValue;
921 
922  if( aCopperThickness < 0 )
923  aCopperThickness = 0;
924 
925  int dx = aPad.GetSize().x / 2;
926  int dy = aPad.GetSize().y / 2;
927 
928  copper_thickness.x = std::min( dx, aCopperThickness );
929  copper_thickness.y = std::min( dy, aCopperThickness );
930 
931  switch( aPad.GetShape() )
932  {
933  case PAD_SHAPE_CIRCLE: // Add 4 similar holes
934  {
935  /* we create 4 copper holes and put them in position 1, 2, 3 and 4
936  * here is the area of the rectangular pad + its thermal gap
937  * the 4 copper holes remove the copper in order to create the thermal gap
938  * 4 ------ 1
939  * | |
940  * | |
941  * | |
942  * | |
943  * 3 ------ 2
944  * holes 2, 3, 4 are the same as hole 1, rotated 90, 180, 270 deg
945  */
946 
947  // Build the hole pattern, for the hole in the X >0, Y > 0 plane:
948  // The pattern roughtly is a 90 deg arc pie
949  std::vector <wxPoint> corners_buffer;
950 
951  // Radius of outer arcs of the shape corrected for arc approximation by lines
952  int outer_radius = KiROUND( (dx + aThermalGap) * aCorrectionFactor );
953 
954  // Crosspoint of thermal spoke sides, the first point of polygon buffer
955  corners_buffer.push_back( wxPoint( copper_thickness.x / 2, copper_thickness.y / 2 ) );
956 
957  // Add an intermediate point on spoke sides, to allow a > 90 deg angle between side
958  // and first seg of arc approx
959  corner.x = copper_thickness.x / 2;
960  int y = outer_radius - (aThermalGap / 4);
961  corner.y = KiROUND( sqrt( ( (double) y * y - (double) corner.x * corner.x ) ) );
962 
963  if( aThermalRot != 0 )
964  corners_buffer.push_back( corner );
965 
966  // calculate the starting point of the outter arc
967  corner.x = copper_thickness.x / 2;
968 
969  corner.y = KiROUND( sqrt( ( (double) outer_radius * outer_radius ) -
970  ( (double) corner.x * corner.x ) ) );
971  RotatePoint( &corner, 90 ); // 9 degrees is the spoke fillet size
972 
973  // calculate the ending point of the outter arc
974  corner_end.x = corner.y;
975  corner_end.y = corner.x;
976 
977  // calculate intermediate points (y coordinate from corner.y to corner_end.y
978  while( (corner.y > corner_end.y) && (corner.x < corner_end.x) )
979  {
980  corners_buffer.push_back( corner );
981  RotatePoint( &corner, delta );
982  }
983 
984  corners_buffer.push_back( corner_end );
985 
986  /* add an intermediate point, to avoid angles < 90 deg between last arc approx line
987  * and radius line
988  */
989  corner.x = corners_buffer[1].y;
990  corner.y = corners_buffer[1].x;
991  corners_buffer.push_back( corner );
992 
993  // Now, add the 4 holes ( each is the pattern, rotated by 0, 90, 180 and 270 deg
994  // aThermalRot = 450 (45.0 degrees orientation) work fine.
995  double angle_pad = aPad.GetOrientation(); // Pad orientation
996  double th_angle = aThermalRot;
997 
998  for( unsigned ihole = 0; ihole < 4; ihole++ )
999  {
1000  aCornerBuffer.NewOutline();
1001 
1002  for( unsigned ii = 0; ii < corners_buffer.size(); ii++ )
1003  {
1004  corner = corners_buffer[ii];
1005  RotatePoint( &corner, th_angle + angle_pad ); // Rotate by segment angle and pad orientation
1006  corner += padShapePos;
1007  aCornerBuffer.Append( corner.x, corner.y );
1008  }
1009 
1010  th_angle += 900; // Note: th_angle in in 0.1 deg.
1011  }
1012  }
1013  break;
1014 
1015  case PAD_SHAPE_OVAL:
1016  {
1017  // Oval pad support along the lines of round and rectangular pads
1018  std::vector <wxPoint> corners_buffer; // Polygon buffer as vector
1019 
1020  dx = (aPad.GetSize().x / 2) + aThermalGap; // Cutout radius x
1021  dy = (aPad.GetSize().y / 2) + aThermalGap; // Cutout radius y
1022 
1023  wxPoint shape_offset;
1024 
1025  // We want to calculate an oval shape with dx > dy.
1026  // if this is not the case, exchange dx and dy, and rotate the shape 90 deg.
1027  int supp_angle = 0;
1028 
1029  if( dx < dy )
1030  {
1031  std::swap( dx, dy );
1032  supp_angle = 900;
1033  std::swap( copper_thickness.x, copper_thickness.y );
1034  }
1035 
1036  int deltasize = dx - dy; // = distance between shape position and the 2 demi-circle ends centre
1037  // here we have dx > dy
1038  // Radius of outer arcs of the shape:
1039  int outer_radius = dy; // The radius of the outer arc is radius end + aThermalGap
1040 
1041  // Some coordinate fiddling, depending on the shape offset direction
1042  shape_offset = wxPoint( deltasize, 0 );
1043 
1044  // Crosspoint of thermal spoke sides, the first point of polygon buffer
1045  corner.x = copper_thickness.x / 2;
1046  corner.y = copper_thickness.y / 2;
1047  corners_buffer.push_back( corner );
1048 
1049  // Arc start point calculation, the intersecting point of cutout arc and thermal spoke edge
1050  // If copper thickness is more than shape offset, we need to calculate arc intercept point.
1051  if( copper_thickness.x > deltasize )
1052  {
1053  corner.x = copper_thickness.x / 2;
1054  corner.y = KiROUND( sqrt( ( (double) outer_radius * outer_radius ) -
1055  ( (double) ( corner.x - delta ) * ( corner.x - deltasize ) ) ) );
1056  corner.x -= deltasize;
1057 
1058  /* creates an intermediate point, to have a > 90 deg angle
1059  * between the side and the first segment of arc approximation
1060  */
1061  wxPoint intpoint = corner;
1062  intpoint.y -= aThermalGap / 4;
1063  corners_buffer.push_back( intpoint + shape_offset );
1064  RotatePoint( &corner, 90 ); // 9 degrees of thermal fillet
1065  }
1066  else
1067  {
1068  corner.x = copper_thickness.x / 2;
1069  corner.y = outer_radius;
1070  corners_buffer.push_back( corner );
1071  }
1072 
1073  // Add an intermediate point on spoke sides, to allow a > 90 deg angle between side
1074  // and first seg of arc approx
1075  wxPoint last_corner;
1076  last_corner.y = copper_thickness.y / 2;
1077  int px = outer_radius - (aThermalGap / 4);
1078  last_corner.x =
1079  KiROUND( sqrt( ( ( (double) px * px ) - (double) last_corner.y * last_corner.y ) ) );
1080 
1081  // Arc stop point calculation, the intersecting point of cutout arc and thermal spoke edge
1082  corner_end.y = copper_thickness.y / 2;
1083  corner_end.x =
1084  KiROUND( sqrt( ( (double) outer_radius *
1085  outer_radius ) - ( (double) corner_end.y * corner_end.y ) ) );
1086  RotatePoint( &corner_end, -90 ); // 9 degrees of thermal fillet
1087 
1088  // calculate intermediate arc points till limit is reached
1089  while( (corner.y > corner_end.y) && (corner.x < corner_end.x) )
1090  {
1091  corners_buffer.push_back( corner + shape_offset );
1092  RotatePoint( &corner, delta );
1093  }
1094 
1095  //corners_buffer.push_back(corner + shape_offset); // TODO: about one mil geometry error forms somewhere.
1096  corners_buffer.push_back( corner_end + shape_offset );
1097  corners_buffer.push_back( last_corner + shape_offset ); // Enabling the line above shows intersection point.
1098 
1099  /* Create 2 holes, rotated by pad rotation.
1100  */
1101  double angle = aPad.GetOrientation() + supp_angle;
1102 
1103  for( int irect = 0; irect < 2; irect++ )
1104  {
1105  aCornerBuffer.NewOutline();
1106  for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
1107  {
1108  wxPoint cpos = corners_buffer[ic];
1109  RotatePoint( &cpos, angle );
1110  cpos += padShapePos;
1111  aCornerBuffer.Append( cpos.x, cpos.y );
1112  }
1113 
1114  angle = AddAngles( angle, 1800 ); // this is calculate hole 3
1115  }
1116 
1117  // Create holes, that are the mirrored from the previous holes
1118  for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
1119  {
1120  wxPoint swap = corners_buffer[ic];
1121  swap.x = -swap.x;
1122  corners_buffer[ic] = swap;
1123  }
1124 
1125  // Now add corner 4 and 2 (2 is the corner 4 rotated by 180 deg
1126  angle = aPad.GetOrientation() + supp_angle;
1127 
1128  for( int irect = 0; irect < 2; irect++ )
1129  {
1130  aCornerBuffer.NewOutline();
1131 
1132  for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
1133  {
1134  wxPoint cpos = corners_buffer[ic];
1135  RotatePoint( &cpos, angle );
1136  cpos += padShapePos;
1137  aCornerBuffer.Append( cpos.x, cpos.y );
1138  }
1139 
1140  angle = AddAngles( angle, 1800 );
1141  }
1142  }
1143  break;
1144 
1145  case PAD_SHAPE_ROUNDRECT: // thermal shape is the same for round rect and rect.
1146  case PAD_SHAPE_RECT:
1147  {
1148  /* we create 4 copper holes and put them in position 1, 2, 3 and 4
1149  * here is the area of the rectangular pad + its thermal gap
1150  * the 4 copper holes remove the copper in order to create the thermal gap
1151  * 4 ------ 1
1152  * | |
1153  * | |
1154  * | |
1155  * | |
1156  * 3 ------ 2
1157  * hole 3 is the same as hole 1, rotated 180 deg
1158  * hole 4 is the same as hole 2, rotated 180 deg and is the same as hole 1, mirrored
1159  */
1160 
1161  // First, create a rectangular hole for position 1 :
1162  // 2 ------- 3
1163  // | |
1164  // | |
1165  // | |
1166  // 1 -------4
1167 
1168  // Modified rectangles with one corner rounded. TODO: merging with oval thermals
1169  // and possibly round too.
1170 
1171  std::vector <wxPoint> corners_buffer; // Polygon buffer as vector
1172 
1173  dx = (aPad.GetSize().x / 2) + aThermalGap; // Cutout radius x
1174  dy = (aPad.GetSize().y / 2) + aThermalGap; // Cutout radius y
1175 
1176  // The first point of polygon buffer is left lower corner, second the crosspoint of
1177  // thermal spoke sides, the third is upper right corner and the rest are rounding
1178  // vertices going anticlockwise. Note the inveted Y-axis in CG.
1179  corners_buffer.push_back( wxPoint( -dx, -(aThermalGap / 4 + copper_thickness.y / 2) ) ); // Adds small miters to zone
1180  corners_buffer.push_back( wxPoint( -(dx - aThermalGap / 4), -copper_thickness.y / 2 ) ); // fill and spoke corner
1181  corners_buffer.push_back( wxPoint( -copper_thickness.x / 2, -copper_thickness.y / 2 ) );
1182  corners_buffer.push_back( wxPoint( -copper_thickness.x / 2, -(dy - aThermalGap / 4) ) );
1183  corners_buffer.push_back( wxPoint( -(aThermalGap / 4 + copper_thickness.x / 2), -dy ) );
1184 
1185  double angle = aPad.GetOrientation();
1186  int rounding_radius = KiROUND( aThermalGap * aCorrectionFactor ); // Corner rounding radius
1187 
1188  for( int i = 0; i < aCircleToSegmentsCount / 4 + 1; i++ )
1189  {
1190  wxPoint corner_position = wxPoint( 0, -rounding_radius );
1191 
1192  // Start at half increment offset
1193  RotatePoint( &corner_position, 1800.0 / aCircleToSegmentsCount );
1194  double angle_pg = i * delta;
1195 
1196  RotatePoint( &corner_position, angle_pg ); // Rounding vector rotation
1197  corner_position -= aPad.GetSize() / 2; // Rounding vector + Pad corner offset
1198 
1199  corners_buffer.push_back( wxPoint( corner_position.x, corner_position.y ) );
1200  }
1201 
1202  for( int irect = 0; irect < 2; irect++ )
1203  {
1204  aCornerBuffer.NewOutline();
1205 
1206  for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
1207  {
1208  wxPoint cpos = corners_buffer[ic];
1209  RotatePoint( &cpos, angle ); // Rotate according to module orientation
1210  cpos += padShapePos; // Shift origin to position
1211  aCornerBuffer.Append( cpos.x, cpos.y );
1212  }
1213 
1214  angle = AddAngles( angle, 1800 ); // this is calculate hole 3
1215  }
1216 
1217  // Create holes, that are the mirrored from the previous holes
1218  for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
1219  {
1220  wxPoint swap = corners_buffer[ic];
1221  swap.x = -swap.x;
1222  corners_buffer[ic] = swap;
1223  }
1224 
1225  // Now add corner 4 and 2 (2 is the corner 4 rotated by 180 deg
1226  for( int irect = 0; irect < 2; irect++ )
1227  {
1228  aCornerBuffer.NewOutline();
1229 
1230  for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
1231  {
1232  wxPoint cpos = corners_buffer[ic];
1233  RotatePoint( &cpos, angle );
1234  cpos += padShapePos;
1235  aCornerBuffer.Append( cpos.x, cpos.y );
1236  }
1237 
1238  angle = AddAngles( angle, 1800 );
1239  }
1240  }
1241  break;
1242 
1243  case PAD_SHAPE_TRAPEZOID:
1244  {
1245  SHAPE_POLY_SET antipad; // The full antipad area
1246 
1247  // We need a length to build the stubs of the thermal reliefs
1248  // the value is not very important. The pad bounding box gives a reasonable value
1249  EDA_RECT bbox = aPad.GetBoundingBox();
1250  int stub_len = std::max( bbox.GetWidth(), bbox.GetHeight() );
1251 
1252  aPad.TransformShapeWithClearanceToPolygon( antipad, aThermalGap,
1253  aCircleToSegmentsCount, aCorrectionFactor );
1254 
1255  SHAPE_POLY_SET stub; // A basic stub ( a rectangle)
1256  SHAPE_POLY_SET stubs; // the full stubs shape
1257 
1258 
1259  // We now substract the stubs (connections to the copper zone)
1260  //ClipperLib::Clipper clip_engine;
1261  // Prepare a clipping transform
1262  //clip_engine.AddPath( antipad, ClipperLib::ptSubject, true );
1263 
1264  // Create stubs and add them to clipper engine
1265  wxPoint stubBuffer[4];
1266  stubBuffer[0].x = stub_len;
1267  stubBuffer[0].y = copper_thickness.y/2;
1268  stubBuffer[1] = stubBuffer[0];
1269  stubBuffer[1].y = -copper_thickness.y/2;
1270  stubBuffer[2] = stubBuffer[1];
1271  stubBuffer[2].x = -stub_len;
1272  stubBuffer[3] = stubBuffer[2];
1273  stubBuffer[3].y = copper_thickness.y/2;
1274 
1275  stub.NewOutline();
1276 
1277  for( unsigned ii = 0; ii < DIM( stubBuffer ); ii++ )
1278  {
1279  wxPoint cpos = stubBuffer[ii];
1280  RotatePoint( &cpos, aPad.GetOrientation() );
1281  cpos += padShapePos;
1282  stub.Append( cpos.x, cpos.y );
1283  }
1284 
1285  stubs.Append( stub );
1286 
1287  stubBuffer[0].y = stub_len;
1288  stubBuffer[0].x = copper_thickness.x/2;
1289  stubBuffer[1] = stubBuffer[0];
1290  stubBuffer[1].x = -copper_thickness.x/2;
1291  stubBuffer[2] = stubBuffer[1];
1292  stubBuffer[2].y = -stub_len;
1293  stubBuffer[3] = stubBuffer[2];
1294  stubBuffer[3].x = copper_thickness.x/2;
1295 
1296  stub.RemoveAllContours();
1297  stub.NewOutline();
1298 
1299  for( unsigned ii = 0; ii < DIM( stubBuffer ); ii++ )
1300  {
1301  wxPoint cpos = stubBuffer[ii];
1302  RotatePoint( &cpos, aPad.GetOrientation() );
1303  cpos += padShapePos;
1304  stub.Append( cpos.x, cpos.y );
1305  }
1306 
1307  stubs.Append( stub );
1309 
1310  antipad.BooleanSubtract( stubs, SHAPE_POLY_SET::PM_FAST );
1311  aCornerBuffer.Append( antipad );
1312 
1313  break;
1314  }
1315 
1316  default:
1317  ;
1318  }
1319 }
1320 
1322  int aClearanceValue,
1323  int aCircleToSegmentsCount,
1324  double aCorrectionFactor ) const
1325 {
1326  aCornerBuffer = m_FilledPolysList;
1328 }
void TransformRoundedEndsSegmentToPolygon(SHAPE_POLY_SET &aCornerBuffer, wxPoint aStart, wxPoint aEnd, int aCircleToSegmentsCount, int aWidth)
Function TransformRoundedEndsSegmentToPolygon convert a segment with rounded ends to a polygon Conver...
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:130
#define DIM(x)
of elements in an array
Definition: macros.h:98
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
double GetDrawRotation() const
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:405
TEXTE_PCB class definition.
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
bool IsItalic() const
Definition: eda_text.h:168
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:65
static void addTextSegmToPoly(int x0, int y0, int xf, int yf, void *aData)
Implementation of conversion functions that require both schematic and board internal units...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void TransformCircleToPolygon(SHAPE_POLY_SET &aCornerBuffer, wxPoint aCenter, int aRadius, int aCircleToSegmentsCount)
Function TransformCircleToPolygon convert a circle to a polygon, using multiple straight lines...
int PointCount() const
Function PointCount()
void GetPoly(std::vector< wxPoint > &aOutput, int aMinSegLen=0)
Converts Bezier curve to a polygon.
void TransformGraphicShapesWithClearanceToPolygonSet(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aCornerBuffer, int aInflateValue, int aCircleToSegmentsCount, double aCorrectionFactor, int aCircleToSegmentsCountForTexts=0, bool aIncludeText=true) const
function TransformGraphicShapesWithClearanceToPolygonSet generate shapes of graphic items (outlines) ...
Class BOARD to handle a board.
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 color
Definition: DXF_plotter.cpp:62
polygon (not yet used for tracks, but could be in microwave apps)
MODULE * Next() const
Definition: class_module.h:123
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
int GetHeight() const
Definition: eda_rect.h:118
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
void CreateThermalReliefPadPolygon(SHAPE_POLY_SET &aCornerBuffer, const D_PAD &aPad, int aThermalGap, int aCopperThickness, int aMinThicknessValue, int aCircleToSegmentsCount, double aCorrectionFactor, double aThermalRot)
Function CreateThermalReliefPadPolygon Add holes around a pad to create a thermal relief copper thick...
Classes to handle copper zones.
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:388
usual segment : line with rounded ends
EDA_ITEM * Next() const
Definition: base_struct.h:206
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
void TransformOvalClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, wxPoint aStart, wxPoint aEnd, int aWidth, int aCircleToSegmentsCount, double aCorrectionFactor)
convert a oblong shape to a polygon, using multiple segments It is similar to TransformRoundedEndsSeg...
const wxSize & GetDrillSize() const
Definition: class_pad.h:275
virtual wxString GetShownText() const override
Returns the string actually shown after processing of the base text.
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:216
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
static const int delta[8][2]
Definition: solve.cpp:112
void DrawGraphicText(EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, COLOR4D aColor, 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)
Function DrawGraphicText Draw a graphic text (like module texts)
Functions relatives to tracks, vias and segments used to fill zones.
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:152
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: common.cpp:86
void TransformSolidAreasShapesToPolygonSet(SHAPE_POLY_SET &aCornerBuffer, int aCircleToSegmentsCount, double aCorrectionFactor) const
Function TransformSolidAreasShapesToPolygonSet Convert solid areas full shapes to polygon set (the fu...
BOARD_ITEM * Next() const
PCB_LAYER_ID
A quick note on layer IDs:
void TransformShapeWithClearanceToPolygonSet(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const
Function TransformShapeWithClearanceToPolygonSet Convert the text shape to a set of polygons (one by ...
void Inflate(int aFactor, int aCircleSegmentsCount)
Performs outline inflation/deflation, using round corners.
void TransformBoundingBoxWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue) const
Function TransformBoundingBoxWithClearanceToPolygon Convert the text bounding box to a rectangular po...
T AddAngles(T a1, T2 a2)
Add two angles (keeping the result normalized). T2 is here.
Definition: trigo.h:288
double GetOrientation() const
Definition: class_module.h:189
Class SHAPE_POLY_SET.
int GetSolderMaskMargin() const
Function GetSolderMaskMargin.
Definition: class_pad.cpp:585
TSEGM_2_POLY_PRMS prms
Arcs (with rounded ends)
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const override
Function TransformShapeWithClearanceToPolygon Convert the track shape to a closed polygon Used in fil...
D_PAD * Next() const
Definition: class_pad.h:160
const wxSize & GetSize() const
Definition: class_pad.h:269
void SetSize(const wxSize &aSize)
Definition: class_pad.h:268
void ConvertBrdLayerToPolygonalContours(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aOutlines)
Function ConvertBrdLayerToPolygonalContours Build a set of polygons which are the outlines of copper ...
a few functions useful in geometry calculations.
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
void TransformGraphicTextWithClearanceToPolygonSet(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aCornerBuffer, int aInflateValue, int aCircleToSegmentsCount, double aCorrectionFactor, int aCircleToSegmentsCountForTexts=0) const
TransformGraphicTextWithClearanceToPolygonSet This function is the same as TransformGraphicShapesWith...
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const override
Function TransformShapeWithClearanceToPolygon Convert the pad shape to a closed polygon Used in filli...
int GetBottom() const
Definition: eda_rect.h:122
Bezier Curve.
int GetRight() const
Definition: eda_rect.h:119
void TransformPadsShapesWithClearanceToPolygon(PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aCornerBuffer, int aInflateValue, int aCircleToSegmentsCount, double aCorrectionFactor, bool aSkipNPTHPadsWihNoCopper=false) const
function TransformPadsShapesWithClearanceToPolygon generate pads shapes on layer aLayer as polygons...
int NewOutline()
Creates a new empty polygon in the set and returns its index
Pad object description.
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const override
Function TransformShapeWithClearanceToPolygon Convert the track shape to a closed polygon Used in fil...
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
void TransformRingToPolygon(SHAPE_POLY_SET &aCornerBuffer, wxPoint aCentre, int aRadius, int aCircleToSegmentsCount, int aWidth)
Function TransformRingToPolygon Creates a polygon from a ring Convert arcs to multiple straight segme...
Bezier curves to polygon converter.
Definition: bezier_curves.h:35
void TransformArcToPolygon(SHAPE_POLY_SET &aCornerBuffer, wxPoint aCentre, wxPoint aStart, double aArcAngle, int aCircleToSegmentsCount, int aWidth)
Function TransformArcToPolygon Creates a polygon from an Arc Convert arcs to multiple straight segmen...
TRACK * Next() const
Definition: class_track.h:99
Class to handle a graphic segment.
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
#define max(a, b)
Definition: auxiliary.h:86
bool IsMirrored() const
Definition: eda_text.h:177
Class SHAPE_LINE_CHAIN.
bool IsVisible() const
Definition: eda_text.h:174
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
size_t i
Definition: json11.cpp:597
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
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
wxSize GetSolderPasteMargin() const
Function GetSolderPasteMargin.
Definition: class_pad.cpp:628
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
int GetWidth() const
Definition: eda_rect.h:117
void BuildPadShapePolygon(SHAPE_POLY_SET &aCornerBuffer, wxSize aInflateValue, int aSegmentsPerCircle, double aCorrectionFactor) const
Function BuildPadShapePolygon Build the Corner list of the polygonal shape, depending on shape...
wxPoint ShapePos() const
Definition: class_pad.cpp:508
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset difference For aFastMode meaning, see function booleanOp ...
Module description (excepted pads)
Definition: colors.h:45
const wxSize & GetTextSize() const
Definition: eda_text.h:213
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const override
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:654
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
bool BuildPadDrillShapePolygon(SHAPE_POLY_SET &aCornerBuffer, int aInflateValue, int aSegmentsPerCircle) const
Function BuildPadDrillShapePolygon Build the Corner list of the polygonal drill shape, depending on shape pad hole and orientation.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
const wxPoint GetPosition() const override
Definition: class_module.h:184
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: class_pad.cpp:207
const wxPoint & GetOffset() const
Definition: class_pad.h:278
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
#define min(a, b)
Definition: auxiliary.h:85
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
double GetCircletoPolyCorrectionFactor(int aSegCountforCircle)