KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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) 2014 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27
28#include <trigo.h>
29#include <chrono>
30#include <bitmap_base.h>
31#include <connection_graph.h>
33#include <callback_gal.h>
35#include <geometry/shape_rect.h>
36#include <geometry/roundrect.h>
39#include <gr_text.h>
40#include <sch_pin.h>
41#include <math/util.h>
42#include <pin_layout_cache.h>
43#include <pgm_base.h>
44#include <sch_bitmap.h>
45#include <sch_bus_entry.h>
46#include <sch_symbol.h>
47#include <sch_edit_frame.h>
48#include <sch_field.h>
49#include <sch_group.h>
50#include <sch_junction.h>
51#include <sch_line.h>
52#include <sch_shape.h>
53#include <sch_marker.h>
54#include <sch_no_connect.h>
55#include <sch_sheet.h>
56#include <sch_sheet_pin.h>
57#include <sch_text.h>
58#include <sch_textbox.h>
59#include <sch_table.h>
60#include <schematic.h>
62#include <trace_helpers.h>
63#include <view/view.h>
64#include <kiface_base.h>
65#include <default_values.h>
66#include <advanced_config.h>
68#include <stroke_params.h>
69#include <string_utils.h>
70#include "sch_painter.h"
71#include "common.h"
72
74
75namespace KIGFX
76{
77
79{
80 return dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
81}
82
83
84std::vector<KICAD_T> SCH_PAINTER::g_ScaledSelectionTypes = {
103};
104
105
107 KIGFX::PAINTER( aGal ),
108 m_schematic( nullptr )
109{ }
110
111
112bool SCH_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
113{
114 const EDA_ITEM* item = dynamic_cast<const EDA_ITEM*>( aItem );
115
116 if( !item )
117 return false;
118
119 draw( item, aLayer, false );
120
121 return false;
122}
123
124
125void SCH_PAINTER::draw( const EDA_ITEM* aItem, int aLayer, bool aDimmed )
126{
127
128#ifdef CONNECTIVITY_DEBUG
129
130 auto sch_item = dynamic_cast<const SCH_ITEM*>( aItem );
131 auto conn = sch_item ? sch_item->Connection( *g_CurrentSheet ) : nullptr;
132
133 if( conn )
134 {
135 auto pos = aItem->GetBoundingBox().Centre();
136 auto label = conn->Name( true );
137
138 m_canvas->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
139 m_canvas->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
140 m_canvas->SetStrokeColor( COLOR4D( LIGHTRED ) );
141 m_canvas->SetLineWidth( Mils2ui( 2 ) );
142 m_canvas->SetGlyphSize( VECTOR2D( Mils2ui( 20 ), Mils2ui( 20 ) ) );
143 m_canvas->StrokeText( *m_canvas, conn->Name( true ), pos, 0.0, 0 );
144 }
145
146#endif
147
148 // Enable draw bounding box on request. Some bboxes are handled locally.
149 bool drawBoundingBox = m_schSettings.GetDrawBoundingBoxes();
150
151 switch( aItem->Type() )
152 {
153 case LIB_SYMBOL_T:
154 draw( static_cast<const LIB_SYMBOL*>( aItem ), aLayer );
155 break;
156 case SCH_PIN_T:
157 drawBoundingBox = false;
158 draw( static_cast<const SCH_PIN*>( aItem ), aLayer, aDimmed );
159 break;
160 case SCH_SYMBOL_T:
161 draw( static_cast<const SCH_SYMBOL*>( aItem ), aLayer );
162 break;
163 case SCH_JUNCTION_T:
164 draw( static_cast<const SCH_JUNCTION*>( aItem ), aLayer );
165 break;
166 case SCH_LINE_T:
167 draw( static_cast<const SCH_LINE*>( aItem ), aLayer );
168 break;
169 case SCH_SHAPE_T:
170 draw( static_cast<const SCH_SHAPE*>( aItem ), aLayer, aDimmed );
171 break;
172 case SCH_RULE_AREA_T:
173 draw( static_cast<const SCH_SHAPE*>( aItem ), aLayer, aDimmed );
174 break;
175 case SCH_TEXT_T:
176 draw( static_cast<const SCH_TEXT*>( aItem ), aLayer, aDimmed );
177 break;
178 case SCH_TEXTBOX_T:
179 draw( static_cast<const SCH_TEXTBOX*>( aItem ), aLayer, aDimmed );
180 break;
181 case SCH_TABLE_T:
182 draw( static_cast<const SCH_TABLE*>( aItem ), aLayer, aDimmed );
183 break;
184 case SCH_LABEL_T:
185 draw( static_cast<const SCH_LABEL*>( aItem ), aLayer, aDimmed );
186 break;
188 draw( static_cast<const SCH_DIRECTIVE_LABEL*>( aItem ), aLayer, aDimmed );
189 break;
190 case SCH_FIELD_T:
191 draw( static_cast<const SCH_FIELD*>( aItem ), aLayer, aDimmed );
192 break;
193 case SCH_HIER_LABEL_T:
194 draw( static_cast<const SCH_HIERLABEL*>( aItem ), aLayer, aDimmed );
195 break;
197 draw( static_cast<const SCH_GLOBALLABEL*>( aItem ), aLayer, aDimmed );
198 break;
199 case SCH_SHEET_T:
200 draw( static_cast<const SCH_SHEET*>( aItem ), aLayer );
201 break;
202 case SCH_SHEET_PIN_T:
203 draw( static_cast<const SCH_HIERLABEL*>( aItem ), aLayer, aDimmed );
204 break;
205 case SCH_NO_CONNECT_T:
206 draw( static_cast<const SCH_NO_CONNECT*>( aItem ), aLayer );
207 break;
209 draw( static_cast<const SCH_BUS_ENTRY_BASE*>( aItem ), aLayer );
210 break;
212 draw( static_cast<const SCH_BUS_ENTRY_BASE*>( aItem ), aLayer );
213 break;
214 case SCH_BITMAP_T:
215 draw( static_cast<const SCH_BITMAP*>( aItem ), aLayer );
216 break;
217 case SCH_MARKER_T:
218 draw( static_cast<const SCH_MARKER*>( aItem ), aLayer );
219 break;
220 case SCH_GROUP_T:
221 draw( static_cast<const SCH_GROUP*>( aItem ), aLayer );
222 break;
223 default:
224 return;
225 }
226
227 if( drawBoundingBox )
228 drawItemBoundingBox( aItem );
229}
230
231
233{
234 if( const SCH_ITEM* item = dynamic_cast<const SCH_ITEM*>( aItem ) )
235 {
236 if( item->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
237 return;
238 }
239
240 BOX2I box = aItem->GetBoundingBox();
241
242 if( aItem->Type() == SCH_SYMBOL_T )
243 box = static_cast<const SCH_SYMBOL*>( aItem )->GetBodyBoundingBox();
244
245 m_gal->SetIsFill( false );
246 m_gal->SetIsStroke( true );
247 m_gal->SetStrokeColor( aItem->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 )
248 : COLOR4D( 0.2, 0.2, 0.2, 1 ) );
249 m_gal->SetLineWidth( schIUScale.MilsToIU( 3 ) );
250 m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
251}
252
253
255{
256 // TODO: it would be nice to have a more definitive test for this, but we've currently got
257 // no access to the VIEW_GROUP to see if it's cached or not.
258 return aItem->IsSelected();
259}
260
261
263{
264 if( m_schSettings.m_ShowUnit // showing a specific unit
265 && aItem->GetUnit() // item is unit-specific
266 && aItem->GetUnit() != m_schSettings.m_ShowUnit )
267 {
268 return false;
269 }
270
271 if( m_schSettings.m_ShowBodyStyle // showing a specific body style
272 && aItem->GetBodyStyle() // item is body-style-specific
273 && aItem->GetBodyStyle() != m_schSettings.m_ShowBodyStyle )
274 {
275 return false;
276 }
277
278 return true;
279}
280
281
283{
284 if( KIFONT::FONT* font = aItem->GetDrawFont( &m_schSettings ) )
285 return font;
286
287 return KIFONT::FONT::GetFont( m_schSettings.GetDefaultFont(), aItem->IsBold(), aItem->IsItalic() );
288}
289
290
291float SCH_PAINTER::getShadowWidth( bool aForHighlight ) const
292{
293 const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
294
295 int milsWidth = aForHighlight ? eeconfig()->m_Selection.highlight_thickness
297
298 // For best visuals the selection width must be a cross between the zoom level and the
299 // default line width.
300 return (float) std::fabs( matrix.GetScale().x * milsWidth ) + schIUScale.MilsToIU( milsWidth );
301}
302
303
304COLOR4D SCH_PAINTER::getRenderColor( const SCH_ITEM* aItem, int aLayer, bool aDrawingShadows,
305 bool aDimmed, bool aIgnoreNets ) const
306{
307 auto isBackgroundLayer =
308 []( int layer )
309 {
310 return layer == LAYER_DEVICE_BACKGROUND || layer == LAYER_NOTES_BACKGROUND
311 || layer == LAYER_SHAPES_BACKGROUND || layer == LAYER_SHEET_BACKGROUND;
312 };
313
314 COLOR4D color = m_schSettings.GetLayerColor( aLayer );
315
316 // Graphic items of a SYMBOL frequently use the LAYER_DEVICE layer color
317 // (i.e. when no specific color is set)
318 bool isSymbolChild = aItem->GetParentSymbol() != nullptr;
319
320 if( !m_schSettings.m_OverrideItemColors )
321 {
322 if( aItem->Type() == SCH_LINE_T )
323 {
324 color = static_cast<const SCH_LINE*>( aItem )->GetLineColor();
325 }
326 else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
327 {
328 color = static_cast<const SCH_BUS_WIRE_ENTRY*>( aItem )->GetBusEntryColor();
329 }
330 else if( aItem->Type() == SCH_JUNCTION_T )
331 {
332 color = static_cast<const SCH_JUNCTION*>( aItem )->GetJunctionColor();
333 }
334 else if( aItem->Type() == SCH_SHEET_T )
335 {
336 const SCH_SHEET* sheet = static_cast<const SCH_SHEET*>( aItem );
337
338 if( isBackgroundLayer( aLayer ) )
339 color = sheet->GetBackgroundColor();
340 else
341 color = sheet->GetBorderColor();
342 }
343 else if( aItem->Type() == SCH_SHAPE_T || aItem->Type() == SCH_RULE_AREA_T )
344 {
345 const SCH_SHAPE* shape = static_cast<const SCH_SHAPE*>( aItem );
346
347 if( isBackgroundLayer( aLayer ) )
348 {
349 switch( shape->GetFillMode() )
350 {
351 case FILL_T::NO_FILL:
352 break;
353
355 color = shape->GetStroke().GetColor();
356 break;
357
358 case FILL_T::HATCH:
362 color = shape->GetFillColor();
363 break;
364
366 color = m_schSettings.GetLayerColor( LAYER_DEVICE_BACKGROUND );
367 break;
368
369 default:
370 wxFAIL_MSG( wxT( "Unsupported fill type" ) );
371 }
372
373 // A filled shape means filled; if they didn't specify a fill colour then use
374 // the border colour.
375 if( shape->GetFillMode() != FILL_T::NO_FILL && color == COLOR4D::UNSPECIFIED )
376 {
377 if( aItem->Type() == SCH_RULE_AREA_T )
378 color = m_schSettings.GetLayerColor( LAYER_RULE_AREAS );
379 else if( isSymbolChild )
380 color = m_schSettings.GetLayerColor( LAYER_DEVICE );
381 else
382 color = m_schSettings.GetLayerColor( LAYER_NOTES );
383 }
384 }
385 else
386 {
387 color = shape->GetStroke().GetColor();
388 }
389 }
390 else if( aItem->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
391 {
392 const SCH_LABEL_BASE* label = static_cast<const SCH_LABEL_BASE*>( aItem );
393
394 if( label->GetTextColor() != COLOR4D::UNSPECIFIED )
395 color = label->GetTextColor(); // override color
396 else if( aIgnoreNets )
397 color = m_schSettings.GetLayerColor( aLayer ); // layer color
398 else
399 color = label->GetLabelColor(); // net/netclass color
400 }
401 else if( aItem->Type() == SCH_FIELD_T )
402 {
403 color = static_cast<const SCH_FIELD*>( aItem )->GetFieldColor();
404 }
405 else if( aItem->Type() == SCH_TEXTBOX_T || aItem->Type() == SCH_TABLECELL_T )
406 {
407 const SCH_TEXTBOX* textBox = static_cast<const SCH_TEXTBOX*>( aItem );
408
409 if( isBackgroundLayer( aLayer ) )
410 color = textBox->GetFillColor();
411 else if( !isSymbolChild || textBox->GetTextColor() != COLOR4D::UNSPECIFIED )
412 color = textBox->GetTextColor();
413 }
414 else if( const EDA_TEXT* otherTextItem = dynamic_cast<const EDA_TEXT*>( aItem ) )
415 {
416 if( !isSymbolChild || otherTextItem->GetTextColor() != COLOR4D::UNSPECIFIED )
417 color = otherTextItem->GetTextColor();
418 }
419
420 if( color.m_text )
421 color = COLOR4D( aItem->ResolveText( *color.m_text, &m_schematic->CurrentSheet() ) );
422 }
423 else /* overrideItemColors */
424 {
425 // If we ARE overriding the item colors, what do we do with non-item-color fills?
426 // There are two theories: we should leave them untouched, or we should drop them entirely.
427 // We currently implment the first.
428 if( isBackgroundLayer( aLayer) )
429 {
430 if( aItem->Type() == SCH_SHAPE_T || aItem->Type() == SCH_RULE_AREA_T )
431 {
432 const SCH_SHAPE* shape = static_cast<const SCH_SHAPE*>( aItem );
433
434 if( shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
435 color = shape->GetFillColor();
436 }
437 else if( aItem->Type() == SCH_SHEET_T )
438 {
439 const SCH_SHEET* sheet = static_cast<const SCH_SHEET*>( aItem );
440
441 color = sheet->GetBackgroundColor();
442 }
443 }
444 }
445
446 if( color == COLOR4D::UNSPECIFIED )
447 color = m_schSettings.GetLayerColor( aLayer );
448
449 if( aItem->IsBrightened() ) // Selection disambiguation, net highlighting, etc.
450 {
451 color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
452
453 if( aDrawingShadows )
454 {
455 if( aItem->IsSelected() )
456 color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS );
457 else
458 color = color.WithAlpha( 0.15 );
459 }
460 else if( isBackgroundLayer( aLayer ) )
461 {
462 color = color.WithAlpha( 0.2 );
463 }
464 }
465 else if( aItem->IsSelected() && aDrawingShadows )
466 {
467 color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS );
468 }
469 else if( aItem->IsSelected() && isBackgroundLayer( aLayer ) )
470 {
471 // Selected items will be painted over all other items, so make backgrounds translucent so
472 // that non-selected overlapping objects are visible
473 color = color.WithAlpha( 0.5 );
474 }
475
476 if( m_schSettings.m_ShowDisabled
477 || ( m_schSettings.m_ShowGraphicsDisabled && aItem->Type() != SCH_FIELD_T ) )
478 {
479 color = color.Darken( 0.5f );
480 }
481
482 if( aDimmed && !( aItem->IsSelected() && aDrawingShadows ) )
483 {
484 COLOR4D sheetColour = m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
485 color.Desaturate();
486 color = color.Mix( sheetColour, 0.5f );
487 }
488
489 if( aItem->GetForcedTransparency() > 0.0 )
490 color = color.WithAlpha( color.a * ( 1.0 - aItem->GetForcedTransparency() ) );
491
492 return color;
493}
494
495
496float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows,
497 bool aDrawingWireColorHighlights ) const
498{
499 wxCHECK( aItem, static_cast<float>( schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS ) ) );
500
501 int pen = aItem->GetEffectivePenWidth( &m_schSettings );
502 float width = pen;
503
504 if( aItem->IsBrightened() || aItem->IsSelected() )
505 {
506 if( aDrawingShadows && aItem->IsType( g_ScaledSelectionTypes ) )
507 width += getShadowWidth( aItem->IsBrightened() );
508 }
509
510 if( aDrawingWireColorHighlights )
511 {
512 float colorHighlightWidth = schIUScale.MilsToIU( 15.0 );
513 EESCHEMA_SETTINGS* eeschemaCfg = eeconfig();
514
515 if( eeschemaCfg )
516 colorHighlightWidth = schIUScale.MilsToIU( eeschemaCfg->m_Selection.highlight_netclass_colors_thickness );
517
518 width += colorHighlightWidth;
519 }
520
521 return width;
522}
523
524
525float SCH_PAINTER::getTextThickness( const SCH_ITEM* aItem ) const
526{
527 int pen = m_schSettings.GetDefaultPenWidth();
528
529 switch( aItem->Type() )
530 {
531 case SCH_FIELD_T:
532 pen = static_cast<const SCH_FIELD*>( aItem )->GetEffectiveTextPenWidth( pen );
533 break;
534
535 case SCH_TEXT_T:
536 pen = static_cast<const SCH_TEXT*>( aItem )->GetEffectiveTextPenWidth( pen );
537 break;
538
539 case SCH_LABEL_T:
542 case SCH_HIER_LABEL_T:
543 case SCH_SHEET_PIN_T:
544 pen = static_cast<const SCH_LABEL_BASE*>( aItem )->GetEffectiveTextPenWidth( pen );
545 break;
546
547 case SCH_TEXTBOX_T:
548 case SCH_TABLECELL_T:
549 pen = static_cast<const SCH_TEXTBOX*>( aItem )->GetEffectiveTextPenWidth( pen );
550 break;
551
552 default:
553 UNIMPLEMENTED_FOR( aItem->GetClass() );
554 }
555
556 return (float) pen;
557}
558
559
561{
562 int docTextSize = schIUScale.MilsToIU( 50 );
563 int screenTextSize = std::abs( (int) m_gal->GetScreenWorldMatrix().GetScale().y * 7 );
564
565 // 66% zoom-relative
566 return KiROUND( ( docTextSize + screenTextSize * 2 ) / 3.0 );
567}
568
569
570static bool isFieldsLayer( int aLayer )
571{
572 return aLayer == LAYER_REFERENCEPART
573 || aLayer == LAYER_VALUEPART
574 || aLayer == LAYER_INTERSHEET_REFS
575 || aLayer == LAYER_NETCLASS_REFS
576 || aLayer == LAYER_FIELDS
577 || aLayer == LAYER_SHEETNAME
578 || aLayer == LAYER_SHEETFILENAME
579 || aLayer == LAYER_SHEETFIELDS;
580}
581
582
583static BOX2I GetTextExtents( const wxString& aText, const VECTOR2D& aPosition, KIFONT::FONT& aFont,
584 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
585{
586 const VECTOR2I extents = aFont.StringBoundaryLimits( aText, aAttrs.m_Size, aAttrs.m_StrokeWidth,
587 aAttrs.m_Bold, aAttrs.m_Italic, aFontMetrics );
588 BOX2I box( aPosition, VECTOR2I( extents.x, aAttrs.m_Size.y ) );
589
590 switch( aAttrs.m_Halign )
591 {
592 case GR_TEXT_H_ALIGN_LEFT: break;
593 case GR_TEXT_H_ALIGN_CENTER: box.SetX( box.GetX() - box.GetWidth() / 2 ); break;
594 case GR_TEXT_H_ALIGN_RIGHT: box.SetX( box.GetX() - box.GetWidth() ); break;
595 case GR_TEXT_H_ALIGN_INDETERMINATE: wxFAIL_MSG( wxT( "Legal only in dialogs" ) ); break;
596 }
597
598 switch( aAttrs.m_Valign )
599 {
600 case GR_TEXT_V_ALIGN_TOP: break;
601 case GR_TEXT_V_ALIGN_CENTER: box.SetY( box.GetY() - box.GetHeight() / 2 ); break;
602 case GR_TEXT_V_ALIGN_BOTTOM: box.SetY( box.GetY() - box.GetHeight() ); break;
603 case GR_TEXT_V_ALIGN_INDETERMINATE: wxFAIL_MSG( wxT( "Legal only in dialogs" ) ); break;
604 }
605
606 box.Normalize(); // Make h and v sizes always >= 0
607 box = box.GetBoundingBoxRotated( aPosition, aAttrs.m_Angle );
608
609 return box;
610}
611
612
613static void strokeText( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
614 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics,
615 std::optional<VECTOR2I> aMousePos = std::nullopt, wxString* aActiveUrl = nullptr )
616{
617 KIFONT::FONT* font = aAttrs.m_Font;
618
619 if( !font )
620 font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, aAttrs.m_Bold, aAttrs.m_Italic );
621
622 aGal.SetIsFill( font->IsOutline() );
623 aGal.SetIsStroke( font->IsStroke() );
624
625 font->Draw( &aGal, aText, aPosition, aAttrs, aFontMetrics, aMousePos, aActiveUrl );
626}
627
628
629static void bitmapText( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
630 const TEXT_ATTRIBUTES& aAttrs )
631{
632 // Bitmap font has different metrics from the stroke font so we compensate a bit before
633 // stroking
634 aGal.SetGlyphSize( VECTOR2I( aAttrs.m_Size.x, KiROUND( aAttrs.m_Size.y * 1.05 ) ) );
635 aGal.SetLineWidth( (float) aAttrs.m_StrokeWidth * 1.35f );
636
637 aGal.SetHorizontalJustify( aAttrs.m_Halign );
638 aGal.SetVerticalJustify( aAttrs.m_Valign );
639
640 aGal.BitmapText( aText, aPosition, aAttrs.m_Angle );
641}
642
643
644static void knockoutText( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
645 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
646{
647 TEXT_ATTRIBUTES attrs( aAttrs );
648 KIFONT::FONT* font = aAttrs.m_Font;
649
650 if( !font )
651 {
652 font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, attrs.m_Bold,
653 attrs.m_Italic );
654 }
655
657 SHAPE_POLY_SET knockouts;
658
659 CALLBACK_GAL callback_gal( empty_opts,
660 // Polygon callback
661 [&]( const SHAPE_LINE_CHAIN& aPoly )
662 {
663 knockouts.AddOutline( aPoly );
664 } );
665
666 callback_gal.SetIsFill( false );
667 callback_gal.SetIsStroke( true );
668 callback_gal.SetLineWidth( (float) attrs.m_StrokeWidth );
669 font->Draw( &callback_gal, aText, aPosition, attrs, aFontMetrics );
670
671 BOX2I bbox = knockouts.BBox( attrs.m_StrokeWidth * 2 );
672 SHAPE_POLY_SET finalPoly;
673
674 finalPoly.NewOutline();
675 finalPoly.Append( bbox.GetLeft(), bbox.GetTop() );
676 finalPoly.Append( bbox.GetRight(), bbox.GetTop() );
677 finalPoly.Append( bbox.GetRight(), bbox.GetBottom() );
678 finalPoly.Append( bbox.GetLeft(), bbox.GetBottom() );
679
680 finalPoly.BooleanSubtract( knockouts );
681 finalPoly.Fracture();
682
683 aGal.SetIsStroke( false );
684 aGal.SetIsFill( true );
685 aGal.SetFillColor( attrs.m_Color );
686 aGal.DrawPolygon( finalPoly );
687}
688
689
690static void boxText( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
691 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
692{
693 KIFONT::FONT* font = aAttrs.m_Font;
694
695 if( !font )
696 font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, aAttrs.m_Bold, aAttrs.m_Italic );
697
698 BOX2I box = GetTextExtents( aText, aPosition, *font, aAttrs, aFontMetrics );
699
700 // Give the highlight a bit of margin.
701 box.Inflate( aAttrs.m_StrokeWidth / 2, aAttrs.m_StrokeWidth * 2 );
702
703 aGal.SetIsFill( true );
704 aGal.SetIsStroke( false );
705 aGal.DrawRectangle( box.GetOrigin(), box.GetEnd() );
706}
707
708
709void SCH_PAINTER::triLine( const VECTOR2D& a, const VECTOR2D& b, const VECTOR2D& c )
710{
711 m_gal->DrawLine( a, b );
712 m_gal->DrawLine( b, c );
713}
714
715
716void SCH_PAINTER::draw( const LIB_SYMBOL* aSymbol, int aLayer, bool aDrawFields, int aUnit,
717 int aBodyStyle, bool aDimmed )
718{
719 if( !aUnit )
720 aUnit = m_schSettings.m_ShowUnit;
721
722 if( !aBodyStyle )
723 aBodyStyle = m_schSettings.m_ShowBodyStyle;
724
725 std::unique_ptr< LIB_SYMBOL > tmpSymbol;
726 const LIB_SYMBOL* drawnSymbol = aSymbol;
727
728 if( aSymbol->IsDerived() )
729 {
730 tmpSymbol = aSymbol->Flatten();
731 drawnSymbol = tmpSymbol.get();
732 }
733
734 // The parent must exist on the union of all its children's draw layers. But that doesn't
735 // mean we want to draw each child on the union.
736 auto childOnLayer =
737 []( const SCH_ITEM& item, int layer )
738 {
739 return alg::contains( item.ViewGetLayers(), layer );
740 };
741
742 for( const SCH_ITEM& item : drawnSymbol->GetDrawItems() )
743 {
744 if( !aDrawFields && item.Type() == SCH_FIELD_T )
745 continue;
746
747 if( !childOnLayer( item, aLayer ) )
748 continue;
749
750 if( aUnit && item.GetUnit() && aUnit != item.GetUnit() )
751 continue;
752
753 if( aBodyStyle && item.GetBodyStyle() && aBodyStyle != item.GetBodyStyle() )
754 continue;
755
756 draw( &item, aLayer, aDimmed );
757 }
758}
759
760
762{
763 if( m_schSettings.m_PinSymbolSize > 0 )
764 return m_schSettings.m_PinSymbolSize;
765
766 return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
767}
768
769
770// Utility for getting the size of the 'external' pin decorators (as a radius)
771// i.e. the negation circle, the polarity 'slopes' and the nonlogic marker
773{
774 if( m_schSettings.m_PinSymbolSize > 0 )
775 return m_schSettings.m_PinSymbolSize;
776
777 return aPin.GetNumberTextSize() / 2;
778}
779
780
781// Draw the target (an open circle) for a pin which has no connection or is being moved.
783 bool aDrawingShadows, bool aBrightened )
784{
785 const PIN_LAYOUT_CACHE& plc = aPin.GetLayoutCache();
786 const CIRCLE c = plc.GetDanglingIndicator();
787
788 float lineWidth = aDrawingShadows ? getShadowWidth( aBrightened )
789 : m_schSettings.GetDanglingIndicatorThickness();
790
791 // Dangling symbols must be drawn in a slightly different colour so they can be seen when
792 // they overlap with a junction dot.
793 m_gal->SetStrokeColor( aColor.Brightened( 0.3 ) );
794
795 m_gal->SetIsFill( false );
796 m_gal->SetIsStroke( true );
797 m_gal->SetLineWidth( lineWidth );
798 m_gal->DrawCircle( c.Center, c.Radius );
799}
800
801
805void SCH_PAINTER::drawLocalPowerIcon( const VECTOR2D& aPos, double aSize, bool aRotate,
806 const COLOR4D& aColor, bool aDrawingShadows,
807 bool aBrightened )
808{
809 double lineWidth = aSize / 10.0;
810
811 if( aDrawingShadows )
812 lineWidth += getShadowWidth( aBrightened );
813
814 std::vector<SCH_SHAPE> shapeList;
815 SCH_SYMBOL::BuildLocalPowerIconShape( shapeList, aPos, aSize, lineWidth, aRotate );
816
817 m_gal->SetLineWidth( lineWidth );
818 m_gal->SetIsStroke( true );
819 m_gal->SetStrokeColor( aColor );
820 m_gal->SetFillColor( aColor );
821
822 for( const SCH_SHAPE& shape : shapeList )
823 {
824 // Currently there are only 2 shapes: BEZIER and CIRCLE
825 m_gal->SetIsFill( shape.GetFillMode() != FILL_T::NO_FILL );
826
827 if( shape.GetShape() == SHAPE_T::BEZIER )
828 m_gal->DrawCurve( shape.GetStart(), shape.GetBezierC1(), shape.GetBezierC2(), shape.GetEnd() );
829 else if( shape.GetShape() == SHAPE_T::CIRCLE )
830 m_gal->DrawCircle( shape.getCenter(), shape.GetRadius() );
831 }
832}
833
834
838static void drawAltPinModesIcon( GAL& aGal, const VECTOR2D& aPos, double aSize, bool aBaseSelected,
839 bool aRotate, int aExtraLineWidth, const COLOR4D& aColor )
840{
841 aGal.Save();
842
843 aGal.Translate( aPos );
844
845 if( aRotate )
846 {
847 aGal.Rotate( ANGLE_270.AsRadians() );
848 }
849
850 aGal.SetIsFill( false );
851 aGal.SetIsStroke( true );
852 aGal.SetLineWidth( aSize / 10.0 + aExtraLineWidth );
853 aGal.SetStrokeColor( aColor );
854
855 /*
856 * ----------->
857 * + <--center
858 * \------->
859 *
860 * or
861 *
862 * ----- ---->
863 * \
864 * \------>
865 */
866
867 const double lineYOffset = aSize / 4;
868 const double arrowHead = aSize / 8;
869
870 const VECTOR2D topLineREnd = VECTOR2D{ aSize / 2, -lineYOffset };
871 const VECTOR2D btmLineREnd = VECTOR2D{ aSize / 2, lineYOffset };
872
873 // Top line and arrowhead
874 if( aBaseSelected )
875 {
876 // Full top line
877 aGal.DrawLine( topLineREnd, topLineREnd - VECTOR2D{ aSize, 0 } );
878 }
879 else
880 {
881 // Line with a gap
882 aGal.DrawLine( topLineREnd, topLineREnd - VECTOR2D{ aSize / 2, 0 } );
883 aGal.DrawLine( topLineREnd - VECTOR2D{ aSize, 0 },
884 topLineREnd - VECTOR2D{ aSize * 0.7, 0 } );
885 }
886
887 aGal.DrawLine( topLineREnd, topLineREnd - VECTOR2D{ arrowHead * 1.2, arrowHead } );
888 aGal.DrawLine( topLineREnd, topLineREnd - VECTOR2D{ arrowHead * 1.2, -arrowHead } );
889
890 // Bottom line and arrowhead
891 aGal.DrawLine( btmLineREnd, btmLineREnd - VECTOR2D{ aSize / 2, 0 } );
892 aGal.DrawLine( btmLineREnd, btmLineREnd - VECTOR2D{ arrowHead * 1.2, arrowHead } );
893 aGal.DrawLine( btmLineREnd, btmLineREnd - VECTOR2D{ arrowHead * 1.2, -arrowHead } );
894
895 // Top and bottom 'S' arcs
896 if( !aBaseSelected )
897 {
898 aGal.DrawArc( topLineREnd - VECTOR2D{ aSize, -lineYOffset },
899 lineYOffset, ANGLE_0, -ANGLE_90 );
900 }
901
902 aGal.DrawArc( topLineREnd - VECTOR2D{ aSize - lineYOffset * 2, -lineYOffset },
903 lineYOffset, ANGLE_180, -ANGLE_90 );
904
905 aGal.Restore();
906};
907
908
909void SCH_PAINTER::draw( const SCH_PIN* aPin, int aLayer, bool aDimmed )
910{
911 // Don't draw pins from a selection view-group. Pins in a schematic must always be drawn
912 // from their parent symbol's m_part.
913 if( dynamic_cast<const SCH_SYMBOL*>( aPin->GetParentSymbol() ) )
914 return;
915
916 if( !isUnitAndConversionShown( aPin ) )
917 return;
918
919 const bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
920 const bool drawingDangling = aLayer == LAYER_DANGLING;
921 const bool drawingOP = aLayer == LAYER_OP_CURRENTS;
922
923 if( m_schSettings.IsPrinting() && ( drawingShadows || drawingDangling ) )
924 return;
925
926 const bool isDangling = m_schSettings.m_IsSymbolEditor || aPin->HasFlag( IS_DANGLING );
927
928 if( drawingShadows && !( aPin->IsBrightened() || aPin->IsSelected() ) )
929 return;
930
931 const VECTOR2I pos = aPin->GetPosition();
932 COLOR4D color = getRenderColor( aPin, LAYER_PIN, drawingShadows, aDimmed );
933
934 if( !aPin->IsVisible() )
935 {
936 if( m_schSettings.IsPrinting() )
937 return;
938
940 : m_schSettings.m_ShowHiddenPins;
941
942 if( force_show )
943 {
944 color = getRenderColor( aPin, LAYER_HIDDEN, drawingShadows, aDimmed );
945 }
946 else
947 {
948 if( drawingDangling && isDangling && aPin->IsGlobalPower() )
949 drawPinDanglingIndicator( *aPin, color, drawingShadows, aPin->IsBrightened() );
950
951 return;
952 }
953 }
954
955 if( drawingDangling )
956 {
957 if( isDangling )
958 drawPinDanglingIndicator( *aPin, color, drawingShadows, aPin->IsBrightened() );
959
960 return;
961 }
962
963 if( m_schSettings.GetDrawBoundingBoxes() )
964 drawItemBoundingBox( aPin );
965
966 const VECTOR2I p0 = aPin->GetPinRoot();
967 const VECTOR2I dir( sign( pos.x - p0.x ), sign( pos.y - p0.y ) );
968 const int len = aPin->GetLength();
969
970 if( drawingOP && !aPin->GetOperatingPoint().IsEmpty() )
971 {
972 int textSize = getOperatingPointTextSize();
973 VECTOR2I mid = ( p0 + pos ) / 2;
974 int textOffset = KiROUND( textSize * 0.22 );
975 TEXT_ATTRIBUTES attrs;
976
977 if( len > textSize )
978 {
979 if( dir.x == 0 )
980 {
981 mid.x += KiROUND( textOffset * 1.2 );
983 }
984 else
985 {
986 mid.y -= KiROUND( textOffset * 1.2 );
987 attrs.m_Angle = ANGLE_VERTICAL;
988 }
989
992
993 attrs.m_Font = KIFONT::FONT::GetFont(); // always use stroke font for performance
994 attrs.m_Size = VECTOR2I( textSize, textSize );
995 attrs.m_StrokeWidth = GetPenSizeForDemiBold( textSize );
996 attrs.m_Color = m_schSettings.GetLayerColor( LAYER_OP_CURRENTS );
997
998 knockoutText( *m_gal, aPin->GetOperatingPoint(), mid, attrs, aPin->GetFontMetrics() );
999 }
1000 }
1001
1002 if( drawingOP )
1003 return;
1004
1005 VECTOR2D pc;
1006
1007 m_gal->SetIsStroke( true );
1008 m_gal->SetIsFill( false );
1009 m_gal->SetLineWidth( getLineWidth( aPin, drawingShadows ) );
1010 m_gal->SetStrokeColor( color );
1011 m_gal->SetFontBold( false );
1012 m_gal->SetFontUnderlined( false );
1013 m_gal->SetFontItalic( false );
1014
1015 const int radius = externalPinDecoSize( *aPin );
1016 const int diam = radius*2;
1017 const int clock_size = internalPinDecoSize( *aPin );
1018
1019 if( aPin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
1020 {
1021 m_gal->DrawLine( p0, pos );
1022
1023 m_gal->DrawLine( pos + VECTOR2D( -1, -1 ) * TARGET_PIN_RADIUS,
1024 pos + VECTOR2D( 1, 1 ) * TARGET_PIN_RADIUS );
1025 m_gal->DrawLine( pos + VECTOR2D( 1, -1 ) * TARGET_PIN_RADIUS ,
1026 pos + VECTOR2D( -1, 1 ) * TARGET_PIN_RADIUS );
1027 }
1028 else
1029 {
1030 switch( aPin->GetShape() )
1031 {
1032 default:
1034 m_gal->DrawLine( p0, pos );
1035 break;
1036
1038 m_gal->DrawCircle( p0 + dir * radius, radius );
1039 m_gal->DrawLine( p0 + dir * ( diam ), pos );
1040 break;
1041
1043 pc = p0 - dir * clock_size ;
1044
1045 triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
1046 pc,
1047 p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
1048
1049 m_gal->DrawCircle( p0 + dir * radius, radius );
1050 m_gal->DrawLine( p0 + dir * ( diam ), pos );
1051 break;
1052
1055 pc = p0 - dir * clock_size ;
1056
1057 triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
1058 pc,
1059 p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
1060
1061 if( !dir.y )
1062 {
1063 triLine( p0 + VECTOR2D(dir.x, 0) * diam,
1064 p0 + VECTOR2D(dir.x, -1) * diam,
1065 p0 );
1066 }
1067 else /* MapX1 = 0 */
1068 {
1069 triLine( p0 + VECTOR2D( 0, dir.y) * diam,
1070 p0 + VECTOR2D(-1, dir.y) * diam,
1071 p0 );
1072 }
1073
1074 m_gal->DrawLine( p0, pos );
1075 break;
1076
1078 m_gal->DrawLine( p0, pos );
1079
1080 if( !dir.y )
1081 {
1082 triLine( p0 + VECTOR2D( 0, clock_size ),
1083 p0 + VECTOR2D( -dir.x * clock_size, 0 ),
1084 p0 + VECTOR2D( 0, -clock_size ) );
1085 }
1086 else
1087 {
1088 triLine( p0 + VECTOR2D( clock_size, 0 ),
1089 p0 + VECTOR2D( 0, -dir.y * clock_size ),
1090 p0 + VECTOR2D( -clock_size, 0 ) );
1091 }
1092 break;
1093
1095 m_gal->DrawLine( p0, pos );
1096
1097 if( !dir.y )
1098 {
1099 triLine( p0 + VECTOR2D(dir.x, 0) * diam,
1100 p0 + VECTOR2D(dir.x, -1) * diam,
1101 p0 );
1102 }
1103 else /* MapX1 = 0 */
1104 {
1105 triLine( p0 + VECTOR2D( 0, dir.y) * diam,
1106 p0 + VECTOR2D(-1, dir.y) * diam,
1107 p0 );
1108 }
1109 break;
1110
1111 case GRAPHIC_PINSHAPE::OUTPUT_LOW: // IEEE symbol "Active Low Output"
1112 m_gal->DrawLine( p0, pos );
1113
1114 if( !dir.y ) // Horizontal pin
1115 m_gal->DrawLine( p0 - VECTOR2D( 0, diam ), p0 + VECTOR2D( dir.x, 0 ) * diam );
1116 else // Vertical pin
1117 m_gal->DrawLine( p0 - VECTOR2D( diam, 0 ), p0 + VECTOR2D( 0, dir.y ) * diam );
1118 break;
1119
1120 case GRAPHIC_PINSHAPE::NONLOGIC: // NonLogic pin symbol
1121 m_gal->DrawLine( p0, pos );
1122
1123 m_gal->DrawLine( p0 - VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius,
1124 p0 + VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius );
1125 m_gal->DrawLine( p0 - VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius,
1126 p0 + VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius );
1127 break;
1128 }
1129 }
1130
1131 if( drawingShadows && !eeconfig()->m_Selection.draw_selected_children )
1132 return;
1133
1134 // Draw the labels
1135 float nameStrokeWidth = getLineWidth( aPin, false );
1136 float numStrokeWidth = getLineWidth( aPin, false );
1137
1138 nameStrokeWidth = ClampTextPenSize( nameStrokeWidth, aPin->GetNameTextSize(), true );
1139 numStrokeWidth = ClampTextPenSize( numStrokeWidth, aPin->GetNumberTextSize(), true );
1140
1141 float shadowWidth = 0.0f;
1142
1143 if( drawingShadows )
1144 {
1145 shadowWidth = getShadowWidth( aPin->IsBrightened() );
1146 }
1147
1148 PIN_LAYOUT_CACHE& cache = aPin->GetLayoutCache();
1149 cache.SetRenderParameters( nameStrokeWidth, numStrokeWidth, m_schSettings.m_ShowPinsElectricalType,
1150 m_schSettings.m_ShowPinAltIcons );
1151
1152 const auto textRendersAsBitmap =
1153 [&]( KIGFX::GAL& aGal, int aTextSize )
1154 {
1155 // Rendering text is expensive (particularly when using outline fonts). At small effective
1156 // sizes (ie: zoomed out) the visual differences between outline and/or stroke fonts and the
1157 // bitmap font becomes immaterial, and there's often more to draw when zoomed out so the
1158 // performance gain becomes more significant.
1159 static const float BITMAP_FONT_SIZE_THRESHOLD = 3.5;
1160
1161 // Any text non bitmappable?
1162 return aTextSize * aGal.GetWorldScale() < BITMAP_FONT_SIZE_THRESHOLD;
1163 };
1164
1165 // Helper function for drawing braces around multi-line text
1166 const auto drawBrace =
1167 [&]( KIGFX::GAL& aGal, const VECTOR2D& aTop, const VECTOR2D& aBottom,
1168 int aBraceWidth, bool aLeftBrace, const TEXT_ATTRIBUTES& aAttrs )
1169 {
1170 // Draw a simple brace using line segments, accounting for text rotation
1171 VECTOR2D mid = ( aTop + aBottom ) / 2.0;
1172
1173 aGal.SetLineWidth( aAttrs.m_StrokeWidth );
1174 aGal.SetIsFill( false );
1175 aGal.SetIsStroke( true );
1176
1177 // Calculate brace points in text coordinate system
1178 VECTOR2D p1 = aTop;
1179 VECTOR2D p2 = aTop;
1180 VECTOR2D p3 = mid;
1181 VECTOR2D p4 = aBottom;
1182 VECTOR2D p5 = aBottom;
1183
1184 // Apply brace offset based on text orientation
1185 if( aAttrs.m_Angle == ANGLE_VERTICAL )
1186 {
1187 // For vertical text, braces extend in the Y direction
1188 // "Left" brace is actually towards negative Y, "right" towards positive Y
1189 double braceOffset = aLeftBrace ? -aBraceWidth : aBraceWidth;
1190 p2.y += braceOffset / 2;
1191 p3.y += braceOffset;
1192 p4.y += braceOffset / 2;
1193 }
1194 else
1195 {
1196 // For horizontal text, braces extend in the X direction
1197 double braceOffset = aLeftBrace ? -aBraceWidth : aBraceWidth;
1198 p2.x += braceOffset / 2;
1199 p3.x += braceOffset;
1200 p4.x += braceOffset / 2;
1201 }
1202
1203 // Draw the brace segments
1204 aGal.DrawLine( p1, p2 );
1205 aGal.DrawLine( p2, p3 );
1206 aGal.DrawLine( p3, p4 );
1207 aGal.DrawLine( p4, p5 );
1208 };
1209
1210 const auto drawBracesAroundText =
1211 [&]( KIGFX::GAL& aGal, const wxArrayString& aLines, const VECTOR2D& aStartPos,
1212 int aLineSpacing, const TEXT_ATTRIBUTES& aAttrs )
1213 {
1214 if( aLines.size() <= 1 )
1215 return;
1216
1217 // Calculate brace dimensions
1218 int braceWidth = aAttrs.m_Size.x / 3; // Make braces a bit larger
1219
1220 // Find the maximum line width to position braces
1221 int maxLineWidth = 0;
1222 KIFONT::FONT* font = aAttrs.m_Font;
1223
1224 if( !font )
1225 font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font );
1226
1227 for( const wxString& line : aLines )
1228 {
1229 wxString trimmedLine = line;
1230 trimmedLine.Trim( true ).Trim( false );
1231 VECTOR2I lineExtents = font->StringBoundaryLimits( trimmedLine, aAttrs.m_Size,
1232 aAttrs.m_StrokeWidth, false, false,
1233 KIFONT::METRICS() );
1234 maxLineWidth = std::max( maxLineWidth, lineExtents.x );
1235 }
1236
1237 // Calculate brace positions based on text vertical alignment and rotation
1238 VECTOR2D braceStart = aStartPos;
1239 VECTOR2D braceEnd = aStartPos;
1240
1241 // Extend braces beyond the text bounds
1242 int textHeight = aAttrs.m_Size.y;
1243 int extraHeight = textHeight / 3; // Extend braces by 1/3 of text height beyond text
1244
1245 if( aAttrs.m_Angle == ANGLE_VERTICAL )
1246 {
1247 // For vertical text, lines are spaced horizontally and braces are horizontal
1248 braceEnd.x += ( (int) aLines.size() - 1 ) * aLineSpacing;
1249
1250 // Extend braces horizontally to encompass all lines plus extra space
1251 braceStart.x -= 2 * extraHeight;
1252
1253 // Position braces in the perpendicular direction (Y) with proper spacing
1254 int braceSpacing = maxLineWidth / 2 + braceWidth;
1255
1256 VECTOR2D topBraceStart = braceStart;
1257 topBraceStart.y -= braceSpacing;
1258
1259 VECTOR2D topBraceEnd = braceEnd;
1260 topBraceEnd.y -= braceSpacing;
1261
1262 drawBrace( aGal, topBraceStart, topBraceEnd, braceWidth, true, aAttrs );
1263
1264 VECTOR2D bottomBraceStart = braceStart;
1265 bottomBraceStart.y += braceSpacing;
1266
1267 VECTOR2D bottomBraceEnd = braceEnd;
1268 bottomBraceEnd.y += braceSpacing;
1269
1270 drawBrace( aGal, bottomBraceStart, bottomBraceEnd, braceWidth, false, aAttrs );
1271 }
1272 else
1273 {
1274 // For horizontal text, lines are spaced vertically and braces are vertical
1275 braceEnd.y += ( (int) aLines.size() - 1 ) * aLineSpacing;
1276
1277 // Extend braces vertically to encompass all lines plus extra space
1278 braceStart.y -= 2 * extraHeight;
1279
1280 // Position braces in the perpendicular direction (X) with proper spacing
1281 int braceSpacing = maxLineWidth / 2 + braceWidth;
1282
1283 // Draw left brace
1284 VECTOR2D leftTop = braceStart;
1285 leftTop.x -= braceSpacing;
1286
1287 VECTOR2D leftBottom = braceEnd;
1288 leftBottom.x -= braceSpacing;
1289
1290 drawBrace( aGal, leftTop, leftBottom, braceWidth, true, aAttrs );
1291
1292 // Draw right brace
1293 VECTOR2D rightTop = braceStart;
1294 rightTop.x += braceSpacing;
1295
1296 VECTOR2D rightBottom = braceEnd;
1297 rightBottom.x += braceSpacing;
1298
1299 drawBrace( aGal, rightTop, rightBottom, braceWidth, false, aAttrs );
1300 }
1301 };
1302
1303 const auto drawBracesAroundTextBitmap =
1304 [&]( KIGFX::GAL& aGal, const wxArrayString& aLines, const VECTOR2D& aStartPos,
1305 int aLineSpacing, const TEXT_ATTRIBUTES& aAttrs )
1306 {
1307 // Simplified brace drawing for bitmap text
1308 if( aLines.size() <= 1 )
1309 return;
1310
1311 int braceWidth = aAttrs.m_Size.x / 4;
1312
1313 // Estimate max line width (less precise for bitmap text)
1314 int maxLineWidth = aAttrs.m_Size.x * 4; // Conservative estimate
1315
1316 // Calculate brace positions based on rotation
1317 VECTOR2D braceStart = aStartPos;
1318 VECTOR2D braceEnd = aStartPos;
1319
1320 int textHalfHeight = aAttrs.m_Size.y / 2;
1321
1322 if( aAttrs.m_Angle == ANGLE_VERTICAL )
1323 {
1324 // For vertical text, lines are spaced horizontally
1325 braceEnd.x += ( (int) aLines.size() - 1 ) * aLineSpacing;
1326
1327 VECTOR2D leftStart = braceStart;
1328 leftStart.y -= maxLineWidth / 2.0 + braceWidth / 2.0;
1329
1330 VECTOR2D leftEnd = braceEnd;
1331 leftEnd.y -= maxLineWidth / 2.0 + braceWidth / 2.0;
1332
1333 drawBrace( aGal, leftStart, leftEnd, braceWidth, true, aAttrs );
1334
1335 VECTOR2D rightStart = braceStart;
1336 rightStart.y += maxLineWidth / 2.0 + braceWidth / 2.0;
1337
1338 VECTOR2D rightEnd = braceEnd;
1339 rightEnd.y += maxLineWidth / 2.0 + braceWidth / 2.0;
1340
1341 drawBrace( aGal, rightStart, rightEnd, braceWidth, false, aAttrs );
1342 }
1343 else
1344 {
1345 // For horizontal text, lines are spaced vertically
1346 braceEnd.y += ( (int) aLines.size() - 1 ) * aLineSpacing;
1347
1348 VECTOR2D braceTop = braceStart;
1349 braceTop.y -= textHalfHeight;
1350
1351 VECTOR2D braceBottom = braceEnd;
1352 braceBottom.y += textHalfHeight;
1353
1354 VECTOR2D leftTop = braceTop;
1355 leftTop.x -= maxLineWidth / 2.0 + braceWidth / 2.0;
1356
1357 VECTOR2D leftBottom = braceBottom;
1358 leftBottom.x -= maxLineWidth / 2.0 + braceWidth / 2.0;
1359
1360 drawBrace( aGal, leftTop, leftBottom, braceWidth, true, aAttrs );
1361
1362 VECTOR2D rightTop = braceTop;
1363 rightTop.x += maxLineWidth / 2.0 + braceWidth / 2.0;
1364
1365 VECTOR2D rightBottom = braceBottom;
1366 rightBottom.x += maxLineWidth / 2.0 + braceWidth / 2.0;
1367
1368 drawBrace( aGal, rightTop, rightBottom, braceWidth, false, aAttrs );
1369 }
1370 };
1371
1372 // Helper functions for drawing multi-line pin text with braces
1373 const auto drawMultiLineText =
1374 [&]( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
1375 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
1376 {
1377 // Check if this is multi-line stacked pin text with braces
1378 if( aText.StartsWith( "[" ) && aText.EndsWith( "]" ) && aText.Contains( "\n" ) )
1379 {
1380 // Extract content between braces and split into lines
1381 wxString content = aText.Mid( 1, aText.Length() - 2 );
1382 wxArrayString lines;
1383 wxStringSplit( content, lines, '\n' );
1384
1385 if( lines.size() > 1 )
1386 {
1387 // Calculate line spacing (similar to EDA_TEXT::GetInterline)
1388 int lineSpacing = KiROUND( aAttrs.m_Size.y * 1.3 ); // 130% of text height
1389
1390 // Calculate positioning based on text alignment and rotation
1391 VECTOR2D startPos = aPosition;
1392
1393 if( aAttrs.m_Angle == ANGLE_VERTICAL )
1394 {
1395 // For vertical text, lines are spaced horizontally
1396 // Adjust start position based on horizontal alignment
1397 if( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT )
1398 {
1399 int totalWidth = ( (int) lines.size() - 1 ) * lineSpacing;
1400 startPos.x -= totalWidth;
1401 }
1402 else if( aAttrs.m_Halign == GR_TEXT_H_ALIGN_CENTER )
1403 {
1404 int totalWidth = ( (int) lines.size() - 1 ) * lineSpacing;
1405 startPos.x -= totalWidth / 2.0;
1406 }
1407
1408 // Draw each line
1409 for( size_t i = 0; i < lines.size(); i++ )
1410 {
1411 VECTOR2D linePos = startPos;
1412 linePos.x += i * lineSpacing;
1413
1414 wxString line = lines[i];
1415 line.Trim( true ).Trim( false );
1416
1417 strokeText( aGal, line, linePos, aAttrs, aFontMetrics );
1418 }
1419 }
1420 else
1421 {
1422 // For horizontal text, lines are spaced vertically
1423 // Adjust start position based on vertical alignment
1424 if( aAttrs.m_Valign == GR_TEXT_V_ALIGN_BOTTOM )
1425 {
1426 int totalHeight = ( (int) lines.size() - 1 ) * lineSpacing;
1427 startPos.y -= totalHeight;
1428 }
1429 else if( aAttrs.m_Valign == GR_TEXT_V_ALIGN_CENTER )
1430 {
1431 int totalHeight = ( (int) lines.size() - 1 ) * lineSpacing;
1432 startPos.y -= totalHeight / 2.0;
1433 }
1434
1435 // Draw each line
1436 for( size_t i = 0; i < lines.size(); i++ )
1437 {
1438 VECTOR2D linePos = startPos;
1439 linePos.y += (int) i * lineSpacing;
1440
1441 wxString line = lines[i];
1442 line.Trim( true ).Trim( false );
1443
1444 strokeText( aGal, line, linePos, aAttrs, aFontMetrics );
1445 }
1446 }
1447
1448 // Draw braces around the text
1449 drawBracesAroundText( aGal, lines, startPos, lineSpacing, aAttrs );
1450 return;
1451 }
1452 }
1453
1454 // Fallback to regular single-line text
1455 strokeText( aGal, aText, aPosition, aAttrs, aFontMetrics );
1456 };
1457
1458 const auto boxMultiLineText =
1459 [&]( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
1460 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
1461 {
1462 // Similar to drawMultiLineText but uses boxText for outline fonts
1463 if( aText.StartsWith( "[" ) && aText.EndsWith( "]" ) && aText.Contains( "\n" ) )
1464 {
1465 wxString content = aText.Mid( 1, aText.Length() - 2 );
1466 wxArrayString lines;
1467 wxStringSplit( content, lines, '\n' );
1468
1469 if( lines.size() > 1 )
1470 {
1471 int lineSpacing = KiROUND( aAttrs.m_Size.y * 1.3 );
1472 VECTOR2D startPos = aPosition;
1473
1474 if( aAttrs.m_Angle == ANGLE_VERTICAL )
1475 {
1476 // For vertical text, lines are spaced horizontally
1477 if( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT )
1478 {
1479 int totalWidth = ( (int) lines.size() - 1 ) * lineSpacing;
1480 startPos.x -= totalWidth;
1481 }
1482 else if( aAttrs.m_Halign == GR_TEXT_H_ALIGN_CENTER )
1483 {
1484 int totalWidth = ( (int) lines.size() - 1 ) * lineSpacing;
1485 startPos.x -= totalWidth / 2.0;
1486 }
1487
1488 for( size_t i = 0; i < lines.size(); i++ )
1489 {
1490 VECTOR2D linePos = startPos;
1491 linePos.x += (int) i * lineSpacing;
1492
1493 wxString line = lines[i];
1494 line.Trim( true ).Trim( false );
1495
1496 boxText( aGal, line, linePos, aAttrs, aFontMetrics );
1497 }
1498 }
1499 else
1500 {
1501 // For horizontal text, lines are spaced vertically
1502 if( aAttrs.m_Valign == GR_TEXT_V_ALIGN_BOTTOM )
1503 {
1504 int totalHeight = ( (int) lines.size() - 1 ) * lineSpacing;
1505 startPos.y -= totalHeight;
1506 }
1507 else if( aAttrs.m_Valign == GR_TEXT_V_ALIGN_CENTER )
1508 {
1509 int totalHeight = ( (int) lines.size() - 1 ) * lineSpacing;
1510 startPos.y -= totalHeight / 2.0;
1511 }
1512
1513 for( size_t i = 0; i < lines.size(); i++ )
1514 {
1515 VECTOR2D linePos = startPos;
1516 linePos.y += (int) i * lineSpacing;
1517
1518 wxString line = lines[i];
1519 line.Trim( true ).Trim( false );
1520
1521 boxText( aGal, line, linePos, aAttrs, aFontMetrics );
1522 }
1523 }
1524
1525 drawBracesAroundText( aGal, lines, startPos, lineSpacing, aAttrs );
1526 return;
1527 }
1528 }
1529
1530 boxText( aGal, aText, aPosition, aAttrs, aFontMetrics );
1531 };
1532
1533 const auto drawMultiLineBitmapText =
1534 [&]( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
1535 const TEXT_ATTRIBUTES& aAttrs )
1536 {
1537 // Similar to drawMultiLineText but uses bitmapText
1538 if( aText.StartsWith( "[" ) && aText.EndsWith( "]" ) && aText.Contains( "\n" ) )
1539 {
1540 wxString content = aText.Mid( 1, aText.Length() - 2 );
1541 wxArrayString lines;
1542 wxStringSplit( content, lines, '\n' );
1543
1544 if( lines.size() > 1 )
1545 {
1546 int lineSpacing = KiROUND( aAttrs.m_Size.y * 1.3 );
1547 VECTOR2D startPos = aPosition;
1548
1549 if( aAttrs.m_Angle == ANGLE_VERTICAL )
1550 {
1551 // For vertical text, lines are spaced horizontally
1552 if( aAttrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT )
1553 {
1554 int totalWidth = ( (int) lines.size() - 1 ) * lineSpacing;
1555 startPos.x -= totalWidth;
1556 }
1557 else if( aAttrs.m_Halign == GR_TEXT_H_ALIGN_CENTER )
1558 {
1559 int totalWidth = ( (int) lines.size() - 1 ) * lineSpacing;
1560 startPos.x -= totalWidth / 2.0;
1561 }
1562
1563 for( size_t i = 0; i < lines.size(); i++ )
1564 {
1565 VECTOR2D linePos = startPos;
1566 linePos.x += (int) i * lineSpacing;
1567
1568 wxString line = lines[i];
1569 line.Trim( true ).Trim( false );
1570
1571 bitmapText( aGal, line, linePos, aAttrs );
1572 }
1573 }
1574 else
1575 {
1576 // For horizontal text, lines are spaced vertically
1577 if( aAttrs.m_Valign == GR_TEXT_V_ALIGN_BOTTOM )
1578 {
1579 int totalHeight = ( (int) lines.size() - 1 ) * lineSpacing;
1580 startPos.y -= totalHeight;
1581 }
1582 else if( aAttrs.m_Valign == GR_TEXT_V_ALIGN_CENTER )
1583 {
1584 int totalHeight = ( (int) lines.size() - 1 ) * lineSpacing;
1585 startPos.y -= totalHeight / 2.0;
1586 }
1587
1588 for( size_t i = 0; i < lines.size(); i++ )
1589 {
1590 VECTOR2D linePos = startPos;
1591 linePos.y += (int) i * lineSpacing;
1592
1593 wxString line = lines[i];
1594 line.Trim( true ).Trim( false );
1595
1596 bitmapText( aGal, line, linePos, aAttrs );
1597 }
1598 }
1599
1600 // Draw braces with bitmap text (simplified version)
1601 drawBracesAroundTextBitmap( aGal, lines, startPos, lineSpacing, aAttrs );
1602 return;
1603 }
1604 }
1605
1606 bitmapText( aGal, aText, aPosition, aAttrs );
1607 };
1608
1609 const auto drawTextInfo =
1610 [&]( const PIN_LAYOUT_CACHE::TEXT_INFO& aTextInfo, const COLOR4D& aColor )
1611 {
1612 // const double iconSize = std::min( aPin->GetNameTextSize(), schIUScale.mmToIU( 1.5 ) );
1613 const bool renderTextAsBitmap = textRendersAsBitmap( *m_gal, aTextInfo.m_TextSize );
1614
1615 // Which of these gets used depends on the font technology, so set both
1616 m_gal->SetStrokeColor( aColor );
1617 m_gal->SetFillColor( aColor );
1618
1619 TEXT_ATTRIBUTES attrs;
1620 attrs.m_Font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font );
1621 attrs.m_Size = VECTOR2I( aTextInfo.m_TextSize, aTextInfo.m_TextSize );
1622 attrs.m_Halign = aTextInfo.m_HAlign;
1623 attrs.m_Valign = aTextInfo.m_VAlign;
1624 attrs.m_Angle = aTextInfo.m_Angle;
1625 attrs.m_StrokeWidth = aTextInfo.m_Thickness;
1626
1627 if( drawingShadows )
1628 {
1629 attrs.m_StrokeWidth += KiROUND( shadowWidth );
1630
1631 if( !attrs.m_Font->IsOutline() )
1632 {
1633 drawMultiLineText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs,
1634 aPin->GetFontMetrics() );
1635 }
1636 else
1637 {
1638 boxMultiLineText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs,
1639 aPin->GetFontMetrics() );
1640 }
1641 }
1642 else if( nonCached( aPin ) && renderTextAsBitmap )
1643 {
1644 drawMultiLineBitmapText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs );
1645 const_cast<SCH_PIN*>( aPin )->SetFlags( IS_SHOWN_AS_BITMAP );
1646 }
1647 else
1648 {
1649 drawMultiLineText( *m_gal, aTextInfo.m_Text, aTextInfo.m_TextPosition, attrs,
1650 aPin->GetFontMetrics() );
1651 const_cast<SCH_PIN*>( aPin )->SetFlags( IS_SHOWN_AS_BITMAP );
1652 }
1653 };
1654
1655 const auto getColorForLayer =
1656 [&]( int aDrawnLayer )
1657 {
1658 if( !aPin->IsVisible() )
1659 return getRenderColor( aPin, LAYER_HIDDEN, drawingShadows, aDimmed );
1660
1661 return getRenderColor( aPin, aDrawnLayer, drawingShadows, aDimmed );
1662 };
1663
1664 // Request text layout info and draw it
1665
1666 if( std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> numInfo = cache.GetPinNumberInfo( shadowWidth ) )
1667 drawTextInfo( *numInfo, getColorForLayer( LAYER_PINNUM ) );
1668
1669 if( std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> nameInfo = cache.GetPinNameInfo( shadowWidth ) )
1670 {
1671 drawTextInfo( *nameInfo, getColorForLayer( LAYER_PINNAM ) );
1672
1673 if( OPT_BOX2I altIconBox = cache.GetAltIconBBox() )
1674 {
1675 drawAltPinModesIcon( *m_gal, altIconBox->GetCenter(), altIconBox->GetWidth(),
1676 // Icon style doesn't work due to the tempPin having no alt
1677 // but maybe it's better with just one style anyway.
1678 true, nameInfo->m_Angle == ANGLE_VERTICAL, shadowWidth,
1679 getColorForLayer( LAYER_PINNAM ) );
1680 }
1681 }
1682
1683 if( std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> elecTypeInfo = cache.GetPinElectricalTypeInfo( shadowWidth ) )
1684 drawTextInfo( *elecTypeInfo, getColorForLayer( LAYER_PRIVATE_NOTES ) );
1685}
1686
1687
1688void SCH_PAINTER::drawAnchor( const VECTOR2I& aPos, bool aDrawingShadows )
1689{
1690 if( m_schSettings.IsPrinting() )
1691 return;
1692
1693 // In order for the anchors to be visible but unobtrusive, their size must factor in the
1694 // current zoom level.
1695 const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
1696 int radius = KiROUND( std::fabs( matrix.GetScale().x * TEXT_ANCHOR_SIZE ) / 25.0 )
1697 + schIUScale.MilsToIU( TEXT_ANCHOR_SIZE );
1698
1699 COLOR4D color = aDrawingShadows ? m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS )
1700 : m_schSettings.GetLayerColor( LAYER_SCHEMATIC_ANCHOR );
1701
1702 m_gal->SetStrokeColor( color );
1703 m_gal->SetIsStroke( true );
1704 m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth( false )
1705 : m_schSettings.GetDanglingIndicatorThickness() );
1706
1707 m_gal->DrawLine( aPos - VECTOR2I( radius, 0 ), aPos + VECTOR2I( radius, 0 ) );
1708 m_gal->DrawLine( aPos - VECTOR2I( 0, radius ), aPos + VECTOR2I( 0, radius ) );
1709}
1710
1711
1712void SCH_PAINTER::drawDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor, int aWidth,
1713 bool aDangling, bool aDrawingShadows, bool aBrightened )
1714{
1715 if( m_schSettings.IsPrinting() )
1716 return;
1717
1718 int size = aDangling ? DANGLING_SYMBOL_SIZE : UNSELECTED_END_SIZE;
1719
1720 if( !aDangling )
1721 aWidth /= 2;
1722
1723 VECTOR2I radius( aWidth + schIUScale.MilsToIU( size / 2 ),
1724 aWidth + schIUScale.MilsToIU( size / 2 ) );
1725
1726 // Dangling symbols must be drawn in a slightly different colour so they can be seen when
1727 // they overlap with a junction dot.
1728 m_gal->SetStrokeColor( aColor.Brightened( 0.3 ) );
1729 m_gal->SetIsStroke( true );
1730 m_gal->SetIsFill( false );
1731 m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth( aBrightened )
1732 : m_schSettings.GetDanglingIndicatorThickness() );
1733
1734 m_gal->DrawRectangle( aPos - radius, aPos + radius );
1735}
1736
1737
1738void SCH_PAINTER::draw( const SCH_JUNCTION* aJct, int aLayer )
1739{
1740 bool highlightNetclassColors = false;
1741 EESCHEMA_SETTINGS* eeschemaCfg = eeconfig();
1742
1743 if( eeschemaCfg )
1744 {
1745 highlightNetclassColors = eeschemaCfg->m_Selection.highlight_netclass_colors;
1746 }
1747
1748 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1749
1750 if( m_schSettings.IsPrinting() && drawingShadows )
1751 return;
1752
1753 if( drawingShadows && !( aJct->IsBrightened() || aJct->IsSelected() ) )
1754 return;
1755
1756 COLOR4D color;
1757
1758 if( highlightNetclassColors && aLayer == aJct->GetLayer() )
1759 color = m_schSettings.GetLayerColor( aJct->GetLayer() );
1760 else
1761 color = getRenderColor( aJct, aJct->GetLayer(), drawingShadows );
1762
1763 int junctionSize = aJct->GetEffectiveDiameter() / 2;
1764
1765 if( junctionSize > 1 )
1766 {
1767 m_gal->SetIsStroke( drawingShadows );
1768 m_gal->SetLineWidth( getLineWidth( aJct, drawingShadows ) );
1769 m_gal->SetStrokeColor( color );
1770 m_gal->SetIsFill( !drawingShadows );
1771 m_gal->SetFillColor( color );
1772 m_gal->DrawCircle( aJct->GetPosition(), junctionSize );
1773 }
1774}
1775
1776
1777void SCH_PAINTER::draw( const SCH_LINE* aLine, int aLayer )
1778{
1779 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1780 bool drawingNetColorHighlights = aLayer == LAYER_NET_COLOR_HIGHLIGHT;
1781 bool drawingWires = aLayer == LAYER_WIRE;
1782 bool drawingBusses = aLayer == LAYER_BUS;
1783 bool drawingDangling = aLayer == LAYER_DANGLING;
1784 bool drawingOP = aLayer == LAYER_OP_VOLTAGES;
1785
1786 bool highlightNetclassColors = false;
1787 double highlightAlpha = 0.6;
1788 EESCHEMA_SETTINGS* eeschemaCfg = eeconfig();
1789 double hopOverScale = 0.0;
1790 int defaultLineWidth = schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
1791
1792 if( aLine->Schematic() ) // Can be nullptr when run from the color selection panel
1793 {
1794 hopOverScale = aLine->Schematic()->Settings().m_HopOverScale;
1795 defaultLineWidth = aLine->Schematic()->Settings().m_DefaultLineWidth;
1796 }
1797
1798 if( eeschemaCfg )
1799 {
1800 highlightNetclassColors = eeschemaCfg->m_Selection.highlight_netclass_colors;
1801 highlightAlpha = eeschemaCfg->m_Selection.highlight_netclass_colors_alpha;
1802 }
1803
1804 if( !highlightNetclassColors && drawingNetColorHighlights )
1805 return;
1806
1807 if( drawingNetColorHighlights && !( aLine->IsWire() || aLine->IsBus() ) )
1808 return;
1809
1810 if( m_schSettings.m_OverrideItemColors && drawingNetColorHighlights )
1811 return;
1812
1813 if( m_schSettings.IsPrinting() && drawingShadows )
1814 return;
1815
1816 if( drawingShadows && !( aLine->IsBrightened() || aLine->IsSelected() ) )
1817 return;
1818
1819 // Line end dangling status isn't updated until the line is finished drawing, so don't warn
1820 // them about ends that are probably connected
1821 if( aLine->IsNew() && drawingDangling )
1822 return;
1823
1824 COLOR4D color = getRenderColor( aLine, aLine->GetLayer(), drawingShadows );
1825 float width = getLineWidth( aLine, drawingShadows, drawingNetColorHighlights );
1826 LINE_STYLE lineStyle = aLine->GetEffectiveLineStyle();
1827
1828 if( highlightNetclassColors )
1829 {
1830 // Force default color for nets we are going to highlight
1831 if( drawingWires )
1832 color = m_schSettings.GetLayerColor( LAYER_WIRE );
1833 else if( drawingBusses )
1834 color = m_schSettings.GetLayerColor( LAYER_BUS );
1835 }
1836
1837 if( drawingNetColorHighlights )
1838 {
1839 // Don't draw highlights for default-colored nets
1840 if( ( aLine->IsWire() && color == m_schSettings.GetLayerColor( LAYER_WIRE ) )
1841 || ( aLine->IsBus() && color == m_schSettings.GetLayerColor( LAYER_BUS ) ) )
1842 {
1843 return;
1844 }
1845
1846 color = color.WithAlpha( color.a * highlightAlpha );
1847 }
1848
1849 if( ( drawingDangling || drawingShadows ) && !aLine->IsNew() )
1850 {
1851 if( ( aLine->IsWire() && aLine->IsStartDangling() )
1852 || ( drawingShadows && aLine->IsSelected() && !aLine->HasFlag( STARTPOINT ) ) )
1853 {
1854 COLOR4D indicatorColor( color );
1855
1856 if( drawingShadows && !aLine->HasFlag( STARTPOINT ) )
1857 indicatorColor.Invert();
1858
1859 drawDanglingIndicator( aLine->GetStartPoint(), indicatorColor, KiROUND( width ),
1860 aLine->IsWire() && aLine->IsStartDangling(), drawingShadows,
1861 aLine->IsBrightened() );
1862 }
1863
1864 if( ( aLine->IsWire() && aLine->IsEndDangling() )
1865 || ( drawingShadows && aLine->IsSelected() && !aLine->HasFlag( ENDPOINT ) ) )
1866 {
1867 COLOR4D indicatorColor( color );
1868
1869 if( drawingShadows && !aLine->HasFlag( ENDPOINT ) )
1870 indicatorColor.Invert();
1871
1872 drawDanglingIndicator( aLine->GetEndPoint(), indicatorColor, KiROUND( width ),
1873 aLine->IsWire() && aLine->IsEndDangling(), drawingShadows,
1874 aLine->IsBrightened() );
1875 }
1876 }
1877
1878 if( drawingDangling )
1879 return;
1880
1881 if( drawingOP && !aLine->GetOperatingPoint().IsEmpty() )
1882 {
1883 int textSize = getOperatingPointTextSize();
1884 VECTOR2I pos = aLine->GetMidPoint();
1885 int textOffset = KiROUND( textSize * 0.22 );
1886 TEXT_ATTRIBUTES attrs;
1887
1888 if( aLine->GetStartPoint().y == aLine->GetEndPoint().y )
1889 {
1890 pos.y -= textOffset;
1893 }
1894 else
1895 {
1896 pos.x += KiROUND( textOffset * 1.2 );
1899 }
1900
1901 attrs.m_Font = KIFONT::FONT::GetFont(); // always use stroke font for performance
1902 attrs.m_Size = VECTOR2I( textSize, textSize );
1903 attrs.m_StrokeWidth = GetPenSizeForDemiBold( textSize );
1904 attrs.m_Color = m_schSettings.GetLayerColor( LAYER_OP_VOLTAGES );
1905
1906 knockoutText( *m_gal, aLine->GetOperatingPoint(), pos, attrs, aLine->GetFontMetrics() );
1907 }
1908
1909 if( drawingOP )
1910 return;
1911
1912 m_gal->SetIsStroke( true );
1913 m_gal->SetIsFill( false );
1914 m_gal->SetStrokeColor( color );
1915 m_gal->SetLineWidth( width );
1916
1917 std::vector<VECTOR3I> curr_wire_shape;
1918
1919 if( aLine->IsWire() && hopOverScale > 0.0 )
1920 {
1921 double arcRadius = defaultLineWidth * hopOverScale;
1922 curr_wire_shape = aLine->BuildWireWithHopShape( m_schematic->GetCurrentScreen(), arcRadius );
1923 }
1924 else
1925 {
1926 curr_wire_shape.emplace_back( aLine->GetStartPoint().x, aLine->GetStartPoint().y, 0 );
1927 curr_wire_shape.emplace_back( aLine->GetEndPoint().x, aLine->GetEndPoint().y, 0 );
1928 }
1929
1930 for( size_t ii = 1; ii < curr_wire_shape.size(); ii++ )
1931 {
1932 VECTOR2I start( curr_wire_shape[ii-1].x, curr_wire_shape[ii-1].y );
1933
1934 if( curr_wire_shape[ii-1].z == 0 ) // This is the start point of a segment
1935 // there are always 2 points in list for a segment
1936 {
1937 VECTOR2I end( curr_wire_shape[ii].x, curr_wire_shape[ii].y );
1938 drawLine( start, end, lineStyle, ( lineStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows ), width );
1939 }
1940 else // This is the start point of a arc. there are always 3 points in list for an arc
1941 {
1942 // Hop are a small arc, so use a solid line style gives best results
1943 VECTOR2I arc_middle( curr_wire_shape[ii].x, curr_wire_shape[ii].y );
1944 ii++;
1945 VECTOR2I arc_end( curr_wire_shape[ii].x, curr_wire_shape[ii].y );
1946 ii++;
1947
1948 VECTOR2D dstart = start;
1949 VECTOR2D dmid = arc_middle;
1950 VECTOR2D dend = arc_end;
1951 VECTOR2D center = CalcArcCenter( dstart, dmid, dend );
1952
1953 EDA_ANGLE startAngle( dstart - center );
1954 EDA_ANGLE midAngle( dmid - center );
1955 EDA_ANGLE endAngle( dend - center );
1956
1957 EDA_ANGLE angle1 = midAngle - startAngle;
1958 EDA_ANGLE angle2 = endAngle - midAngle;
1959
1960 EDA_ANGLE angle = angle1.Normalize180() + angle2.Normalize180();
1961
1962 m_gal->DrawArc( center, ( dstart - center ).EuclideanNorm(), startAngle, angle );
1963 }
1964 }
1965}
1966
1967
1968void SCH_PAINTER::draw( const SCH_SHAPE* aShape, int aLayer, bool aDimmed )
1969{
1970 if( !isUnitAndConversionShown( aShape ) )
1971 return;
1972
1973 if( aShape->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
1974 return;
1975
1976 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1977
1978 if( m_schSettings.IsPrinting() && drawingShadows )
1979 return;
1980
1981 LINE_STYLE lineStyle = aShape->GetEffectiveLineStyle();
1982 COLOR4D color = getRenderColor( aShape, aLayer, drawingShadows, aDimmed );
1983
1984 if( drawingShadows && !( aShape->IsBrightened() || aShape->IsSelected() ) )
1985 return;
1986
1987 auto drawShape =
1988 [&]( const SCH_SHAPE* shape )
1989 {
1990 switch( shape->GetShape() )
1991 {
1992 case SHAPE_T::ARC:
1993 {
1994 VECTOR2D start = shape->GetStart();
1995 VECTOR2D mid = shape->GetArcMid();
1996 VECTOR2D end = shape->GetEnd();
1997 VECTOR2D center = CalcArcCenter( start, mid, end );
1998
1999 EDA_ANGLE startAngle( start - center );
2000 EDA_ANGLE midAngle( mid - center );
2001 EDA_ANGLE endAngle( end - center );
2002
2003 EDA_ANGLE angle1 = midAngle - startAngle;
2004 EDA_ANGLE angle2 = endAngle - midAngle;
2005
2006 EDA_ANGLE angle = angle1.Normalize180() + angle2.Normalize180();
2007
2008 m_gal->DrawArc( center, ( start - center ).EuclideanNorm(), startAngle, angle );
2009 break;
2010 }
2011
2012 case SHAPE_T::CIRCLE:
2013 m_gal->DrawCircle( shape->GetPosition(), shape->GetRadius() );
2014 break;
2015
2016 case SHAPE_T::RECTANGLE:
2017 if( shape->GetCornerRadius() > 0 )
2018 {
2019 // Creates a normalized ROUNDRECT item
2020 // (GetRectangleWidth() and GetRectangleHeight() can be < 0 with transforms
2021 ROUNDRECT rr( SHAPE_RECT( shape->GetPosition(),
2022 shape->GetRectangleWidth(),
2023 shape->GetRectangleHeight() ),
2024 shape->GetCornerRadius(), true /* normalize */ );
2025 SHAPE_POLY_SET poly;
2026 rr.TransformToPolygon( poly, shape->GetMaxError() );
2027 m_gal->DrawPolygon( poly );
2028 }
2029 else
2030 {
2031 m_gal->DrawRectangle( shape->GetPosition(), shape->GetEnd() );
2032 }
2033 break;
2034
2035 case SHAPE_T::POLY:
2036 {
2037 const std::vector<SHAPE*> polySegments = shape->MakeEffectiveShapes( true );
2038
2039 if( !polySegments.empty() )
2040 {
2041 std::deque<VECTOR2D> pts;
2042
2043 for( SHAPE* polySegment : polySegments )
2044 pts.push_back( static_cast<SHAPE_SEGMENT*>( polySegment )->GetSeg().A );
2045
2046 pts.push_back( static_cast<SHAPE_SEGMENT*>( polySegments.back() )->GetSeg().B );
2047
2048 for( SHAPE* polySegment : polySegments )
2049 delete polySegment;
2050
2051 m_gal->DrawPolygon( pts );
2052 }
2053 break;
2054 }
2055
2056 case SHAPE_T::BEZIER:
2057 {
2058 m_gal->DrawCurve( shape->GetStart(), shape->GetBezierC1(),
2059 shape->GetBezierC2(), shape->GetEnd() );
2060 break;
2061 }
2062
2063 default:
2064 UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
2065 }
2066 };
2067
2068 if( aLayer == LAYER_SELECTION_SHADOWS )
2069 {
2070 if( eeconfig()->m_Selection.fill_shapes )
2071 {
2072 // Consider a NAND gate. We have no idea which side of the arc is "inside"
2073 // so we can't reliably fill.
2074 if( aShape->GetShape() == SHAPE_T::ARC )
2075 m_gal->SetIsFill( aShape->IsSolidFill() );
2076 else
2077 m_gal->SetIsFill( true );
2078
2079 m_gal->SetFillColor( color );
2080 }
2081 else
2082 {
2083 m_gal->SetIsFill( false );
2084 }
2085
2086 // We still always draw the stroke, as otherwise single-segment shapes
2087 // (like a line) don't get a shadow, and special-casing them looks inconsistent.
2088 m_gal->SetIsStroke( true );
2089 m_gal->SetLineWidth( getLineWidth( aShape, true ) );
2090 m_gal->SetStrokeColor( color );
2091
2092 drawShape( aShape );
2093 }
2094 else if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_NOTES_BACKGROUND
2095 || aLayer == LAYER_SHAPES_BACKGROUND )
2096 {
2097 switch( aShape->GetFillMode() )
2098 {
2099 case FILL_T::NO_FILL:
2100 break;
2101
2103 // Fill in the foreground layer
2104 break;
2105
2106 case FILL_T::HATCH:
2109 aShape->UpdateHatching();
2110 m_gal->SetIsFill( false );
2111 m_gal->SetIsStroke( true );
2112 m_gal->SetStrokeColor( color );
2113 m_gal->SetLineWidth( aShape->GetHatchLineWidth() );
2114
2115 for( const SEG& seg : aShape->GetHatchLines() )
2116 m_gal->DrawLine( seg.A, seg.B );
2117
2118 break;
2119
2122 // Do not fill the shape in B&W print mode, to avoid to visible items inside the shape
2123 if( !m_schSettings.PrintBlackAndWhiteReq() )
2124 {
2125 m_gal->SetIsFill( true );
2126 m_gal->SetIsStroke( false );
2127 m_gal->SetFillColor( color );
2128
2129 drawShape( aShape );
2130 }
2131 break;
2132
2133 default:
2134 wxFAIL_MSG( wxT( "Unsupported fill type" ) );
2135 }
2136 }
2137 else if( aLayer == LAYER_DEVICE || aLayer == LAYER_NOTES || aLayer == LAYER_PRIVATE_NOTES
2138 || aLayer == LAYER_RULE_AREAS )
2139 {
2140 // Shapes filled with the device colour must be filled in the foreground
2141 if( aShape->GetFillMode() == FILL_T::FILLED_SHAPE )
2142 {
2143 m_gal->SetIsFill( true );
2144 m_gal->SetIsStroke( false );
2145 m_gal->SetFillColor( color );
2146
2147 drawShape( aShape );
2148 }
2149
2150 float lineWidth = getLineWidth( aShape, drawingShadows );
2151
2152 if( lineWidth > 0 )
2153 {
2154 m_gal->SetIsFill( false );
2155 m_gal->SetIsStroke( true );
2156 m_gal->SetLineWidth( lineWidth );
2157 m_gal->SetStrokeColor( color );
2158
2159 if( lineStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows )
2160 {
2161 drawShape( aShape );
2162 }
2163 else
2164 {
2165 std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
2166
2167 for( SHAPE* shape : shapes )
2168 {
2169 STROKE_PARAMS::Stroke( shape, lineStyle, KiROUND( lineWidth ), &m_schSettings,
2170 [this]( const VECTOR2I& a, const VECTOR2I& b )
2171 {
2172 // DrawLine has problem with 0 length lines so enforce minimum
2173 if( a == b )
2174 m_gal->DrawLine( a+1, b );
2175 else
2176 m_gal->DrawLine( a, b );
2177 } );
2178 }
2179
2180 for( SHAPE* shape : shapes )
2181 delete shape;
2182 }
2183 }
2184 }
2185}
2186
2187
2188void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed )
2189{
2190 if( !isUnitAndConversionShown( aText ) )
2191 return;
2192
2193 if( aText->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2194 return;
2195
2196 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2197
2198 if( m_schSettings.IsPrinting() && drawingShadows )
2199 return;
2200
2201 if( drawingShadows && !( aText->IsBrightened() || aText->IsSelected() ) )
2202 return;
2203
2204 switch( aText->Type() )
2205 {
2206 case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break;
2207 case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break;
2208 case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break;
2209 case SCH_DIRECTIVE_LABEL_T: aLayer = LAYER_NETCLASS_REFS; break;
2210 case SCH_LABEL_T: aLayer = LAYER_LOCLABEL; break;
2211 case SCH_TEXT_T: aLayer = aText->GetParentSymbol() ? LAYER_DEVICE
2212 : LAYER_NOTES; break;
2213 default: aLayer = LAYER_NOTES; break;
2214 }
2215
2216 COLOR4D color = getRenderColor( aText, aLayer, drawingShadows, aDimmed );
2217
2218 if( m_schematic )
2219 {
2220 SCH_CONNECTION* conn = nullptr;
2221
2222 if( !aText->IsConnectivityDirty() )
2223 conn = aText->Connection();
2224
2225 if( conn && conn->IsBus() )
2226 color = getRenderColor( aText, LAYER_BUS, drawingShadows );
2227 }
2228
2229 if( !( aText->IsVisible() || aText->IsForceVisible() ) )
2230 {
2231 if( m_schSettings.m_IsSymbolEditor || eeconfig()->m_Appearance.show_hidden_fields )
2232 color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
2233 else
2234 return;
2235 }
2236
2237 m_gal->SetStrokeColor( color );
2238 m_gal->SetFillColor( color );
2239 m_gal->SetHoverColor( color );
2240
2241 wxString shownText( aText->GetShownText( true ) );
2242 VECTOR2I text_offset = aText->GetSchematicTextOffset( &m_schSettings );
2243 TEXT_ATTRIBUTES attrs = aText->GetAttributes();
2244 KIFONT::FONT* font = getFont( aText );
2245
2246 attrs.m_Angle = aText->GetDrawRotation();
2247 attrs.m_StrokeWidth = KiROUND( getTextThickness( aText ) );
2248
2249 if( drawingShadows && font->IsOutline() )
2250 {
2251 // Trying to draw glyph-shaped shadows on outline text is a fool's errand. Just box it.
2252 // Use GetBoundingBox() which correctly handles multiline text dimensions.
2253 BOX2I bbox = aText->GetBoundingBox();
2254
2255 bbox.Inflate( attrs.m_StrokeWidth / 2, attrs.m_StrokeWidth * 2 );
2256
2257 m_gal->SetIsFill( true );
2258 m_gal->SetIsStroke( false );
2259 m_gal->DrawRectangle( bbox.GetOrigin(), bbox.GetEnd() );
2260 }
2261 else if( aText->GetLayer() == LAYER_DEVICE )
2262 {
2263 BOX2I bBox = aText->GetBoundingBox();
2264 VECTOR2D pos = bBox.Centre();
2265
2266 // Due to the fact a shadow text can be drawn left or right aligned, it needs to be
2267 // offset by shadowWidth/2 to be drawn at the same place as normal text.
2268 double shadowOffset = 0.0;
2269
2270 if( drawingShadows )
2271 {
2272 double shadowWidth = getShadowWidth( !aText->IsSelected() );
2273 attrs.m_StrokeWidth += getShadowWidth( !aText->IsSelected() );
2274
2275 const double adjust = 1.2f; // Value chosen after tests
2276 shadowOffset = shadowWidth/2.0f * adjust;
2277 }
2278
2279 if( attrs.m_Angle == ANGLE_VERTICAL )
2280 {
2281 switch( attrs.m_Halign )
2282 {
2284 pos.y = bBox.GetBottom() + shadowOffset;
2285 break;
2287 pos.y = ( bBox.GetTop() + bBox.GetBottom() ) / 2.0;
2288 break;
2290 pos.y = bBox.GetTop() - shadowOffset;
2291 break;
2293 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
2294 break;
2295 }
2296 }
2297 else
2298 {
2299 switch( attrs.m_Halign )
2300 {
2302 pos.x = bBox.GetLeft() - shadowOffset;
2303 break;
2305 pos.x = ( bBox.GetLeft() + bBox.GetRight() ) / 2.0;
2306 break;
2308 pos.x = bBox.GetRight() + shadowOffset;
2309 break;
2311 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
2312 break;
2313 }
2314 }
2315
2316 // Because the text vertical position is the bounding box center, the text is drawn as
2317 // vertically centered.
2319
2320 strokeText( *m_gal, shownText, pos, attrs, aText->GetFontMetrics() );
2321 }
2322 else if( drawingShadows )
2323 {
2324 m_gal->SetIsFill( false );
2325 m_gal->SetIsStroke( true );
2326 attrs.m_StrokeWidth += KiROUND( getShadowWidth( !aText->IsSelected() ) );
2327 attrs.m_Underlined = false;
2328
2329 // Fudge factors to match 6.0 positioning
2330 // New text stroking has width dependent offset but we need to center the shadow on the
2331 // stroke. NB this offset is in font.cpp also.
2332 int fudge = KiROUND( getShadowWidth( !aText->IsSelected() ) / 1.52 );
2333
2334 if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_0 )
2335 text_offset.x -= fudge;
2336 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_90 )
2337 text_offset.y -= fudge;
2338 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_0 )
2339 text_offset.x += fudge;
2340 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_90 )
2341 text_offset.y += fudge;
2342
2343 strokeText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs, aText->GetFontMetrics() );
2344 }
2345 else
2346 {
2347 wxString activeUrl;
2348
2349 if( aText->IsRollover() && !aText->IsMoving() )
2350 {
2351 // Highlight any urls found within the text
2352 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2353
2354 // Highlight the whole text if it has a link definition
2355 if( aText->HasHyperlink() )
2356 {
2357 attrs.m_Hover = true;
2358 attrs.m_Underlined = true;
2359 activeUrl = aText->GetHyperlink();
2360 }
2361 }
2362
2363 if( aText->Type() == SCH_TEXT_T )
2364 text_offset += aText->GetOffsetToMatchSCH_FIELD( nullptr );
2365
2366 if( nonCached( aText ) && aText->RenderAsBitmap( m_gal->GetWorldScale() )
2367 && !shownText.Contains( wxT( "\n" ) ) )
2368 {
2369 bitmapText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs );
2370 const_cast<SCH_TEXT*>( aText )->SetFlags( IS_SHOWN_AS_BITMAP );
2371 }
2372 else
2373 {
2374 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2375
2376 if( !aText->IsRollover() && font->IsOutline() )
2377 cache = aText->GetRenderCache( font, shownText, text_offset );
2378
2379 if( cache )
2380 {
2381 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2382 m_gal->DrawGlyphs( *cache );
2383 }
2384 else
2385 {
2386 strokeText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs,
2387 aText->GetFontMetrics(), aText->GetRolloverPos(), &activeUrl );
2388 }
2389
2390 const_cast<SCH_TEXT*>( aText )->ClearFlags( IS_SHOWN_AS_BITMAP );
2391 }
2392
2393 aText->SetActiveUrl( activeUrl );
2394 }
2395
2396 // Draw anchor
2397 if( aText->IsSelected() )
2398 {
2399 bool showAnchor;
2400
2401 switch( aText->Type() )
2402 {
2403 case SCH_TEXT_T:
2404 showAnchor = true;
2405 break;
2406
2407 case SCH_LABEL_T:
2408 // Don't clutter things up if we're already showing a dangling indicator
2409 showAnchor = !static_cast<const SCH_LABEL*>( aText )->IsDangling();
2410 break;
2411
2413 case SCH_HIER_LABEL_T:
2414 case SCH_GLOBAL_LABEL_T:
2415 case SCH_SHEET_PIN_T:
2416 // These all have shapes and so don't need anchors
2417 showAnchor = false;
2418 break;
2419
2420 default:
2421 showAnchor = false;
2422 break;
2423 }
2424
2425 if( showAnchor )
2426 drawAnchor( aText->GetPosition(), drawingShadows );
2427 }
2428}
2429
2430
2431void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer, bool aDimmed )
2432{
2433 if( aTextBox->Type() == SCH_TABLECELL_T )
2434 {
2435 const SCH_TABLECELL* cell = static_cast<const SCH_TABLECELL*>( aTextBox );
2436
2437 if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
2438 return;
2439 }
2440
2441 if( !isUnitAndConversionShown( aTextBox ) )
2442 return;
2443
2444 if( aTextBox->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2445 return;
2446
2447 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2448
2449 if( m_schSettings.IsPrinting() && drawingShadows )
2450 return;
2451
2452 COLOR4D color = getRenderColor( aTextBox, aLayer, drawingShadows, aDimmed );
2453 COLOR4D bg = m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
2454 float borderWidth = getLineWidth( aTextBox, drawingShadows );
2455 KIFONT::FONT* font = getFont( aTextBox );
2456
2457 auto drawText =
2458 [&]()
2459 {
2460 wxString shownText = aTextBox->GetShownText( true );
2461 TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes();
2462 wxString activeUrl;
2463
2464 attrs.m_Angle = aTextBox->GetDrawRotation();
2465 attrs.m_StrokeWidth = KiROUND( getTextThickness( aTextBox ) );
2466
2467 if( aTextBox->IsRollover() && !aTextBox->IsMoving() )
2468 {
2469 // Highlight any urls found within the text
2470 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2471
2472 // Highlight the whole text if it has a link definition
2473 if( aTextBox->HasHyperlink() )
2474 {
2475 attrs.m_Hover = true;
2476 attrs.m_Underlined = true;
2477 activeUrl = aTextBox->GetHyperlink();
2478 }
2479 }
2480
2481 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2482
2483 if( !aTextBox->IsRollover() && font->IsOutline() )
2484 cache = aTextBox->GetRenderCache( font, shownText );
2485
2486 if( cache )
2487 {
2488 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2489 m_gal->DrawGlyphs( *cache );
2490 }
2491 else
2492 {
2493 strokeText( *m_gal, shownText, aTextBox->GetDrawPos(), attrs,
2494 aTextBox->GetFontMetrics(), aTextBox->GetRolloverPos(), &activeUrl );
2495 }
2496
2497 aTextBox->SetActiveUrl( activeUrl );
2498 };
2499
2500 if( drawingShadows && !( aTextBox->IsBrightened() || aTextBox->IsSelected() ) )
2501 return;
2502
2503 m_gal->SetFillColor( color );
2504 m_gal->SetStrokeColor( color );
2505 m_gal->SetHoverColor( color );
2506
2507 if( aLayer == LAYER_SELECTION_SHADOWS )
2508 {
2509 m_gal->SetIsFill( true );
2510 m_gal->SetIsStroke( false );
2511 m_gal->SetLineWidth( borderWidth );
2512
2513 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2514 }
2515 else if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_NOTES_BACKGROUND
2516 || aLayer == LAYER_SHAPES_BACKGROUND )
2517 {
2518 // Do not fill the shape in B&W print mode, to avoid to visible items
2519 // inside the shape
2520 if( aTextBox->IsSolidFill() && !m_schSettings.PrintBlackAndWhiteReq() )
2521 {
2522 m_gal->SetIsFill( true );
2523 m_gal->SetIsStroke( false );
2524 m_gal->SetLineWidth( borderWidth );
2525
2526 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2527 }
2528 }
2529 else if( aLayer == LAYER_DEVICE || aLayer == LAYER_NOTES || aLayer == LAYER_PRIVATE_NOTES )
2530 {
2531 drawText();
2532
2533 if( aTextBox->Type() != SCH_TABLECELL_T && borderWidth > 0 )
2534 {
2535 COLOR4D borderColor = aTextBox->GetStroke().GetColor();
2536 LINE_STYLE borderStyle = aTextBox->GetEffectiveLineStyle();
2537 double transparency = aTextBox->GetForcedTransparency();
2538
2539 if( m_schSettings.m_OverrideItemColors || aTextBox->IsBrightened()
2540 || borderColor == COLOR4D::UNSPECIFIED )
2541 {
2542 borderColor = m_schSettings.GetLayerColor( aLayer );
2543 }
2544
2545 if( transparency > 0.0 )
2546 borderColor = borderColor.WithAlpha( borderColor.a * ( 1.0 - transparency ) );
2547
2548 if( aDimmed )
2549 {
2550 borderColor = borderColor.Mix( bg, 0.5f );
2551 borderColor.Desaturate( );
2552 }
2553
2554 m_gal->SetIsFill( false );
2555 m_gal->SetIsStroke( true );
2556 m_gal->SetStrokeColor( borderColor );
2557 m_gal->SetLineWidth( borderWidth );
2558
2559 if( borderStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows )
2560 {
2561 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2562 }
2563 else
2564 {
2565 std::vector<SHAPE*> shapes = aTextBox->MakeEffectiveShapes( true );
2566
2567 for( SHAPE* shape : shapes )
2568 {
2569 STROKE_PARAMS::Stroke( shape, borderStyle, KiROUND( borderWidth ),
2571 [this]( const VECTOR2I& a, const VECTOR2I& b )
2572 {
2573 // DrawLine has problem with 0 length lines so enforce minimum
2574 if( a == b )
2575 m_gal->DrawLine( a+1, b );
2576 else
2577 m_gal->DrawLine( a, b );
2578 } );
2579 }
2580
2581 for( SHAPE* shape : shapes )
2582 delete shape;
2583 }
2584 }
2585 }
2586}
2587
2588
2589void SCH_PAINTER::draw( const SCH_TABLE* aTable, int aLayer, bool aDimmed )
2590{
2591 if( aTable->GetCells().empty() )
2592 return;
2593
2594 for( SCH_TABLECELL* cell : aTable->GetCells() )
2595 draw( cell, aLayer, aDimmed );
2596
2597 if( aLayer == LAYER_SELECTION_SHADOWS )
2598 return;
2599
2600 aTable->DrawBorders(
2601 [&]( const VECTOR2I& ptA, const VECTOR2I& ptB, const STROKE_PARAMS& stroke )
2602 {
2603 int lineWidth = stroke.GetWidth();
2604 COLOR4D color = stroke.GetColor();
2605 LINE_STYLE lineStyle = stroke.GetLineStyle();
2606
2607 if( lineWidth == 0 )
2608 lineWidth = m_schSettings.GetDefaultPenWidth();
2609
2610 if( color == COLOR4D::UNSPECIFIED )
2611 color = m_schSettings.GetLayerColor( LAYER_NOTES );
2612
2613 if( lineStyle == LINE_STYLE::DEFAULT )
2614 lineStyle = LINE_STYLE::SOLID;
2615
2616 m_gal->SetIsFill( false );
2617 m_gal->SetIsStroke( true );
2618 m_gal->SetStrokeColor( color );
2619 m_gal->SetLineWidth( (float) lineWidth );
2620
2621 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2622 {
2623 m_gal->DrawLine( ptA, ptB );
2624 }
2625 else
2626 {
2627 SHAPE_SEGMENT seg( ptA, ptB );
2628 STROKE_PARAMS::Stroke( &seg, lineStyle, lineWidth, &m_schSettings,
2629 [&]( const VECTOR2I& a, const VECTOR2I& b )
2630 {
2631 // DrawLine has problem with 0 length lines so enforce minimum
2632 if( a == b )
2633 m_gal->DrawLine( a+1, b );
2634 else
2635 m_gal->DrawLine( a, b );
2636 } );
2637 }
2638 } );
2639}
2640
2641
2642wxString SCH_PAINTER::expandLibItemTextVars( const wxString& aSourceText,
2643 const SCH_SYMBOL* aSymbolContext )
2644{
2645 std::function<bool( wxString* )> symbolResolver =
2646 [&]( wxString* token ) -> bool
2647 {
2648 if( !m_schematic )
2649 return false;
2650
2651 return aSymbolContext->ResolveTextVar( &m_schematic->CurrentSheet(), token );
2652 };
2653
2654 return ExpandTextVars( aSourceText, &symbolResolver );
2655}
2656
2657
2658void SCH_PAINTER::draw( const SCH_SYMBOL* aSymbol, int aLayer )
2659{
2660 auto t1 = std::chrono::high_resolution_clock::now();
2661 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2662
2663 std::optional<SCH_SHEET_PATH> optSheetPath;
2664
2665 wxString variantName;
2666
2667 if( m_schematic )
2668 {
2669 optSheetPath = m_schematic->CurrentSheet();
2670 variantName = m_schematic->GetCurrentVariant();
2671 wxLogTrace( traceSchPainter,
2672 "SCH_PAINTER::draw symbol %s: Current sheet path='%s', variant='%s', size=%zu, empty=%d",
2673 aSymbol->m_Uuid.AsString(),
2674 variantName.IsEmpty() ? GetDefaultVariantName() : variantName,
2675 optSheetPath->Path().AsString(),
2676 optSheetPath->size(),
2677 optSheetPath->empty() ? 1 : 0 );
2678 }
2679
2680 SCH_SHEET_PATH* sheetPath = optSheetPath ? &optSheetPath.value() : nullptr;
2681 bool DNP = aSymbol->GetDNP( sheetPath, variantName );
2682 bool markExclusion = eeconfig()->m_Appearance.mark_sim_exclusions && aSymbol->GetExcludedFromSim( sheetPath,
2683 variantName );
2684
2685 if( m_schSettings.IsPrinting() && drawingShadows )
2686 return;
2687
2688 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
2689 {
2690 for( const SCH_FIELD& field : aSymbol->GetFields() )
2691 draw( &field, aLayer, DNP );
2692 }
2693
2694 if( isFieldsLayer( aLayer ) )
2695 return;
2696
2697 if( drawingShadows && !( aSymbol->IsBrightened() || aSymbol->IsSelected() ) )
2698 {
2699 // Don't exit here; symbol may still have selected pins
2700 // return;
2701 }
2702
2703 int unit = m_schematic ? aSymbol->GetUnitSelection( &m_schematic->CurrentSheet() ) : 1;
2704 int bodyStyle = aSymbol->GetBodyStyle();
2705
2706 // Use dummy symbol if the actual couldn't be found (or couldn't be locked).
2707 LIB_SYMBOL* originalSymbol = aSymbol->GetLibSymbolRef() ? aSymbol->GetLibSymbolRef().get()
2709 std::vector<SCH_PIN*> originalPins = originalSymbol->GetGraphicalPins( unit, bodyStyle );
2710
2711 // Copy the source so we can re-orient and translate it.
2712 auto tCopy1 = std::chrono::high_resolution_clock::now();
2713 LIB_SYMBOL tempSymbol( *originalSymbol, nullptr, false );
2714 auto tCopy2 = std::chrono::high_resolution_clock::now();
2715
2716 if( std::chrono::duration_cast<std::chrono::microseconds>( tCopy2 - tCopy1 ).count() > 100 )
2717 {
2718 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw symbol copy %s: %lld us", aSymbol->m_Uuid.AsString(),
2719 std::chrono::duration_cast<std::chrono::microseconds>( tCopy2 - tCopy1 ).count() );
2720 }
2721
2722 std::vector<SCH_PIN*> tempPins = tempSymbol.GetGraphicalPins( unit, bodyStyle );
2723
2724 tempSymbol.SetFlags( aSymbol->GetFlags() );
2725
2726 OrientAndMirrorSymbolItems( &tempSymbol, aSymbol->GetOrientation() );
2727
2728 for( SCH_ITEM& tempItem : tempSymbol.GetDrawItems() )
2729 {
2730 tempItem.SetFlags( aSymbol->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2731 tempItem.Move( aSymbol->GetPosition() );
2732
2733 if( tempItem.Type() == SCH_TEXT_T )
2734 {
2735 SCH_TEXT* textItem = static_cast<SCH_TEXT*>( &tempItem );
2736
2737 if( textItem->HasTextVars() )
2738 textItem->SetText( expandLibItemTextVars( textItem->GetText(), aSymbol ) );
2739 }
2740 else if( tempItem.Type() == SCH_TEXTBOX_T )
2741 {
2742 SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( &tempItem );
2743
2744 if( textboxItem->HasTextVars() )
2745 textboxItem->SetText( expandLibItemTextVars( textboxItem->GetText(), aSymbol ) );
2746 }
2747 }
2748
2749 // Copy the pin info from the symbol to the temp pins
2750 for( unsigned i = 0; i < tempPins.size(); ++ i )
2751 {
2752 SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
2753 SCH_PIN* tempPin = tempPins[ i ];
2754
2755 if( !symbolPin )
2756 continue;
2757
2758 tempPin->ClearFlags();
2759 tempPin->SetFlags( symbolPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2760 // IS_SHOWN_AS_BITMAP
2761
2762 tempPin->SetName( expandLibItemTextVars( symbolPin->GetShownName(), aSymbol ) );
2763 tempPin->SetType( symbolPin->GetType() );
2764 tempPin->SetShape( symbolPin->GetShape() );
2765
2766 if( symbolPin->IsDangling() )
2767 tempPin->SetFlags( IS_DANGLING );
2768 else
2769 tempPin->ClearFlags( IS_DANGLING );
2770
2771 tempPin->SetOperatingPoint( symbolPin->GetOperatingPoint() );
2772 }
2773
2774 draw( &tempSymbol, aLayer, false, aSymbol->GetUnit(), aSymbol->GetBodyStyle(), DNP );
2775
2776 for( unsigned i = 0; i < tempPins.size(); ++i )
2777 {
2778 SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
2779 SCH_PIN* tempPin = tempPins[ i ];
2780
2781 if( !symbolPin )
2782 continue;
2783
2784 symbolPin->ClearFlags();
2785 tempPin->ClearFlags( IS_DANGLING ); // Clear this temporary flag
2786 symbolPin->SetFlags( tempPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2787 // IS_SHOWN_AS_BITMAP
2788 }
2789
2790 // Draw DNP and EXCLUDE from SIM markers.
2791 // These drawings are associated to the symbol body, so draw them only when the LAYER_DEVICE
2792 // is drawn (to avoid draw artifacts).
2793 if( DNP && aLayer == LAYER_DEVICE )
2794 {
2795 COLOR4D marker_color = m_schSettings.GetLayerColor( LAYER_DNP_MARKER );
2796 BOX2I bbox = aSymbol->GetBodyBoundingBox();
2797 BOX2I pins = aSymbol->GetBodyAndPinsBoundingBox();
2798 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
2799 std::max( bbox.GetY() - pins.GetY(), pins.GetEnd().y - bbox.GetEnd().y ) );
2800 int strokeWidth = 3 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
2801
2802 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
2803 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
2804 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
2805
2806 VECTOR2I pt1 = bbox.GetOrigin();
2807 VECTOR2I pt2 = bbox.GetEnd();
2808
2810 m_gal->AdvanceDepth();
2811 m_gal->SetIsStroke( true );
2812 m_gal->SetIsFill( true );
2813 m_gal->SetStrokeColor( marker_color );
2814 m_gal->SetFillColor( marker_color );
2815
2816 m_gal->DrawSegment( pt1, pt2, strokeWidth );
2817 std::swap( pt1.x, pt2.x );
2818 m_gal->DrawSegment( pt1, pt2, strokeWidth );
2819 }
2820
2821 if( markExclusion && aLayer == LAYER_DEVICE )
2822 {
2823 COLOR4D marker_color = m_schSettings.GetLayerColor( LAYER_EXCLUDED_FROM_SIM );
2824 BOX2I bbox = aSymbol->GetBodyBoundingBox();
2825 int strokeWidth = schIUScale.MilsToIU( ADVANCED_CFG::GetCfg().m_ExcludeFromSimulationLineWidth );
2826
2827 bbox.Inflate( KiROUND( strokeWidth * 0.5 ) );
2828
2830 m_gal->AdvanceDepth();
2831 m_gal->SetIsStroke( true );
2832 m_gal->SetIsFill( true );
2833 m_gal->SetStrokeColor( marker_color );
2834 m_gal->SetFillColor( marker_color );
2835
2836 m_gal->DrawSegment( bbox.GetPosition(), VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), strokeWidth );
2837 m_gal->DrawSegment( VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), bbox.GetEnd(), strokeWidth );
2838 m_gal->DrawSegment( bbox.GetEnd(), VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), strokeWidth );
2839 m_gal->DrawSegment( VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), bbox.GetPosition(), strokeWidth );
2840
2841 int offset = 2 * strokeWidth;
2842 VECTOR2D center = bbox.GetEnd() + VECTOR2D( offset + strokeWidth, -offset );
2843 VECTOR2D left = center + VECTOR2D( -offset, 0 );
2844 VECTOR2D right = center + VECTOR2D( offset, 0 );
2845 VECTOR2D top = center + VECTOR2D( 0, offset );
2846 VECTOR2D bottom = center + VECTOR2D( 0, -offset );
2847
2848 m_gal->SetFillColor( marker_color.WithAlpha( 0.1 ) );
2849 m_gal->DrawCircle( center, offset );
2850 m_gal->AdvanceDepth();
2851 m_gal->SetFillColor( marker_color );
2852 m_gal->DrawCurve( left, top, bottom, right, 1 );
2853 }
2854
2855 auto t2 = std::chrono::high_resolution_clock::now();
2856
2857 if( std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() > 100 )
2858 {
2859 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw symbol %s: %lld us", aSymbol->m_Uuid.AsString(),
2860 std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() );
2861 }
2862}
2863
2864
2865void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
2866{
2867 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2868
2869 if( m_schSettings.IsPrinting() && drawingShadows )
2870 return;
2871
2872 if( drawingShadows && !( aField->IsBrightened() || aField->IsSelected() ) )
2873 return;
2874
2875 if( !isUnitAndConversionShown( aField ) )
2876 return;
2877
2878 if( aField->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2879 return;
2880
2881 // Must check layer as fields are sometimes drawn by their parent rather than directly
2882 // from the view.
2883 std::vector<int> layers = aField->ViewGetLayers();
2884
2885 if( std::find( layers.begin(), layers.end(), aLayer ) == layers.end() )
2886 return;
2887
2888 aLayer = aField->GetLayer();
2889
2890 COLOR4D color = getRenderColor( aField, aLayer, drawingShadows, aDimmed );
2891
2892 if( !( aField->IsVisible() || aField->IsForceVisible() ) )
2893 {
2895 : m_schSettings.m_ShowHiddenFields;
2896
2897 if( force_show )
2898 color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows, aDimmed );
2899 else
2900 return;
2901 }
2902
2903 SCH_SHEET_PATH* sheetPath = nullptr;
2904 wxString variant;
2905
2906 if( m_schematic )
2907 {
2908 sheetPath = &m_schematic->CurrentSheet();
2909 variant = m_schematic->GetCurrentVariant();
2910 }
2911
2912 wxString shownText = aField->GetShownText( sheetPath, true, 0, variant );
2913
2914 if( shownText.IsEmpty() )
2915 return;
2916
2917 // Calculate the text orientation according to the parent orientation.
2918 EDA_ANGLE orient = aField->GetTextAngle();
2919
2920 if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
2921 {
2922 if( static_cast<SCH_SYMBOL*>( aField->GetParent() )->GetTransform().y1 )
2923 {
2924 // Rotate symbol 90 degrees.
2925 if( orient.IsHorizontal() )
2926 orient = ANGLE_VERTICAL;
2927 else
2928 orient = ANGLE_HORIZONTAL;
2929 }
2930 }
2931
2932 /*
2933 * Calculate the text justification, according to the symbol orientation/mirror.
2934 * This is a bit complicated due to cumulative calculations:
2935 * - numerous cases (mirrored or not, rotation)
2936 * - the DrawGraphicText function recalculate also H and H justifications according to the
2937 * text orientation.
2938 * - when symbol is mirrored, the text is not mirrored and justifications are complicated
2939 * to calculate so the easier way is to use no justifications (centered text) and use
2940 * GetBoundingBox to know the text coordinate considered as centered
2941 */
2942 BOX2I bbox = aField->GetBoundingBox();
2943
2944 if( aField->GetParent() && aField->GetParent()->Type() == SCH_GLOBAL_LABEL_T )
2945 {
2946 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( aField->GetParent() );
2947 bbox.Offset( label->GetSchematicTextOffset( &m_schSettings ) );
2948 }
2949
2950 if( m_schSettings.GetDrawBoundingBoxes() )
2951 drawItemBoundingBox( aField );
2952
2953 TEXT_ATTRIBUTES attributes = aField->GetAttributes();
2954 attributes.m_StrokeWidth = KiROUND( getTextThickness( aField ) );
2955
2956 m_gal->SetStrokeColor( color );
2957 m_gal->SetFillColor( color );
2958 m_gal->SetHoverColor( color );
2959
2960 if( drawingShadows && getFont( aField )->IsOutline() )
2961 {
2962 // Trying to draw glyph-shaped shadows on outline text is a fool's errand. Just box it.
2963 VECTOR2I textpos = bbox.Centre();
2964
2965 attributes.m_Halign = GR_TEXT_H_ALIGN_CENTER;
2966 attributes.m_Valign = GR_TEXT_V_ALIGN_CENTER;
2967 attributes.m_Angle = orient;
2968 boxText( *m_gal, shownText, textpos, attributes, aField->GetFontMetrics() );
2969 }
2970 else
2971 {
2972 VECTOR2I textpos = bbox.Centre();
2973
2974 attributes.m_Halign = GR_TEXT_H_ALIGN_CENTER;
2975 attributes.m_Valign = GR_TEXT_V_ALIGN_CENTER;
2976 attributes.m_Angle = orient;
2977
2978 if( drawingShadows )
2979 attributes.m_StrokeWidth += getShadowWidth( !aField->IsSelected() );
2980
2981 if( aField->IsRollover() && !aField->IsMoving() )
2982 {
2983 // Highlight any urls found within the text
2984 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2985
2986 // Highlight the whole text if it has a link definition
2987 if( aField->HasHyperlink() )
2988 {
2989 attributes.m_Hover = true;
2990 attributes.m_Underlined = true;
2991 }
2992 }
2993
2994 if( nonCached( aField ) && aField->RenderAsBitmap( m_gal->GetWorldScale() ) )
2995 {
2996 bitmapText( *m_gal, shownText, textpos, attributes );
2997 const_cast<SCH_FIELD*>( aField )->SetFlags( IS_SHOWN_AS_BITMAP );
2998 }
2999 else
3000 {
3001 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
3002
3003 if( !aField->IsRollover() )
3004 cache = aField->GetRenderCache( shownText, textpos, attributes );
3005
3006 if( cache )
3007 {
3008 m_gal->SetLineWidth( attributes.m_StrokeWidth );
3009 m_gal->DrawGlyphs( *cache );
3010 }
3011 else
3012 {
3013 strokeText( *m_gal, shownText, textpos, attributes, aField->GetFontMetrics(),
3014 aField->GetRolloverPos() );
3015 }
3016
3017 const_cast<SCH_FIELD*>( aField )->ClearFlags( IS_SHOWN_AS_BITMAP );
3018 }
3019 }
3020
3021 if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
3022 {
3023 SCH_SYMBOL* parent = static_cast<SCH_SYMBOL*>( aField->GetParent() );
3024 bool rotated = !orient.IsHorizontal();
3025
3026 VECTOR2D pos;
3027 double size = bbox.GetHeight() / 1.5;
3028
3029 if( rotated )
3030 {
3031 pos = VECTOR2D( bbox.GetRight() - bbox.GetWidth() / 6.0,
3032 bbox.GetBottom() + bbox.GetWidth() / 2.0 );
3033 size = bbox.GetWidth() / 1.5;
3034 }
3035 else
3036 {
3037 pos = VECTOR2D( bbox.GetLeft() - bbox.GetHeight() / 2.0,
3038 bbox.GetBottom() - bbox.GetHeight() / 6.0 );
3039 }
3040
3041 if( parent->IsSymbolLikePowerLocalLabel() && aField->GetId() == FIELD_T::VALUE )
3042 drawLocalPowerIcon( pos, size, rotated, color, drawingShadows, aField->IsBrightened() );
3043 }
3044
3045 // Draw anchor or umbilical line
3046 if( aField->IsMoving() && m_schematic )
3047 {
3048 VECTOR2I parentPos = aField->GetParentPosition();
3049
3050 m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() );
3051 m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
3052 m_gal->DrawLine( aField->GetPosition(), parentPos );
3053 }
3054 else if( aField->IsSelected() )
3055 {
3056 drawAnchor( aField->GetPosition(), drawingShadows );
3057 }
3058}
3059
3060
3061void SCH_PAINTER::draw( const SCH_GLOBALLABEL* aLabel, int aLayer, bool aDimmed )
3062{
3063 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3064
3065 if( m_schSettings.IsPrinting() && drawingShadows )
3066 return;
3067
3068 bool drawingDangling = aLayer == LAYER_DANGLING;
3069
3070 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3071 {
3072 for( const SCH_FIELD& field : aLabel->GetFields() )
3073 draw( &field, aLayer, false );
3074 }
3075
3076 if( isFieldsLayer( aLayer ) )
3077 return;
3078
3079 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3080 return;
3081
3082 COLOR4D color = getRenderColor( aLabel, LAYER_GLOBLABEL, drawingShadows, aDimmed, true );
3083
3084 if( drawingDangling )
3085 {
3086 if( aLabel->IsDangling() )
3087 {
3088 drawDanglingIndicator( aLabel->GetTextPos(), color,
3089 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3090 drawingShadows, aLabel->IsBrightened() );
3091 }
3092
3093 return;
3094 }
3095
3096 std::vector<VECTOR2I> pts;
3097 std::deque<VECTOR2D> pts2;
3098
3099 aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
3100
3101 for( const VECTOR2I& p : pts )
3102 pts2.emplace_back( VECTOR2D( p.x, p.y ) );
3103
3104 m_gal->SetIsStroke( true );
3105 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3106 m_gal->SetStrokeColor( color );
3107
3108 if( drawingShadows )
3109 {
3110 m_gal->SetIsFill( eeconfig()->m_Selection.fill_shapes );
3111 m_gal->SetFillColor( color );
3112 m_gal->DrawPolygon( pts2 );
3113 }
3114 else
3115 {
3116 m_gal->SetIsFill( false );
3117 m_gal->DrawPolyline( pts2 );
3118 }
3119
3120 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3121}
3122
3123
3124void SCH_PAINTER::draw( const SCH_LABEL* aLabel, int aLayer, bool aDimmed )
3125{
3126 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3127
3128 if( m_schSettings.IsPrinting() && drawingShadows )
3129 return;
3130
3131 bool drawingDangling = aLayer == LAYER_DANGLING;
3132
3133 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3134 {
3135 for( const SCH_FIELD& field : aLabel->GetFields() )
3136 draw( &field, aLayer, false );
3137 }
3138
3139 if( isFieldsLayer( aLayer ) )
3140 return;
3141
3142 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3143 return;
3144
3145 COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows, aDimmed, true );
3146
3147 if( drawingDangling )
3148 {
3149 if( aLabel->IsDangling() )
3150 {
3151 drawDanglingIndicator( aLabel->GetTextPos(), color,
3152 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3153 drawingShadows, aLabel->IsBrightened() );
3154 }
3155
3156 return;
3157 }
3158
3159 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3160}
3161
3162
3163void SCH_PAINTER::draw( const SCH_HIERLABEL* aLabel, int aLayer, bool aDimmed )
3164{
3165 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3166
3167 if( m_schSettings.IsPrinting() && drawingShadows )
3168 return;
3169
3170 bool drawingDangling = aLayer == LAYER_DANGLING;
3171
3172 if( !( drawingShadows || drawingDangling ) || eeconfig()->m_Selection.draw_selected_children )
3173 {
3174 for( const SCH_FIELD& field : aLabel->GetFields() )
3175 draw( &field, aLayer, false );
3176 }
3177
3178 if( isFieldsLayer( aLayer ) )
3179 return;
3180
3181 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3182 return;
3183
3184 COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows, aDimmed, true );
3185
3186 if( drawingDangling )
3187 {
3188 if( aLabel->IsDangling() )
3189 {
3190 drawDanglingIndicator( aLabel->GetTextPos(), color,
3191 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3192 drawingShadows, aLabel->IsBrightened() );
3193 }
3194
3195 return;
3196 }
3197
3198 std::vector<VECTOR2I> i_pts;
3199 std::deque<VECTOR2D> d_pts;
3200
3201 aLabel->CreateGraphicShape( &m_schSettings, i_pts, (VECTOR2I)aLabel->GetTextPos() );
3202
3203 for( const VECTOR2I& i_pt : i_pts )
3204 d_pts.emplace_back( VECTOR2D( i_pt.x, i_pt.y ) );
3205
3206 m_gal->SetIsFill( true );
3207 m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
3208 m_gal->SetIsStroke( true );
3209 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3210 m_gal->SetStrokeColor( color );
3211 m_gal->DrawPolyline( d_pts );
3212
3213 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3214}
3215
3216
3217void SCH_PAINTER::draw( const SCH_DIRECTIVE_LABEL* aLabel, int aLayer, bool aDimmed )
3218{
3219 if( !eeconfig()->m_Appearance.show_directive_labels && !aLabel->IsSelected() )
3220 return;
3221
3222 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3223
3224 if( m_schSettings.IsPrinting() && drawingShadows )
3225 return;
3226
3227 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3228 {
3229 for( const SCH_FIELD& field : aLabel->GetFields() )
3230 draw( &field, aLayer, false );
3231 }
3232
3233 if( isFieldsLayer( aLayer ) )
3234 return;
3235
3236 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3237 return;
3238
3239 COLOR4D color = getRenderColor( aLabel, LAYER_NETCLASS_REFS, drawingShadows, aDimmed, true );
3240
3241 if( aLayer == LAYER_DANGLING )
3242 {
3243 if( aLabel->IsDangling() )
3244 {
3245 drawDanglingIndicator( aLabel->GetTextPos(), color,
3246 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3247 drawingShadows, aLabel->IsBrightened() );
3248 }
3249
3250 return;
3251 }
3252
3253 std::vector<VECTOR2I> pts;
3254 std::deque<VECTOR2D> pts2;
3255
3256 aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
3257
3258 for( const VECTOR2I& p : pts )
3259 pts2.emplace_back( VECTOR2D( p.x, p.y ) );
3260
3261 m_gal->SetIsFill( false );
3262 m_gal->SetFillColor( color );
3263 m_gal->SetIsStroke( true );
3264 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3265 m_gal->SetStrokeColor( color );
3266
3267 if( aLabel->GetShape() == LABEL_FLAG_SHAPE::F_DOT )
3268 {
3269 m_gal->DrawLine( pts2[0], pts2[1] );
3270 m_gal->SetIsFill( true );
3271 m_gal->DrawCircle( pts2[2], ( pts2[2] - pts2[1] ).EuclideanNorm() );
3272 }
3273 else if( aLabel->GetShape() == LABEL_FLAG_SHAPE::F_ROUND )
3274 {
3275 m_gal->DrawLine( pts2[0], pts2[1] );
3276 m_gal->DrawCircle( pts2[2], ( pts2[2] - pts2[1] ).EuclideanNorm() );
3277 }
3278 else
3279 {
3280 m_gal->DrawPolyline( pts2 );
3281 }
3282}
3283
3284
3285void SCH_PAINTER::draw( const SCH_SHEET* aSheet, int aLayer )
3286{
3287 SCH_SHEET_PATH* sheetPath = nullptr;
3288 wxString variant;
3289 bool DNP = false;
3290
3291 if( m_schematic )
3292 {
3293 sheetPath = &m_schematic->CurrentSheet();
3294 variant = m_schematic->GetCurrentVariant();
3295 DNP = aSheet->GetDNP( sheetPath, variant );
3296 }
3297
3298 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3299 bool markExclusion = eeconfig()->m_Appearance.mark_sim_exclusions
3300 && aSheet->GetExcludedFromSim( sheetPath, variant );
3301
3302 if( m_schSettings.IsPrinting() && drawingShadows )
3303 return;
3304
3305 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3306 {
3307 for( const SCH_FIELD& field : aSheet->GetFields() )
3308 draw( &field, aLayer, DNP );
3309
3310 for( SCH_SHEET_PIN* sheetPin : aSheet->GetPins() )
3311 draw( static_cast<SCH_HIERLABEL*>( sheetPin ), aLayer, DNP );
3312 }
3313
3314 if( isFieldsLayer( aLayer ) )
3315 return;
3316
3317 VECTOR2D pos = aSheet->GetPosition();
3318 VECTOR2D size = aSheet->GetSize();
3319
3320 if( aLayer == LAYER_SHEET_BACKGROUND )
3321 {
3322 // Do not fill the shape in B&W print mode, to avoid to visible items
3323 // inside the shape
3324 if( !m_schSettings.PrintBlackAndWhiteReq() )
3325 {
3326 COLOR4D backgroundColor = aSheet->GetBackgroundColor();
3327
3328 if( m_schSettings.m_OverrideItemColors || backgroundColor == COLOR4D::UNSPECIFIED )
3329 backgroundColor = m_schSettings.GetLayerColor( LAYER_SHEET_BACKGROUND );
3330
3331 // Only draw the background if it has a visible alpha value
3332 if( backgroundColor.a > 0.0 )
3333 {
3334 m_gal->SetFillColor( getRenderColor( aSheet, LAYER_SHEET_BACKGROUND, false ) );
3335 m_gal->SetIsFill( true );
3336 m_gal->SetIsStroke( false );
3337
3338 m_gal->DrawRectangle( pos, pos + size );
3339 }
3340 }
3341 }
3342
3343 if( aLayer == LAYER_SHEET || aLayer == LAYER_SELECTION_SHADOWS )
3344 {
3345 m_gal->SetStrokeColor( getRenderColor( aSheet, LAYER_SHEET, drawingShadows ) );
3346 m_gal->SetIsStroke( true );
3347 m_gal->SetLineWidth( getLineWidth( aSheet, drawingShadows ) );
3348 m_gal->SetIsFill( false );
3349
3350 m_gal->DrawRectangle( pos, pos + size );
3351 }
3352
3353 if( DNP && aLayer == LAYER_SHEET )
3354 {
3355 int layer = LAYER_DNP_MARKER;
3356 BOX2I bbox = aSheet->GetBodyBoundingBox();
3357 BOX2I pins = aSheet->GetBoundingBox();
3358 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
3359 std::max( bbox.GetY() - pins.GetY(), pins.GetEnd().y - bbox.GetEnd().y ) );
3360 int strokeWidth = 3 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
3361
3362 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
3363 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
3364 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
3365
3366 VECTOR2I pt1 = bbox.GetOrigin();
3367 VECTOR2I pt2 = bbox.GetEnd();
3368
3370 m_gal->AdvanceDepth();
3371 m_gal->SetIsStroke( true );
3372 m_gal->SetIsFill( true );
3373 m_gal->SetStrokeColor( m_schSettings.GetLayerColor( layer ) );
3374 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ) );
3375
3376 m_gal->DrawSegment( pt1, pt2, strokeWidth );
3377 std::swap( pt1.x, pt2.x );
3378 m_gal->DrawSegment( pt1, pt2, strokeWidth );
3379 }
3380
3381 if( markExclusion )
3382 {
3383 int layer = LAYER_EXCLUDED_FROM_SIM;
3384 BOX2I bbox = aSheet->GetBodyBoundingBox();
3385 int strokeWidth = schIUScale.MilsToIU( ADVANCED_CFG::GetCfg().m_ExcludeFromSimulationLineWidth );
3386
3387 bbox.Inflate( KiROUND( strokeWidth * 0.5 ) );
3388
3390 m_gal->AdvanceDepth();
3391 m_gal->SetIsStroke( true );
3392 m_gal->SetIsFill( true );
3393 m_gal->SetStrokeColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3394 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3395
3396 m_gal->DrawSegment( bbox.GetPosition(), VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), strokeWidth );
3397 m_gal->DrawSegment( VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), bbox.GetEnd(), strokeWidth );
3398 m_gal->DrawSegment( bbox.GetEnd(), VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), strokeWidth );
3399 m_gal->DrawSegment( VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), bbox.GetPosition(), strokeWidth );
3400
3401 int offset = 2 * strokeWidth;
3402 VECTOR2D center = bbox.GetEnd() + VECTOR2D( offset + strokeWidth, -offset );
3403 VECTOR2D left = center + VECTOR2D( -offset, 0 );
3404 VECTOR2D right = center + VECTOR2D( offset, 0 );
3405 VECTOR2D top = center + VECTOR2D( 0, offset );
3406 VECTOR2D bottom = center + VECTOR2D( 0, -offset );
3407
3408 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.1 ) );
3409 m_gal->DrawCircle( center, offset );
3410 m_gal->AdvanceDepth();
3411 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3412 m_gal->DrawCurve( left, top, bottom, right, 1 );
3413 }
3414}
3415
3416
3417void SCH_PAINTER::draw( const SCH_NO_CONNECT* aNC, int aLayer )
3418{
3419 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3420
3421 if( m_schSettings.IsPrinting() && drawingShadows )
3422 return;
3423
3424 if( drawingShadows && !( aNC->IsBrightened() || aNC->IsSelected() ) )
3425 return;
3426
3427 m_gal->SetIsStroke( true );
3428 m_gal->SetLineWidth( getLineWidth( aNC, drawingShadows ) );
3429 m_gal->SetStrokeColor( getRenderColor( aNC, LAYER_NOCONNECT, drawingShadows ) );
3430 m_gal->SetIsFill( false );
3431
3432 VECTOR2D p = aNC->GetPosition();
3433 int delta = std::max( aNC->GetSize(), m_schSettings.GetDefaultPenWidth() * 3 ) / 2;
3434
3435 m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
3436 m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
3437}
3438
3439
3440void SCH_PAINTER::draw( const SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
3441{
3443 SCH_LINE line( VECTOR2I(), layer );
3444 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3445 bool drawingNetColorHighlights = aLayer == LAYER_NET_COLOR_HIGHLIGHT;
3446 bool drawingDangling = aLayer == LAYER_DANGLING;
3447 bool drawingWires = aLayer == LAYER_WIRE;
3448 bool drawingBusses = aLayer == LAYER_BUS;
3449
3450 if( m_schSettings.IsPrinting() && drawingShadows )
3451 return;
3452
3453 bool highlightNetclassColors = false;
3454 EESCHEMA_SETTINGS* eeschemaCfg = eeconfig();
3455
3456 if( eeschemaCfg )
3457 {
3458 highlightNetclassColors = eeschemaCfg->m_Selection.highlight_netclass_colors;
3459 }
3460
3461 if( !highlightNetclassColors && drawingNetColorHighlights )
3462 return;
3463
3464 if( m_schSettings.m_OverrideItemColors && drawingNetColorHighlights )
3465 return;
3466
3467 if( drawingShadows && !( aEntry->IsBrightened() || aEntry->IsSelected() ) )
3468 return;
3469
3470 if( aEntry->IsSelected() )
3471 {
3472 line.SetSelected();
3473
3474 // Never show unselected endpoints on bus entries
3475 line.SetFlags( STARTPOINT | ENDPOINT );
3476 }
3477 else if( aEntry->IsBrightened() )
3478 {
3479 line.SetBrightened();
3480 }
3481
3482 line.SetStartPoint( aEntry->GetPosition() );
3483 line.SetEndPoint( aEntry->GetEnd() );
3484 line.SetStroke( aEntry->GetStroke() );
3485 line.SetLineWidth( KiROUND( getLineWidth( aEntry, false ) ) );
3486
3487 COLOR4D color = getRenderColor( aEntry, LAYER_WIRE, drawingShadows );
3488
3489 if( aEntry->Type() == SCH_BUS_BUS_ENTRY_T )
3490 color = getRenderColor( aEntry, LAYER_BUS, drawingShadows );
3491
3492 if( highlightNetclassColors )
3493 {
3494 // Force default color for nets we are going to highlight
3495 if( drawingWires )
3496 color = m_schSettings.GetLayerColor( LAYER_WIRE );
3497 else if( drawingBusses )
3498 color = m_schSettings.GetLayerColor( LAYER_BUS );
3499 }
3500
3501 if( drawingNetColorHighlights )
3502 {
3503 // Don't draw highlights for default-colored nets
3504 if( ( aEntry->Type() == SCH_BUS_WIRE_ENTRY_T
3505 && color == m_schSettings.GetLayerColor( LAYER_WIRE ) )
3506 || ( aEntry->Type() == SCH_BUS_BUS_ENTRY_T
3507 && color == m_schSettings.GetLayerColor( LAYER_BUS ) ) )
3508 {
3509 return;
3510 }
3511 }
3512
3513 if( drawingDangling )
3514 {
3515 m_gal->SetIsFill( false );
3516 m_gal->SetIsStroke( true );
3517 m_gal->SetStrokeColor( color.Brightened( 0.3 ) );
3518 m_gal->SetLineWidth( m_schSettings.GetDanglingIndicatorThickness() );
3519
3520 if( aEntry->IsStartDangling() )
3521 {
3522 m_gal->DrawCircle( aEntry->GetPosition(),
3523 aEntry->GetPenWidth() + KiROUND( TARGET_BUSENTRY_RADIUS / 2.0 ) );
3524 }
3525
3526 if( aEntry->IsEndDangling() )
3527 {
3528 m_gal->DrawCircle( aEntry->GetEnd(),
3529 aEntry->GetPenWidth() + KiROUND( TARGET_BUSENTRY_RADIUS / 2.0 ) );
3530 }
3531 }
3532 else
3533 {
3534 line.SetLineColor( color );
3535 line.SetLineStyle( aEntry->GetEffectiveLineStyle() );
3536
3537 draw( &line, aLayer );
3538 }
3539}
3540
3541
3542void SCH_PAINTER::draw( const SCH_BITMAP* aBitmap, int aLayer )
3543{
3544 auto t1 = std::chrono::high_resolution_clock::now();
3545 m_gal->Save();
3546 m_gal->Translate( aBitmap->GetPosition() );
3547
3548 const REFERENCE_IMAGE& refImage = aBitmap->GetReferenceImage();
3549
3550 // When the image scale factor is not 1.0, we need to modify the actual as the image scale
3551 // factor is similar to a local zoom
3552 const double img_scale = refImage.GetImageScale();
3553
3554 if( img_scale != 1.0 )
3555 m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
3556
3557 if( aLayer == LAYER_DRAW_BITMAPS )
3558 {
3559 m_gal->DrawBitmap( refImage.GetImage() );
3560 }
3561
3562 if( aLayer == LAYER_SELECTION_SHADOWS )
3563 {
3564 if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
3565 {
3566 const COLOR4D color = getRenderColor( aBitmap, LAYER_DRAW_BITMAPS, true );
3567 m_gal->SetIsStroke( true );
3568 m_gal->SetStrokeColor( color );
3569 m_gal->SetLineWidth ( getShadowWidth( aBitmap->IsBrightened() ) );
3570 m_gal->SetIsFill( false );
3571
3572 // Draws a bounding box.
3573 VECTOR2D bm_size( refImage.GetSize() );
3574
3575 // bm_size is the actual image size in UI.
3576 // but m_canvas scale was previously set to img_scale
3577 // so recalculate size relative to this image size.
3578 bm_size.x /= img_scale;
3579 bm_size.y /= img_scale;
3580 const VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
3581 const VECTOR2D end = origin + bm_size;
3582
3583 m_gal->DrawRectangle( origin, end );
3584 }
3585 }
3586
3587 m_gal->Restore();
3588 auto t2 = std::chrono::high_resolution_clock::now();
3589
3590 if( std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() > 100 )
3591 {
3592 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw bitmap %s: %lld us", aBitmap->m_Uuid.AsString(),
3593 std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() );
3594 }
3595}
3596
3597
3598void SCH_PAINTER::draw( const SCH_MARKER* aMarker, int aLayer )
3599{
3600 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3601
3602 if( m_schSettings.IsPrinting() && drawingShadows )
3603 return;
3604
3605 if( drawingShadows && !( aMarker->IsBrightened() || aMarker->IsSelected() ) )
3606 return;
3607
3608 COLOR4D color = getRenderColor( aMarker, aMarker->GetColorLayer(), drawingShadows );
3609
3610 m_gal->Save();
3611 m_gal->Translate( aMarker->GetPosition() );
3612 m_gal->SetIsFill( !drawingShadows );
3613 m_gal->SetFillColor( color );
3614 m_gal->SetIsStroke( drawingShadows );
3615 m_gal->SetLineWidth( getLineWidth( aMarker, drawingShadows ) );
3616 m_gal->SetStrokeColor( color );
3617
3618 SHAPE_LINE_CHAIN polygon;
3619 aMarker->ShapeToPolygon( polygon );
3620
3621 m_gal->DrawPolygon( polygon );
3622 m_gal->Restore();
3623}
3624
3625
3626void SCH_PAINTER::draw( const SCH_GROUP* aGroup, int aLayer )
3627{
3628 const bool drawingShadows = false;
3629
3630 if( aLayer == LAYER_SCHEMATIC_ANCHOR )
3631 {
3632 if( aGroup->IsSelected() && !( aGroup->GetParent() && aGroup->GetParent()->IsSelected() ) )
3633 {
3634 // Selected on our own; draw enclosing box
3635 }
3636 else if( aGroup->IsEntered() )
3637 {
3638 // Entered group; draw enclosing box
3639 }
3640 else
3641 {
3642 // Neither selected nor entered; draw nothing at the group level (ie: only draw
3643 // its members)
3644 return;
3645 }
3646
3647 const COLOR4D color = getRenderColor( aGroup, LAYER_SCHEMATIC_ANCHOR, drawingShadows );
3648
3649 m_gal->SetStrokeColor( color );
3650 m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() * 2.0f );
3651
3652 BOX2I bbox = aGroup->GetBoundingBox();
3653 VECTOR2I topLeft = bbox.GetPosition();
3654 VECTOR2I width = VECTOR2I( bbox.GetWidth(), 0 );
3655 VECTOR2I height = VECTOR2I( 0, bbox.GetHeight() );
3656
3657 m_gal->DrawLine( topLeft, topLeft + width );
3658 m_gal->DrawLine( topLeft + width, topLeft + width + height );
3659 m_gal->DrawLine( topLeft + width + height, topLeft + height );
3660 m_gal->DrawLine( topLeft + height, topLeft );
3661
3662 wxString name = aGroup->GetName();
3663
3664 if( name.IsEmpty() )
3665 return;
3666
3667 int ptSize = 12;
3668 int scaledSize = abs( KiROUND( m_gal->GetScreenWorldMatrix().GetScale().x * ptSize ) );
3669 int unscaledSize = schIUScale.MilsToIU( ptSize );
3670
3671 // Scale by zoom a bit, but not too much
3672 int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3;
3673 VECTOR2I textOffset = KiROUND( width.x / 2.0, -textSize * 0.5 );
3674 VECTOR2I titleHeight = KiROUND( 0.0, textSize * 2.0 );
3675
3676 if( PrintableCharCount( name ) * textSize < bbox.GetWidth() )
3677 {
3678 m_gal->DrawLine( topLeft, topLeft - titleHeight );
3679 m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight );
3680 m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width );
3681
3682 TEXT_ATTRIBUTES attrs;
3683 attrs.m_Italic = true;
3686 attrs.m_Size = VECTOR2I( textSize, textSize );
3687 attrs.m_StrokeWidth = GetPenSizeForNormal( textSize );
3688
3689 KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs,
3690 aGroup->GetFontMetrics() );
3691 }
3692 }
3693}
3694
3695
3696void SCH_PAINTER::drawLine( const VECTOR2I& aStartPoint, const VECTOR2I& aEndPoint,
3697 LINE_STYLE aLineStyle, bool aDrawDirectLine, int aWidth )
3698{
3699 if( aDrawDirectLine )
3700 {
3701 m_gal->DrawLine( aStartPoint, aEndPoint );
3702 }
3703 else
3704 {
3705 SHAPE_SEGMENT segment( aStartPoint, aEndPoint );
3706
3707 STROKE_PARAMS::Stroke( &segment, aLineStyle, KiROUND( aWidth ), &m_schSettings,
3708 [&]( const VECTOR2I& start, const VECTOR2I& end )
3709 {
3710 if( start == end )
3711 m_gal->DrawLine( start + 1, end );
3712 else
3713 m_gal->DrawLine( start, end );
3714 } );
3715 }
3716}
3717
3718}; // namespace KIGFX
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
std::optional< BOX2I > OPT_BOX2I
Definition box2.h:926
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
constexpr const Vec & GetPosition() const
Definition box2.h:211
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:558
constexpr const Vec GetEnd() const
Definition box2.h:212
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:146
constexpr coord_type GetY() const
Definition box2.h:208
constexpr size_type GetWidth() const
Definition box2.h:214
constexpr Vec Centre() const
Definition box2.h:97
constexpr coord_type GetX() const
Definition box2.h:207
constexpr size_type GetHeight() const
Definition box2.h:215
constexpr coord_type GetLeft() const
Definition box2.h:228
constexpr void SetX(coord_type val)
Definition box2.h:277
constexpr const Vec & GetOrigin() const
Definition box2.h:210
constexpr void SetY(coord_type val)
Definition box2.h:282
const BOX2< Vec > GetBoundingBoxRotated(const VECTOR2I &aRotCenter, const EDA_ANGLE &aAngle) const
Useful to calculate bounding box of rotated items, when rotation is not cardinal.
Definition box2.h:720
constexpr coord_type GetRight() const
Definition box2.h:217
constexpr coord_type GetTop() const
Definition box2.h:229
constexpr void Offset(coord_type dx, coord_type dy)
Definition box2.h:259
constexpr coord_type GetBottom() const
Definition box2.h:222
Represent basic circle geometry with utility geometry functions.
Definition circle.h:33
VECTOR2I Center
Public to make access simpler.
Definition circle.h:130
int Radius
Public to make access simpler.
Definition circle.h:129
bool IsHorizontal() const
Definition eda_angle.h:142
EDA_ANGLE Normalize180()
Definition eda_angle.h:268
wxString GetName() const
Definition eda_group.h:51
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:99
VECTOR2I GetRolloverPos() const
Definition eda_item.h:133
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:120
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:148
const KIID m_Uuid
Definition eda_item.h:527
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
bool IsEntered() const
Definition eda_item.h:129
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:150
bool IsSelected() const
Definition eda_item.h:128
void SetSelected()
Definition eda_item.h:140
void SetBrightened()
Definition eda_item.h:141
EDA_ITEM * GetParent() const
Definition eda_item.h:113
bool IsRollover() const
Definition eda_item.h:132
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:152
bool IsBrightened() const
Definition eda_item.h:130
bool IsForceVisible() const
Definition eda_item.h:217
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:151
bool IsMoving() const
Definition eda_item.h:126
bool IsNew() const
Definition eda_item.h:125
FILL_T GetFillMode() const
Definition eda_shape.h:142
SHAPE_T GetShape() const
Definition eda_shape.h:169
const std::vector< SEG > & GetHatchLines() const
Definition eda_shape.h:149
bool IsSolidFill() const
Definition eda_shape.h:117
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:216
COLOR4D GetFillColor() const
Definition eda_shape.h:153
virtual void UpdateHatching() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:80
const VECTOR2I & GetTextPos() const
Definition eda_text.h:273
COLOR4D GetTextColor() const
Definition eda_text.h:270
void SetActiveUrl(const wxString &aUrl) const
Definition eda_text.h:278
bool IsItalic() const
Definition eda_text.h:169
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:147
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
virtual bool IsVisible() const
Definition eda_text.h:187
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:697
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:379
virtual VECTOR2I GetDrawPos() const
Definition eda_text.h:380
virtual bool HasHyperlink() const
Definition eda_text.h:402
wxString GetHyperlink() const
Definition eda_text.h:403
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:661
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition eda_text.h:117
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:231
bool IsBold() const
Definition eda_text.h:184
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:284
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:98
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:147
virtual bool IsStroke() const
Definition font.h:105
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr) const
Draw a string.
Definition font.cpp:250
virtual bool IsOutline() const
Definition font.h:106
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
Definition font.cpp:451
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition color4d.h:312
COLOR4D & Invert()
Makes the color inverted, alpha remains the same.
Definition color4d.h:243
COLOR4D & Darken(double aFactor)
Makes the color darker by a given factor.
Definition color4d.h:227
std::shared_ptr< wxString > m_text
Definition color4d.h:399
double a
Alpha component.
Definition color4d.h:396
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
Definition color4d.h:269
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:402
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition color4d.cpp:532
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:296
Attribute save/restore for GAL attributes.
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 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 SetHorizontalJustify(const GR_TEXT_H_ALIGN_T aHorizontalJustify)
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void Restore()
Restore the context.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
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 DrawArc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle)
Draw an arc.
virtual void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
Draw a text using a bitmap font.
virtual void Save()
Save the context.
double GetWorldScale() const
Get the world scale.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition painter.h:102
PAINTER(GAL *aGal)
Initialize this object for painting on any of the polymorphic GRAPHICS_ABSTRACTION_LAYER* derivatives...
Definition painter.cpp:33
virtual bool Draw(const VIEW_ITEM *, int) override
Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item.
void drawPinDanglingIndicator(const SCH_PIN &aPin, const COLOR4D &aColor, bool aDrawingShadows, bool aBrightened)
float getTextThickness(const SCH_ITEM *aItem) const
void drawLocalPowerIcon(const VECTOR2D &aPos, double aSize, bool aRotate, const COLOR4D &aColor, bool aDrawingShadows, bool aBrightened)
Draw an local power pin indicator icon.
float getShadowWidth(bool aForHighlight) const
COLOR4D getRenderColor(const SCH_ITEM *aItem, int aLayer, bool aDrawingShadows, bool aDimmed=false, bool aIgnoreNets=false) const
int externalPinDecoSize(const SCH_PIN &aPin)
KIFONT::FONT * getFont(const EDA_TEXT *aText) const
void draw(const EDA_ITEM *, int, bool aDimmed)
wxString expandLibItemTextVars(const wxString &aSourceText, const SCH_SYMBOL *aSymbolContext)
static std::vector< KICAD_T > g_ScaledSelectionTypes
SCHEMATIC * m_schematic
void drawLine(const VECTOR2I &aStartPoint, const VECTOR2I &aEndPoint, LINE_STYLE aLineStyle, bool aDrawDirectLine=false, int aWidth=0)
int getOperatingPointTextSize() const
float getLineWidth(const SCH_ITEM *aItem, bool aDrawingShadows, bool aDrawingWireColorHighlights=false) const
void triLine(const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c)
SCH_RENDER_SETTINGS m_schSettings
void drawAnchor(const VECTOR2I &aPos, bool aDrawingShadows)
Draw anchor indicating the anchor position of text objects, local labels, or fields.
bool nonCached(const EDA_ITEM *aItem)
Indicates the item is drawn on a non-cached layer in OpenGL.
void drawDanglingIndicator(const VECTOR2I &aPos, const COLOR4D &aColor, int aWidth, bool aDangling, bool aDrawingShadows, bool aBrightened)
Draw the target (an open square) for a wire or label which has no connection or is being moved.
void drawItemBoundingBox(const EDA_ITEM *aItem)
int internalPinDecoSize(const SCH_PIN &aPin)
bool isUnitAndConversionShown(const SCH_ITEM *aItem) const
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:86
double GetForcedTransparency() const
Definition view_item.h:171
wxString AsString() const
Definition kiid.cpp:244
Define a library symbol object.
Definition lib_symbol.h:83
std::vector< const SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
bool IsDerived() const
Definition lib_symbol.h:200
static LIB_SYMBOL * GetDummy()
Returns a dummy LIB_SYMBOL, used when one is missing in the schematic.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:712
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon, int aScale=-1) const
Return the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to the...
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition matrix3x3.h:295
A pin layout helper is a class that manages the layout of the parts of a pin on a schematic symbol:
OPT_BOX2I GetAltIconBBox()
Get the box of the alt mode icon, if there is one.
std::optional< TEXT_INFO > GetPinNameInfo(int aShadowWidth)
Get the text info for the pin name.
std::optional< TEXT_INFO > GetPinElectricalTypeInfo(int aShadowWidth)
CIRCLE GetDanglingIndicator() const
Gets the dangling indicator geometry for this pin, if the pin were to be dangling.
std::optional< TEXT_INFO > GetPinNumberInfo(int aShadowWidth)
void SetRenderParameters(int aNameThickness, int aNumberThickness, bool aShowElectricalType, bool aShowAltIcons)
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
VECTOR2I GetSize() const
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
A round rectangle shape, based on a rectangle and a radius.
Definition roundrect.h:36
void TransformToPolygon(SHAPE_POLY_SET &aBuffer, int aMaxError) const
Get the polygonal representation of the roundrect.
Definition roundrect.cpp:83
SCHEMATIC_SETTINGS & Settings() const
Object to handle a bitmap image that can be inserted in a schematic.
Definition sch_bitmap.h:40
VECTOR2I GetPosition() const override
REFERENCE_IMAGE & GetReferenceImage()
Definition sch_bitmap.h:51
Base class for a bus or wire entry.
bool IsStartDangling() const
VECTOR2I GetPosition() const override
bool IsEndDangling() const
virtual STROKE_PARAMS GetStroke() const override
int GetPenWidth() const override
VECTOR2I GetEnd() const
LINE_STYLE GetEffectiveLineStyle() const
Class for a wire to bus entry.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool IsBus() const
void CreateGraphicShape(const RENDER_SETTINGS *aSettings, std::vector< VECTOR2I > &aPoints, const VECTOR2I &aPos) const override
Calculate the graphic shape (a polygon) associated to the text.
virtual bool IsDangling() const override
Determines dangling state from connectivity and cached connected rule areas.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
VECTOR2I GetPosition() const override
FIELD_T GetId() const
Definition sch_field.h:120
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0, const wxString &aVariantName=wxEmptyString) const
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
VECTOR2I GetParentPosition() const
void CreateGraphicShape(const RENDER_SETTINGS *aRenderSettings, std::vector< VECTOR2I > &aPoints, const VECTOR2I &aPos) const override
Calculate the graphic shape (a polygon) associated to the text.
VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:52
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void CreateGraphicShape(const RENDER_SETTINGS *aSettings, std::vector< VECTOR2I > &aPoints, const VECTOR2I &aPos) const override
Calculate the graphic shape (a polygon) associated to the text.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:260
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:254
int GetBodyStyle() const
Definition sch_item.h:248
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition sch_item.cpp:457
int GetUnit() const
Definition sch_item.h:239
bool IsPrivate() const
Definition sch_item.h:254
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition sch_item.h:341
bool RenderAsBitmap(double aWorldScale) const override
Definition sch_item.cpp:796
bool IsConnectivityDirty() const
Definition sch_item.h:588
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:473
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:363
wxString GetClass() const override
Return the class name.
Definition sch_item.h:178
const KIFONT::METRICS & GetFontMetrics() const
Definition sch_item.cpp:764
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:773
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition sch_item.h:183
int GetEffectiveDiameter() const
VECTOR2I GetPosition() const override
bool IsDangling() const override
Definition sch_label.h:337
COLOR4D GetLabelColor() const
LABEL_FLAG_SHAPE GetShape() const
Definition sch_label.h:180
std::vector< SCH_FIELD > & GetFields()
Definition sch_label.h:212
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
void SetStartPoint(const VECTOR2I &aPosition)
Definition sch_line.h:140
std::vector< VECTOR3I > BuildWireWithHopShape(const SCH_SCREEN *aScreen, double aArcRadius) const
For wires only: build the list of points to draw the shape using segments and 180 deg arcs Points are...
bool IsWire() const
Return true if the line is a wire.
Definition sch_line.cpp:992
bool IsStartDangling() const
Definition sch_line.h:303
void SetLineColor(const COLOR4D &aColor)
Definition sch_line.cpp:281
void SetLineWidth(const int aSize)
Definition sch_line.cpp:347
LINE_STYLE GetEffectiveLineStyle() const
Definition sch_line.cpp:334
VECTOR2I GetMidPoint() const
Definition sch_line.h:146
VECTOR2I GetEndPoint() const
Definition sch_line.h:148
VECTOR2I GetStartPoint() const
Definition sch_line.h:139
bool IsEndDangling() const
Definition sch_line.h:304
bool IsBus() const
Return true if the line is a bus.
Definition sch_line.cpp:998
void SetLineStyle(const LINE_STYLE aStyle)
Definition sch_line.cpp:318
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition sch_line.h:202
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:149
const wxString & GetOperatingPoint() const
Definition sch_line.h:347
SCH_LAYER_ID GetColorLayer() const
VECTOR2I GetPosition() const override
Definition sch_marker.h:102
int GetSize() const
VECTOR2I GetPosition() const override
int GetNumberTextSize() const
Definition sch_pin.cpp:681
int GetLength() const
Definition sch_pin.cpp:301
const wxString & GetOperatingPoint() const
Definition sch_pin.h:337
void SetName(const wxString &aName)
Definition sch_pin.cpp:423
bool IsGlobalPower() const
Return whether this pin forms a global power connection: i.e., is part of a power symbol and of type ...
Definition sch_pin.cpp:359
bool IsVisible() const
Definition sch_pin.cpp:391
VECTOR2I GetPinRoot() const
Definition sch_pin.cpp:705
bool IsDangling() const override
Definition sch_pin.cpp:465
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition sch_pin.h:96
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:258
int GetNameTextSize() const
Definition sch_pin.cpp:657
const wxString & GetShownName() const
Definition sch_pin.cpp:581
PIN_LAYOUT_CACHE & GetLayoutCache() const
Get the layout cache associated with this pin.
Definition sch_pin.h:351
void SetOperatingPoint(const wxString &aText)
Definition sch_pin.h:338
void SetType(ELECTRICAL_PINTYPE aType)
Definition sch_pin.cpp:335
GRAPHIC_PINSHAPE GetShape() const
Definition sch_pin.cpp:280
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:315
std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const override
Make a set of SHAPE objects representing the SCH_SHAPE.
Definition sch_shape.h:112
LINE_STYLE GetEffectiveLineStyle() const
Definition sch_shape.h:63
int GetHatchLineWidth() const override
Definition sch_shape.h:71
STROKE_PARAMS GetStroke() const override
Definition sch_shape.h:58
VECTOR2I GetPosition() const override
Definition sch_shape.h:85
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
Definition sch_sheet.h:88
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
VECTOR2I GetSize() const
Definition sch_sheet.h:142
VECTOR2I GetPosition() const override
Definition sch_sheet.h:491
const BOX2I GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
KIGFX::COLOR4D GetBorderColor() const
Definition sch_sheet.h:148
bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flags.
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:228
KIGFX::COLOR4D GetBackgroundColor() const
Definition sch_sheet.h:151
Schematic symbol object.
Definition sch_symbol.h:76
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
BOX2I GetBodyAndPinsBoundingBox() const override
Return a bounding box for the symbol body and pins but not the fields.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:867
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
static void BuildLocalPowerIconShape(std::vector< SCH_SHAPE > &aShapeList, const VECTOR2D &aPos, double aSize, double aLineWidth, bool aHorizontal)
Build the local power pin indicator icon shape, at coordinate aPos.
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
int GetOrientation() const override
Get the display symbol orientation.
bool IsSymbolLikePowerLocalLabel() const
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:184
BOX2I GetBodyBoundingBox() const override
Return a bounding box for the symbol body but not the pins or fields.
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
int GetColSpan() const
int GetRowSpan() const
std::vector< SCH_TABLECELL * > GetCells() const
Definition sch_table.h:157
void DrawBorders(const std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const STROKE_PARAMS &aStroke)> &aCallback) const
virtual wxString GetShownText(const RENDER_SETTINGS *aSettings, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
VECTOR2I GetDrawPos() const override
VECTOR2I GetPosition() const override
Definition sch_text.h:147
VECTOR2I GetOffsetToMatchSCH_FIELD(SCH_RENDER_SETTINGS *aRenderSettings) const
Definition sch_text.cpp:456
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_text.cpp:297
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition sch_text.cpp:318
virtual VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition sch_text.cpp:76
Definition seg.h:42
VECTOR2I B
Definition seg.h:50
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
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)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
const SEG & GetSeg() const
An abstract shape on 2D plane.
Definition shape.h:126
Simple container to manage line stroke parameters.
int GetWidth() const
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
static void Stroke(const SHAPE *aShape, LINE_STYLE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, const std::function< void(const VECTOR2I &a, const VECTOR2I &b)> &aStroker)
const TRANSFORM & GetTransform() const
Definition symbol.h:247
KIGFX::COLOR4D m_Color
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
KIFONT::FONT * m_Font
@ LIGHTRED
Definition color4d.h:65
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition common.cpp:62
The common library.
#define DANGLING_SYMBOL_SIZE
The size of the rectangle indicating an unconnected wire or label.
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define UNSELECTED_END_SIZE
The size of the rectangle indicating the anchor of a text object (including fields)
#define TEXT_ANCHOR_SIZE
The default pin len value when creating pins(can be changed in preference menu)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:408
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:407
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:416
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:415
#define IS_SHOWN_AS_BITMAP
#define ENDPOINT
ends. (Used to support dragging.)
#define IS_DANGLING
indicates a pin is dangling
#define STARTPOINT
When a line is selected, these flags indicate which.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:46
@ FILLED_WITH_COLOR
Definition eda_shape.h:60
@ NO_FILL
Definition eda_shape.h:57
@ REVERSE_HATCH
Definition eda_shape.h:62
@ HATCH
Definition eda_shape.h:61
@ FILLED_WITH_BG_BODYCOLOR
Definition eda_shape.h:59
@ FILLED_SHAPE
Fill with object color.
Definition eda_shape.h:58
@ CROSS_HATCH
Definition eda_shape.h:63
int GetPenSizeForDemiBold(int aTextSize)
Definition gr_text.cpp:43
int GetPenSizeForNormal(int aTextSize)
Definition gr_text.cpp:61
int ClampTextPenSize(int aPenSize, int aSize, bool aStrict)
Pen width should not allow characters to become cluttered up in their own fatness.
Definition gr_text.cpp:73
const wxChar *const traceSchPainter
Flag to enable debug output of schematic painter operations.
@ LAYER_DRAW_BITMAPS
Draw images.
Definition layer_ids.h:284
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:449
@ LAYER_DANGLING
Definition layer_ids.h:477
@ LAYER_SHAPES_BACKGROUND
Definition layer_ids.h:483
@ LAYER_SHEETNAME
Definition layer_ids.h:472
@ LAYER_SCHEMATIC_ANCHOR
Definition layer_ids.h:500
@ LAYER_SHEETLABEL
Definition layer_ids.h:475
@ LAYER_PINNUM
Definition layer_ids.h:458
@ LAYER_RULE_AREAS
Definition layer_ids.h:465
@ LAYER_DEVICE
Definition layer_ids.h:466
@ LAYER_SHEET_BACKGROUND
Definition layer_ids.h:485
@ LAYER_EXCLUDED_FROM_SIM
Definition layer_ids.h:482
@ LAYER_BRIGHTENED
Definition layer_ids.h:491
@ LAYER_HIDDEN
Definition layer_ids.h:492
@ LAYER_HIERLABEL
Definition layer_ids.h:457
@ LAYER_PINNAM
Definition layer_ids.h:459
@ LAYER_PRIVATE_NOTES
Definition layer_ids.h:468
@ LAYER_HOVERED
Definition layer_ids.h:490
@ LAYER_GLOBLABEL
Definition layer_ids.h:456
@ LAYER_WIRE
Definition layer_ids.h:452
@ LAYER_NOTES
Definition layer_ids.h:467
@ LAYER_NET_COLOR_HIGHLIGHT
Definition layer_ids.h:493
@ LAYER_PIN
Definition layer_ids.h:470
@ LAYER_VALUEPART
Definition layer_ids.h:461
@ LAYER_BUS
Definition layer_ids.h:453
@ LAYER_FIELDS
Definition layer_ids.h:462
@ LAYER_DEVICE_BACKGROUND
Definition layer_ids.h:484
@ LAYER_LOCLABEL
Definition layer_ids.h:455
@ LAYER_SHEETFIELDS
Definition layer_ids.h:474
@ LAYER_REFERENCEPART
Definition layer_ids.h:460
@ LAYER_NETCLASS_REFS
Definition layer_ids.h:464
@ LAYER_NOTES_BACKGROUND
Definition layer_ids.h:469
@ LAYER_OP_CURRENTS
Definition layer_ids.h:502
@ LAYER_SHEET
Definition layer_ids.h:471
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:495
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:488
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:463
@ LAYER_OP_VOLTAGES
Definition layer_ids.h:501
@ LAYER_SHEETFILENAME
Definition layer_ids.h:473
@ LAYER_DNP_MARKER
Definition layer_ids.h:478
@ LAYER_NOCONNECT
Definition layer_ids.h:476
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:96
MATRIX3x3< double > MATRIX3x3D
Definition matrix3x3.h:473
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
static void boxText(KIGFX::GAL &aGal, const wxString &aText, const VECTOR2D &aPosition, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics)
static void bitmapText(KIGFX::GAL &aGal, const wxString &aText, const VECTOR2D &aPosition, const TEXT_ATTRIBUTES &aAttrs)
EESCHEMA_SETTINGS * eeconfig()
static void strokeText(KIGFX::GAL &aGal, const wxString &aText, const VECTOR2D &aPosition, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr)
static void knockoutText(KIGFX::GAL &aGal, const wxString &aText, const VECTOR2D &aPosition, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics)
static void drawAltPinModesIcon(GAL &aGal, const VECTOR2D &aPos, double aSize, bool aBaseSelected, bool aRotate, int aExtraLineWidth, const COLOR4D &aColor)
Draw an alternate pin mode indicator icon.
static bool isFieldsLayer(int aLayer)
static BOX2I GetTextExtents(const wxString &aText, const VECTOR2D &aPosition, KIFONT::FONT &aFont, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:100
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
see class PGM_BASE
@ PT_NC
not connected (must be left open)
Definition pin_type.h:50
#define TARGET_BUSENTRY_RADIUS
Class to handle a set of SCH_ITEMs.
#define BITMAP_FONT_SIZE_THRESHOLD
Definition sch_item.cpp:47
@ F_DOT
Definition sch_label.h:107
@ F_ROUND
Definition sch_label.h:108
#define TARGET_PIN_RADIUS
Definition sch_pin.h:37
Utility functions for working with shapes.
wxString GetDefaultVariantName()
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
int PrintableCharCount(const wxString &aString)
Return the number of printable (ie: non-formatting) chars.
LINE_STYLE
Dashed line types.
void OrientAndMirrorSymbolItems(LIB_SYMBOL *aSymbol, int aOrientation)
Rotate and/or mirror graphic objects of LIB_SYMBOL aSymbol according to aOrientMirror.
@ VALUE
Field Value of part, i.e. "3.3K".
KIBIS top(path, &reporter)
VECTOR2I center
int radius
VECTOR2I end
int delta
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
wxLogTrace helper definitions.
const VECTOR2I CalcArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
Definition trigo.cpp:521
@ SCH_GROUP_T
Definition typeinfo.h:177
@ SCH_TABLE_T
Definition typeinfo.h:169
@ SCH_LINE_T
Definition typeinfo.h:167
@ LIB_SYMBOL_T
Definition typeinfo.h:152
@ SCH_NO_CONNECT_T
Definition typeinfo.h:164
@ SCH_SYMBOL_T
Definition typeinfo.h:176
@ SCH_TABLECELL_T
Definition typeinfo.h:170
@ SCH_FIELD_T
Definition typeinfo.h:154
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:175
@ SCH_LABEL_T
Definition typeinfo.h:171
@ SCH_SHEET_T
Definition typeinfo.h:179
@ SCH_MARKER_T
Definition typeinfo.h:162
@ SCH_SHAPE_T
Definition typeinfo.h:153
@ SCH_RULE_AREA_T
Definition typeinfo.h:174
@ SCH_HIER_LABEL_T
Definition typeinfo.h:173
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:166
@ SCH_SHEET_PIN_T
Definition typeinfo.h:178
@ SCH_TEXT_T
Definition typeinfo.h:155
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:165
@ SCH_BITMAP_T
Definition typeinfo.h:168
@ SCH_TEXTBOX_T
Definition typeinfo.h:156
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:172
@ SCH_JUNCTION_T
Definition typeinfo.h:163
@ SCH_PIN_T
Definition typeinfo.h:157
constexpr int sign(T val)
Definition util.h:145
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694