KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_painter.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27
28#include <trigo.h>
29#include <chrono>
30#include <bitmap_base.h>
31#include <connection_graph.h>
33#include <callback_gal.h>
35#include <geometry/shape_rect.h>
36#include <geometry/roundrect.h>
39#include <gr_text.h>
40#include <sch_pin.h>
41#include <math/util.h>
42#include <pin_layout_cache.h>
43#include <pgm_base.h>
44#include <sch_bitmap.h>
45#include <sch_bus_entry.h>
46#include <sch_symbol.h>
47#include <sch_edit_frame.h>
48#include <sch_field.h>
49#include <sch_group.h>
50#include <sch_junction.h>
51#include <sch_line.h>
52#include <sch_shape.h>
53#include <sch_marker.h>
54#include <sch_no_connect.h>
55#include <sch_sheet.h>
56#include <sch_sheet_pin.h>
57#include <sch_text.h>
58#include <sch_textbox.h>
59#include <sch_table.h>
60#include <schematic.h>
62#include <trace_helpers.h>
63#include <view/view.h>
64#include <kiface_base.h>
65#include <default_values.h>
66#include <advanced_config.h>
68#include <stroke_params.h>
69#include <string_utils.h>
70#include "sch_painter.h"
71#include "common.h"
72
74
75namespace KIGFX
76{
77
79{
80 return dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
81}
82
83
84std::vector<KICAD_T> SCH_PAINTER::g_ScaledSelectionTypes = {
103};
104
105
107 KIGFX::PAINTER( aGal ),
108 m_schematic( nullptr )
109{ }
110
111
112bool SCH_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
113{
114 const EDA_ITEM* item = dynamic_cast<const EDA_ITEM*>( aItem );
115
116 if( !item )
117 return false;
118
119 draw( item, aLayer, false );
120
121 return false;
122}
123
124
125void SCH_PAINTER::draw( const EDA_ITEM* aItem, int aLayer, bool aDimmed )
126{
127
128#ifdef CONNECTIVITY_DEBUG
129
130 auto sch_item = dynamic_cast<const SCH_ITEM*>( aItem );
131 auto conn = sch_item ? sch_item->Connection( *g_CurrentSheet ) : nullptr;
132
133 if( conn )
134 {
135 auto pos = aItem->GetBoundingBox().Centre();
136 auto label = conn->Name( true );
137
138 m_canvas->SetHorizontalJustify( GR_TEXT_H_ALIGN_CENTER );
139 m_canvas->SetVerticalJustify( GR_TEXT_V_ALIGN_CENTER );
140 m_canvas->SetStrokeColor( COLOR4D( LIGHTRED ) );
141 m_canvas->SetLineWidth( Mils2ui( 2 ) );
142 m_canvas->SetGlyphSize( VECTOR2D( Mils2ui( 20 ), Mils2ui( 20 ) ) );
143 m_canvas->StrokeText( *m_canvas, conn->Name( true ), pos, 0.0, 0 );
144 }
145
146#endif
147
148 // Enable draw bounding box on request. Some bboxes are handled locally.
149 bool drawBoundingBox = m_schSettings.GetDrawBoundingBoxes();
150
151 switch( aItem->Type() )
152 {
153 case LIB_SYMBOL_T:
154 draw( static_cast<const LIB_SYMBOL*>( aItem ), aLayer );
155 break;
156 case SCH_PIN_T:
157 drawBoundingBox = false;
158 draw( static_cast<const SCH_PIN*>( aItem ), aLayer, aDimmed );
159 break;
160 case SCH_SYMBOL_T:
161 draw( static_cast<const SCH_SYMBOL*>( aItem ), aLayer );
162 break;
163 case SCH_JUNCTION_T:
164 draw( static_cast<const SCH_JUNCTION*>( aItem ), aLayer );
165 break;
166 case SCH_LINE_T:
167 draw( static_cast<const SCH_LINE*>( aItem ), aLayer );
168 break;
169 case SCH_SHAPE_T:
170 draw( static_cast<const SCH_SHAPE*>( aItem ), aLayer, aDimmed );
171 break;
172 case SCH_RULE_AREA_T:
173 draw( static_cast<const SCH_SHAPE*>( aItem ), aLayer, aDimmed );
174 break;
175 case SCH_TEXT_T:
176 draw( static_cast<const SCH_TEXT*>( aItem ), aLayer, aDimmed );
177 break;
178 case SCH_TEXTBOX_T:
179 draw( static_cast<const SCH_TEXTBOX*>( aItem ), aLayer, aDimmed );
180 break;
181 case SCH_TABLE_T:
182 draw( static_cast<const SCH_TABLE*>( aItem ), aLayer, aDimmed );
183 break;
184 case SCH_LABEL_T:
185 draw( static_cast<const SCH_LABEL*>( aItem ), aLayer, aDimmed );
186 break;
188 draw( static_cast<const SCH_DIRECTIVE_LABEL*>( aItem ), aLayer, aDimmed );
189 break;
190 case SCH_FIELD_T:
191 draw( static_cast<const SCH_FIELD*>( aItem ), aLayer, aDimmed );
192 break;
193 case SCH_HIER_LABEL_T:
194 draw( static_cast<const SCH_HIERLABEL*>( aItem ), aLayer, aDimmed );
195 break;
197 draw( static_cast<const SCH_GLOBALLABEL*>( aItem ), aLayer, aDimmed );
198 break;
199 case SCH_SHEET_T:
200 draw( static_cast<const SCH_SHEET*>( aItem ), aLayer );
201 break;
202 case SCH_SHEET_PIN_T:
203 draw( static_cast<const SCH_HIERLABEL*>( aItem ), aLayer, aDimmed );
204 break;
205 case SCH_NO_CONNECT_T:
206 draw( static_cast<const SCH_NO_CONNECT*>( aItem ), aLayer );
207 break;
209 draw( static_cast<const SCH_BUS_ENTRY_BASE*>( aItem ), aLayer );
210 break;
212 draw( static_cast<const SCH_BUS_ENTRY_BASE*>( aItem ), aLayer );
213 break;
214 case SCH_BITMAP_T:
215 draw( static_cast<const SCH_BITMAP*>( aItem ), aLayer );
216 break;
217 case SCH_MARKER_T:
218 draw( static_cast<const SCH_MARKER*>( aItem ), aLayer );
219 break;
220 case SCH_GROUP_T:
221 draw( static_cast<const SCH_GROUP*>( aItem ), aLayer );
222 break;
223 default:
224 return;
225 }
226
227 if( drawBoundingBox )
228 drawItemBoundingBox( aItem );
229}
230
231
233{
234 if( const SCH_ITEM* item = dynamic_cast<const SCH_ITEM*>( aItem ) )
235 {
236 if( item->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
237 return;
238 }
239
240 BOX2I box = aItem->GetBoundingBox();
241
242 if( aItem->Type() == SCH_SYMBOL_T )
243 box = static_cast<const SCH_SYMBOL*>( aItem )->GetBodyBoundingBox();
244
245 m_gal->SetIsFill( false );
246 m_gal->SetIsStroke( true );
247 m_gal->SetStrokeColor( aItem->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 )
248 : COLOR4D( 0.2, 0.2, 0.2, 1 ) );
249 m_gal->SetLineWidth( schIUScale.MilsToIU( 3 ) );
250 m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
251}
252
253
255{
256 // TODO: it would be nice to have a more definitive test for this, but we've currently got
257 // no access to the VIEW_GROUP to see if it's cached or not.
258 return aItem->IsSelected();
259}
260
261
263{
264 if( m_schSettings.m_ShowUnit // showing a specific unit
265 && aItem->GetUnit() // item is unit-specific
266 && aItem->GetUnit() != m_schSettings.m_ShowUnit )
267 {
268 return false;
269 }
270
271 if( m_schSettings.m_ShowBodyStyle // showing a specific body style
272 && aItem->GetBodyStyle() // item is body-style-specific
273 && aItem->GetBodyStyle() != m_schSettings.m_ShowBodyStyle )
274 {
275 return false;
276 }
277
278 return true;
279}
280
281
283{
284 if( KIFONT::FONT* font = aItem->GetDrawFont( &m_schSettings ) )
285 return font;
286
287 return KIFONT::FONT::GetFont( m_schSettings.GetDefaultFont(), aItem->IsBold(), aItem->IsItalic() );
288}
289
290
291float SCH_PAINTER::getShadowWidth( bool aForHighlight ) const
292{
293 const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
294
295 int milsWidth = aForHighlight ? eeconfig()->m_Selection.highlight_thickness
297
298 // For best visuals the selection width must be a cross between the zoom level and the
299 // default line width.
300 return (float) std::fabs( matrix.GetScale().x * milsWidth ) + schIUScale.MilsToIU( milsWidth );
301}
302
303
304COLOR4D SCH_PAINTER::getRenderColor( const SCH_ITEM* aItem, int aLayer, bool aDrawingShadows,
305 bool aDimmed, bool aIgnoreNets ) const
306{
307 auto isBackgroundLayer =
308 []( int layer )
309 {
310 return layer == LAYER_DEVICE_BACKGROUND || layer == LAYER_NOTES_BACKGROUND
311 || layer == LAYER_SHAPES_BACKGROUND || layer == LAYER_SHEET_BACKGROUND;
312 };
313
314 COLOR4D color = m_schSettings.GetLayerColor( aLayer );
315
316 // Graphic items of a SYMBOL frequently use the LAYER_DEVICE layer color
317 // (i.e. when no specific color is set)
318 bool isSymbolChild = aItem->GetParentSymbol() != nullptr;
319
320 if( !m_schSettings.m_OverrideItemColors )
321 {
322 if( aItem->Type() == SCH_LINE_T )
323 {
324 color = static_cast<const SCH_LINE*>( aItem )->GetLineColor();
325 }
326 else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
327 {
328 color = static_cast<const SCH_BUS_WIRE_ENTRY*>( aItem )->GetBusEntryColor();
329 }
330 else if( aItem->Type() == SCH_JUNCTION_T )
331 {
332 color = static_cast<const SCH_JUNCTION*>( aItem )->GetJunctionColor();
333 }
334 else if( aItem->Type() == SCH_SHEET_T )
335 {
336 const SCH_SHEET* sheet = static_cast<const SCH_SHEET*>( aItem );
337
338 if( isBackgroundLayer( aLayer ) )
339 color = sheet->GetBackgroundColor();
340 else
341 color = sheet->GetBorderColor();
342 }
343 else if( aItem->Type() == SCH_SHAPE_T || aItem->Type() == SCH_RULE_AREA_T )
344 {
345 const SCH_SHAPE* shape = static_cast<const SCH_SHAPE*>( aItem );
346
347 if( isBackgroundLayer( aLayer ) )
348 {
349 switch( shape->GetFillMode() )
350 {
351 case FILL_T::NO_FILL:
352 break;
353
355 color = shape->GetStroke().GetColor();
356 break;
357
358 case FILL_T::HATCH:
362 color = shape->GetFillColor();
363 break;
364
366 color = m_schSettings.GetLayerColor( LAYER_DEVICE_BACKGROUND );
367 break;
368
369 default:
370 wxFAIL_MSG( wxT( "Unsupported fill type" ) );
371 }
372
373 // A filled shape means filled; if they didn't specify a fill colour then use
374 // the border colour.
375 if( shape->GetFillMode() != FILL_T::NO_FILL && color == COLOR4D::UNSPECIFIED )
376 {
377 if( aItem->Type() == SCH_RULE_AREA_T )
378 color = m_schSettings.GetLayerColor( LAYER_RULE_AREAS );
379 else if( isSymbolChild )
380 color = m_schSettings.GetLayerColor( LAYER_DEVICE );
381 else
382 color = m_schSettings.GetLayerColor( LAYER_NOTES );
383 }
384 }
385 else
386 {
387 color = shape->GetStroke().GetColor();
388 }
389 }
390 else if( aItem->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
391 {
392 const SCH_LABEL_BASE* label = static_cast<const SCH_LABEL_BASE*>( aItem );
393
394 if( label->GetTextColor() != COLOR4D::UNSPECIFIED )
395 color = label->GetTextColor(); // override color
396 else if( aIgnoreNets )
397 color = m_schSettings.GetLayerColor( aLayer ); // layer color
398 else
399 color = label->GetLabelColor(); // net/netclass color
400 }
401 else if( aItem->Type() == SCH_FIELD_T )
402 {
403 color = static_cast<const SCH_FIELD*>( aItem )->GetFieldColor();
404 }
405 else if( aItem->Type() == SCH_TEXTBOX_T || aItem->Type() == SCH_TABLECELL_T )
406 {
407 const SCH_TEXTBOX* textBox = static_cast<const SCH_TEXTBOX*>( aItem );
408
409 if( isBackgroundLayer( aLayer ) )
410 color = textBox->GetFillColor();
411 else if( !isSymbolChild || textBox->GetTextColor() != COLOR4D::UNSPECIFIED )
412 color = textBox->GetTextColor();
413 }
414 else if( const EDA_TEXT* otherTextItem = dynamic_cast<const EDA_TEXT*>( aItem ) )
415 {
416 if( !isSymbolChild || otherTextItem->GetTextColor() != COLOR4D::UNSPECIFIED )
417 color = otherTextItem->GetTextColor();
418 }
419
420 if( color.m_text )
421 color = COLOR4D( aItem->ResolveText( *color.m_text, &m_schematic->CurrentSheet() ) );
422 }
423 else /* overrideItemColors */
424 {
425 // If we ARE overriding the item colors, what do we do with non-item-color fills?
426 // There are two theories: we should leave them untouched, or we should drop them entirely.
427 // We currently implment the first.
428 if( isBackgroundLayer( aLayer) )
429 {
430 if( aItem->Type() == SCH_SHAPE_T || aItem->Type() == SCH_RULE_AREA_T )
431 {
432 const SCH_SHAPE* shape = static_cast<const SCH_SHAPE*>( aItem );
433
434 if( shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
435 color = shape->GetFillColor();
436 }
437 else if( aItem->Type() == SCH_SHEET_T )
438 {
439 const SCH_SHEET* sheet = static_cast<const SCH_SHEET*>( aItem );
440
441 color = sheet->GetBackgroundColor();
442 }
443 }
444 }
445
446 if( color == COLOR4D::UNSPECIFIED )
447 color = m_schSettings.GetLayerColor( aLayer );
448
449 if( aItem->IsBrightened() ) // Selection disambiguation, net highlighting, etc.
450 {
451 color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
452
453 if( aDrawingShadows )
454 {
455 if( aItem->IsSelected() )
456 color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS );
457 else
458 color = color.WithAlpha( 0.15 );
459 }
460 else if( isBackgroundLayer( aLayer ) )
461 {
462 color = color.WithAlpha( 0.2 );
463 }
464 }
465 else if( aItem->IsSelected() && aDrawingShadows )
466 {
467 color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS );
468 }
469 else if( aItem->IsSelected() && isBackgroundLayer( aLayer ) )
470 {
471 // Selected items will be painted over all other items, so make backgrounds translucent so
472 // that non-selected overlapping objects are visible
473 color = color.WithAlpha( 0.5 );
474 }
475
476 if( m_schSettings.m_ShowDisabled
477 || ( m_schSettings.m_ShowGraphicsDisabled && aItem->Type() != SCH_FIELD_T ) )
478 {
479 color = color.Darken( 0.5f );
480 }
481
482 if( aDimmed && !( aItem->IsSelected() && aDrawingShadows ) )
483 {
484 COLOR4D sheetColour = m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
485 color.Desaturate();
486 color = color.Mix( sheetColour, 0.5f );
487 }
488
489 if( aItem->GetForcedTransparency() > 0.0 )
490 color = color.WithAlpha( color.a * ( 1.0 - aItem->GetForcedTransparency() ) );
491
492 return color;
493}
494
495
496float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows,
497 bool aDrawingWireColorHighlights ) const
498{
499 wxCHECK( aItem, static_cast<float>( schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS ) ) );
500
501 int pen = aItem->GetEffectivePenWidth( &m_schSettings );
502 float width = pen;
503
504 if( aItem->IsBrightened() || aItem->IsSelected() )
505 {
506 if( aDrawingShadows && aItem->IsType( g_ScaledSelectionTypes ) )
507 width += getShadowWidth( aItem->IsBrightened() );
508 }
509
510 if( aDrawingWireColorHighlights )
511 {
512 float colorHighlightWidth = schIUScale.MilsToIU( 15.0 );
513 EESCHEMA_SETTINGS* eeschemaCfg = eeconfig();
514
515 if( eeschemaCfg )
516 colorHighlightWidth = schIUScale.MilsToIU( eeschemaCfg->m_Selection.highlight_netclass_colors_thickness );
517
518 width += colorHighlightWidth;
519 }
520
521 return width;
522}
523
524
525float SCH_PAINTER::getTextThickness( const SCH_ITEM* aItem ) const
526{
527 int pen = m_schSettings.GetDefaultPenWidth();
528
529 switch( aItem->Type() )
530 {
531 case SCH_FIELD_T:
532 pen = static_cast<const SCH_FIELD*>( aItem )->GetEffectiveTextPenWidth( pen );
533 break;
534
535 case SCH_TEXT_T:
536 pen = static_cast<const SCH_TEXT*>( aItem )->GetEffectiveTextPenWidth( pen );
537 break;
538
539 case SCH_LABEL_T:
542 case SCH_HIER_LABEL_T:
543 case SCH_SHEET_PIN_T:
544 pen = static_cast<const SCH_LABEL_BASE*>( aItem )->GetEffectiveTextPenWidth( pen );
545 break;
546
547 case SCH_TEXTBOX_T:
548 case SCH_TABLECELL_T:
549 pen = static_cast<const SCH_TEXTBOX*>( aItem )->GetEffectiveTextPenWidth( pen );
550 break;
551
552 default:
553 UNIMPLEMENTED_FOR( aItem->GetClass() );
554 }
555
556 return (float) pen;
557}
558
559
561{
562 int docTextSize = schIUScale.MilsToIU( 50 );
563 int screenTextSize = std::abs( (int) m_gal->GetScreenWorldMatrix().GetScale().y * 7 );
564
565 // 66% zoom-relative
566 return KiROUND( ( docTextSize + screenTextSize * 2 ) / 3.0 );
567}
568
569
570static bool isFieldsLayer( int aLayer )
571{
572 return aLayer == LAYER_REFERENCEPART
573 || aLayer == LAYER_VALUEPART
574 || aLayer == LAYER_INTERSHEET_REFS
575 || aLayer == LAYER_NETCLASS_REFS
576 || aLayer == LAYER_FIELDS
577 || aLayer == LAYER_SHEETNAME
578 || aLayer == LAYER_SHEETFILENAME
579 || aLayer == LAYER_SHEETFIELDS;
580}
581
582
583static BOX2I GetTextExtents( const wxString& aText, const VECTOR2D& aPosition, KIFONT::FONT& aFont,
584 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
585{
586 const VECTOR2I extents = aFont.StringBoundaryLimits( aText, aAttrs.m_Size, aAttrs.m_StrokeWidth,
587 aAttrs.m_Bold, aAttrs.m_Italic, aFontMetrics );
588 BOX2I box( aPosition, VECTOR2I( extents.x, aAttrs.m_Size.y ) );
589
590 switch( aAttrs.m_Halign )
591 {
592 case GR_TEXT_H_ALIGN_LEFT: break;
593 case GR_TEXT_H_ALIGN_CENTER: box.SetX( box.GetX() - box.GetWidth() / 2 ); break;
594 case GR_TEXT_H_ALIGN_RIGHT: box.SetX( box.GetX() - box.GetWidth() ); break;
595 case GR_TEXT_H_ALIGN_INDETERMINATE: wxFAIL_MSG( wxT( "Legal only in dialogs" ) ); break;
596 }
597
598 switch( aAttrs.m_Valign )
599 {
600 case GR_TEXT_V_ALIGN_TOP: break;
601 case GR_TEXT_V_ALIGN_CENTER: box.SetY( box.GetY() - box.GetHeight() / 2 ); break;
602 case GR_TEXT_V_ALIGN_BOTTOM: box.SetY( box.GetY() - box.GetHeight() ); break;
603 case GR_TEXT_V_ALIGN_INDETERMINATE: wxFAIL_MSG( wxT( "Legal only in dialogs" ) ); break;
604 }
605
606 box.Normalize(); // Make h and v sizes always >= 0
607 box = box.GetBoundingBoxRotated( aPosition, aAttrs.m_Angle );
608
609 return box;
610}
611
612
613static void strokeText( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
614 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics,
615 std::optional<VECTOR2I> aMousePos = std::nullopt, wxString* aActiveUrl = nullptr )
616{
617 KIFONT::FONT* font = aAttrs.m_Font;
618
619 if( !font )
620 font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, aAttrs.m_Bold, aAttrs.m_Italic );
621
622 aGal.SetIsFill( font->IsOutline() );
623 aGal.SetIsStroke( font->IsStroke() );
624
625 font->Draw( &aGal, aText, aPosition, aAttrs, aFontMetrics, aMousePos, aActiveUrl );
626}
627
628
629static void bitmapText( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
630 const TEXT_ATTRIBUTES& aAttrs )
631{
632 // Bitmap font has different metrics from the stroke font so we compensate a bit before
633 // stroking
634 aGal.SetGlyphSize( VECTOR2I( aAttrs.m_Size.x, KiROUND( aAttrs.m_Size.y * 1.05 ) ) );
635 aGal.SetLineWidth( (float) aAttrs.m_StrokeWidth * 1.35f );
636
637 aGal.SetHorizontalJustify( aAttrs.m_Halign );
638 aGal.SetVerticalJustify( aAttrs.m_Valign );
639
640 aGal.BitmapText( aText, aPosition, aAttrs.m_Angle );
641}
642
643
644static void knockoutText( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
645 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
646{
647 TEXT_ATTRIBUTES attrs( aAttrs );
648 KIFONT::FONT* font = aAttrs.m_Font;
649
650 if( !font )
651 {
652 font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, attrs.m_Bold,
653 attrs.m_Italic );
654 }
655
657 SHAPE_POLY_SET knockouts;
658
659 CALLBACK_GAL callback_gal( empty_opts,
660 // Polygon callback
661 [&]( const SHAPE_LINE_CHAIN& aPoly )
662 {
663 knockouts.AddOutline( aPoly );
664 } );
665
666 callback_gal.SetIsFill( false );
667 callback_gal.SetIsStroke( true );
668 callback_gal.SetLineWidth( (float) attrs.m_StrokeWidth );
669 font->Draw( &callback_gal, aText, aPosition, attrs, aFontMetrics );
670
671 BOX2I bbox = knockouts.BBox( attrs.m_StrokeWidth * 2 );
672 SHAPE_POLY_SET finalPoly;
673
674 finalPoly.NewOutline();
675 finalPoly.Append( bbox.GetLeft(), bbox.GetTop() );
676 finalPoly.Append( bbox.GetRight(), bbox.GetTop() );
677 finalPoly.Append( bbox.GetRight(), bbox.GetBottom() );
678 finalPoly.Append( bbox.GetLeft(), bbox.GetBottom() );
679
680 finalPoly.BooleanSubtract( knockouts );
681 finalPoly.Fracture();
682
683 aGal.SetIsStroke( false );
684 aGal.SetIsFill( true );
685 aGal.SetFillColor( attrs.m_Color );
686 aGal.DrawPolygon( finalPoly );
687}
688
689
690static void boxText( KIGFX::GAL& aGal, const wxString& aText, const VECTOR2D& aPosition,
691 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics )
692{
693 KIFONT::FONT* font = aAttrs.m_Font;
694
695 if( !font )
696 font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, aAttrs.m_Bold, aAttrs.m_Italic );
697
698 BOX2I box = GetTextExtents( aText, aPosition, *font, aAttrs, aFontMetrics );
699
700 // Give the highlight a bit of margin.
701 box.Inflate( 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 aShape->UpdateHatching();
2108 m_gal->SetIsFill( false );
2109 m_gal->SetIsStroke( true );
2110 m_gal->SetStrokeColor( color );
2111 m_gal->SetLineWidth( aShape->GetHatchLineWidth() );
2112
2113 for( const SEG& seg : aShape->GetHatchLines() )
2114 m_gal->DrawLine( seg.A, seg.B );
2115
2116 break;
2117
2120 // Do not fill the shape in B&W print mode, to avoid to visible items inside the shape
2121 if( !m_schSettings.PrintBlackAndWhiteReq() )
2122 {
2123 m_gal->SetIsFill( true );
2124 m_gal->SetIsStroke( false );
2125 m_gal->SetFillColor( color );
2126
2127 drawShape( aShape );
2128 }
2129 break;
2130
2131 default:
2132 wxFAIL_MSG( wxT( "Unsupported fill type" ) );
2133 }
2134 }
2135 else if( aLayer == LAYER_DEVICE || aLayer == LAYER_NOTES || aLayer == LAYER_PRIVATE_NOTES
2136 || aLayer == LAYER_RULE_AREAS )
2137 {
2138 // Shapes filled with the device colour must be filled in the foreground
2139 if( aShape->GetFillMode() == FILL_T::FILLED_SHAPE )
2140 {
2141 m_gal->SetIsFill( true );
2142 m_gal->SetIsStroke( false );
2143 m_gal->SetFillColor( color );
2144
2145 drawShape( aShape );
2146 }
2147
2148 float lineWidth = getLineWidth( aShape, drawingShadows );
2149
2150 if( lineWidth > 0 )
2151 {
2152 m_gal->SetIsFill( false );
2153 m_gal->SetIsStroke( true );
2154 m_gal->SetLineWidth( lineWidth );
2155 m_gal->SetStrokeColor( color );
2156
2157 if( lineStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows )
2158 {
2159 drawShape( aShape );
2160 }
2161 else
2162 {
2163 std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
2164
2165 for( SHAPE* shape : shapes )
2166 {
2167 STROKE_PARAMS::Stroke( shape, lineStyle, KiROUND( lineWidth ), &m_schSettings,
2168 [this]( const VECTOR2I& a, const VECTOR2I& b )
2169 {
2170 // DrawLine has problem with 0 length lines so enforce minimum
2171 if( a == b )
2172 m_gal->DrawLine( a+1, b );
2173 else
2174 m_gal->DrawLine( a, b );
2175 } );
2176 }
2177
2178 for( SHAPE* shape : shapes )
2179 delete shape;
2180 }
2181 }
2182 }
2183}
2184
2185
2186void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed )
2187{
2188 if( !isUnitAndConversionShown( aText ) )
2189 return;
2190
2191 if( aText->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2192 return;
2193
2194 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2195
2196 if( m_schSettings.IsPrinting() && drawingShadows )
2197 return;
2198
2199 if( drawingShadows && !( aText->IsBrightened() || aText->IsSelected() ) )
2200 return;
2201
2202 switch( aText->Type() )
2203 {
2204 case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break;
2205 case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break;
2206 case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break;
2207 case SCH_DIRECTIVE_LABEL_T: aLayer = LAYER_NETCLASS_REFS; break;
2208 case SCH_LABEL_T: aLayer = LAYER_LOCLABEL; break;
2209 case SCH_TEXT_T: aLayer = aText->GetParentSymbol() ? LAYER_DEVICE
2210 : LAYER_NOTES; break;
2211 default: aLayer = LAYER_NOTES; break;
2212 }
2213
2214 COLOR4D color = getRenderColor( aText, aLayer, drawingShadows, aDimmed );
2215
2216 if( m_schematic )
2217 {
2218 SCH_CONNECTION* conn = nullptr;
2219
2220 if( !aText->IsConnectivityDirty() )
2221 conn = aText->Connection();
2222
2223 if( conn && conn->IsBus() )
2224 color = getRenderColor( aText, LAYER_BUS, drawingShadows );
2225 }
2226
2227 if( !( aText->IsVisible() || aText->IsForceVisible() ) )
2228 {
2229 if( m_schSettings.m_IsSymbolEditor || eeconfig()->m_Appearance.show_hidden_fields )
2230 color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
2231 else
2232 return;
2233 }
2234
2235 m_gal->SetStrokeColor( color );
2236 m_gal->SetFillColor( color );
2237 m_gal->SetHoverColor( color );
2238
2239 wxString shownText( aText->GetShownText( true ) );
2240 VECTOR2I text_offset = aText->GetSchematicTextOffset( &m_schSettings );
2241 TEXT_ATTRIBUTES attrs = aText->GetAttributes();
2242 KIFONT::FONT* font = getFont( aText );
2243
2244 attrs.m_Angle = aText->GetDrawRotation();
2245 attrs.m_StrokeWidth = KiROUND( getTextThickness( aText ) );
2246
2247 // Adjust text drawn in an outline font to more closely mimic the positioning of
2248 // SCH_FIELD text.
2249 if( font->IsOutline() && aText->Type() == SCH_TEXT_T )
2250 {
2251 BOX2I firstLineBBox = aText->GetTextBox( nullptr, 0 );
2252 int sizeDiff = firstLineBBox.GetHeight() - aText->GetTextSize().y;
2253 int adjust = KiROUND( sizeDiff * 0.35 );
2254 VECTOR2I adjust_offset( 0, adjust );
2255
2256 RotatePoint( adjust_offset, aText->GetDrawRotation() );
2257 text_offset += adjust_offset;
2258 }
2259
2260 if( drawingShadows && font->IsOutline() )
2261 {
2262 BOX2I bBox = aText->GetBoundingBox();
2263 bBox.Inflate( KiROUND( getTextThickness( aText ) * 2 ) );
2264
2265 m_gal->SetIsStroke( false );
2266 m_gal->SetIsFill( true );
2267 m_gal->DrawRectangle( bBox.GetPosition(), bBox.GetEnd() );
2268 }
2269 else if( aText->GetLayer() == LAYER_DEVICE )
2270 {
2271 BOX2I bBox = aText->GetBoundingBox();
2272 VECTOR2D pos = bBox.Centre();
2273
2274 // Due to the fact a shadow text can be drawn left or right aligned, it needs to be
2275 // offset by shadowWidth/2 to be drawn at the same place as normal text.
2276 // For some reason we need to slightly modify this offset for a better look (better
2277 // alignment of shadow shape), for KiCad font only.
2278 double shadowOffset = 0.0;
2279
2280 if( drawingShadows )
2281 {
2282 double shadowWidth = getShadowWidth( !aText->IsSelected() );
2283 attrs.m_StrokeWidth += getShadowWidth( !aText->IsSelected() );
2284
2285 const double adjust = 1.2f; // Value chosen after tests
2286 shadowOffset = shadowWidth/2.0f * adjust;
2287 }
2288
2289 if( attrs.m_Angle == ANGLE_VERTICAL )
2290 {
2291 switch( attrs.m_Halign )
2292 {
2294 pos.y = bBox.GetBottom() + shadowOffset;
2295 break;
2297 pos.y = ( bBox.GetTop() + bBox.GetBottom() ) / 2.0;
2298 break;
2300 pos.y = bBox.GetTop() - shadowOffset;
2301 break;
2303 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
2304 break;
2305 }
2306 }
2307 else
2308 {
2309 switch( attrs.m_Halign )
2310 {
2312 pos.x = bBox.GetLeft() - shadowOffset;
2313 break;
2315 pos.x = ( bBox.GetLeft() + bBox.GetRight() ) / 2.0;
2316 break;
2318 pos.x = bBox.GetRight() + shadowOffset;
2319 break;
2321 wxFAIL_MSG( wxT( "Indeterminate state legal only in dialogs." ) );
2322 break;
2323 }
2324 }
2325
2326 // Because the text vertical position is the bounding box center, the text is drawn as
2327 // vertically centered.
2329
2330 strokeText( *m_gal, shownText, pos, attrs, aText->GetFontMetrics() );
2331 }
2332 else if( drawingShadows )
2333 {
2334 m_gal->SetIsFill( false );
2335 m_gal->SetIsStroke( true );
2336 attrs.m_StrokeWidth += KiROUND( getShadowWidth( !aText->IsSelected() ) );
2337 attrs.m_Underlined = false;
2338
2339 // Fudge factors to match 6.0 positioning
2340 // New text stroking has width dependent offset but we need to center the shadow on the
2341 // stroke. NB this offset is in font.cpp also.
2342 int fudge = KiROUND( getShadowWidth( !aText->IsSelected() ) / 1.52 );
2343
2344 if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_0 )
2345 text_offset.x -= fudge;
2346 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_90 )
2347 text_offset.y -= fudge;
2348 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_RIGHT && attrs.m_Angle == ANGLE_0 )
2349 text_offset.x += fudge;
2350 else if( attrs.m_Halign == GR_TEXT_H_ALIGN_LEFT && attrs.m_Angle == ANGLE_90 )
2351 text_offset.y += fudge;
2352
2353 strokeText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs,
2354 aText->GetFontMetrics() );
2355 }
2356 else
2357 {
2358 wxString activeUrl;
2359
2360 if( aText->IsRollover() && !aText->IsMoving() )
2361 {
2362 // Highlight any urls found within the text
2363 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2364
2365 // Highlight the whole text if it has a link definition
2366 if( aText->HasHyperlink() )
2367 {
2368 attrs.m_Hover = true;
2369 attrs.m_Underlined = true;
2370 activeUrl = aText->GetHyperlink();
2371 }
2372 }
2373
2374 if( nonCached( aText ) && aText->RenderAsBitmap( m_gal->GetWorldScale() )
2375 && !shownText.Contains( wxT( "\n" ) ) )
2376 {
2377 bitmapText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs );
2378 const_cast<SCH_TEXT*>( aText )->SetFlags( IS_SHOWN_AS_BITMAP );
2379 }
2380 else
2381 {
2382 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2383
2384 if( !aText->IsRollover() && font->IsOutline() )
2385 cache = aText->GetRenderCache( font, shownText, text_offset );
2386
2387 if( cache )
2388 {
2389 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2390 m_gal->DrawGlyphs( *cache );
2391 }
2392 else
2393 {
2394 strokeText( *m_gal, shownText, aText->GetDrawPos() + text_offset, attrs,
2395 aText->GetFontMetrics(), aText->GetRolloverPos(), &activeUrl );
2396 }
2397
2398 const_cast<SCH_TEXT*>( aText )->ClearFlags( IS_SHOWN_AS_BITMAP );
2399 }
2400
2401 aText->SetActiveUrl( activeUrl );
2402 }
2403
2404 // Draw anchor
2405 if( aText->IsSelected() )
2406 {
2407 bool showAnchor;
2408
2409 switch( aText->Type() )
2410 {
2411 case SCH_TEXT_T:
2412 showAnchor = true;
2413 break;
2414
2415 case SCH_LABEL_T:
2416 // Don't clutter things up if we're already showing a dangling indicator
2417 showAnchor = !static_cast<const SCH_LABEL*>( aText )->IsDangling();
2418 break;
2419
2421 case SCH_HIER_LABEL_T:
2422 case SCH_GLOBAL_LABEL_T:
2423 case SCH_SHEET_PIN_T:
2424 // These all have shapes and so don't need anchors
2425 showAnchor = false;
2426 break;
2427
2428 default:
2429 showAnchor = false;
2430 break;
2431 }
2432
2433 if( showAnchor )
2434 drawAnchor( aText->GetPosition(), drawingShadows );
2435 }
2436}
2437
2438
2439void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer, bool aDimmed )
2440{
2441 if( aTextBox->Type() == SCH_TABLECELL_T )
2442 {
2443 const SCH_TABLECELL* cell = static_cast<const SCH_TABLECELL*>( aTextBox );
2444
2445 if( cell->GetColSpan() == 0 || cell->GetRowSpan() == 0 )
2446 return;
2447 }
2448
2449 if( !isUnitAndConversionShown( aTextBox ) )
2450 return;
2451
2452 if( aTextBox->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2453 return;
2454
2455 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2456
2457 if( m_schSettings.IsPrinting() && drawingShadows )
2458 return;
2459
2460 COLOR4D color = getRenderColor( aTextBox, aLayer, drawingShadows, aDimmed );
2461 COLOR4D bg = m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
2462 float borderWidth = getLineWidth( aTextBox, drawingShadows );
2463 KIFONT::FONT* font = getFont( aTextBox );
2464
2465 auto drawText =
2466 [&]()
2467 {
2468 wxString shownText = aTextBox->GetShownText( true );
2469 TEXT_ATTRIBUTES attrs = aTextBox->GetAttributes();
2470 wxString activeUrl;
2471
2472 attrs.m_Angle = aTextBox->GetDrawRotation();
2473 attrs.m_StrokeWidth = KiROUND( getTextThickness( aTextBox ) );
2474
2475 if( aTextBox->IsRollover() && !aTextBox->IsMoving() )
2476 {
2477 // Highlight any urls found within the text
2478 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2479
2480 // Highlight the whole text if it has a link definition
2481 if( aTextBox->HasHyperlink() )
2482 {
2483 attrs.m_Hover = true;
2484 attrs.m_Underlined = true;
2485 activeUrl = aTextBox->GetHyperlink();
2486 }
2487 }
2488
2489 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
2490
2491 if( !aTextBox->IsRollover() && font->IsOutline() )
2492 cache = aTextBox->GetRenderCache( font, shownText );
2493
2494 if( cache )
2495 {
2496 m_gal->SetLineWidth( attrs.m_StrokeWidth );
2497 m_gal->DrawGlyphs( *cache );
2498 }
2499 else
2500 {
2501 strokeText( *m_gal, shownText, aTextBox->GetDrawPos(), attrs,
2502 aTextBox->GetFontMetrics(), aTextBox->GetRolloverPos(), &activeUrl );
2503 }
2504
2505 aTextBox->SetActiveUrl( activeUrl );
2506 };
2507
2508 if( drawingShadows && !( aTextBox->IsBrightened() || aTextBox->IsSelected() ) )
2509 return;
2510
2511 m_gal->SetFillColor( color );
2512 m_gal->SetStrokeColor( color );
2513 m_gal->SetHoverColor( color );
2514
2515 if( aLayer == LAYER_SELECTION_SHADOWS )
2516 {
2517 m_gal->SetIsFill( true );
2518 m_gal->SetIsStroke( false );
2519 m_gal->SetLineWidth( borderWidth );
2520
2521 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2522 }
2523 else if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_NOTES_BACKGROUND
2524 || aLayer == LAYER_SHAPES_BACKGROUND )
2525 {
2526 // Do not fill the shape in B&W print mode, to avoid to visible items
2527 // inside the shape
2528 if( aTextBox->IsSolidFill() && !m_schSettings.PrintBlackAndWhiteReq() )
2529 {
2530 m_gal->SetIsFill( true );
2531 m_gal->SetIsStroke( false );
2532 m_gal->SetLineWidth( borderWidth );
2533
2534 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2535 }
2536 }
2537 else if( aLayer == LAYER_DEVICE || aLayer == LAYER_NOTES || aLayer == LAYER_PRIVATE_NOTES )
2538 {
2539 drawText();
2540
2541 if( aTextBox->Type() != SCH_TABLECELL_T && borderWidth > 0 )
2542 {
2543 COLOR4D borderColor = aTextBox->GetStroke().GetColor();
2544 LINE_STYLE borderStyle = aTextBox->GetEffectiveLineStyle();
2545 double transparency = aTextBox->GetForcedTransparency();
2546
2547 if( m_schSettings.m_OverrideItemColors || aTextBox->IsBrightened()
2548 || borderColor == COLOR4D::UNSPECIFIED )
2549 {
2550 borderColor = m_schSettings.GetLayerColor( aLayer );
2551 }
2552
2553 if( transparency > 0.0 )
2554 borderColor = borderColor.WithAlpha( borderColor.a * ( 1.0 - transparency ) );
2555
2556 if( aDimmed )
2557 {
2558 borderColor = borderColor.Mix( bg, 0.5f );
2559 borderColor.Desaturate( );
2560 }
2561
2562 m_gal->SetIsFill( false );
2563 m_gal->SetIsStroke( true );
2564 m_gal->SetStrokeColor( borderColor );
2565 m_gal->SetLineWidth( borderWidth );
2566
2567 if( borderStyle <= LINE_STYLE::FIRST_TYPE || drawingShadows )
2568 {
2569 m_gal->DrawRectangle( aTextBox->GetPosition(), aTextBox->GetEnd() );
2570 }
2571 else
2572 {
2573 std::vector<SHAPE*> shapes = aTextBox->MakeEffectiveShapes( true );
2574
2575 for( SHAPE* shape : shapes )
2576 {
2577 STROKE_PARAMS::Stroke( shape, borderStyle, KiROUND( borderWidth ),
2579 [this]( const VECTOR2I& a, const VECTOR2I& b )
2580 {
2581 // DrawLine has problem with 0 length lines so enforce minimum
2582 if( a == b )
2583 m_gal->DrawLine( a+1, b );
2584 else
2585 m_gal->DrawLine( a, b );
2586 } );
2587 }
2588
2589 for( SHAPE* shape : shapes )
2590 delete shape;
2591 }
2592 }
2593 }
2594}
2595
2596
2597void SCH_PAINTER::draw( const SCH_TABLE* aTable, int aLayer, bool aDimmed )
2598{
2599 if( aTable->GetCells().empty() )
2600 return;
2601
2602 for( SCH_TABLECELL* cell : aTable->GetCells() )
2603 draw( cell, aLayer, aDimmed );
2604
2605 if( aLayer == LAYER_SELECTION_SHADOWS )
2606 return;
2607
2608 aTable->DrawBorders(
2609 [&]( const VECTOR2I& ptA, const VECTOR2I& ptB, const STROKE_PARAMS& stroke )
2610 {
2611 int lineWidth = stroke.GetWidth();
2612 COLOR4D color = stroke.GetColor();
2613 LINE_STYLE lineStyle = stroke.GetLineStyle();
2614
2615 if( lineWidth == 0 )
2616 lineWidth = m_schSettings.GetDefaultPenWidth();
2617
2618 if( color == COLOR4D::UNSPECIFIED )
2619 color = m_schSettings.GetLayerColor( LAYER_NOTES );
2620
2621 if( lineStyle == LINE_STYLE::DEFAULT )
2622 lineStyle = LINE_STYLE::SOLID;
2623
2624 m_gal->SetIsFill( false );
2625 m_gal->SetIsStroke( true );
2626 m_gal->SetStrokeColor( color );
2627 m_gal->SetLineWidth( (float) lineWidth );
2628
2629 if( lineStyle <= LINE_STYLE::FIRST_TYPE )
2630 {
2631 m_gal->DrawLine( ptA, ptB );
2632 }
2633 else
2634 {
2635 SHAPE_SEGMENT seg( ptA, ptB );
2636 STROKE_PARAMS::Stroke( &seg, lineStyle, lineWidth, &m_schSettings,
2637 [&]( const VECTOR2I& a, const VECTOR2I& b )
2638 {
2639 // DrawLine has problem with 0 length lines so enforce minimum
2640 if( a == b )
2641 m_gal->DrawLine( a+1, b );
2642 else
2643 m_gal->DrawLine( a, b );
2644 } );
2645 }
2646 } );
2647}
2648
2649
2650wxString SCH_PAINTER::expandLibItemTextVars( const wxString& aSourceText,
2651 const SCH_SYMBOL* aSymbolContext )
2652{
2653 std::function<bool( wxString* )> symbolResolver =
2654 [&]( wxString* token ) -> bool
2655 {
2656 if( !m_schematic )
2657 return false;
2658
2659 return aSymbolContext->ResolveTextVar( &m_schematic->CurrentSheet(), token );
2660 };
2661
2662 return ExpandTextVars( aSourceText, &symbolResolver );
2663}
2664
2665
2666void SCH_PAINTER::draw( const SCH_SYMBOL* aSymbol, int aLayer )
2667{
2668 auto t1 = std::chrono::high_resolution_clock::now();
2669 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2670
2671 std::optional<SCH_SHEET_PATH> optSheetPath;
2672
2673 wxString variantName;
2674
2675 if( m_schematic )
2676 {
2677 optSheetPath = m_schematic->CurrentSheet();
2678 variantName = m_schematic->GetCurrentVariant();
2679 wxLogTrace( traceSchPainter,
2680 "SCH_PAINTER::draw symbol %s: Current sheet path='%s', variant='%s', size=%zu, empty=%d",
2681 aSymbol->m_Uuid.AsString(),
2682 variantName.IsEmpty() ? GetDefaultVariantName() : variantName,
2683 optSheetPath->Path().AsString(),
2684 optSheetPath->size(),
2685 optSheetPath->empty() ? 1 : 0 );
2686 }
2687
2688 SCH_SHEET_PATH* sheetPath = optSheetPath ? &optSheetPath.value() : nullptr;
2689 bool DNP = aSymbol->GetDNP( sheetPath, variantName );
2690 bool markExclusion = eeconfig()->m_Appearance.mark_sim_exclusions && aSymbol->GetExcludedFromSim( sheetPath,
2691 variantName );
2692
2693 if( m_schSettings.IsPrinting() && drawingShadows )
2694 return;
2695
2696 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
2697 {
2698 for( const SCH_FIELD& field : aSymbol->GetFields() )
2699 draw( &field, aLayer, DNP );
2700 }
2701
2702 if( isFieldsLayer( aLayer ) )
2703 return;
2704
2705 if( drawingShadows && !( aSymbol->IsBrightened() || aSymbol->IsSelected() ) )
2706 {
2707 // Don't exit here; symbol may still have selected pins
2708 // return;
2709 }
2710
2711 int unit = m_schematic ? aSymbol->GetUnitSelection( &m_schematic->CurrentSheet() ) : 1;
2712 int bodyStyle = aSymbol->GetBodyStyle();
2713
2714 // Use dummy symbol if the actual couldn't be found (or couldn't be locked).
2715 LIB_SYMBOL* originalSymbol =
2716 aSymbol->GetLibSymbolRef() ? aSymbol->GetLibSymbolRef().get() : LIB_SYMBOL::GetDummy();
2717 std::vector<SCH_PIN*> originalPins = originalSymbol->GetGraphicalPins( unit, bodyStyle );
2718
2719 // Copy the source so we can re-orient and translate it.
2720 auto tCopy1 = std::chrono::high_resolution_clock::now();
2721 LIB_SYMBOL tempSymbol( *originalSymbol, nullptr, false );
2722 auto tCopy2 = std::chrono::high_resolution_clock::now();
2723
2724 if( std::chrono::duration_cast<std::chrono::microseconds>( tCopy2 - tCopy1 ).count() > 100 )
2725 {
2726 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw symbol copy %s: %lld us", aSymbol->m_Uuid.AsString(),
2727 std::chrono::duration_cast<std::chrono::microseconds>( tCopy2 - tCopy1 ).count() );
2728 }
2729
2730 std::vector<SCH_PIN*> tempPins = tempSymbol.GetGraphicalPins( unit, bodyStyle );
2731
2732 tempSymbol.SetFlags( aSymbol->GetFlags() );
2733
2734 OrientAndMirrorSymbolItems( &tempSymbol, aSymbol->GetOrientation() );
2735
2736 for( SCH_ITEM& tempItem : tempSymbol.GetDrawItems() )
2737 {
2738 tempItem.SetFlags( aSymbol->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2739 tempItem.Move( aSymbol->GetPosition() );
2740
2741 if( tempItem.Type() == SCH_TEXT_T )
2742 {
2743 SCH_TEXT* textItem = static_cast<SCH_TEXT*>( &tempItem );
2744
2745 if( textItem->HasTextVars() )
2746 textItem->SetText( expandLibItemTextVars( textItem->GetText(), aSymbol ) );
2747 }
2748 else if( tempItem.Type() == SCH_TEXTBOX_T )
2749 {
2750 SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( &tempItem );
2751
2752 if( textboxItem->HasTextVars() )
2753 textboxItem->SetText( expandLibItemTextVars( textboxItem->GetText(), aSymbol ) );
2754 }
2755 }
2756
2757 // Copy the pin info from the symbol to the temp pins
2758 for( unsigned i = 0; i < tempPins.size(); ++ i )
2759 {
2760 SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
2761 SCH_PIN* tempPin = tempPins[ i ];
2762
2763 if( !symbolPin )
2764 continue;
2765
2766 tempPin->ClearFlags();
2767 tempPin->SetFlags( symbolPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2768 // IS_SHOWN_AS_BITMAP
2769
2770 tempPin->SetName( expandLibItemTextVars( symbolPin->GetShownName(), aSymbol ) );
2771 tempPin->SetType( symbolPin->GetType() );
2772 tempPin->SetShape( symbolPin->GetShape() );
2773
2774 if( symbolPin->IsDangling() )
2775 tempPin->SetFlags( IS_DANGLING );
2776 else
2777 tempPin->ClearFlags( IS_DANGLING );
2778
2779 tempPin->SetOperatingPoint( symbolPin->GetOperatingPoint() );
2780 }
2781
2782 draw( &tempSymbol, aLayer, false, aSymbol->GetUnit(), aSymbol->GetBodyStyle(), DNP );
2783
2784 for( unsigned i = 0; i < tempPins.size(); ++i )
2785 {
2786 SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] );
2787 SCH_PIN* tempPin = tempPins[ i ];
2788
2789 if( !symbolPin )
2790 continue;
2791
2792 symbolPin->ClearFlags();
2793 tempPin->ClearFlags( IS_DANGLING ); // Clear this temporary flag
2794 symbolPin->SetFlags( tempPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED,
2795 // IS_SHOWN_AS_BITMAP
2796 }
2797
2798 // Draw DNP and EXCLUDE from SIM markers.
2799 // These drawings are associated to the symbol body, so draw them only when the LAYER_DEVICE
2800 // is drawn (to avoid draw artifacts).
2801 if( DNP && aLayer == LAYER_DEVICE )
2802 {
2803 COLOR4D marker_color = m_schSettings.GetLayerColor( LAYER_DNP_MARKER );
2804 BOX2I bbox = aSymbol->GetBodyBoundingBox();
2805 BOX2I pins = aSymbol->GetBodyAndPinsBoundingBox();
2806 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
2807 std::max( bbox.GetY() - pins.GetY(),
2808 pins.GetEnd().y - bbox.GetEnd().y ) );
2809 int strokeWidth = 3 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
2810
2811 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
2812 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
2813 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
2814
2815 VECTOR2I pt1 = bbox.GetOrigin();
2816 VECTOR2I pt2 = bbox.GetEnd();
2817
2819 m_gal->AdvanceDepth();
2820 m_gal->SetIsStroke( true );
2821 m_gal->SetIsFill( true );
2822 m_gal->SetStrokeColor( marker_color );
2823 m_gal->SetFillColor( marker_color );
2824
2825 m_gal->DrawSegment( pt1, pt2, strokeWidth );
2826 std::swap( pt1.x, pt2.x );
2827 m_gal->DrawSegment( pt1, pt2, strokeWidth );
2828 }
2829
2830 if( markExclusion && aLayer == LAYER_DEVICE )
2831 {
2832 COLOR4D marker_color = m_schSettings.GetLayerColor( LAYER_EXCLUDED_FROM_SIM );
2833 BOX2I bbox = aSymbol->GetBodyBoundingBox();
2834 int strokeWidth = schIUScale.MilsToIU( ADVANCED_CFG::GetCfg().m_ExcludeFromSimulationLineWidth );
2835
2836 bbox.Inflate( KiROUND( strokeWidth * 0.5 ) );
2837
2839 m_gal->AdvanceDepth();
2840 m_gal->SetIsStroke( true );
2841 m_gal->SetIsFill( true );
2842 m_gal->SetStrokeColor( marker_color );
2843 m_gal->SetFillColor( marker_color );
2844
2845 m_gal->DrawSegment( bbox.GetPosition(), VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), strokeWidth );
2846 m_gal->DrawSegment( VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), bbox.GetEnd(), strokeWidth );
2847 m_gal->DrawSegment( bbox.GetEnd(), VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), strokeWidth );
2848 m_gal->DrawSegment( VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), bbox.GetPosition(), strokeWidth );
2849
2850 int offset = 2 * strokeWidth;
2851 VECTOR2D center = bbox.GetEnd() + VECTOR2D( offset + strokeWidth, -offset );
2852 VECTOR2D left = center + VECTOR2D( -offset, 0 );
2853 VECTOR2D right = center + VECTOR2D( offset, 0 );
2854 VECTOR2D top = center + VECTOR2D( 0, offset );
2855 VECTOR2D bottom = center + VECTOR2D( 0, -offset );
2856
2857 m_gal->SetFillColor( marker_color.WithAlpha( 0.1 ) );
2858 m_gal->DrawCircle( center, offset );
2859 m_gal->AdvanceDepth();
2860 m_gal->SetFillColor( marker_color );
2861 m_gal->DrawCurve( left, top, bottom, right, 1 );
2862 }
2863
2864 auto t2 = std::chrono::high_resolution_clock::now();
2865
2866 if( std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() > 100 )
2867 {
2868 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw symbol %s: %lld us", aSymbol->m_Uuid.AsString(),
2869 std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() );
2870 }
2871}
2872
2873
2874void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
2875{
2876 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
2877
2878 if( m_schSettings.IsPrinting() && drawingShadows )
2879 return;
2880
2881 if( drawingShadows && !( aField->IsBrightened() || aField->IsSelected() ) )
2882 return;
2883
2884 if( !isUnitAndConversionShown( aField ) )
2885 return;
2886
2887 if( aField->IsPrivate() && !m_schSettings.m_IsSymbolEditor )
2888 return;
2889
2890 // Must check layer as fields are sometimes drawn by their parent rather than directly
2891 // from the view.
2892 std::vector<int> layers = aField->ViewGetLayers();
2893
2894 if( std::find( layers.begin(), layers.end(), aLayer ) == layers.end() )
2895 return;
2896
2897 aLayer = aField->GetLayer();
2898
2899 COLOR4D color = getRenderColor( aField, aLayer, drawingShadows, aDimmed );
2900
2901 if( !( aField->IsVisible() || aField->IsForceVisible() ) )
2902 {
2904 : m_schSettings.m_ShowHiddenFields;
2905
2906 if( force_show )
2907 color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows, aDimmed );
2908 else
2909 return;
2910 }
2911
2912 SCH_SHEET_PATH* sheetPath = nullptr;
2913 wxString variant;
2914
2915 if( m_schematic )
2916 {
2917 sheetPath = &m_schematic->CurrentSheet();
2918 variant = m_schematic->GetCurrentVariant();
2919 }
2920
2921 wxString shownText = aField->GetShownText( sheetPath, true, 0, variant );
2922
2923 if( shownText.IsEmpty() )
2924 return;
2925
2926 // Calculate the text orientation according to the parent orientation.
2927 EDA_ANGLE orient = aField->GetTextAngle();
2928
2929 if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
2930 {
2931 if( static_cast<SCH_SYMBOL*>( aField->GetParent() )->GetTransform().y1 )
2932 {
2933 // Rotate symbol 90 degrees.
2934 if( orient.IsHorizontal() )
2935 orient = ANGLE_VERTICAL;
2936 else
2937 orient = ANGLE_HORIZONTAL;
2938 }
2939 }
2940
2941 /*
2942 * Calculate the text justification, according to the symbol orientation/mirror.
2943 * This is a bit complicated due to cumulative calculations:
2944 * - numerous cases (mirrored or not, rotation)
2945 * - the DrawGraphicText function recalculate also H and H justifications according to the
2946 * text orientation.
2947 * - when symbol is mirrored, the text is not mirrored and justifications are complicated
2948 * to calculate so the easier way is to use no justifications (centered text) and use
2949 * GetBoundingBox to know the text coordinate considered as centered
2950 */
2951 BOX2I bbox = aField->GetBoundingBox();
2952
2953 if( aField->GetParent() && aField->GetParent()->Type() == SCH_GLOBAL_LABEL_T )
2954 {
2955 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( aField->GetParent() );
2956 bbox.Offset( label->GetSchematicTextOffset( &m_schSettings ) );
2957 }
2958
2959 if( m_schSettings.GetDrawBoundingBoxes() )
2960 drawItemBoundingBox( aField );
2961
2962 m_gal->SetStrokeColor( color );
2963 m_gal->SetFillColor( color );
2964 m_gal->SetHoverColor( color );
2965
2966 if( drawingShadows && getFont( aField )->IsOutline() )
2967 {
2968 BOX2I shadow_box = bbox;
2969 shadow_box.Inflate( KiROUND( getTextThickness( aField ) * 2 ) );
2970
2971 m_gal->SetIsStroke( false );
2972 m_gal->SetIsFill( true );
2973 m_gal->DrawRectangle( shadow_box.GetPosition(), shadow_box.GetEnd() );
2974 }
2975 else
2976 {
2977 VECTOR2I textpos = bbox.Centre();
2978 TEXT_ATTRIBUTES attributes = aField->GetAttributes();
2979
2980 attributes.m_Halign = GR_TEXT_H_ALIGN_CENTER;
2981 attributes.m_Valign = GR_TEXT_V_ALIGN_CENTER;
2982 attributes.m_StrokeWidth = KiROUND( getTextThickness( aField ) );
2983 attributes.m_Angle = orient;
2984
2985 if( drawingShadows )
2986 attributes.m_StrokeWidth += getShadowWidth( !aField->IsSelected() );
2987
2988 if( aField->IsRollover() && !aField->IsMoving() )
2989 {
2990 // Highlight any urls found within the text
2991 m_gal->SetHoverColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) );
2992
2993 // Highlight the whole text if it has a link definition
2994 if( aField->HasHyperlink() )
2995 {
2996 attributes.m_Hover = true;
2997 attributes.m_Underlined = true;
2998 }
2999 }
3000
3001 if( nonCached( aField ) && aField->RenderAsBitmap( m_gal->GetWorldScale() ) )
3002 {
3003 bitmapText( *m_gal, shownText, textpos, attributes );
3004 const_cast<SCH_FIELD*>( aField )->SetFlags( IS_SHOWN_AS_BITMAP );
3005 }
3006 else
3007 {
3008 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
3009
3010 if( !aField->IsRollover() )
3011 cache = aField->GetRenderCache( shownText, textpos, attributes );
3012
3013 if( cache )
3014 {
3015 m_gal->SetLineWidth( attributes.m_StrokeWidth );
3016 m_gal->DrawGlyphs( *cache );
3017 }
3018 else
3019 {
3020 strokeText( *m_gal, shownText, textpos, attributes, aField->GetFontMetrics(),
3021 aField->GetRolloverPos() );
3022 }
3023
3024 const_cast<SCH_FIELD*>( aField )->ClearFlags( IS_SHOWN_AS_BITMAP );
3025 }
3026 }
3027
3028 if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
3029 {
3030 SCH_SYMBOL* parent = static_cast<SCH_SYMBOL*>( aField->GetParent() );
3031 bool rotated = !orient.IsHorizontal();
3032
3033 VECTOR2D pos;
3034 double size = bbox.GetHeight() / 1.5;
3035
3036 if( rotated )
3037 {
3038 pos = VECTOR2D( bbox.GetRight() - bbox.GetWidth() / 6.0,
3039 bbox.GetBottom() + bbox.GetWidth() / 2.0 );
3040 size = bbox.GetWidth() / 1.5;
3041 }
3042 else
3043 {
3044 pos = VECTOR2D( bbox.GetLeft() - bbox.GetHeight() / 2.0,
3045 bbox.GetBottom() - bbox.GetHeight() / 6.0 );
3046 }
3047
3048 if( parent->IsSymbolLikePowerLocalLabel() && aField->GetId() == FIELD_T::VALUE )
3049 drawLocalPowerIcon( pos, size, rotated, color, drawingShadows, aField->IsBrightened() );
3050 }
3051
3052 // Draw anchor or umbilical line
3053 if( aField->IsMoving() && m_schematic )
3054 {
3055 VECTOR2I parentPos = aField->GetParentPosition();
3056
3057 m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() );
3058 m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
3059 m_gal->DrawLine( aField->GetPosition(), parentPos );
3060 }
3061 else if( aField->IsSelected() )
3062 {
3063 drawAnchor( aField->GetPosition(), drawingShadows );
3064 }
3065}
3066
3067
3068void SCH_PAINTER::draw( const SCH_GLOBALLABEL* aLabel, int aLayer, bool aDimmed )
3069{
3070 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3071
3072 if( m_schSettings.IsPrinting() && drawingShadows )
3073 return;
3074
3075 bool drawingDangling = aLayer == LAYER_DANGLING;
3076
3077 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3078 {
3079 for( const SCH_FIELD& field : aLabel->GetFields() )
3080 draw( &field, aLayer, false );
3081 }
3082
3083 if( isFieldsLayer( aLayer ) )
3084 return;
3085
3086 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3087 return;
3088
3089 COLOR4D color = getRenderColor( aLabel, LAYER_GLOBLABEL, drawingShadows, aDimmed, true );
3090
3091 if( drawingDangling )
3092 {
3093 if( aLabel->IsDangling() )
3094 {
3095 drawDanglingIndicator( aLabel->GetTextPos(), color,
3096 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3097 drawingShadows, aLabel->IsBrightened() );
3098 }
3099
3100 return;
3101 }
3102
3103 std::vector<VECTOR2I> pts;
3104 std::deque<VECTOR2D> pts2;
3105
3106 aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
3107
3108 for( const VECTOR2I& p : pts )
3109 pts2.emplace_back( VECTOR2D( p.x, p.y ) );
3110
3111 m_gal->SetIsStroke( true );
3112 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3113 m_gal->SetStrokeColor( color );
3114
3115 if( drawingShadows )
3116 {
3117 m_gal->SetIsFill( eeconfig()->m_Selection.fill_shapes );
3118 m_gal->SetFillColor( color );
3119 m_gal->DrawPolygon( pts2 );
3120 }
3121 else
3122 {
3123 m_gal->SetIsFill( false );
3124 m_gal->DrawPolyline( pts2 );
3125 }
3126
3127 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3128}
3129
3130
3131void SCH_PAINTER::draw( const SCH_LABEL* aLabel, int aLayer, bool aDimmed )
3132{
3133 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3134
3135 if( m_schSettings.IsPrinting() && drawingShadows )
3136 return;
3137
3138 bool drawingDangling = aLayer == LAYER_DANGLING;
3139
3140 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3141 {
3142 for( const SCH_FIELD& field : aLabel->GetFields() )
3143 draw( &field, aLayer, false );
3144 }
3145
3146 if( isFieldsLayer( aLayer ) )
3147 return;
3148
3149 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3150 return;
3151
3152 COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows, aDimmed, true );
3153
3154 if( drawingDangling )
3155 {
3156 if( aLabel->IsDangling() )
3157 {
3158 drawDanglingIndicator( aLabel->GetTextPos(), color,
3159 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3160 drawingShadows, aLabel->IsBrightened() );
3161 }
3162
3163 return;
3164 }
3165
3166 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3167}
3168
3169
3170void SCH_PAINTER::draw( const SCH_HIERLABEL* aLabel, int aLayer, bool aDimmed )
3171{
3172 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3173
3174 if( m_schSettings.IsPrinting() && drawingShadows )
3175 return;
3176
3177 bool drawingDangling = aLayer == LAYER_DANGLING;
3178
3179 if( !( drawingShadows || drawingDangling ) || eeconfig()->m_Selection.draw_selected_children )
3180 {
3181 for( const SCH_FIELD& field : aLabel->GetFields() )
3182 draw( &field, aLayer, false );
3183 }
3184
3185 if( isFieldsLayer( aLayer ) )
3186 return;
3187
3188 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3189 return;
3190
3191 COLOR4D color = getRenderColor( aLabel, LAYER_HIERLABEL, drawingShadows, aDimmed, true );
3192
3193 if( drawingDangling )
3194 {
3195 if( aLabel->IsDangling() )
3196 {
3197 drawDanglingIndicator( aLabel->GetTextPos(), color,
3198 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3199 drawingShadows, aLabel->IsBrightened() );
3200 }
3201
3202 return;
3203 }
3204
3205 std::vector<VECTOR2I> i_pts;
3206 std::deque<VECTOR2D> d_pts;
3207
3208 aLabel->CreateGraphicShape( &m_schSettings, i_pts, (VECTOR2I)aLabel->GetTextPos() );
3209
3210 for( const VECTOR2I& i_pt : i_pts )
3211 d_pts.emplace_back( VECTOR2D( i_pt.x, i_pt.y ) );
3212
3213 m_gal->SetIsFill( true );
3214 m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ) );
3215 m_gal->SetIsStroke( true );
3216 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3217 m_gal->SetStrokeColor( color );
3218 m_gal->DrawPolyline( d_pts );
3219
3220 draw( static_cast<const SCH_TEXT*>( aLabel ), aLayer, false );
3221}
3222
3223
3224void SCH_PAINTER::draw( const SCH_DIRECTIVE_LABEL* aLabel, int aLayer, bool aDimmed )
3225{
3226 if( !eeconfig()->m_Appearance.show_directive_labels && !aLabel->IsSelected() )
3227 return;
3228
3229 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3230
3231 if( m_schSettings.IsPrinting() && drawingShadows )
3232 return;
3233
3234 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3235 {
3236 for( const SCH_FIELD& field : aLabel->GetFields() )
3237 draw( &field, aLayer, false );
3238 }
3239
3240 if( isFieldsLayer( aLayer ) )
3241 return;
3242
3243 if( drawingShadows && !( aLabel->IsBrightened() || aLabel->IsSelected() ) )
3244 return;
3245
3246 COLOR4D color = getRenderColor( aLabel, LAYER_NETCLASS_REFS, drawingShadows, aDimmed, true );
3247
3248 if( aLayer == LAYER_DANGLING )
3249 {
3250 if( aLabel->IsDangling() )
3251 {
3252 drawDanglingIndicator( aLabel->GetTextPos(), color,
3253 schIUScale.MilsToIU( DANGLING_SYMBOL_SIZE / 2 ), true,
3254 drawingShadows, aLabel->IsBrightened() );
3255 }
3256
3257 return;
3258 }
3259
3260 std::vector<VECTOR2I> pts;
3261 std::deque<VECTOR2D> pts2;
3262
3263 aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() );
3264
3265 for( const VECTOR2I& p : pts )
3266 pts2.emplace_back( VECTOR2D( p.x, p.y ) );
3267
3268 m_gal->SetIsFill( false );
3269 m_gal->SetFillColor( color );
3270 m_gal->SetIsStroke( true );
3271 m_gal->SetLineWidth( getLineWidth( aLabel, drawingShadows ) );
3272 m_gal->SetStrokeColor( color );
3273
3274 if( aLabel->GetShape() == LABEL_FLAG_SHAPE::F_DOT )
3275 {
3276 m_gal->DrawLine( pts2[0], pts2[1] );
3277 m_gal->SetIsFill( true );
3278 m_gal->DrawCircle( pts2[2], ( pts2[2] - pts2[1] ).EuclideanNorm() );
3279 }
3280 else if( aLabel->GetShape() == LABEL_FLAG_SHAPE::F_ROUND )
3281 {
3282 m_gal->DrawLine( pts2[0], pts2[1] );
3283 m_gal->DrawCircle( pts2[2], ( pts2[2] - pts2[1] ).EuclideanNorm() );
3284 }
3285 else
3286 {
3287 m_gal->DrawPolyline( pts2 );
3288 }
3289}
3290
3291
3292void SCH_PAINTER::draw( const SCH_SHEET* aSheet, int aLayer )
3293{
3294 SCH_SHEET_PATH* sheetPath = nullptr;
3295 wxString variant;
3296 bool DNP = false;
3297
3298 if( m_schematic )
3299 {
3300 sheetPath = &m_schematic->CurrentSheet();
3301 variant = m_schematic->GetCurrentVariant();
3302 DNP = aSheet->GetDNP( sheetPath, variant );
3303 }
3304
3305 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3306 bool markExclusion = eeconfig()->m_Appearance.mark_sim_exclusions
3307 && aSheet->GetExcludedFromSim( sheetPath, variant );
3308
3309 if( m_schSettings.IsPrinting() && drawingShadows )
3310 return;
3311
3312 if( !drawingShadows || eeconfig()->m_Selection.draw_selected_children )
3313 {
3314 for( const SCH_FIELD& field : aSheet->GetFields() )
3315 draw( &field, aLayer, DNP );
3316
3317 for( SCH_SHEET_PIN* sheetPin : aSheet->GetPins() )
3318 draw( static_cast<SCH_HIERLABEL*>( sheetPin ), aLayer, DNP );
3319 }
3320
3321 if( isFieldsLayer( aLayer ) )
3322 return;
3323
3324 VECTOR2D pos = aSheet->GetPosition();
3325 VECTOR2D size = aSheet->GetSize();
3326
3327 if( aLayer == LAYER_SHEET_BACKGROUND )
3328 {
3329 // Do not fill the shape in B&W print mode, to avoid to visible items
3330 // inside the shape
3331 if( !m_schSettings.PrintBlackAndWhiteReq() )
3332 {
3333 COLOR4D backgroundColor = aSheet->GetBackgroundColor();
3334
3335 if( m_schSettings.m_OverrideItemColors || backgroundColor == COLOR4D::UNSPECIFIED )
3336 backgroundColor = m_schSettings.GetLayerColor( LAYER_SHEET_BACKGROUND );
3337
3338 // Only draw the background if it has a visible alpha value
3339 if( backgroundColor.a > 0.0 )
3340 {
3341 m_gal->SetFillColor( getRenderColor( aSheet, LAYER_SHEET_BACKGROUND, false ) );
3342 m_gal->SetIsFill( true );
3343 m_gal->SetIsStroke( false );
3344
3345 m_gal->DrawRectangle( pos, pos + size );
3346 }
3347 }
3348 }
3349
3350 if( aLayer == LAYER_SHEET || aLayer == LAYER_SELECTION_SHADOWS )
3351 {
3352 m_gal->SetStrokeColor( getRenderColor( aSheet, LAYER_SHEET, drawingShadows ) );
3353 m_gal->SetIsStroke( true );
3354 m_gal->SetLineWidth( getLineWidth( aSheet, drawingShadows ) );
3355 m_gal->SetIsFill( false );
3356
3357 m_gal->DrawRectangle( pos, pos + size );
3358 }
3359
3360 if( DNP && aLayer == LAYER_SHEET )
3361 {
3362 int layer = LAYER_DNP_MARKER;
3363 BOX2I bbox = aSheet->GetBodyBoundingBox();
3364 BOX2I pins = aSheet->GetBoundingBox();
3365 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
3366 std::max( bbox.GetY() - pins.GetY(), pins.GetEnd().y - bbox.GetEnd().y ) );
3367 int strokeWidth = 3 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
3368
3369 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
3370 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
3371 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
3372
3373 VECTOR2I pt1 = bbox.GetOrigin();
3374 VECTOR2I pt2 = bbox.GetEnd();
3375
3377 m_gal->AdvanceDepth();
3378 m_gal->SetIsStroke( true );
3379 m_gal->SetIsFill( true );
3380 m_gal->SetStrokeColor( m_schSettings.GetLayerColor( layer ) );
3381 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ) );
3382
3383 m_gal->DrawSegment( pt1, pt2, strokeWidth );
3384 std::swap( pt1.x, pt2.x );
3385 m_gal->DrawSegment( pt1, pt2, strokeWidth );
3386 }
3387
3388 if( markExclusion )
3389 {
3390 int layer = LAYER_EXCLUDED_FROM_SIM;
3391 BOX2I bbox = aSheet->GetBodyBoundingBox();
3392 int strokeWidth = schIUScale.MilsToIU( ADVANCED_CFG::GetCfg().m_ExcludeFromSimulationLineWidth );
3393
3394 bbox.Inflate( KiROUND( strokeWidth * 0.5 ) );
3395
3397 m_gal->AdvanceDepth();
3398 m_gal->SetIsStroke( true );
3399 m_gal->SetIsFill( true );
3400 m_gal->SetStrokeColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3401 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3402
3403 m_gal->DrawSegment( bbox.GetPosition(), VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), strokeWidth );
3404 m_gal->DrawSegment( VECTOR2D( bbox.GetEnd().x, bbox.GetY() ), bbox.GetEnd(), strokeWidth );
3405 m_gal->DrawSegment( bbox.GetEnd(), VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), strokeWidth );
3406 m_gal->DrawSegment( VECTOR2D( bbox.GetX(), bbox.GetEnd().y ), bbox.GetPosition(), strokeWidth );
3407
3408 int offset = 2 * strokeWidth;
3409 VECTOR2D center = bbox.GetEnd() + VECTOR2D( offset + strokeWidth, -offset );
3410 VECTOR2D left = center + VECTOR2D( -offset, 0 );
3411 VECTOR2D right = center + VECTOR2D( offset, 0 );
3412 VECTOR2D top = center + VECTOR2D( 0, offset );
3413 VECTOR2D bottom = center + VECTOR2D( 0, -offset );
3414
3415 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.1 ) );
3416 m_gal->DrawCircle( center, offset );
3417 m_gal->AdvanceDepth();
3418 m_gal->SetFillColor( m_schSettings.GetLayerColor( layer ).WithAlpha( 0.5 ) );
3419 m_gal->DrawCurve( left, top, bottom, right, 1 );
3420 }
3421}
3422
3423
3424void SCH_PAINTER::draw( const SCH_NO_CONNECT* aNC, int aLayer )
3425{
3426 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3427
3428 if( m_schSettings.IsPrinting() && drawingShadows )
3429 return;
3430
3431 if( drawingShadows && !( aNC->IsBrightened() || aNC->IsSelected() ) )
3432 return;
3433
3434 m_gal->SetIsStroke( true );
3435 m_gal->SetLineWidth( getLineWidth( aNC, drawingShadows ) );
3436 m_gal->SetStrokeColor( getRenderColor( aNC, LAYER_NOCONNECT, drawingShadows ) );
3437 m_gal->SetIsFill( false );
3438
3439 VECTOR2D p = aNC->GetPosition();
3440 int delta = std::max( aNC->GetSize(), m_schSettings.GetDefaultPenWidth() * 3 ) / 2;
3441
3442 m_gal->DrawLine( p + VECTOR2D( -delta, -delta ), p + VECTOR2D( delta, delta ) );
3443 m_gal->DrawLine( p + VECTOR2D( -delta, delta ), p + VECTOR2D( delta, -delta ) );
3444}
3445
3446
3447void SCH_PAINTER::draw( const SCH_BUS_ENTRY_BASE *aEntry, int aLayer )
3448{
3450 SCH_LINE line( VECTOR2I(), layer );
3451 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3452 bool drawingNetColorHighlights = aLayer == LAYER_NET_COLOR_HIGHLIGHT;
3453 bool drawingDangling = aLayer == LAYER_DANGLING;
3454 bool drawingWires = aLayer == LAYER_WIRE;
3455 bool drawingBusses = aLayer == LAYER_BUS;
3456
3457 if( m_schSettings.IsPrinting() && drawingShadows )
3458 return;
3459
3460 bool highlightNetclassColors = false;
3461 EESCHEMA_SETTINGS* eeschemaCfg = eeconfig();
3462
3463 if( eeschemaCfg )
3464 {
3465 highlightNetclassColors = eeschemaCfg->m_Selection.highlight_netclass_colors;
3466 }
3467
3468 if( !highlightNetclassColors && drawingNetColorHighlights )
3469 return;
3470
3471 if( m_schSettings.m_OverrideItemColors && drawingNetColorHighlights )
3472 return;
3473
3474 if( drawingShadows && !( aEntry->IsBrightened() || aEntry->IsSelected() ) )
3475 return;
3476
3477 if( aEntry->IsSelected() )
3478 {
3479 line.SetSelected();
3480
3481 // Never show unselected endpoints on bus entries
3482 line.SetFlags( STARTPOINT | ENDPOINT );
3483 }
3484 else if( aEntry->IsBrightened() )
3485 {
3486 line.SetBrightened();
3487 }
3488
3489 line.SetStartPoint( aEntry->GetPosition() );
3490 line.SetEndPoint( aEntry->GetEnd() );
3491 line.SetStroke( aEntry->GetStroke() );
3492 line.SetLineWidth( KiROUND( getLineWidth( aEntry, false ) ) );
3493
3494 COLOR4D color = getRenderColor( aEntry, LAYER_WIRE, drawingShadows );
3495
3496 if( aEntry->Type() == SCH_BUS_BUS_ENTRY_T )
3497 color = getRenderColor( aEntry, LAYER_BUS, drawingShadows );
3498
3499 if( highlightNetclassColors )
3500 {
3501 // Force default color for nets we are going to highlight
3502 if( drawingWires )
3503 color = m_schSettings.GetLayerColor( LAYER_WIRE );
3504 else if( drawingBusses )
3505 color = m_schSettings.GetLayerColor( LAYER_BUS );
3506 }
3507
3508 if( drawingNetColorHighlights )
3509 {
3510 // Don't draw highlights for default-colored nets
3511 if( ( aEntry->Type() == SCH_BUS_WIRE_ENTRY_T
3512 && color == m_schSettings.GetLayerColor( LAYER_WIRE ) )
3513 || ( aEntry->Type() == SCH_BUS_BUS_ENTRY_T
3514 && color == m_schSettings.GetLayerColor( LAYER_BUS ) ) )
3515 {
3516 return;
3517 }
3518 }
3519
3520 if( drawingDangling )
3521 {
3522 m_gal->SetIsFill( false );
3523 m_gal->SetIsStroke( true );
3524 m_gal->SetStrokeColor( color.Brightened( 0.3 ) );
3525 m_gal->SetLineWidth( m_schSettings.GetDanglingIndicatorThickness() );
3526
3527 if( aEntry->IsStartDangling() )
3528 {
3529 m_gal->DrawCircle( aEntry->GetPosition(),
3530 aEntry->GetPenWidth() + KiROUND( TARGET_BUSENTRY_RADIUS / 2.0 ) );
3531 }
3532
3533 if( aEntry->IsEndDangling() )
3534 {
3535 m_gal->DrawCircle( aEntry->GetEnd(),
3536 aEntry->GetPenWidth() + KiROUND( TARGET_BUSENTRY_RADIUS / 2.0 ) );
3537 }
3538 }
3539 else
3540 {
3541 line.SetLineColor( color );
3542 line.SetLineStyle( aEntry->GetEffectiveLineStyle() );
3543
3544 draw( &line, aLayer );
3545 }
3546}
3547
3548
3549void SCH_PAINTER::draw( const SCH_BITMAP* aBitmap, int aLayer )
3550{
3551 auto t1 = std::chrono::high_resolution_clock::now();
3552 m_gal->Save();
3553 m_gal->Translate( aBitmap->GetPosition() );
3554
3555 const REFERENCE_IMAGE& refImage = aBitmap->GetReferenceImage();
3556
3557 // When the image scale factor is not 1.0, we need to modify the actual as the image scale
3558 // factor is similar to a local zoom
3559 const double img_scale = refImage.GetImageScale();
3560
3561 if( img_scale != 1.0 )
3562 m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
3563
3564 if( aLayer == LAYER_DRAW_BITMAPS )
3565 {
3566 m_gal->DrawBitmap( refImage.GetImage() );
3567 }
3568
3569 if( aLayer == LAYER_SELECTION_SHADOWS )
3570 {
3571 if( aBitmap->IsSelected() || aBitmap->IsBrightened() )
3572 {
3573 const COLOR4D color = getRenderColor( aBitmap, LAYER_DRAW_BITMAPS, true );
3574 m_gal->SetIsStroke( true );
3575 m_gal->SetStrokeColor( color );
3576 m_gal->SetLineWidth ( getShadowWidth( aBitmap->IsBrightened() ) );
3577 m_gal->SetIsFill( false );
3578
3579 // Draws a bounding box.
3580 VECTOR2D bm_size( refImage.GetSize() );
3581
3582 // bm_size is the actual image size in UI.
3583 // but m_canvas scale was previously set to img_scale
3584 // so recalculate size relative to this image size.
3585 bm_size.x /= img_scale;
3586 bm_size.y /= img_scale;
3587 const VECTOR2D origin( -bm_size.x / 2.0, -bm_size.y / 2.0 );
3588 const VECTOR2D end = origin + bm_size;
3589
3590 m_gal->DrawRectangle( origin, end );
3591 }
3592 }
3593
3594 m_gal->Restore();
3595 auto t2 = std::chrono::high_resolution_clock::now();
3596
3597 if( std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() > 100 )
3598 {
3599 wxLogTrace( traceSchPainter, "SCH_PAINTER::draw bitmap %s: %lld us", aBitmap->m_Uuid.AsString(),
3600 std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count() );
3601 }
3602}
3603
3604
3605void SCH_PAINTER::draw( const SCH_MARKER* aMarker, int aLayer )
3606{
3607 bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
3608
3609 if( m_schSettings.IsPrinting() && drawingShadows )
3610 return;
3611
3612 if( drawingShadows && !( aMarker->IsBrightened() || aMarker->IsSelected() ) )
3613 return;
3614
3615 COLOR4D color = getRenderColor( aMarker, aMarker->GetColorLayer(), drawingShadows );
3616
3617 m_gal->Save();
3618 m_gal->Translate( aMarker->GetPosition() );
3619 m_gal->SetIsFill( !drawingShadows );
3620 m_gal->SetFillColor( color );
3621 m_gal->SetIsStroke( drawingShadows );
3622 m_gal->SetLineWidth( getLineWidth( aMarker, drawingShadows ) );
3623 m_gal->SetStrokeColor( color );
3624
3625 SHAPE_LINE_CHAIN polygon;
3626 aMarker->ShapeToPolygon( polygon );
3627
3628 m_gal->DrawPolygon( polygon );
3629 m_gal->Restore();
3630}
3631
3632
3633void SCH_PAINTER::draw( const SCH_GROUP* aGroup, int aLayer )
3634{
3635 const bool drawingShadows = false;
3636
3637 if( aLayer == LAYER_SCHEMATIC_ANCHOR )
3638 {
3639 if( aGroup->IsSelected() && !( aGroup->GetParent() && aGroup->GetParent()->IsSelected() ) )
3640 {
3641 // Selected on our own; draw enclosing box
3642 }
3643 else if( aGroup->IsEntered() )
3644 {
3645 // Entered group; draw enclosing box
3646 }
3647 else
3648 {
3649 // Neither selected nor entered; draw nothing at the group level (ie: only draw
3650 // its members)
3651 return;
3652 }
3653
3654 const COLOR4D color = getRenderColor( aGroup, LAYER_SCHEMATIC_ANCHOR, drawingShadows );
3655
3656 m_gal->SetStrokeColor( color );
3657 m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() * 2.0f );
3658
3659 BOX2I bbox = aGroup->GetBoundingBox();
3660 VECTOR2I topLeft = bbox.GetPosition();
3661 VECTOR2I width = VECTOR2I( bbox.GetWidth(), 0 );
3662 VECTOR2I height = VECTOR2I( 0, bbox.GetHeight() );
3663
3664 m_gal->DrawLine( topLeft, topLeft + width );
3665 m_gal->DrawLine( topLeft + width, topLeft + width + height );
3666 m_gal->DrawLine( topLeft + width + height, topLeft + height );
3667 m_gal->DrawLine( topLeft + height, topLeft );
3668
3669 wxString name = aGroup->GetName();
3670
3671 if( name.IsEmpty() )
3672 return;
3673
3674 int ptSize = 12;
3675 int scaledSize = abs( KiROUND( m_gal->GetScreenWorldMatrix().GetScale().x * ptSize ) );
3676 int unscaledSize = schIUScale.MilsToIU( ptSize );
3677
3678 // Scale by zoom a bit, but not too much
3679 int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3;
3680 VECTOR2I textOffset = KiROUND( width.x / 2.0, -textSize * 0.5 );
3681 VECTOR2I titleHeight = KiROUND( 0.0, textSize * 2.0 );
3682
3683 if( PrintableCharCount( name ) * textSize < bbox.GetWidth() )
3684 {
3685 m_gal->DrawLine( topLeft, topLeft - titleHeight );
3686 m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight );
3687 m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width );
3688
3689 TEXT_ATTRIBUTES attrs;
3690 attrs.m_Italic = true;
3693 attrs.m_Size = VECTOR2I( textSize, textSize );
3694 attrs.m_StrokeWidth = GetPenSizeForNormal( textSize );
3695
3696 KIFONT::FONT::GetFont()->Draw( m_gal, aGroup->GetName(), topLeft + textOffset, attrs,
3697 aGroup->GetFontMetrics() );
3698 }
3699 }
3700}
3701
3702
3703void SCH_PAINTER::drawLine( const VECTOR2I& aStartPoint, const VECTOR2I& aEndPoint,
3704 LINE_STYLE aLineStyle, bool aDrawDirectLine, int aWidth )
3705{
3706 if( aDrawDirectLine )
3707 {
3708 m_gal->DrawLine( aStartPoint, aEndPoint );
3709 }
3710 else
3711 {
3712 SHAPE_SEGMENT segment( aStartPoint, aEndPoint );
3713
3714 STROKE_PARAMS::Stroke( &segment, aLineStyle, KiROUND( aWidth ), &m_schSettings,
3715 [&]( const VECTOR2I& start, const VECTOR2I& end )
3716 {
3717 if( start == end )
3718 m_gal->DrawLine( start + 1, end );
3719 else
3720 m_gal->DrawLine( start, end );
3721 } );
3722 }
3723}
3724
3725}; // 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:147
const KIID m_Uuid
Definition eda_item.h:521
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:149
bool IsSelected() const
Definition eda_item.h:127
void SetSelected()
Definition eda_item.h:139
void SetBrightened()
Definition eda_item.h:140
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:151
bool IsBrightened() const
Definition eda_item.h:129
bool IsForceVisible() const
Definition eda_item.h:216
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:150
bool IsMoving() const
Definition eda_item.h:125
bool IsNew() const
Definition eda_item.h:124
FILL_T GetFillMode() const
Definition eda_shape.h:142
SHAPE_T GetShape() const
Definition eda_shape.h:169
const std::vector< SEG > & GetHatchLines() const
Definition eda_shape.h:149
bool IsSolidFill() const
Definition eda_shape.h:117
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:216
COLOR4D GetFillColor() const
Definition eda_shape.h:153
virtual void UpdateHatching() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:80
const VECTOR2I & GetTextPos() const
Definition eda_text.h:273
COLOR4D GetTextColor() const
Definition eda_text.h:270
void SetActiveUrl(const wxString &aUrl) const
Definition eda_text.h:278
bool IsItalic() const
Definition eda_text.h:169
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:147
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
virtual bool IsVisible() const
Definition eda_text.h:187
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
Definition eda_text.cpp:695
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:379
virtual VECTOR2I GetDrawPos() const
Definition eda_text.h:380
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:753
virtual bool HasHyperlink() const
Definition eda_text.h:402
wxString GetHyperlink() const
Definition eda_text.h:403
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:659
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:282
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
COLOR4D & Darken(double aFactor)
Makes the color darker by a given factor.
Definition color4d.h:227
std::shared_ptr< wxString > m_text
Definition color4d.h:399
double a
Alpha component.
Definition color4d.h:396
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
Definition color4d.h:269
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:402
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition color4d.cpp:532
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:296
Attribute save/restore for GAL attributes.
Abstract interface for drawing on a 2D-surface.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void Rotate(double aAngle)
Rotate the context.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
void SetVerticalJustify(const GR_TEXT_V_ALIGN_T aVerticalJustify)
void SetHorizontalJustify(const GR_TEXT_H_ALIGN_T aHorizontalJustify)
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void Restore()
Restore the context.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
void SetGlyphSize(const VECTOR2I aSize)
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle)
Draw an arc.
virtual void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
Draw a text using a bitmap font.
virtual void Save()
Save the context.
double GetWorldScale() const
Get the world scale.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition painter.h:102
PAINTER(GAL *aGal)
Initialize this object for painting on any of the polymorphic GRAPHICS_ABSTRACTION_LAYER* derivatives...
Definition painter.cpp:33
virtual bool Draw(const VIEW_ITEM *, int) override
Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item.
void drawPinDanglingIndicator(const SCH_PIN &aPin, const COLOR4D &aColor, bool aDrawingShadows, bool aBrightened)
float getTextThickness(const SCH_ITEM *aItem) const
void drawLocalPowerIcon(const VECTOR2D &aPos, double aSize, bool aRotate, const COLOR4D &aColor, bool aDrawingShadows, bool aBrightened)
Draw an local power pin indicator icon.
float getShadowWidth(bool aForHighlight) const
COLOR4D getRenderColor(const SCH_ITEM *aItem, int aLayer, bool aDrawingShadows, bool aDimmed=false, bool aIgnoreNets=false) const
int externalPinDecoSize(const SCH_PIN &aPin)
KIFONT::FONT * getFont(const EDA_TEXT *aText) const
void draw(const EDA_ITEM *, int, bool aDimmed)
wxString expandLibItemTextVars(const wxString &aSourceText, const SCH_SYMBOL *aSymbolContext)
static std::vector< KICAD_T > g_ScaledSelectionTypes
SCHEMATIC * m_schematic
void drawLine(const VECTOR2I &aStartPoint, const VECTOR2I &aEndPoint, LINE_STYLE aLineStyle, bool aDrawDirectLine=false, int aWidth=0)
int getOperatingPointTextSize() const
float getLineWidth(const SCH_ITEM *aItem, bool aDrawingShadows, bool aDrawingWireColorHighlights=false) const
void triLine(const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c)
SCH_RENDER_SETTINGS m_schSettings
void drawAnchor(const VECTOR2I &aPos, bool aDrawingShadows)
Draw anchor indicating the anchor position of text objects, local labels, or fields.
bool nonCached(const EDA_ITEM *aItem)
Indicates the item is drawn on a non-cached layer in OpenGL.
void drawDanglingIndicator(const VECTOR2I &aPos, const COLOR4D &aColor, int aWidth, bool aDangling, bool aDrawingShadows, bool aBrightened)
Draw the target (an open square) for a wire or label which has no connection or is being moved.
void drawItemBoundingBox(const EDA_ITEM *aItem)
int internalPinDecoSize(const SCH_PIN &aPin)
bool isUnitAndConversionShown(const SCH_ITEM *aItem) const
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:86
double GetForcedTransparency() const
Definition view_item.h:171
wxString AsString() const
Definition kiid.cpp:247
Define a library symbol object.
Definition lib_symbol.h:83
std::vector< const SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
bool IsDerived() const
Definition lib_symbol.h:203
static LIB_SYMBOL * GetDummy()
Returns a dummy LIB_SYMBOL, used when one is missing in the schematic.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:712
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon, int aScale=-1) const
Return the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to the...
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition matrix3x3.h:295
A pin layout helper is a class that manages the layout of the parts of a pin on a schematic symbol:
OPT_BOX2I GetAltIconBBox()
Get the box of the alt mode icon, if there is one.
std::optional< TEXT_INFO > GetPinNameInfo(int aShadowWidth)
Get the text info for the pin name.
std::optional< TEXT_INFO > GetPinElectricalTypeInfo(int aShadowWidth)
CIRCLE GetDanglingIndicator() const
Gets the dangling indicator geometry for this pin, if the pin were to be dangling.
std::optional< TEXT_INFO > GetPinNumberInfo(int aShadowWidth)
void SetRenderParameters(int aNameThickness, int aNumberThickness, bool aShowElectricalType, bool aShowAltIcons)
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
VECTOR2I GetSize() const
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
A round rectangle shape, based on a rectangle and a radius.
Definition roundrect.h:36
void TransformToPolygon(SHAPE_POLY_SET &aBuffer, int aMaxError) const
Get the polygonal representation of the roundrect.
Definition roundrect.cpp:83
SCHEMATIC_SETTINGS & Settings() const
Object to handle a bitmap image that can be inserted in a schematic.
Definition sch_bitmap.h:40
VECTOR2I GetPosition() const override
REFERENCE_IMAGE & GetReferenceImage()
Definition sch_bitmap.h:51
Base class for a bus or wire entry.
bool IsStartDangling() const
VECTOR2I GetPosition() const override
bool IsEndDangling() const
virtual STROKE_PARAMS GetStroke() const override
int GetPenWidth() const override
VECTOR2I GetEnd() const
LINE_STYLE GetEffectiveLineStyle() const
Class for a wire to bus entry.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool IsBus() const
void CreateGraphicShape(const RENDER_SETTINGS *aSettings, std::vector< VECTOR2I > &aPoints, const VECTOR2I &aPos) const override
Calculate the graphic shape (a polygon) associated to the text.
virtual bool IsDangling() const override
Determines dangling state from connectivity and cached connected rule areas.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
VECTOR2I GetPosition() const override
FIELD_T GetId() const
Definition sch_field.h:120
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0, const wxString &aVariantName=wxEmptyString) const
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
VECTOR2I GetParentPosition() const
void CreateGraphicShape(const RENDER_SETTINGS *aRenderSettings, std::vector< VECTOR2I > &aPoints, const VECTOR2I &aPos) const override
Calculate the graphic shape (a polygon) associated to the text.
VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:52
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void CreateGraphicShape(const RENDER_SETTINGS *aSettings, std::vector< VECTOR2I > &aPoints, const VECTOR2I &aPos) const override
Calculate the graphic shape (a polygon) associated to the text.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:258
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:252
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:455
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:789
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:471
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:361
wxString GetClass() const override
Return the class name.
Definition sch_item.h:177
const KIFONT::METRICS & GetFontMetrics() const
Definition sch_item.cpp:757
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:766
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:667
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:409
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:357
bool IsVisible() const
Definition sch_pin.cpp:377
VECTOR2I GetPinRoot() const
Definition sch_pin.cpp:691
bool IsDangling() const override
Definition sch_pin.cpp:451
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:643
const wxString & GetShownName() const
Definition sch_pin.cpp:567
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
int GetHatchLineWidth() const override
Definition sch_shape.h:71
STROKE_PARAMS GetStroke() const override
Definition sch_shape.h:58
VECTOR2I GetPosition() const override
Definition sch_shape.h:85
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
Definition sch_sheet.h:88
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
VECTOR2I GetSize() const
Definition sch_sheet.h:147
VECTOR2I GetPosition() const override
Definition sch_sheet.h:496
const BOX2I GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
KIGFX::COLOR4D GetBorderColor() const
Definition sch_sheet.h:153
bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flags.
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:233
KIGFX::COLOR4D GetBackgroundColor() const
Definition sch_sheet.h:156
Schematic symbol object.
Definition sch_symbol.h:76
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
BOX2I GetBodyAndPinsBoundingBox() const override
Return a bounding box for the symbol body and pins but not the fields.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:867
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
static void BuildLocalPowerIconShape(std::vector< SCH_SHAPE > &aShapeList, const VECTOR2D &aPos, double aSize, double aLineWidth, bool aHorizontal)
Build the local power pin indicator icon shape, at coordinate aPos.
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
int GetOrientation() const override
Get the display symbol orientation.
bool IsSymbolLikePowerLocalLabel() const
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:184
BOX2I GetBodyBoundingBox() const override
Return a bounding box for the symbol body but not the pins or fields.
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
int GetColSpan() const
int GetRowSpan() const
std::vector< SCH_TABLECELL * > GetCells() const
Definition sch_table.h:157
void DrawBorders(const std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const STROKE_PARAMS &aStroke)> &aCallback) const
virtual wxString GetShownText(const RENDER_SETTINGS *aSettings, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
VECTOR2I GetDrawPos() const override
VECTOR2I GetPosition() const override
Definition sch_text.h:147
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
Definition seg.h:42
VECTOR2I B
Definition seg.h:50
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
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:62
The common library.
#define DANGLING_SYMBOL_SIZE
The size of the rectangle indicating an unconnected wire or label.
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define UNSELECTED_END_SIZE
The size of the rectangle indicating the anchor of a text object (including fields)
#define TEXT_ANCHOR_SIZE
The default pin len value when creating pins(can be changed in preference menu)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:408
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:407
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:416
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:415
#define IS_SHOWN_AS_BITMAP
#define ENDPOINT
ends. (Used to support dragging.)
#define IS_DANGLING
indicates a pin is dangling
#define STARTPOINT
When a line is selected, these flags indicate which.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:46
@ FILLED_WITH_COLOR
Definition eda_shape.h:60
@ NO_FILL
Definition eda_shape.h:57
@ REVERSE_HATCH
Definition eda_shape.h:62
@ HATCH
Definition eda_shape.h:61
@ FILLED_WITH_BG_BODYCOLOR
Definition eda_shape.h:59
@ FILLED_SHAPE
Fill with object color.
Definition eda_shape.h:58
@ CROSS_HATCH
Definition eda_shape.h:63
int GetPenSizeForDemiBold(int aTextSize)
Definition gr_text.cpp:43
int GetPenSizeForNormal(int aTextSize)
Definition gr_text.cpp:61
int ClampTextPenSize(int aPenSize, int aSize, bool aStrict)
Pen width should not allow characters to become cluttered up in their own fatness.
Definition gr_text.cpp:73
const wxChar *const traceSchPainter
Flag to enable debug output of schematic painter operations.
@ LAYER_DRAW_BITMAPS
Draw images.
Definition layer_ids.h:284
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:449
@ LAYER_DANGLING
Definition layer_ids.h:477
@ LAYER_SHAPES_BACKGROUND
Definition layer_ids.h:483
@ LAYER_SHEETNAME
Definition layer_ids.h:472
@ LAYER_SCHEMATIC_ANCHOR
Definition layer_ids.h:500
@ LAYER_SHEETLABEL
Definition layer_ids.h:475
@ LAYER_PINNUM
Definition layer_ids.h:458
@ LAYER_RULE_AREAS
Definition layer_ids.h:465
@ LAYER_DEVICE
Definition layer_ids.h:466
@ LAYER_SHEET_BACKGROUND
Definition layer_ids.h:485
@ LAYER_EXCLUDED_FROM_SIM
Definition layer_ids.h:482
@ LAYER_BRIGHTENED
Definition layer_ids.h:491
@ LAYER_HIDDEN
Definition layer_ids.h:492
@ LAYER_HIERLABEL
Definition layer_ids.h:457
@ LAYER_PINNAM
Definition layer_ids.h:459
@ LAYER_PRIVATE_NOTES
Definition layer_ids.h:468
@ LAYER_HOVERED
Definition layer_ids.h:490
@ LAYER_GLOBLABEL
Definition layer_ids.h:456
@ LAYER_WIRE
Definition layer_ids.h:452
@ LAYER_NOTES
Definition layer_ids.h:467
@ LAYER_NET_COLOR_HIGHLIGHT
Definition layer_ids.h:493
@ LAYER_PIN
Definition layer_ids.h:470
@ LAYER_VALUEPART
Definition layer_ids.h:461
@ LAYER_BUS
Definition layer_ids.h:453
@ LAYER_FIELDS
Definition layer_ids.h:462
@ LAYER_DEVICE_BACKGROUND
Definition layer_ids.h:484
@ LAYER_LOCLABEL
Definition layer_ids.h:455
@ LAYER_SHEETFIELDS
Definition layer_ids.h:474
@ LAYER_REFERENCEPART
Definition layer_ids.h:460
@ LAYER_NETCLASS_REFS
Definition layer_ids.h:464
@ LAYER_NOTES_BACKGROUND
Definition layer_ids.h:469
@ LAYER_OP_CURRENTS
Definition layer_ids.h:502
@ LAYER_SHEET
Definition layer_ids.h:471
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:495
@ LAYER_SCHEMATIC_BACKGROUND
Definition layer_ids.h:488
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:463
@ LAYER_OP_VOLTAGES
Definition layer_ids.h:501
@ LAYER_SHEETFILENAME
Definition layer_ids.h:473
@ LAYER_DNP_MARKER
Definition layer_ids.h:478
@ LAYER_NOCONNECT
Definition layer_ids.h:476
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:96
MATRIX3x3< double > MATRIX3x3D
Definition matrix3x3.h:473
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
static void boxText(KIGFX::GAL &aGal, const wxString &aText, const VECTOR2D &aPosition, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics)
static void bitmapText(KIGFX::GAL &aGal, const wxString &aText, const VECTOR2D &aPosition, const TEXT_ATTRIBUTES &aAttrs)
EESCHEMA_SETTINGS * eeconfig()
static void strokeText(KIGFX::GAL &aGal, const wxString &aText, const VECTOR2D &aPosition, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr)
static void knockoutText(KIGFX::GAL &aGal, const wxString &aText, const VECTOR2D &aPosition, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics)
static void drawAltPinModesIcon(GAL &aGal, const VECTOR2D &aPos, double aSize, bool aBaseSelected, bool aRotate, int aExtraLineWidth, const COLOR4D &aColor)
Draw an alternate pin mode indicator icon.
static bool isFieldsLayer(int aLayer)
static BOX2I GetTextExtents(const wxString &aText, const VECTOR2D &aPosition, KIFONT::FONT &aFont, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:100
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
see class PGM_BASE
@ PT_NC
not connected (must be left open)
Definition pin_type.h:50
#define TARGET_BUSENTRY_RADIUS
Class to handle a set of SCH_ITEMs.
#define BITMAP_FONT_SIZE_THRESHOLD
Definition sch_item.cpp: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