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 (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
32#include "../3d_rendering/raytracing/shapes2D/ring_2d.h"
33#include "../3d_rendering/raytracing/shapes2D/filled_circle_2d.h"
34#include "../3d_rendering/raytracing/shapes2D/round_segment_2d.h"
35#include "../3d_rendering/raytracing/shapes2D/triangle_2d.h"
36#include <board_adapter.h>
37#include <board.h>
38#include <footprint.h>
39#include <pad.h>
40#include <pcb_text.h>
41#include <pcb_textbox.h>
42#include <pcb_table.h>
44#include <pcb_painter.h> // for PCB_RENDER_SETTINGS
45#include <zone.h>
47#include <trigo.h>
51#include <geometry/shape_rect.h>
53#include <utility>
54#include <vector>
55#include <wx/log.h>
56#include <macros.h>
57#include <callback_gal.h>
58
59
60#define TO_3DU( x ) ( ( x ) * m_biuTo3Dunits )
61
62#define TO_SFVEC2F( vec ) SFVEC2F( TO_3DU( vec.x ), TO_3DU( -vec.y ) )
63
64
65void addFILLED_CIRCLE_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aCenter, float aRadius,
66 const BOARD_ITEM& aBoardItem )
67{
68 if( aRadius > 0.0f )
69 aContainer->Add( new FILLED_CIRCLE_2D( aCenter, aRadius, aBoardItem ) );
70}
71
72
73void addRING_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aCenter, float aInnerRadius,
74 float aOuterRadius, const BOARD_ITEM& aBoardItem )
75{
76 if( aOuterRadius > aInnerRadius && aInnerRadius > 0.0f )
77 aContainer->Add( new RING_2D( aCenter, aInnerRadius, aOuterRadius, aBoardItem ) );
78}
79
80
81void addROUND_SEGMENT_2D( CONTAINER_2D_BASE* aContainer, const SFVEC2F& aStart, const SFVEC2F& aEnd,
82 float aWidth, const BOARD_ITEM& aBoardItem )
83{
84 if( Is_segment_a_circle( aStart, aEnd ) )
85 {
86 // Cannot add segments that have the same start and end point
87 addFILLED_CIRCLE_2D( aContainer, aStart, aWidth / 2, aBoardItem );
88 return;
89 }
90
91 if( aWidth > 0.0f )
92 aContainer->Add( new ROUND_SEGMENT_2D( aStart, aEnd, aWidth, aBoardItem ) );
93}
94
95
96void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContainer,
97 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
104 if( !font )
105 font = KIFONT::FONT::GetFont( wxEmptyString, aText->IsBold(), aText->IsItalic() );
106
107 if( aOwner && aOwner->IsKnockout() )
108 {
109 SHAPE_POLY_SET finalPoly;
110 const PCB_TEXT* pcbText = static_cast<const PCB_TEXT*>( aOwner );
111
113 ERROR_INSIDE );
114
115 // Do not call finalPoly.Fracture() here: ConvertPolygonToTriangles() call it
116 // if needed, and Fracture() called twice can create bad results and is useless
117 ConvertPolygonToTriangles( finalPoly, *aContainer, m_biuTo3Dunits, *aOwner );
118 }
119 else
120 {
121 CALLBACK_GAL callback_gal( empty_opts,
122 // Stroke callback
123 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
124 {
125 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( aPt1 ), TO_SFVEC2F( aPt2 ),
126 penWidth_3DU, *aOwner );
127 },
128 // Triangulation callback
129 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
130 {
131 aContainer->Add( new TRIANGLE_2D( TO_SFVEC2F( aPt1 ), TO_SFVEC2F( aPt2 ),
132 TO_SFVEC2F( aPt3 ), *aOwner ) );
133 } );
134
135 attrs.m_Angle = aText->GetDrawRotation();
136
137 font->Draw( &callback_gal, aText->GetShownText( true ), aText->GetDrawPos(), attrs,
138 aOwner->GetFontMetrics() );
139 }
140}
141
142
144 const BOARD_ITEM* aOwner )
145{
146 addText( aDimension, aContainer, aDimension );
147
148 const int linewidth = aDimension->GetLineThickness();
149
150 for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
151 {
152 switch( shape->Type() )
153 {
154 case SH_SEGMENT:
155 {
156 const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
157
158 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( seg.A ), TO_SFVEC2F( seg.B ),
159 TO_3DU( linewidth ), *aOwner );
160 break;
161 }
162
163 case SH_CIRCLE:
164 {
165 int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
166 float innerR3DU = TO_3DU( radius ) - TO_3DU( aDimension->GetLineThickness() ) / 2.0f;
167 float outerR3DU = TO_3DU( radius ) + TO_3DU( aDimension->GetLineThickness() ) / 2.0f;
168
169 addRING_2D( aContainer, TO_SFVEC2F( shape->Centre() ), innerR3DU, outerR3DU, *aOwner );
170
171 break;
172 }
173
174 default:
175 break;
176 }
177 }
178}
179
180
182 PCB_LAYER_ID aLayerId,
183 const std::bitset<LAYER_3D_END>& aVisibilityFlags )
184{
186
187 for( PCB_FIELD* field : aFootprint->GetFields() )
188 {
189 if( field->GetLayer() == aLayerId && field->IsVisible() )
190 {
191 if( !aVisibilityFlags.test( LAYER_FP_TEXT ) )
192 continue;
193 else if( field->IsReference() && !aVisibilityFlags.test( LAYER_FP_REFERENCES ) )
194 continue;
195 else if( field->IsValue() && !aVisibilityFlags.test( LAYER_FP_VALUES ) )
196 continue;
197
198 addText( field, aContainer, field );
199 }
200 }
201
202 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
203 {
204 switch( item->Type() )
205 {
206 case PCB_TEXT_T:
207 {
208 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
209
210 if( text->GetLayer() == aLayerId && text->IsVisible() )
211 {
212 if( !aVisibilityFlags.test( LAYER_FP_TEXT ) )
213 continue;
214 else if( text->GetText() == wxT( "${REFERENCE}" ) && !aVisibilityFlags.test( LAYER_FP_REFERENCES ) )
215 continue;
216 else if( text->GetText() == wxT( "${VALUE}" ) && !aVisibilityFlags.test( LAYER_FP_VALUES ) )
217 continue;
218
219 addText( text, aContainer, text );
220 }
221
222 break;
223 }
224
225 case PCB_TEXTBOX_T:
226 {
227 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
228
229 if( textbox->GetLayer() == aLayerId )
230 addShape( textbox, aContainer, aFootprint );
231
232 break;
233 }
234
235 case PCB_TABLE_T:
236 {
237 PCB_TABLE* table = static_cast<PCB_TABLE*>( item );
238
239 if( table->GetLayer() == aLayerId )
240 addTable( table, aContainer, aFootprint );
241
242 break;
243 }
244
246 case PCB_DIM_CENTER_T:
248 case PCB_DIM_RADIAL_T:
249 case PCB_DIM_LEADER_T:
250 {
251 PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( item );
252
253 if( dimension->GetLayer() == aLayerId )
254 addShape( dimension, aContainer, aFootprint );
255
256 break;
257 }
258
259 case PCB_SHAPE_T:
260 {
261 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
262
263 if( shape->GetLayer() == aLayerId )
264 addShape( shape, aContainer, aFootprint );
265
266 break;
267 }
268
269 default:
270 break;
271 }
272 }
273}
274
275
277 int aMargin )
278{
279 SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() );
280 SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() );
281 const float radius3DU = TO_3DU( ( aTrack->GetWidth() / 2.0 ) + aMargin );
282
283 addFILLED_CIRCLE_2D( aDstContainer, start3DU, radius3DU, *aTrack );
284}
285
286
287void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer )
288{
289 SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() );
290 SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() );
291
292 switch( aTrack->Type() )
293 {
294 case PCB_VIA_T:
295 addFILLED_CIRCLE_2D( aDstContainer, start3DU, TO_3DU( aTrack->GetWidth() / 2.0 ), *aTrack );
296 break;
297
298 case PCB_ARC_T:
299 {
300 const PCB_ARC* arc = static_cast<const PCB_ARC*>( aTrack );
301
302 if( arc->IsDegenerated() )
303 {
304 // Draw this very small arc like a track segment (a PCB_TRACE_T)
305 PCB_TRACK track( arc->GetParent() );
306 track.SetStart( arc->GetStart() );
307 track.SetEnd( arc->GetEnd() );
308 track.SetWidth( arc->GetWidth() );
309 track.SetLayer( arc->GetLayer() );
310
311 createTrack( &track, aDstContainer );
312 return;
313 }
314
315 VECTOR2I center( arc->GetCenter() );
316 EDA_ANGLE arc_angle = arc->GetAngle();
317 double radius = arc->GetRadius();
318 int arcsegcount = GetArcToSegmentCount( KiROUND( radius ), ARC_HIGH_DEF, arc_angle );
319 int circlesegcount;
320
321 // Avoid arcs that cannot be drawn
322 if( radius < std::numeric_limits<double>::min() || arc_angle.IsZero() )
323 break;
324
325 // We need a circle to segment count. However, the arc angle can be small, and the
326 // radius very big. so we calculate a reasonable value for circlesegcount.
327 if( arcsegcount <= 1 ) // The arc will be approximated by a segment
328 {
329 circlesegcount = 1;
330 }
331 else
332 {
333 circlesegcount = KiROUND( arcsegcount * 360.0 / std::abs( arc_angle.AsDegrees() ) );
334 circlesegcount = alg::clamp( 1, circlesegcount, 128 );
335 }
336
337 createArcSegments( center, arc->GetStart(), arc_angle, circlesegcount, arc->GetWidth(),
338 aDstContainer, *arc );
339 break;
340 }
341
342 case PCB_TRACE_T: // Track is a usual straight segment
343 {
344 addROUND_SEGMENT_2D( aDstContainer, start3DU, end3DU, TO_3DU( aTrack->GetWidth() ), *aTrack );
345 break;
346 }
347
348 default:
349 break;
350 }
351}
352
353
355 PCB_LAYER_ID aLayer, const VECTOR2I& aMargin ) const
356{
357 SHAPE_POLY_SET poly;
358 int maxError = GetBoard()->GetDesignSettings().m_MaxError;
359 VECTOR2I clearance = aMargin;
360
361 // Our shape-based builder can't handle negative or differing x:y clearance values (the
362 // former are common for solder paste while the later get generated when a relative paste
363 // margin is used with an oblong pad). So we apply this huge hack and fake a larger pad to
364 // run the general-purpose polygon builder on.
365 // Of course being a hack it falls down when dealing with custom shape pads (where the size
366 // is only the size of the anchor), so for those we punt and just use aMargin.x.
367
368 if( ( clearance.x < 0 || clearance.x != clearance.y )
369 && aPad->GetShape() != PAD_SHAPE::CUSTOM )
370 {
371 VECTOR2I dummySize = VECTOR2I( aPad->GetSize() ) + clearance + clearance;
372
373 if( dummySize.x <= 0 || dummySize.y <= 0 )
374 return;
375
376 PAD dummy( *aPad );
377 dummy.SetSize( VECTOR2I( dummySize.x, dummySize.y ) );
378 dummy.TransformShapeToPolygon( poly, aLayer, 0, maxError, ERROR_INSIDE );
379 clearance = { 0, 0 };
380
381 // Remove group membership from dummy item before deleting
382 dummy.SetParentGroup( nullptr );
383 }
384 else
385 {
386 auto padShapes = std::static_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape() );
387
388 for( const SHAPE* shape : padShapes->Shapes() )
389 {
390 switch( shape->Type() )
391 {
392 case SH_SEGMENT:
393 {
394 const SHAPE_SEGMENT* seg = static_cast<const SHAPE_SEGMENT*>( shape );
395
396 addROUND_SEGMENT_2D( aContainer,
397 TO_SFVEC2F( seg->GetSeg().A ),
398 TO_SFVEC2F( seg->GetSeg().B ),
399 TO_3DU( seg->GetWidth() + clearance.x * 2 ),
400 *aPad );
401 break;
402 }
403
404 case SH_CIRCLE:
405 {
406 const SHAPE_CIRCLE* circle = static_cast<const SHAPE_CIRCLE*>( shape );
407
408 addFILLED_CIRCLE_2D( aContainer,
409 TO_SFVEC2F( circle->GetCenter() ),
410 TO_3DU( circle->GetRadius() + clearance.x ),
411 *aPad );
412 break;
413 }
414
415 case SH_RECT:
416 {
417 const SHAPE_RECT* rect = static_cast<const SHAPE_RECT*>( shape );
418
419 poly.NewOutline();
420 poly.Append( rect->GetPosition() );
421 poly.Append( rect->GetPosition().x + rect->GetSize().x, rect->GetPosition().y );
422 poly.Append( rect->GetPosition() + rect->GetSize() );
423 poly.Append( rect->GetPosition().x, rect->GetPosition().y + rect->GetSize().y );
424 break;
425 }
426
427 case SH_SIMPLE:
428 poly.AddOutline( static_cast<const SHAPE_SIMPLE*>( shape )->Vertices() );
429 break;
430
431 case SH_POLY_SET:
432 poly = *(SHAPE_POLY_SET*) shape;
433 break;
434
435 case SH_ARC:
436 {
437 const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( shape );
438 SHAPE_LINE_CHAIN l = arc->ConvertToPolyline( maxError );
439
440 for( int i = 0; i < l.SegmentCount(); i++ )
441 {
442 SHAPE_SEGMENT seg( l.Segment( i ).A, l.Segment( i ).B, arc->GetWidth() );
443
444 addROUND_SEGMENT_2D( aContainer,
445 TO_SFVEC2F( seg.GetSeg().A ),
446 TO_SFVEC2F( seg.GetSeg().B ),
447 TO_3DU( arc->GetWidth() + clearance.x * 2 ),
448 *aPad );
449 }
450
451 break;
452 }
453
454 default:
455 UNIMPLEMENTED_FOR( SHAPE_TYPE_asString( shape->Type() ) );
456 break;
457 }
458 }
459 }
460
461 if( !poly.IsEmpty() )
462 {
463 if( clearance.x )
464 poly.Inflate( clearance.x, CORNER_STRATEGY::ROUND_ALL_CORNERS, maxError );
465
466 // Add the PAD polygon
467 ConvertPolygonToTriangles( poly, *aContainer, m_biuTo3Dunits, *aPad );
468 }
469}
470
471
473 int aInflateValue )
474{
475 if( !aPad->HasHole() )
476 {
477 wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::createPadWithHole - found an invalid pad" ) );
478 return;
479 }
480
481 std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
482
483 addROUND_SEGMENT_2D( aDstContainer,
484 TO_SFVEC2F( slot->GetSeg().A ),
485 TO_SFVEC2F( slot->GetSeg().B ),
486 TO_3DU( slot->GetWidth() + aInflateValue * 2 ),
487 *aPad );
488}
489
490
491void BOARD_ADAPTER::addPads( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aContainer,
492 PCB_LAYER_ID aLayerId, bool aSkipPlatedPads, bool aSkipNonPlatedPads )
493{
494 for( PAD* pad : aFootprint->Pads() )
495 {
496 if( !pad->IsOnLayer( aLayerId ) )
497 continue;
498
499 if( IsCopperLayer( aLayerId ) )
500 {
501 // Skip pad annulus when there isn't one (note: this is more discerning than
502 // pad->IsOnLayer(), which doesn't check for NPTH pads with holes that consume
503 // the entire pad).
504 if( !pad->IsOnCopperLayer() )
505 continue;
506
507 // Skip pad annulus when not connected on this layer (if removing is enabled)
508 if( !pad->FlashLayer( aLayerId ) )
509 continue;
510 }
511
512 VECTOR2I margin( 0, 0 );
513
514 switch( aLayerId )
515 {
516 case F_Cu:
517 if( aSkipPlatedPads && pad->FlashLayer( F_Mask ) )
518 continue;
519
520 if( aSkipNonPlatedPads && !pad->FlashLayer( F_Mask ) )
521 continue;
522
523 break;
524
525 case B_Cu:
526 if( aSkipPlatedPads && pad->FlashLayer( B_Mask ) )
527 continue;
528
529 if( aSkipNonPlatedPads && !pad->FlashLayer( B_Mask ) )
530 continue;
531
532 break;
533
534 case F_Mask:
535 case B_Mask:
536 margin.x += pad->GetSolderMaskExpansion();
537 margin.y += pad->GetSolderMaskExpansion();
538 break;
539
540 case F_Paste:
541 case B_Paste:
542 margin += pad->GetSolderPasteMargin();
543 break;
544
545 default:
546 break;
547 }
548
549 createPadWithMargin( pad, aContainer, aLayerId, margin );
550 }
551}
552
553
554// based on TransformArcToPolygon function from
555// common/convert_basic_shapes_to_polygon.cpp
556void BOARD_ADAPTER::createArcSegments( const VECTOR2I& aCentre, const VECTOR2I& aStart,
557 const EDA_ANGLE& aArcAngle, int aCircleToSegmentsCount,
558 int aWidth, CONTAINER_2D_BASE* aContainer,
559 const BOARD_ITEM& aOwner )
560{
561 // Don't attempt to render degenerate shapes
562 if( aWidth == 0 )
563 return;
564
565 VECTOR2I arc_start, arc_end;
566 EDA_ANGLE arcAngle( aArcAngle );
567 EDA_ANGLE delta = ANGLE_360 / aCircleToSegmentsCount; // rotate angle
568
569 arc_end = arc_start = aStart;
570
571 if( arcAngle != ANGLE_360 )
572 RotatePoint( arc_end, aCentre, -arcAngle );
573
574 if( arcAngle < ANGLE_0 )
575 {
576 std::swap( arc_start, arc_end );
577 arcAngle = -arcAngle;
578 }
579
580 // Compute the ends of segments and creates poly
581 VECTOR2I curr_end = arc_start;
582 VECTOR2I curr_start = arc_start;
583
584 for( EDA_ANGLE ii = delta; ii < arcAngle; ii += delta )
585 {
586 curr_end = arc_start;
587 RotatePoint( curr_end, aCentre, -ii );
588
589 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( curr_start ), TO_SFVEC2F( curr_end ),
590 TO_3DU( aWidth ), aOwner );
591
592 curr_start = curr_end;
593 }
594
595 if( curr_end != arc_end )
596 {
597 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( curr_end ), TO_SFVEC2F( arc_end ),
598 TO_3DU( aWidth ), aOwner );
599 }
600}
601
602
603void BOARD_ADAPTER::addShape( const PCB_SHAPE* aShape, CONTAINER_2D_BASE* aContainer,
604 const BOARD_ITEM* aOwner )
605{
606 // The full width of the lines to create
607 const float linewidth3DU = TO_3DU( aShape->GetWidth() );
608 LINE_STYLE lineStyle = aShape->GetStroke().GetLineStyle();
609
610 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
611 {
612 switch( aShape->GetShape() )
613 {
614 case SHAPE_T::CIRCLE:
615 {
616 SFVEC2F center3DU = TO_SFVEC2F( aShape->GetCenter() );
617 float innerR3DU = TO_3DU( aShape->GetRadius() ) - linewidth3DU / 2.0;
618 float outerR3DU = TO_3DU( aShape->GetRadius() ) + linewidth3DU / 2.0;
619
620 if( aShape->IsFilled() || innerR3DU <= 0.0 )
621 addFILLED_CIRCLE_2D( aContainer, center3DU, outerR3DU, *aOwner );
622 else
623 addRING_2D( aContainer, center3DU, innerR3DU, outerR3DU, *aOwner );
624
625 break;
626 }
627
628 case SHAPE_T::RECTANGLE:
629 if( aShape->IsFilled() )
630 {
631 SHAPE_POLY_SET polyList;
632
634 ERROR_INSIDE );
635
637
638 ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aOwner );
639 }
640 else
641 {
642 std::vector<VECTOR2I> pts = aShape->GetRectCorners();
643
644 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[0] ), TO_SFVEC2F( pts[1] ),
645 linewidth3DU, *aOwner );
646 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[1] ), TO_SFVEC2F( pts[2] ),
647 linewidth3DU, *aOwner );
648 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[2] ), TO_SFVEC2F( pts[3] ),
649 linewidth3DU, *aOwner );
650 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( pts[3] ), TO_SFVEC2F( pts[0] ),
651 linewidth3DU, *aOwner );
652 }
653 break;
654
655 case SHAPE_T::ARC:
656 {
657 unsigned int segCount = GetCircleSegmentCount( aShape->GetBoundingBox().GetSizeMax() );
658
659 createArcSegments( aShape->GetCenter(), aShape->GetStart(), aShape->GetArcAngle(),
660 segCount, aShape->GetWidth(), aContainer, *aOwner );
661 break;
662 }
663
664 case SHAPE_T::SEGMENT:
665 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( aShape->GetStart() ),
666 TO_SFVEC2F( aShape->GetEnd() ), linewidth3DU, *aOwner );
667 break;
668
669 case SHAPE_T::BEZIER:
670 case SHAPE_T::POLY:
671 {
672 SHAPE_POLY_SET polyList;
673
675 ERROR_INSIDE );
676
677 // Some polygons can be a bit complex (especially when coming from a
678 // picture ot a text converted to a polygon
679 // So call Simplify before calling ConvertPolygonToTriangles, just in case.
681
682 if( polyList.IsEmpty() ) // Just for caution
683 break;
684
685 ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aOwner );
686 break;
687 }
688
689 default:
690 wxFAIL_MSG( wxT( "BOARD_ADAPTER::addShape no implementation for " )
691 + aShape->SHAPE_T_asString() );
692 break;
693 }
694 }
695 else
696 {
697 std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
698 SFVEC2F a3DU;
699 SFVEC2F b3DU;
700
701 const PCB_PLOT_PARAMS& plotParams = aShape->GetBoard()->GetPlotOptions();
702 KIGFX::PCB_RENDER_SETTINGS renderSettings;
703
704 renderSettings.SetDashLengthRatio( plotParams.GetDashedLineDashRatio() );
705 renderSettings.SetGapLengthRatio( plotParams.GetDashedLineGapRatio() );
706
707 for( SHAPE* shape : shapes )
708 {
709 STROKE_PARAMS::Stroke( shape, lineStyle, aShape->GetWidth(), &renderSettings,
710 [&]( const VECTOR2I& a, const VECTOR2I& b )
711 {
712 addROUND_SEGMENT_2D( aContainer, TO_SFVEC2F( a ), TO_SFVEC2F( b ),
713 linewidth3DU, *aOwner );
714 } );
715 }
716
717 for( SHAPE* shape : shapes )
718 delete shape;
719 }
720}
721
722
723void BOARD_ADAPTER::addShape( const PCB_TEXTBOX* aTextBox, CONTAINER_2D_BASE* aContainer,
724 const BOARD_ITEM* aOwner )
725{
726 addText( aTextBox, aContainer, aOwner );
727
728 if( !aTextBox->IsBorderEnabled() )
729 return;
730
731 // We cannot use PCB_TEXTBOX::TransformShapeToPolygon because it convert the textbox
732 // as filled polygon even if there's no background colour.
733 // So for polygon, we use PCB_SHAPE::TransformShapeToPolygon
734
735 if( aTextBox->GetShape() == SHAPE_T::RECTANGLE )
736 {
737 addShape( static_cast<const PCB_SHAPE*>( aTextBox ), aContainer, aOwner );
738 }
739 else
740 {
741 SHAPE_POLY_SET polyList;
742
743 aTextBox->PCB_SHAPE::TransformShapeToPolygon( polyList, UNDEFINED_LAYER, 0,
745
746 ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aOwner );
747 }
748}
749
750
751void BOARD_ADAPTER::addTable( const PCB_TABLE* aTable, CONTAINER_2D_BASE* aContainer,
752 const BOARD_ITEM* aOwner )
753{
754 // JEY TODO: tables
755 // add borders
756
757 for( PCB_TABLECELL* cell : aTable->GetCells() )
758 addText( cell, aContainer, aOwner );
759}
760
761
763 PCB_LAYER_ID aLayerId )
764{
765 // This convert the poly in outline and holes
766 ConvertPolygonToTriangles( *aZone->GetFilledPolysList( aLayerId ), *aContainer, m_biuTo3Dunits,
767 *aZone );
768}
769
770
772 int aWidth )
773{
774 if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring
775 {
776 const SFVEC2F center3DU = TO_SFVEC2F( aPad->ShapePos() );
777 const int radius = aPad->GetSize().x / 2;
778 const float inner_radius3DU = TO_3DU( radius - aWidth / 2.0 );
779 const float outer_radius3DU = TO_3DU( radius + aWidth / 2.0 );
780
781 addRING_2D( aContainer, center3DU, inner_radius3DU, outer_radius3DU, *aPad );
782 }
783 else
784 {
785 // For other shapes, add outlines as thick segments in polygon buffer
786 const std::shared_ptr<SHAPE_POLY_SET>& corners = aPad->GetEffectivePolygon( ERROR_INSIDE );
787 const SHAPE_LINE_CHAIN& path = corners->COutline( 0 );
788
789 for( int j = 0; j < path.PointCount(); j++ )
790 {
791 SFVEC2F start3DU = TO_SFVEC2F( path.CPoint( j ) );
792 SFVEC2F end3DU = TO_SFVEC2F( path.CPoint( j + 1 ) );
793
794 addROUND_SEGMENT_2D( aContainer, start3DU, end3DU, TO_3DU( aWidth ), *aPad );
795 }
796 }
797}
constexpr int ARC_HIGH_DEF
Definition: base_units.h:120
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 addPads(const FOOTPRINT *aFootprint, CONTAINER_2D_BASE *aDstContainer, PCB_LAYER_ID aLayerId, bool aSkipPlatedPads, bool aSkipNonPlatedPads)
const BOARD * GetBoard() const noexcept
void createPadWithHole(const PAD *aPad, CONTAINER_2D_BASE *aDstContainer, int aInflateValue)
void buildPadOutlineAsSegments(const PAD *aPad, CONTAINER_2D_BASE *aDstContainer, int aWidth)
void addShape(const PCB_SHAPE *aShape, CONTAINER_2D_BASE *aContainer, const BOARD_ITEM *aOwner)
void createTrack(const PCB_TRACK *aTrack, CONTAINER_2D_BASE *aDstContainer)
void addTable(const PCB_TABLE *aTable, CONTAINER_2D_BASE *aContainer, const BOARD_ITEM *aOwner)
unsigned int GetCircleSegmentCount(float aDiameter3DU) const
void createViaWithMargin(const PCB_TRACK *aTrack, CONTAINER_2D_BASE *aDstContainer, int aMargin)
double m_biuTo3Dunits
Scale factor to convert board internal units to 3D units normalized between -1.0 and 1....
void addText(const EDA_TEXT *aText, CONTAINER_2D_BASE *aDstContainer, const BOARD_ITEM *aOwner)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
virtual bool IsKnockout() const
Definition: board_item.h:296
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:260
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:97
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:204
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: board.h:674
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:797
int GetSizeMax() const
Definition: box2.h:225
void Add(OBJECT_2D *aObject)
Definition: container_2d.h:49
double AsDegrees() const
Definition: eda_angle.h:155
bool IsZero() const
Definition: eda_angle.h:175
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:663
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.h:304
bool IsFilled() const
Definition: eda_shape.h:91
int GetRadius() const
Definition: eda_shape.cpp:593
SHAPE_T GetShape() const
Definition: eda_shape.h:120
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:150
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:125
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1139
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:89
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
bool IsItalic() const
Definition: eda_text.h:144
KIFONT::FONT * GetFont() const
Definition: eda_text.h:211
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:340
virtual VECTOR2I GetDrawPos() const
Definition: eda_text.h:341
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:195
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:322
bool IsBold() const
Definition: eda_text.h:148
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:109
PADS & Pads()
Definition: footprint.h:191
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with PCB_TEXTs.
Definition: footprint.cpp:565
DRAWINGS & GraphicalItems()
Definition: footprint.h:194
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:146
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Draw a string.
Definition: font.cpp:257
PCB specific render settings.
Definition: pcb_painter.h:77
void SetGapLengthRatio(double aRatio)
void SetDashLengthRatio(double aRatio)
Definition: pad.h:59
VECTOR2I ShapePos() const
Definition: pad.cpp:951
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon(ERROR_LOC aErrorLoc=ERROR_INSIDE) const
Definition: pad.cpp:514
PAD_SHAPE GetShape() const
Definition: pad.h:193
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING flashPTHPads=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pad.cpp:523
bool HasHole() const override
Definition: pad.h:109
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const override
Return a SHAPE_SEGMENT object representing the pad's hole.
Definition: pad.cpp:560
const VECTOR2I & GetSize() const
Definition: pad.h:247
bool IsDegenerated(int aThreshold=5) const
Definition: pcb_track.cpp:1585
double GetRadius() const
Definition: pcb_track.cpp:1548
EDA_ANGLE GetAngle() const
Definition: pcb_track.cpp:1555
virtual VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_track.h:322
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.
Definition: pcb_shape.h:115
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:75
int GetWidth() const override
Definition: pcb_shape.cpp:367
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.
Definition: pcb_shape.cpp:786
STROKE_PARAMS GetStroke() const override
Definition: pcb_shape.h:85
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:138
bool IsBorderEnabled() const
Disables the border, this is done by changing the stroke internally.
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Function TransformTextToPolySet Convert the text to a polygonSet describing the actual character stro...
Definition: pcb_text.cpp:568
void SetWidth(int aWidth)
Definition: pcb_track.h:106
int GetWidth() const
Definition: pcb_track.h:107
void SetEnd(const VECTOR2I &aEnd)
Definition: pcb_track.h:109
void SetStart(const VECTOR2I &aStart)
Definition: pcb_track.h:112
const VECTOR2I & GetStart() const
Definition: pcb_track.h:113
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:110
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
int GetWidth() const
Definition: shape_arc.h:160
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=DefaultAccuracyForPCB(), double *aEffectiveAccuracy=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:512
int GetRadius() const
Definition: shape_circle.h:108
const VECTOR2I GetCenter() const
Definition: shape_circle.h:113
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
SEG Segment(int aIndex) const
Return a copy of the aIndex-th segment in the line chain.
int SegmentCount() const
Return the number of segments in this 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(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
int NewOutline()
Creates a new empty polygon in the set and returns its index.
const VECTOR2I & GetPosition() const
Definition: shape_rect.h:127
const VECTOR2I GetSize() const
Definition: shape_rect.h:135
const SEG & GetSeg() const
int GetWidth() const
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Definition: shape_simple.h:42
const SHAPE_LINE_CHAIN & Vertices() const
Return the list of vertices defining this simple polygon.
Definition: shape_simple.h:124
An abstract shape on 2D plane.
Definition: shape.h:126
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
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)
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:615
#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:435
static constexpr EDA_ANGLE ANGLE_360
Definition: eda_angle.h:441
a few functions useful in geometry calculations.
@ ERROR_INSIDE
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 IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:881
@ LAYER_FP_REFERENCES
show footprints references (when texts are visible)
Definition: layer_ids.h:215
@ LAYER_FP_TEXT
Definition: layer_ids.h:202
@ LAYER_FP_VALUES
show footprints values (when texts are visible)
Definition: layer_ids.h:214
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_Paste
Definition: layer_ids.h:101
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ F_Mask
Definition: layer_ids.h:107
@ B_Paste
Definition: layer_ids.h:100
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:96
T clamp(T min, T value, T max)
Definition: kicad_algo.h:205
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:424
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:52
@ SH_RECT
axis-aligned rectangle
Definition: shape.h:47
@ SH_CIRCLE
circle
Definition: shape.h:50
@ SH_SIMPLE
simple polygon
Definition: shape.h:51
@ SH_SEGMENT
line segment
Definition: shape.h:48
@ SH_ARC
circular arc
Definition: shape.h:54
static wxString SHAPE_TYPE_asString(SHAPE_TYPE a)
Definition: shape.h:59
std::vector< FAB_LAYER_COLOR > dummy
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:48
constexpr 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:228
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:105
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:103
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:93
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:101
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition: typeinfo.h:94
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:104
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42