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.has_value() )
421 color = COLOR4D( aItem->ResolveText( color.m_text.value(), &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( 0, 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 drawMultiLineTextBox =
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 drawMultiLineTextBox( *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 m_gal->SetIsFill( true );
2108 m_gal->SetIsStroke( false );
2109 m_gal->SetFillColor( color );
2110 m_gal->DrawPolygon( aShape->GetHatching() );
2111 break;
2112
2115 // Do not fill the shape in B&W print mode, to avoid to visible items inside the shape
2116 if( !m_schSettings.PrintBlackAndWhiteReq() )
2117 {
2118 m_gal->SetIsFill( true );
2119 m_gal->SetIsStroke( false );
2120 m_gal->SetFillColor( color );
2121
2122 drawShape( aShape );
2123 }
2124 break;
2125
2126 default:
2127 wxFAIL_MSG( wxT( "Unsupported fill type" ) );
2128 }
2129 }
2130 else if( aLayer == LAYER_DEVICE || aLayer == LAYER_NOTES || aLayer == LAYER_PRIVATE_NOTES
2131 || aLayer == LAYER_RULE_AREAS )
2132 {
2133 // Shapes filled with the device colour must be filled in the foreground
2134 if( aShape->GetFillMode() == FILL_T::FILLED_SHAPE )
2135 {
2136 m_gal->SetIsFill( true );
2137 m_gal->SetIsStroke( false );
2138 m_gal->SetFillColor( color );
2139
2140 drawShape( aShape );
2141 }
2142
2143 float lineWidth = getLineWidth( aShape, drawingShadows );
2144
2145 if( lineWidth > 0 )
2146 {
2147 m_gal->SetIsFill( false );
2148 m_gal->SetIsStroke( true );
2149 m_gal->SetLineWidth( lineWidth );
2150 m_gal->SetStrokeColor( color );
2151
2152 if( lineStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows )
2153 {
2154 drawShape( aShape );
2155 }
2156 else
2157 {
2158 std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
2159
2160 for( SHAPE* shape : shapes )
2161 {
2162 STROKE_PARAMS::Stroke( shape, lineStyle, KiROUND( lineWidth ), &m_schSettings,
2163 [this]( const VECTOR2I& a, const VECTOR2I& b )
2164 {
2165 // DrawLine has problem with 0 length lines so enforce minimum
2166 if( a == b )
2167 m_gal->DrawLine( a+1, b );
2168 else
2169 m_gal->DrawLine( a, b );
2170 } );
2171 }
2172
2173 for( SHAPE* shape : shapes )
2174 delete shape;
2175 }
2176 }
2177 }
2178}
2179
2180
2181void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed )
2182{
2183 if( !isUnitAndConversionShown( aText ) )
2184 return;
2185
2186 if( aText->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2187 return;
2188
2189 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2190
2191 if( m_schSettings.IsPrinting() && drawingShadows )
2192 return;
2193
2194 if( drawingShadows && !( aText->IsBrightened() || aText->IsSelected() ) )
2195 return;
2196
2197 switch( aText->Type() )
2198 {
2199 case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break;
2200 case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break;
2201 case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break;
2202 case SCH_DIRECTIVE_LABEL_T: aLayer = LAYER_NETCLASS_REFS; break;
2203 case SCH_LABEL_T: aLayer = LAYER_LOCLABEL; break;
2204 case SCH_TEXT_T: aLayer = aText->GetParentSymbol() ? LAYER_DEVICE
2205 : LAYER_NOTES; break;
2206 default: aLayer = LAYER_NOTES; break;
2207 }
2208
2209 COLOR4D color = getRenderColor( aText, aLayer, drawingShadows, aDimmed );
2210
2211 if( m_schematic )
2212 {
2213 SCH_CONNECTION* conn = nullptr;
2214
2215 if( !aText->IsConnectivityDirty() )
2216 conn = aText->Connection();
2217
2218 if( conn && conn->IsBus() )
2219 color = getRenderColor( aText, LAYER_BUS, drawingShadows );
2220 }
2221
2222 if( !( aText->IsVisible() || aText->IsForceVisible() ) )
2223 {
2224 if( m_schSettings.m_IsSymbolEditor || eeconfig()->m_Appearance.show_hidden_fields )
2225 color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
2226 else
2227 return;
2228 }
2229
2230 m_gal->SetStrokeColor( color );
2231 m_gal->SetFillColor( color );
2232 m_gal->SetHoverColor( color );
2233
2234 wxString shownText( aText->GetShownText( true ) );
2235 VECTOR2I text_offset = aText->GetSchematicTextOffset( &m_schSettings );
2236 TEXT_ATTRIBUTES attrs = aText->GetAttributes();
2237 KIFONT::FONT* font = getFont( aText );
2238
2239 attrs.m_Angle = aText->GetDrawRotation();
2240 attrs.m_StrokeWidth = KiROUND( getTextThickness( aText ) );
2241
2242 // Adjust text drawn in an outline font to more closely mimic the positioning of
2243 // SCH_FIELD text.
2244 if( font->IsOutline() && aText->Type() == SCH_TEXT_T )
2245 {
2246 BOX2I firstLineBBox = aText->GetTextBox( nullptr, 0 );
2247 int sizeDiff = firstLineBBox.GetHeight() - aText->GetTextSize().y;
2248 int adjust = KiROUND( sizeDiff * 0.35 );
2249 VECTOR2I adjust_offset( 0, adjust );
2250
2251 RotatePoint( adjust_offset, aText->GetDrawRotation() );
2252 text_offset += adjust_offset;
2253 }
2254
2255 if( drawingShadows && font->IsOutline() )
2256 {
2257 BOX2I bBox = aText->GetBoundingBox();
2258 bBox.Inflate( KiROUND( getTextThickness( aText ) * 2 ) );
2259
2260 m_gal->SetIsStroke( false );
2261 m_gal->SetIsFill( true );
2262 m_gal->DrawRectangle( bBox.GetPosition(), bBox.GetEnd() );
2263 }
2264 else if( aText->GetLayer() == LAYER_DEVICE )
2265 {
2266 BOX2I bBox = aText->GetBoundingBox();
2267 VECTOR2D pos = bBox.Centre();
2268
2269 // Due to the fact a shadow text can be drawn left or right aligned, it needs to be
2270 // offset by shadowWidth/2 to be drawn at the same place as normal text.
2271 // For some reason we need to slightly modify this offset for a better look (better
2272 // alignment of shadow shape), for KiCad font only.
2273 double shadowOffset = 0.0;
2274
2275 if( drawingShadows )
2276 {
2277 double shadowWidth = getShadowWidth( !aText->IsSelected() );
2278 attrs.m_StrokeWidth += getShadowWidth( !aText->IsSelected() );
2279
2280 const double adjust = 1.2f; // Value chosen after tests
2281 shadowOffset = shadowWidth/2.0f * adjust;
2282 }
2283
2284 if( attrs.m_Angle == ANGLE_VERTICAL )
2285 {
2286 switch( attrs.m_Halign )
2287 {
2289 pos.y = bBox.GetBottom() + shadowOffset;
2290 break;
2292 pos.y = ( bBox.GetTop() + bBox.GetBottom() ) / 2.0;
2293 break;
2295 pos.y = bBox.GetTop() - shadowOffset;
2296 break;
2298 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
2299 break;
2300 }
2301 }
2302 else
2303 {
2304 switch( attrs.m_Halign )
2305 {
2307 pos.x = bBox.GetLeft() - shadowOffset;
2308 break;
2310 pos.x = ( bBox.GetLeft() + bBox.GetRight() ) / 2.0;
2311 break;
2313 pos.x = bBox.GetRight() + shadowOffset;
2314 break;
2316 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
2317 break;
2318 }
2319 }
2320
2321 // Because the text vertical position is the bounding box center, the text is drawn as
2322 // vertically centered.
2324
2325 strokeText( *m_gal, shownText, pos, attrs, aText->GetFontMetrics() );
2326 }
2327 else if( drawingShadows )
2328 {
2329 m_gal->SetIsFill( false );
2330 m_gal->SetIsStroke( true );
2331 attrs.m_StrokeWidth += KiROUND( getShadowWidth( !aText->IsSelected() ) );
2332 attrs.m_Underlined = false;
2333
2334 // Fudge factors to match 6.0 positioning
2335 // New text stroking has width dependent offset but we need to center the shadow on the
2336 // stroke. NB this offset is in font.cpp also.
2337 int fudge = KiROUND( getShadowWidth( !aText->IsSelected() ) / 1.52 );
2338
2339 if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_0 )
2340 text_offset.x -= fudge;
2341 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_90 )
2342 text_offset.y -= fudge;
2343 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_0 )
2344 text_offset.x += fudge;
2345 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_90 )
2346 text_offset.y += fudge;
2347
2348 strokeText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs,
2349 aText->GetFontMetrics() );
2350 }
2351 else
2352 {
2353 if( aText->IsRollover() && !aText->IsMoving() )
2354 {
2355 // Highlight any urls found within the text
2356 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2357
2358 // Highlight the whole text if it has a link definition
2359 if( aText->HasHyperlink() )
2360 {
2361 attrs.m_Hover = true;
2362 attrs.m_Underlined = true;
2363 }
2364 }
2365
2366 if( nonCached( aText ) && aText->RenderAsBitmap( m_gal->GetWorldScale() )
2367 && !shownText.Contains( wxT( "\n" ) ) )
2368 {
2369 bitmapText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs );
2370 const_cast<SCH_TEXT*>( aText )->SetFlags( IS_SHOWN_AS_BITMAP );
2371 }
2372 else
2373 {
2374 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2375
2376 if( !aText->IsRollover() && font->IsOutline() )
2377 cache = aText->GetRenderCache( font, shownText, text_offset );
2378
2379 if( cache )
2380 {
2381 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2382 m_gal->DrawGlyphs( *cache );
2383 }
2384 else
2385 {
2386 wxString activeUrl;
2387
2388 strokeText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs,
2389 aText->GetFontMetrics(), aText->GetRolloverPos(), &activeUrl );
2390
2391 aText->SetActiveUrl( activeUrl );
2392 }
2393
2394 const_cast<SCH_TEXT*>( aText )->ClearFlags( IS_SHOWN_AS_BITMAP );
2395 }
2396 }
2397
2398 // Draw anchor
2399 if( aText->IsSelected() )
2400 {
2401 bool showAnchor;
2402
2403 switch( aText->Type() )
2404 {
2405 case SCH_TEXT_T:
2406 showAnchor = true;
2407 break;
2408
2409 case SCH_LABEL_T:
2410 // Don't clutter things up if we're already showing a dangling indicator
2411 showAnchor = !static_cast<const SCH_LABEL*>( aText )->IsDangling();
2412 break;
2413
2415 case SCH_HIER_LABEL_T:
2416 case SCH_GLOBAL_LABEL_T:
2417 case SCH_SHEET_PIN_T:
2418 // These all have shapes and so don't need anchors
2419 showAnchor = false;
2420 break;
2421
2422 default:
2423 showAnchor = false;
2424 break;
2425 }
2426
2427 if( showAnchor )
2428 drawAnchor( aText->GetPosition(), drawingShadows );
2429 }
2430}
2431
2432
2433void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer, bool aDimmed )
2434{
2435 if( aTextBox->Type() == SCH_TABLECELL_T )
2436 {
2437 const SCH_TABLECELL* cell = static_cast<const SCH_TABLECELL*>( aTextBox );
2438
2439 if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
2440 return;
2441 }
2442
2443 if( !isUnitAndConversionShown( aTextBox ) )
2444 return;
2445
2446 if( aTextBox->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2447 return;
2448
2449 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2450
2451 if( m_schSettings.IsPrinting() && drawingShadows )
2452 return;
2453
2454 COLOR4D color = getRenderColor( aTextBox, aLayer, drawingShadows, aDimmed );
2455 COLOR4D bg = m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
2456 float borderWidth = getLineWidth( aTextBox, drawingShadows );
2457 KIFONT::FONT* font = getFont( aTextBox );
2458
2459 auto drawText =
2460 [&]()
2461 {
2462 wxString shownText = aTextBox->GetShownText( true );
2463 TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes();
2464
2465 attrs.m_Angle = aTextBox->GetDrawRotation();
2466 attrs.m_StrokeWidth = KiROUND( getTextThickness( aTextBox ) );
2467
2468 if( aTextBox->IsRollover() && !aTextBox->IsMoving() )
2469 {
2470 // Highlight any urls found within the text
2471 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2472
2473 // Highlight the whole text if it has a link definition
2474 if( aTextBox->HasHyperlink() )
2475 {
2476 attrs.m_Hover = true;
2477 attrs.m_Underlined = true;
2478 }
2479 }
2480
2481 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2482
2483 if( !aTextBox->IsRollover() && font->IsOutline() )
2484 cache = aTextBox->GetRenderCache( font, shownText );
2485
2486 if( cache )
2487 {
2488 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2489 m_gal->DrawGlyphs( *cache );
2490 }
2491 else
2492 {
2493 wxString activeUrl;
2494
2495 strokeText( *m_gal, shownText, aTextBox->GetDrawPos(), attrs,
2496 aTextBox->GetFontMetrics(), aTextBox->GetRolloverPos(), &activeUrl );
2497
2498 aTextBox->SetActiveUrl( activeUrl );
2499 }
2500 };
2501
2502 if( drawingShadows && !( aTextBox->IsBrightened() || aTextBox->IsSelected() ) )
2503 return;
2504
2505 m_gal->SetFillColor( color );
2506 m_gal->SetStrokeColor( color );
2507 m_gal->SetHoverColor( color );
2508
2509 if( aLayer == LAYER_SELECTION_SHADOWS )
2510 {
2511 m_gal->SetIsFill( true );
2512 m_gal->SetIsStroke( false );
2513 m_gal->SetLineWidth( borderWidth );
2514
2515 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2516 }
2517 else if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_NOTES_BACKGROUND
2518 || aLayer == LAYER_SHAPES_BACKGROUND )
2519 {
2520 // Do not fill the shape in B&W print mode, to avoid to visible items
2521 // inside the shape
2522 if( aTextBox->IsSolidFill() && !m_schSettings.PrintBlackAndWhiteReq() )
2523 {
2524 m_gal->SetIsFill( true );
2525 m_gal->SetIsStroke( false );
2526 m_gal->SetLineWidth( borderWidth );
2527
2528 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2529 }
2530 }
2531 else if( aLayer == LAYER_DEVICE || aLayer == LAYER_NOTES || aLayer == LAYER_PRIVATE_NOTES )
2532 {
2533 drawText();
2534
2535 if( aTextBox->Type() != SCH_TABLECELL_T && borderWidth > 0 )
2536 {
2537 COLOR4D borderColor = aTextBox->GetStroke().GetColor();
2538 LINE_STYLE borderStyle = aTextBox->GetEffectiveLineStyle();
2539 double transparency = aTextBox->GetForcedTransparency();
2540
2541 if( m_schSettings.m_OverrideItemColors || aTextBox->IsBrightened()
2542 || borderColor == COLOR4D::UNSPECIFIED )
2543 {
2544 borderColor = m_schSettings.GetLayerColor( aLayer );
2545 }
2546
2547 if( transparency > 0.0 )
2548 borderColor = borderColor.WithAlpha( borderColor.a * ( 1.0 - transparency ) );
2549
2550 if( aDimmed )
2551 {
2552 borderColor = borderColor.Mix( bg, 0.5f );
2553 borderColor.Desaturate( );
2554 }
2555
2556 m_gal->SetIsFill( false );
2557 m_gal->SetIsStroke( true );
2558 m_gal->SetStrokeColor( borderColor );
2559 m_gal->SetLineWidth( borderWidth );
2560
2561 if( borderStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows )
2562 {
2563 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2564 }
2565 else
2566 {
2567 std::vector<SHAPE*> shapes = aTextBox->MakeEffectiveShapes( true );
2568
2569 for( SHAPE* shape : shapes )
2570 {
2571 STROKE_PARAMS::Stroke( shape, borderStyle, KiROUND( borderWidth ),
2573 [this]( const VECTOR2I& a, const VECTOR2I& b )
2574 {
2575 // DrawLine has problem with 0 length lines so enforce minimum
2576 if( a == b )
2577 m_gal->DrawLine( a+1, b );
2578 else
2579 m_gal->DrawLine( a, b );
2580 } );
2581 }
2582
2583 for( SHAPE* shape : shapes )
2584 delete shape;
2585 }
2586 }
2587 }
2588}
2589
2590
2591void SCH_PAINTER::draw( const SCH_TABLE* aTable, int aLayer, bool aDimmed )
2592{
2593 if( aTable->GetCells().empty() )
2594 return;
2595
2596 for( SCH_TABLECELL* cell : aTable->GetCells() )
2597 draw( cell, aLayer, aDimmed );
2598
2599 if( aLayer == LAYER_SELECTION_SHADOWS )
2600 return;
2601
2602 aTable->DrawBorders(
2603 [&]( const VECTOR2I& ptA, const VECTOR2I& ptB, const STROKE_PARAMS& stroke )
2604 {
2605 int lineWidth = stroke.GetWidth();
2606 COLOR4D color = stroke.GetColor();
2607 LINE_STYLE lineStyle = stroke.GetLineStyle();
2608
2609 if( lineWidth == 0 )
2610 lineWidth = m_schSettings.GetDefaultPenWidth();
2611
2612 if( color == COLOR4D::UNSPECIFIED )
2613 color = m_schSettings.GetLayerColor( LAYER_NOTES );
2614
2615 if( lineStyle == LINE_STYLE::DEFAULT )
2616 lineStyle = LINE_STYLE::SOLID;
2617
2618 m_gal->SetIsFill( false );
2619 m_gal->SetIsStroke( true );
2620 m_gal->SetStrokeColor( color );
2621 m_gal->SetLineWidth( (float) lineWidth );
2622
2623 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2624 {
2625 m_gal->DrawLine( ptA, ptB );
2626 }
2627 else
2628 {
2629 SHAPE_SEGMENT seg( ptA, ptB );
2630 STROKE_PARAMS::Stroke( &seg, lineStyle, lineWidth, &m_schSettings,
2631 [&]( const VECTOR2I& a, const VECTOR2I& b )
2632 {
2633 // DrawLine has problem with 0 length lines so enforce minimum
2634 if( a == b )
2635 m_gal->DrawLine( a+1, b );
2636 else
2637 m_gal->DrawLine( a, b );
2638 } );
2639 }
2640 } );
2641}
2642
2643
2644wxString SCH_PAINTER::expandLibItemTextVars( const wxString& aSourceText,
2645 const SCH_SYMBOL* aSymbolContext )
2646{
2647 std::function<bool( wxString* )> symbolResolver =
2648 [&]( wxString* token ) -> bool
2649 {
2650 if( !m_schematic )
2651 return false;
2652
2653 return aSymbolContext->ResolveTextVar( &m_schematic->CurrentSheet(), token );
2654 };
2655
2656 return ExpandTextVars( aSourceText, &symbolResolver );
2657}
2658
2659
2660void SCH_PAINTER::draw( const SCH_SYMBOL* aSymbol, int aLayer )
2661{
2662 auto t1 = std::chrono::high_resolution_clock::now();
2663 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2664
2665 std::optional<SCH_SHEET_PATH> optSheetPath;
2666
2667 wxString variantName;
2668
2669 if( m_schematic )
2670 {
2671 optSheetPath = m_schematic->CurrentSheet();
2672 variantName = m_schematic->GetCurrentVariant();
2673 wxLogTrace( traceSchPainter,
2674 "SCH_PAINTER::draw symbol %s: Current sheet path='%s', variant='%s', size=%zu, empty=%d",
2675 aSymbol->m_Uuid.AsString(),
2676 variantName.IsEmpty() ? GetDefaultVariantName() : variantName,
2677 optSheetPath->Path().AsString(),
2678 optSheetPath->size(),
2679 optSheetPath->empty() ? 1 : 0 );
2680 }
2681
2682 SCH_SHEET_PATH* sheetPath = optSheetPath ? &optSheetPath.value() : nullptr;
2683 bool DNP = aSymbol->GetDNP( sheetPath, variantName );
2684 bool markExclusion = eeconfig()->m_Appearance.mark_sim_exclusions && aSymbol->GetExcludedFromSim( sheetPath,
2685 variantName );
2686
2687 if( m_schSettings.IsPrinting() && drawingShadows )
2688 return;
2689
2690 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
2691 {
2692 for( const SCH_FIELD& field : aSymbol->GetFields() )
2693 draw( &field, aLayer, DNP );
2694 }
2695
2696 if( isFieldsLayer( aLayer ) )
2697 return;
2698
2699 if( drawingShadows && !( aSymbol->IsBrightened() || aSymbol->IsSelected() ) )
2700 {
2701 // Don't exit here; symbol may still have selected pins
2702 // return;
2703 }
2704
2705 int unit = m_schematic ? aSymbol->GetUnitSelection( &m_schematic->CurrentSheet() ) : 1;
2706 int bodyStyle = aSymbol->GetBodyStyle();
2707
2708 // Use dummy symbol if the actual couldn't be found (or couldn't be locked).
2709 LIB_SYMBOL* originalSymbol =
2710 aSymbol->GetLibSymbolRef() ? aSymbol->GetLibSymbolRef().get() : LIB_SYMBOL::GetDummy();
2711 std::vector<SCH_PIN*> originalPins = originalSymbol->GetGraphicalPins( unit, bodyStyle );
2712
2713 // Copy the source so we can re-orient and translate it.
2714 auto tCopy1 = std::chrono::high_resolution_clock::now();
2715 LIB_SYMBOL tempSymbol( *originalSymbol, nullptr, false );
2716 auto tCopy2 = std::chrono::high_resolution_clock::now();
2717
2718 if( std::chrono::duration_cast<std::chrono::microseconds>( tCopy2 - tCopy1 ).count() > 100 )
2719 {
2720 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw symbol copy %s: %lld us", aSymbol->m_Uuid.AsString(),
2721 std::chrono::duration_cast<std::chrono::microseconds>( tCopy2 - tCopy1 ).count() );
2722 }
2723
2724 std::vector<SCH_PIN*> tempPins = tempSymbol.GetGraphicalPins( unit, bodyStyle );
2725
2726 tempSymbol.SetFlags( aSymbol->GetFlags() );
2727
2728 OrientAndMirrorSymbolItems( &tempSymbol, aSymbol->GetOrientation() );
2729
2730 for( SCH_ITEM& tempItem : tempSymbol.GetDrawItems() )
2731 {
2732 tempItem.SetFlags( aSymbol->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2733 tempItem.Move( aSymbol->GetPosition() );
2734
2735 if( tempItem.Type() == SCH_TEXT_T )
2736 {
2737 SCH_TEXT* textItem = static_cast<SCH_TEXT*>( &tempItem );
2738
2739 if( textItem->HasTextVars() )
2740 textItem->SetText( expandLibItemTextVars( textItem->GetText(), aSymbol ) );
2741 }
2742 else if( tempItem.Type() == SCH_TEXTBOX_T )
2743 {
2744 SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( &tempItem );
2745
2746 if( textboxItem->HasTextVars() )
2747 textboxItem->SetText( expandLibItemTextVars( textboxItem->GetText(), aSymbol ) );
2748 }
2749 }
2750
2751 // Copy the pin info from the symbol to the temp pins
2752 for( unsigned i = 0; i < tempPins.size(); ++ i )
2753 {
2754 SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
2755 SCH_PIN* tempPin = tempPins[ i ];
2756
2757 if( !symbolPin )
2758 continue;
2759
2760 tempPin->ClearFlags();
2761 tempPin->SetFlags( symbolPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2762 // IS_SHOWN_AS_BITMAP
2763
2764 tempPin->SetName( expandLibItemTextVars( symbolPin->GetShownName(), aSymbol ) );
2765 tempPin->SetType( symbolPin->GetType() );
2766 tempPin->SetShape( symbolPin->GetShape() );
2767
2768 if( symbolPin->IsDangling() )
2769 tempPin->SetFlags( IS_DANGLING );
2770 else
2771 tempPin->ClearFlags( IS_DANGLING );
2772
2773 tempPin->SetOperatingPoint( symbolPin->GetOperatingPoint() );
2774 }
2775
2776 draw( &tempSymbol, aLayer, false, aSymbol->GetUnit(), aSymbol->GetBodyStyle(), DNP );
2777
2778 for( unsigned i = 0; i < tempPins.size(); ++i )
2779 {
2780 SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
2781 SCH_PIN* tempPin = tempPins[ i ];
2782
2783 if( !symbolPin )
2784 continue;
2785
2786 symbolPin->ClearFlags();
2787 tempPin->ClearFlags( IS_DANGLING ); // Clear this temporary flag
2788 symbolPin->SetFlags( tempPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2789 // IS_SHOWN_AS_BITMAP
2790 }
2791
2792 // Draw DNP and EXCLUDE from SIM markers.
2793 // These drawings are associated to the symbol body, so draw them only when the LAYER_DEVICE
2794 // is drawn (to avoid draw artifacts).
2795 if( DNP && aLayer == LAYER_DEVICE )
2796 {
2797 COLOR4D marker_color = m_schSettings.GetLayerColor( LAYER_DNP_MARKER );
2798 BOX2I bbox = aSymbol->GetBodyBoundingBox();
2799 BOX2I pins = aSymbol->GetBodyAndPinsBoundingBox();
2800 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
2801 std::max( bbox.GetY() - pins.GetY(),
2802 pins.GetEnd().y - bbox.GetEnd().y ) );
2803 int strokeWidth = 3 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
2804
2805 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
2806 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
2807 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
2808
2809 VECTOR2I pt1 = bbox.GetOrigin();
2810 VECTOR2I pt2 = bbox.GetEnd();
2811
2813 m_gal->AdvanceDepth();
2814 m_gal->SetIsStroke( true );
2815 m_gal->SetIsFill( true );
2816 m_gal->SetStrokeColor( marker_color );
2817 m_gal->SetFillColor( marker_color );
2818
2819 m_gal->DrawSegment( pt1, pt2, strokeWidth );
2820 std::swap( pt1.x, pt2.x );
2821 m_gal->DrawSegment( pt1, pt2, strokeWidth );
2822 }
2823
2824 if( markExclusion && aLayer == LAYER_DEVICE )
2825 {
2826 COLOR4D marker_color = m_schSettings.GetLayerColor( LAYER_EXCLUDED_FROM_SIM );
2827 BOX2I bbox = aSymbol->GetBodyBoundingBox();
2828 int strokeWidth = schIUScale.MilsToIU( ADVANCED_CFG::GetCfg().m_ExcludeFromSimulationLineWidth );
2829
2830 bbox.Inflate( KiROUND( strokeWidth * 0.5 ) );
2831
2833 m_gal->AdvanceDepth();
2834 m_gal->SetIsStroke( true );
2835 m_gal->SetIsFill( true );
2836 m_gal->SetStrokeColor( marker_color );
2837 m_gal->SetFillColor( marker_color );
2838
2839 m_gal->DrawSegment( bbox.GetPosition(), VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), strokeWidth );
2840 m_gal->DrawSegment( VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), bbox.GetEnd(), strokeWidth );
2841 m_gal->DrawSegment( bbox.GetEnd(), VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), strokeWidth );
2842 m_gal->DrawSegment( VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), bbox.GetPosition(), strokeWidth );
2843
2844 int offset = 2 * strokeWidth;
2845 VECTOR2D center = bbox.GetEnd() + VECTOR2D( offset + strokeWidth, -offset );
2846 VECTOR2D left = center + VECTOR2D( -offset, 0 );
2847 VECTOR2D right = center + VECTOR2D( offset, 0 );
2848 VECTOR2D top = center + VECTOR2D( 0, offset );
2849 VECTOR2D bottom = center + VECTOR2D( 0, -offset );
2850
2851 m_gal->SetFillColor( marker_color.WithAlpha( 0.1 ) );
2852 m_gal->DrawCircle( center, offset );
2853 m_gal->AdvanceDepth();
2854 m_gal->SetFillColor( marker_color );
2855 m_gal->DrawCurve( left, top, bottom, right, 1 );
2856 }
2857
2858 auto t2 = std::chrono::high_resolution_clock::now();
2859
2860 if( std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() > 100 )
2861 {
2862 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw symbol %s: %lld us", aSymbol->m_Uuid.AsString(),
2863 std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() );
2864 }
2865}
2866
2867
2868void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
2869{
2870 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2871
2872 if( m_schSettings.IsPrinting() && drawingShadows )
2873 return;
2874
2875 if( drawingShadows && !( aField->IsBrightened() || aField->IsSelected() ) )
2876 return;
2877
2878 if( !isUnitAndConversionShown( aField ) )
2879 return;
2880
2881 if( aField->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2882 return;
2883
2884 // Must check layer as fields are sometimes drawn by their parent rather than directly
2885 // from the view.
2886 std::vector<int> layers = aField->ViewGetLayers();
2887
2888 if( std::find( layers.begin(), layers.end(), aLayer ) == layers.end() )
2889 return;
2890
2891 aLayer = aField->GetLayer();
2892
2893 COLOR4D color = getRenderColor( aField, aLayer, drawingShadows, aDimmed );
2894
2895 if( !( aField->IsVisible() || aField->IsForceVisible() ) )
2896 {
2898 : m_schSettings.m_ShowHiddenFields;
2899
2900 if( force_show )
2901 color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows, aDimmed );
2902 else
2903 return;
2904 }
2905
2906 wxString shownText = aField->GetShownText( true );
2907
2908 if( shownText.IsEmpty() )
2909 return;
2910
2911 // Calculate the text orientation according to the parent orientation.
2912 EDA_ANGLE orient = aField->GetTextAngle();
2913
2914 if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
2915 {
2916 if( static_cast<SCH_SYMBOL*>( aField->GetParent() )->GetTransform().y1 )
2917 {
2918 // Rotate symbol 90 degrees.
2919 if( orient.IsHorizontal() )
2920 orient = ANGLE_VERTICAL;
2921 else
2922 orient = ANGLE_HORIZONTAL;
2923 }
2924 }
2925
2926 /*
2927 * Calculate the text justification, according to the symbol orientation/mirror.
2928 * This is a bit complicated due to cumulative calculations:
2929 * - numerous cases (mirrored or not, rotation)
2930 * - the DrawGraphicText function recalculate also H and H justifications according to the
2931 * text orientation.
2932 * - when symbol is mirrored, the text is not mirrored and justifications are complicated
2933 * to calculate so the easier way is to use no justifications (centered text) and use
2934 * GetBoundingBox to know the text coordinate considered as centered
2935 */
2936 BOX2I bbox = aField->GetBoundingBox();
2937
2938 if( aField->GetParent() && aField->GetParent()->Type() == SCH_GLOBAL_LABEL_T )
2939 {
2940 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( aField->GetParent() );
2941 bbox.Offset( label->GetSchematicTextOffset( &m_schSettings ) );
2942 }
2943
2944 if( m_schSettings.GetDrawBoundingBoxes() )
2945 drawItemBoundingBox( aField );
2946
2947 m_gal->SetStrokeColor( color );
2948 m_gal->SetFillColor( color );
2949 m_gal->SetHoverColor( color );
2950
2951 if( drawingShadows && getFont( aField )->IsOutline() )
2952 {
2953 BOX2I shadow_box = bbox;
2954 shadow_box.Inflate( KiROUND( getTextThickness( aField ) * 2 ) );
2955
2956 m_gal->SetIsStroke( false );
2957 m_gal->SetIsFill( true );
2958 m_gal->DrawRectangle( shadow_box.GetPosition(), shadow_box.GetEnd() );
2959 }
2960 else
2961 {
2962 VECTOR2I textpos = bbox.Centre();
2963 TEXT_ATTRIBUTES attributes = aField->GetAttributes();
2964
2965 attributes.m_Halign = GR_TEXT_H_ALIGN_CENTER;
2966 attributes.m_Valign = GR_TEXT_V_ALIGN_CENTER;
2967 attributes.m_StrokeWidth = KiROUND( getTextThickness( aField ) );
2968 attributes.m_Angle = orient;
2969
2970 if( drawingShadows )
2971 attributes.m_StrokeWidth += getShadowWidth( !aField->IsSelected() );
2972
2973 if( aField->IsRollover() && !aField->IsMoving() )
2974 {
2975 // Highlight any urls found within the text
2976 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2977
2978 // Highlight the whole text if it has a link definition
2979 if( aField->HasHyperlink() )
2980 {
2981 attributes.m_Hover = true;
2982 attributes.m_Underlined = true;
2983 }
2984 }
2985
2986 if( nonCached( aField ) && aField->RenderAsBitmap( m_gal->GetWorldScale() ) )
2987 {
2988 bitmapText( *m_gal, shownText, textpos, attributes );
2989 const_cast<SCH_FIELD*>( aField )->SetFlags( IS_SHOWN_AS_BITMAP );
2990 }
2991 else
2992 {
2993 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2994
2995 if( !aField->IsRollover() )
2996 cache = aField->GetRenderCache( shownText, textpos, attributes );
2997
2998 if( cache )
2999 {
3000 m_gal->SetLineWidth( attributes.m_StrokeWidth );
3001 m_gal->DrawGlyphs( *cache );
3002 }
3003 else
3004 {
3005 strokeText( *m_gal, shownText, textpos, attributes, aField->GetFontMetrics(),
3006 aField->GetRolloverPos() );
3007 }
3008
3009 const_cast<SCH_FIELD*>( aField )->ClearFlags( IS_SHOWN_AS_BITMAP );
3010 }
3011 }
3012
3013 if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
3014 {
3015 SCH_SYMBOL* parent = static_cast<SCH_SYMBOL*>( aField->GetParent() );
3016 bool rotated = !orient.IsHorizontal();
3017
3018 VECTOR2D pos;
3019 double size = bbox.GetHeight() / 1.5;
3020
3021 if( rotated )
3022 {
3023 pos = VECTOR2D( bbox.GetRight() - bbox.GetWidth() / 6.0,
3024 bbox.GetBottom() + bbox.GetWidth() / 2.0 );
3025 size = bbox.GetWidth() / 1.5;
3026 }
3027 else
3028 {
3029 pos = VECTOR2D( bbox.GetLeft() - bbox.GetHeight() / 2.0,
3030 bbox.GetBottom() - bbox.GetHeight() / 6.0 );
3031 }
3032
3033 if( parent->IsSymbolLikePowerLocalLabel() && aField->GetId() == FIELD_T::VALUE )
3034 drawLocalPowerIcon( pos, size, rotated, color, drawingShadows, aField->IsBrightened() );
3035 }
3036
3037 // Draw anchor or umbilical line
3038 if( aField->IsMoving() && m_schematic )
3039 {
3040 VECTOR2I parentPos = aField->GetParentPosition();
3041
3042 m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() );
3043 m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
3044 m_gal->DrawLine( aField->GetPosition(), parentPos );
3045 }
3046 else if( aField->IsSelected() )
3047 {
3048 drawAnchor( aField->GetPosition(), drawingShadows );
3049 }
3050}
3051
3052
3053void SCH_PAINTER::draw( const SCH_GLOBALLABEL* aLabel, int aLayer, bool aDimmed )
3054{
3055 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3056
3057 if( m_schSettings.IsPrinting() && drawingShadows )
3058 return;
3059
3060 bool drawingDangling = aLayer == LAYER_DANGLING;
3061
3062 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3063 {
3064 for( const SCH_FIELD& field : aLabel->GetFields() )
3065 draw( &field, aLayer, false );
3066 }
3067
3068 if( isFieldsLayer( aLayer ) )
3069 return;
3070
3071 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3072 return;
3073
3074 COLOR4D color = getRenderColor( aLabel, LAYER_GLOBLABEL, drawingShadows, aDimmed, true );
3075
3076 if( drawingDangling )
3077 {
3078 if( aLabel->IsDangling() )
3079 {
3080 drawDanglingIndicator( aLabel->GetTextPos(), color,
3081 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3082 drawingShadows, aLabel->IsBrightened() );
3083 }
3084
3085 return;
3086 }
3087
3088 std::vector<VECTOR2I> pts;
3089 std::deque<VECTOR2D> pts2;
3090
3091 aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
3092
3093 for( const VECTOR2I& p : pts )
3094 pts2.emplace_back( VECTOR2D( p.x, p.y ) );
3095
3096 m_gal->SetIsStroke( true );
3097 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3098 m_gal->SetStrokeColor( color );
3099
3100 if( drawingShadows )
3101 {
3102 m_gal->SetIsFill( eeconfig()->m_Selection.fill_shapes );
3103 m_gal->SetFillColor( color );
3104 m_gal->DrawPolygon( pts2 );
3105 }
3106 else
3107 {
3108 m_gal->SetIsFill( false );
3109 m_gal->DrawPolyline( pts2 );
3110 }
3111
3112 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3113}
3114
3115
3116void SCH_PAINTER::draw( const SCH_LABEL* aLabel, int aLayer, bool aDimmed )
3117{
3118 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3119
3120 if( m_schSettings.IsPrinting() && drawingShadows )
3121 return;
3122
3123 bool drawingDangling = aLayer == LAYER_DANGLING;
3124
3125 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3126 {
3127 for( const SCH_FIELD& field : aLabel->GetFields() )
3128 draw( &field, aLayer, false );
3129 }
3130
3131 if( isFieldsLayer( aLayer ) )
3132 return;
3133
3134 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3135 return;
3136
3137 COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows, aDimmed, true );
3138
3139 if( drawingDangling )
3140 {
3141 if( aLabel->IsDangling() )
3142 {
3143 drawDanglingIndicator( aLabel->GetTextPos(), color,
3144 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3145 drawingShadows, aLabel->IsBrightened() );
3146 }
3147
3148 return;
3149 }
3150
3151 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3152}
3153
3154
3155void SCH_PAINTER::draw( const SCH_HIERLABEL* aLabel, int aLayer, bool aDimmed )
3156{
3157 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3158
3159 if( m_schSettings.IsPrinting() && drawingShadows )
3160 return;
3161
3162 bool drawingDangling = aLayer == LAYER_DANGLING;
3163
3164 if( !( drawingShadows || drawingDangling ) || eeconfig()->m_Selection.draw_selected_children )
3165 {
3166 for( const SCH_FIELD& field : aLabel->GetFields() )
3167 draw( &field, aLayer, false );
3168 }
3169
3170 if( isFieldsLayer( aLayer ) )
3171 return;
3172
3173 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3174 return;
3175
3176 COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows, aDimmed, true );
3177
3178 if( drawingDangling )
3179 {
3180 if( aLabel->IsDangling() )
3181 {
3182 drawDanglingIndicator( aLabel->GetTextPos(), color,
3183 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3184 drawingShadows, aLabel->IsBrightened() );
3185 }
3186
3187 return;
3188 }
3189
3190 std::vector<VECTOR2I> i_pts;
3191 std::deque<VECTOR2D> d_pts;
3192
3193 aLabel->CreateGraphicShape( &m_schSettings, i_pts, (VECTOR2I)aLabel->GetTextPos() );
3194
3195 for( const VECTOR2I& i_pt : i_pts )
3196 d_pts.emplace_back( VECTOR2D( i_pt.x, i_pt.y ) );
3197
3198 m_gal->SetIsFill( true );
3199 m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
3200 m_gal->SetIsStroke( true );
3201 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3202 m_gal->SetStrokeColor( color );
3203 m_gal->DrawPolyline( d_pts );
3204
3205 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3206}
3207
3208
3209void SCH_PAINTER::draw( const SCH_DIRECTIVE_LABEL* aLabel, int aLayer, bool aDimmed )
3210{
3211 if( !eeconfig()->m_Appearance.show_directive_labels && !aLabel->IsSelected() )
3212 return;
3213
3214 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3215
3216 if( m_schSettings.IsPrinting() && drawingShadows )
3217 return;
3218
3219 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3220 {
3221 for( const SCH_FIELD& field : aLabel->GetFields() )
3222 draw( &field, aLayer, false );
3223 }
3224
3225 if( isFieldsLayer( aLayer ) )
3226 return;
3227
3228 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3229 return;
3230
3231 COLOR4D color = getRenderColor( aLabel, LAYER_NETCLASS_REFS, drawingShadows, aDimmed, true );
3232
3233 if( aLayer == LAYER_DANGLING )
3234 {
3235 if( aLabel->IsDangling() )
3236 {
3237 drawDanglingIndicator( aLabel->GetTextPos(), color,
3238 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3239 drawingShadows, aLabel->IsBrightened() );
3240 }
3241
3242 return;
3243 }
3244
3245 std::vector<VECTOR2I> pts;
3246 std::deque<VECTOR2D> pts2;
3247
3248 aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
3249
3250 for( const VECTOR2I& p : pts )
3251 pts2.emplace_back( VECTOR2D( p.x, p.y ) );
3252
3253 m_gal->SetIsFill( false );
3254 m_gal->SetFillColor( color );
3255 m_gal->SetIsStroke( true );
3256 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3257 m_gal->SetStrokeColor( color );
3258
3259 if( aLabel->GetShape() == LABEL_FLAG_SHAPE::F_DOT )
3260 {
3261 m_gal->DrawLine( pts2[0], pts2[1] );
3262 m_gal->SetIsFill( true );
3263 m_gal->DrawCircle( pts2[2], ( pts2[2] - pts2[1] ).EuclideanNorm() );
3264 }
3265 else if( aLabel->GetShape() == LABEL_FLAG_SHAPE::F_ROUND )
3266 {
3267 m_gal->DrawLine( pts2[0], pts2[1] );
3268 m_gal->DrawCircle( pts2[2], ( pts2[2] - pts2[1] ).EuclideanNorm() );
3269 }
3270 else
3271 {
3272 m_gal->DrawPolyline( pts2 );
3273 }
3274}
3275
3276
3277void SCH_PAINTER::draw( const SCH_SHEET* aSheet, int aLayer )
3278{
3279 bool DNP = false;
3280
3281 if( m_schematic )
3282 DNP = aSheet->GetDNP( &m_schematic->CurrentSheet(), m_schematic->GetCurrentVariant() );
3283
3284 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3285 bool markExclusion = eeconfig()->m_Appearance.mark_sim_exclusions && aSheet->GetExcludedFromSim();
3286
3287 if( m_schSettings.IsPrinting() && drawingShadows )
3288 return;
3289
3290 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3291 {
3292 for( const SCH_FIELD& field : aSheet->GetFields() )
3293 draw( &field, aLayer, DNP );
3294
3295 for( SCH_SHEET_PIN* sheetPin : aSheet->GetPins() )
3296 draw( static_cast<SCH_HIERLABEL*>( sheetPin ), aLayer, DNP );
3297 }
3298
3299 if( isFieldsLayer( aLayer ) )
3300 return;
3301
3302 VECTOR2D pos = aSheet->GetPosition();
3303 VECTOR2D size = aSheet->GetSize();
3304
3305 if( aLayer == LAYER_SHEET_BACKGROUND )
3306 {
3307 // Do not fill the shape in B&W print mode, to avoid to visible items
3308 // inside the shape
3309 if( !m_schSettings.PrintBlackAndWhiteReq() )
3310 {
3311 m_gal->SetFillColor( getRenderColor( aSheet, LAYER_SHEET_BACKGROUND, true ) );
3312 m_gal->SetIsFill( true );
3313 m_gal->SetIsStroke( false );
3314
3315 m_gal->DrawRectangle( pos, pos + size );
3316 }
3317 }
3318
3319 if( aLayer == LAYER_SHEET || aLayer == LAYER_SELECTION_SHADOWS )
3320 {
3321 m_gal->SetStrokeColor( getRenderColor( aSheet, LAYER_SHEET, drawingShadows ) );
3322 m_gal->SetIsStroke( true );
3323 m_gal->SetLineWidth( getLineWidth( aSheet, drawingShadows ) );
3324 m_gal->SetIsFill( false );
3325
3326 m_gal->DrawRectangle( pos, pos + size );
3327 }
3328
3329 if( DNP && aLayer == LAYER_SHEET )
3330 {
3331 int layer = LAYER_DNP_MARKER;
3332 BOX2I bbox = aSheet->GetBodyBoundingBox();
3333 BOX2I pins = aSheet->GetBoundingBox();
3334 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
3335 std::max( bbox.GetY() - pins.GetY(), pins.GetEnd().y - bbox.GetEnd().y ) );
3336 int strokeWidth = 3 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
3337
3338 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
3339 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
3340 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
3341
3342 VECTOR2I pt1 = bbox.GetOrigin();
3343 VECTOR2I pt2 = bbox.GetEnd();
3344
3346 m_gal->AdvanceDepth();
3347 m_gal->SetIsStroke( true );
3348 m_gal->SetIsFill( true );
3349 m_gal->SetStrokeColor( m_schSettings.GetLayerColor( layer ) );
3350 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ) );
3351
3352 m_gal->DrawSegment( pt1, pt2, strokeWidth );
3353 std::swap( pt1.x, pt2.x );
3354 m_gal->DrawSegment( pt1, pt2, strokeWidth );
3355 }
3356
3357 if( markExclusion )
3358 {
3359 int layer = LAYER_EXCLUDED_FROM_SIM;
3360 BOX2I bbox = aSheet->GetBodyBoundingBox();
3361 int strokeWidth = schIUScale.MilsToIU( ADVANCED_CFG::GetCfg().m_ExcludeFromSimulationLineWidth );
3362
3363 bbox.Inflate( KiROUND( strokeWidth * 0.5 ) );
3364
3366 m_gal->AdvanceDepth();
3367 m_gal->SetIsStroke( true );
3368 m_gal->SetIsFill( true );
3369 m_gal->SetStrokeColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3370 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3371
3372 m_gal->DrawSegment( bbox.GetPosition(), VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), strokeWidth );
3373 m_gal->DrawSegment( VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), bbox.GetEnd(), strokeWidth );
3374 m_gal->DrawSegment( bbox.GetEnd(), VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), strokeWidth );
3375 m_gal->DrawSegment( VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), bbox.GetPosition(), strokeWidth );
3376
3377 int offset = 2 * strokeWidth;
3378 VECTOR2D center = bbox.GetEnd() + VECTOR2D( offset + strokeWidth, -offset );
3379 VECTOR2D left = center + VECTOR2D( -offset, 0 );
3380 VECTOR2D right = center + VECTOR2D( offset, 0 );
3381 VECTOR2D top = center + VECTOR2D( 0, offset );
3382 VECTOR2D bottom = center + VECTOR2D( 0, -offset );
3383
3384 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.1 ) );
3385 m_gal->DrawCircle( center, offset );
3386 m_gal->AdvanceDepth();
3387 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3388 m_gal->DrawCurve( left, top, bottom, right, 1 );
3389 }
3390}
3391
3392
3393void SCH_PAINTER::draw( const SCH_NO_CONNECT* aNC, int aLayer )
3394{
3395 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3396
3397 if( m_schSettings.IsPrinting() && drawingShadows )
3398 return;
3399
3400 if( drawingShadows && !( aNC->IsBrightened() || aNC->IsSelected() ) )
3401 return;
3402
3403 m_gal->SetIsStroke( true );
3404 m_gal->SetLineWidth( getLineWidth( aNC, drawingShadows ) );
3405 m_gal->SetStrokeColor( getRenderColor( aNC, LAYER_NOCONNECT, drawingShadows ) );
3406 m_gal->SetIsFill( false );
3407
3408 VECTOR2D p = aNC->GetPosition();
3409 int delta = std::max( aNC->GetSize(), m_schSettings.GetDefaultPenWidth() * 3 ) / 2;
3410
3411 m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
3412 m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
3413}
3414
3415
3416void SCH_PAINTER::draw( const SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
3417{
3419 SCH_LINE line( VECTOR2I(), layer );
3420 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3421 bool drawingNetColorHighlights = aLayer == LAYER_NET_COLOR_HIGHLIGHT;
3422 bool drawingDangling = aLayer == LAYER_DANGLING;
3423 bool drawingWires = aLayer == LAYER_WIRE;
3424 bool drawingBusses = aLayer == LAYER_BUS;
3425
3426 if( m_schSettings.IsPrinting() && drawingShadows )
3427 return;
3428
3429 bool highlightNetclassColors = false;
3430 EESCHEMA_SETTINGS* eeschemaCfg = eeconfig();
3431
3432 if( eeschemaCfg )
3433 {
3434 highlightNetclassColors = eeschemaCfg->m_Selection.highlight_netclass_colors;
3435 }
3436
3437 if( !highlightNetclassColors && drawingNetColorHighlights )
3438 return;
3439
3440 if( m_schSettings.m_OverrideItemColors && drawingNetColorHighlights )
3441 return;
3442
3443 if( drawingShadows && !( aEntry->IsBrightened() || aEntry->IsSelected() ) )
3444 return;
3445
3446 if( aEntry->IsSelected() )
3447 {
3448 line.SetSelected();
3449
3450 // Never show unselected endpoints on bus entries
3451 line.SetFlags( STARTPOINT | ENDPOINT );
3452 }
3453 else if( aEntry->IsBrightened() )
3454 {
3455 line.SetBrightened();
3456 }
3457
3458 line.SetStartPoint( aEntry->GetPosition() );
3459 line.SetEndPoint( aEntry->GetEnd() );
3460 line.SetStroke( aEntry->GetStroke() );
3461 line.SetLineWidth( KiROUND( getLineWidth( aEntry, false ) ) );
3462
3463 COLOR4D color = getRenderColor( aEntry, LAYER_WIRE, drawingShadows );
3464
3465 if( aEntry->Type() == SCH_BUS_BUS_ENTRY_T )
3466 color = getRenderColor( aEntry, LAYER_BUS, drawingShadows );
3467
3468 if( highlightNetclassColors )
3469 {
3470 // Force default color for nets we are going to highlight
3471 if( drawingWires )
3472 color = m_schSettings.GetLayerColor( LAYER_WIRE );
3473 else if( drawingBusses )
3474 color = m_schSettings.GetLayerColor( LAYER_BUS );
3475 }
3476
3477 if( drawingNetColorHighlights )
3478 {
3479 // Don't draw highlights for default-colored nets
3480 if( ( aEntry->Type() == SCH_BUS_WIRE_ENTRY_T
3481 && color == m_schSettings.GetLayerColor( LAYER_WIRE ) )
3482 || ( aEntry->Type() == SCH_BUS_BUS_ENTRY_T
3483 && color == m_schSettings.GetLayerColor( LAYER_BUS ) ) )
3484 {
3485 return;
3486 }
3487 }
3488
3489 if( drawingDangling )
3490 {
3491 m_gal->SetIsFill( false );
3492 m_gal->SetIsStroke( true );
3493 m_gal->SetStrokeColor( color.Brightened( 0.3 ) );
3494 m_gal->SetLineWidth( m_schSettings.GetDanglingIndicatorThickness() );
3495
3496 if( aEntry->IsStartDangling() )
3497 {
3498 m_gal->DrawCircle( aEntry->GetPosition(),
3499 aEntry->GetPenWidth() + KiROUND( TARGET_BUSENTRY_RADIUS / 2.0 ) );
3500 }
3501
3502 if( aEntry->IsEndDangling() )
3503 {
3504 m_gal->DrawCircle( aEntry->GetEnd(),
3505 aEntry->GetPenWidth() + KiROUND( TARGET_BUSENTRY_RADIUS / 2.0 ) );
3506 }
3507 }
3508 else
3509 {
3510 line.SetLineColor( color );
3511 line.SetLineStyle( aEntry->GetEffectiveLineStyle() );
3512
3513 draw( &line, aLayer );
3514 }
3515}
3516
3517
3518void SCH_PAINTER::draw( const SCH_BITMAP* aBitmap, int aLayer )
3519{
3520 auto t1 = std::chrono::high_resolution_clock::now();
3521 m_gal->Save();
3522 m_gal->Translate( aBitmap->GetPosition() );
3523
3524 const REFERENCE_IMAGE& refImage = aBitmap->GetReferenceImage();
3525
3526 // When the image scale factor is not 1.0, we need to modify the actual as the image scale
3527 // factor is similar to a local zoom
3528 const double img_scale = refImage.GetImageScale();
3529
3530 if( img_scale != 1.0 )
3531 m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
3532
3533 if( aLayer == LAYER_DRAW_BITMAPS )
3534 {
3535 m_gal->DrawBitmap( refImage.GetImage() );
3536 }
3537
3538 if( aLayer == LAYER_SELECTION_SHADOWS )
3539 {
3540 if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
3541 {
3542 const COLOR4D color = getRenderColor( aBitmap, LAYER_DRAW_BITMAPS, true );
3543 m_gal->SetIsStroke( true );
3544 m_gal->SetStrokeColor( color );
3545 m_gal->SetLineWidth ( getShadowWidth( aBitmap->IsBrightened() ) );
3546 m_gal->SetIsFill( false );
3547
3548 // Draws a bounding box.
3549 VECTOR2D bm_size( refImage.GetSize() );
3550
3551 // bm_size is the actual image size in UI.
3552 // but m_canvas scale was previously set to img_scale
3553 // so recalculate size relative to this image size.
3554 bm_size.x /= img_scale;
3555 bm_size.y /= img_scale;
3556 const VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
3557 const VECTOR2D end = origin + bm_size;
3558
3559 m_gal->DrawRectangle( origin, end );
3560 }
3561 }
3562
3563 m_gal->Restore();
3564 auto t2 = std::chrono::high_resolution_clock::now();
3565
3566 if( std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() > 100 )
3567 {
3568 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw bitmap %s: %lld us", aBitmap->m_Uuid.AsString(),
3569 std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() );
3570 }
3571}
3572
3573
3574void SCH_PAINTER::draw( const SCH_MARKER* aMarker, int aLayer )
3575{
3576 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3577
3578 if( m_schSettings.IsPrinting() && drawingShadows )
3579 return;
3580
3581 if( drawingShadows && !( aMarker->IsBrightened() || aMarker->IsSelected() ) )
3582 return;
3583
3584 COLOR4D color = getRenderColor( aMarker, aMarker->GetColorLayer(), drawingShadows );
3585
3586 m_gal->Save();
3587 m_gal->Translate( aMarker->GetPosition() );
3588 m_gal->SetIsFill( !drawingShadows );
3589 m_gal->SetFillColor( color );
3590 m_gal->SetIsStroke( drawingShadows );
3591 m_gal->SetLineWidth( getLineWidth( aMarker, drawingShadows ) );
3592 m_gal->SetStrokeColor( color );
3593
3594 SHAPE_LINE_CHAIN polygon;
3595 aMarker->ShapeToPolygon( polygon );
3596
3597 m_gal->DrawPolygon( polygon );
3598 m_gal->Restore();
3599}
3600
3601
3602void SCH_PAINTER::draw( const SCH_GROUP* aGroup, int aLayer )
3603{
3604 const bool drawingShadows = false;
3605
3606 if( aLayer == LAYER_SCHEMATIC_ANCHOR )
3607 {
3608 if( aGroup->IsSelected() && !( aGroup->GetParent() && aGroup->GetParent()->IsSelected() ) )
3609 {
3610 // Selected on our own; draw enclosing box
3611 }
3612 else if( aGroup->IsEntered() )
3613 {
3614 // Entered group; draw enclosing box
3615 }
3616 else
3617 {
3618 // Neither selected nor entered; draw nothing at the group level (ie: only draw
3619 // its members)
3620 return;
3621 }
3622
3623 const COLOR4D color = getRenderColor( aGroup, LAYER_SCHEMATIC_ANCHOR, drawingShadows );
3624
3625 m_gal->SetStrokeColor( color );
3626 m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() * 2.0f );
3627
3628 BOX2I bbox = aGroup->GetBoundingBox();
3629 VECTOR2I topLeft = bbox.GetPosition();
3630 VECTOR2I width = VECTOR2I( bbox.GetWidth(), 0 );
3631 VECTOR2I height = VECTOR2I( 0, bbox.GetHeight() );
3632
3633 m_gal->DrawLine( topLeft, topLeft + width );
3634 m_gal->DrawLine( topLeft + width, topLeft + width + height );
3635 m_gal->DrawLine( topLeft + width + height, topLeft + height );
3636 m_gal->DrawLine( topLeft + height, topLeft );
3637
3638 wxString name = aGroup->GetName();
3639
3640 if( name.IsEmpty() )
3641 return;
3642
3643 int ptSize = 12;
3644 int scaledSize = abs( KiROUND( m_gal->GetScreenWorldMatrix().GetScale().x * ptSize ) );
3645 int unscaledSize = schIUScale.MilsToIU( ptSize );
3646
3647 // Scale by zoom a bit, but not too much
3648 int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3;
3649 VECTOR2I textOffset = KiROUND( width.x / 2.0, -textSize * 0.5 );
3650 VECTOR2I titleHeight = KiROUND( 0.0, textSize * 2.0 );
3651
3652 if( PrintableCharCount( name ) * textSize < bbox.GetWidth() )
3653 {
3654 m_gal->DrawLine( topLeft, topLeft - titleHeight );
3655 m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight );
3656 m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width );
3657
3658 TEXT_ATTRIBUTES attrs;
3659 attrs.m_Italic = true;
3662 attrs.m_Size = VECTOR2I( textSize, textSize );
3663 attrs.m_StrokeWidth = GetPenSizeForNormal( textSize );
3664
3665 KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs,
3666 aGroup->GetFontMetrics() );
3667 }
3668 }
3669}
3670
3671
3672void SCH_PAINTER::drawLine( const VECTOR2I& aStartPoint, const VECTOR2I& aEndPoint,
3673 LINE_STYLE aLineStyle, bool aDrawDirectLine, int aWidth )
3674{
3675 if( aDrawDirectLine )
3676 {
3677 m_gal->DrawLine( aStartPoint, aEndPoint );
3678 }
3679 else
3680 {
3681 SHAPE_SEGMENT segment( aStartPoint, aEndPoint );
3682
3683 STROKE_PARAMS::Stroke( &segment, aLineStyle, KiROUND( aWidth ), &m_schSettings,
3684 [&]( const VECTOR2I& start, const VECTOR2I& end )
3685 {
3686 if( start == end )
3687 m_gal->DrawLine( start + 1, end );
3688 else
3689 m_gal->DrawLine( start, end );
3690 } );
3691 }
3692}
3693
3694}; // 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:98
VECTOR2I GetRolloverPos() const
Definition eda_item.h:132
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:110
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:148
const KIID m_Uuid
Definition eda_item.h:522
void SetActiveUrl(const wxString &aUrl) const
Definition eda_item.h:138
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
bool IsEntered() const
Definition eda_item.h:128
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:150
bool IsSelected() const
Definition eda_item.h:127
void SetSelected()
Definition eda_item.h:140
void SetBrightened()
Definition eda_item.h:141
EDA_ITEM * GetParent() const
Definition eda_item.h:112
bool IsRollover() const
Definition eda_item.h:131
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:152
bool IsBrightened() const
Definition eda_item.h:129
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:125
bool IsNew() const
Definition eda_item.h:124
const SHAPE_POLY_SET & GetHatching() const
Definition eda_shape.h:148
FILL_T GetFillMode() const
Definition eda_shape.h:142
SHAPE_T GetShape() const
Definition eda_shape.h:168
bool IsSolidFill() const
Definition eda_shape.h:117
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:215
COLOR4D GetFillColor() const
Definition eda_shape.h:152
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
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:692
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:377
virtual VECTOR2I GetDrawPos() const
Definition eda_text.h:378
BOX2I GetTextBox(const RENDER_SETTINGS *aSettings, int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition eda_text.cpp:746
virtual bool HasHyperlink() const
Definition eda_text.h:400
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:656
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:279
VECTOR2I GetTextSize() const
Definition eda_text.h:261
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:95
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:147
virtual bool IsStroke() const
Definition font.h:138
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr) const
Draw a string.
Definition font.cpp:250
virtual bool IsOutline() const
Definition font.h:139
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
std::optional< wxString > m_text
Definition color4d.h:399
COLOR4D & Darken(double aFactor)
Makes the color darker by a given factor.
Definition color4d.h:227
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:246
Define a library symbol object.
Definition lib_symbol.h:83
bool IsDerived() const
Definition lib_symbol.h:204
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:699
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
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:122
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:167
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:253
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:247
int GetBodyStyle() const
Definition sch_item.h:247
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:450
int GetUnit() const
Definition sch_item.h:238
bool IsPrivate() const
Definition sch_item.h:253
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition sch_item.h:340
bool RenderAsBitmap(double aWorldScale) const override
Definition sch_item.cpp:784
bool IsConnectivityDirty() const
Definition sch_item.h:587
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:466
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:356
wxString GetClass() const override
Return the class name.
Definition sch_item.h:177
const KIFONT::METRICS & GetFontMetrics() const
Definition sch_item.cpp:752
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:761
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition sch_item.h:182
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:991
bool IsStartDangling() const
Definition sch_line.h:303
void SetLineColor(const COLOR4D &aColor)
Definition sch_line.cpp:280
void SetLineWidth(const int aSize)
Definition sch_line.cpp:346
LINE_STYLE GetEffectiveLineStyle() const
Definition sch_line.cpp:333
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:997
void SetLineStyle(const LINE_STYLE aStyle)
Definition sch_line.cpp:317
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:679
int GetLength() const
Definition sch_pin.cpp:299
const wxString & GetOperatingPoint() const
Definition sch_pin.h:337
void SetName(const wxString &aName)
Definition sch_pin.cpp:419
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:367
bool IsVisible() const
Definition sch_pin.cpp:387
VECTOR2I GetPinRoot() const
Definition sch_pin.cpp:703
bool IsDangling() const override
Definition sch_pin.cpp:461
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition sch_pin.h:96
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:256
int GetNameTextSize() const
Definition sch_pin.cpp:655
wxString GetShownName() const
Definition sch_pin.cpp:577
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:333
GRAPHIC_PINSHAPE GetShape() const
Definition sch_pin.cpp:278
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:313
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
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:854
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
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_text.cpp:295
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition sch_text.cpp:316
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:74
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.
void Fracture()
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
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 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:61
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:45
@ 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.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:229
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