KiCad PCB EDA Suite
Loading...
Searching...
No Matches
create_3Dgraphic_brd_items.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) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2023 CERN
6 * Copyright The 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, see <https://www.gnu.org/licenses/>.
20 */
21
27
32#include <board_adapter.h>
33#include <board.h>
34#include <footprint.h>
35#include <pad.h>
36#include <pcb_text.h>
37#include <pcb_textbox.h>
38#include <pcb_table.h>
39#include <pcb_track.h>
40#include <pcb_painter.h> // for PCB_RENDER_SETTINGS
41#include <zone.h>
43#include <trigo.h>
47#include <geometry/roundrect.h>
48#include <geometry/shape_rect.h>
51#include <bezier_curves.h>
52#include <utility>
53#include <vector>
54#include <wx/log.h>
55#include <macros.h>
56#include <callback_gal.h>
57#include <line_ending.h>
58#include <pcb_barcode.h>
59
60
61#define TO_3DU( x ) ( ( x ) * m_biuTo3Dunits )
62
63#define TO_SFVEC2F( vec ) SFVEC2F( TO_3DU( vec.x ), TO_3DU( -vec.y ) )
64
65
66void addFILLED_CIRCLE_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aCenter, float aRadius,
67 const BOARD_ITEM& aBoardItem )
68{
69 if( aRadius > 0.0f )
70 aContainer->Add( new FILLED_CIRCLE_2D( aCenter, aRadius, aBoardItem ) );
71}
72
73
74void addRING_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aCenter, float aInnerRadius,
75 float aOuterRadius, const BOARD_ITEM& aBoardItem )
76{
77 if( aOuterRadius > aInnerRadius && aInnerRadius > 0.0f )
78 aContainer->Add( new RING_2D( aCenter, aInnerRadius, aOuterRadius, aBoardItem ) );
79}
80
81
82void addROUND_SEGMENT_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aStart, const SFVEC2F& aEnd,
83 float aWidth, const BOARD_ITEM& aBoardItem )
84{
85 if( Is_segment_a_circle( aStart, aEnd ) )
86 {
87 // Cannot add segments that have the same start and end point
88 addFILLED_CIRCLE_2D( aContainer, aStart, aWidth / 2, aBoardItem );
89 return;
90 }
91
92 if( aWidth > 0.0f )
93 aContainer->Add( new ROUND_SEGMENT_2D( aStart, aEnd, aWidth, aBoardItem ) );
94}
95
96
97void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContainer, const BOARD_ITEM* aOwner )
98{
100 TEXT_ATTRIBUTES attrs = aText->GetAttributes();
101 float penWidth_3DU = TO_3DU( aText->GetEffectiveTextPenWidth() );
102 KIFONT::FONT* font = aText->GetFont();
103 wxString shownText = aText->GetShownText( FOR_CANVAS );
104
105 if( !font )
106 font = KIFONT::FONT::GetFont( wxEmptyString, aText->IsBold(), aText->IsItalic() );
107
108 if( aOwner && aOwner->IsKnockout() )
109 {
110 SHAPE_POLY_SET finalPoly;
111
112 if( const PCB_TEXTBOX* pcbTextBox = dynamic_cast<const PCB_TEXTBOX*>( aOwner ) )
113 pcbTextBox->TransformTextToPolySet( finalPoly, 0, aOwner->GetMaxError(), ERROR_INSIDE );
114 else if( const PCB_TEXT* pcbText = dynamic_cast<const PCB_TEXT*>( aOwner ) )
115 pcbText->TransformTextToPolySet( finalPoly, 0, aOwner->GetMaxError(), ERROR_INSIDE );
116
117 // Do not call finalPoly.Fracture() here: ConvertPolygonToTriangles() call it
118 // if needed, and Fracture() called twice can create bad results and is useless
119 ConvertPolygonToTriangles( finalPoly, *aContainer, m_biuTo3Dunits, *aOwner );
120 }
121 else
122 {
123 CALLBACK_GAL callback_gal( empty_opts,
124 // Stroke callback
125 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
126 {
127 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( aPt1 ), TO_SFVEC2F( aPt2 ),
128 penWidth_3DU, *aOwner );
129 },
130 // Triangulation callback
131 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
132 {
133 aContainer->Add( new TRIANGLE_2D( TO_SFVEC2F( aPt1 ), TO_SFVEC2F( aPt2 ),
134 TO_SFVEC2F( aPt3 ), *aOwner ) );
135 } );
136
137 attrs.m_Angle = aText->GetDrawRotation();
138
139 if( auto* cache = aText->GetRenderCache( font, shownText ) )
140 {
141 callback_gal.DrawGlyphs( *cache );
142 }
143 else
144 {
145 font->Draw( &callback_gal, shownText, aText->GetDrawPos(), attrs,
146 aOwner->GetFontMetrics() );
147 }
148 }
149}
150
151
152void BOARD_ADAPTER::addBarCode( const PCB_BARCODE* aBarCode, CONTAINER_2D_BASE* aDstContainer,
153 const BOARD_ITEM* aOwner )
154{
155 SHAPE_POLY_SET shape;
156 aBarCode->TransformShapeToPolySet( shape, aBarCode->GetLayer(), 0, 0, ERROR_INSIDE );
157 shape.Simplify();
158
159 ConvertPolygonToTriangles( shape, *aDstContainer, m_biuTo3Dunits, *aOwner );
160}
161
162
164 const BOARD_ITEM* aOwner )
165{
166 addText( aDimension, aContainer, aDimension );
167
168 const int linewidth = aDimension->GetLineThickness();
169
170 for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
171 {
172 switch( shape->Type() )
173 {
174 case SH_SEGMENT:
175 {
176 const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
177
178 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( seg.A ), TO_SFVEC2F( seg.B ),
179 TO_3DU( linewidth ), *aOwner );
180 break;
181 }
182
183 case SH_CIRCLE:
184 {
185 int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
186 float innerR3DU = TO_3DU( radius ) - TO_3DU( aDimension->GetLineThickness() ) / 2.0f;
187 float outerR3DU = TO_3DU( radius ) + TO_3DU( aDimension->GetLineThickness() ) / 2.0f;
188
189 addRING_2D( aContainer, TO_SFVEC2F( shape->Centre() ), innerR3DU, outerR3DU, *aOwner );
190
191 break;
192 }
193
194 default:
195 break;
196 }
197 }
198}
199
200
202 PCB_LAYER_ID aLayerId,
203 const std::bitset<LAYER_3D_END>& aFlags )
204{
206
207 for( PCB_FIELD* field : aFootprint->GetFields() )
208 {
209 if( !aFlags.test( LAYER_FP_TEXT ) )
210 continue;
211
212 wxCHECK2( field, continue );
213
214 if( field->IsReference() && !aFlags.test( LAYER_FP_REFERENCES ) )
215 continue;
216
217 if( field->IsValue() && !aFlags.test( LAYER_FP_VALUES ) )
218 continue;
219
220 if( field->GetLayer() == aLayerId && field->IsVisible() )
221 addText( field, aContainer, field );
222 }
223
224 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
225 {
226 switch( item->Type() )
227 {
228 case PCB_TEXT_T:
229 {
230 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
231
232 if( !aFlags.test( LAYER_FP_TEXT ) )
233 continue;
234
235 if( text->GetText() == wxT( "${REFERENCE}" ) && !aFlags.test( LAYER_FP_REFERENCES ) )
236 continue;
237
238 if( text->GetText() == wxT( "${VALUE}" ) && !aFlags.test( LAYER_FP_VALUES ) )
239 continue;
240
241 if( text->GetLayer() == aLayerId )
242 addText( text, aContainer, text );
243
244 break;
245 }
246
247 case PCB_TEXTBOX_T:
248 {
249 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
250
251 if( textbox->GetLayer() == aLayerId )
252 addShape( textbox, aContainer, textbox );
253
254 break;
255 }
256
257 case PCB_TABLE_T:
258 {
259 PCB_TABLE* table = static_cast<PCB_TABLE*>( item );
260
261 if( table->GetLayer() == aLayerId )
262 addTable( table, aContainer, aFootprint );
263
264 break;
265 }
266
268 case PCB_DIM_CENTER_T:
270 case PCB_DIM_RADIAL_T:
271 case PCB_DIM_LEADER_T:
272 {
273 PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( item );
274
275 if( dimension->GetLayer() == aLayerId )
276 addShape( dimension, aContainer, aFootprint );
277
278 break;
279 }
280
281 case PCB_SHAPE_T:
282 {
283 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
284
285 if( shape->IsOnLayer( aLayerId ) )
286 addShape( shape, aContainer, aFootprint, aLayerId );
287
288 break;
289 }
290
291 case PCB_BARCODE_T:
292 {
293 PCB_BARCODE* barcode = static_cast<PCB_BARCODE*>( item );
294
295 if( barcode->GetLayer() == aLayerId )
296 addBarCode( barcode, aContainer, aFootprint );
297
298 break;
299 }
300
301 default:
302 break;
303 }
304 }
305}
306
307
309 PCB_LAYER_ID aLayer, int aMargin, const BOARD_ITEM* aOwner )
310{
311 // aTrack can be an object created on the stack; the 2D objects keep a pointer to the
312 // owner passed here.
313 const BOARD_ITEM& owner = aOwner ? *aOwner : *aTrack;
314
315 SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() );
316 SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() );
317
318 switch( aTrack->Type() )
319 {
320 case PCB_VIA_T:
321 {
322 const PCB_VIA* via = static_cast<const PCB_VIA*>( aTrack );
323 float width3DU = TO_3DU( via->GetWidth( aLayer ) + aMargin * 2 );
324
325 addFILLED_CIRCLE_2D( aDstContainer, start3DU, width3DU / 2.0, owner );
326 break;
327 }
328
329 case PCB_ARC_T:
330 {
331 const PCB_ARC* arc = static_cast<const PCB_ARC*>( aTrack );
332
333 if( arc->IsDegenerated() )
334 {
335 // Draw this very small arc like a track segment (a PCB_TRACE_T). The stand-in
336 // track is created on the stack, so attribute the geometry to the arc itself.
337 PCB_TRACK track( arc->GetParent() );
338 track.SetStart( arc->GetStart() );
339 track.SetEnd( arc->GetEnd() );
340 track.SetWidth( arc->GetWidth() );
341 track.SetLayer( arc->GetLayer() );
342
343 createTrackWithMargin( &track, aDstContainer, aLayer, aMargin, arc );
344 return;
345 }
346
347 VECTOR2I center( arc->GetCenter() );
348 EDA_ANGLE arc_angle = arc->GetAngle();
349 double radius = arc->GetRadius();
350 int arcsegcount = GetArcToSegmentCount( KiROUND( radius ), arc->GetMaxError(), arc_angle );
351 int circlesegcount;
352
353 // Avoid arcs that cannot be drawn
354 if( radius < std::numeric_limits<double>::min() || arc_angle.IsZero() )
355 break;
356
357 // We need a circle to segment count. However, the arc angle can be small, and the
358 // radius very big. so we calculate a reasonable value for circlesegcount.
359 if( arcsegcount <= 1 ) // The arc will be approximated by a segment
360 {
361 circlesegcount = 1;
362 }
363 else
364 {
365 circlesegcount = KiROUND( arcsegcount * 360.0 / std::abs( arc_angle.AsDegrees() ) );
366 circlesegcount = std::clamp( circlesegcount, 1, 128 );
367 }
368
369 createArcSegments( center, arc->GetStart(), arc_angle, circlesegcount,
370 arc->GetWidth() + aMargin * 2, aDstContainer, *arc );
371 break;
372 }
373
374 case PCB_TRACE_T: // Track is a usual straight segment
375 {
376 float width3DU = TO_3DU( aTrack->GetWidth() + aMargin * 2 );
377 addROUND_SEGMENT_2D( aDstContainer, start3DU, end3DU, width3DU, owner );
378 break;
379 }
380
381 default:
382 break;
383 }
384}
385
386
388 PCB_LAYER_ID aLayer, const VECTOR2I& aMargin ) const
389{
390 SHAPE_POLY_SET poly;
391 VECTOR2I clearance = aMargin;
392
393 // Our shape-based builder can't handle negative or differing x:y clearance values (the
394 // former are common for solder paste while the later get generated when a relative paste
395 // margin is used with an oblong pad). So we apply this huge hack and fake a larger pad to
396 // run the general-purpose polygon builder on.
397 // Of course being a hack it falls down when dealing with custom shape pads (where the size
398 // is only the size of the anchor), so for those we punt and just use aMargin.x.
399
400 if( ( clearance.x < 0 || clearance.x != clearance.y ) && aPad->GetShape( aLayer ) != PAD_SHAPE::CUSTOM )
401 {
402 VECTOR2I dummySize = VECTOR2I( aPad->GetSize( aLayer ) ) + clearance + clearance;
403
404 if( dummySize.x <= 0 || dummySize.y <= 0 )
405 return;
406
407 PAD dummy( *aPad );
408 dummy.SetSize( aLayer, VECTOR2I( dummySize.x, dummySize.y ) );
409 dummy.TransformShapeToPolygon( poly, aLayer, 0, aPad->GetMaxError(), ERROR_INSIDE );
410 clearance = { 0, 0 };
411 }
412 else if( aPad->GetShape( aLayer ) == PAD_SHAPE::CUSTOM )
413 {
414 // A custom pad can have many complex subshape items. To avoid issues, use its
415 // final polygon shape, not its basic shape set. One cannot apply the clearance
416 // to each subshape: it does no work
417 aPad->TransformShapeToPolygon( poly, aLayer, 0, aPad->GetMaxError() );
418 }
419 else
420 {
421 auto padShapes = std::static_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape( aLayer ) );
422
423 for( const SHAPE* shape : padShapes->Shapes() )
424 {
425 switch( shape->Type() )
426 {
427 case SH_SEGMENT:
428 {
429 const SHAPE_SEGMENT* seg = static_cast<const SHAPE_SEGMENT*>( shape );
430
431 addROUND_SEGMENT_2D( aContainer,
432 TO_SFVEC2F( seg->GetSeg().A ),
433 TO_SFVEC2F( seg->GetSeg().B ),
434 TO_3DU( seg->GetWidth() + clearance.x * 2 ),
435 *aPad );
436 break;
437 }
438
439 case SH_CIRCLE:
440 {
441 const SHAPE_CIRCLE* circle = static_cast<const SHAPE_CIRCLE*>( shape );
442
443 addFILLED_CIRCLE_2D( aContainer,
444 TO_SFVEC2F( circle->GetCenter() ),
445 TO_3DU( circle->GetRadius() + clearance.x ),
446 *aPad );
447 break;
448 }
449
450 case SH_RECT:
451 {
452 const SHAPE_RECT* rect = static_cast<const SHAPE_RECT*>( shape );
453
454 poly.NewOutline();
455 poly.Append( rect->GetPosition() );
456 poly.Append( rect->GetPosition().x + rect->GetSize().x, rect->GetPosition().y );
457 poly.Append( rect->GetPosition() + rect->GetSize() );
458 poly.Append( rect->GetPosition().x, rect->GetPosition().y + rect->GetSize().y );
459 break;
460 }
461
462 case SH_SIMPLE:
463 poly.AddOutline( static_cast<const SHAPE_SIMPLE*>( shape )->Vertices() );
464 break;
465
466 case SH_POLY_SET:
467 poly.Append( *static_cast<const SHAPE_POLY_SET*>( shape ) );
468 break;
469
470 case SH_ARC:
471 {
472 const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( shape );
474
475 for( int i = 0; i < l.SegmentCount(); i++ )
476 {
477 SHAPE_SEGMENT seg( l.Segment( i ).A, l.Segment( i ).B, arc->GetWidth() );
478
479 addROUND_SEGMENT_2D( aContainer,
480 TO_SFVEC2F( seg.GetSeg().A ),
481 TO_SFVEC2F( seg.GetSeg().B ),
482 TO_3DU( arc->GetWidth() + clearance.x * 2 ),
483 *aPad );
484 }
485
486 break;
487 }
488
489 case SH_ELLIPSE:
490 {
491 const SHAPE_ELLIPSE* ellipse = static_cast<const SHAPE_ELLIPSE*>( shape );
492 SHAPE_LINE_CHAIN l = ellipse->ConvertToPolyline( aPad->GetMaxError() );
493 const int width = ellipse->GetWidth();
494
495 for( int i = 0; i < l.SegmentCount(); i++ )
496 {
497 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( l.Segment( i ).A ), TO_SFVEC2F( l.Segment( i ).B ),
498 TO_3DU( width + clearance.x * 2 ), *aPad );
499 }
500
501 break;
502 }
503
504 default:
505 UNIMPLEMENTED_FOR( SHAPE_TYPE_asString( shape->Type() ) );
506 break;
507 }
508 }
509 }
510
511 if( !poly.IsEmpty() )
512 {
513 if( clearance.x )
515
516 // Add the PAD polygon
517 ConvertPolygonToTriangles( poly, *aContainer, m_biuTo3Dunits, *aPad );
518 }
519}
520
521
523 int aInflateValue )
524{
525 if( !aPad->HasHole() )
526 {
527 wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::createPadHole pad has no hole" ) );
528 return;
529 }
530
531 std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
532
533 addROUND_SEGMENT_2D( aDstContainer,
534 TO_SFVEC2F( slot->GetSeg().A ),
535 TO_SFVEC2F( slot->GetSeg().B ),
536 TO_3DU( slot->GetWidth() + aInflateValue * 2 ),
537 *aPad );
538}
539
540
541void BOARD_ADAPTER::addPads( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aContainer,
542 PCB_LAYER_ID aLayerId )
543{
544 for( PAD* pad : aFootprint->Pads() )
545 {
546 if( !pad->IsOnLayer( aLayerId ) )
547 continue;
548
549 if( IsCopperLayer( aLayerId ) )
550 {
551 // Skip pad annulus when there isn't one (note: this is more discerning than
552 // pad->IsOnLayer(), which doesn't check for NPTH pads with holes that consume
553 // the entire pad).
554 if( !pad->IsOnCopperLayer() )
555 continue;
556
557 // Skip pad annulus when not connected on this layer (if removing is enabled)
558 if( !pad->FlashLayer( aLayerId ) )
559 continue;
560 }
561
562 VECTOR2I margin( 0, 0 );
563
564 switch( aLayerId )
565 {
566 case F_Mask:
567 case B_Mask:
568 margin.x += pad->GetSolderMaskExpansion( aLayerId );
569 margin.y += pad->GetSolderMaskExpansion( aLayerId );
570 break;
571
572 case F_Paste:
573 case B_Paste:
574 margin += pad->GetSolderPasteMargin( aLayerId );
575 break;
576
577 default:
578 break;
579 }
580
581 createPadWithMargin( pad, aContainer, aLayerId, margin );
582 }
583}
584
585
586// based on TransformArcToPolygon function from
587// common/convert_basic_shapes_to_polygon.cpp
588void BOARD_ADAPTER::createArcSegments( const VECTOR2I& aCentre, const VECTOR2I& aStart,
589 const EDA_ANGLE& aArcAngle, int aCircleToSegmentsCount,
590 int aWidth, CONTAINER_2D_BASE* aContainer,
591 const BOARD_ITEM& aOwner )
592{
593 // Don't attempt to render degenerate shapes
594 if( aWidth == 0 )
595 return;
596
597 VECTOR2I arc_start, arc_end;
598 EDA_ANGLE arcAngle( aArcAngle );
599 EDA_ANGLE delta = ANGLE_360 / aCircleToSegmentsCount; // rotate angle
600
601 arc_end = arc_start = aStart;
602
603 if( arcAngle != ANGLE_360 )
604 RotatePoint( arc_end, aCentre, -arcAngle );
605
606 if( arcAngle < ANGLE_0 )
607 {
608 std::swap( arc_start, arc_end );
609 arcAngle = -arcAngle;
610 }
611
612 // Compute the ends of segments and creates poly
613 VECTOR2I curr_end = arc_start;
614 VECTOR2I curr_start = arc_start;
615
616 for( EDA_ANGLE ii = delta; ii < arcAngle; ii += delta )
617 {
618 curr_end = arc_start;
619 RotatePoint( curr_end, aCentre, -ii );
620
621 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( curr_start ), TO_SFVEC2F( curr_end ),
622 TO_3DU( aWidth ), aOwner );
623
624 curr_start = curr_end;
625 }
626
627 if( curr_end != arc_end )
628 {
629 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( curr_end ), TO_SFVEC2F( arc_end ),
630 TO_3DU( aWidth ), aOwner );
631 }
632}
633
634
635void BOARD_ADAPTER::addShape( const PCB_SHAPE* aShape, CONTAINER_2D_BASE* aContainer,
636 const BOARD_ITEM* aOwner, PCB_LAYER_ID aLayer )
637{
638 LINE_STYLE lineStyle = aShape->GetStroke().GetLineStyle();
639 int linewidth = aShape->GetWidth();
640 int margin = 0;
641 bool isSolidFill = aShape->IsSolidFill();
642 bool isHatchedFill = aShape->IsHatchedFill();
643
644 if( IsSolderMaskLayer( aLayer )
645 && aShape->HasSolderMask()
646 && ( aShape->IsOnLayer( F_Cu ) || aShape->IsOnLayer( B_Cu ) ) )
647 {
648 margin = aShape->GetSolderMaskExpansion();
649 linewidth += margin * 2;
650 lineStyle = LINE_STYLE::SOLID;
651
652 if( isHatchedFill )
653 {
654 isSolidFill = true;
655 isHatchedFill = false;
656 }
657 }
658
659 float linewidth3DU = TO_3DU( linewidth );
660
661 if( lineStyle <= LINE_STYLE::FIRST_TYPE || isSolidFill )
662 {
663 switch( aShape->GetShape() )
664 {
665 case SHAPE_T::CIRCLE:
666 {
667 SFVEC2F center3DU = TO_SFVEC2F( aShape->GetCenter() );
668 float innerR3DU = TO_3DU( aShape->GetRadius() ) - linewidth3DU / 2.0;
669 float outerR3DU = TO_3DU( aShape->GetRadius() ) + linewidth3DU / 2.0;
670
671 if( isSolidFill || innerR3DU <= 0.0 )
672 {
673 // For a filled circle with a line style not a simple line, ignore line width
674 // the outline will be drawn later
675 if( lineStyle > LINE_STYLE::FIRST_TYPE )
676 addFILLED_CIRCLE_2D( aContainer, center3DU, TO_3DU( aShape->GetRadius() ), *aOwner );
677 else
678 addFILLED_CIRCLE_2D( aContainer, center3DU, outerR3DU, *aOwner );
679 }
680 else
681 addRING_2D( aContainer, center3DU, innerR3DU, outerR3DU, *aOwner );
682
683 break;
684 }
685
687 if( isSolidFill )
688 {
689 SHAPE_POLY_SET polyList;
690
691 // For a filled rect with a line style not a simple line, ignore line width
692 // the outline will be drawn later
693 bool ignoreLineWidth = lineStyle > LINE_STYLE::FIRST_TYPE;
694
695 aShape->TransformShapeToPolygon( polyList, UNDEFINED_LAYER, 0, aShape->GetMaxError(),
696 ERROR_INSIDE, ignoreLineWidth );
697
698 polyList.Simplify();
699
700 if( margin != 0 )
701 {
702 polyList.Inflate( margin, CORNER_STRATEGY::ROUND_ALL_CORNERS, aShape->GetMaxError() );
703 }
704
705 ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aOwner );
706 }
707 else
708 {
709 if( aShape->GetCornerRadius() > 0 )
710 {
711 ROUNDRECT rr( SHAPE_RECT( aShape->GetPosition(),
712 aShape->GetRectangleWidth(),
713 aShape->GetRectangleHeight() ),
714 aShape->GetCornerRadius() );
715 SHAPE_POLY_SET poly;
716 rr.TransformToPolygon( poly, aShape->GetMaxError() );
717 SHAPE_LINE_CHAIN& r_outline = poly.Outline( 0 );
718 r_outline.SetClosed( true );
719
720 for( int ii = 0; ii < r_outline.PointCount(); ii++ )
721 {
722 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( r_outline.CPoint( ii ) ),
723 TO_SFVEC2F( r_outline.CPoint( ii+1 ) ),
724 linewidth3DU, *aOwner );
725 }
726
727 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( r_outline.CLastPoint() ),
728 TO_SFVEC2F( r_outline.CPoint( 0 ) ), linewidth3DU, *aOwner );
729 }
730 else
731 {
732 std::vector<VECTOR2I> pts = aShape->GetRectCorners();
733
734 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[0] ), TO_SFVEC2F( pts[1] ),
735 linewidth3DU, *aOwner );
736 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[1] ), TO_SFVEC2F( pts[2] ),
737 linewidth3DU, *aOwner );
738 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[2] ), TO_SFVEC2F( pts[3] ),
739 linewidth3DU, *aOwner );
740 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[3] ), TO_SFVEC2F( pts[0] ),
741 linewidth3DU, *aOwner );
742 }
743 }
744 break;
745
746 case SHAPE_T::ARC:
747 {
748 unsigned int segCount = GetCircleSegmentCount( aShape->GetBoundingBox().GetSizeMax() );
749
750 EDA_ANGLE origStartAngle;
751 EDA_ANGLE endAngle;
752 aShape->CalcArcAngles( origStartAngle, endAngle );
753
754 EDA_ANGLE startAngle = origStartAngle;
755 EDA_ANGLE arcAngle = endAngle - startAngle;
756
757 if( aShape->ShortenArcForEndings( startAngle, arcAngle, aShape->GetRadius(), linewidth ) )
758 {
759 // Rotate the original start point by the angular offset from shortening.
760 VECTOR2I arcStart = aShape->GetStart();
761 RotatePoint( arcStart, aShape->GetCenter(), origStartAngle - startAngle );
762
763 createArcSegments( aShape->GetCenter(), arcStart, arcAngle, segCount, linewidth, aContainer,
764 *aOwner );
765 }
766
767 break;
768 }
769
770 case SHAPE_T::SEGMENT:
771 {
772 VECTOR2I segStart = aShape->GetStart();
773 VECTOR2I segEnd = aShape->GetEnd();
774
775 if( EDA_SHAPE::ShortenSegmentForEndings( segStart, segEnd, aShape->GetStartEnding(),
776 aShape->GetEndEnding(), linewidth ) )
777 {
778 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( segStart ), TO_SFVEC2F( segEnd ), linewidth3DU,
779 *aOwner );
780 }
781
782 break;
783 }
784
785 case SHAPE_T::BEZIER:
786 {
787 std::vector<VECTOR2D> pts = aShape->ShortenedBezierPolyline( linewidth );
788
789 for( size_t i = 0; i + 1 < pts.size(); i++ )
790 {
791 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( VECTOR2I( pts[i] ) ), TO_SFVEC2F( VECTOR2I( pts[i + 1] ) ),
792 linewidth3DU, *aOwner );
793 }
794
795 break;
796 }
797
798 case SHAPE_T::POLY:
799 {
800 if( isSolidFill )
801 {
802 SHAPE_POLY_SET polyList;
803
804 // For a filled poly with a line style not a simple line, ignore line width
805 // the outline will be drawn later
806 bool ignoreLineWidth = lineStyle > LINE_STYLE::FIRST_TYPE;
807
808 aShape->TransformShapeToPolygon( polyList, UNDEFINED_LAYER, 0, aShape->GetMaxError(),
809 ERROR_INSIDE, ignoreLineWidth );
810
811 // Some polygons can be a bit complex (especially when coming from a
812 // picture of a text converted to a polygon
813 // So call Simplify before calling ConvertPolygonToTriangles, just in case.
814 polyList.Simplify();
815
816 if( polyList.IsEmpty() ) // Just for caution
817 break;
818
819 if( margin != 0 )
820 {
823
824 polyList.Inflate( margin, cornerStr, aShape->GetMaxError() );
825 }
826
827 ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aOwner );
828 }
829 else
830 {
831 const SHAPE_POLY_SET& polyShape = aShape->GetPolyShape();
832
833 for( int outlineIdx = 0; outlineIdx < polyShape.OutlineCount(); ++outlineIdx )
834 {
835 const SHAPE_LINE_CHAIN& outline = polyShape.COutline( outlineIdx );
836
837 if( outline.PointCount() < 2 )
838 continue;
839
840 std::vector<VECTOR2I> pts;
841
842 if( aShape->GetShortenedBodyPolyPoints( outline, outlineIdx, pts, linewidth ) )
843 {
844 for( size_t i = 0; i + 1 < pts.size(); i++ )
845 {
846 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[i] ), TO_SFVEC2F( pts[i + 1] ),
847 linewidth3DU, *aOwner );
848 }
849
850 if( outline.IsClosed() )
851 {
852 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts.back() ), TO_SFVEC2F( pts.front() ),
853 linewidth3DU, *aOwner );
854 }
855 }
856 }
857 }
858 break;
859 }
860
861 case SHAPE_T::ELLIPSE:
862 if( isSolidFill )
863 {
864 SHAPE_POLY_SET polyList;
865
866 aShape->TransformShapeToPolygon( polyList, UNDEFINED_LAYER, 0, aShape->GetMaxError(), ERROR_INSIDE );
867
868 polyList.Simplify();
869
870 if( polyList.IsEmpty() )
871 break;
872
873 if( margin != 0 )
874 {
877 polyList.Inflate( margin, cornerStr, aShape->GetMaxError() );
878 }
879
880 ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aOwner );
881 }
882 else
883 {
884 // Hatched fill: draw only the elliptical outline so the hatch polygons
885 // added below remain visible.
886 std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
887
888 for( SHAPE* shape : shapes )
889 {
890 if( shape->Type() == SH_SEGMENT )
891 {
892 const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape )->GetSeg();
893 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( seg.A ), TO_SFVEC2F( seg.B ), linewidth3DU,
894 *aOwner );
895 }
896 }
897
898 for( SHAPE* shape : shapes )
899 delete shape;
900 }
901
902 break;
903
905 {
906 const VECTOR2D center( aShape->GetEllipseCenter() );
907 const int majorR = aShape->GetEllipseMajorRadius();
908 const int minorR = aShape->GetEllipseMinorRadius();
909 const EDA_ANGLE& rot = aShape->GetEllipseRotation();
910 const EDA_ANGLE& start = aShape->GetEllipseStartAngle();
911 const EDA_ANGLE& end = aShape->GetEllipseEndAngle();
912 SHAPE_ELLIPSE ellipse( center, majorR, minorR, rot, start, end );
914 std::vector<VECTOR2I> pts;
915
916 if( aShape->GetShortenedBodyPolyPoints( chain, 0, pts, linewidth ) )
917 {
918 for( size_t i = 0; i + 1 < pts.size(); i++ )
919 {
920 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[i] ), TO_SFVEC2F( pts[i + 1] ), linewidth3DU,
921 *aOwner );
922 }
923 }
924
925 break;
926 }
927
928 default:
929 wxFAIL_MSG( wxT( "BOARD_ADAPTER::addShape no implementation for " ) + aShape->SHAPE_T_asString() );
930 break;
931 }
932 }
933
934 if( lineStyle > LINE_STYLE::FIRST_TYPE )
935 {
936 std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapesForStroking( linewidth );
937 SFVEC2F a3DU;
938 SFVEC2F b3DU;
939
940 const PCB_PLOT_PARAMS& plotParams = aShape->GetBoard()->GetPlotOptions();
941 KIGFX::PCB_RENDER_SETTINGS renderSettings;
942
943 renderSettings.SetDashLengthRatio( plotParams.GetDashedLineDashRatio() );
944 renderSettings.SetGapLengthRatio( plotParams.GetDashedLineGapRatio() );
945
946 for( SHAPE* shape : shapes )
947 {
948 STROKE_PARAMS::Stroke( shape, lineStyle, aShape->GetWidth(), &renderSettings,
949 [&]( const VECTOR2I& a, const VECTOR2I& b )
950 {
951 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( a ), TO_SFVEC2F( b ), linewidth3DU, *aOwner );
952 } );
953 }
954
955 for( SHAPE* shape : shapes )
956 delete shape;
957 }
958
959 // Render line endings.
962 {
963 EDA_ANGLE startTangent, endTangent;
964 aShape->GetEndingTangents( startTangent, endTangent, aShape->GetWidth() );
965
966 VECTOR2I startPt, endPt;
967
968 auto addEnding =
969 [&]( const LINE_ENDING& aEnding, const VECTOR2I& aPoint, const EDA_ANGLE& aTangent )
970 {
971 if( aEnding.GetStyle() == LINE_ENDING_STYLE::NONE )
972 return;
973
974 std::vector<VECTOR2I> pts;
975 aEnding.GetShapes( aPoint, aTangent, linewidth, pts );
976
977 if( pts.empty() )
978 return;
979
980 if( aEnding.GetStyle() == LINE_ENDING_STYLE::ARROW_OPEN )
981 {
982 // Open V-shape: draw as thick line segments, not a filled polygon.
983 int strokeW = aEnding.GetStrokeWidth() > 0 ? aEnding.GetStrokeWidth() : linewidth;
984 float stroke3DU = TO_3DU( strokeW );
985
986 for( size_t ii = 0; ii + 1 < pts.size(); ii++ )
987 {
988 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[ii] ), TO_SFVEC2F( pts[ii + 1] ),
989 stroke3DU, *aOwner );
990 }
991 }
992 else
993 {
994 if( aEnding.GetStrokeWidth() > 0 )
995 {
996 float stroke3DU = TO_3DU( aEnding.GetStrokeWidth() );
997
998 for( size_t ii = 0; ii < pts.size(); ii++ )
999 {
1000 size_t next = ( ii + 1 ) % pts.size();
1001
1002 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[ii] ), TO_SFVEC2F( pts[next] ),
1003 stroke3DU, *aOwner );
1004 }
1005 }
1006
1007 SHAPE_POLY_SET polySet;
1008 polySet.NewOutline();
1009
1010 for( const VECTOR2I& pt : pts )
1011 polySet.Append( pt );
1012
1013 ConvertPolygonToTriangles( polySet, *aContainer, m_biuTo3Dunits, *aOwner );
1014 }
1015 };
1016
1017 if( aShape->GetLineEndingEndpoints( startPt, endPt ) )
1018 {
1019 addEnding( aShape->GetStartEnding(), startPt, startTangent );
1020 addEnding( aShape->GetEndEnding(), endPt, endTangent );
1021 }
1022 }
1023
1024 if( isHatchedFill )
1025 ConvertPolygonToTriangles( aShape->GetHatching(), *aContainer, m_biuTo3Dunits, *aOwner );
1026}
1027
1028
1029void BOARD_ADAPTER::addShape( const PCB_TEXTBOX* aTextBox, CONTAINER_2D_BASE* aContainer,
1030 const BOARD_ITEM* aOwner )
1031{
1032 addText( aTextBox, aContainer, aOwner );
1033
1034 if( !aTextBox->IsBorderEnabled() )
1035 return;
1036
1037 // we use the box polygonal shape to honor the text box rotation and box line style
1038 PCB_SHAPE tb_box = aTextBox->GetPolygonalBoxShape();
1039 addShape( &tb_box, aContainer, aOwner, UNDEFINED_LAYER );
1040}
1041
1042
1043void BOARD_ADAPTER::addTable( const PCB_TABLE* aTable, CONTAINER_2D_BASE* aContainer,
1044 const BOARD_ITEM* aOwner )
1045{
1046 aTable->DrawBorders(
1047 [&]( const VECTOR2I& ptA, const VECTOR2I& ptB, const STROKE_PARAMS& stroke )
1048 {
1049 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( ptA ), TO_SFVEC2F( ptB ),
1050 TO_3DU( stroke.GetWidth() ), *aOwner );
1051 } );
1052
1053 for( PCB_TABLECELL* cell : aTable->GetCells() )
1054 {
1055 if( cell->GetColSpan() > 0 && cell->GetRowSpan() > 0 )
1056 addText( cell, aContainer, aOwner );
1057 }
1058}
1059
1060
1062 PCB_LAYER_ID aLayerId )
1063{
1064 // This convert the poly in outline and holes
1065 ConvertPolygonToTriangles( *aZone->GetFilledPolysList( aLayerId ), *aContainer, m_biuTo3Dunits, *aZone );
1066}
1067
1068
1070 CONTAINER_2D_BASE* aContainer, int aWidth )
1071{
1072 if( aPad->GetShape( aLayer ) == PAD_SHAPE::CIRCLE ) // Draw a ring
1073 {
1074 const SFVEC2F center3DU = TO_SFVEC2F( aPad->ShapePos( aLayer ) );
1075 const int radius = aPad->GetSize( aLayer ).x / 2;
1076 const float inner_radius3DU = TO_3DU( radius - aWidth / 2.0 );
1077 const float outer_radius3DU = TO_3DU( radius + aWidth / 2.0 );
1078
1079 addRING_2D( aContainer, center3DU, inner_radius3DU, outer_radius3DU, *aPad );
1080 }
1081 else
1082 {
1083 // For other shapes, add outlines as thick segments in polygon buffer
1084 const std::shared_ptr<SHAPE_POLY_SET>& corners = aPad->GetEffectivePolygon( aLayer, ERROR_INSIDE );
1085 const SHAPE_LINE_CHAIN& path = corners->COutline( 0 );
1086
1087 for( int j = 0; j < path.PointCount(); j++ )
1088 {
1089 SFVEC2F start3DU = TO_SFVEC2F( path.CPoint( j ) );
1090 SFVEC2F end3DU = TO_SFVEC2F( path.CPoint( j + 1 ) );
1091
1092 addROUND_SEGMENT_2D( aContainer, start3DU, end3DU, TO_3DU( aWidth ), *aPad );
1093 }
1094 }
1095}
@ ERROR_INSIDE
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
void addPads(const FOOTPRINT *aFootprint, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId)
void addSolidAreasShapes(const ZONE *aZone, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId)
void addFootprintShapes(const FOOTPRINT *aFootprint, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId, const std::bitset< LAYER_3D_END > &aVisibilityFlags)
void createArcSegments(const VECTOR2I &aCentre, const VECTOR2I &aStart, const EDA_ANGLE &aArcAngle, int aCircleToSegmentsCount, int aWidth, CONTAINER_2D_BASE *aContainer, const BOARD_ITEM &aOwner)
void createPadWithMargin(const PAD *aPad, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayer, const VECTOR2I &aMargin) const
void addBarCode(const PCB_BARCODE *aBarCode, CONTAINER_2D_BASE *aDstContainer, const BOARD_ITEM *aOwner)
void buildPadOutlineAsSegments(const PAD *aPad, PCB_LAYER_ID aLayer, CONTAINER_2D_BASE *aDstContainer, int aWidth)
void addTable(const PCB_TABLE *aTable, CONTAINER_2D_BASE *aContainer, const BOARD_ITEM *aOwner)
void createPadHoleShape(const PAD *aPad, CONTAINER_2D_BASE *aDstContainer, int aInflateValue)
unsigned int GetCircleSegmentCount(float aDiameter3DU) const
void addShape(const PCB_SHAPE *aShape, CONTAINER_2D_BASE *aContainer, const BOARD_ITEM *aOwner, PCB_LAYER_ID aLayer)
double m_biuTo3Dunits
Scale factor to convert board internal units.
void createTrackWithMargin(const PCB_TRACK *aTrack, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayer, int aMargin=0, const BOARD_ITEM *aOwner=nullptr)
void addText(const EDA_TEXT *aText, CONTAINER_2D_BASE *aDstContainer, const BOARD_ITEM *aOwner)
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual bool IsKnockout() const
Definition board_item.h:437
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
virtual void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const
Convert the item shape to a polyset.
Definition board_item.h:582
const KIFONT::METRICS & GetFontMetrics() const
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:281
int GetMaxError() const
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition board.h:1032
constexpr int GetSizeMax() const
Definition box2.h:238
void Add(OBJECT_2D *aObject)
double AsDegrees() const
Definition eda_angle.h:115
bool IsZero() const
Definition eda_angle.h:135
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
static bool ShortenSegmentForEndings(VECTOR2I &aStart, VECTOR2I &aEnd, const LINE_ENDING &aStartEnding, const LINE_ENDING &aEndEnding, int aLineWidth)
Shorten a segment body for line endings.
int GetEllipseMinorRadius() const
Definition eda_shape.h:404
const VECTOR2I & GetEllipseCenter() const
Definition eda_shape.h:386
const SHAPE_POLY_SET & GetHatching() const
EDA_ANGLE GetEllipseEndAngle() const
Definition eda_shape.h:432
int GetEllipseMajorRadius() const
Definition eda_shape.h:395
int GetRectangleWidth() const
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition eda_shape.h:566
SHAPE_POLY_SET & GetPolyShape()
void GetEndingTangents(EDA_ANGLE &aStartTangent, EDA_ANGLE &aEndTangent, int aLineWidth=0) const
Compute outward-facing tangent angles at the start and end of the shape.
void CalcArcAngles(EDA_ANGLE &aStartAngle, EDA_ANGLE &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
EDA_ANGLE GetEllipseRotation() const
Definition eda_shape.h:413
int GetRadius() const
SHAPE_T GetShape() const
Definition eda_shape.h:178
std::vector< SHAPE * > MakeEffectiveShapesForStroking(int aLineWidth=-1) const
Make a set of SHAPE objects to hand to STROKE_PARAMS::Stroke().
bool GetShortenedBodyPolyPoints(const SHAPE_LINE_CHAIN &aOutline, int aOutlineIdx, std::vector< VECTOR2I > &aPoints, int aLineWidth) const
Copy an outline and apply line-ending body shortening when applicable.
bool IsHatchedFill() const
Definition eda_shape.h:133
bool GetLineEndingEndpoints(VECTOR2I &aStartPoint, VECTOR2I &aEndPoint) const
Return the source endpoints used to place line endings.
bool IsSolidFill() const
Definition eda_shape.h:126
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
std::vector< VECTOR2I > GetRectCorners() const
EDA_ANGLE GetEllipseStartAngle() const
Definition eda_shape.h:423
const LINE_ENDING & GetStartEnding() const
Definition eda_shape.h:180
wxString SHAPE_T_asString() const
int GetRectangleHeight() const
bool ShortenArcForEndings(EDA_ANGLE &aStartAngle, EDA_ANGLE &aArcAngle, double aRadius, int aLineWidth) const
Shorten an arc body for line endings.
std::vector< VECTOR2D > ShortenedBezierPolyline(int aLineWidth) const
Return the flattened Bezier polyline after line-ending shortening.
const LINE_ENDING & GetEndEnding() const
Definition eda_shape.h:186
int GetCornerRadius() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
bool IsItalic() const
Definition eda_text.h:200
KIFONT::FONT * GetFont() const
Definition eda_text.h:286
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
Definition eda_text.cpp:684
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:425
virtual VECTOR2I GetDrawPos() const
Definition eda_text.h:426
virtual wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition eda_text.h:128
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:270
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:428
bool IsBold() const
Definition eda_text.h:215
std::deque< PAD * > & Pads()
Definition footprint.h:355
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
DRAWINGS & GraphicalItems()
Definition footprint.h:358
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:144
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr) const
Draw a string.
Definition font.cpp:243
PCB specific render settings.
Definition pcb_painter.h:94
void SetGapLengthRatio(double aRatio)
void SetDashLengthRatio(double aRatio)
Decorative shape (arrowhead, circle, square) at the start or end of a graphic line,...
Definition line_ending.h:62
LINE_ENDING_STYLE GetStyle() const
Definition line_ending.h:81
void GetShapes(const VECTOR2I &aPoint, const EDA_ANGLE &aTangent, int aLineWidth, std::vector< VECTOR2I > &aPolygon) const
Generate ending geometry as polygon vertices at the given point and direction.
int GetStrokeWidth() const
Outline stroke width.
Definition pad.h:61
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Return a SHAPE_SEGMENT object representing the pad's hole.
Definition pad.cpp:1233
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool aIgnoreLineWidth=false) const override
Convert the pad shape to a closed polygon.
Definition pad.cpp:3036
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:205
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:297
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon(PCB_LAYER_ID aLayer, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
Definition pad.cpp:1111
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition pad.cpp:1124
bool HasHole() const override
Definition pad.h:113
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1825
bool IsDegenerated(int aThreshold=5) const
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_track.h:311
double GetRadius() const
EDA_ANGLE GetAngle() const
Abstract dimension API.
int GetLineThickness() const
const std::vector< std::shared_ptr< SHAPE > > & GetShapes() const
Parameters and options when plotting/printing a board.
double GetDashedLineGapRatio() const
double GetDashedLineDashRatio() const
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_shape.h:80
int GetWidth() const override
bool HasSolderMask() const
Definition pcb_shape.h:349
int GetSolderMaskExpansion() const
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
STROKE_PARAMS GetStroke() const override
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
VECTOR2I GetPosition() const override
Definition pcb_shape.h:78
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:70
std::vector< PCB_TABLECELL * > GetCells() const
Definition pcb_table.h:165
void DrawBorders(const std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const STROKE_PARAMS &aStroke)> &aCallback) const
bool IsBorderEnabled() const
Tests whether the border is disabled, as configured by the stroke.
PCB_SHAPE GetPolygonalBoxShape() const
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:96
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:99
const VECTOR2I & GetStart() const
Definition pcb_track.h:100
const VECTOR2I & GetEnd() const
Definition pcb_track.h:97
virtual void SetWidth(int aWidth)
Definition pcb_track.h:93
virtual int GetWidth() const
Definition pcb_track.h:94
A round rectangle shape, based on a rectangle and a radius.
Definition roundrect.h:32
void TransformToPolygon(SHAPE_POLY_SET &aBuffer, int aMaxError) const
Get the polygonal representation of the roundrect.
Definition roundrect.cpp:79
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
int GetWidth() const override
Definition shape_arc.h:215
const SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError=DefaultAccuracyForPCB(), int *aActualError=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
int GetRadius() const
SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError) const
Build a polyline approximation of the ellipse or arc.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
SEG Segment(int aIndex) const
Return a copy of the aIndex-th segment in the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
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)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const SEG & GetSeg() const
int GetWidth() const override
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
An abstract shape on 2D plane.
Definition shape.h:124
virtual int GetWidth() const
Definition shape.h:299
Simple container to manage line stroke parameters.
int GetWidth() const
LINE_STYLE GetLineStyle() const
static void Stroke(const SHAPE *aShape, LINE_STYLE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, const std::function< void(const VECTOR2I &a, const VECTOR2I &b)> &aStroker)
EDA_ORIENTATION m_Angle
Handle a list of polygons defining a copper zone.
Definition zone.h:70
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:701
@ FOR_CANVAS
Definition common.h:92
CORNER_STRATEGY
define how inflate transform build inflated polygon
@ ROUND_ALL_CORNERS
All angles are rounded.
@ ALLOW_ACUTE_CORNERS
just inflate the polygon. Acute angles create spikes
#define TO_3DU(x)
void addFILLED_CIRCLE_2D(CONTAINER_2D_BASE *aContainer, const SFVEC2F &aCenter, float aRadius, const BOARD_ITEM &aBoardItem)
#define TO_SFVEC2F(vec)
void addROUND_SEGMENT_2D(CONTAINER_2D_BASE *aContainer, const SFVEC2F &aStart, const SFVEC2F &aEnd, float aWidth, const BOARD_ITEM &aBoardItem)
void addRING_2D(CONTAINER_2D_BASE *aContainer, const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, const BOARD_ITEM &aBoardItem)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_360
Definition eda_angle.h:478
@ ELLIPSE
Definition eda_shape.h:63
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
@ ELLIPSE_ARC
Definition eda_shape.h:64
a few functions useful in geometry calculations.
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
static const wxChar * m_logTrace
Trace mask used to enable or disable debug output for this class.
bool IsSolderMaskLayer(int aLayer)
Definition layer_ids.h:815
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_Paste
Definition layer_ids.h:100
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:92
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
BARCODE class definition.
CITER next(CITER it)
Definition ptree.cpp:120
bool Is_segment_a_circle(const SFVEC2F &aStart, const SFVEC2F &aEnd)
Check if segment start and end is very close to each other.
@ SH_POLY_SET
set of polygons (with holes, etc.)
Definition shape.h:48
@ SH_RECT
axis-aligned rectangle
Definition shape.h:43
@ SH_CIRCLE
circle
Definition shape.h:46
@ SH_SIMPLE
simple polygon
Definition shape.h:47
@ SH_ELLIPSE
ellipse or elliptical arc
Definition shape.h:53
@ SH_SEGMENT
line segment
Definition shape.h:44
@ SH_ARC
circular arc
Definition shape.h:50
static wxString SHAPE_TYPE_asString(SHAPE_TYPE a)
Definition shape.h:56
std::vector< FAB_LAYER_COLOR > dummy
LINE_STYLE
Dashed line types.
const std::string table
std::string path
VECTOR2I center
const SHAPE_LINE_CHAIN chain
int radius
VECTOR2I end
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
int clearance
int delta
void ConvertPolygonToTriangles(const SHAPE_POLY_SET &aPolyList, CONTAINER_2D_BASE &aDstContainer, float aBiuTo3dUnitsScale, const BOARD_ITEM &aBoardItem)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:227
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
glm::vec2 SFVEC2F
Definition xv3d_types.h:38