KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_painter.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) 2013-2019 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include <advanced_config.h>
25#include <board.h>
26#include <netinfo.h>
28#include <pcb_track.h>
29#include <pcb_group.h>
30#include <footprint.h>
31#include <pad.h>
32#include <pcb_shape.h>
33#include <string_utils.h>
34#include <zone.h>
35#include <pcb_reference_image.h>
36#include <pcb_text.h>
37#include <pcb_textbox.h>
38#include <pcb_table.h>
39#include <pcb_tablecell.h>
40#include <pcb_marker.h>
41#include <pcb_dimension.h>
42#include <pcb_point.h>
43#include <pcb_barcode.h>
44#include <pcb_target.h>
45#include <pcb_board_outline.h>
46
47#include <layer_ids.h>
48#include <lset.h>
49#include <pcb_painter.h>
50#include <pcb_display_options.h>
56#include <pcbnew_settings.h>
58
61#include <callback_gal.h>
64#include <geometry/shape_rect.h>
66#include <geometry/roundrect.h>
70#include <geometry/shape_arc.h>
72#include <stroke_params.h>
73#include <bezier_curves.h>
74#include <kiface_base.h>
75#include <gr_text.h>
76#include <pgm_base.h>
77
78using namespace KIGFX;
79
80
82{
83 return dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
84}
85
86// Helpers for display options existing in Cvpcb and Pcbnew
87// Note, when running Cvpcb, pcbconfig() returns nullptr and viewer_settings()
88// returns the viewer options existing to Cvpcb and Pcbnew
110
111
113{
114 m_backgroundColor = COLOR4D( 0.0, 0.0, 0.0, 1.0 );
118
119 m_trackOpacity = 1.0;
120 m_viaOpacity = 1.0;
121 m_padOpacity = 1.0;
122 m_zoneOpacity = 1.0;
123 m_imageOpacity = 1.0;
125
127
128 m_PadEditModePad = nullptr;
129
130 SetDashLengthRatio( 12 ); // From ISO 128-2
131 SetGapLengthRatio( 3 ); // From ISO 128-2
132
134
135 update();
136}
137
138
140{
142
143 // Init board layers colors:
144 for( int i = 0; i < PCB_LAYER_ID_COUNT; i++ )
145 {
146 m_layerColors[i] = aSettings->GetColor( i );
147
148 // Guard: if the alpha channel is too small, the layer is not visible.
149 if( m_layerColors[i].a < 0.2 )
150 m_layerColors[i].a = 0.2;
151 }
152
153 // Init specific graphic layers colors:
154 for( int i = GAL_LAYER_ID_START; i < GAL_LAYER_ID_END; i++ )
155 m_layerColors[i] = aSettings->GetColor( i );
156
157 // Colors for layers that aren't theme-able
160
161 // Netnames for copper layers
162 const COLOR4D lightLabel = aSettings->GetColor( NETNAMES_LAYER_ID_START );
163 const COLOR4D darkLabel = lightLabel.Inverted();
164
165 for( PCB_LAYER_ID layer : LSET::AllCuMask().CuStack() )
166 {
167 if( m_layerColors[layer].GetBrightness() > 0.5 )
168 m_layerColors[GetNetnameLayer( layer )] = darkLabel;
169 else
170 m_layerColors[GetNetnameLayer( layer )] = lightLabel;
171 }
172
173 if( PgmOrNull() ) // can be null if used without project (i.e. from python script)
175 else
176 m_hiContrastFactor = 1.0f - 0.8f; // default value
177
178 update();
179}
180
181
183{
190 m_viaOpacity = aOptions.m_ViaOpacity;
191 m_padOpacity = aOptions.m_PadOpacity;
192 m_zoneOpacity = aOptions.m_ZoneOpacity;
195}
196
197
198COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
199{
200 return GetColor( dynamic_cast<const BOARD_ITEM*>( aItem ), aLayer );
201}
202
203
204COLOR4D PCB_RENDER_SETTINGS::GetColor( const BOARD_ITEM* aItem, int aLayer ) const
205{
206 int netCode = -1;
207 int originalLayer = aLayer;
208
209 if( aLayer == LAYER_MARKER_SHADOWS )
210 return m_backgroundColor.WithAlpha( 0.6 );
211
212 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
213 return m_layerColors.at( aLayer );
214
215 // SMD pads use the copper netname layer
216 if( aLayer == LAYER_PAD_FR_NETNAMES )
217 aLayer = GetNetnameLayer( F_Cu );
218 else if( aLayer == LAYER_PAD_BK_NETNAMES )
219 aLayer = GetNetnameLayer( B_Cu );
220
221 if( IsHoleLayer( aLayer ) && m_isPrinting )
222 {
223 // Careful that we don't end up with the same colour for the annular ring and the hole
224 // when printing in B&W.
225 const PAD* pad = dynamic_cast<const PAD*>( aItem );
226 const PCB_VIA* via = dynamic_cast<const PCB_VIA*>( aItem );
227 int holeLayer = aLayer;
228 int annularRingLayer = UNDEFINED_LAYER;
229
230 if( pad && pad->GetAttribute() == PAD_ATTRIB::PTH )
231 {
232 LSET copperLayers = pad->GetLayerSet() & LSET::AllCuMask();
233
234 if( !copperLayers.empty() )
235 annularRingLayer = copperLayers.Seq().front();
236 }
237 else if( via )
238 {
239 annularRingLayer = F_Cu;
240 }
241
242 if( annularRingLayer != UNDEFINED_LAYER )
243 {
244 auto it = m_layerColors.find( holeLayer );
245 auto it2 = m_layerColors.find( annularRingLayer );
246
247 if( it != m_layerColors.end() && it2 != m_layerColors.end() && it->second == it2->second )
248 aLayer = LAYER_PCB_BACKGROUND;
249 }
250 }
251
252 // Zones should pull from the copper layer
253 if( aItem && aItem->Type() == PCB_ZONE_T )
254 {
255 if( IsZoneFillLayer( aLayer ) )
256 aLayer = aLayer - LAYER_ZONE_START;
257 }
258
259 // Points use the LAYER_POINTS color for their virtual per-layer layers
260 if( IsPointsLayer( aLayer ) )
261 aLayer = LAYER_POINTS;
262
263 // Pad and via copper and clearance outlines take their color from the copper layer
264 if( IsPadCopperLayer( aLayer ) )
265 {
266 if( pcbconfig() && aItem && aItem->Type() == PCB_PAD_T )
267 {
268 const PAD* pad = static_cast<const PAD*>( aItem );
269
270 // Old-skool display for people who struggle with change
271 if( pcbconfig()->m_Display.m_UseViaColorForNormalTHPadstacks
272 && pad->GetAttribute() == PAD_ATTRIB::PTH
273 && pad->Padstack().Mode() == PADSTACK::MODE::NORMAL )
274 {
275 aLayer = LAYER_VIA_HOLES;
276 }
277 else
278 {
279 aLayer = aLayer - LAYER_PAD_COPPER_START;
280 }
281 }
282 else
283 {
284 aLayer = aLayer - LAYER_PAD_COPPER_START;
285 }
286 }
287 else if( IsViaCopperLayer( aLayer ) )
288 aLayer = aLayer - LAYER_VIA_COPPER_START;
289 else if( IsClearanceLayer( aLayer ) )
290 aLayer = aLayer - LAYER_CLEARANCE_START;
291
292 // Use via "golden copper" hole color for pad hole walls for contrast
293 else if( aLayer == LAYER_PAD_HOLEWALLS )
294 aLayer = LAYER_VIA_HOLES;
295
296 // Show via mask layers if appropriate
297 if( aLayer == LAYER_VIA_THROUGH && !m_isPrinting )
298 {
299 if( aItem && aItem->GetBoard() )
300 {
301 LSET visibleLayers = aItem->GetBoard()->GetVisibleLayers()
302 & aItem->GetBoard()->GetEnabledLayers()
303 & aItem->GetLayerSet();
304
305 if( GetActiveLayer() == F_Mask && visibleLayers.test( F_Mask ) )
306 {
307 aLayer = F_Mask;
308 }
309 else if( GetActiveLayer() == B_Mask && visibleLayers.test( B_Mask ) )
310 {
311 aLayer = B_Mask;
312 }
313 else if( ( visibleLayers & LSET::AllCuMask() ).none() )
314 {
315 if( visibleLayers.any() )
316 aLayer = visibleLayers.Seq().back();
317 }
318 }
319 }
320
321 // Normal path: get the layer base color
322 auto it = m_layerColors.find( aLayer );
323 COLOR4D color = it == m_layerColors.end() ? COLOR4D::WHITE : it->second;
324
325 if( !aItem )
326 return color;
327
328 // Selection disambiguation
329 if( aItem->IsBrightened() || ( aItem->Type() == PCB_MARKER_T && aItem->IsSelected() ) )
330 {
331 if( aItem->Type() == PCB_MARKER_T )
332 {
333 auto itemLayerIter = m_layerColors.find( LAYER_DRC_HIGHLIGHTED );
334
335 if( itemLayerIter != m_layerColors.end() )
336 return itemLayerIter->second;
337 }
338
339 return color.Brightened( m_selectFactor ).WithAlpha( 0.8 );
340 }
341
342 // Normal selection
343 if( aItem->IsSelected() )
344 {
345 // Selection for tables is done with a background wash, so pass in nullptr to GetColor()
346 // so we just get the "normal" (un-selected/un-brightened) color for the borders.
347 if( aItem->Type() != PCB_TABLE_T && aItem->Type() != PCB_TABLECELL_T )
348 {
349 auto it_selected = m_layerColorsSel.find( aLayer );
350 color = it_selected == m_layerColorsSel.end() ? color.Brightened( 0.8 ) : it_selected->second;
351 }
352 }
353
354 // Some graphic objects are BOARD_CONNECTED_ITEM, but they are seen here as
355 // actually board connected objects only if on a copper layer
356 const BOARD_CONNECTED_ITEM* conItem = nullptr;
357
358 if( aItem->IsConnected() && aItem->IsOnCopperLayer() )
359 conItem = static_cast<const BOARD_CONNECTED_ITEM*>( aItem );
360
361 // Try to obtain the netcode for the aItem
362 if( conItem )
363 netCode = conItem->GetNetCode();
364
365 bool highlighted = m_highlightEnabled && m_highlightNetcodes.count( netCode );
366 bool selected = aItem->IsSelected();
367
368 // Apply net color overrides
369 if( conItem && m_netColorMode == NET_COLOR_MODE::ALL && IsCopperLayer( aLayer ) )
370 {
371 COLOR4D netColor = COLOR4D::UNSPECIFIED;
372
373 auto ii = m_netColors.find( netCode );
374
375 if( ii != m_netColors.end() )
376 netColor = ii->second;
377
378 if( netColor == COLOR4D::UNSPECIFIED )
379 {
380 const NETCLASS* nc = conItem->GetEffectiveNetClass();
381
382 if( nc->HasPcbColor() )
383 netColor = nc->GetPcbColor();
384 }
385
386 if( netColor == COLOR4D::UNSPECIFIED )
387 netColor = color;
388
389 if( selected )
390 {
391 // Selection brightening overrides highlighting
392 netColor.Brighten( m_selectFactor );
393 }
394 else if( m_highlightEnabled )
395 {
396 // Highlight brightens objects on all layers and darkens everything else for contrast
397 if( highlighted )
398 netColor.Brighten( m_highlightFactor );
399 else
400 netColor.Darken( 1.0 - m_highlightFactor );
401 }
402
403 color = netColor;
404 }
405 else if( !selected && m_highlightEnabled )
406 {
407 // Single net highlight mode
408 if( m_highlightNetcodes.contains( netCode ) )
409 {
410 auto it_hi = m_layerColorsHi.find( aLayer );
411 color = it_hi == m_layerColorsHi.end() ? color.Brightened( m_highlightFactor ) : it_hi->second;
412 }
413 else
414 {
415 auto it_dark = m_layerColorsDark.find( aLayer );
416 color = it_dark == m_layerColorsDark.end() ? color.Darkened( 1.0 - m_highlightFactor ) : it_dark->second;
417 }
418 }
419
420 // Apply high-contrast dimming
421 if( m_hiContrastEnabled && m_highContrastLayers.size() && !highlighted && !selected )
422 {
424 bool isActive = m_highContrastLayers.count( aLayer );
425 bool hide = false;
426
427 switch( originalLayer )
428 {
429 case LAYER_PADS:
430 {
431 const PAD* pad = static_cast<const PAD*>( aItem );
432
433 if( pad->IsOnLayer( primary ) && !pad->FlashLayer( primary ) )
434 {
435 isActive = false;
436
437 if( IsCopperLayer( primary ) )
438 hide = true;
439 }
440
442 isActive = false;
443
444 break;
445 }
446
447 case LAYER_VIA_BLIND:
448 case LAYER_VIA_BURIED:
450 {
451 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
452
453 // Target graphic is active if the via crosses the primary layer
454 if( via->GetLayerSet().test( primary ) == 0 )
455 {
456 isActive = false;
457 hide = true;
458 }
459
460 break;
461 }
462
464 {
465 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
466
467 if( !via->FlashLayer( primary ) )
468 {
469 isActive = false;
470
471 if( IsCopperLayer( primary ) )
472 hide = true;
473 }
474
475 break;
476 }
477
481 // Pad holes are active is any physical layer is active
482 if( LSET::PhysicalLayersMask().test( primary ) == 0 )
483 isActive = false;
484
485 break;
486
487 case LAYER_VIA_HOLES:
489 {
490 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
491
492 if( via->GetViaType() == VIATYPE::THROUGH )
493 {
494 // A through via's hole is active if any physical layer is active
495 if( LSET::PhysicalLayersMask().test( primary ) == 0 )
496 isActive = false;
497 }
498 else
499 {
500 // A blind/buried or micro via's hole is active if it crosses the primary layer
501 if( via->GetLayerSet().test( primary ) == 0 )
502 isActive = false;
503 }
504
505 break;
506 }
507
508 case LAYER_DRC_ERROR:
511 case LAYER_DRC_SHAPES:
512 isActive = true;
513 break;
514
515 default:
516 break;
517 }
518
519 if( !isActive )
520 {
521 // Graphics on Edge_Cuts layer are not fully dimmed or hidden because they are
522 // useful when working on another layer
523 // We could use a dim factor = m_hiContrastFactor, but to have a sufficient
524 // contrast whenever m_hiContrastFactor value, we clamp the factor to 0.3f
525 // (arbitray choice after tests)
526 float dim_factor_Edge_Cuts = std::max( m_hiContrastFactor, 0.3f );
527
529 || IsNetnameLayer( aLayer )
530 || hide )
531 {
532 if( originalLayer == Edge_Cuts )
533 {
535
536 if( it != m_layerColors.end() )
537 color = color.Mix( it->second, dim_factor_Edge_Cuts );
538 else
539 color = color.Mix( COLOR4D::BLACK, dim_factor_Edge_Cuts );
540 }
541 else
542 color = COLOR4D::CLEAR;
543 }
544 else
545 {
547 COLOR4D backgroundColor = it == m_layerColors.end() ? COLOR4D::BLACK : it->second;
548
549 if( originalLayer == Edge_Cuts )
550 color = color.Mix( backgroundColor, dim_factor_Edge_Cuts );
551 else
552 color = color.Mix( backgroundColor, m_hiContrastFactor );
553
554 // Reference images can't have their color mixed so just reduce the opacity a bit
555 // so they show through less
556 if( aItem->Type() == PCB_REFERENCE_IMAGE_T )
557 color.a *= m_hiContrastFactor;
558 }
559 }
560 }
561 else if( originalLayer == LAYER_VIA_BLIND
562 || originalLayer == LAYER_VIA_BURIED
563 || originalLayer == LAYER_VIA_MICROVIA )
564 {
565 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
566 const BOARD* board = via->GetBoard();
567 LSET visibleLayers = board->GetVisibleLayers() & board->GetEnabledLayers();
568
569 // Target graphic is visible if the via crosses a visible layer
570 if( ( via->GetLayerSet() & visibleLayers ).none() )
571 color = COLOR4D::CLEAR;
572 }
573
574 // Apply per-type opacity overrides
575 if( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_ARC_T )
576 color.a *= m_trackOpacity;
577 else if( aItem->Type() == PCB_VIA_T )
578 color.a *= m_viaOpacity;
579 else if( aItem->Type() == PCB_PAD_T )
580 color.a *= m_padOpacity;
581 else if( aItem->Type() == PCB_ZONE_T && static_cast<const ZONE*>( aItem )->IsTeardropArea() )
582 color.a *= m_trackOpacity;
583 else if( aItem->Type() == PCB_ZONE_T )
584 color.a *= m_zoneOpacity;
585 else if( aItem->Type() == PCB_REFERENCE_IMAGE_T )
586 color.a *= m_imageOpacity;
587 else if( aItem->Type() == PCB_SHAPE_T && static_cast<const PCB_SHAPE*>( aItem )->IsAnyFill() )
588 color.a *= m_filledShapeOpacity;
589 else if( aItem->Type() == PCB_SHAPE_T && aItem->IsOnCopperLayer() )
590 color.a *= m_trackOpacity;
591
592 if( aItem->GetForcedTransparency() > 0.0 )
593 color = color.WithAlpha( color.a * ( 1.0 - aItem->GetForcedTransparency() ) );
594
595 // No special modifiers enabled
596 return color;
597}
598
599
604
605
607 PAINTER( aGal ),
608 m_frameType( aFrameType ),
612{
613}
614
615
616int PCB_PAINTER::getLineThickness( int aActualThickness ) const
617{
618 // if items have 0 thickness, draw them with the outline
619 // width, otherwise respect the set value (which, no matter
620 // how small will produce something)
621 if( aActualThickness == 0 )
622 return m_pcbSettings.m_outlineWidth;
623
624 return aActualThickness;
625}
626
627
629{
630 return aPad->GetDrillShape();
631}
632
633
635{
636 SHAPE_SEGMENT segm = *aPad->GetEffectiveHoleShape().get();
637 return segm;
638}
639
640
641int PCB_PAINTER::getViaDrillSize( const PCB_VIA* aVia ) const
642{
643 return aVia->GetDrillValue();
644}
645
646
647bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
648{
649 if( !aItem->IsBOARD_ITEM() )
650 return false;
651
652 const BOARD_ITEM* item = static_cast<const BOARD_ITEM*>( aItem );
653
654 if( const BOARD* board = item->GetBoard() )
655 {
656 BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
660
661 if( item->GetParentFootprint() && !board->IsFootprintHolder() )
662 {
663 FOOTPRINT* parentFP = item->GetParentFootprint();
664
665 // Never draw footprint reference images on board
666 if( item->Type() == PCB_REFERENCE_IMAGE_T )
667 {
668 return false;
669 }
670 else if( item->GetLayerSet().count() > 1 )
671 {
672 // For multi-layer objects, exclude only those layers that are private
673 if( IsPcbLayer( aLayer ) && parentFP->GetPrivateLayers().test( aLayer ) )
674 return false;
675 }
676 else if( item->GetLayerSet().count() == 1 )
677 {
678 // For single-layer objects, exclude all layers including ancillary layers
679 // such as holes, netnames, etc.
680 PCB_LAYER_ID singleLayer = item->GetLayerSet().ExtractLayer();
681
682 if( parentFP->GetPrivateLayers().test( singleLayer ) )
683 return false;
684 }
685 }
686 }
687 else
688 {
691 }
692
693 // the "cast" applied in here clarifies which overloaded draw() is called
694 switch( item->Type() )
695 {
696 case PCB_TRACE_T:
697 draw( static_cast<const PCB_TRACK*>( item ), aLayer );
698 break;
699
700 case PCB_ARC_T:
701 draw( static_cast<const PCB_ARC*>( item ), aLayer );
702 break;
703
704 case PCB_VIA_T:
705 draw( static_cast<const PCB_VIA*>( item ), aLayer );
706 break;
707
708 case PCB_PAD_T:
709 draw( static_cast<const PAD*>( item ), aLayer );
710 break;
711
712 case PCB_SHAPE_T:
713 draw( static_cast<const PCB_SHAPE*>( item ), aLayer );
714 break;
715
717 draw( static_cast<const PCB_REFERENCE_IMAGE*>( item ), aLayer );
718 break;
719
720 case PCB_FIELD_T:
721 draw( static_cast<const PCB_FIELD*>( item ), aLayer );
722 break;
723
724 case PCB_TEXT_T:
725 draw( static_cast<const PCB_TEXT*>( item ), aLayer );
726 break;
727
728 case PCB_TEXTBOX_T:
729 draw( static_cast<const PCB_TEXTBOX*>( item ), aLayer );
730 break;
731
732 case PCB_TABLE_T:
733 draw( static_cast<const PCB_TABLE*>( item ), aLayer );
734 break;
735
736 case PCB_FOOTPRINT_T:
737 draw( static_cast<const FOOTPRINT*>( item ), aLayer );
738 break;
739
740 case PCB_GROUP_T:
741 draw( static_cast<const PCB_GROUP*>( item ), aLayer );
742 break;
743
744 case PCB_ZONE_T:
745 draw( static_cast<const ZONE*>( item ), aLayer );
746 break;
747
749 case PCB_DIM_CENTER_T:
750 case PCB_DIM_RADIAL_T:
752 case PCB_DIM_LEADER_T:
753 draw( static_cast<const PCB_DIMENSION_BASE*>( item ), aLayer );
754 break;
755
756 case PCB_BARCODE_T:
757 draw( static_cast<const PCB_BARCODE*>( item ), aLayer );
758 break;
759
760 case PCB_TARGET_T:
761 draw( static_cast<const PCB_TARGET*>( item ) );
762 break;
763
764 case PCB_POINT_T:
765 draw( static_cast<const PCB_POINT*>( item ), aLayer );
766 break;
767
768 case PCB_MARKER_T:
769 draw( static_cast<const PCB_MARKER*>( item ), aLayer );
770 break;
771
773 draw( static_cast<const PCB_BOARD_OUTLINE*>( item ), aLayer );
774 break;
775
776 default:
777 // Painter does not know how to draw the object
778 return false;
779 }
780
781 // Draw bounding boxes after drawing objects so they can be seen.
782 if( m_pcbSettings.GetDrawBoundingBoxes() )
783 {
784 // Show bounding boxes of painted objects for debugging.
785 BOX2I box = item->GetBoundingBox();
786
787 m_gal->SetIsFill( false );
788 m_gal->SetIsStroke( true );
789
790 if( item->Type() == PCB_FOOTPRINT_T )
791 {
792 m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
793 COLOR4D( MAGENTA ) );
794 }
795 else
796 {
797 m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
798 COLOR4D( 0.4, 0.4, 0.4, 1 ) );
799 }
800
801 m_gal->SetLineWidth( 1 );
802 m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
803
804 if( item->Type() == PCB_FOOTPRINT_T )
805 {
806 m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
807 COLOR4D( CYAN ) );
808
809 const FOOTPRINT* fp = static_cast<const FOOTPRINT*>( item );
810
811 if( fp )
812 {
813 const SHAPE_POLY_SET& convex = fp->GetBoundingHull();
814
815 m_gal->DrawPolyline( convex.COutline( 0 ) );
816 }
817 }
818 }
819
820 return true;
821}
822
823
824void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
825{
826 VECTOR2I start( aTrack->GetStart() );
827 VECTOR2I end( aTrack->GetEnd() );
828 int track_width = aTrack->GetWidth();
829 COLOR4D color = m_pcbSettings.GetColor( aTrack, aLayer );
830
831 // If a chain highlight is active and the track belongs to the highlighted
832 // chain, and the chain has a colour override configured on the board,
833 // prefer that colour. Only do this when we're drawing the actual copper
834 // (not netname labels, clearance outlines, etc.).
835 if( IsCopperLayer( aLayer ) && !m_pcbSettings.m_highlightedNetChain.IsEmpty() )
836 {
837 if( NETINFO_ITEM* netinfo = aTrack->GetNet() )
838 {
839 if( netinfo->GetNetChain() == m_pcbSettings.m_highlightedNetChain )
840 {
841 if( const BOARD* board = aTrack->GetBoard() )
842 {
843 COLOR4D chainColor =
844 board->GetNetChainColor( m_pcbSettings.m_highlightedNetChain );
845
846 if( chainColor != COLOR4D::UNSPECIFIED )
847 color = chainColor.WithAlpha( color.a );
848 }
849 }
850 }
851 }
852
853 if( IsNetnameLayer( aLayer ) )
854 {
855 if( !pcbconfig() || pcbconfig()->m_Display.m_NetNames < 2 )
856 return;
857
858 if( aTrack->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
859 return;
860
861 SHAPE_SEGMENT trackShape( { aTrack->GetStart(), aTrack->GetEnd() }, aTrack->GetWidth() );
862 renderNetNameForSegment( trackShape, color, aTrack->GetDisplayNetname() );
863 return;
864 }
865 else if( IsCopperLayer( aLayer ) || IsSolderMaskLayer( aLayer )
866 || aLayer == LAYER_LOCKED_ITEM_SHADOW )
867 {
868 // Draw a regular track
869 bool outline_mode = pcbconfig()
871 && aLayer != LAYER_LOCKED_ITEM_SHADOW;
872 m_gal->SetStrokeColor( color );
873 m_gal->SetFillColor( color );
874 m_gal->SetIsStroke( outline_mode );
875 m_gal->SetIsFill( not outline_mode );
876 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
877
878 if( IsSolderMaskLayer( aLayer ) )
879 track_width = track_width + aTrack->GetSolderMaskExpansion() * 2;
880
881 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
882 track_width = track_width + m_lockedShadowMargin;
883
884 m_gal->DrawSegment( start, end, track_width );
885 }
886
887 // Clearance lines
888 if( IsClearanceLayer( aLayer ) && pcbconfig()
889 && pcbconfig()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
890 && !m_pcbSettings.m_isPrinting )
891 {
892 const PCB_LAYER_ID copperLayerForClearance = ToLAYER_ID( aLayer - LAYER_CLEARANCE_START );
893
894 int clearance = aTrack->GetOwnClearance( copperLayerForClearance );
895
896 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
897 m_gal->SetIsFill( false );
898 m_gal->SetIsStroke( true );
899 m_gal->SetStrokeColor( color );
900 m_gal->DrawSegment( start, end, track_width + clearance * 2 );
901 }
902}
903
904
906 const wxString& aNetName ) const
907{
908 // When drawing netnames, clip the track to the viewport
909 BOX2D viewport;
910 VECTOR2D screenSize = m_gal->GetScreenPixelSize();
911 const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
912
913 viewport.SetOrigin( VECTOR2D( matrix * VECTOR2D( 0, 0 ) ) );
914 viewport.SetEnd( VECTOR2D( matrix * screenSize ) );
915 viewport.Normalize();
916
917 int num_char = aNetName.size();
918
919 // Check if the track is long enough to have a netname displayed
920 int seg_minlength = aSeg.GetWidth() * num_char;
921 SEG::ecoord seg_minlength_sq = (SEG::ecoord)seg_minlength * seg_minlength;
922
923 if( aSeg.GetSeg().SquaredLength() < seg_minlength_sq )
924 return;
925
926 double textSize = aSeg.GetWidth();
927 double penWidth = textSize / 12.0;
928 EDA_ANGLE textOrientation;
929 int num_names = 1;
930
931 VECTOR2I start = aSeg.GetSeg().A;
932 VECTOR2I end = aSeg.GetSeg().B;
933 VECTOR2D segV = end - start;
934
935 if( end.y == start.y ) // horizontal
936 {
937 textOrientation = ANGLE_HORIZONTAL;
938 num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / viewport.GetWidth() ) );
939 }
940 else if( end.x == start.x ) // vertical
941 {
942 textOrientation = ANGLE_VERTICAL;
943 num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / viewport.GetHeight() ) );
944 }
945 else
946 {
947 textOrientation = -EDA_ANGLE( segV );
948 textOrientation.Normalize90();
949
950 double min_size = std::min( viewport.GetWidth(), viewport.GetHeight() );
951 num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / ( M_SQRT2 * min_size ) ) );
952 }
953
954 m_gal->SetIsStroke( true );
955 m_gal->SetIsFill( false );
956 m_gal->SetStrokeColor( aColor );
957 m_gal->SetLineWidth( penWidth );
958 m_gal->SetFontBold( false );
959 m_gal->SetFontItalic( false );
960 m_gal->SetFontUnderlined( false );
961 m_gal->SetTextMirrored( false );
962 m_gal->SetGlyphSize( VECTOR2D( textSize * 0.55, textSize * 0.55 ) );
963 m_gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
964 m_gal->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
965
966 int divisions = num_names + 1;
967
968 for( int ii = 1; ii < divisions; ++ii )
969 {
970 VECTOR2I textPosition = start + segV * ( (double) ii / divisions );
971
972 if( viewport.Contains( textPosition ) )
973 m_gal->BitmapText( aNetName, textPosition, textOrientation );
974 }
975}
976
977
978void PCB_PAINTER::draw( const PCB_ARC* aArc, int aLayer )
979{
980 VECTOR2D center( aArc->GetCenter() );
981 int width = aArc->GetWidth();
982 COLOR4D color = m_pcbSettings.GetColor( aArc, aLayer );
983 double radius = aArc->GetRadius();
984 EDA_ANGLE start_angle = aArc->GetArcAngleStart();
985 EDA_ANGLE angle = aArc->GetAngle();
986
987 if( IsNetnameLayer( aLayer ) )
988 {
989 if( !pcbconfig() || pcbconfig()->m_Display.m_NetNames < 2 )
990 return;
991
993 return;
994
995 wxString netname = aArc->GetDisplayNetname();
996
997 if( netname.IsEmpty() )
998 return;
999
1000 // Arc length must accommodate the label width.
1001 double arcLen = std::abs( radius * angle.AsRadians() );
1002
1003 if( arcLen < (double) width * (double) netname.size() )
1004 return;
1005
1006 // Tangent at the arc midpoint is perpendicular to the radius there.
1007 VECTOR2I midPt = aArc->GetMid();
1008 VECTOR2D radial = midPt - aArc->GetCenter();
1009 EDA_ANGLE textOrientation( VECTOR2D( -radial.y, radial.x ) );
1010 textOrientation = -textOrientation;
1011 textOrientation.Normalize90();
1012
1013 double textSize = width;
1014 double penWidth = textSize / 12.0;
1015
1016 m_gal->SetIsStroke( true );
1017 m_gal->SetIsFill( false );
1018 m_gal->SetStrokeColor( color );
1019 m_gal->SetLineWidth( penWidth );
1020 m_gal->SetFontBold( false );
1021 m_gal->SetFontItalic( false );
1022 m_gal->SetFontUnderlined( false );
1023 m_gal->SetTextMirrored( false );
1024 m_gal->SetGlyphSize( VECTOR2D( textSize * 0.55, textSize * 0.55 ) );
1025 m_gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
1026 m_gal->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
1027
1028 m_gal->BitmapText( netname, midPt, textOrientation );
1029 return;
1030 }
1031 else if( IsCopperLayer( aLayer ) || IsSolderMaskLayer( aLayer ) || aLayer == LAYER_LOCKED_ITEM_SHADOW )
1032 {
1033 // Draw a regular track
1034 bool outline_mode = pcbconfig()
1036 && aLayer != LAYER_LOCKED_ITEM_SHADOW;
1037 m_gal->SetStrokeColor( color );
1038 m_gal->SetFillColor( color );
1039 m_gal->SetIsStroke( outline_mode );
1040 m_gal->SetIsFill( not outline_mode );
1041 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
1042
1043 if( IsSolderMaskLayer( aLayer ) )
1044 width = width + aArc->GetSolderMaskExpansion() * 2;
1045
1046 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
1047 width = width + m_lockedShadowMargin;
1048
1049 m_gal->DrawArcSegment( center, radius, start_angle, angle, width, m_maxError );
1050 }
1051
1052 // Clearance lines
1053 if( IsClearanceLayer( aLayer )
1054 && pcbconfig() && pcbconfig()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
1055 && !m_pcbSettings.m_isPrinting )
1056 {
1057 /*
1058 * Showing the clearance area is not obvious for optionally-flashed pads and vias, so we
1059 * choose to not display clearance lines at all on non-copper active layers. We follow
1060 * the same rule for tracks to be consistent (even though they don't have the same issue).
1061 */
1062 const PCB_LAYER_ID activeLayer = m_pcbSettings.GetActiveLayer();
1063 const BOARD& board = *aArc->GetBoard();
1064
1065 if( IsCopperLayer( activeLayer ) && board.GetVisibleLayers().test( activeLayer ) )
1066 {
1067 int clearance = aArc->GetOwnClearance( activeLayer );
1068
1069 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
1070 m_gal->SetIsFill( false );
1071 m_gal->SetIsStroke( true );
1072 m_gal->SetStrokeColor( color );
1073
1074 m_gal->DrawArcSegment( center, radius, start_angle, angle, width + clearance * 2, m_maxError );
1075 }
1076 }
1077
1078#if 0
1079 // Debug only: enable this code only to test the TransformArcToPolygon function and display the polygon
1080 // outline created by it.
1081 // arcs on F_Cu are approximated with ERROR_INSIDE, others with ERROR_OUTSIDE
1082 SHAPE_POLY_SET cornerBuffer;
1084 TransformArcToPolygon( cornerBuffer, aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(), width,
1085 m_maxError, errorloc );
1086 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
1087 m_gal->SetIsFill( false );
1088 m_gal->SetIsStroke( true );
1089 m_gal->SetStrokeColor( COLOR4D( 0, 0, 1.0, 1.0 ) );
1090 m_gal->DrawPolygon( cornerBuffer );
1091#endif
1092
1093#if 0
1094 // Debug only: enable this code only to test the arc geometry.
1095 // Draw 3 lines from arc center to arc start, arc middle, arc end to show how the arc is defined
1096 SHAPE_ARC arc( aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(), m_pcbSettings.m_outlineWidth );
1097 m_gal->SetIsFill( false );
1098 m_gal->SetIsStroke( true );
1099 m_gal->SetStrokeColor( COLOR4D( 0, 0, 1.0, 1.0 ) );
1100 m_gal->DrawSegment( arc.GetStart(), arc.GetCenter(), m_pcbSettings.m_outlineWidth );
1101 m_gal->DrawSegment( aArc->GetFocusPosition(), arc.GetCenter(), m_pcbSettings.m_outlineWidth );
1102 m_gal->DrawSegment( arc.GetEnd(), arc.GetCenter(), m_pcbSettings.m_outlineWidth );
1103#endif
1104
1105#if 0
1106 // Debug only: enable this code only to test the SHAPE_ARC::ConvertToPolyline function and display the
1107 // polyline created by it.
1108 SHAPE_ARC arc( aArc->GetCenter(), aArc->GetStart(), aArc->GetAngle(), aArc->GetWidth() );
1110 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
1111 m_gal->SetIsFill( false );
1112 m_gal->SetIsStroke( true );
1113 m_gal->SetStrokeColor( COLOR4D( 0.3, 0.2, 0.5, 1.0 ) );
1114
1115 for( int idx = 1; idx < arcSpine.PointCount(); idx++ )
1116 m_gal->DrawSegment( arcSpine.CPoint( idx-1 ), arcSpine.CPoint( idx ), aArc->GetWidth() );
1117#endif
1118}
1119
1120
1121void PCB_PAINTER::draw( const PCB_VIA* aVia, int aLayer )
1122{
1123 const BOARD* board = aVia->GetBoard();
1124 COLOR4D color = m_pcbSettings.GetColor( aVia, aLayer );
1125 VECTOR2D center( aVia->GetStart() );
1126
1127 if( color == COLOR4D::CLEAR )
1128 return;
1129
1130 // Chain highlight colour override for copper/hole layers.
1131 if( board && !m_pcbSettings.m_highlightedNetChain.IsEmpty()
1132 && ( IsCopperLayer( aLayer ) || IsViaCopperLayer( aLayer )
1133 || aLayer == LAYER_VIA_HOLES ) )
1134 {
1135 if( NETINFO_ITEM* netinfo = aVia->GetNet() )
1136 {
1137 if( netinfo->GetNetChain() == m_pcbSettings.m_highlightedNetChain )
1138 {
1139 COLOR4D chainColor =
1140 board->GetNetChainColor( m_pcbSettings.m_highlightedNetChain );
1141
1142 if( chainColor != COLOR4D::UNSPECIFIED )
1143 color = chainColor.WithAlpha( color.a );
1144 }
1145 }
1146 }
1147
1148 const int copperLayer = IsViaCopperLayer( aLayer ) ? aLayer - LAYER_VIA_COPPER_START : aLayer;
1149
1150 PCB_LAYER_ID currentLayer = ToLAYER_ID( copperLayer );
1151 PCB_LAYER_ID layerTop, layerBottom;
1152 aVia->LayerPair( &layerTop, &layerBottom );
1153
1154 // Blind/buried vias (and microvias) will use different hole and label rendering
1155 bool isBlindBuried = aVia->GetViaType() == VIATYPE::BLIND
1156 || aVia->GetViaType() == VIATYPE::BURIED
1157 || ( aVia->GetViaType() == VIATYPE::MICROVIA
1158 && ( layerTop != F_Cu || layerBottom != B_Cu ) );
1159
1160 // Draw description layer
1161 if( IsNetnameLayer( aLayer ) )
1162 {
1163 VECTOR2D position( center );
1164
1165 // Is anything that we can display enabled (netname and/or layers ids)?
1166 bool showNets = pcbconfig() && pcbconfig()->m_Display.m_NetNames != 0
1167 && !aVia->GetNetname().empty();
1168 bool showLayers = aVia->GetViaType() != VIATYPE::THROUGH;
1169
1170 if( !showNets && !showLayers )
1171 return;
1172
1173 double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
1174 double size = aVia->GetWidth( currentLayer );
1175
1176 // Font size limits
1177 if( size > maxSize )
1178 size = maxSize;
1179
1180 m_gal->Save();
1181 m_gal->Translate( position );
1182
1183 // Default font settings
1184 m_gal->ResetTextAttributes();
1185 m_gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
1186 m_gal->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
1187 m_gal->SetFontBold( false );
1188 m_gal->SetFontItalic( false );
1189 m_gal->SetFontUnderlined( false );
1190 m_gal->SetTextMirrored( false );
1191 m_gal->SetStrokeColor( m_pcbSettings.GetColor( aVia, aLayer ) );
1192 m_gal->SetIsStroke( true );
1193 m_gal->SetIsFill( false );
1194
1195 // Set the text position via position. if only one text, it is on the via position
1196 // For 2 lines, the netname is slightly below the center, and the layer IDs above
1197 // the netname
1198 VECTOR2D textpos( 0.0, 0.0 );
1199
1200 wxString netname = aVia->GetDisplayNetname();
1201
1202 PCB_LAYER_ID topLayerId = aVia->TopLayer();
1203 PCB_LAYER_ID bottomLayerId = aVia->BottomLayer();
1204 int topLayer; // The via top layer number (from 1 to copper layer count)
1205 int bottomLayer; // The via bottom layer number (from 1 to copper layer count)
1206
1207 switch( topLayerId )
1208 {
1209 case F_Cu: topLayer = 1; break;
1210 case B_Cu: topLayer = board->GetCopperLayerCount(); break;
1211 default: topLayer = (topLayerId - B_Cu)/2 + 1; break;
1212 }
1213
1214 switch( bottomLayerId )
1215 {
1216 case F_Cu: bottomLayer = 1; break;
1217 case B_Cu: bottomLayer = board->GetCopperLayerCount(); break;
1218 default: bottomLayer = (bottomLayerId - B_Cu)/2 + 1; break;
1219 }
1220
1221 wxString layerIds;
1222#if wxUSE_UNICODE_WCHAR
1223 layerIds << std::to_wstring( topLayer ) << L'-' << std::to_wstring( bottomLayer );
1224#else
1225 layerIds << std::to_string( topLayer ) << '-' << std::to_string( bottomLayer );
1226#endif
1227
1228 // a good size is set room for at least 6 chars, to be able to print 2 lines of text,
1229 // or at least 3 chars for only the netname
1230 // (The layerIds string has 5 chars max)
1231 int minCharCnt = showLayers ? 6 : 3;
1232
1233 // approximate the size of netname and layerIds text:
1234 double tsize = 1.5 * size / std::max( PrintableCharCount( netname ), minCharCnt );
1235 tsize = std::min( tsize, size );
1236
1237 // Use a smaller text size to handle interline, pen size..
1238 tsize *= 0.75;
1239 VECTOR2D namesize( tsize, tsize );
1240
1241 // For 2 lines, adjust the text pos (move it a small amount to the bottom)
1242 if( showLayers && showNets )
1243 textpos.y += ( tsize * 1.3 )/ 2;
1244
1245 m_gal->SetGlyphSize( namesize );
1246 m_gal->SetLineWidth( namesize.x / 10.0 );
1247
1248 if( showNets )
1249 m_gal->BitmapText( netname, textpos, ANGLE_HORIZONTAL );
1250
1251 if( showLayers )
1252 {
1253 if( showNets )
1254 textpos.y -= tsize * 1.3;
1255
1256 m_gal->BitmapText( layerIds, textpos, ANGLE_HORIZONTAL );
1257 }
1258
1259 m_gal->Restore();
1260
1261 return;
1262 }
1263
1264 bool outline_mode = pcbconfig() && !pcbconfig()->m_Display.m_DisplayViaFill;
1265
1266 m_gal->SetStrokeColor( color );
1267 m_gal->SetFillColor( color );
1268 m_gal->SetIsStroke( true );
1269 m_gal->SetIsFill( false );
1270
1271 if( outline_mode )
1272 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
1273
1274 if( aLayer == LAYER_VIA_HOLEWALLS )
1275 {
1276 double thickness =
1278 double drillRadius = getViaDrillSize( aVia ) / 2.0;
1279 double maxRadius = aVia->GetWidth( layerTop ) / 2.0;
1280 double radius = drillRadius + thickness;
1281
1282 // Clamp the hole wall so it doesn't extend beyond the via's copper
1283 if( radius > maxRadius )
1284 {
1285 radius = maxRadius;
1286 thickness = radius - drillRadius;
1287 }
1288
1289 if( thickness <= 0 )
1290 return;
1291
1292 if( !outline_mode )
1293 {
1294 m_gal->SetLineWidth( thickness );
1295 radius -= thickness / 2.0;
1296 }
1297
1298 // Underpaint the hole so that there aren't artifacts at its edge
1299 m_gal->SetIsFill( true );
1300
1301 m_gal->DrawCircle( center, radius );
1302
1303 // Draw backdrill indicators (semi-circles extending into the hole) on top of the
1304 // hole wall so they remain visible regardless of layer rendering order
1305 if( !m_pcbSettings.IsPrinting() )
1306 {
1307 std::optional<int> secDrill = aVia->GetSecondaryDrillSize();
1308 std::optional<int> terDrill = aVia->GetTertiaryDrillSize();
1309
1310 if( secDrill.value_or( 0 ) > 0 )
1311 {
1312 drawBackdrillIndicator( aVia, center, *secDrill,
1314 aVia->GetSecondaryDrillEndLayer() );
1315 }
1316
1317 if( terDrill.value_or( 0 ) > 0 )
1318 {
1319 drawBackdrillIndicator( aVia, center, *terDrill,
1321 aVia->GetTertiaryDrillEndLayer() );
1322 }
1323 }
1324 }
1325 else if( aLayer == LAYER_VIA_HOLES )
1326 {
1327 double radius = getViaDrillSize( aVia ) / 2.0;
1328
1329 m_gal->SetIsStroke( false );
1330 m_gal->SetIsFill( true );
1331
1332 if( isBlindBuried && !m_pcbSettings.IsPrinting() )
1333 {
1334 m_gal->SetIsStroke( false );
1335 m_gal->SetIsFill( true );
1336
1337 m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerTop ) );
1338 m_gal->DrawArc( center, radius, EDA_ANGLE( 180, DEGREES_T ),
1339 EDA_ANGLE( 180, DEGREES_T ) );
1340
1341 m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerBottom ) );
1342 m_gal->DrawArc( center, radius, EDA_ANGLE( 0, DEGREES_T ),
1343 EDA_ANGLE( 180, DEGREES_T ) );
1344 }
1345 else
1346 {
1347 m_gal->DrawCircle( center, radius );
1348 }
1349
1350 }
1351 else if( ( aLayer == F_Mask && aVia->IsOnLayer( F_Mask ) )
1352 || ( aLayer == B_Mask && aVia->IsOnLayer( B_Mask ) ) )
1353 {
1354 int margin = board->GetDesignSettings().m_SolderMaskExpansion;
1355
1356 m_gal->SetIsFill( true );
1357 m_gal->SetIsStroke( false );
1358
1359 m_gal->SetLineWidth( margin );
1360 m_gal->DrawCircle( center, aVia->GetWidth( currentLayer ) / 2.0 + margin );
1361 }
1362 else if( m_pcbSettings.IsPrinting() || IsCopperLayer( currentLayer ) )
1363 {
1364 int annular_width = ( aVia->GetWidth( currentLayer ) - getViaDrillSize( aVia ) ) / 2.0;
1365 double radius = aVia->GetWidth( currentLayer ) / 2.0;
1366 bool draw = false;
1367
1368 if( m_pcbSettings.IsPrinting() )
1369 {
1370 draw = aVia->FlashLayer( m_pcbSettings.GetPrintLayers() );
1371 }
1372 else if( aVia->IsSelected() )
1373 {
1374 draw = true;
1375 }
1376 else if( aVia->FlashLayer( board->GetVisibleLayers() & board->GetEnabledLayers() ) )
1377 {
1378 draw = true;
1379 }
1380
1381 if( !aVia->FlashLayer( currentLayer ) )
1382 draw = false;
1383
1384 if( !outline_mode )
1385 {
1386 m_gal->SetLineWidth( annular_width );
1387 radius -= annular_width / 2.0;
1388 }
1389
1390 if( draw )
1391 m_gal->DrawCircle( center, radius );
1392
1393 // Draw post-machining indicator if this layer is post-machined
1394 if( !m_pcbSettings.IsPrinting() && draw )
1395 {
1396 drawPostMachiningIndicator( aVia, center, currentLayer );
1397 }
1398 }
1399 else if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // draw a ring around the via
1400 {
1401 m_gal->SetLineWidth( m_lockedShadowMargin );
1402
1403 m_gal->DrawCircle( center, ( aVia->GetWidth( currentLayer ) + m_lockedShadowMargin ) / 2.0 );
1404 }
1405
1406 // Clearance lines
1407 if( IsClearanceLayer( aLayer ) && pcbconfig()
1408 && pcbconfig()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
1409 && !m_pcbSettings.m_isPrinting )
1410 {
1411 const PCB_LAYER_ID copperLayerForClearance = ToLAYER_ID( aLayer - LAYER_CLEARANCE_START );
1412
1413 double radius;
1414
1415 if( aVia->FlashLayer( copperLayerForClearance ) )
1416 radius = aVia->GetWidth( copperLayerForClearance ) / 2.0;
1417 else
1419
1420 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
1421 m_gal->SetIsFill( false );
1422 m_gal->SetIsStroke( true );
1423 m_gal->SetStrokeColor( color );
1424 m_gal->DrawCircle( center, radius + aVia->GetOwnClearance( copperLayerForClearance ) );
1425 }
1426}
1427
1428
1429void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
1430{
1431 COLOR4D color = m_pcbSettings.GetColor( aPad, aLayer );
1432 const int copperLayer = IsPadCopperLayer( aLayer ) ? aLayer - LAYER_PAD_COPPER_START : aLayer;
1433 PCB_LAYER_ID pcbLayer = static_cast<PCB_LAYER_ID>( copperLayer );
1434
1435 if( IsNetnameLayer( aLayer ) )
1436 {
1437 PCBNEW_SETTINGS::DISPLAY_OPTIONS* displayOpts = pcbconfig() ? &pcbconfig()->m_Display : nullptr;
1438 wxString netname;
1439 wxString padNumber;
1440
1441 if( viewer_settings()->m_ViewersDisplay.m_DisplayPadNumbers )
1442 {
1443 padNumber = UnescapeString( aPad->GetNumber() );
1444
1445 if( dynamic_cast<CVPCB_SETTINGS*>( viewer_settings() ) )
1446 netname = aPad->GetPinFunction();
1447 }
1448
1449 if( displayOpts && !dynamic_cast<CVPCB_SETTINGS*>( viewer_settings() ) )
1450 {
1451 if( displayOpts->m_NetNames == 1 || displayOpts->m_NetNames == 3 )
1452 netname = aPad->GetDisplayNetname();
1453
1454 if( aPad->IsNoConnectPad() )
1455 netname = wxT( "x" );
1456 else if( aPad->IsFreePad() )
1457 netname = wxT( "*" );
1458 }
1459
1460 if( netname.IsEmpty() && padNumber.IsEmpty() )
1461 return;
1462
1463 BOX2I padBBox = aPad->GetBoundingBox();
1464 VECTOR2D position = padBBox.Centre();
1465 VECTOR2D padsize = VECTOR2D( padBBox.GetSize() );
1466
1467 if( aPad->IsEntered() )
1468 {
1469 FOOTPRINT* fp = aPad->GetParentFootprint();
1470
1471 // Find the number box
1472 for( const BOARD_ITEM* aItem : fp->GraphicalItems() )
1473 {
1474 if( aItem->Type() == PCB_SHAPE_T )
1475 {
1476 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aItem );
1477
1478 if( shape->IsProxyItem() && shape->GetShape() == SHAPE_T::RECTANGLE )
1479 {
1480 position = shape->GetCenter();
1481 padsize = shape->GetBotRight() - shape->GetTopLeft();
1482
1483 // We normally draw a bit outside the pad, but this will be somewhat
1484 // unexpected when the user has drawn a box.
1485 padsize *= 0.9;
1486
1487 break;
1488 }
1489 }
1490 }
1491 }
1492 else if( aPad->GetShape( pcbLayer ) == PAD_SHAPE::CUSTOM )
1493 {
1494 // See if we have a number box
1495 for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives( pcbLayer ) )
1496 {
1497 if( primitive->IsProxyItem() && primitive->GetShape() == SHAPE_T::RECTANGLE )
1498 {
1499 position = primitive->GetCenter();
1500 RotatePoint( position, aPad->GetOrientation() );
1501 position += aPad->ShapePos( pcbLayer );
1502
1503 padsize.x = abs( primitive->GetBotRight().x - primitive->GetTopLeft().x );
1504 padsize.y = abs( primitive->GetBotRight().y - primitive->GetTopLeft().y );
1505
1506 // We normally draw a bit outside the pad, but this will be somewhat
1507 // unexpected when the user has drawn a box.
1508 padsize *= 0.9;
1509
1510 break;
1511 }
1512 }
1513 }
1514
1515 if( aPad->GetShape( pcbLayer ) != PAD_SHAPE::CUSTOM )
1516 {
1517 // Don't allow a 45° rotation to bloat a pad's bounding box unnecessarily
1518 double limit = std::min( aPad->GetSize( pcbLayer ).x,
1519 aPad->GetSize( pcbLayer ).y ) * 1.1;
1520
1521 if( padsize.x > limit && padsize.y > limit )
1522 {
1523 padsize.x = limit;
1524 padsize.y = limit;
1525 }
1526 }
1527
1528 double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
1529 double size = padsize.y;
1530
1531 m_gal->Save();
1532 m_gal->Translate( position );
1533
1534 // Keep the size ratio for the font, but make it smaller
1535 if( padsize.x < ( padsize.y * 0.95 ) )
1536 {
1537 m_gal->Rotate( -ANGLE_90.AsRadians() );
1538 size = padsize.x;
1539 std::swap( padsize.x, padsize.y );
1540 }
1541
1542 // Font size limits
1543 if( size > maxSize )
1544 size = maxSize;
1545
1546 // Default font settings
1547 m_gal->ResetTextAttributes();
1548 m_gal->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
1549 m_gal->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
1550 m_gal->SetFontBold( false );
1551 m_gal->SetFontItalic( false );
1552 m_gal->SetFontUnderlined( false );
1553 m_gal->SetTextMirrored( false );
1554 m_gal->SetStrokeColor( m_pcbSettings.GetColor( aPad, aLayer ) );
1555 m_gal->SetIsStroke( true );
1556 m_gal->SetIsFill( false );
1557
1558 // We have already translated the GAL to be centered at the center of the pad's
1559 // bounding box
1560 VECTOR2I textpos( 0, 0 );
1561
1562 // Divide the space, to display both pad numbers and netnames and set the Y text
1563 // offset position to display 2 lines
1564 int Y_offset_numpad = 0;
1565 int Y_offset_netname = 0;
1566
1567 if( !netname.IsEmpty() && !padNumber.IsEmpty() )
1568 {
1569 // The magic numbers are defined experimentally for a better look.
1570 size = size / 2.5;
1571 Y_offset_netname = size / 1.4; // netname size is usually smaller than num pad
1572 // so the offset can be smaller
1573 Y_offset_numpad = size / 1.7;
1574 }
1575
1576 // We are using different fonts to display names, depending on the graphic
1577 // engine (OpenGL or Cairo).
1578 // Xscale_for_stroked_font adjust the text X size for cairo (stroke fonts) engine
1579 const double Xscale_for_stroked_font = 0.9;
1580
1581 if( !netname.IsEmpty() )
1582 {
1583 // approximate the size of net name text:
1584 // We use a size for at least 5 chars, to give a good look even for short names
1585 // (like VCC, GND...)
1586 double tsize = 1.5 * padsize.x / std::max( PrintableCharCount( netname )+1, 5 );
1587 tsize = std::min( tsize, size );
1588
1589 // Use a smaller text size to handle interline, pen size...
1590 tsize *= 0.85;
1591
1592 // Round and oval pads have less room to display the net name than other
1593 // (i.e RECT) shapes, so reduce the text size for these shapes
1594 if( aPad->GetShape( pcbLayer ) == PAD_SHAPE::CIRCLE
1595 || aPad->GetShape( pcbLayer ) == PAD_SHAPE::OVAL )
1596 {
1597 tsize *= 0.9;
1598 }
1599
1600 VECTOR2D namesize( tsize*Xscale_for_stroked_font, tsize );
1601 textpos.y = std::min( tsize * 1.4, double( Y_offset_netname ) );
1602
1603 m_gal->SetGlyphSize( namesize );
1604 m_gal->SetLineWidth( namesize.x / 6.0 );
1605 m_gal->SetFontBold( true );
1606 m_gal->BitmapText( netname, textpos, ANGLE_HORIZONTAL );
1607 }
1608
1609 if( !padNumber.IsEmpty() )
1610 {
1611 // approximate the size of the pad number text:
1612 // We use a size for at least 3 chars, to give a good look even for short numbers
1613 double tsize = 1.5 * padsize.x / std::max( PrintableCharCount( padNumber ), 3 );
1614 tsize = std::min( tsize, size );
1615
1616 // Use a smaller text size to handle interline, pen size...
1617 tsize *= 0.85;
1618 tsize = std::min( tsize, size );
1619 VECTOR2D numsize( tsize*Xscale_for_stroked_font, tsize );
1620 textpos.y = -Y_offset_numpad;
1621
1622 m_gal->SetGlyphSize( numsize );
1623 m_gal->SetLineWidth( numsize.x / 6.0 );
1624 m_gal->SetFontBold( true );
1625 m_gal->BitmapText( padNumber, textpos, ANGLE_HORIZONTAL );
1626 }
1627
1628 m_gal->Restore();
1629
1630 return;
1631 }
1632 else if( aLayer == LAYER_PAD_HOLEWALLS )
1633 {
1634 m_gal->SetIsFill( true );
1635 m_gal->SetIsStroke( false );
1637 double lineWidth = widthFactor * m_holePlatingThickness;
1638 lineWidth = std::min( lineWidth, aPad->GetSizeX() / 2.0 );
1639 lineWidth = std::min( lineWidth, aPad->GetSizeY() / 2.0 );
1640
1641 m_gal->SetFillColor( color );
1642 m_gal->SetMinLineWidth( lineWidth );
1643
1644 std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
1645
1646 if( slot->GetSeg().A == slot->GetSeg().B ) // Circular hole
1647 {
1648 double holeRadius = slot->GetWidth() / 2.0;
1649 m_gal->DrawHoleWall( slot->GetSeg().A, holeRadius, lineWidth );
1650 }
1651 else
1652 {
1653 int holeSize = slot->GetWidth() + ( 2 * lineWidth );
1654 m_gal->DrawSegment( slot->GetSeg().A, slot->GetSeg().B, holeSize );
1655 }
1656
1657 m_gal->SetMinLineWidth( 1.0 );
1658
1659 // Draw backdrill indicators on top of the hole wall so they remain visible
1660 // regardless of layer rendering order
1661 if( !m_pcbSettings.IsPrinting() && aPad->GetDrillSizeX() > 0 )
1662 {
1663 VECTOR2I holePos = slot->GetSeg().A;
1664 VECTOR2I secDrill = aPad->GetSecondaryDrillSize();
1665 VECTOR2I terDrill = aPad->GetTertiaryDrillSize();
1666
1667 if( secDrill.x > 0 )
1668 {
1669 drawBackdrillIndicator( aPad, holePos, secDrill.x,
1671 aPad->GetSecondaryDrillEndLayer() );
1672 }
1673
1674 if( terDrill.x > 0 )
1675 {
1676 drawBackdrillIndicator( aPad, holePos, terDrill.x,
1678 aPad->GetTertiaryDrillEndLayer() );
1679 }
1680 }
1681
1682 return;
1683 }
1684
1685 bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayPadFill;
1686
1687 if( m_pcbSettings.m_ForcePadSketchModeOn )
1688 outline_mode = true;
1689
1690 bool drawShape = false;
1691
1692 if( m_pcbSettings.IsPrinting() )
1693 {
1694 drawShape = aPad->FlashLayer( m_pcbSettings.GetPrintLayers() );
1695 }
1696 else if( ( aLayer < PCB_LAYER_ID_COUNT || IsPadCopperLayer( aLayer ) )
1697 && aPad->FlashLayer( pcbLayer ) )
1698 {
1699 drawShape = true;
1700 }
1701 else if( aPad->IsSelected() )
1702 {
1703 drawShape = true;
1704 outline_mode = true;
1705 }
1706 else if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
1707 {
1708 drawShape = true;
1709 outline_mode = false;
1710 }
1711
1712 // Plated holes are always filled as they use a solid BG fill to
1713 // draw the "hole" over the hole-wall segment/circle.
1714 if( outline_mode && aLayer != LAYER_PAD_PLATEDHOLES )
1715 {
1716 // Outline mode
1717 m_gal->SetIsFill( false );
1718 m_gal->SetIsStroke( true );
1719 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
1720 m_gal->SetStrokeColor( color );
1721 }
1722 else
1723 {
1724 // Filled mode
1725 m_gal->SetIsFill( true );
1726 m_gal->SetIsStroke( false );
1727 m_gal->SetFillColor( color );
1728 }
1729
1730 if( aLayer == LAYER_PAD_PLATEDHOLES || aLayer == LAYER_NON_PLATEDHOLES )
1731 {
1732 SHAPE_SEGMENT slot = getPadHoleShape( aPad );
1733 VECTOR2I center = slot.GetSeg().A;
1734
1735 if( slot.GetSeg().A == slot.GetSeg().B ) // Circular hole
1736 m_gal->DrawCircle( center, slot.GetWidth() / 2.0 );
1737 else
1738 m_gal->DrawSegment( slot.GetSeg().A, slot.GetSeg().B, slot.GetWidth() );
1739 }
1740 else if( drawShape )
1741 {
1742 VECTOR2I pad_size = aPad->GetSize( pcbLayer );
1743 VECTOR2I margin;
1744
1745 auto getExpansion =
1746 [&]( PCB_LAYER_ID layer )
1747 {
1748 VECTOR2I expansion;
1749
1750 switch( aLayer )
1751 {
1752 case F_Mask:
1753 case B_Mask:
1754 expansion.x = expansion.y = aPad->GetSolderMaskExpansion( layer );
1755 break;
1756
1757 case F_Paste:
1758 case B_Paste:
1759 expansion = aPad->GetSolderPasteMargin( layer );
1760 break;
1761
1762 default:
1763 expansion.x = expansion.y = 0;
1764 break;
1765 }
1766
1767 return expansion;
1768 };
1769
1770 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
1771 {
1772 LSET visibleLayers = aPad->GetBoard()->GetVisibleLayers()
1773 & aPad->GetBoard()->GetEnabledLayers()
1774 & aPad->GetLayerSet();
1775
1776 for( PCB_LAYER_ID layer : visibleLayers )
1777 margin = std::max( margin, getExpansion( layer ) );
1778
1779 margin.x += m_lockedShadowMargin / 2;
1780 margin.y += m_lockedShadowMargin / 2;
1781 }
1782 else
1783 {
1784 margin = getExpansion( pcbLayer );
1785 }
1786
1787 std::unique_ptr<PAD> dummyPad;
1788 std::shared_ptr<SHAPE_COMPOUND> shapes;
1789
1790 // Drawing components of compound shapes in outline mode produces a mess.
1791 bool simpleShapes = !outline_mode;
1792
1793 // When this layer has post-machining (counterbore/countersink), GetEffectiveShape returns
1794 // the counterbore hole circle (for DRC purposes), not the actual copper shape. Force the
1795 // slower TransformShapeToPolygon path which always returns the correct copper shape.
1796 if( IsCopperLayer( pcbLayer ) && aPad->GetPostMachiningKnockout( pcbLayer ) > 0 )
1797 simpleShapes = false;
1798
1799 if( simpleShapes )
1800 {
1801 if( ( margin.x != margin.y && aPad->GetShape( pcbLayer ) != PAD_SHAPE::CUSTOM )
1802 || ( aPad->GetShape( pcbLayer ) == PAD_SHAPE::ROUNDRECT
1803 && ( margin.x < 0 || margin.y < 0 ) ) )
1804 {
1805 // Our algorithms below (polygon inflation in particular) can't handle differential
1806 // inflation along separate axes. So for those cases we build a dummy pad instead,
1807 // and inflate it.
1808
1809 // Margin is added to both sides. If the total margin is larger than the pad
1810 // then don't display this layer
1811 if( pad_size.x + 2 * margin.x <= 0 || pad_size.y + 2 * margin.y <= 0 )
1812 return;
1813
1814 dummyPad.reset( static_cast<PAD*>( aPad->Duplicate( IGNORE_PARENT_GROUP ) ) );
1815
1816 int initial_radius = dummyPad->GetRoundRectCornerRadius( pcbLayer );
1817
1818 dummyPad->SetSize( pcbLayer, pad_size + margin + margin );
1819
1820 if( dummyPad->GetShape( pcbLayer ) == PAD_SHAPE::ROUNDRECT )
1821 {
1822 // To keep the right margin around the corners, we need to modify the corner radius.
1823 // We must have only one radius correction, so use the smallest absolute margin.
1824 int radius_margin = std::max( margin.x, margin.y ); // radius_margin is < 0
1825 dummyPad->SetRoundRectCornerRadius(
1826 pcbLayer, std::max( initial_radius + radius_margin, 0 ) );
1827 }
1828
1829 shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>(
1830 dummyPad->GetEffectiveShape( pcbLayer ) );
1831 margin.x = margin.y = 0;
1832 }
1833 else
1834 {
1835 shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>(
1836 aPad->GetEffectiveShape( pcbLayer ) );
1837 }
1838
1839 // The dynamic cast above will fail if the pad returned the hole shape or a null shape
1840 // instead of a SHAPE_COMPOUND, which happens if we're on a copper layer and the pad has
1841 // no shape on that layer.
1842 if( !shapes )
1843 return;
1844
1845 if( aPad->GetShape( pcbLayer ) == PAD_SHAPE::CUSTOM && ( margin.x || margin.y ) )
1846 {
1847 // We can't draw as shapes because we don't know which edges are internal and which
1848 // are external (so we don't know when to apply the margin and when not to).
1849 simpleShapes = false;
1850 }
1851
1852 for( const SHAPE* shape : shapes->Shapes() )
1853 {
1854 if( !simpleShapes )
1855 break;
1856
1857 switch( shape->Type() )
1858 {
1859 case SH_SEGMENT:
1860 case SH_CIRCLE:
1861 case SH_RECT:
1862 case SH_SIMPLE:
1863 // OK so far
1864 break;
1865
1866 default:
1867 // Not OK
1868 simpleShapes = false;
1869 break;
1870 }
1871 }
1872 }
1873
1874 const auto drawOneSimpleShape =
1875 [&]( const SHAPE& aShape )
1876 {
1877 switch( aShape.Type() )
1878 {
1879 case SH_SEGMENT:
1880 {
1881 const SHAPE_SEGMENT& seg = (const SHAPE_SEGMENT&) aShape;
1882 int effectiveWidth = seg.GetWidth() + 2 * margin.x;
1883
1884 if( effectiveWidth > 0 )
1885 m_gal->DrawSegment( seg.GetSeg().A, seg.GetSeg().B, effectiveWidth );
1886
1887 break;
1888 }
1889
1890 case SH_CIRCLE:
1891 {
1892 const SHAPE_CIRCLE& circle = (const SHAPE_CIRCLE&) aShape;
1893 int effectiveRadius = circle.GetRadius() + margin.x;
1894
1895 if( effectiveRadius > 0 )
1896 m_gal->DrawCircle( circle.GetCenter(), effectiveRadius );
1897
1898 break;
1899 }
1900
1901 case SH_RECT:
1902 {
1903 const SHAPE_RECT& r = (const SHAPE_RECT&) aShape;
1904 VECTOR2I pos = r.GetPosition();
1905 VECTOR2I effectiveMargin = margin;
1906
1907 if( effectiveMargin.x < 0 )
1908 {
1909 // A negative margin just produces a smaller rect.
1910 VECTOR2I effectiveSize = r.GetSize() + effectiveMargin;
1911
1912 if( effectiveSize.x > 0 && effectiveSize.y > 0 )
1913 m_gal->DrawRectangle( pos - effectiveMargin, pos + effectiveSize );
1914 }
1915 else if( effectiveMargin.x > 0 )
1916 {
1917 // A positive margin produces a larger rect, but with rounded corners
1918 m_gal->DrawRectangle( r.GetPosition(), r.GetPosition() + r.GetSize() );
1919
1920 // Use segments to produce the margin with rounded corners
1921 m_gal->DrawSegment( pos,
1922 pos + VECTOR2I( r.GetWidth(), 0 ),
1923 effectiveMargin.x * 2 );
1924 m_gal->DrawSegment( pos + VECTOR2I( r.GetWidth(), 0 ),
1925 pos + r.GetSize(),
1926 effectiveMargin.x * 2 );
1927 m_gal->DrawSegment( pos + r.GetSize(),
1928 pos + VECTOR2I( 0, r.GetHeight() ),
1929 effectiveMargin.x * 2 );
1930 m_gal->DrawSegment( pos + VECTOR2I( 0, r.GetHeight() ),
1931 pos,
1932 effectiveMargin.x * 2 );
1933 }
1934 else
1935 {
1936 m_gal->DrawRectangle( r.GetPosition(), r.GetPosition() + r.GetSize() );
1937 }
1938
1939 break;
1940 }
1941
1942 case SH_SIMPLE:
1943 {
1944 const SHAPE_SIMPLE& poly = static_cast<const SHAPE_SIMPLE&>( aShape );
1945
1946 if( poly.PointCount() < 2 ) // Careful of empty pads
1947 break;
1948
1949 if( margin.x < 0 ) // The poly shape must be deflated
1950 {
1951 SHAPE_POLY_SET outline;
1952 outline.NewOutline();
1953
1954 for( int ii = 0; ii < poly.PointCount(); ++ii )
1955 outline.Append( poly.CPoint( ii ) );
1956
1958
1959 m_gal->DrawPolygon( outline );
1960 }
1961 else
1962 {
1963 m_gal->DrawPolygon( poly.Vertices() );
1964 }
1965
1966 // Now add on a rounded margin (using segments) if the margin > 0
1967 if( margin.x > 0 )
1968 {
1969 for( size_t ii = 0; ii < poly.GetSegmentCount(); ++ii )
1970 {
1971 SEG seg = poly.GetSegment( ii );
1972 m_gal->DrawSegment( seg.A, seg.B, margin.x * 2 );
1973 }
1974 }
1975
1976 break;
1977 }
1978
1979 default:
1980 // Better not get here; we already pre-flighted the shapes...
1981 break;
1982 }
1983 };
1984
1985 if( simpleShapes )
1986 {
1987 for( const SHAPE* shape : shapes->Shapes() )
1988 drawOneSimpleShape( *shape );
1989 }
1990 else
1991 {
1992 // This is expensive. Avoid if possible.
1993 SHAPE_POLY_SET polySet;
1994 aPad->TransformShapeToPolygon( polySet, ToLAYER_ID( aLayer ), margin.x, m_maxError, ERROR_INSIDE );
1995 m_gal->DrawPolygon( polySet );
1996 }
1997
1998 }
1999
2000 if( !m_pcbSettings.IsPrinting() && IsCopperLayer( pcbLayer ) && aPad->GetDrillSizeX() > 0 )
2001 {
2002 VECTOR2D holePos = aPad->GetPosition() + aPad->GetOffset( pcbLayer );
2003 drawPostMachiningIndicator( aPad, holePos, pcbLayer );
2004 }
2005
2006 if( IsClearanceLayer( aLayer )
2007 && ( ( pcbconfig() && pcbconfig()->m_Display.m_PadClearance ) || !pcbconfig() )
2008 && !m_pcbSettings.m_isPrinting )
2009 {
2010 const PCB_LAYER_ID copperLayerForClearance = ToLAYER_ID( aLayer - LAYER_CLEARANCE_START );
2011
2012 if( aPad->GetAttribute() == PAD_ATTRIB::NPTH )
2013 color = m_pcbSettings.GetLayerColor( LAYER_NON_PLATEDHOLES );
2014
2015 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
2016 m_gal->SetIsStroke( true );
2017 m_gal->SetIsFill( false );
2018 m_gal->SetStrokeColor( color );
2019
2020 const int clearance = aPad->GetOwnClearance( copperLayerForClearance );
2021
2022 if( aPad->FlashLayer( copperLayerForClearance ) && clearance > 0 )
2023 {
2024 auto shape = std::dynamic_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape( pcbLayer ) );
2025
2026 if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_SEGMENT )
2027 {
2028 const SHAPE_SEGMENT* seg = (SHAPE_SEGMENT*) shape->Shapes()[0];
2029 m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B,
2030 seg->GetWidth() + 2 * clearance );
2031 }
2032 else if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_CIRCLE )
2033 {
2034 const SHAPE_CIRCLE* circle = (SHAPE_CIRCLE*) shape->Shapes()[0];
2035 m_gal->DrawCircle( circle->GetCenter(), circle->GetRadius() + clearance );
2036 }
2037 else
2038 {
2039 SHAPE_POLY_SET polySet;
2040
2041 // Use ERROR_INSIDE because it avoids Clipper and is therefore much faster.
2042 aPad->TransformShapeToPolygon( polySet, copperLayerForClearance, clearance,
2044
2045 if( polySet.Outline( 0 ).PointCount() > 2 ) // Careful of empty pads
2046 m_gal->DrawPolygon( polySet );
2047 }
2048 }
2049 else if( aPad->GetEffectiveHoleShape() && clearance > 0 )
2050 {
2051 std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
2052 m_gal->DrawSegment( slot->GetSeg().A, slot->GetSeg().B,
2053 slot->GetWidth() + 2 * clearance );
2054 }
2055 }
2056
2057 if( m_pcbSettings.IsHighlightEnabled()
2058 && m_pcbSettings.GetHighlightNetCodes().contains( aPad->GetNetCode() ) )
2059 {
2060 NETINFO_ITEM* net = aPad->GetNet();
2061 if( net && ( net->GetTerminalPad( 0 ) == aPad || net->GetTerminalPad( 1 ) == aPad ) )
2062 {
2063 BOX2I box = aPad->GetBoundingBox();
2064 m_gal->SetIsFill( false );
2065 m_gal->SetIsStroke( true );
2066
2067 // Base emphasis (net highlight)
2068 COLOR4D termColor = color.Brightened( 0.2 );
2069 int baseWidth = m_pcbSettings.m_outlineWidth * 2;
2070
2071 // If a grouped chain highlight is active and this pad belongs to that chain,
2072 // make the emphasis stronger (brighter + thicker + inset second rectangle).
2073 if( !m_pcbSettings.m_highlightedNetChain.IsEmpty()
2074 && net && net->GetNetChain() == m_pcbSettings.m_highlightedNetChain )
2075 {
2076 // Prefer the chain's own colour override if the board has one.
2077 if( const BOARD* board = aPad->GetBoard() )
2078 {
2079 COLOR4D chainColor =
2080 board->GetNetChainColor( m_pcbSettings.m_highlightedNetChain );
2081
2082 if( chainColor != COLOR4D::UNSPECIFIED )
2083 termColor = chainColor;
2084 else
2085 termColor = termColor.Brightened( 0.25 );
2086 }
2087 else
2088 {
2089 termColor = termColor.Brightened( 0.25 );
2090 }
2091
2092 baseWidth = m_pcbSettings.m_outlineWidth * 3;
2093 }
2094
2095 m_gal->SetStrokeColor( termColor );
2096 m_gal->SetLineWidth( baseWidth );
2097 m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
2098
2099 if( !m_pcbSettings.m_highlightedNetChain.IsEmpty()
2100 && net && net->GetNetChain() == m_pcbSettings.m_highlightedNetChain )
2101 {
2102 // Draw an inner rectangle for additional visual distinction.
2103 // Shrink by one outline width equivalent to avoid excessive size.
2104 int inset = baseWidth * 2; // screen-space approx; acceptable heuristic
2105 BOX2I inner = box;
2106 inner.Inflate( -inset, -inset );
2107 if( inner.GetWidth() > 0 && inner.GetHeight() > 0 )
2108 {
2109 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
2110 m_gal->DrawRectangle( inner.GetOrigin(), inner.GetEnd() );
2111 }
2112 }
2113 }
2114 }
2115}
2116
2117
2118void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
2119{
2120 COLOR4D color = m_pcbSettings.GetColor( aShape, aLayer );
2122 int thickness = getLineThickness( aShape->GetWidth() );
2123 LINE_STYLE lineStyle = aShape->GetStroke().GetLineStyle();
2124 bool isSolidFill = aShape->IsSolidFill();
2125 bool isHatchedFill = aShape->IsHatchedFill();
2126
2127 if( lineStyle == LINE_STYLE::DEFAULT )
2128 lineStyle = LINE_STYLE::SOLID;
2129
2130 if( IsSolderMaskLayer( aLayer )
2131 && aShape->HasSolderMask()
2132 && IsExternalCopperLayer( aShape->GetLayer() ) )
2133 {
2134 lineStyle = LINE_STYLE::SOLID;
2135 thickness += aShape->GetSolderMaskExpansion() * 2;
2136
2137 if( isHatchedFill )
2138 {
2139 isSolidFill = true;
2140 isHatchedFill = false;
2141 }
2142 }
2143
2144 if( IsNetnameLayer( aLayer ) )
2145 {
2146 // Net names are shown only in board editor:
2148 return;
2149
2150 if( !pcbconfig() || pcbconfig()->m_Display.m_NetNames < 2 )
2151 return;
2152
2153 if( aShape->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
2154 return;
2155
2156 const wxString& netname = aShape->GetDisplayNetname();
2157
2158 if( netname.IsEmpty() )
2159 return;
2160
2161 if( aShape->GetShape() == SHAPE_T::SEGMENT )
2162 {
2163 SHAPE_SEGMENT seg( { aShape->GetStart(), aShape->GetEnd() }, aShape->GetWidth() );
2164 renderNetNameForSegment( seg, color, netname );
2165 return;
2166 }
2167
2168 // TODO: Maybe use some of the pad code?
2169
2170 return;
2171 }
2172
2173 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
2174 {
2175 color = m_pcbSettings.GetColor( aShape, aLayer );
2176 thickness = thickness + m_lockedShadowMargin;
2177
2178 // Note: on LAYER_LOCKED_ITEM_SHADOW always draw shadow shapes as continuous lines
2179 // otherwise the look is very strange and ugly
2180 lineStyle = LINE_STYLE::SOLID;
2181 }
2182
2183 if( outline_mode )
2184 {
2185 m_gal->SetIsFill( false );
2186 m_gal->SetIsStroke( true );
2187 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
2188 }
2189
2190 m_gal->SetFillColor( color );
2191 m_gal->SetStrokeColor( color );
2192
2193 if( lineStyle == LINE_STYLE::SOLID || aShape->IsSolidFill() )
2194 {
2195 switch( aShape->GetShape() )
2196 {
2197 case SHAPE_T::SEGMENT:
2198 if( aShape->IsProxyItem() )
2199 {
2200 std::vector<VECTOR2I> pts;
2201 VECTOR2I offset = ( aShape->GetEnd() - aShape->GetStart() ).Perpendicular();
2202 offset = offset.Resize( thickness / 2 );
2203
2204 pts.push_back( aShape->GetStart() + offset );
2205 pts.push_back( aShape->GetStart() - offset );
2206 pts.push_back( aShape->GetEnd() - offset );
2207 pts.push_back( aShape->GetEnd() + offset );
2208
2209 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
2210 m_gal->DrawLine( pts[0], pts[1] );
2211 m_gal->DrawLine( pts[1], pts[2] );
2212 m_gal->DrawLine( pts[2], pts[3] );
2213 m_gal->DrawLine( pts[3], pts[0] );
2214 m_gal->DrawLine( ( pts[0] + pts[1] ) / 2, ( pts[1] + pts[2] ) / 2 );
2215 m_gal->DrawLine( ( pts[1] + pts[2] ) / 2, ( pts[2] + pts[3] ) / 2 );
2216 m_gal->DrawLine( ( pts[2] + pts[3] ) / 2, ( pts[3] + pts[0] ) / 2 );
2217 m_gal->DrawLine( ( pts[3] + pts[0] ) / 2, ( pts[0] + pts[1] ) / 2 );
2218 }
2219 else if( outline_mode )
2220 {
2221 m_gal->DrawSegment( aShape->GetStart(), aShape->GetEnd(), thickness );
2222 }
2223 else if( lineStyle == LINE_STYLE::SOLID )
2224 {
2225 m_gal->SetIsFill( true );
2226 m_gal->SetIsStroke( false );
2227
2228 m_gal->DrawSegment( aShape->GetStart(), aShape->GetEnd(), thickness );
2229 }
2230
2231 break;
2232
2233 case SHAPE_T::RECTANGLE:
2234 {
2235 if( aShape->GetCornerRadius() > 0 )
2236 {
2237 // Creates a normalized ROUNDRECT item
2238 // (GetRectangleWidth() and GetRectangleHeight() can be < 0 with transforms
2239 ROUNDRECT rr( SHAPE_RECT( aShape->GetStart(), aShape->GetRectangleWidth(),
2240 aShape->GetRectangleHeight() ),
2241 aShape->GetCornerRadius(), true /* normalize */ );
2242 SHAPE_POLY_SET poly;
2243 rr.TransformToPolygon( poly, aShape->GetMaxError() );
2244 SHAPE_LINE_CHAIN outline = poly.Outline( 0 );
2245
2246 if( aShape->IsProxyItem() )
2247 {
2248 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
2249 m_gal->DrawPolygon( outline );
2250 }
2251 else if( outline_mode )
2252 {
2253 m_gal->DrawSegmentChain( outline, thickness );
2254 }
2255 else
2256 {
2257 m_gal->SetIsFill( true );
2258 m_gal->SetIsStroke( false );
2259
2260 if( lineStyle == LINE_STYLE::SOLID && thickness > 0 )
2261 {
2262 m_gal->DrawSegmentChain( outline, thickness );
2263 }
2264
2265 if( isSolidFill )
2266 {
2267 if( thickness < 0 )
2268 {
2269 SHAPE_POLY_SET deflated_shape = outline;
2270 deflated_shape.Inflate( thickness / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS, m_maxError );
2271 m_gal->DrawPolygon( deflated_shape );
2272 }
2273 else
2274 {
2275 m_gal->DrawPolygon( outline );
2276 }
2277 }
2278 }
2279 }
2280 else
2281 {
2282 std::vector<VECTOR2I> pts = aShape->GetRectCorners();
2283
2284 if( aShape->IsProxyItem() )
2285 {
2286 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
2287 m_gal->DrawLine( pts[0], pts[1] );
2288 m_gal->DrawLine( pts[1], pts[2] );
2289 m_gal->DrawLine( pts[2], pts[3] );
2290 m_gal->DrawLine( pts[3], pts[0] );
2291 m_gal->DrawLine( pts[0], pts[2] );
2292 m_gal->DrawLine( pts[1], pts[3] );
2293 }
2294 else if( outline_mode )
2295 {
2296 m_gal->DrawSegment( pts[0], pts[1], thickness );
2297 m_gal->DrawSegment( pts[1], pts[2], thickness );
2298 m_gal->DrawSegment( pts[2], pts[3], thickness );
2299 m_gal->DrawSegment( pts[3], pts[0], thickness );
2300 }
2301 else
2302 {
2303 m_gal->SetIsFill( true );
2304 m_gal->SetIsStroke( false );
2305
2306 if( lineStyle == LINE_STYLE::SOLID && thickness > 0 )
2307 {
2308 m_gal->DrawSegment( pts[0], pts[1], thickness );
2309 m_gal->DrawSegment( pts[1], pts[2], thickness );
2310 m_gal->DrawSegment( pts[2], pts[3], thickness );
2311 m_gal->DrawSegment( pts[3], pts[0], thickness );
2312 }
2313
2314 if( isSolidFill )
2315 {
2316 SHAPE_POLY_SET poly;
2317 poly.NewOutline();
2318
2319 for( const VECTOR2I& pt : pts )
2320 poly.Append( pt );
2321
2322 if( thickness < 0 )
2323 poly.Inflate( thickness / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
2324 m_maxError );
2325
2326 m_gal->DrawPolygon( poly );
2327 }
2328 }
2329 }
2330
2331 break;
2332 }
2333
2334 case SHAPE_T::ARC:
2335 {
2336 EDA_ANGLE startAngle;
2337 EDA_ANGLE endAngle;
2338 aShape->CalcArcAngles( startAngle, endAngle );
2339
2340 if( outline_mode )
2341 {
2342 m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(), startAngle,
2343 endAngle - startAngle, thickness, m_maxError );
2344 }
2345 else if( lineStyle == LINE_STYLE::SOLID )
2346 {
2347 m_gal->SetIsFill( true );
2348 m_gal->SetIsStroke( false );
2349
2350 m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(), startAngle,
2351 endAngle - startAngle, thickness, m_maxError );
2352 }
2353 break;
2354 }
2355
2356 case SHAPE_T::CIRCLE:
2357 if( outline_mode )
2358 {
2359 m_gal->DrawCircle( aShape->GetStart(), aShape->GetRadius() - thickness / 2 );
2360 m_gal->DrawCircle( aShape->GetStart(), aShape->GetRadius() + thickness / 2 );
2361 }
2362 else
2363 {
2364 m_gal->SetIsFill( aShape->IsSolidFill() );
2365 m_gal->SetIsStroke( lineStyle == LINE_STYLE::SOLID && thickness > 0 );
2366 m_gal->SetLineWidth( thickness );
2367
2368 int radius = aShape->GetRadius();
2369
2370 if( lineStyle == LINE_STYLE::SOLID && thickness > 0 )
2371 {
2372 m_gal->DrawCircle( aShape->GetStart(), radius );
2373 }
2374 else if( isSolidFill )
2375 {
2376 if( thickness < 0 )
2377 {
2378 radius += thickness / 2;
2379 radius = std::max( radius, 0 );
2380 }
2381
2382 m_gal->DrawCircle( aShape->GetStart(), radius );
2383 }
2384 }
2385 break;
2386
2387 case SHAPE_T::POLY:
2388 {
2389 SHAPE_POLY_SET& shape = const_cast<PCB_SHAPE*>( aShape )->GetPolyShape();
2390
2391 if( shape.OutlineCount() == 0 )
2392 break;
2393
2394 if( outline_mode )
2395 {
2396 for( int ii = 0; ii < shape.OutlineCount(); ++ii )
2397 m_gal->DrawSegmentChain( shape.Outline( ii ), thickness );
2398 }
2399 else
2400 {
2401 m_gal->SetIsFill( true );
2402 m_gal->SetIsStroke( false );
2403
2404 if( lineStyle == LINE_STYLE::SOLID && thickness > 0 )
2405 {
2406 for( int ii = 0; ii < shape.OutlineCount(); ++ii )
2407 m_gal->DrawSegmentChain( shape.Outline( ii ), thickness );
2408 }
2409
2410 if( isSolidFill )
2411 {
2412 if( thickness < 0 )
2413 {
2414 SHAPE_POLY_SET deflated_shape = shape;
2415 deflated_shape.Inflate( thickness / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
2416 m_maxError );
2417 m_gal->DrawPolygon( deflated_shape );
2418 }
2419 else
2420 {
2421 // On Opengl, a not convex filled polygon is usually drawn by using
2422 // triangles as primitives. CacheTriangulation() can create basic triangle
2423 // primitives to draw the polygon solid shape on Opengl. GLU tessellation
2424 // is much slower, so currently we are using our tessellation.
2425 if( m_gal->IsOpenGlEngine() && !shape.IsTriangulationUpToDate() )
2426 shape.CacheTriangulation( true );
2427
2428 m_gal->DrawPolygon( shape );
2429 }
2430 }
2431 }
2432
2433 break;
2434 }
2435
2436 case SHAPE_T::BEZIER:
2437 if( outline_mode )
2438 {
2439 std::vector<VECTOR2D> output;
2440 std::vector<VECTOR2D> pointCtrl;
2441
2442 pointCtrl.push_back( aShape->GetStart() );
2443 pointCtrl.push_back( aShape->GetBezierC1() );
2444 pointCtrl.push_back( aShape->GetBezierC2() );
2445 pointCtrl.push_back( aShape->GetEnd() );
2446
2447 BEZIER_POLY converter( pointCtrl );
2448 converter.GetPoly( output, m_maxError );
2449
2450 m_gal->DrawSegmentChain( aShape->GetBezierPoints(), thickness );
2451 }
2452 else
2453 {
2454 m_gal->SetIsFill( aShape->IsSolidFill() );
2455 m_gal->SetIsStroke( lineStyle == LINE_STYLE::SOLID && thickness > 0 );
2456 m_gal->SetLineWidth( thickness );
2457
2458 if( aShape->GetBezierPoints().size() > 2 )
2459 {
2460 m_gal->DrawPolygon( aShape->GetBezierPoints() );
2461 }
2462 else
2463 {
2464 m_gal->DrawCurve( VECTOR2D( aShape->GetStart() ),
2465 VECTOR2D( aShape->GetBezierC1() ),
2466 VECTOR2D( aShape->GetBezierC2() ),
2467 VECTOR2D( aShape->GetEnd() ), m_maxError );
2468 }
2469 }
2470
2471 break;
2472
2473 case SHAPE_T::ELLIPSE:
2474 {
2475 const VECTOR2D center( aShape->GetEllipseCenter() );
2476 const int majorR = aShape->GetEllipseMajorRadius();
2477 const int minorR = aShape->GetEllipseMinorRadius();
2478 const EDA_ANGLE& rot = aShape->GetEllipseRotation();
2479
2480 if( outline_mode )
2481 {
2482 m_gal->DrawEllipse( center, majorR - thickness / 2, minorR - thickness / 2, rot );
2483 m_gal->DrawEllipse( center, majorR + thickness / 2, minorR + thickness / 2, rot );
2484 }
2485 else
2486 {
2487 m_gal->SetIsFill( aShape->IsSolidFill() );
2488 m_gal->SetIsStroke( lineStyle == LINE_STYLE::SOLID && thickness > 0 );
2489 m_gal->SetLineWidth( thickness );
2490
2491 if( lineStyle == LINE_STYLE::SOLID && thickness > 0 )
2492 m_gal->DrawEllipse( center, majorR, minorR, rot );
2493 else if( isSolidFill )
2494 m_gal->DrawEllipse( center, majorR, minorR, rot );
2495 }
2496
2497 break;
2498 }
2499
2501 {
2502 const VECTOR2D center( aShape->GetEllipseCenter() );
2503 const int majorR = aShape->GetEllipseMajorRadius();
2504 const int minorR = aShape->GetEllipseMinorRadius();
2505 const EDA_ANGLE& rot = aShape->GetEllipseRotation();
2506 const EDA_ANGLE& start = aShape->GetEllipseStartAngle();
2507 const EDA_ANGLE& end = aShape->GetEllipseEndAngle();
2508
2509 if( outline_mode )
2510 {
2511 m_gal->DrawEllipseArc( center, majorR - thickness / 2, minorR - thickness / 2, rot, start, end );
2512 m_gal->DrawEllipseArc( center, majorR + thickness / 2, minorR + thickness / 2, rot, start, end );
2513 }
2514 else if( lineStyle == LINE_STYLE::SOLID )
2515 {
2516 // no interior fill for arcs
2517 m_gal->SetIsFill( false );
2518 m_gal->SetIsStroke( thickness > 0 );
2519 m_gal->SetLineWidth( thickness );
2520 m_gal->DrawEllipseArc( center, majorR, minorR, rot, start, end );
2521 }
2522
2523 break;
2524 }
2525
2526 case SHAPE_T::UNDEFINED:
2527 break;
2528 }
2529 }
2530
2531 if( lineStyle != LINE_STYLE::SOLID )
2532 {
2533 if( !outline_mode )
2534 {
2535 m_gal->SetIsFill( true );
2536 m_gal->SetIsStroke( false );
2537 }
2538
2539 std::vector<SHAPE*> shapes;
2540
2541 // For ellipses, use SHAPE_ELLIPSE directly so STROKE_PARAMS::Stroke can
2542 // distribute dashes uniformly by arc length instead of per-tessellation-segment.
2543 if( aShape->GetShape() == SHAPE_T::ELLIPSE )
2544 {
2545 shapes.push_back( new SHAPE_ELLIPSE( aShape->GetEllipseCenter(), aShape->GetEllipseMajorRadius(),
2546 aShape->GetEllipseMinorRadius(), aShape->GetEllipseRotation() ) );
2547 }
2548 else if( aShape->GetShape() == SHAPE_T::ELLIPSE_ARC )
2549 {
2550 shapes.push_back( new SHAPE_ELLIPSE( aShape->GetEllipseCenter(), aShape->GetEllipseMajorRadius(),
2551 aShape->GetEllipseMinorRadius(), aShape->GetEllipseRotation(),
2552 aShape->GetEllipseStartAngle(), aShape->GetEllipseEndAngle() ) );
2553 }
2554 else
2555 {
2556 shapes = aShape->MakeEffectiveShapes( true );
2557 }
2558
2559 for( SHAPE* shape : shapes )
2560 {
2561 STROKE_PARAMS::Stroke( shape, lineStyle, getLineThickness( aShape->GetWidth() ),
2563 [&]( const VECTOR2I& a, const VECTOR2I& b )
2564 {
2565 m_gal->DrawSegment( a, b, thickness );
2566 } );
2567 }
2568
2569 for( SHAPE* shape : shapes )
2570 delete shape;
2571 }
2572
2573 if( isHatchedFill )
2574 {
2575 aShape->UpdateHatching();
2576 m_gal->SetIsFill( false );
2577 m_gal->SetIsStroke( true );
2578 m_gal->SetLineWidth( aShape->GetHatchLineWidth() );
2579
2580 for( const SEG& seg : aShape->GetHatchLines() )
2581 m_gal->DrawLine( seg.A, seg.B );
2582 }
2583}
2584
2585
2586void PCB_PAINTER::strokeText( const wxString& aText, const VECTOR2I& aPosition,
2587 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
2588{
2589 KIFONT::FONT* font = aAttrs.m_Font;
2590
2591 if( !font )
2592 font = KIFONT::FONT::GetFont( wxEmptyString, aAttrs.m_Bold, aAttrs.m_Italic );
2593
2594 m_gal->SetIsFill( font->IsOutline() );
2595 m_gal->SetIsStroke( font->IsStroke() );
2596
2597 VECTOR2I pos( aPosition );
2598 VECTOR2I fudge( KiROUND( 0.16 * aAttrs.m_StrokeWidth ), 0 );
2599
2600 RotatePoint( fudge, aAttrs.m_Angle );
2601
2602 if( ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && !aAttrs.m_Mirrored )
2603 || ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && aAttrs.m_Mirrored ) )
2604 {
2605 pos -= fudge;
2606 }
2607 else if( ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && !aAttrs.m_Mirrored )
2608 || ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && aAttrs.m_Mirrored ) )
2609 {
2610 pos += fudge;
2611 }
2612
2613 font->Draw( m_gal, aText, pos, aAttrs, aFontMetrics );
2614}
2615
2616
2617void PCB_PAINTER::draw( const PCB_REFERENCE_IMAGE* aBitmap, int aLayer )
2618{
2619 m_gal->Save();
2620
2621 const REFERENCE_IMAGE& refImg = aBitmap->GetReferenceImage();
2622 m_gal->Translate( refImg.GetPosition() );
2623
2624 // When the image scale factor is not 1.0, we need to modify the actual as the image scale
2625 // factor is similar to a local zoom
2626 const double img_scale = refImg.GetImageScale();
2627
2628 if( img_scale != 1.0 )
2629 m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
2630
2631 const double imgAlpha = m_pcbSettings.GetColor( aBitmap, aBitmap->GetLayer() ).a;
2632
2633 if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
2634 {
2635 COLOR4D color = m_pcbSettings.GetColor( aBitmap, LAYER_ANCHOR );
2636 m_gal->SetIsStroke( true );
2637 m_gal->SetStrokeColor( color );
2638 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth * 2.0f );
2639 m_gal->SetIsFill( false );
2640
2641 // Draws a bounding box.
2642 VECTOR2D bm_size( refImg.GetSize() );
2643 // bm_size is the actual image size in UI.
2644 // but m_canvas scale was previously set to img_scale
2645 // so recalculate size relative to this image size.
2646 bm_size.x /= img_scale;
2647 bm_size.y /= img_scale;
2648 VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
2649 VECTOR2D end = origin + bm_size;
2650
2651 m_gal->DrawRectangle( origin, end );
2652
2653 // Keep reference images opaque when selected (and not moving). Otherwise cached layers
2654 // will not be rendered under the selected image because cached layers are rendered
2655 // after non-cached layers (e.g. bitmaps), which will have a closer Z order.
2656 m_gal->DrawBitmap( refImg.GetImage(), aBitmap->IsMoving() ? imgAlpha : 1.0 );
2657 }
2658 else
2659 m_gal->DrawBitmap( refImg.GetImage(), imgAlpha );
2660
2661 m_gal->Restore();
2662}
2663
2664
2665void PCB_PAINTER::draw( const PCB_FIELD* aField, int aLayer )
2666{
2667 if( aField->IsVisible() )
2668 draw( static_cast<const PCB_TEXT*>( aField ), aLayer );
2669}
2670
2671
2672void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer )
2673{
2674 wxString resolvedText( aText->GetShownText( true ) );
2675
2676 if( resolvedText.Length() == 0 )
2677 return;
2678
2679 if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked
2680 {
2681 const COLOR4D color = m_pcbSettings.GetColor( aText, aLayer );
2682
2683 m_gal->SetIsFill( true );
2684 m_gal->SetIsStroke( true );
2685 m_gal->SetFillColor( color );
2686 m_gal->SetStrokeColor( color );
2687 m_gal->SetLineWidth( m_lockedShadowMargin );
2688
2689 SHAPE_POLY_SET poly;
2690 aText->TransformShapeToPolygon( poly, aText->GetLayer(), 0, m_maxError, ERROR_OUTSIDE );
2691 m_gal->DrawPolygon( poly );
2692
2693 return;
2694 }
2695
2696 const KIFONT::METRICS& metrics = aText->GetFontMetrics();
2697 TEXT_ATTRIBUTES attrs = aText->GetAttributes();
2698 // Raw attrs are lib frame for FP children, pull scaled values for render.
2699 attrs.m_Size = aText->GetTextSize();
2700 attrs.m_StrokeWidth = aText->GetTextThickness();
2701 const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer );
2702 bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill;
2703
2704 KIFONT::FONT* font = aText->GetDrawFont( &m_pcbSettings );
2705
2706 m_gal->SetStrokeColor( color );
2707 m_gal->SetFillColor( color );
2708 attrs.m_Angle = aText->GetDrawRotation();
2709
2710 if( aText->IsKnockout() )
2711 {
2712 const SHAPE_POLY_SET& finalPoly = aText->GetKnockoutCache( font, resolvedText, m_maxError );
2713
2714 m_gal->SetIsStroke( false );
2715 m_gal->SetIsFill( true );
2716 m_gal->DrawPolygon( finalPoly );
2717 }
2718 else
2719 {
2720 if( outline_mode )
2721 attrs.m_StrokeWidth = m_pcbSettings.m_outlineWidth;
2722 else
2724
2725 if( m_gal->IsFlippedX() && !aText->IsSideSpecific() )
2726 {
2727 // We do not want to change the mirroring for this kind of text
2728 // on the mirrored canvas
2729 // (not mirrored is draw not mirrored and mirrored is draw mirrored)
2730 // So we need to recalculate the text position to keep it at the same position
2731 // on the canvas
2732 VECTOR2I textPos = aText->GetTextPos();
2733 VECTOR2I textWidth = VECTOR2I( aText->GetTextBox( &m_pcbSettings ).GetWidth(), 0 );
2734
2735 if( aText->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
2736 textWidth.x = -textWidth.x;
2737 else if( aText->GetHorizJustify() == GR_TEXT_H_ALIGN_CENTER )
2738 textWidth.x = 0;
2739
2740 RotatePoint( textWidth, VECTOR2I( 0, 0 ), aText->GetDrawRotation() );
2741
2742 if( attrs.m_Mirrored )
2743 textPos -= textWidth;
2744 else
2745 textPos += textWidth;
2746
2747 attrs.m_Mirrored = !attrs.m_Mirrored;
2748 strokeText( resolvedText, textPos, attrs, metrics );
2749 return;
2750 }
2751
2752 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2753
2754 if( font->IsOutline() )
2755 cache = aText->GetRenderCache( font, resolvedText );
2756
2757 if( cache )
2758 {
2759 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2760 m_gal->DrawGlyphs( *cache );
2761 }
2762 else
2763 {
2764 strokeText( resolvedText, aText->GetTextPos(), attrs, metrics );
2765 }
2766 }
2767
2768 // Draw the umbilical line for texts in footprints
2769 FOOTPRINT* fp_parent = aText->GetParentFootprint();
2770
2771 if( fp_parent && aText->IsSelected() )
2772 {
2773 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
2774 m_gal->SetStrokeColor( m_pcbSettings.GetColor( nullptr, LAYER_ANCHOR ) );
2775 m_gal->DrawLine( aText->GetTextPos(), fp_parent->GetPosition() );
2776 }
2777}
2778
2779
2780void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer )
2781{
2782 if( aTextBox->Type() == PCB_TABLECELL_T )
2783 {
2784 const PCB_TABLECELL* cell = static_cast<const PCB_TABLECELL*>( aTextBox );
2785
2786 if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
2787 return;
2788 }
2789
2790 COLOR4D color = m_pcbSettings.GetColor( aTextBox, aLayer );
2791 int thickness = getLineThickness( aTextBox->GetWidth() );
2792 LINE_STYLE lineStyle = aTextBox->GetStroke().GetLineStyle();
2793 wxString resolvedText( aTextBox->GetShownText( true ) );
2794 KIFONT::FONT* font = aTextBox->GetDrawFont( &m_pcbSettings );
2795
2796 if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked
2797 {
2798 const COLOR4D sh_color = m_pcbSettings.GetColor( aTextBox, aLayer );
2799
2800 m_gal->SetIsFill( true );
2801 m_gal->SetIsStroke( false );
2802 m_gal->SetFillColor( sh_color );
2803 m_gal->SetStrokeColor( sh_color );
2804
2805 // Draw the box with a larger thickness than box thickness to show
2806 // the shadow mask
2807 std::vector<VECTOR2I> pts = aTextBox->GetCorners();
2808 int line_thickness = std::max( thickness*3, pcbIUScale.mmToIU( 0.2 ) );
2809
2810 std::deque<VECTOR2D> dpts;
2811
2812 for( const VECTOR2I& pt : pts )
2813 dpts.push_back( VECTOR2D( pt ) );
2814
2815 dpts.push_back( VECTOR2D( pts[0] ) );
2816
2817 m_gal->SetIsStroke( true );
2818 m_gal->SetLineWidth( line_thickness );
2819 m_gal->DrawPolygon( dpts );
2820 }
2821
2822 m_gal->SetFillColor( color );
2823 m_gal->SetStrokeColor( color );
2824 m_gal->SetIsFill( true );
2825 m_gal->SetIsStroke( false );
2826
2827 if( aTextBox->Type() != PCB_TABLECELL_T && aTextBox->IsBorderEnabled() )
2828 {
2829 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2830 {
2831 if( thickness > 0 )
2832 {
2833 std::vector<VECTOR2I> pts = aTextBox->GetCorners();
2834
2835 for( size_t ii = 0; ii < pts.size(); ++ii )
2836 m_gal->DrawSegment( pts[ii], pts[( ii + 1 ) % pts.size()], thickness );
2837 }
2838 }
2839 else
2840 {
2841 std::vector<SHAPE*> shapes = aTextBox->MakeEffectiveShapes( true );
2842
2843 for( SHAPE* shape : shapes )
2844 {
2845 STROKE_PARAMS::Stroke( shape, lineStyle, thickness, &m_pcbSettings,
2846 [&]( const VECTOR2I& a, const VECTOR2I& b )
2847 {
2848 m_gal->DrawSegment( a, b, thickness );
2849 } );
2850 }
2851
2852 for( SHAPE* shape : shapes )
2853 delete shape;
2854 }
2855 }
2856
2857 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
2858 {
2859 // For now, the textbox is a filled shape.
2860 // so the text drawn on LAYER_LOCKED_ITEM_SHADOW with a thick width is disabled
2861 // If enabled, the thick text position must be offsetted to be exactly on the
2862 // initial text, which is not easy, depending on its rotation and justification.
2863#if 0
2864 const COLOR4D sh_color = m_pcbSettings.GetColor( aTextBox, aLayer );
2865 m_canvas->SetFillColor( sh_color );
2866 m_canvas->SetStrokeColor( sh_color );
2867 attrs.m_StrokeWidth += m_lockedShadowMargin;
2868#else
2869 return;
2870#endif
2871 }
2872
2873 if( aTextBox->IsKnockout() )
2874 {
2875 SHAPE_POLY_SET finalPoly;
2876 aTextBox->TransformTextToPolySet( finalPoly, 0, m_maxError, ERROR_INSIDE );
2877 finalPoly.Fracture();
2878
2879 m_gal->SetIsStroke( false );
2880 m_gal->SetIsFill( true );
2881 m_gal->DrawPolygon( finalPoly );
2882 }
2883 else
2884 {
2885 if( resolvedText.Length() == 0 )
2886 return;
2887
2888 const KIFONT::METRICS& metrics = aTextBox->GetFontMetrics();
2889 TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes();
2890 // Raw attrs are lib frame for FP children, pull scaled size for render.
2891 attrs.m_Size = aTextBox->GetTextSize();
2893
2894 if( m_gal->IsFlippedX() && !aTextBox->IsSideSpecific() )
2895 {
2896 attrs.m_Mirrored = !attrs.m_Mirrored;
2897 strokeText( resolvedText, aTextBox->GetDrawPos( true ), attrs, metrics );
2898 return;
2899 }
2900
2901 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2902
2903 if( font->IsOutline() )
2904 cache = aTextBox->GetRenderCache( font, resolvedText );
2905
2906 if( cache )
2907 {
2908 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2909 m_gal->DrawGlyphs( *cache );
2910 }
2911 else
2912 {
2913 strokeText( resolvedText, aTextBox->GetDrawPos(), attrs, metrics );
2914 }
2915 }
2916}
2917
2918void PCB_PAINTER::draw( const PCB_TABLE* aTable, int aLayer )
2919{
2920 if( aTable->GetCells().empty() )
2921 return;
2922
2923 for( PCB_TABLECELL* cell : aTable->GetCells() )
2924 {
2925 if( cell->GetColSpan() > 0 || cell->GetRowSpan() > 0 )
2926 draw( static_cast<PCB_TEXTBOX*>( cell ), aLayer );
2927 }
2928
2929 COLOR4D color = m_pcbSettings.GetColor( aTable, aLayer );
2930
2931 aTable->DrawBorders(
2932 [&]( const VECTOR2I& ptA, const VECTOR2I& ptB, const STROKE_PARAMS& stroke )
2933 {
2934 int lineWidth = getLineThickness( stroke.GetWidth() );
2935 LINE_STYLE lineStyle = stroke.GetLineStyle();
2936
2937 m_gal->SetIsFill( false );
2938 m_gal->SetIsStroke( true );
2939 m_gal->SetStrokeColor( color );
2940 m_gal->SetLineWidth( lineWidth );
2941
2942 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2943 {
2944 m_gal->DrawLine( ptA, ptB );
2945 }
2946 else
2947 {
2948 SHAPE_SEGMENT seg( ptA, ptB );
2949
2950 STROKE_PARAMS::Stroke( &seg, lineStyle, lineWidth, &m_pcbSettings,
2951 [&]( VECTOR2I a, VECTOR2I b )
2952 {
2953 // DrawLine has problem with 0 length lines so enforce minimum
2954 if( a == b )
2955 m_gal->DrawLine( a+1, b );
2956 else
2957 m_gal->DrawLine( a, b );
2958 } );
2959 }
2960 } );
2961
2962 // Highlight selected tablecells with a background wash.
2963 for( PCB_TABLECELL* cell : aTable->GetCells() )
2964 {
2965 if( aTable->IsSelected() || cell->IsSelected() )
2966 {
2967 std::vector<VECTOR2I> corners = cell->GetCorners();
2968 std::deque<VECTOR2D> pts;
2969
2970 pts.insert( pts.end(), corners.begin(), corners.end() );
2971
2972 m_gal->SetFillColor( color.WithAlpha( 0.5 ) );
2973 m_gal->SetIsFill( true );
2974 m_gal->SetIsStroke( false );
2975 m_gal->DrawPolygon( pts );
2976 }
2977 }
2978}
2979
2980
2981void PCB_PAINTER::draw( const FOOTPRINT* aFootprint, int aLayer )
2982{
2983 if( aLayer == LAYER_ANCHOR )
2984 {
2985 const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
2986
2987 // Keep the size and width constant, not related to the scale because the anchor
2988 // is just a marker on screen
2989 double anchorSize = 5.0 / m_gal->GetWorldScale(); // 5 pixels size
2990 double anchorThickness = 1.0 / m_gal->GetWorldScale(); // 1 pixels width
2991
2992 // Draw anchor
2993 m_gal->SetIsFill( false );
2994 m_gal->SetIsStroke( true );
2995 m_gal->SetStrokeColor( color );
2996 m_gal->SetLineWidth( anchorThickness );
2997
2998 VECTOR2D center = aFootprint->GetPosition();
2999 m_gal->DrawLine( center - VECTOR2D( anchorSize, 0 ), center + VECTOR2D( anchorSize, 0 ) );
3000 m_gal->DrawLine( center - VECTOR2D( 0, anchorSize ), center + VECTOR2D( 0, anchorSize ) );
3001 }
3002
3003 if( aLayer == LAYER_LOCKED_ITEM_SHADOW && m_frameType == FRAME_PCB_EDITOR ) // happens only if locked
3004 {
3005 const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
3006
3007 m_gal->SetIsFill( true );
3008 m_gal->SetIsStroke( false );
3009 m_gal->SetFillColor( color );
3010
3011#if 0 // GetBoundingHull() can be very slow, especially for logos imported from graphics
3012 const SHAPE_POLY_SET& poly = aFootprint->GetBoundingHull();
3013 m_canvas->DrawPolygon( poly );
3014#else
3015 BOX2I bbox = aFootprint->GetBoundingBox( false );
3016 VECTOR2I topLeft = bbox.GetPosition();
3017 VECTOR2I botRight = bbox.GetPosition() + bbox.GetSize();
3018
3019 m_gal->DrawRectangle( topLeft, botRight );
3020
3021 // Use segments to produce a margin with rounded corners
3022 m_gal->DrawSegment( topLeft, VECTOR2I( botRight.x, topLeft.y ), m_lockedShadowMargin );
3023 m_gal->DrawSegment( VECTOR2I( botRight.x, topLeft.y ), botRight, m_lockedShadowMargin );
3024 m_gal->DrawSegment( botRight, VECTOR2I( topLeft.x, botRight.y ), m_lockedShadowMargin );
3025 m_gal->DrawSegment( VECTOR2I( topLeft.x, botRight.y ), topLeft, m_lockedShadowMargin );
3026#endif
3027 }
3028
3029 if( aLayer == LAYER_CONFLICTS_SHADOW && aFootprint->IsConflicting() )
3030 {
3031 const SHAPE_POLY_SET& frontpoly = aFootprint->GetCourtyard( F_CrtYd );
3032 const SHAPE_POLY_SET& backpoly = aFootprint->GetCourtyard( B_CrtYd );
3033
3034 const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
3035
3036 m_gal->SetIsFill( true );
3037 m_gal->SetIsStroke( false );
3038 m_gal->SetFillColor( color );
3039
3040 if( frontpoly.OutlineCount() > 0 )
3041 m_gal->DrawPolygon( frontpoly );
3042
3043 if( backpoly.OutlineCount() > 0 )
3044 m_gal->DrawPolygon( backpoly );
3045 }
3046}
3047
3048
3049void PCB_PAINTER::draw( const PCB_GROUP* aGroup, int aLayer )
3050{
3051 if( aLayer == LAYER_ANCHOR )
3052 {
3053 if( aGroup->IsSelected() && !( aGroup->GetParent() && aGroup->GetParent()->IsSelected() ) )
3054 {
3055 // Selected on our own; draw enclosing box
3056 }
3057 else if( aGroup->IsEntered() )
3058 {
3059 // Entered group; draw enclosing box
3060 }
3061 else
3062 {
3063 // Neither selected nor entered; draw nothing at the group level (ie: only draw
3064 // its members)
3065 return;
3066 }
3067
3068 const COLOR4D color = m_pcbSettings.GetColor( aGroup, LAYER_ANCHOR );
3069
3070 m_gal->SetStrokeColor( color );
3071 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth * 2.0f );
3072
3073 BOX2I bbox = aGroup->GetBoundingBox();
3074 VECTOR2I topLeft = bbox.GetPosition();
3075 VECTOR2I width = VECTOR2I( bbox.GetWidth(), 0 );
3076 VECTOR2I height = VECTOR2I( 0, bbox.GetHeight() );
3077
3078 m_gal->DrawLine( topLeft, topLeft + width );
3079 m_gal->DrawLine( topLeft + width, topLeft + width + height );
3080 m_gal->DrawLine( topLeft + width + height, topLeft + height );
3081 m_gal->DrawLine( topLeft + height, topLeft );
3082
3083 wxString name = aGroup->GetName();
3084
3085 if( name.IsEmpty() )
3086 return;
3087
3088 int ptSize = 12;
3089 int scaledSize = abs( KiROUND( m_gal->GetScreenWorldMatrix().GetScale().x * ptSize ) );
3090 int unscaledSize = pcbIUScale.MilsToIU( ptSize );
3091
3092 // Scale by zoom a bit, but not too much
3093 int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3;
3094 VECTOR2I textOffset = KiROUND( width.x / 2.0, -textSize * 0.5 );
3095 VECTOR2I titleHeight = KiROUND( 0.0, textSize * 2.0 );
3096
3097 if( PrintableCharCount( name ) * textSize < bbox.GetWidth() )
3098 {
3099 m_gal->DrawLine( topLeft, topLeft - titleHeight );
3100 m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight );
3101 m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width );
3102
3103 TEXT_ATTRIBUTES attrs;
3104 attrs.m_Italic = true;
3107 attrs.m_Size = VECTOR2I( textSize, textSize );
3108 attrs.m_StrokeWidth = GetPenSizeForNormal( textSize );
3109
3110 KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs,
3111 aGroup->GetFontMetrics() );
3112 }
3113 }
3114}
3115
3116
3117bool KIGFX::ZoneOutlineDrawnOnLayer( bool aIsRuleArea, int aLayer )
3118{
3119 if( aIsRuleArea )
3120 return IsZoneFillLayer( aLayer );
3121
3122 return !IsZoneFillLayer( aLayer );
3123}
3124
3125
3126void PCB_PAINTER::draw( const ZONE* aZone, int aLayer )
3127{
3128 if( aLayer == LAYER_CONFLICTS_SHADOW )
3129 {
3130 if( aZone->IsConflicting() && aZone->GetIsRuleArea() )
3131 {
3132 COLOR4D color = m_pcbSettings.GetColor( aZone, aLayer );
3133
3134 m_gal->SetIsFill( true );
3135 m_gal->SetIsStroke( false );
3136 m_gal->SetFillColor( color );
3137
3138 m_gal->DrawPolygon( aZone->GetBoardOutline().Outline( 0 ) );
3139 }
3140
3141 return;
3142 }
3143
3144 /*
3145 * aLayer will be the virtual zone layer (LAYER_ZONE_START, ... in GAL_LAYER_ID)
3146 * This is used for draw ordering in the GAL.
3147 * The color for the zone comes from the associated copper layer ( aLayer - LAYER_ZONE_START )
3148 * and the visibility comes from the combination of that copper layer and LAYER_ZONES
3149 */
3150 PCB_LAYER_ID layer;
3151
3152 if( IsZoneFillLayer( aLayer ) )
3153 layer = ToLAYER_ID( aLayer - LAYER_ZONE_START );
3154 else
3155 layer = ToLAYER_ID( aLayer );
3156
3157 if( !aZone->IsOnLayer( layer ) )
3158 return;
3159
3160 COLOR4D color = m_pcbSettings.GetColor( aZone, layer );
3161 std::deque<VECTOR2D> corners;
3162 ZONE_DISPLAY_MODE displayMode = m_pcbSettings.m_ZoneDisplayMode;
3163
3164 if( aZone->IsTeardropArea() )
3165 displayMode = ZONE_DISPLAY_MODE::SHOW_FILLED;
3166
3167 // Draw the outline
3168 if( ZoneOutlineDrawnOnLayer( aZone->GetIsRuleArea(), aLayer ) )
3169 {
3170 const SHAPE_POLY_SET boardOutline = aZone->GetBoardOutline();
3171 const SHAPE_POLY_SET* outline = &boardOutline;
3172 bool allowDrawOutline = aZone->GetHatchStyle() != ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER;
3173
3174 if( allowDrawOutline && !m_pcbSettings.m_isPrinting && outline && outline->OutlineCount() > 0 )
3175 {
3176 m_gal->SetStrokeColor( color.a > 0.0 ? color.WithAlpha( 1.0 ) : color );
3177 m_gal->SetIsFill( false );
3178 m_gal->SetIsStroke( true );
3179 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
3180
3181 // Draw each contour (main contour and holes)
3182
3183 /*
3184 * m_canvas->DrawPolygon( *outline );
3185 * should be enough, but currently does not work to draw holes contours in a complex
3186 * polygon so each contour is draw as a simple polygon
3187 */
3188
3189 // Draw the main contour(s?)
3190 for( int ii = 0; ii < outline->OutlineCount(); ++ii )
3191 {
3192 m_gal->DrawPolyline( outline->COutline( ii ) );
3193
3194 // Draw holes
3195 int holes_count = outline->HoleCount( ii );
3196
3197 for( int jj = 0; jj < holes_count; ++jj )
3198 m_gal->DrawPolyline( outline->CHole( ii, jj ) );
3199 }
3200
3201 // Draw hatch lines
3202 for( const SEG& hatchLine : aZone->GetHatchLines() )
3203 m_gal->DrawLine( hatchLine.A, hatchLine.B );
3204 }
3205 }
3206
3207 // Draw the filling
3208 if( IsZoneFillLayer( aLayer )
3209 && ( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED
3211 || displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ) )
3212 {
3213 const std::shared_ptr<SHAPE_POLY_SET>& polySet = aZone->GetFilledPolysList( layer );
3214
3215 if( polySet->OutlineCount() == 0 ) // Nothing to draw
3216 return;
3217
3218 m_gal->SetStrokeColor( color );
3219 m_gal->SetFillColor( color );
3220 m_gal->SetLineWidth( 0 );
3221
3222 if( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED )
3223 {
3224 m_gal->SetIsFill( true );
3225 m_gal->SetIsStroke( false );
3226 }
3227 else
3228 {
3229 m_gal->SetIsFill( false );
3230 m_gal->SetIsStroke( true );
3231 }
3232
3233 // On Opengl, a not convex filled polygon is usually drawn by using triangles
3234 // as primitives. CacheTriangulation() can create basic triangle primitives to
3235 // draw the polygon solid shape on Opengl. GLU tessellation is much slower,
3236 // so currently we are using our tessellation.
3237 if( m_gal->IsOpenGlEngine() && !polySet->IsTriangulationUpToDate() )
3238 polySet->CacheTriangulation( true );
3239
3240 m_gal->DrawPolygon( *polySet, displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION );
3241 }
3242}
3243
3244
3245void PCB_PAINTER::draw( const PCB_BARCODE* aBarcode, int aLayer )
3246{
3247 const COLOR4D& color = m_pcbSettings.GetColor( aBarcode, aLayer );
3248
3249 m_gal->SetIsFill( true );
3250 m_gal->SetIsStroke( false );
3251 m_gal->SetFillColor( color );
3252
3253 // Draw the barcode
3254 SHAPE_POLY_SET shape;
3255
3256 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
3257 aBarcode->GetBoundingHull( shape, aBarcode->GetLayer(), m_lockedShadowMargin, m_maxError, ERROR_INSIDE );
3258 else
3259 aBarcode->TransformShapeToPolySet( shape, aBarcode->GetLayer(), 0, m_maxError, ERROR_INSIDE );
3260
3261 if( shape.OutlineCount() != 0 )
3262 m_gal->DrawPolygon( shape );
3263}
3264
3265
3266void PCB_PAINTER::draw( const PCB_DIMENSION_BASE* aDimension, int aLayer )
3267{
3268 const COLOR4D& color = m_pcbSettings.GetColor( aDimension, aLayer );
3269
3270 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
3271 {
3272 m_gal->SetIsFill( true );
3273 m_gal->SetIsStroke( true );
3274 m_gal->SetFillColor( color );
3275 m_gal->SetStrokeColor( color );
3276 m_gal->SetLineWidth( m_lockedShadowMargin );
3277
3278 for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
3279 {
3280 switch( shape->Type() )
3281 {
3282 case SH_SEGMENT:
3283 {
3284 const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
3285 m_gal->DrawSegment( seg.A, seg.B, m_lockedShadowMargin );
3286 break;
3287 }
3288
3289 case SH_CIRCLE:
3290 {
3291 int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
3292 m_gal->DrawCircle( shape->Centre(), radius );
3293 break;
3294 }
3295
3296 default: break;
3297 }
3298 }
3299
3300 SHAPE_POLY_SET poly;
3301 aDimension->PCB_TEXT::TransformShapeToPolygon( poly, aDimension->GetLayer(), 0, m_maxError, ERROR_OUTSIDE );
3302 m_gal->DrawPolygon( poly );
3303
3304 return;
3305 }
3306
3307 m_gal->SetStrokeColor( color );
3308 m_gal->SetFillColor( color );
3309 m_gal->SetIsFill( false );
3310 m_gal->SetIsStroke( true );
3311
3313
3314 if( outline_mode )
3315 m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth );
3316 else
3317 m_gal->SetLineWidth( getLineThickness( aDimension->GetLineThickness() ) );
3318
3319 // Draw dimension shapes
3320 // TODO(JE) lift this out
3321 for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
3322 {
3323 switch( shape->Type() )
3324 {
3325 case SH_SEGMENT:
3326 {
3327 const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
3328 m_gal->DrawLine( seg.A, seg.B );
3329 break;
3330 }
3331
3332 case SH_CIRCLE:
3333 {
3334 int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
3335 m_gal->DrawCircle( shape->Centre(), radius );
3336 break;
3337 }
3338
3339 default:
3340 break;
3341 }
3342 }
3343
3344 // Draw text
3345 wxString resolvedText = aDimension->GetShownText( true );
3346 TEXT_ATTRIBUTES attrs = aDimension->GetAttributes();
3347
3348 if( m_gal->IsFlippedX() && !aDimension->IsSideSpecific() )
3349 attrs.m_Mirrored = !attrs.m_Mirrored;
3350
3351 if( outline_mode )
3352 attrs.m_StrokeWidth = m_pcbSettings.m_outlineWidth;
3353 else
3355
3356 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
3357
3358 if( aDimension->GetFont() && aDimension->GetFont()->IsOutline() )
3359 cache = aDimension->GetRenderCache( aDimension->GetFont(), resolvedText );
3360
3361 if( cache )
3362 {
3363 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : *cache )
3364 m_gal->DrawGlyph( *glyph.get() );
3365 }
3366 else
3367 {
3368 strokeText( resolvedText, aDimension->GetTextPos(), attrs, aDimension->GetFontMetrics() );
3369 }
3370}
3371
3372
3373void PCB_PAINTER::draw( const PCB_TARGET* aTarget )
3374{
3375 const COLOR4D strokeColor = m_pcbSettings.GetColor( aTarget, aTarget->GetLayer() );
3376 VECTOR2D position( aTarget->GetPosition() );
3377 double size, radius;
3378
3379 m_gal->SetLineWidth( getLineThickness( aTarget->GetWidth() ) );
3380 m_gal->SetStrokeColor( strokeColor );
3381 m_gal->SetIsFill( false );
3382 m_gal->SetIsStroke( true );
3383
3384 m_gal->Save();
3385 m_gal->Translate( position );
3386
3387 if( aTarget->GetShape() )
3388 {
3389 // shape x
3390 m_gal->Rotate( M_PI / 4.0 );
3391 size = 2.0 * aTarget->GetSize() / 3.0;
3392 radius = aTarget->GetSize() / 2.0;
3393 }
3394 else
3395 {
3396 // shape +
3397 size = aTarget->GetSize() / 2.0;
3398 radius = aTarget->GetSize() / 3.0;
3399 }
3400
3401 m_gal->DrawLine( VECTOR2D( -size, 0.0 ), VECTOR2D( size, 0.0 ) );
3402 m_gal->DrawLine( VECTOR2D( 0.0, -size ), VECTOR2D( 0.0, size ) );
3403 m_gal->DrawCircle( VECTOR2D( 0.0, 0.0 ), radius );
3404
3405 m_gal->Restore();
3406}
3407
3408
3409void PCB_PAINTER::draw( const PCB_POINT* aPoint, int aLayer )
3410{
3411 // aLayer will be the virtual point layer (LAYER_POINT_START, ... in GAL_LAYER_ID).
3412 // This is used for draw ordering in the GAL.
3413 // The cross color comes from LAYER_POINTS and the ring color follows the point's board layer.
3414 // Visibility comes from the combination of that board layer and LAYER_POINTS.
3415
3416 double size = (double)aPoint->GetSize() / 2;
3417
3418 // Keep the width constant, not related to the scale because the anchor
3419 // is just a marker on screen, just draw in pixels
3420 double thickness = m_pcbSettings.m_outlineWidth;
3421
3422 // The general "points" colour
3423 COLOR4D crossColor = m_pcbSettings.GetColor( aPoint, LAYER_POINTS );
3424 // The colour for the ring around the point follows the "real" layer of the point
3425 COLOR4D ringColor = m_pcbSettings.GetColor( aPoint, aPoint->GetLayer() );
3426
3427 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
3428 {
3429 thickness += m_lockedShadowMargin;
3430 crossColor = m_pcbSettings.GetColor( aPoint, aLayer );
3431 ringColor = m_pcbSettings.GetColor( aPoint, aLayer );
3432 }
3433
3434 VECTOR2D position( aPoint->GetPosition() );
3435
3436 m_gal->SetLineWidth( thickness );
3437 m_gal->SetStrokeColor( crossColor );
3438 m_gal->SetIsFill( false );
3439 m_gal->SetIsStroke( true );
3440
3441 m_gal->Save();
3442 m_gal->Translate( position );
3443
3444 // Draw as X to make it clearer when overlaid on cursor or axes
3445 m_gal->DrawLine( VECTOR2D( -size, -size ), VECTOR2D( size, size ) );
3446 m_gal->DrawLine( VECTOR2D( size, -size ), VECTOR2D( -size, size ) );
3447
3448 // Draw the circle in the layer colour
3449 m_gal->SetStrokeColor( ringColor );
3450 m_gal->DrawCircle( VECTOR2D( 0.0, 0.0 ), size / 2 );
3451
3452 m_gal->Restore();
3453}
3454
3455
3456void PCB_PAINTER::draw( const PCB_MARKER* aMarker, int aLayer )
3457{
3458 // Don't paint invisible markers.
3459 // It would be nice to do this through layer dependencies but we can't do an "or" there today
3460 if( aMarker->GetBoard() && !aMarker->GetBoard()->IsElementVisible( aMarker->GetColorLayer() ) )
3461 return;
3462
3463 COLOR4D color = m_pcbSettings.GetColor( aMarker, aMarker->GetColorLayer() );
3464
3465 aMarker->SetZoom( 1.0 / sqrt( m_gal->GetZoomFactor() ) );
3466
3467 switch( aLayer )
3468 {
3470 case LAYER_DRC_ERROR:
3471 case LAYER_DRC_WARNING:
3474 {
3475 // The active marker is redrawn on LAYER_DRC_HIGHLIGHTED so it lands on top of any
3476 // neighbouring inactive markers
3477 if( aLayer == LAYER_DRC_HIGHLIGHTED && !aMarker->IsBrightened() && !aMarker->IsSelected() )
3478 return;
3479
3480 bool isShadow = aLayer == LAYER_MARKER_SHADOWS;
3481
3482 SHAPE_LINE_CHAIN polygon;
3483 aMarker->ShapeToPolygon( polygon );
3484
3485 m_gal->Save();
3486 m_gal->Translate( aMarker->GetPosition() );
3487
3488 if( isShadow )
3489 {
3490 m_gal->SetStrokeColor( m_pcbSettings.GetColor( aMarker, LAYER_MARKER_SHADOWS ) );
3491 m_gal->SetIsStroke( true );
3492 m_gal->SetLineWidth( (float) aMarker->MarkerScale() );
3493 }
3494 else
3495 {
3496 m_gal->SetFillColor( color );
3497 m_gal->SetIsFill( true );
3498 }
3499
3500 m_gal->DrawPolygon( polygon );
3501 m_gal->Restore();
3502 break;
3503 }
3504
3505 case LAYER_DRC_SHAPES:
3506 if( !aMarker->IsBrightened() && !aMarker->IsSelected() )
3507 return;
3508
3509 for( const PCB_SHAPE& shape : aMarker->GetShapes() )
3510 {
3511 if( shape.GetStroke().GetWidth() == 1.0 )
3512 {
3513 m_gal->SetIsFill( false );
3514 m_gal->SetIsStroke( true );
3515 m_gal->SetStrokeColor( color );
3516 m_gal->SetLineWidth( KiROUND( aMarker->MarkerScale() / 2.0 ) );
3517
3518 if( shape.GetShape() == SHAPE_T::SEGMENT )
3519 {
3520 m_gal->DrawLine( shape.GetStart(), shape.GetEnd() );
3521 }
3522 else if( shape.GetShape() == SHAPE_T::ARC )
3523 {
3524 EDA_ANGLE startAngle, endAngle;
3525 shape.CalcArcAngles( startAngle, endAngle );
3526
3527 m_gal->DrawArc( shape.GetCenter(), shape.GetRadius(), startAngle, shape.GetArcAngle() );
3528 }
3529 }
3530 else
3531 {
3532 m_gal->SetIsFill( true );
3533 m_gal->SetIsStroke( false );
3534 m_gal->SetFillColor( color.WithAlpha( 0.5 ) );
3535
3536 if( shape.GetShape() == SHAPE_T::SEGMENT )
3537 {
3538 m_gal->DrawSegment( shape.GetStart(), shape.GetEnd(), shape.GetWidth() );
3539 }
3540 else if( shape.GetShape() == SHAPE_T::ARC )
3541 {
3542 EDA_ANGLE startAngle, endAngle;
3543 shape.CalcArcAngles( startAngle, endAngle );
3544
3545 m_gal->DrawArcSegment( shape.GetCenter(), shape.GetRadius(), startAngle, shape.GetArcAngle(),
3546 shape.GetWidth(), ARC_HIGH_DEF );
3547 }
3548 }
3549 }
3550
3551 break;
3552 }
3553}
3554
3555
3556void PCB_PAINTER::draw( const PCB_BOARD_OUTLINE* aBoardOutline, int aLayer )
3557{
3558 if( !aBoardOutline->HasOutline() )
3559 return;
3560
3561 // aBoardOutline makes sense only for the board editor. for fp holder boards
3562 // there are no board outlines area.
3563 const BOARD* brd = aBoardOutline->GetBoard();
3564
3565 if( !brd || brd->GetBoardUse() == BOARD_USE::FPHOLDER )
3566 return;
3567
3569 m_gal->Save();
3570
3571 const COLOR4D& outlineColor = m_pcbSettings.GetColor( aBoardOutline, aLayer );
3572 m_gal->SetFillColor( outlineColor );
3573 m_gal->AdvanceDepth();
3574 m_gal->SetLineWidth( 0 );
3575 m_gal->SetIsFill( true );
3576 m_gal->SetIsStroke( false );
3577 m_gal->DrawPolygon( aBoardOutline->GetOutline() );
3578
3579 m_gal->Restore();
3580}
3581
3582
3584 int aDrillSize, PCB_LAYER_ID aStartLayer,
3585 PCB_LAYER_ID aEndLayer )
3586{
3587 double backdrillRadius = aDrillSize / 2.0;
3588 double lineWidth = std::max( backdrillRadius / 4.0, m_pcbSettings.m_outlineWidth * 2.0 );
3589
3591 m_gal->AdvanceDepth();
3592 m_gal->SetIsFill( false );
3593 m_gal->SetIsStroke( true );
3594 m_gal->SetLineWidth( lineWidth );
3595
3596 // Draw semi-circle in start layer color (top half, from 90° to 270°)
3597 m_gal->SetStrokeColor( m_pcbSettings.GetColor( aItem, aStartLayer ) );
3598 m_gal->DrawArc( aCenter, backdrillRadius, EDA_ANGLE( 90, DEGREES_T ),
3599 EDA_ANGLE( 180, DEGREES_T ) );
3600
3601 // Draw semi-circle in end layer color (bottom half, from 270° to 90°)
3602 m_gal->SetStrokeColor( m_pcbSettings.GetColor( aItem, aEndLayer ) );
3603 m_gal->DrawArc( aCenter, backdrillRadius, EDA_ANGLE( 270, DEGREES_T ),
3604 EDA_ANGLE( 180, DEGREES_T ) );
3605}
3606
3607
3609{
3610 int size = 0;
3611
3612 // Check to see if the pad or via has a post-machining operation on this layer
3613 if( const PAD* pad = dynamic_cast<const PAD*>( aItem ) )
3614 {
3615 size = pad->GetPostMachiningKnockout( aLayer );
3616 }
3617 else if( const PCB_VIA* via = dynamic_cast<const PCB_VIA*>( aItem ) )
3618 {
3619 size = via->GetPostMachiningKnockout( aLayer );
3620 }
3621
3622 if( size <= 0 )
3623 return;
3624
3626 m_gal->AdvanceDepth();
3627
3628 double pmRadius = size / 2.0;
3629 // Use a line width proportional to the radius for visibility
3630 double lineWidth = std::max( pmRadius / 8.0, m_pcbSettings.m_outlineWidth * 2.0 );
3631
3632 COLOR4D layerColor = m_pcbSettings.GetColor( aItem, aLayer );
3633
3634 m_gal->SetIsFill( false );
3635 m_gal->SetIsStroke( true );
3636 m_gal->SetStrokeColor( layerColor );
3637 m_gal->SetLineWidth( lineWidth );
3638
3639 // Draw dashed circle manually with fixed number of segments for consistent appearance
3640 constexpr int NUM_DASHES = 12; // Number of dashes around the circle
3641 EDA_ANGLE dashAngle = ANGLE_360 / ( NUM_DASHES * 2 ); // Dash and gap are equal size
3642
3643 for( int i = 0; i < NUM_DASHES; ++i )
3644 {
3645 EDA_ANGLE startAngle = dashAngle * ( i * 2 );
3646 m_gal->DrawArc( aCenter, pmRadius, startAngle, dashAngle );
3647 }
3648}
3649
3650
3651const double PCB_RENDER_SETTINGS::MAX_FONT_SIZE = pcbIUScale.mmToIU( 10.0 );
const char * name
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
@ ERROR_OUTSIDE
@ ERROR_INSIDE
constexpr int ARC_HIGH_DEF
Definition base_units.h:137
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
@ FPHOLDER
Definition board.h:364
@ NORMAL
Inactive layers are shown normally (no high-contrast mode)
@ HIDDEN
Inactive layers are hidden.
@ RATSNEST
Net/netclass colors are shown on ratsnest lines only.
@ ALL
Net/netclass colors are shown on all net copper.
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
BOX2< VECTOR2D > BOX2D
Definition box2.h:919
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
const wxString & GetDisplayNetname() const
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
Container for design settings for a BOARD object.
int GetHolePlatingThickness() const
Pad & via drills are finish size.
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:265
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:155
virtual bool IsKnockout() const
Definition board_item.h:352
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:285
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:479
const KIFONT::METRICS & GetFontMetrics() const
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:231
bool IsSideSpecific() const
virtual bool IsOnCopperLayer() const
Definition board_item.h:172
int GetMaxError() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
BOARD_USE GetBoardUse() const
Get what the board use is.
Definition board.h:391
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition board.cpp:1100
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1048
int GetCopperLayerCount() const
Definition board.cpp:985
KIGFX::COLOR4D GetNetChainColor(const wxString &aChain) const
Definition board.h:1206
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1149
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1034
constexpr const Vec & GetPosition() const
Definition box2.h:207
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:554
constexpr const Vec GetEnd() const
Definition box2.h:208
constexpr void SetOrigin(const Vec &pos)
Definition box2.h:233
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:142
constexpr size_type GetWidth() const
Definition box2.h:210
constexpr Vec Centre() const
Definition box2.h:93
constexpr size_type GetHeight() const
Definition box2.h:211
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:164
constexpr const Vec & GetOrigin() const
Definition box2.h:206
constexpr const SizeVec & GetSize() const
Definition box2.h:202
constexpr void SetEnd(coord_type x, coord_type y)
Definition box2.h:293
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
APPEARANCE m_Appearance
EDA_ANGLE Normalize90()
Definition eda_angle.h:257
double AsRadians() const
Definition eda_angle.h:120
wxString GetName() const
Definition eda_group.h:47
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:135
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
bool IsEntered() const
Definition eda_item.h:133
bool IsSelected() const
Definition eda_item.h:132
bool IsBrightened() const
Definition eda_item.h:134
bool IsMoving() const
Definition eda_item.h:130
int GetEllipseMinorRadius() const
Definition eda_shape.h:310
const VECTOR2I & GetBezierC2() const
Definition eda_shape.h:283
const VECTOR2I & GetEllipseCenter() const
Definition eda_shape.h:292
virtual VECTOR2I GetTopLeft() const
Definition eda_shape.h:271
EDA_ANGLE GetEllipseEndAngle() const
Definition eda_shape.h:338
int GetEllipseMajorRadius() const
Definition eda_shape.h:301
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:462
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:319
int GetRadius() const
SHAPE_T GetShape() const
Definition eda_shape.h:185
virtual VECTOR2I GetBotRight() const
Definition eda_shape.h:272
const std::vector< SEG > & GetHatchLines() const
bool IsHatchedFill() const
Definition eda_shape.h:140
virtual int GetHatchLineWidth() const
Definition eda_shape.h:175
bool IsSolidFill() const
Definition eda_shape.h:133
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:240
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:190
std::vector< VECTOR2I > GetRectCorners() const
bool IsAnyFill() const
Definition eda_shape.h:128
EDA_ANGLE GetEllipseStartAngle() const
Definition eda_shape.h:329
const std::vector< VECTOR2I > & GetBezierPoints() const
Definition eda_shape.h:404
const VECTOR2I & GetBezierC1() const
Definition eda_shape.h:280
int GetRectangleHeight() const
int GetCornerRadius() const
virtual bool IsVisible() const
Definition eda_text.h:208
KIFONT::FONT * GetFont() const
Definition eda_text.h:268
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:703
BOX2I GetTextBox(const RENDER_SETTINGS *aSettings, int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition eda_text.cpp:773
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:221
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:667
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:252
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:461
LSET GetPrivateLayers() const
Definition footprint.h:315
SHAPE_POLY_SET GetBoundingHull() const
Return a bounding polygon for the shapes and pads in the footprint.
bool IsConflicting() const
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
VECTOR2I GetPosition() const override
Definition footprint.h:403
DRAWINGS & GraphicalItems()
Definition footprint.h:378
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:91
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:143
virtual bool IsStroke() const
Definition font.h:101
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:246
virtual bool IsOutline() const
Definition font.h:102
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition color4d.h:308
static const COLOR4D CLEAR
Definition color4d.h:403
COLOR4D & Darken(double aFactor)
Makes the color darker by a given factor.
Definition color4d.h:223
COLOR4D Darkened(double aFactor) const
Return a color that is darker by a given factor, without modifying object.
Definition color4d.h:279
COLOR4D Inverted() const
Returns an inverted color, alpha remains the same.
Definition color4d.h:320
COLOR4D & Brighten(double aFactor)
Makes the color brighter by a given factor.
Definition color4d.h:206
static const COLOR4D WHITE
Definition color4d.h:401
double a
Alpha component.
Definition color4d.h:392
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
Definition color4d.h:265
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
static const COLOR4D BLACK
Definition color4d.h:402
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:292
Attribute save/restore for GAL attributes.
Abstract interface for drawing on a 2D-surface.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition painter.h:98
PAINTER(GAL *aGal)
Initialize this object for painting on any of the polymorphic GRAPHICS_ABSTRACTION_LAYER* derivatives...
Definition painter.cpp:29
void drawPostMachiningIndicator(const BOARD_ITEM *aItem, const VECTOR2D &aCenter, PCB_LAYER_ID aLayer)
Draw post-machining indicator (dashed circle) at the given center point.
virtual SHAPE_SEGMENT getPadHoleShape(const PAD *aPad) const
Return hole shape for a pad (internal units).
PCB_PAINTER(GAL *aGal, FRAME_T aFrameType)
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
void renderNetNameForSegment(const SHAPE_SEGMENT &aSeg, const COLOR4D &aColor, const wxString &aNetName) const
PCB_VIEWERS_SETTINGS_BASE * viewer_settings()
void draw(const PCB_TRACK *aTrack, int aLayer)
virtual PAD_DRILL_SHAPE getDrillShape(const PAD *aPad) const
Return drill shape of a pad.
PCB_RENDER_SETTINGS m_pcbSettings
virtual int getViaDrillSize(const PCB_VIA *aVia) const
Return drill diameter for a via (internal units).
void strokeText(const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics)
void drawBackdrillIndicator(const BOARD_ITEM *aItem, const VECTOR2D &aCenter, int aDrillSize, PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer)
Draw backdrill indicator (two semi-circles) at the given center point.
virtual bool Draw(const VIEW_ITEM *aItem, int aLayer) override
Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item.
double m_zoneOpacity
Opacity override for filled zones.
double m_trackOpacity
Opacity override for all tracks.
double m_imageOpacity
Opacity override for user images.
double m_viaOpacity
Opacity override for all types of via.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
void LoadColors(const COLOR_SETTINGS *aSettings) override
double m_padOpacity
Opacity override for SMD pads and PTHs.
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
HIGH_CONTRAST_MODE m_ContrastModeDisplay
std::map< int, KIGFX::COLOR4D > m_netColors
Set of net codes that should not have their ratsnest displayed.
NET_COLOR_MODE m_netColorMode
Overrides for specific netclass colors.
static const double MAX_FONT_SIZE
< Maximum font size for netnames (and other dynamically shown strings)
double m_filledShapeOpacity
Opacity override for graphic shapes.
bool GetShowPageLimits() const override
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Load settings related to display options (high-contrast mode, full or outline modes for vias/pads/tra...
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
void SetGapLengthRatio(double aRatio)
PCB_LAYER_ID GetActiveLayer() const
std::map< int, COLOR4D > m_layerColorsHi
virtual void update()
Precalculates extra colors for layers (e.g.
void SetDashLengthRatio(double aRatio)
std::set< int > m_highlightNetcodes
std::map< int, COLOR4D > m_layerColorsDark
std::map< int, COLOR4D > m_layerColorsSel
std::set< int > m_highContrastLayers
std::map< int, COLOR4D > m_layerColors
bool m_hiContrastEnabled
Parameters for display modes.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
bool IsBOARD_ITEM() const
Definition view_item.h:98
double GetForcedTransparency() const
Definition view_item.h:167
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition lset.cpp:538
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:309
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
static const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition lset.cpp:693
int MarkerScale() const
The scaling factor to convert polygonal shape coordinates to internal units.
Definition marker_base.h:65
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon, int aScale=-1) const
Return the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to the...
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:38
COLOR4D GetPcbColor(bool aIsForSave=false) const
Definition netclass.h:195
bool HasPcbColor() const
Definition netclass.h:194
Handle the data for a net.
Definition netinfo.h:46
const wxString & GetNetChain() const
Definition netinfo.h:112
PAD * GetTerminalPad(int aIndex) const
Definition netinfo.h:115
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:256
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:171
Definition pad.h:61
int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const override
Return the pad's "own" clearance in internal units.
Definition pad.cpp:1944
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition pad.h:552
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives(PCB_LAYER_ID aLayer) const
Accessor to the basic shape list for custom-shaped pads.
Definition pad.h:370
int GetSizeX() const
Definition pad.cpp:311
bool FlashLayer(int aLayer, bool aOnlyCheckIfPermitted=false) const
Check to see whether the pad should be flashed on the specific layer.
Definition pad.cpp:650
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer, FLASHING flashPTHPads=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition pad.cpp:1208
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
Definition pad.cpp:1599
PAD_ATTRIB GetAttribute() const
Definition pad.h:555
const wxString & GetPinFunction() const
Definition pad.h:154
const wxString & GetNumber() const
Definition pad.h:143
VECTOR2I GetPosition() const override
Definition pad.cpp:245
PCB_LAYER_ID GetTertiaryDrillEndLayer() const
Definition pad.h:537
VECTOR2I GetOffset(PCB_LAYER_ID aLayer) const
Definition pad.cpp:796
PCB_LAYER_ID GetTertiaryDrillStartLayer() const
Definition pad.h:535
bool IsNoConnectPad() const
Definition pad.cpp:567
int GetDrillSizeX() const
Definition pad.h:317
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:202
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool ignoreLineWidth=false) const override
Convert the pad shape to a closed polygon.
Definition pad.cpp:2945
int GetSolderMaskExpansion(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1951
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:287
bool IsFreePad() const
Definition pad.cpp:573
const VECTOR2I & GetSecondaryDrillSize() const
Definition pad.h:506
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition pad.cpp:1723
PAD_DRILL_SHAPE GetDrillShape() const
Definition pad.h:429
int GetSizeY() const
Definition pad.cpp:331
int GetPostMachiningKnockout(PCB_LAYER_ID aLayer) const
Get the knockout diameter for a layer affected by post-machining.
Definition pad.cpp:908
VECTOR2I GetSolderPasteMargin(PCB_LAYER_ID aLayer) const
Usually < 0 (mask shape smaller than pad)because the margin can be dependent on the pad size,...
Definition pad.cpp:2014
PCB_LAYER_ID GetSecondaryDrillStartLayer() const
Definition pad.h:518
const VECTOR2I & GetTertiaryDrillSize() const
Definition pad.h:523
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1831
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const override
Return a SHAPE_SEGMENT object representing the pad's hole.
Definition pad.cpp:1312
PCB_LAYER_ID GetSecondaryDrillEndLayer() const
Definition pad.h:520
DISPLAY_OPTIONS m_Display
EDA_ANGLE GetArcAngleStart() const
const VECTOR2I GetFocusPosition() const override
Similar to GetPosition() but allows items to return their visual center rather than their anchor.
Definition pcb_track.h:291
double GetRadius() const
EDA_ANGLE GetAngle() const
const VECTOR2I & GetMid() const
Definition pcb_track.h:286
virtual VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_track.h:293
void GetBoundingHull(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
bool HasOutline() const
const SHAPE_POLY_SET & GetOutline() const
Abstract dimension API.
int GetLineThickness() const
const std::vector< std::shared_ptr< SHAPE > > & GetShapes() const
double m_TrackOpacity
Opacity override for all tracks.
double m_FilledShapeOpacity
Opacity override for graphic shapes.
double m_ZoneOpacity
Opacity override for filled zone areas.
double m_ImageOpacity
Opacity override for user images.
double m_PadOpacity
Opacity override for SMD pads and PTHs.
double m_ViaOpacity
Opacity override for all types of via.
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
NET_COLOR_MODE m_NetColorMode
How to use color overrides on specific nets and netclasses.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:49
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void SetZoom(double aZoomFactor) const
std::vector< PCB_SHAPE > GetShapes() const
GAL_LAYER_ID GetColorLayer() const
VECTOR2I GetPosition() const override
Definition pcb_marker.h:60
PCB_VIEWERS_SETTINGS_BASE * viewer_settings()
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Definition pcb_point.h:39
int GetSize() const
Definition pcb_point.h:69
VECTOR2I GetPosition() const override
Definition pcb_point.h:60
Object to handle a bitmap image that can be inserted in a PCB.
REFERENCE_IMAGE & GetReferenceImage()
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_shape.h:78
int GetWidth() const override
bool HasSolderMask() const
Definition pcb_shape.h:329
int GetSolderMaskExpansion() const
bool IsProxyItem() const override
Definition pcb_shape.h:146
STROKE_PARAMS GetStroke() const override
void UpdateHatching() const override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:68
int GetRowSpan() const
int GetColSpan() const
std::vector< PCB_TABLECELL * > GetCells() const
Definition pcb_table.h:156
void DrawBorders(const std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const STROKE_PARAMS &aStroke)> &aCallback) const
int GetShape() const
Definition pcb_target.h:54
int GetWidth() const
Definition pcb_target.h:60
int GetSize() const
Definition pcb_target.h:57
VECTOR2I GetPosition() const override
Definition pcb_target.h:51
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...
VECTOR2I GetTextSize() const override
VECTOR2I GetDrawPos() const override
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
std::vector< VECTOR2I > GetCorners() const override
Return 4 corners for a rectangle or rotated rectangle (stored as a poly).
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
Definition pcb_text.cpp:834
const SHAPE_POLY_SET & GetKnockoutCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, int aMaxError) const
Definition pcb_text.cpp:706
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition pcb_text.cpp:161
VECTOR2I GetTextPos() const override
Definition pcb_text.cpp:444
int GetTextThickness() const override
Definition pcb_text.cpp:480
EDA_ANGLE GetDrawRotation() const override
Definition pcb_text.cpp:203
VECTOR2I GetTextSize() const override
Definition pcb_text.cpp:453
int GetSolderMaskExpansion() const
const VECTOR2I & GetStart() const
Definition pcb_track.h:93
const VECTOR2I & GetEnd() const
Definition pcb_track.h:90
virtual int GetWidth() const
Definition pcb_track.h:87
PCB_LAYER_ID BottomLayer() const
PCB_LAYER_ID GetTertiaryDrillEndLayer() const
Definition pcb_track.h:794
std::optional< int > GetTertiaryDrillSize() const
bool FlashLayer(int aLayer) const
Check to see whether the via should have a pad on the specific layer.
std::optional< int > GetSecondaryDrillSize() const
PCB_LAYER_ID GetSecondaryDrillEndLayer() const
Definition pcb_track.h:780
int GetWidth() const override
PCB_LAYER_ID GetTertiaryDrillStartLayer() const
Definition pcb_track.h:791
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
PCB_LAYER_ID TopLayer() const
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
VIATYPE GetViaType() const
Definition pcb_track.h:394
PCB_LAYER_ID GetSecondaryDrillStartLayer() const
Definition pcb_track.h:777
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Return the 2 layers used by the via (the via actually uses all layers between these 2 layers)
VIEWERS_DISPLAY_OPTIONS m_ViewersDisplay
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:528
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
VECTOR2I GetPosition() const
VECTOR2I GetSize() const
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
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::extended_type ecoord
Definition seg.h:40
VECTOR2I B
Definition seg.h:46
int Length() const
Return the length (this).
Definition seg.h:339
ecoord SquaredLength() const
Definition seg.h:344
T * GetAppSettings(const char *aFilename)
Return a handle to the a given settings by type.
VECTOR2I GetEnd() const override
Definition shape_arc.h:204
const SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError=DefaultAccuracyForPCB(), int *aActualError=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
VECTOR2I GetStart() const override
Definition shape_arc.h:203
const VECTOR2I & GetCenter() const
int GetRadius() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
bool IsTriangulationUpToDate() const
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
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)
virtual void CacheTriangulation(bool aSimplify=false, const TASK_SUBMITTER &aSubmitter={})
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
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.
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
int GetWidth() const override
Definition shape_rect.h:181
const VECTOR2I & GetPosition() const
Definition shape_rect.h:165
const VECTOR2I GetSize() const
Definition shape_rect.h:173
int GetHeight() const
Definition shape_rect.h:189
const SEG & GetSeg() const
int GetWidth() const override
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
const SHAPE_LINE_CHAIN & Vertices() const
Return the list of vertices defining this simple polygon.
virtual const SEG GetSegment(int aIndex) const override
const VECTOR2I & CPoint(int aIndex) const
Return a const reference to a given point in the polygon.
int PointCount() const
Return the number of points (vertices) in this polygon.
virtual size_t GetSegmentCount() const override
An abstract shape on 2D plane.
Definition shape.h:124
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)
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
KIFONT::FONT * m_Font
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:381
Handle a list of polygons defining a copper zone.
Definition zone.h:70
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:811
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition zone.h:697
SHAPE_POLY_SET GetBoardOutline() const
Definition zone.cpp:835
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
Definition zone.cpp:730
bool IsTeardropArea() const
Definition zone.h:786
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
Definition zone.h:685
bool IsConflicting() const
For rule areas which exclude footprints (and therefore participate in courtyard conflicts during move...
Definition zone.cpp:517
std::vector< SEG > GetHatchLines() const
Definition zone.cpp:1517
@ MAGENTA
Definition color4d.h:56
@ CYAN
Definition color4d.h:54
void TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
@ CHAMFER_ALL_CORNERS
All angles are chamfered.
@ ROUND_ALL_CORNERS
All angles are rounded.
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
@ DEGREES_T
Definition eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:408
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:407
static constexpr EDA_ANGLE ANGLE_360
Definition eda_angle.h:417
#define IGNORE_PARENT_GROUP
Definition eda_item.h:53
@ UNDEFINED
Definition eda_shape.h:45
@ ELLIPSE
Definition eda_shape.h:52
@ SEGMENT
Definition eda_shape.h:46
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:47
@ ELLIPSE_ARC
Definition eda_shape.h:53
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ FRAME_CVPCB_DISPLAY
Definition frame_type.h:49
@ FRAME_FOOTPRINT_VIEWER
Definition frame_type.h:41
@ FRAME_FOOTPRINT_WIZARD
Definition frame_type.h:42
@ FRAME_FOOTPRINT_PREVIEW
Definition frame_type.h:44
@ FRAME_FOOTPRINT_CHOOSER
Definition frame_type.h:40
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
@ FRAME_PCB_DISPLAY3D
Definition frame_type.h:43
@ FRAME_CVPCB
Definition frame_type.h:48
a few functions useful in geometry calculations.
int GetPenSizeForNormal(int aTextSize)
Definition gr_text.cpp:57
double m_HoleWallPaintingMultiplier
What factor to use when painting via and PTH pad hole walls, so that the painted hole wall can be ove...
bool IsSolderMaskLayer(int aLayer)
Definition layer_ids.h:746
@ LAYER_PAD_FR_NETNAMES
Additional netnames layers (not associated with a PCB layer).
Definition layer_ids.h:196
@ LAYER_PAD_BK_NETNAMES
Definition layer_ids.h:197
@ LAYER_PAD_NETNAMES
Definition layer_ids.h:198
@ NETNAMES_LAYER_ID_START
Definition layer_ids.h:190
bool IsPcbLayer(int aLayer)
Test whether a layer is a valid layer for Pcbnew.
Definition layer_ids.h:664
bool IsPadCopperLayer(int aLayer)
Definition layer_ids.h:879
bool IsPointsLayer(int aLayer)
Definition layer_ids.h:897
int GetNetnameLayer(int aLayer)
Return a netname layer corresponding to the given layer.
Definition layer_ids.h:852
bool IsClearanceLayer(int aLayer)
Definition layer_ids.h:891
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:675
@ LAYER_POINTS
PCB reference/manual snap points visibility.
Definition layer_ids.h:317
@ GAL_LAYER_ID_START
Definition layer_ids.h:225
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition layer_ids.h:303
@ LAYER_PAD_COPPER_START
Virtual layers for pad copper on a given copper layer.
Definition layer_ids.h:335
@ LAYER_VIA_HOLEWALLS
Definition layer_ids.h:294
@ LAYER_CONFLICTS_SHADOW
Shadow layer for items flagged conflicting.
Definition layer_ids.h:306
@ LAYER_NON_PLATEDHOLES
Draw usual through hole vias.
Definition layer_ids.h:235
@ LAYER_DRC_EXCLUSION
Layer for DRC markers which have been individually excluded.
Definition layer_ids.h:300
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition layer_ids.h:277
@ LAYER_DRC_HIGHLIGHTED
Color for highlighted DRC markers.
Definition layer_ids.h:328
@ LAYER_DRC_SHAPES
Custom shapes for DRC markers.
Definition layer_ids.h:311
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition layer_ids.h:288
@ LAYER_DRC_WARNING
Layer for DRC markers with #SEVERITY_WARNING.
Definition layer_ids.h:297
@ LAYER_PAD_PLATEDHOLES
to draw pad holes (plated)
Definition layer_ids.h:267
@ GAL_LAYER_ID_END
Definition layer_ids.h:358
@ LAYER_VIA_COPPER_START
Virtual layers for via copper on a given copper layer.
Definition layer_ids.h:339
@ LAYER_CLEARANCE_START
Virtual layers for pad/via/track clearance outlines for a given copper layer.
Definition layer_ids.h:343
@ LAYER_ZONE_START
Virtual layers for stacking zones and tracks on a given copper layer.
Definition layer_ids.h:331
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition layer_ids.h:244
@ LAYER_VIA_BURIED
Draw blind vias.
Definition layer_ids.h:231
@ LAYER_MARKER_SHADOWS
Shadows for DRC markers.
Definition layer_ids.h:301
@ LAYER_VIA_HOLES
Draw via holes (pad holes do not use this layer).
Definition layer_ids.h:270
@ LAYER_VIA_BLIND
Draw micro vias.
Definition layer_ids.h:230
@ LAYER_VIA_MICROVIA
Definition layer_ids.h:229
@ LAYER_VIA_THROUGH
Draw buried vias.
Definition layer_ids.h:232
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition layer_ids.h:273
@ LAYER_PAD_HOLEWALLS
Definition layer_ids.h:293
bool IsViaCopperLayer(int aLayer)
Definition layer_ids.h:885
bool IsNetnameLayer(int aLayer)
Test whether a layer is a netname layer.
Definition layer_ids.h:867
bool IsHoleLayer(int aLayer)
Definition layer_ids.h:737
bool IsExternalCopperLayer(int aLayerId)
Test whether a layer is an external (F_Cu or B_Cu) copper layer.
Definition layer_ids.h:686
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ Edge_Cuts
Definition layer_ids.h:108
@ 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
@ F_SilkS
Definition layer_ids.h:96
@ B_CrtYd
Definition layer_ids.h:111
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167
@ F_Cu
Definition layer_ids.h:60
bool IsZoneFillLayer(int aLayer)
Definition layer_ids.h:873
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
MATRIX3x3< double > MATRIX3x3D
Definition matrix3x3.h:469
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
bool ZoneOutlineDrawnOnLayer(bool aIsRuleArea, int aLayer)
Decide which GAL draw pass paints a zone's outline.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition padstack.h:69
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:103
@ PTH
Plated through hole pad.
Definition padstack.h:98
@ ROUNDRECT
Definition padstack.h:57
BARCODE class definition.
Class to handle a set of BOARD_ITEMs.
PCBNEW_SETTINGS * pcbconfig()
@ SHOW_WITH_VIA_ALWAYS
PGM_BASE & Pgm()
The global program "get" accessor.
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
see class PGM_BASE
@ 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_SEGMENT
line segment
Definition shape.h:44
wxString UnescapeString(const wxString &aSource)
int PrintableCharCount(const wxString &aString)
Return the number of printable (ie: non-formatting) chars.
LINE_STYLE
Dashed line types.
nlohmann::json output
VECTOR2I center
int radius
VECTOR2I end
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
int clearance
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
#define M_PI
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:225
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:81
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:99
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:96
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:97
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:104
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:86
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:101
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:85
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:82
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:83
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:92
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:94
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition typeinfo.h:100
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:88
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:79
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:95
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:80
@ PCB_BOARD_OUTLINE_T
class PCB_BOARD_OUTLINE_T, a pcb board outline item
Definition typeinfo.h:105
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:91
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:87
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:106
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:98
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682