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