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 (C) 2021-2024 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 <board.h>
30#include <pcb_track.h>
31#include <pcb_group.h>
32#include <footprint.h>
33#include <pad.h>
34#include <pcb_shape.h>
35#include <string_utils.h>
36#include <zone.h>
37#include <pcb_reference_image.h>
38#include <pcb_text.h>
39#include <pcb_textbox.h>
40#include <pcb_table.h>
41#include <pcb_tablecell.h>
42#include <pcb_marker.h>
43#include <pcb_dimension.h>
44#include <pcb_target.h>
45
46#include <layer_ids.h>
47#include <lset.h>
48#include <pcb_painter.h>
49#include <pcb_display_options.h>
55#include <pcbnew_settings.h>
57
60#include <callback_gal.h>
63#include <geometry/shape_rect.h>
67#include <bezier_curves.h>
68#include <kiface_base.h>
69#include <gr_text.h>
70#include <pgm_base.h>
71
72using namespace KIGFX;
73
74
76{
77 return dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
78}
79
80// Helpers for display options existing in Cvpcb and Pcbnew
81// Note, when running Cvpcb, pcbconfig() returns nullptr and viewer_settings()
82// returns the viewer options existing to Cvpcb and Pcbnew
84{
85 switch( m_frameType )
86 {
89 default:
91
95
99 case FRAME_CVPCB:
102 }
103}
104
105
107{
108 m_backgroundColor = COLOR4D( 0.0, 0.0, 0.0, 1.0 );
109 m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_FILLED;
110 m_netColorMode = NET_COLOR_MODE::RATSNEST;
111 m_ContrastModeDisplay = HIGH_CONTRAST_MODE::NORMAL;
112
113 m_trackOpacity = 1.0;
114 m_viaOpacity = 1.0;
115 m_padOpacity = 1.0;
116 m_zoneOpacity = 1.0;
117 m_imageOpacity = 1.0;
119
121
122 m_PadEditModePad = nullptr;
123
124 SetDashLengthRatio( 12 ); // From ISO 128-2
125 SetGapLengthRatio( 3 ); // From ISO 128-2
126
128
129 update();
130}
131
132
134{
136
137 // Init board layers colors:
138 for( int i = 0; i < PCB_LAYER_ID_COUNT; i++ )
139 {
140 m_layerColors[i] = aSettings->GetColor( i );
141
142 // Guard: if the alpha channel is too small, the layer is not visible.
143 if( m_layerColors[i].a < 0.2 )
144 m_layerColors[i].a = 0.2;
145 }
146
147 // Init specific graphic layers colors:
148 for( int i = GAL_LAYER_ID_START; i < GAL_LAYER_ID_END; i++ )
149 m_layerColors[i] = aSettings->GetColor( i );
150
151 // Colors for layers that aren't theme-able
159
160 // Netnames for copper layers
161 const COLOR4D lightLabel = aSettings->GetColor( NETNAMES_LAYER_ID_START );
162 const COLOR4D darkLabel = lightLabel.Inverted();
163
164 for( PCB_LAYER_ID layer : LSET::AllCuMask().CuStack() )
165 {
166 if( m_layerColors[layer].GetBrightness() > 0.5 )
167 m_layerColors[GetNetnameLayer( layer )] = darkLabel;
168 else
169 m_layerColors[GetNetnameLayer( layer )] = lightLabel;
170 }
171
172 if( PgmOrNull() ) // can be null if used without project (i.e. from python script)
174 else
175 m_hiContrastFactor = 1.0f - 0.8f; // default value
176
177 update();
178}
179
180
182{
183 m_hiContrastEnabled = aOptions.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL;
187
189 m_viaOpacity = aOptions.m_ViaOpacity;
190 m_padOpacity = aOptions.m_PadOpacity;
191 m_zoneOpacity = aOptions.m_ZoneOpacity;
194}
195
196
197COLOR4D PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
198{
199 return GetColor( dynamic_cast<const BOARD_ITEM*>( aItem ), aLayer );
200}
201
202
203COLOR4D PCB_RENDER_SETTINGS::GetColor( const BOARD_ITEM* aItem, int aLayer ) const
204{
205 int netCode = -1;
206 int originalLayer = aLayer;
207
208 // Marker shadows
209 if( aLayer == LAYER_MARKER_SHADOWS )
210 return m_backgroundColor.WithAlpha( 0.6 );
211
212 if( IsHoleLayer( aLayer ) && m_isPrinting )
213 {
214 // Careful that we don't end up with the same colour for the annular ring and the hole
215 // when printing in B&W.
216 const PAD* pad = dynamic_cast<const PAD*>( aItem );
217 const PCB_VIA* via = dynamic_cast<const PCB_VIA*>( aItem );
218 int holeLayer = aLayer;
219 int annularRingLayer = UNDEFINED_LAYER;
220
221 if( pad && pad->GetAttribute() == PAD_ATTRIB::PTH )
222 annularRingLayer = LAYER_PADS_TH;
223 else if( via && via->GetViaType() == VIATYPE::MICROVIA )
224 annularRingLayer = LAYER_VIA_MICROVIA;
225 else if( via && via->GetViaType() == VIATYPE::BLIND_BURIED )
226 annularRingLayer = LAYER_VIA_BBLIND;
227 else if( via && via->GetViaType() == VIATYPE::THROUGH )
228 annularRingLayer = LAYER_VIA_THROUGH;
229
230 if( annularRingLayer != UNDEFINED_LAYER
231 && m_layerColors[ holeLayer ] == m_layerColors[ annularRingLayer ] )
232 {
233 aLayer = LAYER_PCB_BACKGROUND;
234 }
235 }
236
237 // Zones should pull from the copper layer
238 if( aItem && aItem->Type() == PCB_ZONE_T )
239 {
240 if( IsZoneFillLayer( aLayer ) )
241 aLayer = aLayer - LAYER_ZONE_START;
242 }
243
244 // Hole walls should pull from the copper layer
245 if( aLayer == LAYER_PAD_HOLEWALLS )
246 aLayer = LAYER_PADS_TH;
247 else if( aLayer == LAYER_VIA_HOLEWALLS )
248 aLayer = LAYER_VIA_THROUGH;
249
250 // Show via mask layers if appropriate
251 if( aLayer == LAYER_VIA_THROUGH && !m_isPrinting )
252 {
253 if( aItem && aItem->GetBoard() )
254 {
255 LSET visibleLayers = aItem->GetBoard()->GetVisibleLayers()
256 & aItem->GetBoard()->GetEnabledLayers()
257 & aItem->GetLayerSet();
258
259 if( GetActiveLayer() == F_Mask && visibleLayers.test( F_Mask ) )
260 aLayer = F_Mask;
261 else if( GetActiveLayer() == B_Mask && visibleLayers.test( B_Mask ) )
262 aLayer = B_Mask;
263 else if( ( visibleLayers & LSET::AllCuMask() ).none() )
264 {
265 if( visibleLayers.any() )
266 aLayer = visibleLayers.Seq().back();
267 }
268 }
269 }
270
271 // Normal path: get the layer base color
272 COLOR4D color = m_layerColors[aLayer];
273
274 if( !aItem )
275 return m_layerColors[aLayer];
276
277 // Selection disambiguation
278 if( aItem->IsBrightened() )
279 return color.Brightened( m_selectFactor ).WithAlpha( 0.8 );
280
281 // Normal selection
282 if( aItem->IsSelected() )
283 color = m_layerColorsSel[aLayer];
284
285 // Some graphic objects are BOARD_CONNECTED_ITEM, but they are seen here as
286 // actually board connected objects only if on a copper layer
287 const BOARD_CONNECTED_ITEM* conItem =
288 aItem->IsConnected() && aItem->IsOnCopperLayer()
289 ? static_cast<const BOARD_CONNECTED_ITEM*>( aItem )
290 : nullptr;
291
292 // Try to obtain the netcode for the aItem
293 if( conItem )
294 netCode = conItem->GetNetCode();
295
296 bool highlighted = m_highlightEnabled && m_highlightNetcodes.count( netCode );
297 bool selected = aItem->IsSelected();
298
299 // Apply net color overrides
300 if( conItem && m_netColorMode == NET_COLOR_MODE::ALL && IsNetCopperLayer( aLayer ) )
301 {
302 COLOR4D netColor = COLOR4D::UNSPECIFIED;
303
304 auto ii = m_netColors.find( netCode );
305
306 if( ii != m_netColors.end() )
307 netColor = ii->second;
308
309 if( netColor == COLOR4D::UNSPECIFIED )
310 {
311 const NETCLASS* nc = conItem->GetEffectiveNetClass();
312
313 if( nc->HasPcbColor() )
314 netColor = nc->GetPcbColor();
315 }
316
317 if( netColor == COLOR4D::UNSPECIFIED )
318 netColor = color;
319
320 if( selected )
321 {
322 // Selection brightening overrides highlighting
323 netColor.Brighten( m_selectFactor );
324 }
325 else if( m_highlightEnabled )
326 {
327 // Highlight brightens objects on all layers and darkens everything else for contrast
328 if( highlighted )
329 netColor.Brighten( m_highlightFactor );
330 else
331 netColor.Darken( 1.0 - m_highlightFactor );
332 }
333
334 color = netColor;
335 }
336 else if( !selected && m_highlightEnabled )
337 {
338 // Single net highlight mode
339 color = m_highlightNetcodes.count( netCode ) ? m_layerColorsHi[aLayer]
340 : m_layerColorsDark[aLayer];
341 }
342
343 // Apply high-contrast dimming
344 if( m_hiContrastEnabled && m_highContrastLayers.size() && !highlighted && !selected )
345 {
347 bool isActive = m_highContrastLayers.count( aLayer );
348 bool hide = false;
349
350 switch( originalLayer )
351 {
354 case LAYER_PADS_TH:
355 {
356 const PAD* pad = static_cast<const PAD*>( aItem );
357
358 if( pad->IsOnLayer( primary ) && !pad->FlashLayer( primary ) )
359 {
360 isActive = false;
361
362 if( IsCopperLayer( primary ) )
363 hide = true;
364 }
365
367 isActive = false;
368
369 break;
370 }
371
372 case LAYER_VIA_BBLIND:
374 {
375 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
376
377 // Target graphic is active if the via crosses the primary layer
378 if( via->GetLayerSet().test( primary ) == 0 )
379 {
380 isActive = false;
381 hide = true;
382 }
383
384 break;
385 }
386
388 {
389 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
390
391 if( !via->FlashLayer( primary ) )
392 {
393 isActive = false;
394
395 if( IsCopperLayer( primary ) )
396 hide = true;
397 }
398
399 break;
400 }
401
405 // Pad holes are active is any physical layer is active
406 if( LSET::PhysicalLayersMask().test( primary ) == 0 )
407 isActive = false;
408
409 break;
410
411 case LAYER_VIA_HOLES:
413 {
414 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
415
416 if( via->GetViaType() == VIATYPE::THROUGH )
417 {
418 // A through via's hole is active if any physical layer is active
419 if( LSET::PhysicalLayersMask().test( primary ) == 0 )
420 isActive = false;
421 }
422 else
423 {
424 // A blind/buried or micro via's hole is active if it crosses the primary layer
425 if( via->GetLayerSet().test( primary ) == 0 )
426 isActive = false;
427 }
428
429 break;
430 }
431
432 case LAYER_DRC_ERROR:
435 isActive = true;
436 break;
437
438 default:
439 break;
440 }
441
442 if( !isActive )
443 {
444 if( m_ContrastModeDisplay == HIGH_CONTRAST_MODE::HIDDEN
445 || IsNetnameLayer( aLayer )
446 || hide )
447 {
449 }
450 else
451 {
453
454 // Reference images can't have their color mixed so just reduce the opacity a bit
455 // so they show through less
456 if( aItem->Type() == PCB_REFERENCE_IMAGE_T )
458 }
459 }
460 }
461 else if( originalLayer == LAYER_VIA_BBLIND || originalLayer == LAYER_VIA_MICROVIA )
462 {
463 const PCB_VIA* via = static_cast<const PCB_VIA*>( aItem );
464 const BOARD* board = via->GetBoard();
465 LSET visibleLayers = board->GetVisibleLayers() & board->GetEnabledLayers();
466
467 // Target graphic is visible if the via crosses a visible layer
468 if( ( via->GetLayerSet() & visibleLayers ).none() )
470 }
471
472 // Apply per-type opacity overrides
473 if( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_ARC_T )
475 else if( aItem->Type() == PCB_VIA_T )
476 color.a *= m_viaOpacity;
477 else if( aItem->Type() == PCB_PAD_T )
478 color.a *= m_padOpacity;
479 else if( aItem->Type() == PCB_ZONE_T && static_cast<const ZONE*>( aItem )->IsTeardropArea() )
481 else if( aItem->Type() == PCB_ZONE_T )
482 color.a *= m_zoneOpacity;
483 else if( aItem->Type() == PCB_REFERENCE_IMAGE_T )
485 else if( aItem->Type() == PCB_SHAPE_T && static_cast<const PCB_SHAPE*>( aItem )->IsFilled() )
487 else if( aItem->Type() == PCB_SHAPE_T && aItem->IsOnCopperLayer() )
489
490 if( aItem->GetForcedTransparency() > 0.0 )
491 color = color.WithAlpha( color.a * ( 1.0 - aItem->GetForcedTransparency() ) );
492
493 // No special modifiers enabled
494 return color;
495}
496
497
499{
500 return pcbconfig() && pcbconfig()->m_ShowPageLimits;
501}
502
503
505 PAINTER( aGal ),
506 m_frameType( aFrameType ),
507 m_maxError( ARC_HIGH_DEF ),
508 m_holePlatingThickness( 0 ),
509 m_lockedShadowMargin( 0 )
510{
511}
512
513
514int PCB_PAINTER::getLineThickness( int aActualThickness ) const
515{
516 // if items have 0 thickness, draw them with the outline
517 // width, otherwise respect the set value (which, no matter
518 // how small will produce something)
519 if( aActualThickness == 0 )
521
522 return aActualThickness;
523}
524
525
527{
528 return aPad->GetDrillShape();
529}
530
531
533{
534 SHAPE_SEGMENT segm = *aPad->GetEffectiveHoleShape().get();
535 return segm;
536}
537
538
539int PCB_PAINTER::getViaDrillSize( const PCB_VIA* aVia ) const
540{
541 return aVia->GetDrillValue();
542}
543
544
545bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
546{
547 if( !aItem->IsBOARD_ITEM() )
548 return false;
549
550 const BOARD_ITEM* item = static_cast<const BOARD_ITEM*>( aItem );
551
552 if( const BOARD* board = item->GetBoard() )
553 {
554 BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
558
559 if( item->GetParentFootprint() && !board->IsFootprintHolder() )
560 {
561 FOOTPRINT* parentFP = item->GetParentFootprint();
562
563 // Never draw footprint reference images on board
564 if( item->Type() == PCB_REFERENCE_IMAGE_T )
565 {
566 return false;
567 }
568 else if( item->GetLayerSet().count() > 1 )
569 {
570 // For multi-layer objects, exclude only those layers that are private
571 if( IsPcbLayer( aLayer ) && parentFP->GetPrivateLayers().test( aLayer ) )
572 return false;
573 }
574 else if( item->GetLayerSet().count() == 1 )
575 {
576 // For single-layer objects, exclude all layers including ancillary layers
577 // such as holes, netnames, etc.
578 PCB_LAYER_ID singleLayer = item->GetLayerSet().ExtractLayer();
579
580 if( parentFP->GetPrivateLayers().test( singleLayer ) )
581 return false;
582 }
583 }
584 }
585 else
586 {
589 }
590
591 // the "cast" applied in here clarifies which overloaded draw() is called
592 switch( item->Type() )
593 {
594 case PCB_TRACE_T:
595 draw( static_cast<const PCB_TRACK*>( item ), aLayer );
596 break;
597
598 case PCB_ARC_T:
599 draw( static_cast<const PCB_ARC*>( item ), aLayer );
600 break;
601
602 case PCB_VIA_T:
603 draw( static_cast<const PCB_VIA*>( item ), aLayer );
604 break;
605
606 case PCB_PAD_T:
607 draw( static_cast<const PAD*>( item ), aLayer );
608 break;
609
610 case PCB_SHAPE_T:
611 draw( static_cast<const PCB_SHAPE*>( item ), aLayer );
612 break;
613
615 draw( static_cast<const PCB_REFERENCE_IMAGE*>( item ), aLayer );
616 break;
617
618 case PCB_FIELD_T:
619 case PCB_TEXT_T:
620 draw( static_cast<const PCB_TEXT*>( item ), aLayer );
621 break;
622
623 case PCB_TEXTBOX_T:
624 draw( static_cast<const PCB_TEXTBOX*>( item ), aLayer );
625 break;
626
627 case PCB_TABLE_T:
628 draw( static_cast<const PCB_TABLE*>( item ), aLayer );
629 break;
630
631 case PCB_FOOTPRINT_T:
632 draw( static_cast<const FOOTPRINT*>( item ), aLayer );
633 break;
634
635 case PCB_GROUP_T:
636 draw( static_cast<const PCB_GROUP*>( item ), aLayer );
637 break;
638
639 case PCB_ZONE_T:
640 draw( static_cast<const ZONE*>( item ), aLayer );
641 break;
642
644 case PCB_DIM_CENTER_T:
645 case PCB_DIM_RADIAL_T:
647 case PCB_DIM_LEADER_T:
648 draw( static_cast<const PCB_DIMENSION_BASE*>( item ), aLayer );
649 break;
650
651 case PCB_TARGET_T:
652 draw( static_cast<const PCB_TARGET*>( item ) );
653 break;
654
655 case PCB_MARKER_T:
656 draw( static_cast<const PCB_MARKER*>( item ), aLayer );
657 break;
658
659 default:
660 // Painter does not know how to draw the object
661 return false;
662 }
663
664 // Draw bounding boxes after drawing objects so they can be seen.
666 {
667 // Show bounding boxes of painted objects for debugging.
668 BOX2I box = item->GetBoundingBox();
669
670 m_gal->SetIsFill( false );
671 m_gal->SetIsStroke( true );
672
673 if( item->Type() == PCB_FOOTPRINT_T )
674 {
675 m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
676 COLOR4D( MAGENTA ) );
677 }
678 else
679 {
680 m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
681 COLOR4D( 0.4, 0.4, 0.4, 1 ) );
682 }
683
684 m_gal->SetLineWidth( 1 );
685 m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
686
687 if( item->Type() == PCB_FOOTPRINT_T )
688 {
689 m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
690 COLOR4D( CYAN ) );
691
692 const FOOTPRINT* fp = static_cast<const FOOTPRINT*>( item );
693
694 if( fp )
695 {
696 const SHAPE_POLY_SET& convex = fp->GetBoundingHull();
697
698 m_gal->DrawPolyline( convex.COutline( 0 ) );
699 }
700 }
701 }
702
703 return true;
704}
705
706
707void PCB_PAINTER::draw( const PCB_TRACK* aTrack, int aLayer )
708{
709 VECTOR2I start( aTrack->GetStart() );
710 VECTOR2I end( aTrack->GetEnd() );
711 int track_width = aTrack->GetWidth();
712 COLOR4D color = m_pcbSettings.GetColor( aTrack, aLayer );
713
714 if( IsNetnameLayer( aLayer ) )
715 {
716 if( !pcbconfig() || pcbconfig()->m_Display.m_NetNames < 2 )
717 return;
718
719 if( aTrack->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
720 return;
721
722 SHAPE_SEGMENT trackShape( { aTrack->GetStart(), aTrack->GetEnd() }, aTrack->GetWidth() );
723 renderNetNameForSegment( trackShape, color, aTrack->GetDisplayNetname() );
724 return;
725 }
726 else if( IsCopperLayer( aLayer ) || aLayer == LAYER_LOCKED_ITEM_SHADOW )
727 {
728 // Draw a regular track
729 bool outline_mode = pcbconfig()
731 && aLayer != LAYER_LOCKED_ITEM_SHADOW;
734 m_gal->SetIsStroke( outline_mode );
735 m_gal->SetIsFill( not outline_mode );
737
738 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
739 track_width = track_width + m_lockedShadowMargin;
740
741 m_gal->DrawSegment( start, end, track_width );
742 }
743
744 // Clearance lines
745 if( pcbconfig() && pcbconfig()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
747 && aLayer != LAYER_LOCKED_ITEM_SHADOW )
748 {
749 /*
750 * Showing the clearance area is not obvious for optionally-flashed pads and vias, so we
751 * choose to not display clearance lines at all on non-copper active layers. We follow
752 * the same rule for tracks to be consistent (even though they don't have the same issue).
753 */
755 const BOARD* board = aTrack->GetBoard();
756
757 if( IsCopperLayer( activeLayer ) && board->GetVisibleLayers().test( activeLayer ) )
758 {
759 int clearance = aTrack->GetOwnClearance( activeLayer );
760
762 m_gal->SetIsFill( false );
763 m_gal->SetIsStroke( true );
765 m_gal->DrawSegment( start, end, track_width + clearance * 2 );
766 }
767 }
768}
769
770
772 const wxString& aNetName ) const
773{
774 // When drawing netnames, clip the track to the viewport
775 BOX2D viewport;
776 VECTOR2D screenSize = m_gal->GetScreenPixelSize();
777 const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
778
779 viewport.SetOrigin( VECTOR2D( matrix * VECTOR2D( 0, 0 ) ) );
780 viewport.SetEnd( VECTOR2D( matrix * screenSize ) );
781 viewport.Normalize();
782
783 int num_char = aNetName.size();
784
785 // Check if the track is long enough to have a netname displayed
786 int seg_minlength = aSeg.GetWidth() * num_char;
787 SEG::ecoord seg_minlength_sq = (SEG::ecoord)seg_minlength * seg_minlength;
788
789 if( aSeg.GetSeg().SquaredLength() < seg_minlength_sq )
790 return;
791
792 double textSize = aSeg.GetWidth();
793 double penWidth = textSize / 12.0;
794 EDA_ANGLE textOrientation;
795 int num_names = 1;
796
797 VECTOR2I start = aSeg.GetSeg().A;
798 VECTOR2I end = aSeg.GetSeg().B;
799 VECTOR2D segV = end - start;
800
801 if( end.y == start.y ) // horizontal
802 {
803 textOrientation = ANGLE_HORIZONTAL;
804 num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / viewport.GetWidth() ) );
805 }
806 else if( end.x == start.x ) // vertical
807 {
808 textOrientation = ANGLE_VERTICAL;
809 num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / viewport.GetHeight() ) );
810 }
811 else
812 {
813 textOrientation = -EDA_ANGLE( segV );
814 textOrientation.Normalize90();
815
816 double min_size = std::min( viewport.GetWidth(), viewport.GetHeight() );
817 num_names = std::max( num_names, KiROUND( aSeg.GetSeg().Length() / ( M_SQRT2 * min_size ) ) );
818 }
819
820 m_gal->SetIsStroke( true );
821 m_gal->SetIsFill( false );
822 m_gal->SetStrokeColor( aColor );
823 m_gal->SetLineWidth( penWidth );
824 m_gal->SetFontBold( false );
825 m_gal->SetFontItalic( false );
826 m_gal->SetFontUnderlined( false );
827 m_gal->SetTextMirrored( false );
828 m_gal->SetGlyphSize( VECTOR2D( textSize * 0.55, textSize * 0.55 ) );
831
832 int divisions = num_names + 1;
833
834 for( int ii = 1; ii < divisions; ++ii )
835 {
836 VECTOR2I textPosition = start + segV * ( (double) ii / divisions );
837
838 if( viewport.Contains( textPosition ) )
839 m_gal->BitmapText( aNetName, textPosition, textOrientation );
840 }
841}
842
843
844void PCB_PAINTER::draw( const PCB_ARC* aArc, int aLayer )
845{
846 VECTOR2D center( aArc->GetCenter() );
847 int width = aArc->GetWidth();
848 COLOR4D color = m_pcbSettings.GetColor( aArc, aLayer );
849 double radius = aArc->GetRadius();
850 EDA_ANGLE start_angle = aArc->GetArcAngleStart();
851 EDA_ANGLE angle = aArc->GetAngle();
852
853 if( IsNetnameLayer( aLayer ) )
854 {
855 // Ummm, yeah. Anyone fancy implementing text on a path?
856 return;
857 }
858 else if( IsCopperLayer( aLayer ) || aLayer == LAYER_LOCKED_ITEM_SHADOW )
859 {
860 // Draw a regular track
861 bool outline_mode = pcbconfig()
863 && aLayer != LAYER_LOCKED_ITEM_SHADOW;
866 m_gal->SetIsStroke( outline_mode );
867 m_gal->SetIsFill( not outline_mode );
869
870 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
871 width = width + m_lockedShadowMargin;
872
873 m_gal->DrawArcSegment( center, radius, start_angle, angle, width, m_maxError );
874 }
875
876 // Clearance lines
877 if( pcbconfig() && pcbconfig()->m_Display.m_TrackClearance == SHOW_WITH_VIA_ALWAYS
879 && aLayer != LAYER_LOCKED_ITEM_SHADOW )
880 {
881 /*
882 * Showing the clearance area is not obvious for optionally-flashed pads and vias, so we
883 * choose to not display clearance lines at all on non-copper active layers. We follow
884 * the same rule for tracks to be consistent (even though they don't have the same issue).
885 */
887 const BOARD* board = aArc->GetBoard();
888
889 if( IsCopperLayer( activeLayer ) && board->GetVisibleLayers().test( activeLayer ) )
890 {
891 int clearance = aArc->GetOwnClearance( activeLayer );
892
894 m_gal->SetIsFill( false );
895 m_gal->SetIsStroke( true );
897
898 m_gal->DrawArcSegment( center, radius, start_angle, angle, width + clearance * 2,
899 m_maxError );
900 }
901 }
902
903// Debug only: enable this code only to test the TransformArcToPolygon function
904// and display the polygon outline created by it.
905// arcs on F_Cu are approximated with ERROR_INSIDE, others with ERROR_OUTSIDE
906#if 0
907 SHAPE_POLY_SET cornerBuffer;
908 ERROR_LOC errorloc = aLayer == F_Cu ? ERROR_LOC::ERROR_INSIDE : ERROR_LOC::ERROR_OUTSIDE;
909 TransformArcToPolygon( cornerBuffer, aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(), width,
910 m_maxError, errorloc );
912 m_gal->SetIsFill( false );
913 m_gal->SetIsStroke( true );
914 m_gal->SetStrokeColor( COLOR4D( 0, 0, 1.0, 1.0 ) );
915 m_gal->DrawPolygon( cornerBuffer );
916#endif
917
918// Debug only: enable this code only to test the SHAPE_ARC::ConvertToPolyline function
919// and display the polyline created by it.
920#if 0
921 SHAPE_ARC arc( aArc->GetCenter(), aArc->GetStart(), aArc->GetAngle(), aArc->GetWidth() );
924 m_gal->SetIsFill( false );
925 m_gal->SetIsStroke( true );
926 m_gal->SetStrokeColor( COLOR4D( 0.3, 0.2, 0.5, 1.0 ) );
927
928 for( int idx = 1; idx < arcSpine.PointCount(); idx++ )
929 m_gal->DrawSegment( arcSpine.CPoint( idx-1 ), arcSpine.CPoint( idx ), aArc->GetWidth() );
930#endif
931}
932
933
934void PCB_PAINTER::draw( const PCB_VIA* aVia, int aLayer )
935{
936 const BOARD* board = aVia->GetBoard();
937 COLOR4D color = m_pcbSettings.GetColor( aVia, aLayer );
938 VECTOR2D center( aVia->GetStart() );
939
940 if( color == COLOR4D::CLEAR )
941 return;
942
943 // Draw description layer
944 if( IsNetnameLayer( aLayer ) )
945 {
946 VECTOR2D position( center );
947
948 // Is anything that we can display enabled (netname and/or layers ids)?
949 bool showNets = pcbconfig() && pcbconfig()->m_Display.m_NetNames != 0
950 && !aVia->GetNetname().empty();
951 bool showLayers = aVia->GetViaType() != VIATYPE::THROUGH;
952
953 if( !showNets && !showLayers )
954 return;
955
956 double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
957 double size = aVia->GetWidth();
958
959 // Font size limits
960 if( size > maxSize )
961 size = maxSize;
962
963 m_gal->Save();
964 m_gal->Translate( position );
965
966 // Default font settings
970 m_gal->SetFontBold( false );
971 m_gal->SetFontItalic( false );
972 m_gal->SetFontUnderlined( false );
973 m_gal->SetTextMirrored( false );
974 m_gal->SetStrokeColor( m_pcbSettings.GetColor( nullptr, aLayer ) );
975 m_gal->SetIsStroke( true );
976 m_gal->SetIsFill( false );
977
978 // Set the text position via position. if only one text, it is on the via position
979 // For 2 lines, the netname is slightly below the center, and the layer IDs above
980 // the netname
981 VECTOR2D textpos( 0.0, 0.0 );
982
983 wxString netname = aVia->GetDisplayNetname();
984
985 int topLayer = aVia->TopLayer() + 1;
986 int bottomLayer = std::min( aVia->BottomLayer() + 1, board->GetCopperLayerCount() );
987
988 wxString layerIds;
989#if wxUSE_UNICODE_WCHAR
990 layerIds << std::to_wstring( topLayer ) << L'-' << std::to_wstring( bottomLayer );
991#else
992 layerIds << std::to_string( topLayer ) << '-' << std::to_string( bottomLayer );
993#endif
994
995 // a good size is set room for at least 6 chars, to be able to print 2 lines of text,
996 // or at least 3 chars for only the netname
997 // (The layerIds string has 5 chars max)
998 int minCharCnt = showLayers ? 6 : 3;
999
1000 // approximate the size of netname and layerIds text:
1001 double tsize = 1.5 * size / std::max( PrintableCharCount( netname ), minCharCnt );
1002 tsize = std::min( tsize, size );
1003
1004 // Use a smaller text size to handle interline, pen size..
1005 tsize *= 0.75;
1006 VECTOR2D namesize( tsize, tsize );
1007
1008 // For 2 lines, adjust the text pos (move it a small amount to the bottom)
1009 if( showLayers )
1010 textpos.y += tsize/5;
1011
1012 m_gal->SetGlyphSize( namesize );
1013 m_gal->SetLineWidth( namesize.x / 10.0 );
1014
1015 if( showNets )
1016 m_gal->BitmapText( netname, textpos, ANGLE_HORIZONTAL );
1017
1018 if( showLayers )
1019 {
1020 if( showNets )
1021 textpos.y -= tsize * 1.3;
1022
1023 m_gal->BitmapText( layerIds, textpos, ANGLE_HORIZONTAL );
1024 }
1025
1026 m_gal->Restore();
1027
1028 return;
1029 }
1030
1031 bool outline_mode = pcbconfig() && !pcbconfig()->m_Display.m_DisplayViaFill;
1032
1035 m_gal->SetIsStroke( true );
1036 m_gal->SetIsFill( false );
1037
1038 if( outline_mode )
1040
1041 if( aLayer == LAYER_VIA_HOLEWALLS )
1042 {
1043 double radius = ( getViaDrillSize( aVia ) / 2.0 ) + m_holePlatingThickness;
1044
1045 if( !outline_mode )
1046 {
1048 radius -= m_holePlatingThickness / 2.0;
1049 }
1050
1051 m_gal->DrawCircle( center, radius );
1052 }
1053 else if( aLayer == LAYER_VIA_HOLES )
1054 {
1055 m_gal->SetIsStroke( false );
1056 m_gal->SetIsFill( true );
1057 m_gal->DrawCircle( center, getViaDrillSize( aVia ) / 2.0 );
1058 }
1059 else if( ( aLayer == F_Mask && aVia->IsOnLayer( F_Mask ) )
1060 || ( aLayer == B_Mask && aVia->IsOnLayer( B_Mask ) ) )
1061 {
1062 int margin = board->GetDesignSettings().m_SolderMaskExpansion;
1063
1064 m_gal->SetIsFill( true );
1065 m_gal->SetIsStroke( false );
1066
1067 m_gal->SetLineWidth( margin );
1068 m_gal->DrawCircle( center, aVia->GetWidth() / 2.0 + margin );
1069 }
1070 else if( aLayer == LAYER_VIA_THROUGH || m_pcbSettings.IsPrinting() )
1071 {
1072 int annular_width = ( aVia->GetWidth() - getViaDrillSize( aVia ) ) / 2.0;
1073 double radius = aVia->GetWidth() / 2.0;
1074 bool draw = false;
1075
1077 {
1079 }
1080 else if( aVia->FlashLayer( board->GetVisibleLayers() & board->GetEnabledLayers() ) )
1081 {
1082 draw = true;
1083 }
1084 else if( aVia->IsSelected() )
1085 {
1086 draw = true;
1087 outline_mode = true;
1089 }
1090
1091 if( !outline_mode )
1092 {
1093 m_gal->SetLineWidth( annular_width );
1094 radius -= annular_width / 2.0;
1095 }
1096
1097 if( draw )
1098 m_gal->DrawCircle( center, radius );
1099 }
1100 else if( aLayer == LAYER_VIA_BBLIND || aLayer == LAYER_VIA_MICROVIA )
1101 {
1102 int annular_width = ( aVia->GetWidth() - getViaDrillSize( aVia ) ) / 2.0;
1103 double radius = aVia->GetWidth() / 2.0;
1104
1105 // Outer circles of blind/buried and micro-vias are drawn in a special way to indicate the
1106 // top and bottom layers
1107 PCB_LAYER_ID layerTop, layerBottom;
1108 aVia->LayerPair( &layerTop, &layerBottom );
1109
1110 if( !outline_mode )
1111 {
1112 m_gal->SetIsStroke( false );
1113 m_gal->SetIsFill( true );
1114 }
1115
1116 m_gal->SetStrokeColor( m_pcbSettings.GetColor( aVia, layerTop ) );
1117 m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerTop ) );
1118 m_gal->DrawArc( center, radius, EDA_ANGLE( 240, DEGREES_T ), EDA_ANGLE( 60, DEGREES_T ) );
1119
1120 m_gal->SetStrokeColor( m_pcbSettings.GetColor( aVia, layerBottom ) );
1121 m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerBottom ) );
1122 m_gal->DrawArc( center, radius, EDA_ANGLE( 60, DEGREES_T ), EDA_ANGLE( 60, DEGREES_T ) );
1123
1126 m_gal->SetIsStroke( true );
1127 m_gal->SetIsFill( false );
1128
1129 if( !outline_mode )
1130 {
1131 m_gal->SetLineWidth( annular_width );
1132 radius -= annular_width / 2.0;
1133 }
1134
1135 m_gal->DrawCircle( center, radius );
1136 }
1137 else if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // draw a ring around the via
1138 {
1140
1141 m_gal->DrawCircle( center, ( aVia->GetWidth() + m_lockedShadowMargin ) / 2.0 );
1142 }
1143
1144 // Clearance lines
1146 && aLayer != LAYER_VIA_HOLES
1148 && aLayer != LAYER_LOCKED_ITEM_SHADOW )
1149 {
1150 /*
1151 * Showing the clearance area is not obvious as the clearance extends from the via's pad
1152 * on flashed copper layers and from the via's hole on non-flashed copper layers. Because
1153 * of this, we choose to not display clearance lines at all on non-copper active layers as
1154 * it's not clear which we'd be displaying.
1155 */
1157
1158 if( IsCopperLayer( activeLayer ) && board->GetVisibleLayers().test( activeLayer ) )
1159 {
1160 double radius;
1161
1162 if( aVia->FlashLayer( activeLayer ) )
1163 radius = aVia->GetWidth() / 2.0;
1164 else
1165 radius = getViaDrillSize( aVia ) / 2.0 + m_holePlatingThickness;
1166
1168 m_gal->SetIsFill( false );
1169 m_gal->SetIsStroke( true );
1171 m_gal->DrawCircle( center, radius + aVia->GetOwnClearance( activeLayer ) );
1172 }
1173 }
1174}
1175
1176
1177void PCB_PAINTER::draw( const PAD* aPad, int aLayer )
1178{
1179 const BOARD* board = aPad->GetBoard();
1180 COLOR4D color = m_pcbSettings.GetColor( aPad, aLayer );
1181
1182 if( IsNetnameLayer( aLayer ) )
1183 {
1184 PCBNEW_SETTINGS::DISPLAY_OPTIONS* displayOpts = pcbconfig() ? &pcbconfig()->m_Display : nullptr;
1185 wxString netname;
1186 wxString padNumber;
1187
1188 if( viewer_settings()->m_ViewersDisplay.m_DisplayPadNumbers )
1189 {
1190 padNumber = UnescapeString( aPad->GetNumber() );
1191
1192 if( dynamic_cast<CVPCB_SETTINGS*>( viewer_settings() ) )
1193 netname = aPad->GetPinFunction();
1194 }
1195
1196 if( displayOpts && !dynamic_cast<CVPCB_SETTINGS*>( viewer_settings() ) )
1197 {
1198 if( displayOpts->m_NetNames == 1 || displayOpts->m_NetNames == 3 )
1199 netname = aPad->GetDisplayNetname();
1200
1201 if( aPad->IsNoConnectPad() )
1202 netname = wxT( "x" );
1203 else if( aPad->IsFreePad() )
1204 netname = wxT( "*" );
1205 }
1206
1207 if( netname.IsEmpty() && padNumber.IsEmpty() )
1208 return;
1209
1210 BOX2I padBBox = aPad->GetBoundingBox();
1211 VECTOR2D position = padBBox.Centre();
1212 VECTOR2D padsize = VECTOR2D( padBBox.GetSize() );
1213
1214 if( aPad->IsEntered() )
1215 {
1216 FOOTPRINT* fp = aPad->GetParentFootprint();
1217
1218 // Find the number box
1219 for( const BOARD_ITEM* aItem : fp->GraphicalItems() )
1220 {
1221 if( aItem->Type() == PCB_SHAPE_T )
1222 {
1223 const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aItem );
1224
1225 if( shape->IsProxyItem() && shape->GetShape() == SHAPE_T::RECTANGLE )
1226 {
1227 position = shape->GetCenter();
1228 padsize = shape->GetBotRight() - shape->GetTopLeft();
1229
1230 // We normally draw a bit outside the pad, but this will be somewhat
1231 // unexpected when the user has drawn a box.
1232 padsize *= 0.9;
1233
1234 break;
1235 }
1236 }
1237 }
1238 }
1239 else if( aPad->GetShape() == PAD_SHAPE::CUSTOM )
1240 {
1241 // See if we have a number box
1242 for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives() )
1243 {
1244 if( primitive->IsProxyItem() && primitive->GetShape() == SHAPE_T::RECTANGLE )
1245 {
1246 position = primitive->GetCenter();
1247 RotatePoint( position, aPad->GetOrientation() );
1248 position += aPad->ShapePos();
1249
1250 padsize.x = abs( primitive->GetBotRight().x - primitive->GetTopLeft().x );
1251 padsize.y = abs( primitive->GetBotRight().y - primitive->GetTopLeft().y );
1252
1253 // We normally draw a bit outside the pad, but this will be somewhat
1254 // unexpected when the user has drawn a box.
1255 padsize *= 0.9;
1256
1257 break;
1258 }
1259 }
1260 }
1261
1262 if( aPad->GetShape() != PAD_SHAPE::CUSTOM )
1263 {
1264 // Don't allow a 45° rotation to bloat a pad's bounding box unnecessarily
1265 double limit = std::min( aPad->GetSize().x, aPad->GetSize().y ) * 1.1;
1266
1267 if( padsize.x > limit && padsize.y > limit )
1268 {
1269 padsize.x = limit;
1270 padsize.y = limit;
1271 }
1272 }
1273
1274 double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
1275 double size = padsize.y;
1276
1277 m_gal->Save();
1278 m_gal->Translate( position );
1279
1280 // Keep the size ratio for the font, but make it smaller
1281 if( padsize.x < ( padsize.y * 0.95 ) )
1282 {
1284 size = padsize.x;
1285 std::swap( padsize.x, padsize.y );
1286 }
1287
1288 // Font size limits
1289 if( size > maxSize )
1290 size = maxSize;
1291
1292 // Default font settings
1296 m_gal->SetFontBold( false );
1297 m_gal->SetFontItalic( false );
1298 m_gal->SetFontUnderlined( false );
1299 m_gal->SetTextMirrored( false );
1300 m_gal->SetStrokeColor( m_pcbSettings.GetColor( aPad, aLayer ) );
1301 m_gal->SetIsStroke( true );
1302 m_gal->SetIsFill( false );
1303
1304 // We have already translated the GAL to be centered at the center of the pad's
1305 // bounding box
1306 VECTOR2I textpos( 0, 0 );
1307
1308 // Divide the space, to display both pad numbers and netnames and set the Y text
1309 // offset position to display 2 lines
1310 int Y_offset_numpad = 0;
1311 int Y_offset_netname = 0;
1312
1313 if( !netname.IsEmpty() && !padNumber.IsEmpty() )
1314 {
1315 // The magic numbers are defined experimentally for a better look.
1316 size = size / 2.5;
1317 Y_offset_netname = size / 1.4; // netname size is usually smaller than num pad
1318 // so the offset can be smaller
1319 Y_offset_numpad = size / 1.7;
1320 }
1321
1322 // We are using different fonts to display names, depending on the graphic
1323 // engine (OpenGL or Cairo).
1324 // Xscale_for_stroked_font adjust the text X size for cairo (stroke fonts) engine
1325 const double Xscale_for_stroked_font = 0.9;
1326
1327 if( !netname.IsEmpty() )
1328 {
1329 // approximate the size of net name text:
1330 // We use a size for at least 5 chars, to give a good look even for short names
1331 // (like VCC, GND...)
1332 double tsize = 1.5 * padsize.x / std::max( PrintableCharCount( netname )+1, 5 );
1333 tsize = std::min( tsize, size );
1334
1335 // Use a smaller text size to handle interline, pen size...
1336 tsize *= 0.85;
1337
1338 // Round and oval pads have less room to display the net name than other
1339 // (i.e RECT) shapes, so reduce the text size for these shapes
1340 if( aPad->GetShape() == PAD_SHAPE::CIRCLE || aPad->GetShape() == PAD_SHAPE::OVAL )
1341 tsize *= 0.9;
1342
1343 VECTOR2D namesize( tsize*Xscale_for_stroked_font, tsize );
1344 textpos.y = std::min( tsize * 1.4, double( Y_offset_netname ) );
1345
1346 m_gal->SetGlyphSize( namesize );
1347 m_gal->SetLineWidth( namesize.x / 6.0 );
1348 m_gal->SetFontBold( true );
1349 m_gal->BitmapText( netname, textpos, ANGLE_HORIZONTAL );
1350 }
1351
1352 if( !padNumber.IsEmpty() )
1353 {
1354 // approximate the size of the pad number text:
1355 // We use a size for at least 3 chars, to give a good look even for short numbers
1356 double tsize = 1.5 * padsize.x / std::max( PrintableCharCount( padNumber ), 3 );
1357 tsize = std::min( tsize, size );
1358
1359 // Use a smaller text size to handle interline, pen size...
1360 tsize *= 0.85;
1361 tsize = std::min( tsize, size );
1362 VECTOR2D numsize( tsize*Xscale_for_stroked_font, tsize );
1363 textpos.y = -Y_offset_numpad;
1364
1365 m_gal->SetGlyphSize( numsize );
1366 m_gal->SetLineWidth( numsize.x / 6.0 );
1367 m_gal->SetFontBold( true );
1368 m_gal->BitmapText( padNumber, textpos, ANGLE_HORIZONTAL );
1369 }
1370
1371 m_gal->Restore();
1372
1373 return;
1374 }
1375 else if( aLayer == LAYER_PAD_HOLEWALLS )
1376 {
1377 m_gal->SetIsFill( false );
1378 m_gal->SetIsStroke( true );
1381
1382 std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
1383 int holeSize = slot->GetWidth() + m_holePlatingThickness;
1384
1385 if( slot->GetSeg().A == slot->GetSeg().B ) // Circular hole
1386 m_gal->DrawCircle( slot->GetSeg().A, KiROUND( holeSize / 2.0 ) );
1387 else
1388 m_gal->DrawSegment( slot->GetSeg().A, slot->GetSeg().B, holeSize );
1389
1390 return;
1391 }
1392
1393 bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayPadFill;
1394
1396 outline_mode = true;
1397
1398 if( outline_mode )
1399 {
1400 // Outline mode
1401 m_gal->SetIsFill( false );
1402 m_gal->SetIsStroke( true );
1405 }
1406 else
1407 {
1408 // Filled mode
1409 m_gal->SetIsFill( true );
1410 m_gal->SetIsStroke( false );
1412 }
1413
1414 bool drawShape = false;
1415
1416 if( aLayer == LAYER_PAD_PLATEDHOLES || aLayer == LAYER_NON_PLATEDHOLES )
1417 {
1418 SHAPE_SEGMENT slot = getPadHoleShape( aPad );
1419
1420 if( slot.GetSeg().A == slot.GetSeg().B ) // Circular hole
1421 m_gal->DrawCircle( slot.GetSeg().A, slot.GetWidth() / 2.0 );
1422 else
1423 m_gal->DrawSegment( slot.GetSeg().A, slot.GetSeg().B, slot.GetWidth() );
1424 }
1425 else if( m_pcbSettings.IsPrinting() )
1426 {
1427 drawShape = aPad->FlashLayer( m_pcbSettings.GetPrintLayers() );
1428 }
1429 else if( aPad->FlashLayer( board->GetVisibleLayers() & board->GetEnabledLayers() ) )
1430 {
1431 drawShape = true;
1432 }
1433 else if( aPad->IsSelected() )
1434 {
1435 drawShape = true;
1436 outline_mode = true;
1437 }
1438
1439 if( outline_mode )
1440 {
1441 // Outline mode
1442 m_gal->SetIsFill( false );
1443 m_gal->SetIsStroke( true );
1446 }
1447
1448 if( drawShape )
1449 {
1450 VECTOR2I pad_size = aPad->GetSize();
1451 VECTOR2I margin;
1452
1453 switch( aLayer )
1454 {
1455 case F_Mask:
1456 case B_Mask:
1457 margin.x = margin.y = aPad->GetSolderMaskExpansion();
1458 break;
1459
1460 case F_Paste:
1461 case B_Paste:
1462 margin = aPad->GetSolderPasteMargin();
1463 break;
1464
1465 default:
1466 margin.x = margin.y = 0;
1467 break;
1468 }
1469
1470 std::unique_ptr<PAD> dummyPad;
1471 std::shared_ptr<SHAPE_COMPOUND> shapes;
1472
1473 // Drawing components of compound shapes in outline mode produces a mess.
1474 bool simpleShapes = !outline_mode;
1475
1476 if( simpleShapes )
1477 {
1478 if( ( margin.x != margin.y && aPad->GetShape() != PAD_SHAPE::CUSTOM )
1479 || ( aPad->GetShape() == PAD_SHAPE::ROUNDRECT && ( margin.x < 0 || margin.y < 0 ) ) )
1480 {
1481 // Our algorithms below (polygon inflation in particular) can't handle differential
1482 // inflation along separate axes. So for those cases we build a dummy pad instead,
1483 // and inflate it.
1484
1485 // Margin is added to both sides. If the total margin is larger than the pad
1486 // then don't display this layer
1487 if( pad_size.x + 2 * margin.x <= 0 || pad_size.y + 2 * margin.y <= 0 )
1488 return;
1489
1490 dummyPad.reset( static_cast<PAD*>( aPad->Duplicate() ) );
1491
1492 if( dummyPad->GetParentGroup() )
1493 dummyPad->GetParentGroup()->RemoveItem( dummyPad.get() );
1494
1495 int initial_radius = dummyPad->GetRoundRectCornerRadius();
1496
1497 dummyPad->SetSize( pad_size + margin + margin );
1498
1499 if( dummyPad->GetShape() == PAD_SHAPE::ROUNDRECT )
1500 {
1501 // To keep the right margin around the corners, we need to modify the corner radius.
1502 // We must have only one radius correction, so use the smallest absolute margin.
1503 int radius_margin = std::max( margin.x, margin.y ); // radius_margin is < 0
1504 dummyPad->SetRoundRectCornerRadius( std::max( initial_radius + radius_margin, 0 ) );
1505 }
1506
1507 shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>( dummyPad->GetEffectiveShape() );
1508 margin.x = margin.y = 0;
1509 }
1510 else
1511 {
1512 shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape() );
1513 }
1514
1515 if( aPad->GetShape() == PAD_SHAPE::CUSTOM && ( margin.x || margin.y ) )
1516 {
1517 // We can't draw as shapes because we don't know which edges are internal and which
1518 // are external (so we don't know when to apply the margin and when not to).
1519 simpleShapes = false;
1520 }
1521
1522 for( const SHAPE* shape : shapes->Shapes() )
1523 {
1524 if( !simpleShapes )
1525 break;
1526
1527 switch( shape->Type() )
1528 {
1529 case SH_SEGMENT:
1530 case SH_CIRCLE:
1531 case SH_RECT:
1532 case SH_SIMPLE:
1533 // OK so far
1534 break;
1535
1536 default:
1537 // Not OK
1538 simpleShapes = false;
1539 break;
1540 }
1541 }
1542 }
1543
1544 if( simpleShapes )
1545 {
1546 for( const SHAPE* shape : shapes->Shapes() )
1547 {
1548 switch( shape->Type() )
1549 {
1550 case SH_SEGMENT:
1551 {
1552 const SHAPE_SEGMENT* seg = (const SHAPE_SEGMENT*) shape;
1553 int effectiveWidth = seg->GetWidth() + 2 * margin.x;
1554
1555 if( effectiveWidth > 0 )
1556 m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B, effectiveWidth );
1557
1558 break;
1559 }
1560
1561 case SH_CIRCLE:
1562 {
1563 const SHAPE_CIRCLE* circle = (const SHAPE_CIRCLE*) shape;
1564 int effectiveRadius = circle->GetRadius() + margin.x;
1565
1566 if( effectiveRadius > 0 )
1567 m_gal->DrawCircle( circle->GetCenter(), effectiveRadius );
1568
1569 break;
1570 }
1571
1572 case SH_RECT:
1573 {
1574 const SHAPE_RECT* r = (const SHAPE_RECT*) shape;
1575 VECTOR2I pos = r->GetPosition();
1576 VECTOR2I effectiveMargin = margin;
1577
1578 if( effectiveMargin.x < 0 )
1579 {
1580 // A negative margin just produces a smaller rect.
1581 VECTOR2I effectiveSize = r->GetSize() + effectiveMargin;
1582
1583 if( effectiveSize.x > 0 && effectiveSize.y > 0 )
1584 m_gal->DrawRectangle( pos - effectiveMargin, pos + effectiveSize );
1585 }
1586 else if( effectiveMargin.x > 0 )
1587 {
1588 // A positive margin produces a larger rect, but with rounded corners
1589 m_gal->DrawRectangle( r->GetPosition(), r->GetPosition() + r->GetSize() );
1590
1591 // Use segments to produce the margin with rounded corners
1592 m_gal->DrawSegment( pos,
1593 pos + VECTOR2I( r->GetWidth(), 0 ),
1594 effectiveMargin.x * 2 );
1595 m_gal->DrawSegment( pos + VECTOR2I( r->GetWidth(), 0 ),
1596 pos + r->GetSize(),
1597 effectiveMargin.x * 2 );
1598 m_gal->DrawSegment( pos + r->GetSize(),
1599 pos + VECTOR2I( 0, r->GetHeight() ),
1600 effectiveMargin.x * 2 );
1601 m_gal->DrawSegment( pos + VECTOR2I( 0, r->GetHeight() ),
1602 pos,
1603 effectiveMargin.x * 2 );
1604 }
1605 else
1606 {
1607 m_gal->DrawRectangle( r->GetPosition(), r->GetPosition() + r->GetSize() );
1608 }
1609
1610 break;
1611 }
1612
1613 case SH_SIMPLE:
1614 {
1615 const SHAPE_SIMPLE* poly = static_cast<const SHAPE_SIMPLE*>( shape );
1616
1617 if( poly->PointCount() < 2 ) // Careful of empty pads
1618 break;
1619
1620 if( margin.x < 0 ) // The poly shape must be deflated
1621 {
1622 SHAPE_POLY_SET outline;
1623 outline.NewOutline();
1624
1625 for( int ii = 0; ii < poly->PointCount(); ++ii )
1626 outline.Append( poly->CPoint( ii ) );
1627
1628 outline.Deflate( -margin.x, CORNER_STRATEGY::CHAMFER_ALL_CORNERS,
1629 m_maxError );
1630
1631 m_gal->DrawPolygon( outline );
1632 }
1633 else
1634 {
1635 m_gal->DrawPolygon( poly->Vertices() );
1636 }
1637
1638 // Now add on a rounded margin (using segments) if the margin > 0
1639 if( margin.x > 0 )
1640 {
1641 for( size_t ii = 0; ii < poly->GetSegmentCount(); ++ii )
1642 {
1643 SEG seg = poly->GetSegment( ii );
1644 m_gal->DrawSegment( seg.A, seg.B, margin.x * 2 );
1645 }
1646 }
1647
1648 break;
1649 }
1650
1651 default:
1652 // Better not get here; we already pre-flighted the shapes...
1653 break;
1654 }
1655 }
1656 }
1657 else
1658 {
1659 // This is expensive. Avoid if possible.
1660 SHAPE_POLY_SET polySet;
1661 aPad->TransformShapeToPolygon( polySet, ToLAYER_ID( aLayer ), margin.x, m_maxError,
1662 ERROR_INSIDE );
1663 m_gal->DrawPolygon( polySet );
1664 }
1665 }
1666
1668 && ( aLayer == LAYER_PADS_SMD_FR || aLayer == LAYER_PADS_SMD_BK || aLayer == LAYER_PADS_TH )
1670 {
1671 /*
1672 * Showing the clearance area is not obvious as the clearance extends from the pad on
1673 * flashed copper layers and from the hole on non-flashed copper layers. Because of this,
1674 * we choose to not display clearance lines at all on non-copper active layers as it's
1675 * not clear which we'd be displaying.
1676 */
1678
1679 if( IsCopperLayer( activeLayer ) && board->GetVisibleLayers().test( activeLayer ) )
1680 {
1681 if( aPad->GetAttribute() == PAD_ATTRIB::NPTH )
1683
1685 m_gal->SetIsStroke( true );
1686 m_gal->SetIsFill( false );
1688
1689 int clearance = aPad->GetOwnClearance( activeLayer );
1690
1691 if( aPad->FlashLayer( activeLayer ) && clearance > 0 )
1692 {
1693 auto shape = std::dynamic_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape() );
1694
1695 if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_SEGMENT )
1696 {
1697 const SHAPE_SEGMENT* seg = (SHAPE_SEGMENT*) shape->Shapes()[0];
1698 m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B,
1699 seg->GetWidth() + 2 * clearance );
1700 }
1701 else if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_CIRCLE )
1702 {
1703 const SHAPE_CIRCLE* circle = (SHAPE_CIRCLE*) shape->Shapes()[0];
1704 m_gal->DrawCircle( circle->GetCenter(), circle->GetRadius() + clearance );
1705 }
1706 else
1707 {
1708 SHAPE_POLY_SET polySet;
1709
1710 // Use ERROR_INSIDE because it avoids Clipper and is therefore much faster.
1711 aPad->TransformShapeToPolygon( polySet, activeLayer, clearance, m_maxError,
1712 ERROR_INSIDE );
1713
1714 if( polySet.Outline( 0 ).PointCount() > 2 ) // Careful of empty pads
1715 m_gal->DrawPolygon( polySet );
1716 }
1717 }
1718 else if( aPad->GetEffectiveHoleShape() && clearance > 0 )
1719 {
1720 std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
1721 m_gal->DrawSegment( slot->GetSeg().A, slot->GetSeg().B,
1722 slot->GetWidth() + 2 * clearance );
1723 }
1724 }
1725 }
1726}
1727
1728
1729void PCB_PAINTER::draw( const PCB_SHAPE* aShape, int aLayer )
1730{
1731 COLOR4D color = m_pcbSettings.GetColor( aShape, aLayer );
1733 int thickness = getLineThickness( aShape->GetWidth() );
1734 LINE_STYLE lineStyle = aShape->GetStroke().GetLineStyle();
1735
1736 if( IsNetnameLayer( aLayer ) )
1737 {
1738 // Net names are shown only in board editor:
1739 if( m_frameType != FRAME_T::FRAME_PCB_EDITOR )
1740 return;
1741
1742 if( !pcbconfig() || pcbconfig()->m_Display.m_NetNames < 2 )
1743 return;
1744
1745 if( aShape->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
1746 return;
1747
1748 wxString netname = aShape->GetDisplayNetname();
1749
1750 if( netname.IsEmpty() )
1751 return;
1752
1753 if( aShape->GetShape() == SHAPE_T::SEGMENT )
1754 {
1755 SHAPE_SEGMENT seg( { aShape->GetStart(), aShape->GetEnd() }, aShape->GetWidth() );
1756 renderNetNameForSegment( seg, color, netname );
1757 return;
1758 }
1759
1760 // TODO: Maybe use some of the pad code?
1761
1762 return;
1763 }
1764
1765 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
1766 {
1767 color = m_pcbSettings.GetColor( aShape, aLayer );
1768 thickness = thickness + m_lockedShadowMargin;
1769 }
1770
1771 if( outline_mode )
1772 {
1773 m_gal->SetIsFill( false );
1774 m_gal->SetIsStroke( true );
1776 }
1777
1780
1781 // Note: on LAYER_LOCKED_ITEM_SHADOW always draw shadow shapes as continuous lines
1782 // otherwise the look is very strange and ugly
1783 if( lineStyle <= LINE_STYLE::FIRST_TYPE || aLayer == LAYER_LOCKED_ITEM_SHADOW )
1784 {
1785 switch( aShape->GetShape() )
1786 {
1787 case SHAPE_T::SEGMENT:
1788 if( aShape->IsProxyItem() )
1789 {
1790 std::vector<VECTOR2I> pts;
1791 VECTOR2I offset = ( aShape->GetEnd() - aShape->GetStart() ).Perpendicular();
1792 offset = offset.Resize( thickness / 2 );
1793
1794 pts.push_back( aShape->GetStart() + offset );
1795 pts.push_back( aShape->GetStart() - offset );
1796 pts.push_back( aShape->GetEnd() - offset );
1797 pts.push_back( aShape->GetEnd() + offset );
1798
1800 m_gal->DrawLine( pts[0], pts[1] );
1801 m_gal->DrawLine( pts[1], pts[2] );
1802 m_gal->DrawLine( pts[2], pts[3] );
1803 m_gal->DrawLine( pts[3], pts[0] );
1804 m_gal->DrawLine( ( pts[0] + pts[1] ) / 2, ( pts[1] + pts[2] ) / 2 );
1805 m_gal->DrawLine( ( pts[1] + pts[2] ) / 2, ( pts[2] + pts[3] ) / 2 );
1806 m_gal->DrawLine( ( pts[2] + pts[3] ) / 2, ( pts[3] + pts[0] ) / 2 );
1807 m_gal->DrawLine( ( pts[3] + pts[0] ) / 2, ( pts[0] + pts[1] ) / 2 );
1808 }
1809 else if( outline_mode )
1810 {
1811 m_gal->DrawSegment( aShape->GetStart(), aShape->GetEnd(), thickness );
1812 }
1813 else
1814 {
1815 m_gal->SetIsFill( true );
1816 m_gal->SetIsStroke( false );
1817
1818 m_gal->DrawSegment( aShape->GetStart(), aShape->GetEnd(), thickness );
1819 }
1820
1821 break;
1822
1823 case SHAPE_T::RECTANGLE:
1824 {
1825 std::vector<VECTOR2I> pts = aShape->GetRectCorners();
1826
1827 if( aShape->IsProxyItem() )
1828 {
1830 m_gal->DrawLine( pts[0], pts[1] );
1831 m_gal->DrawLine( pts[1], pts[2] );
1832 m_gal->DrawLine( pts[2], pts[3] );
1833 m_gal->DrawLine( pts[3], pts[0] );
1834 m_gal->DrawLine( pts[0], pts[2] );
1835 m_gal->DrawLine( pts[1], pts[3] );
1836 }
1837 else if( outline_mode )
1838 {
1839 m_gal->DrawSegment( pts[0], pts[1], thickness );
1840 m_gal->DrawSegment( pts[1], pts[2], thickness );
1841 m_gal->DrawSegment( pts[2], pts[3], thickness );
1842 m_gal->DrawSegment( pts[3], pts[0], thickness );
1843 }
1844 else
1845 {
1846 m_gal->SetIsFill( true );
1847 m_gal->SetIsStroke( false );
1848
1849 if( thickness > 0 )
1850 {
1851 m_gal->DrawSegment( pts[0], pts[1], thickness );
1852 m_gal->DrawSegment( pts[1], pts[2], thickness );
1853 m_gal->DrawSegment( pts[2], pts[3], thickness );
1854 m_gal->DrawSegment( pts[3], pts[0], thickness );
1855 }
1856
1857 if( aShape->IsFilled() )
1858 {
1859 SHAPE_POLY_SET poly;
1860 poly.NewOutline();
1861
1862 for( const VECTOR2I& pt : pts )
1863 poly.Append( pt );
1864
1865 m_gal->DrawPolygon( poly );
1866 }
1867 }
1868
1869 break;
1870 }
1871
1872 case SHAPE_T::ARC:
1873 {
1874 EDA_ANGLE startAngle;
1875 EDA_ANGLE endAngle;
1876 aShape->CalcArcAngles( startAngle, endAngle );
1877
1878 if( outline_mode )
1879 {
1880 m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(), startAngle,
1881 endAngle - startAngle, thickness, m_maxError );
1882 }
1883 else
1884 {
1885 m_gal->SetIsFill( true );
1886 m_gal->SetIsStroke( false );
1887
1888 m_gal->DrawArcSegment( aShape->GetCenter(), aShape->GetRadius(), startAngle,
1889 endAngle - startAngle, thickness, m_maxError );
1890 }
1891 break;
1892 }
1893
1894 case SHAPE_T::CIRCLE:
1895 if( outline_mode )
1896 {
1897 m_gal->DrawCircle( aShape->GetStart(), aShape->GetRadius() - thickness / 2 );
1898 m_gal->DrawCircle( aShape->GetStart(), aShape->GetRadius() + thickness / 2 );
1899 }
1900 else
1901 {
1902 m_gal->SetIsFill( aShape->IsFilled() );
1903 m_gal->SetIsStroke( thickness > 0 );
1904 m_gal->SetLineWidth( thickness );
1905
1906 m_gal->DrawCircle( aShape->GetStart(), aShape->GetRadius() );
1907 }
1908 break;
1909
1910 case SHAPE_T::POLY:
1911 {
1912 SHAPE_POLY_SET& shape = const_cast<PCB_SHAPE*>( aShape )->GetPolyShape();
1913
1914 if( shape.OutlineCount() == 0 )
1915 break;
1916
1917 if( outline_mode )
1918 {
1919 for( int ii = 0; ii < shape.OutlineCount(); ++ii )
1920 m_gal->DrawSegmentChain( shape.Outline( ii ), thickness );
1921 }
1922 else
1923 {
1924 m_gal->SetIsFill( true );
1925 m_gal->SetIsStroke( false );
1926
1927 if( thickness > 0 )
1928 {
1929 for( int ii = 0; ii < shape.OutlineCount(); ++ii )
1930 m_gal->DrawSegmentChain( shape.Outline( ii ), thickness );
1931 }
1932
1933 if( aShape->IsFilled() )
1934 {
1935 // On Opengl, a not convex filled polygon is usually drawn by using triangles
1936 // as primitives. CacheTriangulation() can create basic triangle primitives to
1937 // draw the polygon solid shape on Opengl. GLU tessellation is much slower,
1938 // so currently we are using our tessellation.
1939 if( m_gal->IsOpenGlEngine() && !shape.IsTriangulationUpToDate() )
1940 shape.CacheTriangulation( true, true );
1941
1942 m_gal->DrawPolygon( shape );
1943 }
1944 }
1945
1946 break;
1947 }
1948
1949 case SHAPE_T::BEZIER:
1950 if( outline_mode )
1951 {
1952 std::vector<VECTOR2D> output;
1953 std::vector<VECTOR2D> pointCtrl;
1954
1955 pointCtrl.push_back( aShape->GetStart() );
1956 pointCtrl.push_back( aShape->GetBezierC1() );
1957 pointCtrl.push_back( aShape->GetBezierC2() );
1958 pointCtrl.push_back( aShape->GetEnd() );
1959
1960 BEZIER_POLY converter( pointCtrl );
1961 converter.GetPoly( output, m_maxError );
1962
1963 m_gal->DrawSegmentChain( aShape->GetBezierPoints(), thickness );
1964 }
1965 else
1966 {
1967 m_gal->SetIsFill( aShape->IsFilled() );
1968 m_gal->SetIsStroke( thickness > 0 );
1969 m_gal->SetLineWidth( thickness );
1970
1971 if( aShape->GetBezierPoints().size() > 2 )
1972 {
1973 m_gal->DrawPolygon( aShape->GetBezierPoints() );
1974 }
1975 else
1976 {
1977 m_gal->DrawCurve( VECTOR2D( aShape->GetStart() ),
1978 VECTOR2D( aShape->GetBezierC1() ),
1979 VECTOR2D( aShape->GetBezierC2() ),
1980 VECTOR2D( aShape->GetEnd() ), m_maxError );
1981 }
1982 }
1983
1984 break;
1985
1986 case SHAPE_T::UNDEFINED:
1987 break;
1988 }
1989 }
1990 else
1991 {
1992 if( !outline_mode )
1993 {
1994 m_gal->SetIsFill( true );
1995 m_gal->SetIsStroke( false );
1996 }
1997
1998 std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
1999
2000 for( SHAPE* shape : shapes )
2001 {
2002 STROKE_PARAMS::Stroke( shape, lineStyle, thickness, &m_pcbSettings,
2003 [&]( const VECTOR2I& a, const VECTOR2I& b )
2004 {
2005 m_gal->DrawSegment( a, b, thickness );
2006 } );
2007 }
2008
2009 for( SHAPE* shape : shapes )
2010 delete shape;
2011 }
2012}
2013
2014
2015void PCB_PAINTER::strokeText( const wxString& aText, const VECTOR2I& aPosition,
2016 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
2017{
2018 KIFONT::FONT* font = aAttrs.m_Font;
2019
2020 if( !font )
2021 font = KIFONT::FONT::GetFont( wxEmptyString, aAttrs.m_Bold, aAttrs.m_Italic );
2022
2023 m_gal->SetIsFill( font->IsOutline() );
2024 m_gal->SetIsStroke( font->IsStroke() );
2025
2026 VECTOR2I pos( aPosition );
2027 VECTOR2I fudge( KiROUND( 0.16 * aAttrs.m_StrokeWidth ), 0 );
2028
2029 RotatePoint( fudge, aAttrs.m_Angle );
2030
2031 if( ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && !aAttrs.m_Mirrored )
2032 || ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && aAttrs.m_Mirrored ) )
2033 {
2034 pos -= fudge;
2035 }
2036 else if( ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && !aAttrs.m_Mirrored )
2037 || ( aAttrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && aAttrs.m_Mirrored ) )
2038 {
2039 pos += fudge;
2040 }
2041
2042 font->Draw( m_gal, aText, pos, aAttrs, aFontMetrics );
2043}
2044
2045
2046void PCB_PAINTER::draw( const PCB_REFERENCE_IMAGE* aBitmap, int aLayer )
2047{
2048 m_gal->Save();
2049 m_gal->Translate( aBitmap->GetPosition() );
2050
2051 // When the image scale factor is not 1.0, we need to modify the actual as the image scale
2052 // factor is similar to a local zoom
2053 double img_scale = aBitmap->GetImageScale();
2054
2055 if( img_scale != 1.0 )
2056 m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
2057
2058 if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
2059 {
2061 m_gal->SetIsStroke( true );
2064 m_gal->SetIsFill( false );
2065
2066 // Draws a bounding box.
2067 VECTOR2D bm_size( aBitmap->GetSize() );
2068 // bm_size is the actual image size in UI.
2069 // but m_gal scale was previously set to img_scale
2070 // so recalculate size relative to this image size.
2071 bm_size.x /= img_scale;
2072 bm_size.y /= img_scale;
2073 VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
2074 VECTOR2D end = origin + bm_size;
2075
2076 m_gal->DrawRectangle( origin, end );
2077
2078 // Hard code reference images as opaque when selected. Otherwise cached layers will
2079 // not be rendered under the selected image because cached layers are rendered after
2080 // non-cached layers (e.g. bitmaps), which will have a closer Z order.
2081 m_gal->DrawBitmap( *aBitmap->GetImage(), 1.0 );
2082 }
2083 else
2084 m_gal->DrawBitmap( *aBitmap->GetImage(),
2085 m_pcbSettings.GetColor( aBitmap, aBitmap->GetLayer() ).a );
2086
2087
2088 m_gal->Restore();
2089}
2090
2091
2092void PCB_PAINTER::draw( const PCB_TEXT* aText, int aLayer )
2093{
2094 wxString resolvedText( aText->GetShownText( true ) );
2095
2096 if( resolvedText.Length() == 0
2097 || !( aText->GetAttributes().m_Visible || aLayer == LAYER_HIDDEN_TEXT ) )
2098 return;
2099
2100 if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked
2101 {
2102 const COLOR4D color = m_pcbSettings.GetColor( aText, aLayer );
2103
2104 m_gal->SetIsFill( true );
2105 m_gal->SetIsStroke( true );
2109
2110 SHAPE_POLY_SET poly;
2111 aText->TransformShapeToPolygon( poly, aText->GetLayer(), 0, m_maxError, ERROR_OUTSIDE );
2112 m_gal->DrawPolygon( poly );
2113
2114 return;
2115 }
2116
2117 const KIFONT::METRICS& metrics = aText->GetFontMetrics();
2118 TEXT_ATTRIBUTES attrs = aText->GetAttributes();
2119 const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer );
2120 bool outline_mode = !viewer_settings()->m_ViewersDisplay.m_DisplayTextFill;
2121
2122 KIFONT::FONT* font = aText->GetFont();
2123
2124 if( !font )
2125 {
2127 aText->IsItalic() );
2128 }
2129
2132 attrs.m_Angle = aText->GetDrawRotation();
2133
2134 if( aText->IsKnockout() )
2135 {
2136 SHAPE_POLY_SET finalPoly;
2137 aText->TransformTextToPolySet( finalPoly, 0, m_maxError, ERROR_INSIDE );
2138 finalPoly.Fracture( SHAPE_POLY_SET::PM_FAST );
2139
2140 m_gal->SetIsStroke( false );
2141 m_gal->SetIsFill( true );
2142 m_gal->DrawPolygon( finalPoly );
2143 }
2144 else
2145 {
2146 if( outline_mode )
2148 else
2150
2151 if( m_gal->IsFlippedX() && !aText->IsSideSpecific() )
2152 {
2153 VECTOR2I textPos = aText->GetTextPos();
2154 VECTOR2I textWidth = VECTOR2I( aText->GetTextBox().GetWidth(), 0 );
2155 RotatePoint( textWidth, textPos, aText->GetDrawRotation() );
2156
2157 if( attrs.m_Mirrored )
2158 textPos -= textWidth;
2159 else
2160 textPos += textWidth;
2161
2162 attrs.m_Mirrored = !attrs.m_Mirrored;
2163 strokeText( resolvedText, textPos, attrs, metrics );
2164 return;
2165 }
2166
2167 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2168
2169 if( font->IsOutline() )
2170 cache = aText->GetRenderCache( font, resolvedText );
2171
2172 if( cache )
2173 {
2175 m_gal->DrawGlyphs( *cache );
2176 }
2177 else
2178 {
2179 strokeText( resolvedText, aText->GetTextPos(), attrs, metrics );
2180 }
2181 }
2182
2183 // Draw the umbilical line for texts in footprints
2184 FOOTPRINT* fp_parent = aText->GetParentFootprint();
2185
2186 if( fp_parent && aText->IsSelected() )
2187 {
2190 m_gal->DrawLine( aText->GetTextPos(), fp_parent->GetPosition() );
2191 }
2192}
2193
2194
2195void PCB_PAINTER::draw( const PCB_TEXTBOX* aTextBox, int aLayer )
2196{
2197 if( aTextBox->Type() == PCB_TABLECELL_T )
2198 {
2199 const PCB_TABLECELL* cell = static_cast<const PCB_TABLECELL*>( aTextBox );
2200
2201 if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
2202 return;
2203 }
2204
2205 COLOR4D color = m_pcbSettings.GetColor( aTextBox, aLayer );
2206 int thickness = getLineThickness( aTextBox->GetWidth() );
2207 LINE_STYLE lineStyle = aTextBox->GetStroke().GetLineStyle();
2208 wxString resolvedText( aTextBox->GetShownText( true ) );
2209
2210 KIFONT::FONT* font = aTextBox->GetFont();
2211
2212 if( !font )
2213 {
2215 aTextBox->IsItalic() );
2216 }
2217
2218 if( aLayer == LAYER_LOCKED_ITEM_SHADOW ) // happens only if locked
2219 {
2220 const COLOR4D sh_color = m_pcbSettings.GetColor( aTextBox, aLayer );
2221
2222 m_gal->SetIsFill( true );
2223 m_gal->SetIsStroke( false );
2224 m_gal->SetFillColor( sh_color );
2225 m_gal->SetStrokeColor( sh_color );
2226
2227 // Draw the box with a larger thickness than box thickness to show
2228 // the shadow mask
2229 std::vector<VECTOR2I> pts = aTextBox->GetCorners();
2230 int line_thickness = std::max( thickness*3, pcbIUScale.mmToIU( 0.2 ) );
2231
2232 std::deque<VECTOR2D> dpts;
2233
2234 for( const VECTOR2I& pt : pts )
2235 dpts.push_back( VECTOR2D( pt ) );
2236
2237 dpts.push_back( VECTOR2D( pts[0] ) );
2238
2239 m_gal->SetIsStroke( true );
2240 m_gal->SetLineWidth( line_thickness );
2241 m_gal->DrawPolygon( dpts );
2242 }
2243
2244 if( aTextBox->Type() == PCB_TABLECELL_T )
2245 {
2246 // Selection for tables is done with a background wash, so pass in nullptr to GetColor()
2247 // so we just get the "normal" (un-selected/un-brightened) color for the borders.
2248 color = m_pcbSettings.GetColor( nullptr, aLayer );
2249 }
2250
2253 m_gal->SetIsFill( true );
2254 m_gal->SetIsStroke( false );
2255
2256 if( aTextBox->Type() != PCB_TABLECELL_T && aTextBox->IsBorderEnabled() )
2257 {
2258 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2259 {
2260 if( thickness > 0 )
2261 {
2262 std::vector<VECTOR2I> pts = aTextBox->GetCorners();
2263
2264 for( size_t ii = 0; ii < pts.size(); ++ii )
2265 m_gal->DrawSegment( pts[ii], pts[( ii + 1 ) % pts.size()], thickness );
2266 }
2267 }
2268 else
2269 {
2270 std::vector<SHAPE*> shapes = aTextBox->MakeEffectiveShapes( true );
2271
2272 for( SHAPE* shape : shapes )
2273 {
2274 STROKE_PARAMS::Stroke( shape, lineStyle, thickness, &m_pcbSettings,
2275 [&]( const VECTOR2I& a, const VECTOR2I& b )
2276 {
2277 m_gal->DrawSegment( a, b, thickness );
2278 } );
2279 }
2280
2281 for( SHAPE* shape : shapes )
2282 delete shape;
2283 }
2284 }
2285
2286 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
2287 {
2288 // For now, the textbox is a filled shape.
2289 // so the text drawn on LAYER_LOCKED_ITEM_SHADOW with a thick width is disabled
2290 // If enabled, the thick text position must be offsetted to be exactly on the
2291 // initial text, which is not easy, depending on its rotation and justification.
2292#if 0
2293 const COLOR4D sh_color = m_pcbSettings.GetColor( aTextBox, aLayer );
2294 m_gal->SetFillColor( sh_color );
2295 m_gal->SetStrokeColor( sh_color );
2296 attrs.m_StrokeWidth += m_lockedShadowMargin;
2297#else
2298 return;
2299#endif
2300 }
2301
2302 if( resolvedText.Length() == 0 )
2303 return;
2304
2305 const KIFONT::METRICS& metrics = aTextBox->GetFontMetrics();
2306 TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes();
2308
2309 if( m_gal->IsFlippedX() && !aTextBox->IsSideSpecific() )
2310 {
2311 attrs.m_Mirrored = !attrs.m_Mirrored;
2312 strokeText( resolvedText, aTextBox->GetDrawPos( true ), attrs, metrics );
2313 return;
2314 }
2315
2316 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2317
2318 if( font->IsOutline() )
2319 cache = aTextBox->GetRenderCache( font, resolvedText );
2320
2321 if( cache )
2322 {
2324 m_gal->DrawGlyphs( *cache );
2325 }
2326 else
2327 {
2328 strokeText( resolvedText, aTextBox->GetDrawPos(), attrs, metrics );
2329 }
2330}
2331
2332
2333void PCB_PAINTER::draw( const PCB_TABLE* aTable, int aLayer )
2334{
2335 for( PCB_TABLECELL* cell : aTable->GetCells() )
2336 draw( static_cast<PCB_TEXTBOX*>( cell ), aLayer );
2337
2338 VECTOR2I pos = aTable->GetPosition();
2339 VECTOR2I end = aTable->GetEnd();
2340 EDA_ANGLE drawOrientation = aTable->GetOrientation();
2341
2342 // Selection for tables is done with a background wash, so pass in nullptr to GetColor()
2343 // so we just get the "normal" (un-selected/un-brightened) color for the borders.
2344 COLOR4D color = m_pcbSettings.GetColor( nullptr, aLayer );
2345 int lineWidth;
2346 LINE_STYLE lineStyle;
2347
2348 auto setupStroke =
2349 [&]( const STROKE_PARAMS& stroke )
2350 {
2351 lineWidth = getLineThickness( stroke.GetWidth() );
2352 lineStyle = stroke.GetLineStyle();
2353
2354 m_gal->SetIsFill( false );
2355 m_gal->SetIsStroke( true );
2357 m_gal->SetLineWidth( lineWidth );
2358 };
2359
2360 auto strokeShape =
2361 [&]( const SHAPE& shape )
2362 {
2363 STROKE_PARAMS::Stroke( &shape, lineStyle, lineWidth, &m_pcbSettings,
2364 [&]( VECTOR2I a, VECTOR2I b )
2365 {
2366 RotatePoint( a, pos, drawOrientation );
2367 RotatePoint( b, pos, drawOrientation );
2368
2369 // DrawLine has problem with 0 length lines so enforce minimum
2370 if( a == b )
2371 m_gal->DrawLine( a+1, b );
2372 else
2373 m_gal->DrawLine( a, b );
2374 } );
2375 };
2376
2377 auto strokeLine =
2378 [&]( VECTOR2I ptA, VECTOR2I ptB )
2379 {
2380 RotatePoint( ptA, pos, drawOrientation );
2381 RotatePoint( ptB, pos, drawOrientation );
2382
2383 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2384 {
2385 m_gal->DrawLine( ptA, ptB );
2386 }
2387 else
2388 {
2389 SHAPE_SEGMENT seg( ptA, ptB );
2390 strokeShape( seg );
2391 }
2392 };
2393
2394 auto strokeRect =
2395 [&]( VECTOR2I ptA, VECTOR2I ptB )
2396 {
2397 RotatePoint( ptA, pos, drawOrientation );
2398 RotatePoint( ptB, pos, drawOrientation );
2399
2400 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2401 {
2402 m_gal->DrawRectangle( ptA, ptB );
2403 }
2404 else
2405 {
2406 SHAPE_RECT rect( BOX2I( ptA, ptB - ptA ) );
2407 strokeShape( rect );
2408 }
2409 };
2410
2411 if( aTable->GetSeparatorsStroke().GetWidth() >= 0 )
2412 {
2413 setupStroke( aTable->GetSeparatorsStroke() );
2414
2415 if( aTable->StrokeColumns() )
2416 {
2417 int x = pos.x;
2418
2419 for( int col = 0; col < aTable->GetColCount() - 1; ++col )
2420 {
2421 int y = pos.y;
2422
2423 for( int row = 0; row < aTable->GetRowCount(); ++row )
2424 {
2425 PCB_TABLECELL* cell = aTable->GetCell( row, col );
2426 int rowHeight = aTable->GetRowHeight( row );
2427
2428 if( cell->GetColSpan() > 0 && cell->GetRowSpan() > 0 )
2429 strokeLine( VECTOR2I( x, y ), VECTOR2I( x, y + rowHeight ) );
2430
2431 y += rowHeight;
2432 }
2433
2434 x += aTable->GetColWidth( col );
2435 }
2436 }
2437
2438 if( aTable->StrokeRows() )
2439 {
2440 int y = pos.y;
2441
2442 for( int row = 0; row < aTable->GetRowCount() - 1; ++row )
2443 {
2444 int x = pos.x;
2445
2446 for( int col = 0; col < aTable->GetColCount(); ++col )
2447 {
2448 PCB_TABLECELL* cell = aTable->GetCell( row, col );
2449 int colWidth = aTable->GetColWidth( col );
2450
2451 if( cell->GetColSpan() > 0 && cell->GetRowSpan() > 0 )
2452 strokeLine( VECTOR2I( x, y ), VECTOR2I( x + colWidth, y ) );
2453
2454 x += colWidth;
2455 }
2456
2457 y += aTable->GetRowHeight( row );
2458 }
2459 }
2460 }
2461
2462 if( aTable->GetBorderStroke().GetWidth() >= 0 )
2463 {
2464 setupStroke( aTable->GetBorderStroke() );
2465
2466 if( aTable->StrokeHeader() )
2467 {
2468 int headerBottom = pos.y + aTable->GetRowHeight( 0 );
2469
2470 strokeLine( VECTOR2I( pos.x, headerBottom ), VECTOR2I( end.x, headerBottom ) );
2471 }
2472
2473 if( aTable->StrokeExternal() )
2474 strokeRect( pos, end );
2475 }
2476
2477 // Highlight selected tablecells with a background wash.
2478 for( PCB_TABLECELL* cell : aTable->GetCells() )
2479 {
2480 if( aTable->IsSelected() || cell->IsSelected() )
2481 {
2482 std::vector<VECTOR2I> corners = cell->GetCorners();
2483 std::deque<VECTOR2D> pts;
2484
2485 pts.insert( pts.end(), corners.begin(), corners.end() );
2486
2487 m_gal->SetFillColor( color.WithAlpha( 0.5 ) );
2488 m_gal->SetIsFill( true );
2489 m_gal->SetIsStroke( false );
2490 m_gal->DrawPolygon( pts );
2491 }
2492 }
2493}
2494
2495
2496void PCB_PAINTER::draw( const FOOTPRINT* aFootprint, int aLayer )
2497{
2498 if( aLayer == LAYER_ANCHOR )
2499 {
2500 const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
2501
2502 // Keep the size and width constant, not related to the scale because the anchor
2503 // is just a marker on screen
2504 double anchorSize = 5.0 / m_gal->GetWorldScale(); // 5 pixels size
2505 double anchorThickness = 1.0 / m_gal->GetWorldScale(); // 1 pixels width
2506
2507 // Draw anchor
2508 m_gal->SetIsFill( false );
2509 m_gal->SetIsStroke( true );
2511 m_gal->SetLineWidth( anchorThickness );
2512
2513 VECTOR2D center = aFootprint->GetPosition();
2514 m_gal->DrawLine( center - VECTOR2D( anchorSize, 0 ), center + VECTOR2D( anchorSize, 0 ) );
2515 m_gal->DrawLine( center - VECTOR2D( 0, anchorSize ), center + VECTOR2D( 0, anchorSize ) );
2516 }
2517
2518 if( aLayer == LAYER_LOCKED_ITEM_SHADOW && m_frameType == FRAME_PCB_EDITOR ) // happens only if locked
2519 {
2520 const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
2521
2522 m_gal->SetIsFill( true );
2523 m_gal->SetIsStroke( false );
2525
2526#if 0 // GetBoundingHull() can be very slow, especially for logos imported from graphics
2527 const SHAPE_POLY_SET& poly = aFootprint->GetBoundingHull();
2528 m_gal->DrawPolygon( poly );
2529#else
2530 BOX2I bbox = aFootprint->GetBoundingBox( false, false );
2531 VECTOR2I topLeft = bbox.GetPosition();
2532 VECTOR2I botRight = bbox.GetPosition() + bbox.GetSize();
2533
2534 m_gal->DrawRectangle( topLeft, botRight );
2535
2536 // Use segments to produce a margin with rounded corners
2537 m_gal->DrawSegment( topLeft, VECTOR2I( botRight.x, topLeft.y ), m_lockedShadowMargin );
2538 m_gal->DrawSegment( VECTOR2I( botRight.x, topLeft.y ), botRight, m_lockedShadowMargin );
2539 m_gal->DrawSegment( botRight, VECTOR2I( topLeft.x, botRight.y ), m_lockedShadowMargin );
2540 m_gal->DrawSegment( VECTOR2I( topLeft.x, botRight.y ), topLeft, m_lockedShadowMargin );
2541#endif
2542 }
2543
2544 if( aLayer == LAYER_CONFLICTS_SHADOW )
2545 {
2546 const SHAPE_POLY_SET& frontpoly = aFootprint->GetCourtyard( F_CrtYd );
2547 const SHAPE_POLY_SET& backpoly = aFootprint->GetCourtyard( B_CrtYd );
2548
2549 const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
2550
2551 m_gal->SetIsFill( true );
2552 m_gal->SetIsStroke( false );
2554
2555 if( frontpoly.OutlineCount() > 0 )
2556 m_gal->DrawPolygon( frontpoly );
2557
2558 if( backpoly.OutlineCount() > 0 )
2559 m_gal->DrawPolygon( backpoly );
2560 }
2561}
2562
2563
2564void PCB_PAINTER::draw( const PCB_GROUP* aGroup, int aLayer )
2565{
2566 if( aLayer == LAYER_ANCHOR )
2567 {
2568 if( aGroup->IsSelected() && !( aGroup->GetParent() && aGroup->GetParent()->IsSelected() ) )
2569 {
2570 // Selected on our own; draw enclosing box
2571 }
2572 else if( aGroup->IsEntered() )
2573 {
2574 // Entered group; draw enclosing box
2575 }
2576 else
2577 {
2578 // Neither selected nor entered; draw nothing at the group level (ie: only draw
2579 // its members)
2580 return;
2581 }
2582
2583 const COLOR4D color = m_pcbSettings.GetColor( aGroup, LAYER_ANCHOR );
2584
2587
2588 BOX2I bbox = aGroup->GetBoundingBox();
2589 VECTOR2I topLeft = bbox.GetPosition();
2590 VECTOR2I width = VECTOR2I( bbox.GetWidth(), 0 );
2591 VECTOR2I height = VECTOR2I( 0, bbox.GetHeight() );
2592
2593 m_gal->DrawLine( topLeft, topLeft + width );
2594 m_gal->DrawLine( topLeft + width, topLeft + width + height );
2595 m_gal->DrawLine( topLeft + width + height, topLeft + height );
2596 m_gal->DrawLine( topLeft + height, topLeft );
2597
2598 wxString name = aGroup->GetName();
2599
2600 if( name.IsEmpty() )
2601 return;
2602
2603 int ptSize = 12;
2604 int scaledSize = abs( KiROUND( m_gal->GetScreenWorldMatrix().GetScale().x * ptSize ) );
2605 int unscaledSize = pcbIUScale.MilsToIU( ptSize );
2606
2607 // Scale by zoom a bit, but not too much
2608 int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3;
2609 VECTOR2I textOffset = VECTOR2I( width.x / 2, -KiROUND( textSize * 0.5 ) );
2610 VECTOR2I titleHeight = VECTOR2I( 0, KiROUND( textSize * 2.0 ) );
2611
2612 if( PrintableCharCount( name ) * textSize < bbox.GetWidth() )
2613 {
2614 m_gal->DrawLine( topLeft, topLeft - titleHeight );
2615 m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight );
2616 m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width );
2617
2618 TEXT_ATTRIBUTES attrs;
2619 attrs.m_Italic = true;
2622 attrs.m_Size = VECTOR2I( textSize, textSize );
2623 attrs.m_StrokeWidth = GetPenSizeForNormal( textSize );
2624
2625 KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs,
2626 aGroup->GetFontMetrics() );
2627 }
2628 }
2629}
2630
2631
2632void PCB_PAINTER::draw( const ZONE* aZone, int aLayer )
2633{
2634 if( aLayer == LAYER_CONFLICTS_SHADOW )
2635 {
2636 COLOR4D color = m_pcbSettings.GetColor( aZone, aLayer );
2637
2638 m_gal->SetIsFill( true );
2639 m_gal->SetIsStroke( false );
2641
2642 m_gal->DrawPolygon( aZone->Outline()->Outline( 0 ) );
2643 return;
2644 }
2645
2646 /*
2647 * aLayer will be the virtual zone layer (LAYER_ZONE_START, ... in GAL_LAYER_ID)
2648 * This is used for draw ordering in the GAL.
2649 * The color for the zone comes from the associated copper layer ( aLayer - LAYER_ZONE_START )
2650 * and the visibility comes from the combination of that copper layer and LAYER_ZONES
2651 */
2652 PCB_LAYER_ID layer;
2653
2654 if( IsZoneFillLayer( aLayer ) )
2655 layer = ToLAYER_ID( aLayer - LAYER_ZONE_START );
2656 else
2657 layer = ToLAYER_ID( aLayer );
2658
2659 if( !aZone->IsOnLayer( layer ) )
2660 return;
2661
2662 COLOR4D color = m_pcbSettings.GetColor( aZone, layer );
2663 std::deque<VECTOR2D> corners;
2665
2666 // Draw the outline
2667 if( !IsZoneFillLayer( aLayer ) )
2668 {
2669 const SHAPE_POLY_SET* outline = aZone->Outline();
2670 bool allowDrawOutline = aZone->GetHatchStyle() != ZONE_BORDER_DISPLAY_STYLE::INVISIBLE_BORDER;
2671
2672 if( allowDrawOutline && !m_pcbSettings.m_isPrinting && outline && outline->OutlineCount() > 0 )
2673 {
2674 m_gal->SetStrokeColor( color.a > 0.0 ? color.WithAlpha( 1.0 ) : color );
2675 m_gal->SetIsFill( false );
2676 m_gal->SetIsStroke( true );
2678
2679 // Draw each contour (main contour and holes)
2680
2681 /*
2682 * m_gal->DrawPolygon( *outline );
2683 * should be enough, but currently does not work to draw holes contours in a complex
2684 * polygon so each contour is draw as a simple polygon
2685 */
2686
2687 // Draw the main contour(s?)
2688 for( int ii = 0; ii < outline->OutlineCount(); ++ii )
2689 {
2690 m_gal->DrawPolyline( outline->COutline( ii ) );
2691
2692 // Draw holes
2693 int holes_count = outline->HoleCount( ii );
2694
2695 for( int jj = 0; jj < holes_count; ++jj )
2696 m_gal->DrawPolyline( outline->CHole( ii, jj ) );
2697 }
2698
2699 // Draw hatch lines
2700 for( const SEG& hatchLine : aZone->GetHatchLines() )
2701 m_gal->DrawLine( hatchLine.A, hatchLine.B );
2702 }
2703 }
2704
2705 // Draw the filling
2706 if( IsZoneFillLayer( aLayer )
2707 && ( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED
2708 || displayMode == ZONE_DISPLAY_MODE::SHOW_FRACTURE_BORDERS
2709 || displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ) )
2710 {
2711 const std::shared_ptr<SHAPE_POLY_SET>& polySet = aZone->GetFilledPolysList( layer );
2712
2713 if( polySet->OutlineCount() == 0 ) // Nothing to draw
2714 return;
2715
2718 m_gal->SetLineWidth( 0 );
2719
2720 if( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED )
2721 {
2722 m_gal->SetIsFill( true );
2723 m_gal->SetIsStroke( false );
2724 }
2725 else
2726 {
2727 m_gal->SetIsFill( false );
2728 m_gal->SetIsStroke( true );
2729 }
2730
2731 // On Opengl, a not convex filled polygon is usually drawn by using triangles
2732 // as primitives. CacheTriangulation() can create basic triangle primitives to
2733 // draw the polygon solid shape on Opengl. GLU tessellation is much slower,
2734 // so currently we are using our tessellation.
2735 if( m_gal->IsOpenGlEngine() && !polySet->IsTriangulationUpToDate() )
2736 polySet->CacheTriangulation( true, true );
2737
2738 m_gal->DrawPolygon( *polySet, displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION );
2739 }
2740}
2741
2742
2743void PCB_PAINTER::draw( const PCB_DIMENSION_BASE* aDimension, int aLayer )
2744{
2745 const COLOR4D& color = m_pcbSettings.GetColor( aDimension, aLayer );
2746
2749 m_gal->SetIsFill( false );
2750 m_gal->SetIsStroke( true );
2751
2753
2754 if( outline_mode )
2756 else
2758
2759 // Draw dimension shapes
2760 // TODO(JE) lift this out
2761 for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
2762 {
2763 switch( shape->Type() )
2764 {
2765 case SH_SEGMENT:
2766 {
2767 const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
2768 m_gal->DrawLine( seg.A, seg.B );
2769 break;
2770 }
2771
2772 case SH_CIRCLE:
2773 {
2774 int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
2775 m_gal->DrawCircle( shape->Centre(), radius );
2776 break;
2777 }
2778
2779 default:
2780 break;
2781 }
2782 }
2783
2784 // Draw text
2785 wxString resolvedText = aDimension->GetShownText( true );
2786 TEXT_ATTRIBUTES attrs = aDimension->GetAttributes();
2787
2788 if( m_gal->IsFlippedX() && !aDimension->IsSideSpecific() )
2789 attrs.m_Mirrored = !attrs.m_Mirrored;
2790
2791 if( outline_mode )
2793 else
2795
2796 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2797
2798 if( aDimension->GetFont() && aDimension->GetFont()->IsOutline() )
2799 cache = aDimension->GetRenderCache( aDimension->GetFont(), resolvedText );
2800
2801 if( cache )
2802 {
2803 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : *cache )
2804 m_gal->DrawGlyph( *glyph.get() );
2805 }
2806 else
2807 {
2808 strokeText( resolvedText, aDimension->GetTextPos(), attrs, aDimension->GetFontMetrics() );
2809 }
2810}
2811
2812
2813void PCB_PAINTER::draw( const PCB_TARGET* aTarget )
2814{
2815 const COLOR4D& strokeColor = m_pcbSettings.GetColor( aTarget, aTarget->GetLayer() );
2816 VECTOR2D position( aTarget->GetPosition() );
2817 double size, radius;
2818
2819 m_gal->SetLineWidth( getLineThickness( aTarget->GetWidth() ) );
2820 m_gal->SetStrokeColor( strokeColor );
2821 m_gal->SetIsFill( false );
2822 m_gal->SetIsStroke( true );
2823
2824 m_gal->Save();
2825 m_gal->Translate( position );
2826
2827 if( aTarget->GetShape() )
2828 {
2829 // shape x
2830 m_gal->Rotate( M_PI / 4.0 );
2831 size = 2.0 * aTarget->GetSize() / 3.0;
2832 radius = aTarget->GetSize() / 2.0;
2833 }
2834 else
2835 {
2836 // shape +
2837 size = aTarget->GetSize() / 2.0;
2838 radius = aTarget->GetSize() / 3.0;
2839 }
2840
2841 m_gal->DrawLine( VECTOR2D( -size, 0.0 ), VECTOR2D( size, 0.0 ) );
2842 m_gal->DrawLine( VECTOR2D( 0.0, -size ), VECTOR2D( 0.0, size ) );
2843 m_gal->DrawCircle( VECTOR2D( 0.0, 0.0 ), radius );
2844
2845 m_gal->Restore();
2846}
2847
2848
2849void PCB_PAINTER::draw( const PCB_MARKER* aMarker, int aLayer )
2850{
2851 bool isShadow = aLayer == LAYER_MARKER_SHADOWS;
2852
2853 // Don't paint invisible markers.
2854 // It would be nice to do this through layer dependencies but we can't do an "or" there today
2855 if( aMarker->GetBoard() && !aMarker->GetBoard()->IsElementVisible( aMarker->GetColorLayer() ) )
2856 return;
2857
2858 const_cast<PCB_MARKER*>( aMarker )->SetZoom( 1.0 / sqrt( m_gal->GetZoomFactor() ) );
2859
2860 SHAPE_LINE_CHAIN polygon;
2861 aMarker->ShapeToPolygon( polygon );
2862
2864 : aMarker->GetColorLayer() );
2865
2866 m_gal->Save();
2867 m_gal->Translate( aMarker->GetPosition() );
2868
2869 if( isShadow )
2870 {
2872 m_gal->SetIsStroke( true );
2873 m_gal->SetLineWidth( aMarker->MarkerScale() );
2874 }
2875 else
2876 {
2878 m_gal->SetIsFill( true );
2879 }
2880
2881 m_gal->DrawPolygon( polygon );
2882 m_gal->Restore();
2883}
2884
2885
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
constexpr int ARC_HIGH_DEF
Definition: base_units.h:120
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
BOX2< VECTOR2I > BOX2I
Definition: box2.h:877
bool test(size_t pos) const
Definition: base_set.h:48
bool any() const
Definition: base_set.h:56
size_t count() const
Definition: base_set.h:107
Bezier curves to polygon converter.
Definition: bezier_curves.h:38
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:240
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:136
virtual bool IsKnockout() const
Definition: board_item.h:312
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:211
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:266
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:245
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:100
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:218
bool IsSideSpecific() const
Definition: board_item.cpp:116
virtual bool IsOnCopperLayer() const
Definition: board_item.h:153
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:289
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:760
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:774
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:826
int GetCopperLayerCount() const
Definition: board.cpp:736
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:877
void SetOrigin(const Vec &pos)
Definition: box2.h:227
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:136
const Vec & GetPosition() const
Definition: box2.h:201
const Vec & GetOrigin() const
Definition: box2.h:200
const SizeVec & GetSize() const
Definition: box2.h:196
size_type GetHeight() const
Definition: box2.h:205
size_type GetWidth() const
Definition: box2.h:204
const Vec GetEnd() const
Definition: box2.h:202
bool Contains(const Vec &aPoint) const
Definition: box2.h:158
Vec Centre() const
Definition: box2.h:87
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:280
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:249
double AsRadians() const
Definition: eda_angle.h:117
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:77
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
bool IsEntered() const
Definition: eda_item.h:111
bool IsSelected() const
Definition: eda_item.h:110
bool IsBrightened() const
Definition: eda_item.h:112
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:206
virtual VECTOR2I GetTopLeft() const
Definition: eda_shape.h:194
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition: eda_shape.h:319
bool IsFilled() const
Definition: eda_shape.h:91
void CalcArcAngles(EDA_ANGLE &aStartAngle, EDA_ANGLE &aEndAngle) const
Calc arc start and end angles such that aStartAngle < aEndAngle.
Definition: eda_shape.cpp:594
int GetRadius() const
Definition: eda_shape.cpp:610
SHAPE_T GetShape() const
Definition: eda_shape.h:125
virtual VECTOR2I GetBotRight() const
Definition: eda_shape.h:195
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:167
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:130
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1169
const std::vector< VECTOR2I > & GetBezierPoints() const
Definition: eda_shape.h:262
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:203
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:253
bool IsItalic() const
Definition: eda_text.h:152
KIFONT::FONT * GetFont() const
Definition: eda_text.h:230
BOX2I GetTextBox(int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:601
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:542
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:214
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:354
bool IsBold() const
Definition: eda_text.h:167
LSET GetPrivateLayers() const
Definition: footprint.h:140
SHAPE_POLY_SET GetBoundingHull() const
Return a bounding polygon for the shapes and pads in the footprint.
Definition: footprint.cpp:1458
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.cpp:2847
VECTOR2I GetPosition() const override
Definition: footprint.h:223
DRAWINGS & GraphicalItems()
Definition: footprint.h:208
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:1253
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:146
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:258
virtual bool IsOutline() const
Definition: font.h:139
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:311
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
double a
Alpha component.
Definition: color4d.h:395
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
Abstract interface for drawing on a 2D-surface.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void DrawGlyph(const KIFONT::GLYPH &aGlyph, int aNth=0, int aTotal=1)
Draw a polygon representing a font glyph.
virtual void Rotate(double aAngle)
Rotate the context.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
void SetVerticalJustify(const GR_TEXT_V_ALIGN_T aVerticalJustify)
void SetFontBold(const bool aBold)
void SetFontUnderlined(bool aUnderlined)
void SetHorizontalJustify(const GR_TEXT_H_ALIGN_T aHorizontalJustify)
double GetZoomFactor() const
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
virtual void Restore()
Restore the context.
virtual bool IsOpenGlEngine()
Return true if the GAL engine is a OpenGL based type.
void ResetTextAttributes()
Reset text attributes to default styling.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
void SetTextMirrored(const bool aMirrored)
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void DrawArcSegment(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aWidth, double aMaxError)
Draw an arc segment.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
void SetGlyphSize(const VECTOR2I aSize)
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
virtual void DrawCurve(const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint, double aFilterValue=0.0)
Draw a cubic bezier spline.
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle)
Draw an arc.
void SetFontItalic(bool aItalic)
virtual void DrawBitmap(const BITMAP_BASE &aBitmap, double alphaBlend=1.0)
Draw a bitmap image.
virtual void DrawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth)
Draw a rounded segment.
virtual void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
Draw a text using a bitmap font.
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
virtual void Save()
Save the context.
virtual void DrawSegmentChain(const std::vector< VECTOR2D > &aPointList, double aWidth)
Draw a chain of rounded segments.
double GetWorldScale() const
Get the world scale.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:59
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:102
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()
Definition: pcb_painter.cpp:83
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
Definition: pcb_painter.h:235
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.
Definition: pcb_painter.h:163
double m_trackOpacity
Opacity override for all tracks.
Definition: pcb_painter.h:160
double m_imageOpacity
Opacity override for user images.
Definition: pcb_painter.h:164
double m_viaOpacity
Opacity override for all types of via.
Definition: pcb_painter.h:161
ZONE_DISPLAY_MODE m_ZoneDisplayMode
Definition: pcb_painter.h:138
void LoadColors(const COLOR_SETTINGS *aSettings) override
double m_padOpacity
Opacity override for SMD pads and PTHs.
Definition: pcb_painter.h:162
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
Definition: pcb_painter.h:117
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
Definition: pcb_painter.h:139
std::map< int, KIGFX::COLOR4D > m_netColors
Set of net codes that should not have their ratsnest displayed.
Definition: pcb_painter.h:154
NET_COLOR_MODE m_netColorMode
Overrides for specific netclass colors.
Definition: pcb_painter.h:148
static const double MAX_FONT_SIZE
< Maximum font size for netnames (and other dynamically shown strings)
Definition: pcb_painter.h:145
double m_filledShapeOpacity
Opacity override for graphic shapes.
Definition: pcb_painter.h:165
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)
const wxString & GetDefaultFont() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
PCB_LAYER_ID GetActiveLayer() const
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
COLOR4D m_layerColorsHi[LAYER_ID_COUNT]
virtual void update()
Precalculates extra colors for layers (e.g.
void SetDashLengthRatio(double aRatio)
COLOR4D m_layerColors[LAYER_ID_COUNT]
std::set< int > m_highlightNetcodes
std::set< int > m_highContrastLayers
bool m_hiContrastEnabled
Parameters for display modes.
bool GetDrawBoundingBoxes() const
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
bool IsBOARD_ITEM() const
Definition: view_item.h:100
double GetForcedTransparency() const
Definition: view_item.h:161
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:392
PCB_LAYER_ID ExtractLayer() const
Find the first set PCB_LAYER_ID.
Definition: lset.cpp:686
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:732
static LSET PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition: lset.cpp:822
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...
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:295
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
COLOR4D GetPcbColor(bool aIsForSave=false) const
Definition: netclass.h:176
bool HasPcbColor() const
Definition: netclass.h:175
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:381
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:944
bool FlashLayer(int aLayer, bool aOnlyCheckIfPermitted=false) const
Check to see whether the pad should be flashed on the specific layer.
Definition: pad.cpp:312
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
Definition: pad.cpp:709
int GetSolderMaskExpansion() const
Definition: pad.cpp:970
PAD_ATTRIB GetAttribute() const
Definition: pad.h:391
const wxString & GetPinFunction() const
Definition: pad.h:145
const wxString & GetNumber() const
Definition: pad.h:134
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives() const
Accessor to the basic shape list for custom-shaped pads.
Definition: pad.h:318
bool IsNoConnectPad() const
Definition: pad.cpp:228
VECTOR2I ShapePos() const
Definition: pad.cpp:869
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:1781
bool IsFreePad() const
Definition: pad.cpp:234
PAD_SHAPE GetShape() const
Definition: pad.h:193
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition: pad.h:359
PAD_DRILL_SHAPE GetDrillShape() const
Definition: pad.h:373
VECTOR2I GetSolderPasteMargin() const
Usually < 0 (mask shape smaller than pad)because the margin can be dependent on the pad size,...
Definition: pad.cpp:1007
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING flashPTHPads=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pad.cpp:435
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const override
Return a SHAPE_SEGMENT object representing the pad's hole.
Definition: pad.cpp:472
const VECTOR2I & GetSize() const
Definition: pad.h:256
DISPLAY_OPTIONS m_Display
EDA_ANGLE GetArcAngleStart() const
Definition: pcb_track.cpp:1609
double GetRadius() const
Definition: pcb_track.cpp:1592
EDA_ANGLE GetAngle() const
Definition: pcb_track.cpp:1599
const VECTOR2I & GetMid() const
Definition: pcb_track.h:281
virtual VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_track.h:288
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:52
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_group.cpp:260
wxString GetName() const
Definition: pcb_group.h:66
GAL_LAYER_ID GetColorLayer() const
Definition: pcb_marker.cpp:324
VECTOR2I GetPosition() const override
Definition: pcb_marker.h:68
Object to handle a bitmap image that can be inserted in a PCB.
VECTOR2I GetPosition() const override
double GetImageScale() const
const BITMAP_BASE * GetImage() const
const VECTOR2I GetSize() const
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:75
int GetWidth() const override
Definition: pcb_shape.cpp:369
virtual std::vector< VECTOR2I > GetCorners() const
Return 4 corners for a rectangle or rotated rectangle (stored as a poly).
Definition: pcb_shape.cpp:427
bool IsProxyItem() const override
Definition: pcb_shape.h:110
STROKE_PARAMS GetStroke() const override
Definition: pcb_shape.h:85
int GetRowSpan() const
Definition: pcb_tablecell.h:65
int GetColSpan() const
Definition: pcb_tablecell.h:62
VECTOR2I GetEnd() const
Definition: pcb_table.cpp:118
bool StrokeRows() const
Definition: pcb_table.h:86
int GetRowCount() const
Definition: pcb_table.h:106
bool StrokeColumns() const
Definition: pcb_table.h:83
bool StrokeExternal() const
Definition: pcb_table.h:53
bool StrokeHeader() const
Definition: pcb_table.h:56
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition: pcb_table.h:131
std::vector< PCB_TABLECELL * > GetCells() const
Definition: pcb_table.h:141
int GetColCount() const
Definition: pcb_table.h:104
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: pcb_table.h:71
const STROKE_PARAMS & GetBorderStroke() const
Definition: pcb_table.h:59
int GetColWidth(int aCol) const
Definition: pcb_table.h:113
VECTOR2I GetPosition() const override
Definition: pcb_table.cpp:112
EDA_ANGLE GetOrientation() const
Definition: pcb_table.h:101
int GetRowHeight(int aRow) const
Definition: pcb_table.h:123
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.
VECTOR2I GetDrawPos() const override
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
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:627
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: pcb_text.cpp:186
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Function TransformTextToPolySet Convert the text to a polygonSet describing the actual character stro...
Definition: pcb_text.cpp:569
EDA_ANGLE GetDrawRotation() const override
Definition: pcb_text.cpp:227
const VECTOR2I & GetStart() const
Definition: pcb_track.h:122
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:119
virtual int GetWidth() const
Definition: pcb_track.h:116
PCB_LAYER_ID BottomLayer() const
Definition: pcb_track.cpp:991
bool FlashLayer(int aLayer) const
Check to see whether the via should have a pad on the specific layer.
Definition: pcb_track.cpp:1027
int GetWidth() const override
Definition: pcb_track.cpp:313
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition: pcb_track.cpp:863
PCB_LAYER_ID TopLayer() const
Definition: pcb_track.cpp:985
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
Definition: pcb_track.cpp:547
VIATYPE GetViaType() const
Definition: pcb_track.h:377
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)
Definition: pcb_track.cpp:963
VIEWERS_DISPLAY_OPTIONS m_ViewersDisplay
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:678
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
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:333
ecoord SquaredLength() const
Definition: seg.h:338
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=DefaultAccuracyForPCB(), double *aEffectiveAccuracy=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:560
int GetRadius() const
Definition: shape_circle.h:118
const VECTOR2I GetCenter() const
Definition: shape_circle.h:123
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.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
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.
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
const VECTOR2I & GetPosition() const
Definition: shape_rect.h:137
const VECTOR2I GetSize() const
Definition: shape_rect.h:145
int GetWidth() const
Definition: shape_rect.h:153
int GetHeight() const
Definition: shape_rect.h:161
const SEG & GetSeg() const
int GetWidth() const
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Definition: shape_simple.h:42
const SHAPE_LINE_CHAIN & Vertices() const
Return the list of vertices defining this simple polygon.
Definition: shape_simple.h:124
virtual const SEG GetSegment(int aIndex) const override
Definition: shape_simple.h:174
const VECTOR2I & CPoint(int aIndex) const
Return a const reference to a given point in the polygon.
Definition: shape_simple.h:102
int PointCount() const
Return the number of points (vertices) in this polygon.
Definition: shape_simple.h:88
virtual size_t GetSegmentCount() const override
Definition: shape_simple.h:176
An abstract shape on 2D plane.
Definition: shape.h:126
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
int GetWidth() const
Definition: stroke_params.h:91
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
static void Stroke(const SHAPE *aShape, LINE_STYLE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, const std::function< void(const VECTOR2I &a, const VECTOR2I &b)> &aStroker)
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:383
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
const std::vector< SEG > & GetHatchLines() const
Definition: zone.h:779
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:616
SHAPE_POLY_SET * Outline()
Definition: zone.h:337
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
Definition: zone.cpp:356
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
Definition: zone.h:605
@ 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.
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
@ DEGREES_T
Definition: eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
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.
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
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:64
@ LAYER_PAD_FR_NETNAMES
Additional netnames layers (not associated with a PCB layer)
Definition: layer_ids.h:167
@ LAYER_PAD_BK_NETNAMES
Definition: layer_ids.h:168
@ LAYER_PAD_NETNAMES
Definition: layer_ids.h:169
@ NETNAMES_LAYER_ID_START
Definition: layer_ids.h:159
@ LAYER_VIA_NETNAMES
Definition: layer_ids.h:170
bool IsPcbLayer(int aLayer)
Test whether a layer is a valid layer for Pcbnew.
Definition: layer_ids.h:521
bool IsNetCopperLayer(int aLayer)
Checks if the given layer is "net copper", meaning it is eligible for net coloring.
Definition: layer_ids.h:710
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
Definition: layer_ids.h:662
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:532
@ GAL_LAYER_ID_START
Definition: layer_ids.h:195
@ LAYER_LOCKED_ITEM_SHADOW
shadow layer for locked items
Definition: layer_ids.h:243
@ LAYER_VIA_HOLEWALLS
Definition: layer_ids.h:238
@ LAYER_CONFLICTS_SHADOW
shadow layer for items flagged conficting
Definition: layer_ids.h:245
@ LAYER_NON_PLATEDHOLES
handle color for not plated holes (holes, not pads)
Definition: layer_ids.h:201
@ LAYER_DRC_EXCLUSION
layer for drc markers which have been individually excluded
Definition: layer_ids.h:240
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:224
@ LAYER_DRC_WARNING
layer for drc markers with SEVERITY_WARNING
Definition: layer_ids.h:239
@ LAYER_PAD_PLATEDHOLES
to draw pad holes (plated)
Definition: layer_ids.h:218
@ GAL_LAYER_ID_END
Definition: layer_ids.h:269
@ LAYER_HIDDEN_TEXT
text marked as invisible
Definition: layer_ids.h:204
@ LAYER_ZONE_START
Virtual layers for stacking zones and tracks on a given copper layer.
Definition: layer_ids.h:258
@ LAYER_ANCHOR
anchor of items having an anchor point (texts, footprints)
Definition: layer_ids.h:205
@ LAYER_PADS_SMD_BK
smd pads, back layer
Definition: layer_ids.h:207
@ LAYER_PADS_TH
multilayer pads, usually with holes
Definition: layer_ids.h:217
@ LAYER_PADS_SMD_FR
smd pads, front layer
Definition: layer_ids.h:206
@ LAYER_MARKER_SHADOWS
shadows for drc markers
Definition: layer_ids.h:241
@ LAYER_VIA_HOLES
to draw via holes (pad holes do not use this layer)
Definition: layer_ids.h:219
@ LAYER_VIA_MICROVIA
to draw micro vias
Definition: layer_ids.h:198
@ LAYER_VIA_THROUGH
to draw usual through hole vias
Definition: layer_ids.h:200
@ LAYER_DRC_ERROR
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:220
@ LAYER_VIA_BBLIND
to draw blind/buried vias
Definition: layer_ids.h:199
@ LAYER_PAD_HOLEWALLS
Definition: layer_ids.h:237
bool IsNetnameLayer(int aLayer)
Test whether a layer is a netname layer.
Definition: layer_ids.h:685
bool IsHoleLayer(int aLayer)
Definition: layer_ids.h:571
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:117
@ F_Paste
Definition: layer_ids.h:101
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ F_Mask
Definition: layer_ids.h:107
@ B_Paste
Definition: layer_ids.h:100
@ F_SilkS
Definition: layer_ids.h:104
@ B_CrtYd
Definition: layer_ids.h:116
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137
@ F_Cu
Definition: layer_ids.h:64
bool IsZoneFillLayer(int aLayer)
Definition: layer_ids.h:691
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:875
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition: padstack.h:63
Class to handle a set of BOARD_ITEMs.
PCBNEW_SETTINGS * pcbconfig()
Definition: pcb_painter.cpp:75
@ SHOW_WITH_VIA_ALWAYS
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: pgm_base.cpp:1066
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.
Definition: stroke_params.h:48
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
TRACK_CLEARANCE_MODE m_TrackClearance
@ 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
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:105
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:103
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:110
@ 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:107
@ 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_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:106
@ 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:101
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition: typeinfo.h:94
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:104
constexpr ret_type KiROUND(fp_type v, bool aQuiet=false)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:100
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:676
VECTOR2< double > VECTOR2D
Definition: vector2d.h:675