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
1791 if( aLine->Schematic() ) // Can be nullptr when run from the color selection panel
1792 hopOverScale = aLine->Schematic()->Settings().m_HopOverScale;
1793
1794 if( eeschemaCfg )
1795 {
1796 highlightNetclassColors = eeschemaCfg->m_Selection.highlight_netclass_colors;
1797 highlightAlpha = eeschemaCfg->m_Selection.highlight_netclass_colors_alpha;
1798 }
1799
1800 if( !highlightNetclassColors && drawingNetColorHighlights )
1801 return;
1802
1803 if( drawingNetColorHighlights && !( aLine->IsWire() || aLine->IsBus() ) )
1804 return;
1805
1806 if( m_schSettings.m_OverrideItemColors && drawingNetColorHighlights )
1807 return;
1808
1809 if( m_schSettings.IsPrinting() && drawingShadows )
1810 return;
1811
1812 if( drawingShadows && !( aLine->IsBrightened() || aLine->IsSelected() ) )
1813 return;
1814
1815 // Line end dangling status isn't updated until the line is finished drawing, so don't warn
1816 // them about ends that are probably connected
1817 if( aLine->IsNew() && drawingDangling )
1818 return;
1819
1820 COLOR4D color = getRenderColor( aLine, aLine->GetLayer(), drawingShadows );
1821 float width = getLineWidth( aLine, drawingShadows, drawingNetColorHighlights );
1822 LINE_STYLE lineStyle = aLine->GetEffectiveLineStyle();
1823
1824 if( highlightNetclassColors )
1825 {
1826 // Force default color for nets we are going to highlight
1827 if( drawingWires )
1828 color = m_schSettings.GetLayerColor( LAYER_WIRE );
1829 else if( drawingBusses )
1830 color = m_schSettings.GetLayerColor( LAYER_BUS );
1831 }
1832
1833 if( drawingNetColorHighlights )
1834 {
1835 // Don't draw highlights for default-colored nets
1836 if( ( aLine->IsWire() && color == m_schSettings.GetLayerColor( LAYER_WIRE ) )
1837 || ( aLine->IsBus() && color == m_schSettings.GetLayerColor( LAYER_BUS ) ) )
1838 {
1839 return;
1840 }
1841
1842 color = color.WithAlpha( color.a * highlightAlpha );
1843 }
1844
1845 if( ( drawingDangling || drawingShadows ) && !aLine->IsNew() )
1846 {
1847 if( ( aLine->IsWire() && aLine->IsStartDangling() )
1848 || ( drawingShadows && aLine->IsSelected() && !aLine->HasFlag( STARTPOINT ) ) )
1849 {
1850 COLOR4D indicatorColor( color );
1851
1852 if( drawingShadows && !aLine->HasFlag( STARTPOINT ) )
1853 indicatorColor.Invert();
1854
1855 drawDanglingIndicator( aLine->GetStartPoint(), indicatorColor, KiROUND( width ),
1856 aLine->IsWire() && aLine->IsStartDangling(), drawingShadows,
1857 aLine->IsBrightened() );
1858 }
1859
1860 if( ( aLine->IsWire() && aLine->IsEndDangling() )
1861 || ( drawingShadows && aLine->IsSelected() && !aLine->HasFlag( ENDPOINT ) ) )
1862 {
1863 COLOR4D indicatorColor( color );
1864
1865 if( drawingShadows && !aLine->HasFlag( ENDPOINT ) )
1866 indicatorColor.Invert();
1867
1868 drawDanglingIndicator( aLine->GetEndPoint(), indicatorColor, KiROUND( width ),
1869 aLine->IsWire() && aLine->IsEndDangling(), drawingShadows,
1870 aLine->IsBrightened() );
1871 }
1872 }
1873
1874 if( drawingDangling )
1875 return;
1876
1877 if( drawingOP && !aLine->GetOperatingPoint().IsEmpty() )
1878 {
1879 int textSize = getOperatingPointTextSize();
1880 VECTOR2I pos = aLine->GetMidPoint();
1881 int textOffset = KiROUND( textSize * 0.22 );
1882 TEXT_ATTRIBUTES attrs;
1883
1884 if( aLine->GetStartPoint().y == aLine->GetEndPoint().y )
1885 {
1886 pos.y -= textOffset;
1889 }
1890 else
1891 {
1892 pos.x += KiROUND( textOffset * 1.2 );
1895 }
1896
1897 attrs.m_Font = KIFONT::FONT::GetFont(); // always use stroke font for performance
1898 attrs.m_Size = VECTOR2I( textSize, textSize );
1899 attrs.m_StrokeWidth = GetPenSizeForDemiBold( textSize );
1900 attrs.m_Color = m_schSettings.GetLayerColor( LAYER_OP_VOLTAGES );
1901
1902 knockoutText( *m_gal, aLine->GetOperatingPoint(), pos, attrs, aLine->GetFontMetrics() );
1903 }
1904
1905 if( drawingOP )
1906 return;
1907
1908 m_gal->SetIsStroke( true );
1909 m_gal->SetIsFill( false );
1910 m_gal->SetStrokeColor( color );
1911 m_gal->SetLineWidth( width );
1912
1913 std::vector<VECTOR3I> curr_wire_shape;
1914
1915 if( aLine->IsWire() && hopOverScale > 0.0 )
1916 {
1917 double lineWidth = getLineWidth( aLine, false, drawingNetColorHighlights );
1918 double arcRadius = lineWidth * hopOverScale;
1919 curr_wire_shape = aLine->BuildWireWithHopShape( m_schematic->GetCurrentScreen(), arcRadius );
1920 }
1921 else
1922 {
1923 curr_wire_shape.emplace_back( aLine->GetStartPoint().x, aLine->GetStartPoint().y, 0 );
1924 curr_wire_shape.emplace_back( aLine->GetEndPoint().x, aLine->GetEndPoint().y, 0 );
1925 }
1926
1927 for( size_t ii = 1; ii < curr_wire_shape.size(); ii++ )
1928 {
1929 VECTOR2I start( curr_wire_shape[ii-1].x, curr_wire_shape[ii-1].y );
1930
1931 if( curr_wire_shape[ii-1].z == 0 ) // This is the start point of a segment
1932 // there are always 2 points in list for a segment
1933 {
1934 VECTOR2I end( curr_wire_shape[ii].x, curr_wire_shape[ii].y );
1935 drawLine( start, end, lineStyle,
1936 ( lineStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows ), width );
1937 }
1938 else // This is the start point of a arc. there are always 3 points in list for an arc
1939 {
1940 // Hop are a small arc, so use a solid line style gives best results
1941 VECTOR2I arc_middle( curr_wire_shape[ii].x, curr_wire_shape[ii].y );
1942 ii++;
1943 VECTOR2I arc_end( curr_wire_shape[ii].x, curr_wire_shape[ii].y );
1944 ii++;
1945
1946 VECTOR2D dstart = start;
1947 VECTOR2D dmid = arc_middle;
1948 VECTOR2D dend = arc_end;
1949 VECTOR2D center = CalcArcCenter( dstart, dmid, dend );
1950
1951 EDA_ANGLE startAngle( dstart - center );
1952 EDA_ANGLE midAngle( dmid - center );
1953 EDA_ANGLE endAngle( dend - center );
1954
1955 EDA_ANGLE angle1 = midAngle - startAngle;
1956 EDA_ANGLE angle2 = endAngle - midAngle;
1957
1958 EDA_ANGLE angle = angle1.Normalize180() + angle2.Normalize180();
1959
1960 m_gal->DrawArc( center, ( dstart - center ).EuclideanNorm(), startAngle, angle );
1961 }
1962 }
1963}
1964
1965
1966void SCH_PAINTER::draw( const SCH_SHAPE* aShape, int aLayer, bool aDimmed )
1967{
1968 if( !isUnitAndConversionShown( aShape ) )
1969 return;
1970
1971 if( aShape->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
1972 return;
1973
1974 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
1975
1976 if( m_schSettings.IsPrinting() && drawingShadows )
1977 return;
1978
1979 LINE_STYLE lineStyle = aShape->GetEffectiveLineStyle();
1980 COLOR4D color = getRenderColor( aShape, aLayer, drawingShadows, aDimmed );
1981
1982 if( drawingShadows && !( aShape->IsBrightened() || aShape->IsSelected() ) )
1983 return;
1984
1985 auto drawShape =
1986 [&]( const SCH_SHAPE* shape )
1987 {
1988 switch( shape->GetShape() )
1989 {
1990 case SHAPE_T::ARC:
1991 {
1992 VECTOR2D start = shape->GetStart();
1993 VECTOR2D mid = shape->GetArcMid();
1994 VECTOR2D end = shape->GetEnd();
1995 VECTOR2D center = CalcArcCenter( start, mid, end );
1996
1997 EDA_ANGLE startAngle( start - center );
1998 EDA_ANGLE midAngle( mid - center );
1999 EDA_ANGLE endAngle( end - center );
2000
2001 EDA_ANGLE angle1 = midAngle - startAngle;
2002 EDA_ANGLE angle2 = endAngle - midAngle;
2003
2004 EDA_ANGLE angle = angle1.Normalize180() + angle2.Normalize180();
2005
2006 m_gal->DrawArc( center, ( start - center ).EuclideanNorm(), startAngle, angle );
2007 break;
2008 }
2009
2010 case SHAPE_T::CIRCLE:
2011 m_gal->DrawCircle( shape->GetPosition(), shape->GetRadius() );
2012 break;
2013
2014 case SHAPE_T::RECTANGLE:
2015 if( shape->GetCornerRadius() > 0 )
2016 {
2017 // Creates a normalized ROUNDRECT item
2018 // (GetRectangleWidth() and GetRectangleHeight() can be < 0 with transforms
2019 ROUNDRECT rr( SHAPE_RECT( shape->GetPosition(),
2020 shape->GetRectangleWidth(),
2021 shape->GetRectangleHeight() ),
2022 shape->GetCornerRadius(), true /* normalize */ );
2023 SHAPE_POLY_SET poly;
2024 rr.TransformToPolygon( poly, shape->GetMaxError() );
2025 m_gal->DrawPolygon( poly );
2026 }
2027 else
2028 {
2029 m_gal->DrawRectangle( shape->GetPosition(), shape->GetEnd() );
2030 }
2031 break;
2032
2033 case SHAPE_T::POLY:
2034 {
2035 const std::vector<SHAPE*> polySegments = shape->MakeEffectiveShapes( true );
2036
2037 if( !polySegments.empty() )
2038 {
2039 std::deque<VECTOR2D> pts;
2040
2041 for( SHAPE* polySegment : polySegments )
2042 pts.push_back( static_cast<SHAPE_SEGMENT*>( polySegment )->GetSeg().A );
2043
2044 pts.push_back( static_cast<SHAPE_SEGMENT*>( polySegments.back() )->GetSeg().B );
2045
2046 for( SHAPE* polySegment : polySegments )
2047 delete polySegment;
2048
2049 m_gal->DrawPolygon( pts );
2050 }
2051 break;
2052 }
2053
2054 case SHAPE_T::BEZIER:
2055 {
2056 m_gal->DrawCurve( shape->GetStart(), shape->GetBezierC1(),
2057 shape->GetBezierC2(), shape->GetEnd() );
2058 break;
2059 }
2060
2061 default:
2062 UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
2063 }
2064 };
2065
2066 if( aLayer == LAYER_SELECTION_SHADOWS )
2067 {
2068 if( eeconfig()->m_Selection.fill_shapes )
2069 {
2070 // Consider a NAND gate. We have no idea which side of the arc is "inside"
2071 // so we can't reliably fill.
2072 if( aShape->GetShape() == SHAPE_T::ARC )
2073 m_gal->SetIsFill( aShape->IsSolidFill() );
2074 else
2075 m_gal->SetIsFill( true );
2076
2077 m_gal->SetFillColor( color );
2078 }
2079 else
2080 {
2081 m_gal->SetIsFill( false );
2082 }
2083
2084 // We still always draw the stroke, as otherwise single-segment shapes
2085 // (like a line) don't get a shadow, and special-casing them looks inconsistent.
2086 m_gal->SetIsStroke( true );
2087 m_gal->SetLineWidth( getLineWidth( aShape, true ) );
2088 m_gal->SetStrokeColor( color );
2089
2090 drawShape( aShape );
2091 }
2092 else if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_NOTES_BACKGROUND
2093 || aLayer == LAYER_SHAPES_BACKGROUND )
2094 {
2095 switch( aShape->GetFillMode() )
2096 {
2097 case FILL_T::NO_FILL:
2098 break;
2099
2101 // Fill in the foreground layer
2102 break;
2103
2104 case FILL_T::HATCH:
2107 aShape->UpdateHatching();
2108 m_gal->SetIsFill( false );
2109 m_gal->SetIsStroke( true );
2110 m_gal->SetStrokeColor( color );
2111 m_gal->SetLineWidth( aShape->GetHatchLineWidth() );
2112
2113 for( const SEG& seg : aShape->GetHatchLines() )
2114 m_gal->DrawLine( seg.A, seg.B );
2115
2116 break;
2117
2120 // Do not fill the shape in B&W print mode, to avoid to visible items inside the shape
2121 if( !m_schSettings.PrintBlackAndWhiteReq() )
2122 {
2123 m_gal->SetIsFill( true );
2124 m_gal->SetIsStroke( false );
2125 m_gal->SetFillColor( color );
2126
2127 drawShape( aShape );
2128 }
2129 break;
2130
2131 default:
2132 wxFAIL_MSG( wxT( "Unsupported fill type" ) );
2133 }
2134 }
2135 else if( aLayer == LAYER_DEVICE || aLayer == LAYER_NOTES || aLayer == LAYER_PRIVATE_NOTES
2136 || aLayer == LAYER_RULE_AREAS )
2137 {
2138 // Shapes filled with the device colour must be filled in the foreground
2139 if( aShape->GetFillMode() == FILL_T::FILLED_SHAPE )
2140 {
2141 m_gal->SetIsFill( true );
2142 m_gal->SetIsStroke( false );
2143 m_gal->SetFillColor( color );
2144
2145 drawShape( aShape );
2146 }
2147
2148 float lineWidth = getLineWidth( aShape, drawingShadows );
2149
2150 if( lineWidth > 0 )
2151 {
2152 m_gal->SetIsFill( false );
2153 m_gal->SetIsStroke( true );
2154 m_gal->SetLineWidth( lineWidth );
2155 m_gal->SetStrokeColor( color );
2156
2157 if( lineStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows )
2158 {
2159 drawShape( aShape );
2160 }
2161 else
2162 {
2163 std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
2164
2165 for( SHAPE* shape : shapes )
2166 {
2167 STROKE_PARAMS::Stroke( shape, lineStyle, KiROUND( lineWidth ), &m_schSettings,
2168 [this]( const VECTOR2I& a, const VECTOR2I& b )
2169 {
2170 // DrawLine has problem with 0 length lines so enforce minimum
2171 if( a == b )
2172 m_gal->DrawLine( a+1, b );
2173 else
2174 m_gal->DrawLine( a, b );
2175 } );
2176 }
2177
2178 for( SHAPE* shape : shapes )
2179 delete shape;
2180 }
2181 }
2182 }
2183}
2184
2185
2186void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed )
2187{
2188 if( !isUnitAndConversionShown( aText ) )
2189 return;
2190
2191 if( aText->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2192 return;
2193
2194 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2195
2196 if( m_schSettings.IsPrinting() && drawingShadows )
2197 return;
2198
2199 if( drawingShadows && !( aText->IsBrightened() || aText->IsSelected() ) )
2200 return;
2201
2202 switch( aText->Type() )
2203 {
2204 case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break;
2205 case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break;
2206 case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break;
2207 case SCH_DIRECTIVE_LABEL_T: aLayer = LAYER_NETCLASS_REFS; break;
2208 case SCH_LABEL_T: aLayer = LAYER_LOCLABEL; break;
2209 case SCH_TEXT_T: aLayer = aText->GetParentSymbol() ? LAYER_DEVICE
2210 : LAYER_NOTES; break;
2211 default: aLayer = LAYER_NOTES; break;
2212 }
2213
2214 COLOR4D color = getRenderColor( aText, aLayer, drawingShadows, aDimmed );
2215
2216 if( m_schematic )
2217 {
2218 SCH_CONNECTION* conn = nullptr;
2219
2220 if( !aText->IsConnectivityDirty() )
2221 conn = aText->Connection();
2222
2223 if( conn && conn->IsBus() )
2224 color = getRenderColor( aText, LAYER_BUS, drawingShadows );
2225 }
2226
2227 if( !( aText->IsVisible() || aText->IsForceVisible() ) )
2228 {
2229 if( m_schSettings.m_IsSymbolEditor || eeconfig()->m_Appearance.show_hidden_fields )
2230 color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
2231 else
2232 return;
2233 }
2234
2235 m_gal->SetStrokeColor( color );
2236 m_gal->SetFillColor( color );
2237 m_gal->SetHoverColor( color );
2238
2239 wxString shownText( aText->GetShownText( true ) );
2240 VECTOR2I text_offset = aText->GetSchematicTextOffset( &m_schSettings );
2241 TEXT_ATTRIBUTES attrs = aText->GetAttributes();
2242 KIFONT::FONT* font = getFont( aText );
2243
2244 attrs.m_Angle = aText->GetDrawRotation();
2245 attrs.m_StrokeWidth = KiROUND( getTextThickness( aText ) );
2246
2247 if( drawingShadows && font->IsOutline() )
2248 {
2249 VECTOR2I pos( aText->GetDrawPos() );
2250
2251 pos += text_offset;
2252
2253 if( aText->Type() == SCH_TEXT_T )
2254 pos += aText->GetOffsetToMatchSCH_FIELD( nullptr );
2255
2256 // Trying to draw glyph-shaped shadows on outline text is a fool's errand. Just box it.
2257 boxText( *m_gal, shownText, pos, attrs, aText->GetFontMetrics() );
2258 }
2259 else if( aText->GetLayer() == LAYER_DEVICE )
2260 {
2261 BOX2I bBox = aText->GetBoundingBox();
2262 VECTOR2D pos = bBox.Centre();
2263
2264 // Due to the fact a shadow text can be drawn left or right aligned, it needs to be
2265 // offset by shadowWidth/2 to be drawn at the same place as normal text.
2266 double shadowOffset = 0.0;
2267
2268 if( drawingShadows )
2269 {
2270 double shadowWidth = getShadowWidth( !aText->IsSelected() );
2271 attrs.m_StrokeWidth += getShadowWidth( !aText->IsSelected() );
2272
2273 const double adjust = 1.2f; // Value chosen after tests
2274 shadowOffset = shadowWidth/2.0f * adjust;
2275 }
2276
2277 if( attrs.m_Angle == ANGLE_VERTICAL )
2278 {
2279 switch( attrs.m_Halign )
2280 {
2282 pos.y = bBox.GetBottom() + shadowOffset;
2283 break;
2285 pos.y = ( bBox.GetTop() + bBox.GetBottom() ) / 2.0;
2286 break;
2288 pos.y = bBox.GetTop() - shadowOffset;
2289 break;
2291 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
2292 break;
2293 }
2294 }
2295 else
2296 {
2297 switch( attrs.m_Halign )
2298 {
2300 pos.x = bBox.GetLeft() - shadowOffset;
2301 break;
2303 pos.x = ( bBox.GetLeft() + bBox.GetRight() ) / 2.0;
2304 break;
2306 pos.x = bBox.GetRight() + shadowOffset;
2307 break;
2309 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
2310 break;
2311 }
2312 }
2313
2314 // Because the text vertical position is the bounding box center, the text is drawn as
2315 // vertically centered.
2317
2318 strokeText( *m_gal, shownText, pos, attrs, aText->GetFontMetrics() );
2319 }
2320 else if( drawingShadows )
2321 {
2322 m_gal->SetIsFill( false );
2323 m_gal->SetIsStroke( true );
2324 attrs.m_StrokeWidth += KiROUND( getShadowWidth( !aText->IsSelected() ) );
2325 attrs.m_Underlined = false;
2326
2327 // Fudge factors to match 6.0 positioning
2328 // New text stroking has width dependent offset but we need to center the shadow on the
2329 // stroke. NB this offset is in font.cpp also.
2330 int fudge = KiROUND( getShadowWidth( !aText->IsSelected() ) / 1.52 );
2331
2332 if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_0 )
2333 text_offset.x -= fudge;
2334 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_90 )
2335 text_offset.y -= fudge;
2336 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_0 )
2337 text_offset.x += fudge;
2338 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_90 )
2339 text_offset.y += fudge;
2340
2341 strokeText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs, aText->GetFontMetrics() );
2342 }
2343 else
2344 {
2345 wxString activeUrl;
2346
2347 if( aText->IsRollover() && !aText->IsMoving() )
2348 {
2349 // Highlight any urls found within the text
2350 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2351
2352 // Highlight the whole text if it has a link definition
2353 if( aText->HasHyperlink() )
2354 {
2355 attrs.m_Hover = true;
2356 attrs.m_Underlined = true;
2357 activeUrl = aText->GetHyperlink();
2358 }
2359 }
2360
2361 if( aText->Type() == SCH_TEXT_T )
2362 text_offset += aText->GetOffsetToMatchSCH_FIELD( nullptr );
2363
2364 if( nonCached( aText ) && aText->RenderAsBitmap( m_gal->GetWorldScale() )
2365 && !shownText.Contains( wxT( "\n" ) ) )
2366 {
2367 bitmapText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs );
2368 const_cast<SCH_TEXT*>( aText )->SetFlags( IS_SHOWN_AS_BITMAP );
2369 }
2370 else
2371 {
2372 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2373
2374 if( !aText->IsRollover() && font->IsOutline() )
2375 cache = aText->GetRenderCache( font, shownText, text_offset );
2376
2377 if( cache )
2378 {
2379 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2380 m_gal->DrawGlyphs( *cache );
2381 }
2382 else
2383 {
2384 strokeText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs,
2385 aText->GetFontMetrics(), aText->GetRolloverPos(), &activeUrl );
2386 }
2387
2388 const_cast<SCH_TEXT*>( aText )->ClearFlags( IS_SHOWN_AS_BITMAP );
2389 }
2390
2391 aText->SetActiveUrl( activeUrl );
2392 }
2393
2394 // Draw anchor
2395 if( aText->IsSelected() )
2396 {
2397 bool showAnchor;
2398
2399 switch( aText->Type() )
2400 {
2401 case SCH_TEXT_T:
2402 showAnchor = true;
2403 break;
2404
2405 case SCH_LABEL_T:
2406 // Don't clutter things up if we're already showing a dangling indicator
2407 showAnchor = !static_cast<const SCH_LABEL*>( aText )->IsDangling();
2408 break;
2409
2411 case SCH_HIER_LABEL_T:
2412 case SCH_GLOBAL_LABEL_T:
2413 case SCH_SHEET_PIN_T:
2414 // These all have shapes and so don't need anchors
2415 showAnchor = false;
2416 break;
2417
2418 default:
2419 showAnchor = false;
2420 break;
2421 }
2422
2423 if( showAnchor )
2424 drawAnchor( aText->GetPosition(), drawingShadows );
2425 }
2426}
2427
2428
2429void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer, bool aDimmed )
2430{
2431 if( aTextBox->Type() == SCH_TABLECELL_T )
2432 {
2433 const SCH_TABLECELL* cell = static_cast<const SCH_TABLECELL*>( aTextBox );
2434
2435 if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
2436 return;
2437 }
2438
2439 if( !isUnitAndConversionShown( aTextBox ) )
2440 return;
2441
2442 if( aTextBox->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2443 return;
2444
2445 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2446
2447 if( m_schSettings.IsPrinting() && drawingShadows )
2448 return;
2449
2450 COLOR4D color = getRenderColor( aTextBox, aLayer, drawingShadows, aDimmed );
2451 COLOR4D bg = m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
2452 float borderWidth = getLineWidth( aTextBox, drawingShadows );
2453 KIFONT::FONT* font = getFont( aTextBox );
2454
2455 auto drawText =
2456 [&]()
2457 {
2458 wxString shownText = aTextBox->GetShownText( true );
2459 TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes();
2460 wxString activeUrl;
2461
2462 attrs.m_Angle = aTextBox->GetDrawRotation();
2463 attrs.m_StrokeWidth = KiROUND( getTextThickness( aTextBox ) );
2464
2465 if( aTextBox->IsRollover() && !aTextBox->IsMoving() )
2466 {
2467 // Highlight any urls found within the text
2468 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2469
2470 // Highlight the whole text if it has a link definition
2471 if( aTextBox->HasHyperlink() )
2472 {
2473 attrs.m_Hover = true;
2474 attrs.m_Underlined = true;
2475 activeUrl = aTextBox->GetHyperlink();
2476 }
2477 }
2478
2479 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2480
2481 if( !aTextBox->IsRollover() && font->IsOutline() )
2482 cache = aTextBox->GetRenderCache( font, shownText );
2483
2484 if( cache )
2485 {
2486 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2487 m_gal->DrawGlyphs( *cache );
2488 }
2489 else
2490 {
2491 strokeText( *m_gal, shownText, aTextBox->GetDrawPos(), attrs,
2492 aTextBox->GetFontMetrics(), aTextBox->GetRolloverPos(), &activeUrl );
2493 }
2494
2495 aTextBox->SetActiveUrl( activeUrl );
2496 };
2497
2498 if( drawingShadows && !( aTextBox->IsBrightened() || aTextBox->IsSelected() ) )
2499 return;
2500
2501 m_gal->SetFillColor( color );
2502 m_gal->SetStrokeColor( color );
2503 m_gal->SetHoverColor( color );
2504
2505 if( aLayer == LAYER_SELECTION_SHADOWS )
2506 {
2507 m_gal->SetIsFill( true );
2508 m_gal->SetIsStroke( false );
2509 m_gal->SetLineWidth( borderWidth );
2510
2511 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2512 }
2513 else if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_NOTES_BACKGROUND
2514 || aLayer == LAYER_SHAPES_BACKGROUND )
2515 {
2516 // Do not fill the shape in B&W print mode, to avoid to visible items
2517 // inside the shape
2518 if( aTextBox->IsSolidFill() && !m_schSettings.PrintBlackAndWhiteReq() )
2519 {
2520 m_gal->SetIsFill( true );
2521 m_gal->SetIsStroke( false );
2522 m_gal->SetLineWidth( borderWidth );
2523
2524 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2525 }
2526 }
2527 else if( aLayer == LAYER_DEVICE || aLayer == LAYER_NOTES || aLayer == LAYER_PRIVATE_NOTES )
2528 {
2529 drawText();
2530
2531 if( aTextBox->Type() != SCH_TABLECELL_T && borderWidth > 0 )
2532 {
2533 COLOR4D borderColor = aTextBox->GetStroke().GetColor();
2534 LINE_STYLE borderStyle = aTextBox->GetEffectiveLineStyle();
2535 double transparency = aTextBox->GetForcedTransparency();
2536
2537 if( m_schSettings.m_OverrideItemColors || aTextBox->IsBrightened()
2538 || borderColor == COLOR4D::UNSPECIFIED )
2539 {
2540 borderColor = m_schSettings.GetLayerColor( aLayer );
2541 }
2542
2543 if( transparency > 0.0 )
2544 borderColor = borderColor.WithAlpha( borderColor.a * ( 1.0 - transparency ) );
2545
2546 if( aDimmed )
2547 {
2548 borderColor = borderColor.Mix( bg, 0.5f );
2549 borderColor.Desaturate( );
2550 }
2551
2552 m_gal->SetIsFill( false );
2553 m_gal->SetIsStroke( true );
2554 m_gal->SetStrokeColor( borderColor );
2555 m_gal->SetLineWidth( borderWidth );
2556
2557 if( borderStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows )
2558 {
2559 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2560 }
2561 else
2562 {
2563 std::vector<SHAPE*> shapes = aTextBox->MakeEffectiveShapes( true );
2564
2565 for( SHAPE* shape : shapes )
2566 {
2567 STROKE_PARAMS::Stroke( shape, borderStyle, KiROUND( borderWidth ),
2569 [this]( const VECTOR2I& a, const VECTOR2I& b )
2570 {
2571 // DrawLine has problem with 0 length lines so enforce minimum
2572 if( a == b )
2573 m_gal->DrawLine( a+1, b );
2574 else
2575 m_gal->DrawLine( a, b );
2576 } );
2577 }
2578
2579 for( SHAPE* shape : shapes )
2580 delete shape;
2581 }
2582 }
2583 }
2584}
2585
2586
2587void SCH_PAINTER::draw( const SCH_TABLE* aTable, int aLayer, bool aDimmed )
2588{
2589 if( aTable->GetCells().empty() )
2590 return;
2591
2592 for( SCH_TABLECELL* cell : aTable->GetCells() )
2593 draw( cell, aLayer, aDimmed );
2594
2595 if( aLayer == LAYER_SELECTION_SHADOWS )
2596 return;
2597
2598 aTable->DrawBorders(
2599 [&]( const VECTOR2I& ptA, const VECTOR2I& ptB, const STROKE_PARAMS& stroke )
2600 {
2601 int lineWidth = stroke.GetWidth();
2602 COLOR4D color = stroke.GetColor();
2603 LINE_STYLE lineStyle = stroke.GetLineStyle();
2604
2605 if( lineWidth == 0 )
2606 lineWidth = m_schSettings.GetDefaultPenWidth();
2607
2608 if( color == COLOR4D::UNSPECIFIED )
2609 color = m_schSettings.GetLayerColor( LAYER_NOTES );
2610
2611 if( lineStyle == LINE_STYLE::DEFAULT )
2612 lineStyle = LINE_STYLE::SOLID;
2613
2614 m_gal->SetIsFill( false );
2615 m_gal->SetIsStroke( true );
2616 m_gal->SetStrokeColor( color );
2617 m_gal->SetLineWidth( (float) lineWidth );
2618
2619 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2620 {
2621 m_gal->DrawLine( ptA, ptB );
2622 }
2623 else
2624 {
2625 SHAPE_SEGMENT seg( ptA, ptB );
2626 STROKE_PARAMS::Stroke( &seg, lineStyle, lineWidth, &m_schSettings,
2627 [&]( const VECTOR2I& a, const VECTOR2I& b )
2628 {
2629 // DrawLine has problem with 0 length lines so enforce minimum
2630 if( a == b )
2631 m_gal->DrawLine( a+1, b );
2632 else
2633 m_gal->DrawLine( a, b );
2634 } );
2635 }
2636 } );
2637}
2638
2639
2640wxString SCH_PAINTER::expandLibItemTextVars( const wxString& aSourceText,
2641 const SCH_SYMBOL* aSymbolContext )
2642{
2643 std::function<bool( wxString* )> symbolResolver =
2644 [&]( wxString* token ) -> bool
2645 {
2646 if( !m_schematic )
2647 return false;
2648
2649 return aSymbolContext->ResolveTextVar( &m_schematic->CurrentSheet(), token );
2650 };
2651
2652 return ExpandTextVars( aSourceText, &symbolResolver );
2653}
2654
2655
2656void SCH_PAINTER::draw( const SCH_SYMBOL* aSymbol, int aLayer )
2657{
2658 auto t1 = std::chrono::high_resolution_clock::now();
2659 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2660
2661 std::optional<SCH_SHEET_PATH> optSheetPath;
2662
2663 wxString variantName;
2664
2665 if( m_schematic )
2666 {
2667 optSheetPath = m_schematic->CurrentSheet();
2668 variantName = m_schematic->GetCurrentVariant();
2669 wxLogTrace( traceSchPainter,
2670 "SCH_PAINTER::draw symbol %s: Current sheet path='%s', variant='%s', size=%zu, empty=%d",
2671 aSymbol->m_Uuid.AsString(),
2672 variantName.IsEmpty() ? GetDefaultVariantName() : variantName,
2673 optSheetPath->Path().AsString(),
2674 optSheetPath->size(),
2675 optSheetPath->empty() ? 1 : 0 );
2676 }
2677
2678 SCH_SHEET_PATH* sheetPath = optSheetPath ? &optSheetPath.value() : nullptr;
2679 bool DNP = aSymbol->GetDNP( sheetPath, variantName );
2680 bool markExclusion = eeconfig()->m_Appearance.mark_sim_exclusions && aSymbol->GetExcludedFromSim( sheetPath,
2681 variantName );
2682
2683 if( m_schSettings.IsPrinting() && drawingShadows )
2684 return;
2685
2686 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
2687 {
2688 for( const SCH_FIELD& field : aSymbol->GetFields() )
2689 draw( &field, aLayer, DNP );
2690 }
2691
2692 if( isFieldsLayer( aLayer ) )
2693 return;
2694
2695 if( drawingShadows && !( aSymbol->IsBrightened() || aSymbol->IsSelected() ) )
2696 {
2697 // Don't exit here; symbol may still have selected pins
2698 // return;
2699 }
2700
2701 int unit = m_schematic ? aSymbol->GetUnitSelection( &m_schematic->CurrentSheet() ) : 1;
2702 int bodyStyle = aSymbol->GetBodyStyle();
2703
2704 // Use dummy symbol if the actual couldn't be found (or couldn't be locked).
2705 LIB_SYMBOL* originalSymbol =
2706 aSymbol->GetLibSymbolRef() ? aSymbol->GetLibSymbolRef().get() : LIB_SYMBOL::GetDummy();
2707 std::vector<SCH_PIN*> originalPins = originalSymbol->GetGraphicalPins( unit, bodyStyle );
2708
2709 // Copy the source so we can re-orient and translate it.
2710 auto tCopy1 = std::chrono::high_resolution_clock::now();
2711 LIB_SYMBOL tempSymbol( *originalSymbol, nullptr, false );
2712 auto tCopy2 = std::chrono::high_resolution_clock::now();
2713
2714 if( std::chrono::duration_cast<std::chrono::microseconds>( tCopy2 - tCopy1 ).count() > 100 )
2715 {
2716 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw symbol copy %s: %lld us", aSymbol->m_Uuid.AsString(),
2717 std::chrono::duration_cast<std::chrono::microseconds>( tCopy2 - tCopy1 ).count() );
2718 }
2719
2720 std::vector<SCH_PIN*> tempPins = tempSymbol.GetGraphicalPins( unit, bodyStyle );
2721
2722 tempSymbol.SetFlags( aSymbol->GetFlags() );
2723
2724 OrientAndMirrorSymbolItems( &tempSymbol, aSymbol->GetOrientation() );
2725
2726 for( SCH_ITEM& tempItem : tempSymbol.GetDrawItems() )
2727 {
2728 tempItem.SetFlags( aSymbol->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2729 tempItem.Move( aSymbol->GetPosition() );
2730
2731 if( tempItem.Type() == SCH_TEXT_T )
2732 {
2733 SCH_TEXT* textItem = static_cast<SCH_TEXT*>( &tempItem );
2734
2735 if( textItem->HasTextVars() )
2736 textItem->SetText( expandLibItemTextVars( textItem->GetText(), aSymbol ) );
2737 }
2738 else if( tempItem.Type() == SCH_TEXTBOX_T )
2739 {
2740 SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( &tempItem );
2741
2742 if( textboxItem->HasTextVars() )
2743 textboxItem->SetText( expandLibItemTextVars( textboxItem->GetText(), aSymbol ) );
2744 }
2745 }
2746
2747 // Copy the pin info from the symbol to the temp pins
2748 for( unsigned i = 0; i < tempPins.size(); ++ i )
2749 {
2750 SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
2751 SCH_PIN* tempPin = tempPins[ i ];
2752
2753 if( !symbolPin )
2754 continue;
2755
2756 tempPin->ClearFlags();
2757 tempPin->SetFlags( symbolPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2758 // IS_SHOWN_AS_BITMAP
2759
2760 tempPin->SetName( expandLibItemTextVars( symbolPin->GetShownName(), aSymbol ) );
2761 tempPin->SetType( symbolPin->GetType() );
2762 tempPin->SetShape( symbolPin->GetShape() );
2763
2764 if( symbolPin->IsDangling() )
2765 tempPin->SetFlags( IS_DANGLING );
2766 else
2767 tempPin->ClearFlags( IS_DANGLING );
2768
2769 tempPin->SetOperatingPoint( symbolPin->GetOperatingPoint() );
2770 }
2771
2772 draw( &tempSymbol, aLayer, false, aSymbol->GetUnit(), aSymbol->GetBodyStyle(), DNP );
2773
2774 for( unsigned i = 0; i < tempPins.size(); ++i )
2775 {
2776 SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
2777 SCH_PIN* tempPin = tempPins[ i ];
2778
2779 if( !symbolPin )
2780 continue;
2781
2782 symbolPin->ClearFlags();
2783 tempPin->ClearFlags( IS_DANGLING ); // Clear this temporary flag
2784 symbolPin->SetFlags( tempPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2785 // IS_SHOWN_AS_BITMAP
2786 }
2787
2788 // Draw DNP and EXCLUDE from SIM markers.
2789 // These drawings are associated to the symbol body, so draw them only when the LAYER_DEVICE
2790 // is drawn (to avoid draw artifacts).
2791 if( DNP && aLayer == LAYER_DEVICE )
2792 {
2793 COLOR4D marker_color = m_schSettings.GetLayerColor( LAYER_DNP_MARKER );
2794 BOX2I bbox = aSymbol->GetBodyBoundingBox();
2795 BOX2I pins = aSymbol->GetBodyAndPinsBoundingBox();
2796 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
2797 std::max( bbox.GetY() - pins.GetY(),
2798 pins.GetEnd().y - bbox.GetEnd().y ) );
2799 int strokeWidth = 3 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
2800
2801 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
2802 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
2803 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
2804
2805 VECTOR2I pt1 = bbox.GetOrigin();
2806 VECTOR2I pt2 = bbox.GetEnd();
2807
2809 m_gal->AdvanceDepth();
2810 m_gal->SetIsStroke( true );
2811 m_gal->SetIsFill( true );
2812 m_gal->SetStrokeColor( marker_color );
2813 m_gal->SetFillColor( marker_color );
2814
2815 m_gal->DrawSegment( pt1, pt2, strokeWidth );
2816 std::swap( pt1.x, pt2.x );
2817 m_gal->DrawSegment( pt1, pt2, strokeWidth );
2818 }
2819
2820 if( markExclusion && aLayer == LAYER_DEVICE )
2821 {
2822 COLOR4D marker_color = m_schSettings.GetLayerColor( LAYER_EXCLUDED_FROM_SIM );
2823 BOX2I bbox = aSymbol->GetBodyBoundingBox();
2824 int strokeWidth = schIUScale.MilsToIU( ADVANCED_CFG::GetCfg().m_ExcludeFromSimulationLineWidth );
2825
2826 bbox.Inflate( KiROUND( strokeWidth * 0.5 ) );
2827
2829 m_gal->AdvanceDepth();
2830 m_gal->SetIsStroke( true );
2831 m_gal->SetIsFill( true );
2832 m_gal->SetStrokeColor( marker_color );
2833 m_gal->SetFillColor( marker_color );
2834
2835 m_gal->DrawSegment( bbox.GetPosition(), VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), strokeWidth );
2836 m_gal->DrawSegment( VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), bbox.GetEnd(), strokeWidth );
2837 m_gal->DrawSegment( bbox.GetEnd(), VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), strokeWidth );
2838 m_gal->DrawSegment( VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), bbox.GetPosition(), strokeWidth );
2839
2840 int offset = 2 * strokeWidth;
2841 VECTOR2D center = bbox.GetEnd() + VECTOR2D( offset + strokeWidth, -offset );
2842 VECTOR2D left = center + VECTOR2D( -offset, 0 );
2843 VECTOR2D right = center + VECTOR2D( offset, 0 );
2844 VECTOR2D top = center + VECTOR2D( 0, offset );
2845 VECTOR2D bottom = center + VECTOR2D( 0, -offset );
2846
2847 m_gal->SetFillColor( marker_color.WithAlpha( 0.1 ) );
2848 m_gal->DrawCircle( center, offset );
2849 m_gal->AdvanceDepth();
2850 m_gal->SetFillColor( marker_color );
2851 m_gal->DrawCurve( left, top, bottom, right, 1 );
2852 }
2853
2854 auto t2 = std::chrono::high_resolution_clock::now();
2855
2856 if( std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() > 100 )
2857 {
2858 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw symbol %s: %lld us", aSymbol->m_Uuid.AsString(),
2859 std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() );
2860 }
2861}
2862
2863
2864void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
2865{
2866 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2867
2868 if( m_schSettings.IsPrinting() && drawingShadows )
2869 return;
2870
2871 if( drawingShadows && !( aField->IsBrightened() || aField->IsSelected() ) )
2872 return;
2873
2874 if( !isUnitAndConversionShown( aField ) )
2875 return;
2876
2877 if( aField->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2878 return;
2879
2880 // Must check layer as fields are sometimes drawn by their parent rather than directly
2881 // from the view.
2882 std::vector<int> layers = aField->ViewGetLayers();
2883
2884 if( std::find( layers.begin(), layers.end(), aLayer ) == layers.end() )
2885 return;
2886
2887 aLayer = aField->GetLayer();
2888
2889 COLOR4D color = getRenderColor( aField, aLayer, drawingShadows, aDimmed );
2890
2891 if( !( aField->IsVisible() || aField->IsForceVisible() ) )
2892 {
2894 : m_schSettings.m_ShowHiddenFields;
2895
2896 if( force_show )
2897 color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows, aDimmed );
2898 else
2899 return;
2900 }
2901
2902 SCH_SHEET_PATH* sheetPath = nullptr;
2903 wxString variant;
2904
2905 if( m_schematic )
2906 {
2907 sheetPath = &m_schematic->CurrentSheet();
2908 variant = m_schematic->GetCurrentVariant();
2909 }
2910
2911 wxString shownText = aField->GetShownText( sheetPath, true, 0, variant );
2912
2913 if( shownText.IsEmpty() )
2914 return;
2915
2916 // Calculate the text orientation according to the parent orientation.
2917 EDA_ANGLE orient = aField->GetTextAngle();
2918
2919 if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
2920 {
2921 if( static_cast<SCH_SYMBOL*>( aField->GetParent() )->GetTransform().y1 )
2922 {
2923 // Rotate symbol 90 degrees.
2924 if( orient.IsHorizontal() )
2925 orient = ANGLE_VERTICAL;
2926 else
2927 orient = ANGLE_HORIZONTAL;
2928 }
2929 }
2930
2931 /*
2932 * Calculate the text justification, according to the symbol orientation/mirror.
2933 * This is a bit complicated due to cumulative calculations:
2934 * - numerous cases (mirrored or not, rotation)
2935 * - the DrawGraphicText function recalculate also H and H justifications according to the
2936 * text orientation.
2937 * - when symbol is mirrored, the text is not mirrored and justifications are complicated
2938 * to calculate so the easier way is to use no justifications (centered text) and use
2939 * GetBoundingBox to know the text coordinate considered as centered
2940 */
2941 BOX2I bbox = aField->GetBoundingBox();
2942
2943 if( aField->GetParent() && aField->GetParent()->Type() == SCH_GLOBAL_LABEL_T )
2944 {
2945 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( aField->GetParent() );
2946 bbox.Offset( label->GetSchematicTextOffset( &m_schSettings ) );
2947 }
2948
2949 if( m_schSettings.GetDrawBoundingBoxes() )
2950 drawItemBoundingBox( aField );
2951
2952 TEXT_ATTRIBUTES attributes = aField->GetAttributes();
2953 attributes.m_StrokeWidth = KiROUND( getTextThickness( aField ) );
2954
2955 m_gal->SetStrokeColor( color );
2956 m_gal->SetFillColor( color );
2957 m_gal->SetHoverColor( color );
2958
2959 if( drawingShadows && getFont( aField )->IsOutline() )
2960 {
2961 // Trying to draw glyph-shaped shadows on outline text is a fool's errand. Just box it.
2962 VECTOR2I textpos = bbox.Centre();
2963
2964 attributes.m_Halign = GR_TEXT_H_ALIGN_CENTER;
2965 attributes.m_Valign = GR_TEXT_V_ALIGN_CENTER;
2966 attributes.m_Angle = orient;
2967 boxText( *m_gal, shownText, textpos, attributes, aField->GetFontMetrics() );
2968 }
2969 else
2970 {
2971 VECTOR2I textpos = bbox.Centre();
2972
2973 attributes.m_Halign = GR_TEXT_H_ALIGN_CENTER;
2974 attributes.m_Valign = GR_TEXT_V_ALIGN_CENTER;
2975 attributes.m_Angle = orient;
2976
2977 if( drawingShadows )
2978 attributes.m_StrokeWidth += getShadowWidth( !aField->IsSelected() );
2979
2980 if( aField->IsRollover() && !aField->IsMoving() )
2981 {
2982 // Highlight any urls found within the text
2983 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2984
2985 // Highlight the whole text if it has a link definition
2986 if( aField->HasHyperlink() )
2987 {
2988 attributes.m_Hover = true;
2989 attributes.m_Underlined = true;
2990 }
2991 }
2992
2993 if( nonCached( aField ) && aField->RenderAsBitmap( m_gal->GetWorldScale() ) )
2994 {
2995 bitmapText( *m_gal, shownText, textpos, attributes );
2996 const_cast<SCH_FIELD*>( aField )->SetFlags( IS_SHOWN_AS_BITMAP );
2997 }
2998 else
2999 {
3000 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
3001
3002 if( !aField->IsRollover() )
3003 cache = aField->GetRenderCache( shownText, textpos, attributes );
3004
3005 if( cache )
3006 {
3007 m_gal->SetLineWidth( attributes.m_StrokeWidth );
3008 m_gal->DrawGlyphs( *cache );
3009 }
3010 else
3011 {
3012 strokeText( *m_gal, shownText, textpos, attributes, aField->GetFontMetrics(),
3013 aField->GetRolloverPos() );
3014 }
3015
3016 const_cast<SCH_FIELD*>( aField )->ClearFlags( IS_SHOWN_AS_BITMAP );
3017 }
3018 }
3019
3020 if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
3021 {
3022 SCH_SYMBOL* parent = static_cast<SCH_SYMBOL*>( aField->GetParent() );
3023 bool rotated = !orient.IsHorizontal();
3024
3025 VECTOR2D pos;
3026 double size = bbox.GetHeight() / 1.5;
3027
3028 if( rotated )
3029 {
3030 pos = VECTOR2D( bbox.GetRight() - bbox.GetWidth() / 6.0,
3031 bbox.GetBottom() + bbox.GetWidth() / 2.0 );
3032 size = bbox.GetWidth() / 1.5;
3033 }
3034 else
3035 {
3036 pos = VECTOR2D( bbox.GetLeft() - bbox.GetHeight() / 2.0,
3037 bbox.GetBottom() - bbox.GetHeight() / 6.0 );
3038 }
3039
3040 if( parent->IsSymbolLikePowerLocalLabel() && aField->GetId() == FIELD_T::VALUE )
3041 drawLocalPowerIcon( pos, size, rotated, color, drawingShadows, aField->IsBrightened() );
3042 }
3043
3044 // Draw anchor or umbilical line
3045 if( aField->IsMoving() && m_schematic )
3046 {
3047 VECTOR2I parentPos = aField->GetParentPosition();
3048
3049 m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() );
3050 m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
3051 m_gal->DrawLine( aField->GetPosition(), parentPos );
3052 }
3053 else if( aField->IsSelected() )
3054 {
3055 drawAnchor( aField->GetPosition(), drawingShadows );
3056 }
3057}
3058
3059
3060void SCH_PAINTER::draw( const SCH_GLOBALLABEL* aLabel, int aLayer, bool aDimmed )
3061{
3062 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3063
3064 if( m_schSettings.IsPrinting() && drawingShadows )
3065 return;
3066
3067 bool drawingDangling = aLayer == LAYER_DANGLING;
3068
3069 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3070 {
3071 for( const SCH_FIELD& field : aLabel->GetFields() )
3072 draw( &field, aLayer, false );
3073 }
3074
3075 if( isFieldsLayer( aLayer ) )
3076 return;
3077
3078 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3079 return;
3080
3081 COLOR4D color = getRenderColor( aLabel, LAYER_GLOBLABEL, drawingShadows, aDimmed, true );
3082
3083 if( drawingDangling )
3084 {
3085 if( aLabel->IsDangling() )
3086 {
3087 drawDanglingIndicator( aLabel->GetTextPos(), color,
3088 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3089 drawingShadows, aLabel->IsBrightened() );
3090 }
3091
3092 return;
3093 }
3094
3095 std::vector<VECTOR2I> pts;
3096 std::deque<VECTOR2D> pts2;
3097
3098 aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
3099
3100 for( const VECTOR2I& p : pts )
3101 pts2.emplace_back( VECTOR2D( p.x, p.y ) );
3102
3103 m_gal->SetIsStroke( true );
3104 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3105 m_gal->SetStrokeColor( color );
3106
3107 if( drawingShadows )
3108 {
3109 m_gal->SetIsFill( eeconfig()->m_Selection.fill_shapes );
3110 m_gal->SetFillColor( color );
3111 m_gal->DrawPolygon( pts2 );
3112 }
3113 else
3114 {
3115 m_gal->SetIsFill( false );
3116 m_gal->DrawPolyline( pts2 );
3117 }
3118
3119 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3120}
3121
3122
3123void SCH_PAINTER::draw( const SCH_LABEL* aLabel, int aLayer, bool aDimmed )
3124{
3125 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3126
3127 if( m_schSettings.IsPrinting() && drawingShadows )
3128 return;
3129
3130 bool drawingDangling = aLayer == LAYER_DANGLING;
3131
3132 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3133 {
3134 for( const SCH_FIELD& field : aLabel->GetFields() )
3135 draw( &field, aLayer, false );
3136 }
3137
3138 if( isFieldsLayer( aLayer ) )
3139 return;
3140
3141 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3142 return;
3143
3144 COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows, aDimmed, true );
3145
3146 if( drawingDangling )
3147 {
3148 if( aLabel->IsDangling() )
3149 {
3150 drawDanglingIndicator( aLabel->GetTextPos(), color,
3151 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3152 drawingShadows, aLabel->IsBrightened() );
3153 }
3154
3155 return;
3156 }
3157
3158 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3159}
3160
3161
3162void SCH_PAINTER::draw( const SCH_HIERLABEL* aLabel, int aLayer, bool aDimmed )
3163{
3164 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3165
3166 if( m_schSettings.IsPrinting() && drawingShadows )
3167 return;
3168
3169 bool drawingDangling = aLayer == LAYER_DANGLING;
3170
3171 if( !( drawingShadows || drawingDangling ) || eeconfig()->m_Selection.draw_selected_children )
3172 {
3173 for( const SCH_FIELD& field : aLabel->GetFields() )
3174 draw( &field, aLayer, false );
3175 }
3176
3177 if( isFieldsLayer( aLayer ) )
3178 return;
3179
3180 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3181 return;
3182
3183 COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows, aDimmed, true );
3184
3185 if( drawingDangling )
3186 {
3187 if( aLabel->IsDangling() )
3188 {
3189 drawDanglingIndicator( aLabel->GetTextPos(), color,
3190 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3191 drawingShadows, aLabel->IsBrightened() );
3192 }
3193
3194 return;
3195 }
3196
3197 std::vector<VECTOR2I> i_pts;
3198 std::deque<VECTOR2D> d_pts;
3199
3200 aLabel->CreateGraphicShape( &m_schSettings, i_pts, (VECTOR2I)aLabel->GetTextPos() );
3201
3202 for( const VECTOR2I& i_pt : i_pts )
3203 d_pts.emplace_back( VECTOR2D( i_pt.x, i_pt.y ) );
3204
3205 m_gal->SetIsFill( true );
3206 m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
3207 m_gal->SetIsStroke( true );
3208 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3209 m_gal->SetStrokeColor( color );
3210 m_gal->DrawPolyline( d_pts );
3211
3212 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3213}
3214
3215
3216void SCH_PAINTER::draw( const SCH_DIRECTIVE_LABEL* aLabel, int aLayer, bool aDimmed )
3217{
3218 if( !eeconfig()->m_Appearance.show_directive_labels && !aLabel->IsSelected() )
3219 return;
3220
3221 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3222
3223 if( m_schSettings.IsPrinting() && drawingShadows )
3224 return;
3225
3226 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3227 {
3228 for( const SCH_FIELD& field : aLabel->GetFields() )
3229 draw( &field, aLayer, false );
3230 }
3231
3232 if( isFieldsLayer( aLayer ) )
3233 return;
3234
3235 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3236 return;
3237
3238 COLOR4D color = getRenderColor( aLabel, LAYER_NETCLASS_REFS, drawingShadows, aDimmed, true );
3239
3240 if( aLayer == LAYER_DANGLING )
3241 {
3242 if( aLabel->IsDangling() )
3243 {
3244 drawDanglingIndicator( aLabel->GetTextPos(), color,
3245 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3246 drawingShadows, aLabel->IsBrightened() );
3247 }
3248
3249 return;
3250 }
3251
3252 std::vector<VECTOR2I> pts;
3253 std::deque<VECTOR2D> pts2;
3254
3255 aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
3256
3257 for( const VECTOR2I& p : pts )
3258 pts2.emplace_back( VECTOR2D( p.x, p.y ) );
3259
3260 m_gal->SetIsFill( false );
3261 m_gal->SetFillColor( color );
3262 m_gal->SetIsStroke( true );
3263 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3264 m_gal->SetStrokeColor( color );
3265
3266 if( aLabel->GetShape() == LABEL_FLAG_SHAPE::F_DOT )
3267 {
3268 m_gal->DrawLine( pts2[0], pts2[1] );
3269 m_gal->SetIsFill( true );
3270 m_gal->DrawCircle( pts2[2], ( pts2[2] - pts2[1] ).EuclideanNorm() );
3271 }
3272 else if( aLabel->GetShape() == LABEL_FLAG_SHAPE::F_ROUND )
3273 {
3274 m_gal->DrawLine( pts2[0], pts2[1] );
3275 m_gal->DrawCircle( pts2[2], ( pts2[2] - pts2[1] ).EuclideanNorm() );
3276 }
3277 else
3278 {
3279 m_gal->DrawPolyline( pts2 );
3280 }
3281}
3282
3283
3284void SCH_PAINTER::draw( const SCH_SHEET* aSheet, int aLayer )
3285{
3286 SCH_SHEET_PATH* sheetPath = nullptr;
3287 wxString variant;
3288 bool DNP = false;
3289
3290 if( m_schematic )
3291 {
3292 sheetPath = &m_schematic->CurrentSheet();
3293 variant = m_schematic->GetCurrentVariant();
3294 DNP = aSheet->GetDNP( sheetPath, variant );
3295 }
3296
3297 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3298 bool markExclusion = eeconfig()->m_Appearance.mark_sim_exclusions
3299 && aSheet->GetExcludedFromSim( sheetPath, variant );
3300
3301 if( m_schSettings.IsPrinting() && drawingShadows )
3302 return;
3303
3304 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3305 {
3306 for( const SCH_FIELD& field : aSheet->GetFields() )
3307 draw( &field, aLayer, DNP );
3308
3309 for( SCH_SHEET_PIN* sheetPin : aSheet->GetPins() )
3310 draw( static_cast<SCH_HIERLABEL*>( sheetPin ), aLayer, DNP );
3311 }
3312
3313 if( isFieldsLayer( aLayer ) )
3314 return;
3315
3316 VECTOR2D pos = aSheet->GetPosition();
3317 VECTOR2D size = aSheet->GetSize();
3318
3319 if( aLayer == LAYER_SHEET_BACKGROUND )
3320 {
3321 // Do not fill the shape in B&W print mode, to avoid to visible items
3322 // inside the shape
3323 if( !m_schSettings.PrintBlackAndWhiteReq() )
3324 {
3325 COLOR4D backgroundColor = aSheet->GetBackgroundColor();
3326
3327 if( m_schSettings.m_OverrideItemColors || backgroundColor == COLOR4D::UNSPECIFIED )
3328 backgroundColor = m_schSettings.GetLayerColor( LAYER_SHEET_BACKGROUND );
3329
3330 // Only draw the background if it has a visible alpha value
3331 if( backgroundColor.a > 0.0 )
3332 {
3333 m_gal->SetFillColor( getRenderColor( aSheet, LAYER_SHEET_BACKGROUND, false ) );
3334 m_gal->SetIsFill( true );
3335 m_gal->SetIsStroke( false );
3336
3337 m_gal->DrawRectangle( pos, pos + size );
3338 }
3339 }
3340 }
3341
3342 if( aLayer == LAYER_SHEET || aLayer == LAYER_SELECTION_SHADOWS )
3343 {
3344 m_gal->SetStrokeColor( getRenderColor( aSheet, LAYER_SHEET, drawingShadows ) );
3345 m_gal->SetIsStroke( true );
3346 m_gal->SetLineWidth( getLineWidth( aSheet, drawingShadows ) );
3347 m_gal->SetIsFill( false );
3348
3349 m_gal->DrawRectangle( pos, pos + size );
3350 }
3351
3352 if( DNP && aLayer == LAYER_SHEET )
3353 {
3354 int layer = LAYER_DNP_MARKER;
3355 BOX2I bbox = aSheet->GetBodyBoundingBox();
3356 BOX2I pins = aSheet->GetBoundingBox();
3357 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
3358 std::max( bbox.GetY() - pins.GetY(), pins.GetEnd().y - bbox.GetEnd().y ) );
3359 int strokeWidth = 3 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
3360
3361 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
3362 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
3363 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
3364
3365 VECTOR2I pt1 = bbox.GetOrigin();
3366 VECTOR2I pt2 = bbox.GetEnd();
3367
3369 m_gal->AdvanceDepth();
3370 m_gal->SetIsStroke( true );
3371 m_gal->SetIsFill( true );
3372 m_gal->SetStrokeColor( m_schSettings.GetLayerColor( layer ) );
3373 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ) );
3374
3375 m_gal->DrawSegment( pt1, pt2, strokeWidth );
3376 std::swap( pt1.x, pt2.x );
3377 m_gal->DrawSegment( pt1, pt2, strokeWidth );
3378 }
3379
3380 if( markExclusion )
3381 {
3382 int layer = LAYER_EXCLUDED_FROM_SIM;
3383 BOX2I bbox = aSheet->GetBodyBoundingBox();
3384 int strokeWidth = schIUScale.MilsToIU( ADVANCED_CFG::GetCfg().m_ExcludeFromSimulationLineWidth );
3385
3386 bbox.Inflate( KiROUND( strokeWidth * 0.5 ) );
3387
3389 m_gal->AdvanceDepth();
3390 m_gal->SetIsStroke( true );
3391 m_gal->SetIsFill( true );
3392 m_gal->SetStrokeColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3393 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3394
3395 m_gal->DrawSegment( bbox.GetPosition(), VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), strokeWidth );
3396 m_gal->DrawSegment( VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), bbox.GetEnd(), strokeWidth );
3397 m_gal->DrawSegment( bbox.GetEnd(), VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), strokeWidth );
3398 m_gal->DrawSegment( VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), bbox.GetPosition(), strokeWidth );
3399
3400 int offset = 2 * strokeWidth;
3401 VECTOR2D center = bbox.GetEnd() + VECTOR2D( offset + strokeWidth, -offset );
3402 VECTOR2D left = center + VECTOR2D( -offset, 0 );
3403 VECTOR2D right = center + VECTOR2D( offset, 0 );
3404 VECTOR2D top = center + VECTOR2D( 0, offset );
3405 VECTOR2D bottom = center + VECTOR2D( 0, -offset );
3406
3407 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.1 ) );
3408 m_gal->DrawCircle( center, offset );
3409 m_gal->AdvanceDepth();
3410 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3411 m_gal->DrawCurve( left, top, bottom, right, 1 );
3412 }
3413}
3414
3415
3416void SCH_PAINTER::draw( const SCH_NO_CONNECT* aNC, int aLayer )
3417{
3418 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3419
3420 if( m_schSettings.IsPrinting() && drawingShadows )
3421 return;
3422
3423 if( drawingShadows && !( aNC->IsBrightened() || aNC->IsSelected() ) )
3424 return;
3425
3426 m_gal->SetIsStroke( true );
3427 m_gal->SetLineWidth( getLineWidth( aNC, drawingShadows ) );
3428 m_gal->SetStrokeColor( getRenderColor( aNC, LAYER_NOCONNECT, drawingShadows ) );
3429 m_gal->SetIsFill( false );
3430
3431 VECTOR2D p = aNC->GetPosition();
3432 int delta = std::max( aNC->GetSize(), m_schSettings.GetDefaultPenWidth() * 3 ) / 2;
3433
3434 m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
3435 m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
3436}
3437
3438
3439void SCH_PAINTER::draw( const SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
3440{
3442 SCH_LINE line( VECTOR2I(), layer );
3443 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3444 bool drawingNetColorHighlights = aLayer == LAYER_NET_COLOR_HIGHLIGHT;
3445 bool drawingDangling = aLayer == LAYER_DANGLING;
3446 bool drawingWires = aLayer == LAYER_WIRE;
3447 bool drawingBusses = aLayer == LAYER_BUS;
3448
3449 if( m_schSettings.IsPrinting() && drawingShadows )
3450 return;
3451
3452 bool highlightNetclassColors = false;
3453 EESCHEMA_SETTINGS* eeschemaCfg = eeconfig();
3454
3455 if( eeschemaCfg )
3456 {
3457 highlightNetclassColors = eeschemaCfg->m_Selection.highlight_netclass_colors;
3458 }
3459
3460 if( !highlightNetclassColors && drawingNetColorHighlights )
3461 return;
3462
3463 if( m_schSettings.m_OverrideItemColors && drawingNetColorHighlights )
3464 return;
3465
3466 if( drawingShadows && !( aEntry->IsBrightened() || aEntry->IsSelected() ) )
3467 return;
3468
3469 if( aEntry->IsSelected() )
3470 {
3471 line.SetSelected();
3472
3473 // Never show unselected endpoints on bus entries
3474 line.SetFlags( STARTPOINT | ENDPOINT );
3475 }
3476 else if( aEntry->IsBrightened() )
3477 {
3478 line.SetBrightened();
3479 }
3480
3481 line.SetStartPoint( aEntry->GetPosition() );
3482 line.SetEndPoint( aEntry->GetEnd() );
3483 line.SetStroke( aEntry->GetStroke() );
3484 line.SetLineWidth( KiROUND( getLineWidth( aEntry, false ) ) );
3485
3486 COLOR4D color = getRenderColor( aEntry, LAYER_WIRE, drawingShadows );
3487
3488 if( aEntry->Type() == SCH_BUS_BUS_ENTRY_T )
3489 color = getRenderColor( aEntry, LAYER_BUS, drawingShadows );
3490
3491 if( highlightNetclassColors )
3492 {
3493 // Force default color for nets we are going to highlight
3494 if( drawingWires )
3495 color = m_schSettings.GetLayerColor( LAYER_WIRE );
3496 else if( drawingBusses )
3497 color = m_schSettings.GetLayerColor( LAYER_BUS );
3498 }
3499
3500 if( drawingNetColorHighlights )
3501 {
3502 // Don't draw highlights for default-colored nets
3503 if( ( aEntry->Type() == SCH_BUS_WIRE_ENTRY_T
3504 && color == m_schSettings.GetLayerColor( LAYER_WIRE ) )
3505 || ( aEntry->Type() == SCH_BUS_BUS_ENTRY_T
3506 && color == m_schSettings.GetLayerColor( LAYER_BUS ) ) )
3507 {
3508 return;
3509 }
3510 }
3511
3512 if( drawingDangling )
3513 {
3514 m_gal->SetIsFill( false );
3515 m_gal->SetIsStroke( true );
3516 m_gal->SetStrokeColor( color.Brightened( 0.3 ) );
3517 m_gal->SetLineWidth( m_schSettings.GetDanglingIndicatorThickness() );
3518
3519 if( aEntry->IsStartDangling() )
3520 {
3521 m_gal->DrawCircle( aEntry->GetPosition(),
3522 aEntry->GetPenWidth() + KiROUND( TARGET_BUSENTRY_RADIUS / 2.0 ) );
3523 }
3524
3525 if( aEntry->IsEndDangling() )
3526 {
3527 m_gal->DrawCircle( aEntry->GetEnd(),
3528 aEntry->GetPenWidth() + KiROUND( TARGET_BUSENTRY_RADIUS / 2.0 ) );
3529 }
3530 }
3531 else
3532 {
3533 line.SetLineColor( color );
3534 line.SetLineStyle( aEntry->GetEffectiveLineStyle() );
3535
3536 draw( &line, aLayer );
3537 }
3538}
3539
3540
3541void SCH_PAINTER::draw( const SCH_BITMAP* aBitmap, int aLayer )
3542{
3543 auto t1 = std::chrono::high_resolution_clock::now();
3544 m_gal->Save();
3545 m_gal->Translate( aBitmap->GetPosition() );
3546
3547 const REFERENCE_IMAGE& refImage = aBitmap->GetReferenceImage();
3548
3549 // When the image scale factor is not 1.0, we need to modify the actual as the image scale
3550 // factor is similar to a local zoom
3551 const double img_scale = refImage.GetImageScale();
3552
3553 if( img_scale != 1.0 )
3554 m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
3555
3556 if( aLayer == LAYER_DRAW_BITMAPS )
3557 {
3558 m_gal->DrawBitmap( refImage.GetImage() );
3559 }
3560
3561 if( aLayer == LAYER_SELECTION_SHADOWS )
3562 {
3563 if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
3564 {
3565 const COLOR4D color = getRenderColor( aBitmap, LAYER_DRAW_BITMAPS, true );
3566 m_gal->SetIsStroke( true );
3567 m_gal->SetStrokeColor( color );
3568 m_gal->SetLineWidth ( getShadowWidth( aBitmap->IsBrightened() ) );
3569 m_gal->SetIsFill( false );
3570
3571 // Draws a bounding box.
3572 VECTOR2D bm_size( refImage.GetSize() );
3573
3574 // bm_size is the actual image size in UI.
3575 // but m_canvas scale was previously set to img_scale
3576 // so recalculate size relative to this image size.
3577 bm_size.x /= img_scale;
3578 bm_size.y /= img_scale;
3579 const VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
3580 const VECTOR2D end = origin + bm_size;
3581
3582 m_gal->DrawRectangle( origin, end );
3583 }
3584 }
3585
3586 m_gal->Restore();
3587 auto t2 = std::chrono::high_resolution_clock::now();
3588
3589 if( std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() > 100 )
3590 {
3591 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw bitmap %s: %lld us", aBitmap->m_Uuid.AsString(),
3592 std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() );
3593 }
3594}
3595
3596
3597void SCH_PAINTER::draw( const SCH_MARKER* aMarker, int aLayer )
3598{
3599 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3600
3601 if( m_schSettings.IsPrinting() && drawingShadows )
3602 return;
3603
3604 if( drawingShadows && !( aMarker->IsBrightened() || aMarker->IsSelected() ) )
3605 return;
3606
3607 COLOR4D color = getRenderColor( aMarker, aMarker->GetColorLayer(), drawingShadows );
3608
3609 m_gal->Save();
3610 m_gal->Translate( aMarker->GetPosition() );
3611 m_gal->SetIsFill( !drawingShadows );
3612 m_gal->SetFillColor( color );
3613 m_gal->SetIsStroke( drawingShadows );
3614 m_gal->SetLineWidth( getLineWidth( aMarker, drawingShadows ) );
3615 m_gal->SetStrokeColor( color );
3616
3617 SHAPE_LINE_CHAIN polygon;
3618 aMarker->ShapeToPolygon( polygon );
3619
3620 m_gal->DrawPolygon( polygon );
3621 m_gal->Restore();
3622}
3623
3624
3625void SCH_PAINTER::draw( const SCH_GROUP* aGroup, int aLayer )
3626{
3627 const bool drawingShadows = false;
3628
3629 if( aLayer == LAYER_SCHEMATIC_ANCHOR )
3630 {
3631 if( aGroup->IsSelected() && !( aGroup->GetParent() && aGroup->GetParent()->IsSelected() ) )
3632 {
3633 // Selected on our own; draw enclosing box
3634 }
3635 else if( aGroup->IsEntered() )
3636 {
3637 // Entered group; draw enclosing box
3638 }
3639 else
3640 {
3641 // Neither selected nor entered; draw nothing at the group level (ie: only draw
3642 // its members)
3643 return;
3644 }
3645
3646 const COLOR4D color = getRenderColor( aGroup, LAYER_SCHEMATIC_ANCHOR, drawingShadows );
3647
3648 m_gal->SetStrokeColor( color );
3649 m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() * 2.0f );
3650
3651 BOX2I bbox = aGroup->GetBoundingBox();
3652 VECTOR2I topLeft = bbox.GetPosition();
3653 VECTOR2I width = VECTOR2I( bbox.GetWidth(), 0 );
3654 VECTOR2I height = VECTOR2I( 0, bbox.GetHeight() );
3655
3656 m_gal->DrawLine( topLeft, topLeft + width );
3657 m_gal->DrawLine( topLeft + width, topLeft + width + height );
3658 m_gal->DrawLine( topLeft + width + height, topLeft + height );
3659 m_gal->DrawLine( topLeft + height, topLeft );
3660
3661 wxString name = aGroup->GetName();
3662
3663 if( name.IsEmpty() )
3664 return;
3665
3666 int ptSize = 12;
3667 int scaledSize = abs( KiROUND( m_gal->GetScreenWorldMatrix().GetScale().x * ptSize ) );
3668 int unscaledSize = schIUScale.MilsToIU( ptSize );
3669
3670 // Scale by zoom a bit, but not too much
3671 int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3;
3672 VECTOR2I textOffset = KiROUND( width.x / 2.0, -textSize * 0.5 );
3673 VECTOR2I titleHeight = KiROUND( 0.0, textSize * 2.0 );
3674
3675 if( PrintableCharCount( name ) * textSize < bbox.GetWidth() )
3676 {
3677 m_gal->DrawLine( topLeft, topLeft - titleHeight );
3678 m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight );
3679 m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width );
3680
3681 TEXT_ATTRIBUTES attrs;
3682 attrs.m_Italic = true;
3685 attrs.m_Size = VECTOR2I( textSize, textSize );
3686 attrs.m_StrokeWidth = GetPenSizeForNormal( textSize );
3687
3688 KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs,
3689 aGroup->GetFontMetrics() );
3690 }
3691 }
3692}
3693
3694
3695void SCH_PAINTER::drawLine( const VECTOR2I& aStartPoint, const VECTOR2I& aEndPoint,
3696 LINE_STYLE aLineStyle, bool aDrawDirectLine, int aWidth )
3697{
3698 if( aDrawDirectLine )
3699 {
3700 m_gal->DrawLine( aStartPoint, aEndPoint );
3701 }
3702 else
3703 {
3704 SHAPE_SEGMENT segment( aStartPoint, aEndPoint );
3705
3706 STROKE_PARAMS::Stroke( &segment, aLineStyle, KiROUND( aWidth ), &m_schSettings,
3707 [&]( const VECTOR2I& start, const VECTOR2I& end )
3708 {
3709 if( start == end )
3710 m_gal->DrawLine( start + 1, end );
3711 else
3712 m_gal->DrawLine( start, end );
3713 } );
3714 }
3715}
3716
3717}; // 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:522
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:203
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:791
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:759
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:768
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:147
VECTOR2I GetPosition() const override
Definition sch_sheet.h:496
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:153
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:233
KIGFX::COLOR4D GetBackgroundColor() const
Definition sch_sheet.h:156
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