forked from KiCad/kicad-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsch_painter.cpp
1876 lines (1497 loc) · 59.6 KB
/
sch_painter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 CERN
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <sch_item.h>
#include <trigo.h>
#include <bezier_curves.h>
#include <symbol_library.h>
#include <connection_graph.h>
#include <gal/graphics_abstraction_layer.h>
#include <geometry/geometry_utils.h>
#include <geometry/shape_line_chain.h>
#include <gr_text.h>
#include <lib_shape.h>
#include <lib_field.h>
#include <lib_item.h>
#include <lib_pin.h>
#include <lib_text.h>
#include <math/util.h>
#include <plotters/plotter.h>
#include <sch_bitmap.h>
#include <sch_bus_entry.h>
#include <sch_symbol.h>
#include <sch_edit_frame.h>
#include <sch_field.h>
#include <sch_junction.h>
#include <sch_line.h>
#include <sch_marker.h>
#include <sch_no_connect.h>
#include <sch_sheet.h>
#include <sch_sheet_pin.h>
#include <sch_text.h>
#include <schematic.h>
#include <settings/color_settings.h>
#include <view/view.h>
#include <kiface_base.h>
#include <default_values.h>
#include <advanced_config.h>
#include <string_utils.h>
#include "sch_painter.h"
namespace KIGFX
{
SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() :
m_IsSymbolEditor( false ),
m_ShowUnit( 0 ),
m_ShowConvert( 0 ),
m_ShowHiddenText( true ),
m_ShowHiddenPins( true ),
m_ShowPinsElectricalType( true ),
m_ShowDisabled( false ),
m_ShowGraphicsDisabled( false ),
m_ShowUmbilicals( true ),
m_OverrideItemColors( false ),
m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ),
m_TextOffsetRatio( DEFAULT_TEXT_OFFSET_RATIO ),
m_DefaultWireThickness( DEFAULT_WIRE_WIDTH_MILS * IU_PER_MILS ),
m_DefaultBusThickness( DEFAULT_BUS_WIDTH_MILS * IU_PER_MILS ),
m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ),
m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS )
{
SetDefaultPenWidth( DEFAULT_LINE_WIDTH_MILS * IU_PER_MILS );
m_minPenWidth = ADVANCED_CFG::GetCfg().m_MinPlotPenWidth * IU_PER_MM;
}
void SCH_RENDER_SETTINGS::LoadColors( const COLOR_SETTINGS* aSettings )
{
for( int layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; layer ++)
m_layerColors[ layer ] = aSettings->GetColor( layer );
for( int layer = GAL_LAYER_ID_START; layer < GAL_LAYER_ID_END; layer ++)
m_layerColors[ layer ] = aSettings->GetColor( layer );
m_backgroundColor = aSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
m_layerColors[LAYER_AUX_ITEMS] = m_layerColors[LAYER_SCHEMATIC_AUX_ITEMS];
m_OverrideItemColors = aSettings->GetOverrideSchItemColors();
}
COLOR4D SCH_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
{
return m_layerColors[ aLayer ];
}
EESCHEMA_SETTINGS* eeconfig()
{
return dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
}
/**
* Used when a LIB_SYMBOL is not found in library to draw a dummy shape.
* This symbol is a 400 mils square with the text "??"
*
* DEF DUMMY U 0 40 Y Y 1 0 N
* F0 "U" 0 -350 60 H V
* F1 "DUMMY" 0 350 60 H V
* DRAW
* T 0 0 0 150 0 0 0 ??
* S -200 200 200 -200 0 1 0
* ENDDRAW
* ENDDEF
*/
static LIB_SYMBOL* dummy()
{
static LIB_SYMBOL* symbol;
if( !symbol )
{
symbol = new LIB_SYMBOL( wxEmptyString );
LIB_SHAPE* square = new LIB_SHAPE( symbol, SHAPE_T::RECT );
square->MoveTo( wxPoint( Mils2iu( -200 ), Mils2iu( 200 ) ) );
square->SetEnd( wxPoint( Mils2iu( 200 ), Mils2iu( -200 ) ) );
LIB_TEXT* text = new LIB_TEXT( symbol );
text->SetTextSize( wxSize( Mils2iu( 150 ), Mils2iu( 150 ) ) );
text->SetText( wxString( wxT( "??" ) ) );
symbol->AddDrawItem( square );
symbol->AddDrawItem( text );
}
return symbol;
}
SCH_PAINTER::SCH_PAINTER( GAL* aGal ) :
KIGFX::PAINTER( aGal ),
m_schematic( nullptr )
{ }
#define HANDLE_ITEM( type_id, type_name ) \
case type_id: draw( (type_name *) item, aLayer ); break
bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer )
{
const auto item = dynamic_cast<const EDA_ITEM*>( aItem );
if( !item )
return false;
#ifdef CONNECTIVITY_DEBUG
auto sch_item = dynamic_cast<const SCH_ITEM*>( item );
auto conn = sch_item ? sch_item->Connection( *g_CurrentSheet ) : nullptr;
if( conn )
{
auto pos = item->GetBoundingBox().Centre();
auto label = conn->Name( true );
m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
m_gal->SetStrokeColor( COLOR4D( LIGHTRED ) );
m_gal->SetLineWidth( Mils2ui( 2 ) );
m_gal->SetGlyphSize( VECTOR2D( Mils2ui( 20 ), Mils2ui( 20 ) ) );
m_gal->StrokeText( conn->Name( true ), pos, 0.0, 0 );
}
#endif
if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
{
BOX2I box = item->GetBoundingBox();
if( item->Type() == SCH_SYMBOL_T )
box = static_cast<const SCH_SYMBOL*>( item )->GetBodyBoundingBox();
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 )
: COLOR4D( 0.2, 0.2, 0.2, 1 ) );
m_gal->SetLineWidth( Mils2iu( 3 ) );
m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
}
switch( item->Type() )
{
HANDLE_ITEM( LIB_SYMBOL_T, LIB_SYMBOL );
HANDLE_ITEM( LIB_SHAPE_T, LIB_SHAPE );
HANDLE_ITEM( LIB_PIN_T, LIB_PIN );
HANDLE_ITEM( LIB_FIELD_T, LIB_FIELD );
HANDLE_ITEM( LIB_TEXT_T, LIB_TEXT );
HANDLE_ITEM( SCH_SYMBOL_T, SCH_SYMBOL );
HANDLE_ITEM( SCH_JUNCTION_T, SCH_JUNCTION );
HANDLE_ITEM( SCH_LINE_T, SCH_LINE );
HANDLE_ITEM( SCH_TEXT_T, SCH_TEXT );
HANDLE_ITEM( SCH_LABEL_T, SCH_TEXT );
HANDLE_ITEM( SCH_FIELD_T, SCH_FIELD );
HANDLE_ITEM( SCH_HIER_LABEL_T, SCH_HIERLABEL );
HANDLE_ITEM( SCH_GLOBAL_LABEL_T, SCH_GLOBALLABEL );
HANDLE_ITEM( SCH_SHEET_T, SCH_SHEET );
HANDLE_ITEM( SCH_SHEET_PIN_T, SCH_HIERLABEL );
HANDLE_ITEM( SCH_NO_CONNECT_T, SCH_NO_CONNECT );
HANDLE_ITEM( SCH_BUS_WIRE_ENTRY_T, SCH_BUS_ENTRY_BASE );
HANDLE_ITEM( SCH_BUS_BUS_ENTRY_T, SCH_BUS_ENTRY_BASE );
HANDLE_ITEM( SCH_BITMAP_T, SCH_BITMAP );
HANDLE_ITEM( SCH_MARKER_T, SCH_MARKER );
default: return false;
}
return false;
}
bool SCH_PAINTER::isUnitAndConversionShown( const LIB_ITEM* aItem ) const
{
if( m_schSettings.m_ShowUnit // showing a specific unit
&& aItem->GetUnit() // item is unit-specific
&& aItem->GetUnit() != m_schSettings.m_ShowUnit )
{
return false;
}
if( m_schSettings.m_ShowConvert // showing a specific conversion
&& aItem->GetConvert() // item is conversion-specific
&& aItem->GetConvert() != m_schSettings.m_ShowConvert )
{
return false;
}
return true;
}
float SCH_PAINTER::getShadowWidth() const
{
const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
// For best visuals the selection width must be a cross between the zoom level and the
// default line width.
return (float) std::fabs( matrix.GetScale().x * 2.75 ) +
Mils2iu( eeconfig()->m_Selection.thickness );
}
COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDrawingShadows ) const
{
COLOR4D color = m_schSettings.GetLayerColor( aLayer );
if( aItem->Type() == SCH_LINE_T )
{
COLOR4D lineColor = static_cast<const SCH_LINE*>( aItem )->GetLineColor();
if( lineColor != COLOR4D::UNSPECIFIED )
color = lineColor;
}
else if( aItem->Type() == SCH_BUS_WIRE_ENTRY_T )
{
COLOR4D busEntryColor = static_cast<const SCH_BUS_WIRE_ENTRY*>( aItem )->GetStrokeColor();
if( busEntryColor != COLOR4D::UNSPECIFIED )
color = busEntryColor;
}
else if( aItem->Type() == SCH_JUNCTION_T )
{
COLOR4D junctionColor = static_cast<const SCH_JUNCTION*>( aItem )->GetJunctionColor();
if( junctionColor != COLOR4D::UNSPECIFIED )
color = junctionColor;
}
else if( aItem->Type() == SCH_SHEET_T )
{
SCH_SHEET* sheet = (SCH_SHEET*) aItem;
if( m_schSettings.m_OverrideItemColors )
color = m_schSettings.GetLayerColor( aLayer );
else if( aLayer == LAYER_SHEET )
color = sheet->GetBorderColor();
else if( aLayer == LAYER_SHEET_BACKGROUND )
color = sheet->GetBackgroundColor();
if( color == COLOR4D::UNSPECIFIED )
color = m_schSettings.GetLayerColor( aLayer );
}
if( aItem->IsBrightened() && !aDrawingShadows ) // Selection disambiguation, etc.
{
color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED );
if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_SHEET_BACKGROUND )
color = color.WithAlpha( 0.2 );
}
else if( aItem->IsSelected() )
{
if( aDrawingShadows )
color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS );
}
if( m_schSettings.m_ShowDisabled
|| ( m_schSettings.m_ShowGraphicsDisabled && aItem->Type() != LIB_FIELD_T ) )
{
color = color.Darken( 0.5f );
}
return color;
}
float SCH_PAINTER::getLineWidth( const LIB_ITEM* aItem, bool aDrawingShadows ) const
{
float width = (float) aItem->GetEffectivePenWidth( &m_schSettings );
if( aItem->IsSelected() && aDrawingShadows )
width += getShadowWidth();
return width;
}
float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows ) const
{
wxCHECK( aItem, static_cast<float>( m_schSettings.m_DefaultWireThickness ) );
float width = (float) aItem->GetPenWidth();
if( aItem->IsSelected() && aDrawingShadows )
width += getShadowWidth();
return std::max( width, 1.0f );
}
float SCH_PAINTER::getTextThickness( const SCH_TEXT* aItem, bool aDrawingShadows ) const
{
float width = (float) aItem->GetEffectiveTextPenWidth( m_schSettings.GetDefaultPenWidth() );
if( aItem->IsSelected() && aDrawingShadows )
width += getShadowWidth();
return width;
}
float SCH_PAINTER::getTextThickness( const SCH_FIELD* aItem, bool aDrawingShadows ) const
{
float width = (float) aItem->GetEffectiveTextPenWidth( m_schSettings.GetDefaultPenWidth() );
if( aItem->IsSelected() && aDrawingShadows )
width += getShadowWidth();
return width;
}
float SCH_PAINTER::getTextThickness( const LIB_FIELD* aItem, bool aDrawingShadows ) const
{
float width = (float) std::max( aItem->GetEffectiveTextPenWidth(),
m_schSettings.GetDefaultPenWidth() );
if( aItem->IsSelected() && aDrawingShadows )
width += getShadowWidth();
return width;
}
float SCH_PAINTER::getTextThickness( const LIB_TEXT* aItem, bool aDrawingShadows ) const
{
float width = (float) std::max( aItem->GetEffectiveTextPenWidth(),
m_schSettings.GetDefaultPenWidth() );
if( aItem->IsSelected() && aDrawingShadows )
width += getShadowWidth();
return width;
}
static VECTOR2D mapCoords( const wxPoint& aCoord )
{
return VECTOR2D( aCoord.x, -aCoord.y );
}
void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition, double aAngle )
{
m_gal->StrokeText( aText, VECTOR2D( aPosition.x, aPosition.y ), aAngle );
}
void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition, double aAngle )
{
const STROKE_FONT& font = m_gal->GetStrokeFont();
VECTOR2D extents = font.ComputeStringBoundaryLimits( aText, m_gal->GetGlyphSize(),
m_gal->GetLineWidth() );
EDA_RECT box( (wxPoint) aPosition, wxSize( extents.x, extents.y ) );
if( m_gal->GetHorizontalJustify() == GR_TEXT_HJUSTIFY_CENTER )
box.SetX( box.GetX() - ( box.GetWidth() / 2) );
else if( m_gal->GetHorizontalJustify() == GR_TEXT_HJUSTIFY_RIGHT )
box.SetX( box.GetX() - box.GetWidth() );
if( m_gal->GetVerticalJustify() == GR_TEXT_VJUSTIFY_CENTER )
box.SetY( box.GetY() - ( box.GetHeight() / 2) );
else if( m_gal->GetVerticalJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
box.SetY( box.GetY() - box.GetHeight() );
box.Normalize(); // Make h and v sizes always >= 0
box = box.GetBoundingBoxRotated((wxPoint) aPosition, RAD2DECIDEG( aAngle ) );
box.RevertYAxis();
m_gal->DrawRectangle( mapCoords( box.GetOrigin() ), mapCoords( box.GetEnd() ) );
}
void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c )
{
m_gal->DrawLine( a, b );
m_gal->DrawLine( b, c );
}
void SCH_PAINTER::draw( const LIB_SYMBOL *aSymbol, int aLayer, bool aDrawFields, int aUnit, int aConvert )
{
if( !aUnit )
aUnit = m_schSettings.m_ShowUnit;
if( !aConvert )
aConvert = m_schSettings.m_ShowConvert;
std::unique_ptr< LIB_SYMBOL > tmpSymbol;
const LIB_SYMBOL* drawnSymbol = aSymbol;
if( aSymbol->IsAlias() )
{
tmpSymbol = aSymbol->Flatten();
drawnSymbol = tmpSymbol.get();
}
for( const LIB_ITEM& item : drawnSymbol->GetDrawItems() )
{
if( !aDrawFields && item.Type() == LIB_FIELD_T )
continue;
if( aUnit && item.GetUnit() && aUnit != item.GetUnit() )
continue;
if( aConvert && item.GetConvert() && aConvert != item.GetConvert() )
continue;
Draw( &item, aLayer );
}
}
bool SCH_PAINTER::setDeviceColors( const LIB_ITEM* aItem, int aLayer )
{
const EDA_SHAPE* shape = dynamic_cast<const EDA_SHAPE*>( aItem );
switch( aLayer )
{
case LAYER_SELECTION_SHADOWS:
if( aItem->IsSelected() )
{
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( getLineWidth( aItem, true ) );
m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, true ) );
m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, true ) );
return true;
}
return false;
case LAYER_DEVICE_BACKGROUND:
if( shape && shape->GetFillType() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
{
COLOR4D fillColor = getRenderColor( aItem, LAYER_DEVICE_BACKGROUND, false );
m_gal->SetIsFill( shape->GetFillType() == FILL_T::FILLED_WITH_BG_BODYCOLOR );
m_gal->SetFillColor( fillColor );
m_gal->SetIsStroke( false );
return true;
}
return false;
case LAYER_DEVICE:
m_gal->SetIsFill( shape && shape->GetFillType() == FILL_T::FILLED_SHAPE );
m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
if( aItem->GetPenWidth() >= 0 || !shape || !shape->IsFilled() )
{
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( getLineWidth( aItem, false ) );
m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, false ) );
}
else
{
m_gal->SetIsStroke( false );
}
return true;
default:
return false;
}
}
void SCH_PAINTER::fillIfSelection( int aLayer )
{
if( aLayer == LAYER_SELECTION_SHADOWS && eeconfig()->m_Selection.fill_shapes )
m_gal->SetIsFill( true );
}
void SCH_PAINTER::draw( const LIB_SHAPE *aShape, int aLayer )
{
if( !isUnitAndConversionShown( aShape ) )
return;
if( setDeviceColors( aShape, aLayer ) )
{
fillIfSelection( aLayer );
switch( aShape->GetShape() )
{
case SHAPE_T::ARC:
{
int startAngle;
int endAngle;
aShape->CalcArcAngles( startAngle, endAngle );
TRANSFORM().MapAngles( &startAngle, &endAngle );
m_gal->DrawArc( mapCoords( aShape->GetCenter() ), aShape->GetRadius(),
DECIDEG2RAD( startAngle ), DECIDEG2RAD( endAngle ) );
}
break;
case SHAPE_T::CIRCLE:
m_gal->DrawCircle( mapCoords( aShape->GetPosition() ), aShape->GetRadius() );
break;
case SHAPE_T::RECT:
m_gal->DrawRectangle( mapCoords( aShape->GetPosition() ),
mapCoords( aShape->GetEnd() ) );
break;
case SHAPE_T::POLY:
{
const SHAPE_LINE_CHAIN poly = aShape->GetPolyShape().Outline( 0 );
std::deque<VECTOR2D> mappedPts;
for( const VECTOR2I& pt : poly.CPoints() )
mappedPts.push_back( mapCoords( (wxPoint) pt ) );
fillIfSelection( aLayer );
m_gal->DrawPolygon( mappedPts );
}
break;
case SHAPE_T::BEZIER:
{
std::deque<VECTOR2D> mappedPts;
for( const wxPoint& p : aShape->GetBezierPoints() )
mappedPts.push_back( mapCoords( p ) );
m_gal->DrawPolygon( mappedPts );
}
break;
default:
wxFAIL_MSG( "SCH_PAINTER::draw not implemented for " + aShape->SHAPE_T_asString() );
}
}
}
void SCH_PAINTER::draw( const LIB_FIELD *aField, int aLayer )
{
bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
if( drawingShadows && !aField->IsSelected() )
return;
if( !isUnitAndConversionShown( aField ) )
return;
// Must check layer as fields are sometimes drawn by their parent rather than
// directly from the view.
int layers[KIGFX::VIEW::VIEW_MAX_LAYERS];
int layers_count;
bool foundLayer = false;
aField->ViewGetLayers( layers, layers_count );
for( int i = 0; i < layers_count; ++i )
{
if( layers[i] == aLayer )
foundLayer = true;
}
if( !foundLayer )
return;
COLOR4D color = getRenderColor( aField, aLayer, drawingShadows );
if( !( aField->IsVisible() || aField->IsForceVisible() ) )
{
if( m_schSettings.m_ShowHiddenText )
color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows );
else
return;
}
m_gal->SetLineWidth( getTextThickness( aField, drawingShadows ) );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
EDA_RECT bbox = aField->GetBoundingBox();
wxPoint textpos = bbox.Centre();
if( drawingShadows && eeconfig()->m_Selection.text_as_box )
{
m_gal->SetIsFill( true );
m_gal->SetFillColor( color );
m_gal->SetLineWidth( m_gal->GetLineWidth() * 0.5 );
bbox.RevertYAxis();
m_gal->DrawRectangle( mapCoords( bbox.GetPosition() ), mapCoords( bbox.GetEnd() ) );
}
else
{
m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
m_gal->SetGlyphSize( VECTOR2D( aField->GetTextSize() ) );
m_gal->SetFontItalic( aField->IsItalic() );
strokeText( UnescapeString( aField->GetText() ), textpos, aField->GetTextAngleRadians() );
}
// Draw the umbilical line
if( aField->IsMoving() && m_schSettings.m_ShowUmbilicals )
{
m_gal->SetLineWidth( m_schSettings.m_outlineWidth );
m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
m_gal->DrawLine( textpos, wxPoint( 0, 0 ) );
}
}
void SCH_PAINTER::draw( const LIB_TEXT *aText, int aLayer )
{
if( !isUnitAndConversionShown( aText ) )
return;
bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
if( drawingShadows && !aText->IsSelected() )
return;
COLOR4D color = getRenderColor( aText, LAYER_DEVICE, drawingShadows );
if( !aText->IsVisible() )
{
if( m_schSettings.m_ShowHiddenText )
color = getRenderColor( aText, LAYER_HIDDEN, drawingShadows );
else
return;
}
EDA_RECT bBox = aText->GetBoundingBox();
bBox.RevertYAxis();
VECTOR2D pos = mapCoords( bBox.Centre() );
double orient = aText->GetTextAngleRadians();
m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
m_gal->SetLineWidth( getTextThickness( aText, drawingShadows ) );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( color );
m_gal->SetGlyphSize( VECTOR2D( aText->GetTextSize() ) );
m_gal->SetFontBold( aText->IsBold() );
m_gal->SetFontItalic( aText->IsItalic() );
m_gal->SetFontUnderlined( false );
strokeText( aText->GetText(), pos, orient );
}
int SCH_PAINTER::internalPinDecoSize( const LIB_PIN &aPin )
{
if( m_schSettings.m_PinSymbolSize > 0 )
return m_schSettings.m_PinSymbolSize;
return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
}
// Utility for getting the size of the 'external' pin decorators (as a radius)
// i.e. the negation circle, the polarity 'slopes' and the nonlogic marker
int SCH_PAINTER::externalPinDecoSize( const LIB_PIN &aPin )
{
if( m_schSettings.m_PinSymbolSize > 0 )
return m_schSettings.m_PinSymbolSize;
return aPin.GetNumberTextSize() / 2;
}
// Draw the target (an open circle) for a pin which has no connection or is being moved.
void SCH_PAINTER::drawPinDanglingSymbol( const VECTOR2I& aPos, bool aDrawingShadows )
{
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth()
: m_schSettings.GetDanglineSymbolThickness() );
m_gal->DrawCircle( aPos, TARGET_PIN_RADIUS );
}
void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer )
{
if( !isUnitAndConversionShown( aPin ) )
return;
bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
bool dangling = m_schSettings.m_IsSymbolEditor || aPin->HasFlag( IS_DANGLING );
if( drawingShadows && !aPin->IsSelected() )
return;
VECTOR2I pos = mapCoords( aPin->GetPosition() );
COLOR4D color = getRenderColor( aPin, LAYER_PIN, drawingShadows );
if( !aPin->IsVisible() )
{
if( m_schSettings.m_ShowHiddenPins )
{
color = getRenderColor( aPin, LAYER_HIDDEN, drawingShadows );
}
else
{
if( dangling && aPin->IsPowerConnection() )
drawPinDanglingSymbol( pos, drawingShadows );
return;
}
}
VECTOR2I p0;
VECTOR2I dir;
int len = aPin->GetLength();
int orient = aPin->GetOrientation();
switch( orient )
{
case PIN_UP:
p0 = VECTOR2I( pos.x, pos.y - len );
dir = VECTOR2I( 0, 1 );
break;
case PIN_DOWN:
p0 = VECTOR2I( pos.x, pos.y + len );
dir = VECTOR2I( 0, -1 );
break;
case PIN_LEFT:
p0 = VECTOR2I( pos.x - len, pos.y );
dir = VECTOR2I( 1, 0 );
break;
default:
case PIN_RIGHT:
p0 = VECTOR2I( pos.x + len, pos.y );
dir = VECTOR2I( -1, 0 );
break;
}
VECTOR2D pc;
m_gal->SetIsStroke( true );
m_gal->SetIsFill( false );
m_gal->SetLineWidth( getLineWidth( aPin, drawingShadows ) );
m_gal->SetStrokeColor( color );
m_gal->SetFontBold( false );
m_gal->SetFontUnderlined( false );
m_gal->SetFontItalic( false );
const int radius = externalPinDecoSize( *aPin );
const int diam = radius*2;
const int clock_size = internalPinDecoSize( *aPin );
if( aPin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
{
m_gal->DrawLine( p0, pos );
m_gal->DrawLine( pos + VECTOR2D( -1, -1 ) * TARGET_PIN_RADIUS,
pos + VECTOR2D( 1, 1 ) * TARGET_PIN_RADIUS );
m_gal->DrawLine( pos + VECTOR2D( 1, -1 ) * TARGET_PIN_RADIUS ,
pos + VECTOR2D( -1, 1 ) * TARGET_PIN_RADIUS );
aPin->ClearFlags( IS_DANGLING ); // PIN_NC pin type is always not connected and dangling.
}
else
{
switch( aPin->GetShape() )
{
case GRAPHIC_PINSHAPE::LINE:
m_gal->DrawLine( p0, pos );
break;
case GRAPHIC_PINSHAPE::INVERTED:
m_gal->DrawCircle( p0 + dir * radius, radius );
m_gal->DrawLine( p0 + dir * ( diam ), pos );
break;
case GRAPHIC_PINSHAPE::INVERTED_CLOCK:
pc = p0 - dir * clock_size ;
triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
pc,
p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
m_gal->DrawCircle( p0 + dir * radius, radius );
m_gal->DrawLine( p0 + dir * ( diam ), pos );
break;
case GRAPHIC_PINSHAPE::CLOCK_LOW:
case GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK:
pc = p0 - dir * clock_size ;
triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size,
pc,
p0 + VECTOR2D( -dir.y, dir.x) * clock_size );
if( !dir.y )
{
triLine( p0 + VECTOR2D(dir.x, 0) * diam,
p0 + VECTOR2D(dir.x, -1) * diam,
p0 );
}
else /* MapX1 = 0 */
{
triLine( p0 + VECTOR2D( 0, dir.y) * diam,
p0 + VECTOR2D(-1, dir.y) * diam,
p0 );
}
m_gal->DrawLine( p0, pos );
break;
case GRAPHIC_PINSHAPE::CLOCK:
m_gal->DrawLine( p0, pos );
if( !dir.y )
{
triLine( p0 + VECTOR2D( 0, clock_size ),
p0 + VECTOR2D( -dir.x * clock_size, 0 ),
p0 + VECTOR2D( 0, -clock_size ) );
}
else
{
triLine( p0 + VECTOR2D( clock_size, 0 ),
p0 + VECTOR2D( 0, -dir.y * clock_size ),
p0 + VECTOR2D( -clock_size, 0 ) );
}
break;
case GRAPHIC_PINSHAPE::INPUT_LOW:
m_gal->DrawLine( p0, pos );
if( !dir.y )
{
triLine( p0 + VECTOR2D(dir.x, 0) * diam,
p0 + VECTOR2D(dir.x, -1) * diam,
p0 );
}
else /* MapX1 = 0 */
{
triLine( p0 + VECTOR2D( 0, dir.y) * diam,
p0 + VECTOR2D(-1, dir.y) * diam,
p0 );
}
break;
case GRAPHIC_PINSHAPE::OUTPUT_LOW: // IEEE symbol "Active Low Output"
m_gal->DrawLine( p0, pos );
if( !dir.y ) // Horizontal pin
m_gal->DrawLine( p0 - VECTOR2D( 0, diam ), p0 + VECTOR2D( dir.x, 0 ) * diam );
else // Vertical pin
m_gal->DrawLine( p0 - VECTOR2D( diam, 0 ), p0 + VECTOR2D( 0, dir.y ) * diam );
break;
case GRAPHIC_PINSHAPE::NONLOGIC: // NonLogic pin symbol
m_gal->DrawLine( p0, pos );
m_gal->DrawLine( p0 - VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius,
p0 + VECTOR2D( dir.x + dir.y, dir.y - dir.x ) * radius );
m_gal->DrawLine( p0 - VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius,
p0 + VECTOR2D( dir.x - dir.y, dir.x + dir.y ) * radius );
break;
}
}
if( dangling )
drawPinDanglingSymbol( pos, drawingShadows );
LIB_SYMBOL* libEntry = aPin->GetParent();
// Draw the labels
if( drawingShadows
&& ( libEntry->Type() == LIB_SYMBOL_T || libEntry->IsSelected() )
&& !eeconfig()->m_Selection.draw_selected_children )
{
return;
}
float penWidth = (float) m_schSettings.GetDefaultPenWidth();
int textOffset = libEntry->GetPinNameOffset();
float nameStrokeWidth = getLineWidth( aPin, drawingShadows );
float numStrokeWidth = getLineWidth( aPin, drawingShadows );
nameStrokeWidth = Clamp_Text_PenSize( nameStrokeWidth, aPin->GetNameTextSize(), false );
numStrokeWidth = Clamp_Text_PenSize( numStrokeWidth, aPin->GetNumberTextSize(), false );
int PIN_TEXT_MARGIN = KiROUND( 24 * m_schSettings.m_TextOffsetRatio );
// Four locations around a pin where text can be drawn
enum { INSIDE = 0, OUTSIDE, ABOVE, BELOW };
int size[4] = { 0, 0, 0, 0 };
float thickness[4] = { numStrokeWidth, numStrokeWidth, numStrokeWidth, numStrokeWidth };
COLOR4D colour[4];
wxString text[4];
// TextOffset > 0 means pin NAMES on inside, pin NUMBERS above and nothing below
if( textOffset )
{
size [INSIDE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
thickness[INSIDE] = nameStrokeWidth;
colour [INSIDE] = getRenderColor( aPin, LAYER_PINNAM, drawingShadows );
text [INSIDE] = aPin->GetShownName();
size [ABOVE] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
thickness[ABOVE] = numStrokeWidth;
colour [ABOVE] = getRenderColor( aPin, LAYER_PINNUM, drawingShadows );
text [ABOVE] = aPin->GetShownNumber();
}
// Otherwise pin NAMES go above and pin NUMBERS go below
else
{
size [ABOVE] = libEntry->ShowPinNames() ? aPin->GetNameTextSize() : 0;
thickness[ABOVE] = nameStrokeWidth;
colour [ABOVE] = getRenderColor( aPin, LAYER_PINNAM, drawingShadows );
text [ABOVE] = aPin->GetShownName();
size [BELOW] = libEntry->ShowPinNumbers() ? aPin->GetNumberTextSize() : 0;
thickness[BELOW] = numStrokeWidth;
colour [BELOW] = getRenderColor( aPin, LAYER_PINNUM, drawingShadows );
text [BELOW] = aPin->GetShownNumber();
}
if( m_schSettings.m_ShowPinsElectricalType )
{
size [OUTSIDE] = std::max( aPin->GetNameTextSize() * 3 / 4, Millimeter2iu( 0.7 ) );
thickness[OUTSIDE] = float( size[OUTSIDE] ) / 6.0F;
colour [OUTSIDE] = getRenderColor( aPin, LAYER_NOTES, drawingShadows );
text [OUTSIDE] = aPin->GetElectricalTypeName();