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