KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_pin.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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2015 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2018 CERN
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 * @author Jon Evans <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include "sch_pin.h"
25
26#include <lib_id.h>
27#include <lib_symbol.h>
28#include <pin_map.h>
29#include <sch_symbol.h>
30#include <sch_sheet_path.h>
31#include <api/api_enums.h>
32#include <api/api_utils.h>
33#include <base_units.h>
34#include <pgm_base.h>
35#include <pin_layout_cache.h>
36#include <plotters/plotter.h>
37#include <sch_draw_panel.h>
38#include <sch_edit_frame.h>
39#include <symbol_edit_frame.h>
42#include <trace_helpers.h>
43#include <trigo.h>
44#include <string_utils.h>
45#include <properties/property.h>
47#include <api/schematic/schematic_types.pb.h>
48
49wxString FormatStackedPinForDisplay( const wxString& aPinNumber, int aPinLength, int aTextSize, KIFONT::FONT* aFont,
50 const KIFONT::METRICS& aFontMetrics )
51{
52 // Check if this is stacked pin notation: [A,B,C]
53 if( !aPinNumber.StartsWith( "[" ) || !aPinNumber.EndsWith( "]" ) )
54 return aPinNumber;
55
56 // Escaping must never reach the user, so every display form below is built from the unescaped
57 // items. Range notation (e.g. 1-5) is preserved rather than expanded.
58 wxString inner = aPinNumber.Mid( 1, aPinNumber.Length() - 2 );
59 std::vector<wxString> parts = SplitStackedPinDisplayItems( inner );
60
61 if( parts.empty() )
62 return aPinNumber; // malformed; fallback
63
64 for( wxString& part : parts )
65 part.Trim( true ).Trim( false );
66
67 // Build the single-line (unescaped) form and check whether it fits along the pin.
68 wxString singleLine = "[";
69
70 for( size_t i = 0; i < parts.size(); ++i )
71 {
72 if( i > 0 )
73 singleLine += ",";
74
75 singleLine += parts[i];
76 }
77
78 singleLine += "]";
79
80 const int minPinTextWidth = schIUScale.MilsToIU( 50 );
81 const int maxPinTextWidth = std::max( aPinLength, minPinTextWidth );
82
83 VECTOR2D fontSize( aTextSize, aTextSize );
84 int penWidth = GetPenSizeForNormal( aTextSize );
85 VECTOR2I textExtents = aFont->StringBoundaryLimits( singleLine, fontSize, penWidth, false, false, aFontMetrics );
86
87 if( textExtents.x <= maxPinTextWidth )
88 return singleLine; // Fits already
89
90 // Build multi-line representation inside braces.
91 wxString result = "[";
92
93 for( size_t i = 0; i < parts.size(); ++i )
94 {
95 if( i > 0 )
96 result += "\n";
97
98 result += parts[i];
99 }
100
101 result += "]";
102 return result;
103}
104
105
106// small margin in internal units between the pin text and the pin line
107#define PIN_TEXT_MARGIN 4
108
112static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
113{
114 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
115
116 if( settings && settings->m_PinSymbolSize )
117 return settings->m_PinSymbolSize;
118
119 return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
120}
121
122
126static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
127{
128 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
129
130 if( settings && settings->m_PinSymbolSize )
131 return settings->m_PinSymbolSize;
132
133 return aPin.GetNumberTextSize() / 2;
134}
135
136
137SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol ) :
138 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
139 m_libPin( nullptr ),
140 m_position( { 0, 0 } ),
141 m_length( schIUScale.MilsToIU( DEFAULT_PIN_LENGTH ) ),
142 m_orientation( PIN_ORIENTATION::PIN_RIGHT ),
143 m_shape( GRAPHIC_PINSHAPE::LINE ),
145 m_hidden( false ),
146 m_numTextSize( schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE ) ),
147 m_nameTextSize( schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE ) ),
148 m_isDangling( true )
149{
151 {
152 m_length = schIUScale.MilsToIU( cfg->m_Defaults.pin_length );
153 m_numTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_num_size );
154 m_nameTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_name_size );
155 }
156
157 m_layer = LAYER_DEVICE;
158}
159
160
161SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol, const wxString& aName, const wxString& aNumber,
162 PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength,
163 int aNameTextSize, int aNumTextSize, int aBodyStyle, const VECTOR2I& aPos,
164 int aUnit ) :
165 SCH_ITEM( aParentSymbol, SCH_PIN_T, aUnit, aBodyStyle ),
166 m_libPin( nullptr ),
167 m_position( aPos ),
168 m_length( aLength ),
169 m_orientation( aOrientation ),
171 m_type( aPinType ),
172 m_hidden( false ),
173 m_numTextSize( aNumTextSize ),
174 m_nameTextSize( aNameTextSize ),
175 m_isDangling( true )
176{
177 SetName( aName );
178 SetNumber( aNumber );
179
181}
182
183
184SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, SCH_PIN* aLibPin ) :
185 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
186 m_libPin( aLibPin ),
190 m_isDangling( true )
191{
192 wxASSERT( aParentSymbol );
193
194 SetName( m_libPin->GetName() );
195 SetNumber( m_libPin->GetNumber() );
196 m_position = m_libPin->GetPosition();
197
199}
200
201
202SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt,
203 const KIID& aUuid ) :
204 SCH_ITEM( aParentSymbol, SCH_PIN_T ),
205 m_libPin( nullptr ),
209 m_number( aNumber ),
210 m_alt( aAlt ),
211 m_isDangling( true )
212{
213 wxASSERT( aParentSymbol );
214
215 const_cast<KIID&>( m_Uuid ) = aUuid;
217}
218
219
220SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
221 SCH_ITEM( aPin ),
222 m_libPin( aPin.m_libPin ),
224 m_position( aPin.m_position ),
225 m_length( aPin.m_length ),
227 m_shape( aPin.m_shape ),
228 m_type( aPin.m_type ),
229 m_hidden( aPin.m_hidden ),
232 m_alt( aPin.m_alt ),
234{
235 SetName( aPin.m_name );
236 SetNumber( aPin.m_number );
237
238 m_layer = aPin.m_layer;
239}
240
241
245
246
248{
249 SCH_ITEM::operator=( aPin );
250
251 m_libPin = aPin.m_libPin;
253 m_alt = aPin.m_alt;
254 m_name = aPin.m_name;
255 m_number = aPin.m_number;
256 m_position = aPin.m_position;
257 m_length = aPin.m_length;
259 m_shape = aPin.m_shape;
260 m_type = aPin.m_type;
261 m_hidden = aPin.m_hidden;
265 m_layoutCache.reset();
266
267 return *this;
268}
269
270
271void SCH_PIN::Serialize( google::protobuf::Any& aContainer ) const
272{
273 using namespace kiapi::common;
274 using namespace kiapi::schematic::types;
275 SchematicPin pin;
276
277 pin.mutable_id()->set_value( m_Uuid.AsStdString() );
278 pin.set_name( GetBaseName().ToUTF8() );
279 pin.set_number( GetNumber().ToUTF8() );
280
281 PackVector2( *pin.mutable_position(), GetPosition(), schIUScale );
282 PackDistance( *pin.mutable_length(), GetLength(), schIUScale );
284
287 pin.set_visible( IsVisible() );
288
289 PackDistance( *pin.mutable_name_text_size(), GetNameTextSize(), schIUScale );
290 PackDistance( *pin.mutable_number_text_size(), GetNumberTextSize(), schIUScale );
291
292 for( const ALT& alt : GetAlternates() | std::views::values )
293 {
294 SchematicPinAlternate* altProto = pin.add_alternates();
295 altProto->set_name( alt.m_Name.ToUTF8() );
296 altProto->set_shape( ToProtoEnum<GRAPHIC_PINSHAPE, SchematicPinShape>( alt.m_Shape ) );
297 altProto->set_electrical_type( ToProtoEnum<ELECTRICAL_PINTYPE, types::ElectricalPinType>( alt.m_Type ) );
298 }
299
300 if( !m_alt.IsEmpty() && m_alt != GetBaseName() )
301 pin.set_active_alternate( m_alt.ToUTF8() );
302
303 aContainer.PackFrom( pin );
304}
305
306
307bool SCH_PIN::Deserialize( const google::protobuf::Any& aContainer )
308{
309 using namespace kiapi::common;
310 using namespace kiapi::schematic::types;
311
312 SchematicPin pin;
313
314 if( !aContainer.UnpackTo( &pin ) )
315 return false;
316
317 const_cast<KIID&>( m_Uuid ) = KIID( pin.id().value() );
318 m_name = wxString::FromUTF8( pin.name() );
319 m_number = wxString::FromUTF8( pin.number() );
320
321 SetPosition( UnpackVector2( pin.position(), schIUScale ) );
322 SetLength( UnpackDistance( pin.length(), schIUScale ) );
324
325 m_type = FromProtoEnum<ELECTRICAL_PINTYPE>( pin.electrical_type() );
327 SetVisible( pin.visible() );
328
329 m_nameTextSize = UnpackDistance( pin.name_text_size(), schIUScale );
330 m_numTextSize = UnpackDistance( pin.number_text_size(), schIUScale );
331
332 std::map<wxString, ALT>& alts = GetAlternates();
333
334 for( const SchematicPinAlternate& altProto : pin.alternates() )
335 {
336 ALT alt;
337 alt.m_Name = wxString::FromUTF8( altProto.name() );
338 alt.m_Shape = FromProtoEnum<GRAPHIC_PINSHAPE>( altProto.shape() );
339 alt.m_Type = FromProtoEnum<ELECTRICAL_PINTYPE>( altProto.electrical_type() );
340 alts.emplace( alt.m_Name, alt );
341 }
342
343 if( m_layoutCache )
345
346 return true;
347}
348
349
351{
352 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
353 return symbol->GetTransform().TransformCoordinate( m_position ) + symbol->GetPosition();
354 else
355 return m_position;
356}
357
359{
361 {
362 if( !m_libPin )
364
365 return m_libPin->GetOrientation();
366 }
367
368 return m_orientation;
369}
370
371
373{
374 if( !m_alt.IsEmpty() )
375 {
376 if( !m_libPin )
378
379 return m_libPin->GetAlt( m_alt ).m_Shape;
380 }
382 {
383 if( !m_libPin )
385
386 return m_libPin->GetShape();
387 }
388
389 return m_shape;
390}
391
392
394{
395 if( !m_length.has_value() )
396 {
397 if( !m_libPin )
398 return 0;
399
400 return m_libPin->GetLength();
401 }
402
403 return m_length.value();
404}
405
406
408{
409 if( !m_alt.IsEmpty() )
410 {
411 if( !m_libPin )
413
414 return m_libPin->GetAlt( m_alt ).m_Type;
415 }
417 {
418 if( !m_libPin )
420
421 return m_libPin->GetType();
422 }
423
424 return m_type;
425}
426
428{
429 if( aType == m_type )
430 return;
431
432 m_type = aType;
433
434 if( m_layoutCache )
436}
437
438
440{
441 // Use GetType() which correctly handles alternates
442 return ::GetCanonicalElectricalTypeName( GetType() );
443}
444
445
447{
448 // Use GetType() which correctly handles alternates
450}
451
452
454{
456 return false;
457
458 const SYMBOL* parent = GetParentSymbol();
459
460 if( parent->IsGlobalPower() )
461 return true;
462
463 // Local power symbols are never global, even with invisible pins
464 if( parent->IsLocalPower() )
465 return false;
466
467 // Legacy support: invisible power-in pins on non-power symbols act as global power
468 return !IsVisible();
469}
470
471
477
478
480{
481 return IsLocalPower() || IsGlobalPower();
482}
483
484
486{
487 if( !m_hidden.has_value() )
488 {
489 if( !m_libPin )
490 return true;
491
492 return m_libPin->IsVisible();
493 }
494
495 return !m_hidden.value();
496}
497
498
499const wxString& SCH_PIN::GetName() const
500{
501 if( !m_alt.IsEmpty() )
502 return m_alt;
503
504 return GetBaseName();
505}
506
507
508const wxString& SCH_PIN::GetBaseName() const
509{
510 if( m_libPin )
511 return m_libPin->GetBaseName();
512
513 return m_name;
514}
515
516
517void SCH_PIN::SetName( const wxString& aName )
518{
519 if( m_name == aName )
520 return;
521
522 m_name = aName;
523
524 // pin name string does not support spaces
525 m_name.Replace( wxT( " " ), wxT( "_" ) );
526
527 if( m_layoutCache )
529}
530
531
532void SCH_PIN::SetAlt( const wxString& aAlt )
533{
534 // Do not set the alternate pin definition to the default pin name. This breaks the library
535 // symbol comparison for the ERC and the library diff tool. It also incorrectly causes the
536 // schematic symbol pin alternate to be set.
537 if( aAlt.IsEmpty() || aAlt == GetBaseName() )
538 {
539 m_alt = wxEmptyString;
540 return;
541 }
542
543 if( !m_libPin )
544 {
545 wxFAIL_MSG( wxString::Format( wxS( "Pin '%s' has no corresponding lib_pin" ), m_number ) );
546 m_alt = wxEmptyString;
547 return;
548 }
549
550 if( !m_libPin->GetAlternates().contains( aAlt ) )
551 {
552 wxFAIL_MSG( wxString::Format( wxS( "Pin '%s' has no alterate '%s'" ), m_number, aAlt ) );
553 m_alt = wxEmptyString;
554 return;
555 }
556
557 m_alt = aAlt;
558}
559
561{
563 return false;
564
565 return m_isDangling;
566}
567
568
569void SCH_PIN::SetIsDangling( bool aIsDangling )
570{
571 m_isDangling = aIsDangling;
572}
573
574
575bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const
576{
577 const auto isPassiveOrNic = []( ELECTRICAL_PINTYPE t )
578 {
580 };
581
582 const bool sameParent = m_parent == aPin->GetParent();
583 const bool samePos = GetPosition() == aPin->GetPosition();
584 const bool sameName = GetName() == aPin->GetName();
585 const bool typeCompat = GetType() == aPin->GetType()
586 || isPassiveOrNic( GetType() )
587 || isPassiveOrNic( aPin->GetType() );
588
589 wxLogTrace( traceStackedPins,
590 wxString::Format( "IsStacked: this='%s/%s' other='%s/%s' sameParent=%d samePos=%d sameName=%d typeCompat=%d",
591 GetName(), GetNumber(), aPin->GetName(), aPin->GetNumber(), sameParent,
592 samePos, sameName, typeCompat ) );
593
594 return sameParent && samePos && sameName && typeCompat;
595}
596
597
598bool SCH_PIN::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
599{
600 const SCH_SEARCH_DATA& schSearchData =
601 dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
602
603 if( schSearchData.searchAllPins
604 && ( EDA_ITEM::Matches( GetName(), aSearchData )
605 || EDA_ITEM::Matches( GetNumber(), aSearchData ) ) )
606 {
607 return true;
608 }
609
610 SCH_CONNECTION* connection = nullptr;
611 SCH_SHEET_PATH* sheetPath = reinterpret_cast<SCH_SHEET_PATH*>( aAuxData );
612
613 if( schSearchData.searchNetNames && sheetPath && ( connection = Connection( sheetPath ) ) )
614 {
615 wxString netName = connection->GetNetName();
616
617 if( EDA_ITEM::Matches( netName, aSearchData ) )
618 return true;
619 }
620
621 return false;
622}
623
624
625bool SCH_PIN::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
626{
627 bool isReplaced = false;
628
629 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
630 {
631 isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
632 isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
633 }
634 else
635 {
636 /* TODO: waiting on a way to override pins in the schematic...
637 isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
638 isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
639 */
640 }
641
642 return isReplaced;
643}
644
645
646bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
647{
648 // When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has
649 // no pin number or name. Give it a floor.
650 if( Schematic() )
651 aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 );
652
653 BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
654
655 return rect.Inflate( aAccuracy ).Contains( aPosition );
656}
657
658
659bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
660{
662 return false;
663
664 BOX2I sel = aRect;
665
666 if ( aAccuracy )
667 sel.Inflate( aAccuracy );
668
669 if( aContained )
670 return sel.Contains( GetBoundingBox( false, false, false ) );
671
672 return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) );
673}
674
675
676const wxString& SCH_PIN::GetShownName() const
677{
678 if( !m_alt.IsEmpty() )
679 return m_alt;
680 else if( m_libPin )
681 return m_libPin->GetShownName();
682
683 return m_name;
684}
685
686
687const wxString& SCH_PIN::GetShownNumber() const
688{
689 return m_number;
690}
691
692
693std::vector<wxString> SCH_PIN::GetStackedPinNumbers( bool* aValid ) const
694{
695 return ExpandStackedPinNotation( GetShownNumber(), aValid );
696}
697
698
699int SCH_PIN::GetStackedPinCount( bool* aValid ) const
700{
701 const wxString& shown = GetShownNumber();
702 return CountStackedPinNotation( shown, aValid );
703}
704
705
706std::optional<wxString> SCH_PIN::GetSmallestLogicalNumber() const
707{
708 bool valid = false;
709 auto numbers = GetStackedPinNumbers( &valid );
710
711 if( valid && !numbers.empty() )
712 return numbers.front(); // Already in ascending order
713
714 return std::nullopt;
715}
716
717
719{
720 if( auto smallest = GetSmallestLogicalNumber() )
721 return *smallest;
722
723 return GetShownNumber();
724}
725
726
727wxString SCH_PIN::GetEffectivePadNumber( const SCH_SHEET_PATH& aSheet, const wxString& aVariantName,
728 const LIB_ID& aFootprintLibId, const std::set<wxString>* aFootprintPadNumbers,
729 PAD_RESOLUTION* aState ) const
730{
731 const wxString& pinNumber = GetNumber();
732 const PIN_MAP* map = nullptr;
733
734 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
735 {
736 PIN_MAP_INSTANCE_OVERRIDE ovr = symbol->GetPinMapOverride( &aSheet, aVariantName );
737
738 const LIB_SYMBOL* lib = symbol->GetLibSymbolRef().get();
739
742
743 // Library default, or a named map that no longer exists, resolves through the footprint.
744 if( !map && ovr.m_Mode != PIN_MAP_OVERRIDE_MODE::FORCE_IDENTITY && lib )
745 {
746 for( const ASSOCIATED_FOOTPRINT& assoc : lib->GetEffectiveAssociatedFootprints() )
747 {
748 if( assoc.m_FootprintLibId == aFootprintLibId )
749 {
750 map = lib->GetEffectivePinMaps().FindByName( assoc.m_MapName );
751 break;
752 }
753 }
754 }
755
756 // Instance-local sparse edits patch the resolved map, but are ignored under forced
757 // identity per the PIN_MAP_INSTANCE_OVERRIDE contract.
759 {
760 for( const PIN_MAP_ENTRY& edit : ovr.m_Edits )
761 {
762 if( edit.m_PinNumber == pinNumber )
763 {
764 if( aState )
765 *aState = PAD_RESOLUTION::MAPPED;
766
767 return edit.m_PadNumber;
768 }
769 }
770 }
771 }
772
773 // 1. MAPPED - an explicit entry wins and needs no footprint.
774 if( map && map->HasEntry( pinNumber ) )
775 {
776 if( aState )
777 *aState = PAD_RESOLUTION::MAPPED;
778
779 return map->GetPadNumber( pinNumber );
780 }
781
782 // 2. IDENTITY - no entry, but the footprint carries a pad with this number.
783 if( aFootprintPadNumbers && aFootprintPadNumbers->count( pinNumber ) )
784 {
785 if( aState )
786 *aState = PAD_RESOLUTION::IDENTITY;
787
788 return pinNumber;
789 }
790
791 // 3. UNMAPPED, or assumed identity when no footprint is available (the painter path).
792 if( aState )
793 *aState = aFootprintPadNumbers ? PAD_RESOLUTION::UNMAPPED : PAD_RESOLUTION::IDENTITY;
794
795 return aFootprintPadNumbers ? wxString() : pinNumber;
796}
797
798
799wxString SCH_PIN::GetEffectivePadNumber( const SCH_SHEET_PATH& aSheet, const wxString& aVariantName ) const
800{
801 LIB_ID footprintLibId;
802
803 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
804 footprintLibId.Parse( symbol->GetFootprintFieldText( true, &aSheet, false, aVariantName ) );
805
806 return GetEffectivePadNumber( aSheet, aVariantName, footprintLibId, nullptr );
807}
808
809
810void SCH_PIN::SetNumber( const wxString& aNumber )
811{
812 if( m_number == aNumber )
813 return;
814
815 m_number = aNumber;
816 // pin number string does not support spaces
817 m_number.Replace( wxT( " " ), wxT( "_" ) );
818
819 if( m_layoutCache )
821}
822
823
825{
826 if( !m_nameTextSize.has_value() )
827 {
828 if( !m_libPin )
829 return schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE );
830
831 return m_libPin->GetNameTextSize();
832 }
833
834 return m_nameTextSize.value();
835}
836
837
839{
840 if( aSize == m_nameTextSize )
841 return;
842
843 m_nameTextSize = aSize;
844
845 if( m_layoutCache )
847}
848
849
851{
852 if( !m_numTextSize.has_value() )
853 {
854 if( !m_libPin )
855 return schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE );
856
857 return m_libPin->GetNumberTextSize();
858 }
859
860 return m_numTextSize.value();
861}
862
863
865{
866 if( aSize == m_numTextSize )
867 return;
868
869 m_numTextSize = aSize;
870
871 if( m_layoutCache )
873}
874
875
877{
878 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
879 {
880 const TRANSFORM& t = symbol->GetTransform();
881
882 if( !m_libPin )
883 return GetPosition();
884
885 return t.TransformCoordinate( m_libPin->GetPinRoot() ) + symbol->GetPosition();
886 }
887
888 switch( GetOrientation() )
889 {
890 default:
895 }
896}
897
898
899void SCH_PIN::PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition,
900 PIN_ORIENTATION aOrientation, bool aDimmed ) const
901{
902 int MapX1, MapY1, x1, y1;
903 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
904 COLOR4D color = renderSettings->GetLayerColor( LAYER_PIN );
905 COLOR4D bg = renderSettings->GetBackgroundColor();
906 int penWidth = GetEffectivePenWidth( renderSettings );
907 int pinLength = GetLength();
908
909 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
910 bg = COLOR4D::WHITE;
911
912 if( color.m_text && Schematic() )
913 color = COLOR4D( ResolveText( *color.m_text, &Schematic()->CurrentSheet() ) );
914
915 if( aDimmed )
916 {
917 color.Desaturate( );
918 color = color.Mix( bg, 0.5f );
919 }
920
921 aPlotter->SetColor( color );
922 aPlotter->SetCurrentLineWidth( penWidth );
923
924 MapX1 = MapY1 = 0;
925 x1 = aPosition.x; y1 = aPosition.y;
926
927 switch( aOrientation )
928 {
929 case PIN_ORIENTATION::PIN_UP: y1 = aPosition.y - pinLength; MapY1 = 1; break;
930 case PIN_ORIENTATION::PIN_DOWN: y1 = aPosition.y + pinLength; MapY1 = -1; break;
931 case PIN_ORIENTATION::PIN_LEFT: x1 = aPosition.x - pinLength; MapX1 = 1; break;
932 case PIN_ORIENTATION::PIN_RIGHT: x1 = aPosition.x + pinLength; MapX1 = -1; break;
933 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break;
934 }
935
937 {
938 const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
939 aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
940 FILL_T::NO_FILL, penWidth );
941
942 aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
943 aPlotter->FinishTo( aPosition );
944 }
946 {
947 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
948 if( MapY1 == 0 ) /* MapX1 = +- 1 */
949 {
950 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
951 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
952 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
953 }
954 else /* MapX1 = 0 */
955 {
956 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
957 aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
958 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
959 }
960
961 aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
962 aPlotter->FinishTo( aPosition );
963 }
964 else
965 {
966 aPlotter->MoveTo( VECTOR2I( x1, y1 ) );
967 aPlotter->FinishTo( aPosition );
968 }
969
973 {
974 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
975
976 if( MapY1 == 0 ) /* MapX1 = +- 1 */
977 {
978 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
979 aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) );
980 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
981 }
982 else /* MapX1 = 0 */
983 {
984 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
985 aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) );
986 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
987 }
988 }
989
991 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
992 {
993 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
994
995 if( MapY1 == 0 ) /* MapX1 = +- 1 */
996 {
997 aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
998 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
999 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
1000 }
1001 else /* MapX1 = 0 */
1002 {
1003 aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
1004 aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
1005 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
1006 }
1007 }
1008
1009 if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1010 {
1011 const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1012
1013 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1014 {
1015 aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) );
1016 aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) );
1017 }
1018 else /* MapX1 = 0 */
1019 {
1020 aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) );
1021 aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) );
1022 }
1023 }
1024 else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
1025 {
1026 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1027 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size,
1028 y1 - ( MapY1 - MapX1 ) * deco_size ) );
1029 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size,
1030 y1 + ( MapY1 - MapX1 ) * deco_size ) );
1031 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size,
1032 y1 - ( MapY1 + MapX1 ) * deco_size ) );
1033 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size,
1034 y1 + ( MapY1 + MapX1 ) * deco_size ) );
1035 }
1036
1037 if( GetType() == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
1038 {
1039 const int deco_size = TARGET_PIN_RADIUS;
1040 const int ex1 = aPosition.x;
1041 const int ey1 = aPosition.y;
1042 aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) );
1043 aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) );
1044 aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) );
1045 aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) );
1046 }
1047}
1048
1049
1050void SCH_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient,
1051 int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const
1052{
1053 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
1054 KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false );
1055 wxString name = GetShownName();
1056 wxString number = GetShownNumber();
1057
1058 // Apply stacked pin display formatting (reuse helper from pin_layout_cache)
1059 if( aDrawPinNum && !number.IsEmpty() )
1060 {
1061 const KIFONT::METRICS& metrics = GetFontMetrics();
1062 number = FormatStackedPinForDisplay( number, GetLength(), GetNumberTextSize(), font, metrics );
1063 }
1064
1065 if( name.IsEmpty() || m_nameTextSize == 0 )
1066 aDrawPinName = false;
1067
1068 if( number.IsEmpty() || m_numTextSize == 0 )
1069 aDrawPinNum = false;
1070
1071 if( !aDrawPinNum && !aDrawPinName )
1072 return;
1073
1074 int namePenWidth = settings->GetDefaultPenWidth();
1075 int numPenWidth = settings->GetDefaultPenWidth();
1076
1077 // Include the painter's clearance (PIN_LAYOUT_CACHE::getPinTextOffset()) so plotted pin text
1078 // sits where it's drawn on screen, not a few mils closer to the pin.
1079 int pinTextOffset = schIUScale.MilsToIU( KiROUND( 24 * getRenderSettings( aPlotter )->m_TextOffsetRatio ) );
1080 int name_offset = pinTextOffset + schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + namePenWidth;
1081 int num_offset = pinTextOffset + schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numPenWidth;
1082
1083 COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM );
1084 COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM );
1085 COLOR4D bg = settings->GetBackgroundColor();
1086
1087 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1088 bg = COLOR4D::WHITE;
1089
1090 if( nameColor.m_text && Schematic() )
1091 nameColor = COLOR4D( ResolveText( *nameColor.m_text, &Schematic()->CurrentSheet() ) );
1092
1093 if( numColor.m_text && Schematic() )
1094 numColor = COLOR4D( ResolveText( *numColor.m_text, &Schematic()->CurrentSheet() ) );
1095
1096 if( aDimmed )
1097 {
1098 nameColor.Desaturate();
1099 numColor.Desaturate();
1100 nameColor = nameColor.Mix( bg, 0.5f );
1101 numColor = numColor.Mix( bg, 0.5f );
1102 }
1103
1104 int x1 = aPinPos.x;
1105 int y1 = aPinPos.y;
1106
1107 switch( aPinOrient )
1108 {
1109 case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break;
1110 case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break;
1111 case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break;
1112 case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break;
1113 default: break;
1114 }
1115
1116 auto plotSimpleText =
1117 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify, GR_TEXT_V_ALIGN_T vJustify,
1118 const wxString& txt, int size, int penWidth, const COLOR4D& col )
1119 {
1120 TEXT_ATTRIBUTES attrs;
1121 attrs.m_StrokeWidth = penWidth;
1122 attrs.m_Angle = angle;
1123 attrs.m_Size = VECTOR2I( size, size );
1124 attrs.m_Halign = hJustify;
1125 attrs.m_Valign = vJustify;
1126 attrs.m_Multiline = false; // we'll manage multi-line manually
1127 aPlotter->PlotText( VECTOR2I( x, y ), col, txt, attrs, font, GetFontMetrics() );
1128 };
1129
1130 auto plotMultiLineWithBraces =
1131 [&]( int anchorX, int anchorY, EDA_ANGLE angle, GR_TEXT_V_ALIGN_T vAlign, bool /*numberBlock*/ )
1132 {
1133 // If not multi-line formatted, just plot single line centered.
1134 if( !number.StartsWith( "[" ) || !number.EndsWith( "]" ) || !number.Contains( "\n" ) )
1135 {
1136 plotSimpleText( anchorX, anchorY, angle, GR_TEXT_H_ALIGN_CENTER, vAlign, number,
1137 GetNumberTextSize(), numPenWidth, numColor );
1138 return;
1139 }
1140
1141 wxString content = number.Mid( 1, number.Length() - 2 );
1142 wxArrayString lines;
1143 wxStringSplit( content, lines, '\n' );
1144
1145 if( lines.size() <= 1 )
1146 {
1147 plotSimpleText( anchorX, anchorY, angle, GR_TEXT_H_ALIGN_CENTER, vAlign, content,
1148 GetNumberTextSize(), numPenWidth, numColor );
1149 return;
1150 }
1151
1152 const int textSize = GetNumberTextSize();
1153 const int lineSpacing = KiROUND( textSize * 1.3 );
1154 const int numLines = (int) lines.size();
1155 const bool verticalText = ( angle == ANGLE_VERTICAL );
1156 const KIFONT::METRICS& metrics = GetFontMetrics();
1157
1158 // Centre each line and align the stacked block's edge to the anchor, matching the
1159 // on-screen painter (PIN_LAYOUT_CACHE) so stacked numbers plot where they're drawn.
1160 int firstLineCentre;
1161
1162 switch( vAlign )
1163 {
1165 firstLineCentre = -( 2 * numLines - 1 ) * lineSpacing / 2;
1166 break;
1168 firstLineCentre = lineSpacing / 2;
1169 break;
1170 default: // GR_TEXT_V_ALIGN_CENTER
1171 firstLineCentre = -( numLines - 1 ) * lineSpacing / 2;
1172 break;
1173 }
1174
1175 firstLineCentre += verticalText ? anchorX : anchorY;
1176
1177 // Plot each line centred; track the widest for brace spacing.
1178 int maxLineWidth = 0;
1179
1180 for( int i = 0; i < numLines; ++i )
1181 {
1182 wxString l = lines[i];
1183 l.Trim( true ).Trim( false );
1184
1185 VECTOR2I ext = font->StringBoundaryLimits( l, VECTOR2D( textSize, textSize ),
1186 GetPenSizeForNormal( textSize ), false,
1187 false, metrics );
1188 maxLineWidth = std::max( maxLineWidth, ext.x );
1189
1190 int stack = firstLineCentre + i * lineSpacing;
1191 int lx = verticalText ? stack : anchorX;
1192 int ly = verticalText ? anchorY : stack;
1193 plotSimpleText( lx, ly, angle, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, l,
1194 textSize, numPenWidth, numColor );
1195 }
1196
1197 // Now draw braces emulating SCH_PAINTER brace geometry
1198 auto plotBrace =
1199 [&]( const VECTOR2I& top, const VECTOR2I& bottom, bool leftOrTop, bool isVerticalText )
1200 {
1201 // Build 4 small segments approximating curly brace
1202 VECTOR2I mid = ( top + bottom ) / 2;
1203 int braceWidth = textSize / 3; // same scale as painter
1204 VECTOR2I p1 = top;
1205 VECTOR2I p5 = bottom;
1206 VECTOR2I p2 = top;
1207 VECTOR2I p3 = mid;
1208 VECTOR2I p4 = bottom;
1209 int offset = leftOrTop ? -braceWidth : braceWidth;
1210
1211 if( isVerticalText )
1212 {
1213 // Text vertical => brace extends in Y (horizontal brace lines across X axis set)
1214 // For vertical orientation we offset Y for p2/p3/p4
1215 p2.y += offset / 2;
1216 p3.y += offset;
1217 p4.y += offset / 2;
1218 }
1219 else
1220 {
1221 // Horizontal text => brace extends in X
1222 p2.x += offset / 2;
1223 p3.x += offset;
1224 p4.x += offset / 2;
1225 }
1226
1227 aPlotter->MoveTo( p1 ); aPlotter->FinishTo( p2 );
1228 aPlotter->MoveTo( p2 ); aPlotter->FinishTo( p3 );
1229 aPlotter->MoveTo( p3 ); aPlotter->FinishTo( p4 );
1230 aPlotter->MoveTo( p4 ); aPlotter->FinishTo( p5 );
1231 };
1232
1233 aPlotter->SetCurrentLineWidth( numPenWidth );
1234
1235 const int braceWidth = textSize / 3;
1236 const int extraHeight = textSize / 3; // extend beyond text block
1237 const int braceSpacing = maxLineWidth / 2 + braceWidth;
1238 const int blockSpan = ( numLines - 1 ) * lineSpacing;
1239
1240 if( verticalText )
1241 {
1242 VECTOR2I braceStart( firstLineCentre - 2 * extraHeight, anchorY );
1243 VECTOR2I braceEnd( firstLineCentre + blockSpan, anchorY );
1244
1245 VECTOR2I topStart = braceStart; topStart.y -= braceSpacing;
1246 VECTOR2I topEnd = braceEnd; topEnd.y -= braceSpacing;
1247 VECTOR2I bottomStart = braceStart; bottomStart.y += braceSpacing;
1248 VECTOR2I bottomEnd = braceEnd; bottomEnd.y += braceSpacing;
1249
1250 plotBrace( topStart, topEnd, true, true ); // leftOrTop=true
1251 plotBrace( bottomStart, bottomEnd, false, true );
1252 }
1253 else
1254 {
1255 VECTOR2I braceStart( anchorX, firstLineCentre - 2 * extraHeight );
1256 VECTOR2I braceEnd( anchorX, firstLineCentre + blockSpan );
1257
1258 VECTOR2I leftTop = braceStart; leftTop.x -= braceSpacing;
1259 VECTOR2I leftBot = braceEnd; leftBot.x -= braceSpacing;
1260 VECTOR2I rightTop = braceStart; rightTop.x += braceSpacing;
1261 VECTOR2I rightBot = braceEnd; rightBot.x += braceSpacing;
1262
1263 plotBrace( leftTop, leftBot, true, false );
1264 plotBrace( rightTop, rightBot, false, false );
1265 }
1266 };
1267
1268 // Logic largely mirrors original single-line placement but calls multi-line path for numbers
1269 if( aTextInside )
1270 {
1271 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
1272 {
1273 if( aDrawPinName )
1274 {
1275 if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT )
1276 {
1277 plotSimpleText( x1 + aTextInside, y1, ANGLE_HORIZONTAL, GR_TEXT_H_ALIGN_LEFT,
1278 GR_TEXT_V_ALIGN_CENTER, name, GetNameTextSize(), namePenWidth, nameColor );
1279 }
1280 else
1281 {
1282 plotSimpleText( x1 - aTextInside, y1, ANGLE_HORIZONTAL, GR_TEXT_H_ALIGN_RIGHT,
1283 GR_TEXT_V_ALIGN_CENTER, name, GetNameTextSize(), namePenWidth, nameColor );
1284 }
1285 }
1286
1287 if( aDrawPinNum )
1288 {
1289 plotMultiLineWithBraces( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
1290 GR_TEXT_V_ALIGN_BOTTOM, true );
1291 }
1292 }
1293 else
1294 {
1295 if( aPinOrient == PIN_ORIENTATION::PIN_DOWN )
1296 {
1297 if( aDrawPinName )
1298 {
1299 plotSimpleText( x1, y1 + aTextInside, ANGLE_VERTICAL, GR_TEXT_H_ALIGN_RIGHT,
1300 GR_TEXT_V_ALIGN_CENTER, name, GetNameTextSize(), namePenWidth, nameColor );
1301 }
1302
1303 if( aDrawPinNum )
1304 {
1305 plotMultiLineWithBraces( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1306 GR_TEXT_V_ALIGN_BOTTOM, true );
1307 }
1308 }
1309 else // PIN_UP
1310 {
1311 if( aDrawPinName )
1312 {
1313 plotSimpleText( x1, y1 - aTextInside, ANGLE_VERTICAL, GR_TEXT_H_ALIGN_LEFT,
1314 GR_TEXT_V_ALIGN_CENTER, name, GetNameTextSize(), namePenWidth, nameColor );
1315 }
1316
1317 if( aDrawPinNum )
1318 {
1319 plotMultiLineWithBraces( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1320 GR_TEXT_V_ALIGN_BOTTOM, true );
1321 }
1322 }
1323 }
1324 }
1325 else
1326 {
1327 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
1328 {
1329 if( aDrawPinName && aDrawPinNum )
1330 {
1331 plotSimpleText( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1333 GetNameTextSize(), namePenWidth, nameColor );
1334 plotMultiLineWithBraces( ( x1 + aPinPos.x ) / 2, y1 + num_offset, ANGLE_HORIZONTAL,
1335 GR_TEXT_V_ALIGN_TOP, true );
1336 }
1337 else if( aDrawPinName )
1338 {
1339 plotSimpleText( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1341 GetNameTextSize(), namePenWidth, nameColor );
1342 }
1343 else if( aDrawPinNum )
1344 {
1345 plotMultiLineWithBraces( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1346 GR_TEXT_V_ALIGN_BOTTOM, true );
1347 }
1348 }
1349 else
1350 {
1351 if( aDrawPinName && aDrawPinNum )
1352 {
1353 plotSimpleText( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1355 GetNameTextSize(), namePenWidth, nameColor );
1356 plotMultiLineWithBraces( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1357 GR_TEXT_V_ALIGN_TOP, true );
1358 }
1359 else if( aDrawPinName )
1360 {
1361 plotSimpleText( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1363 GetNameTextSize(), namePenWidth, nameColor );
1364 }
1365 else if( aDrawPinNum )
1366 {
1367 plotMultiLineWithBraces( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1368 GR_TEXT_V_ALIGN_BOTTOM, true );
1369 }
1370 }
1371 }
1372}
1373
1374
1376{
1377 PIN_ORIENTATION orient;
1378 VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1
1379
1380 switch( GetOrientation() )
1381 {
1382 default:
1383 case PIN_ORIENTATION::PIN_RIGHT: end.x = 1; break;
1384 case PIN_ORIENTATION::PIN_UP: end.y = -1; break;
1385 case PIN_ORIENTATION::PIN_DOWN: end.y = 1; break;
1386 case PIN_ORIENTATION::PIN_LEFT: end.x = -1; break;
1387 }
1388
1389 // = pos of end point, according to the symbol orientation.
1390 end = aTransform.TransformCoordinate( end );
1391 orient = PIN_ORIENTATION::PIN_UP;
1392
1393 if( end.x == 0 )
1394 {
1395 if( end.y > 0 )
1397 }
1398 else
1399 {
1401
1402 if( end.x < 0 )
1404 }
1405
1406 return orient;
1407}
1408
1409
1411{
1412 //return new SCH_PIN( *this );
1413 SCH_ITEM* newPin = new SCH_PIN( *this );
1414 wxASSERT( newPin->GetUnit() == m_unit && newPin->GetBodyStyle() == m_bodyStyle );
1415 return newPin;
1416}
1417
1418
1419void SCH_PIN::ChangeLength( int aLength )
1420{
1421 int lengthChange = GetLength() - aLength;
1422 int offsetX = 0;
1423 int offsetY = 0;
1424
1425 switch( GetOrientation() )
1426 {
1427 default:
1429 offsetX = lengthChange;
1430 break;
1432 offsetX = -1 * lengthChange;
1433 break;
1435 offsetY = -1 * lengthChange;
1436 break;
1438 offsetY = lengthChange;
1439 break;
1440 }
1441
1442 m_position += VECTOR2I( offsetX, offsetY );
1443 m_length = aLength;
1444}
1445
1446
1447void SCH_PIN::Move( const VECTOR2I& aOffset )
1448{
1449 m_position += aOffset;
1450}
1451
1452
1454{
1455 m_position.x -= aCenter;
1456 m_position.x *= -1;
1457 m_position.x += aCenter;
1458
1463}
1464
1465
1467{
1468 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1469 MirrorHorizontallyPin( aCenter );
1470}
1471
1472
1474{
1475 m_position.y -= aCenter;
1476 m_position.y *= -1;
1477 m_position.y += aCenter;
1478
1483}
1484
1485
1486void SCH_PIN::MirrorVertically( int aCenter )
1487{
1488 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1489 MirrorVerticallyPin( aCenter );
1490}
1491
1492
1493void SCH_PIN::RotatePin( const VECTOR2I& aCenter, bool aRotateCCW )
1494{
1495 if( aRotateCCW )
1496 {
1497 RotatePoint( m_position, aCenter, ANGLE_90 );
1498
1499 switch( GetOrientation() )
1500 {
1501 default:
1506 }
1507 }
1508 else
1509 {
1510 RotatePoint( m_position, aCenter, -ANGLE_90 );
1511
1512 switch( GetOrientation() )
1513 {
1514 default:
1519 }
1520 }
1521}
1522
1523
1524void SCH_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
1525{
1526 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1527 RotatePin( aCenter, aRotateCCW );
1528}
1529
1530
1531void SCH_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
1532 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
1533{
1534 if( aBackground )
1535 return;
1536
1537 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1538
1539 if( !IsVisible() && !renderSettings->m_ShowHiddenPins )
1540 return;
1541
1542 const SYMBOL* part = GetParentSymbol();
1543 PIN_ORIENTATION orient = PinDrawOrient( renderSettings->m_Transform );
1544 VECTOR2I pos = renderSettings->TransformCoordinate( m_position ) + aOffset;
1545
1546 PlotPinType( aPlotter, pos, orient, aDimmed );
1547 PlotPinTexts( aPlotter, pos, orient, part->GetPinNameOffset(), part->GetShowPinNumbers(),
1548 part->GetShowPinNames(), aDimmed );
1549}
1550
1551
1552void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1553{
1554 SYMBOL* symbol = GetParentSymbol();
1555
1556 aList.emplace_back( _( "Type" ), _( "Pin" ) );
1557
1558 SCH_ITEM::GetMsgPanelInfo( aFrame, aList );
1559
1560 aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) );
1561 aList.emplace_back( _( "Number" ), GetShownNumber() );
1562 aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( GetType() ) );
1563 aList.emplace_back( _( "Style" ), PinShapeGetText( GetShape() ) );
1564
1565 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
1566
1567 // Display pin length
1568 aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength(), true ) );
1569
1570 aList.emplace_back( _( "Orientation" ), PinOrientationName( GetOrientation() ) );
1571
1572 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1573 {
1574 aList.emplace_back( _( "Pos X" ), aFrame->MessageTextFromValue( GetPosition().x, true ) );
1575 aList.emplace_back( _( "Pos Y" ), aFrame->MessageTextFromValue( GetPosition().y, true ) );
1576 }
1577 else if( SCH_SYMBOL* schsymbol = dynamic_cast<SCH_SYMBOL*>( symbol ) )
1578 {
1579 SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
1580 SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
1581
1582 // Don't use GetShownText(); we want to see the variable references here
1583 aList.emplace_back( symbol->GetRef( currentSheet ),
1584 UnescapeString( schsymbol->GetField( FIELD_T::VALUE )->GetText() ) );
1585 }
1586
1587#if defined(DEBUG)
1588 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
1589 {
1590 SCH_CONNECTION* conn = Connection();
1591
1592 if( conn )
1593 conn->AppendInfoToMsgPanel( aList );
1594 }
1595#endif
1596}
1597
1598
1600{
1601 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1602
1603 if( aPath )
1604 m_net_name_map.erase( *aPath );
1605 else
1606 m_net_name_map.clear();
1607}
1608
1609
1610wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect )
1611{
1612 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1613
1614 // Need to check for parent as power symbol to make sure we aren't dealing
1615 // with legacy global power pins on non-power symbols
1616 if( IsGlobalPower() || IsLocalPower() )
1617 {
1618 SYMBOL* parent = GetLibPin() ? GetLibPin()->GetParentSymbol() : nullptr;
1619
1620 if( parent && ( parent->IsGlobalPower() || parent->IsLocalPower() ) )
1621 {
1622 return EscapeString( symbol->GetValue( true, &aPath, false ), CTX_NETNAME );
1623 }
1624 else
1625 {
1626 wxString tmp = m_libPin ? m_libPin->GetName() : wxString( "??" );
1627
1628 return EscapeString( tmp, CTX_NETNAME );
1629 }
1630 }
1631
1632 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1633
1634 auto it = m_net_name_map.find( aPath );
1635
1636 if( it != m_net_name_map.end() )
1637 {
1638 if( it->second.second == aForceNoConnect )
1639 return it->second.first;
1640 }
1641
1642 wxString name = "Net-(";
1643 bool unconnected = false;
1644
1645 if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
1646 {
1647 unconnected = true;
1648 name = ( "unconnected-(" );
1649 }
1650
1651 bool annotated = true;
1652
1653 std::vector<const SCH_PIN*> pins = symbol->GetPins( &aPath );
1654 bool has_multiple = false;
1655
1656 for( const SCH_PIN* pin : pins )
1657 {
1658 if( pin->GetShownName() == GetShownName()
1659 && pin->GetShownNumber() != GetShownNumber()
1660 && unconnected == ( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) )
1661 {
1662 has_multiple = true;
1663 break;
1664 }
1665 }
1666
1667 wxString libPinShownName = m_libPin ? m_libPin->GetShownName() : wxString( "??" );
1668 wxString libPinShownNumber = m_libPin ? m_libPin->GetShownNumber() : wxString( "??" );
1669 wxString effectivePadNumber = m_libPin ? m_libPin->GetSmallestStackedPadNumber() : libPinShownNumber;
1670
1671 if( effectivePadNumber != libPinShownNumber )
1672 {
1673 wxLogTrace( traceStackedPins,
1674 wxString::Format( "GetDefaultNetName: stacked pin shown='%s' -> using smallest logical='%s'",
1675 libPinShownNumber, effectivePadNumber ) );
1676 }
1677
1678 // Use timestamp for unannotated symbols
1679 if( symbol->GetRef( &aPath, false ).Last() == '?' )
1680 {
1682
1683 wxString libPinNumber = m_libPin ? m_libPin->GetNumber() : wxString( "??" );
1684 // Apply same smallest-logical substitution for unannotated symbols
1685 if( effectivePadNumber != libPinShownNumber && !effectivePadNumber.IsEmpty() )
1686 libPinNumber = effectivePadNumber;
1687
1688 name << "-Pad" << libPinNumber << ")";
1689 annotated = false;
1690 }
1691 else if( !libPinShownName.IsEmpty() && ( libPinShownName != libPinShownNumber ) )
1692 {
1693 // Pin names might not be unique between different units so we must have the
1694 // unit token in the reference designator
1695 name << symbol->GetRef( &aPath, true );
1696 name << "-" << EscapeString( libPinShownName, CTX_NETNAME );
1697
1698 if( unconnected || has_multiple )
1699 {
1700 // Use effective (possibly de-stacked) pad number in net name
1701 name << "-Pad" << EscapeString( effectivePadNumber, CTX_NETNAME );
1702 }
1703
1704 name << ")";
1705 }
1706 else
1707 {
1708 // Pin numbers are unique, so we skip the unit token
1709 name << symbol->GetRef( &aPath, false );
1710 name << "-Pad" << EscapeString( effectivePadNumber, CTX_NETNAME ) << ")";
1711 }
1712
1713 if( annotated )
1714 m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );
1715
1716 return name;
1717}
1718
1719
1721{
1722 return GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
1723}
1724
1725
1731
1732
1733void SCH_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText,
1734 EXTENTS_CACHE* aCache ) const
1735{
1736 if( aCache->m_Font == aFont
1737 && aCache->m_FontSize == aSize
1738 && aCache->m_Extents != VECTOR2I() )
1739 {
1740 return;
1741 }
1742
1743 aCache->m_Font = aFont;
1744 aCache->m_FontSize = aSize;
1745
1746 VECTOR2D fontSize( aSize, aSize );
1747 int penWidth = GetPenSizeForNormal( aSize );
1748
1749 aCache->m_Extents = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false,
1750 GetFontMetrics() );
1751}
1752
1753
1754BOX2I SCH_PIN::GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber,
1755 bool aIncludeElectricalType ) const
1756{
1757 // Just defer to the cache
1758 return GetLayoutCache().GetPinBoundingBox( aIncludeLabelsOnInvisiblePins,
1759 aIncludeNameAndNumber,
1760 aIncludeElectricalType );
1761}
1762
1763
1765{
1766 if( !m_layoutCache )
1767 m_layoutCache = std::make_unique<PIN_LAYOUT_CACHE>( *this );
1768
1769 return *m_layoutCache;
1770}
1771
1772
1774 const SCH_SHEET_PATH* aInstance ) const
1775{
1776 // Do not compare to ourself.
1777 if( aItem == this )
1778 return false;
1779
1780 const SCH_PIN* pin = dynamic_cast<const SCH_PIN*>( aItem );
1781
1782 // Don't compare against a different SCH_ITEM.
1783 wxCHECK( pin, false );
1784
1785 if( GetPosition() != pin->GetPosition() )
1786 return true;
1787
1788 if( GetNumber() != pin->GetNumber() )
1789 return true;
1790
1791 if( GetName() != pin->GetName() )
1792 return true;
1793
1794 // For power input pins, visibility changes affect IsGlobalPower() which changes
1795 // connectivity semantics. Hidden power pins create implicit global net connections.
1796 // Also check if a pin changed type to/from PT_POWER_IN.
1798 {
1799 if( IsVisible() != pin->IsVisible() || GetType() != pin->GetType() )
1800 return true;
1801 }
1802
1803 return false;
1804}
1805
1806
1808{
1810}
1811
1812
1814{
1815 if( const SYMBOL* parentSymbol = GetParentSymbol() )
1816 {
1817 if( parentSymbol->IsLocked() )
1818 return true;
1819 }
1820
1821 return SCH_ITEM::IsLocked();
1822}
1823
1824
1826{
1827 if( m_libPin )
1828 return m_libPin->GetMenuImage();
1829
1831}
1832
1833
1834wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const
1835{
1836 return getItemDescription( aAlt );
1837}
1838
1839
1840wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1841{
1842 if( m_libPin )
1843 {
1844 SCH_PIN::ALT localStorage;
1845 SCH_PIN::ALT* alt = nullptr;
1846
1847 if( !m_alt.IsEmpty() )
1848 {
1849 localStorage = m_libPin->GetAlt( m_alt );
1850 alt = &localStorage;
1851 }
1852
1853 wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt )
1854 : wxString( wxS( "Undefined library pin." ) );
1855
1856 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1857
1858 return wxString::Format( "Symbol %s %s",
1860 itemDesc );
1861 }
1862
1863 return getItemDescription( nullptr );
1864}
1865
1866
1867wxString SCH_PIN::getItemDescription( ALT* aAlt ) const
1868{
1869 wxString name = UnescapeString( aAlt ? aAlt->m_Name : GetShownName() );
1870 wxString electricalTypeName = ElectricalPinTypeGetText( aAlt ? aAlt->m_Type : m_type );
1871 wxString pinShapeName = PinShapeGetText( aAlt ? aAlt->m_Shape : m_shape );
1872
1873 if( IsVisible() )
1874 {
1875 if ( !name.IsEmpty() )
1876 {
1877 return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1879 name,
1880 electricalTypeName,
1881 pinShapeName );
1882 }
1883 else
1884 {
1885 return wxString::Format( _( "Pin %s [%s, %s]" ),
1887 electricalTypeName,
1888 pinShapeName );
1889 }
1890 }
1891 else
1892 {
1893 if( !name.IsEmpty() )
1894 {
1895 return wxString::Format( _( "Hidden pin %s [%s, %s, %s]" ),
1897 name,
1898 electricalTypeName,
1899 pinShapeName );
1900 }
1901 else
1902 {
1903 return wxString::Format( _( "Hidden pin %s [%s, %s]" ),
1905 electricalTypeName,
1906 pinShapeName );
1907 }
1908 }
1909}
1910
1911
1912int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1913{
1914 // Ignore the UUID here
1915 // And the position, which we'll do after the number.
1916 int retv = SCH_ITEM::compare( aOther, aCompareFlags | SCH_ITEM::COMPARE_FLAGS::EQUALITY
1918
1919 if( retv )
1920 return retv;
1921
1922 const SCH_PIN* tmp = static_cast<const SCH_PIN*>( &aOther );
1923
1924 wxCHECK( tmp, -1 );
1925
1926 if( m_number != tmp->m_number )
1927 {
1928 // StrNumCmp: sort the same as the pads in the footprint file
1929 return StrNumCmp( m_number, tmp->m_number );
1930 }
1931
1932 if( m_position.x != tmp->m_position.x )
1933 return m_position.x - tmp->m_position.x;
1934
1935 if( m_position.y != tmp->m_position.y )
1936 return m_position.y - tmp->m_position.y;
1937
1938 if( dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
1939 {
1940 if( ( m_libPin == nullptr ) || ( tmp->m_libPin == nullptr ) )
1941 return -1;
1942
1943 retv = m_libPin->compare( *tmp->m_libPin );
1944
1945 if( retv )
1946 return retv;
1947
1948 retv = m_alt.Cmp( tmp->m_alt );
1949
1950 if( retv )
1951 return retv;
1952 }
1953
1954 if( dynamic_cast<const LIB_SYMBOL*>( GetParentSymbol() ) )
1955 {
1956 if( m_length != tmp->m_length )
1957 return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 );
1958
1959 if( m_orientation != tmp->m_orientation )
1960 return static_cast<int>( m_orientation ) - static_cast<int>( tmp->m_orientation );
1961
1962 if( m_shape != tmp->m_shape )
1963 return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
1964
1965 if( m_type != tmp->m_type )
1966 return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
1967
1968 if( m_hidden != tmp->m_hidden )
1969 return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false );
1970
1971 if( m_numTextSize != tmp->m_numTextSize )
1972 return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 );
1973
1974 if( m_nameTextSize != tmp->m_nameTextSize )
1975 return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 );
1976
1977 if( m_alternates.size() != tmp->m_alternates.size() )
1978 return static_cast<int>( m_alternates.size() - tmp->m_alternates.size() );
1979
1980 auto lhsItem = m_alternates.begin();
1981 auto rhsItem = tmp->m_alternates.begin();
1982
1983 while( lhsItem != m_alternates.end() )
1984 {
1985 const ALT& lhsAlt = lhsItem->second;
1986 const ALT& rhsAlt = rhsItem->second;
1987
1988 retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
1989
1990 if( retv )
1991 return retv;
1992
1993 if( lhsAlt.m_Type != rhsAlt.m_Type )
1994 return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
1995
1996 if( lhsAlt.m_Shape != rhsAlt.m_Shape )
1997 return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
1998
1999 ++lhsItem;
2000 ++rhsItem;
2001 }
2002 }
2003
2004 return 0;
2005}
2006
2007
2008double SCH_PIN::Similarity( const SCH_ITEM& aOther ) const
2009{
2010 if( aOther.m_Uuid == m_Uuid )
2011 return 1.0;
2012
2013 if( aOther.Type() != SCH_PIN_T )
2014 return 0.0;
2015
2016 const SCH_PIN* other = static_cast<const SCH_PIN*>( &aOther );
2017
2018 if( m_libPin )
2019 {
2020 if( m_number != other->m_number )
2021 return 0.0;
2022
2023 if( m_position != other->m_position )
2024 return 0.0;
2025
2026 return m_libPin->Similarity( *other->m_libPin );
2027 }
2028
2029 double similarity = SimilarityBase( aOther );
2030
2031 if( m_name != other->m_name )
2032 similarity *= 0.9;
2033
2034 if( m_number != other->m_number )
2035 similarity *= 0.9;
2036
2037 if( m_position != other->m_position )
2038 similarity *= 0.9;
2039
2040 if( m_length != other->m_length )
2041 similarity *= 0.9;
2042
2043 if( m_orientation != other->m_orientation )
2044 similarity *= 0.9;
2045
2046 if( m_shape != other->m_shape )
2047 similarity *= 0.9;
2048
2049 if( m_type != other->m_type )
2050 similarity *= 0.9;
2051
2052 if( m_hidden != other->m_hidden )
2053 similarity *= 0.9;
2054
2055 if( m_numTextSize != other->m_numTextSize )
2056 similarity *= 0.9;
2057
2058 if( m_nameTextSize != other->m_nameTextSize )
2059 similarity *= 0.9;
2060
2061 if( m_alternates.size() != other->m_alternates.size() )
2062 similarity *= 0.9;
2063
2064 return similarity;
2065}
2066
2067
2068std::ostream& SCH_PIN::operator<<( std::ostream& aStream )
2069{
2070 aStream << "SCH_PIN:" << std::endl
2071 << " Name: \"" << m_name << "\"" << std::endl
2072 << " Number: \"" << m_number << "\"" << std::endl
2073 << " Position: " << m_position << std::endl
2074 << " Length: " << GetLength() << std::endl
2075 << " Orientation: " << PinOrientationName( m_orientation ) << std::endl
2076 << " Shape: " << PinShapeGetText( m_shape ) << std::endl
2077 << " Type: " << ElectricalPinTypeGetText( m_type ) << std::endl
2078 << " Name Text Size: " << GetNameTextSize() << std::endl
2079 << " Number Text Size: " << GetNumberTextSize() << std::endl;
2080
2081 return aStream;
2082}
2083
2084
2085#if defined(DEBUG)
2086
2087void SCH_PIN::Show( int nestLevel, std::ostream& os ) const
2088{
2089 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
2090 << " num=\"" << m_number.mb_str()
2091 << '"' << "/>\n";
2092}
2093
2094#endif
2095
2096
2097void SCH_PIN::CalcEdit( const VECTOR2I& aPosition )
2098{
2099 if( IsMoving() )
2100 SetPosition( aPosition );
2101}
2102
2103
2104static struct SCH_PIN_DESC
2105{
2107 {
2108 auto& pinTypeEnum = ENUM_MAP<ELECTRICAL_PINTYPE>::Instance();
2109
2110 if( pinTypeEnum.Choices().GetCount() == 0 )
2111 {
2112 pinTypeEnum.Map( ELECTRICAL_PINTYPE::PT_INPUT, _HKI( "Input" ) )
2113 .Map( ELECTRICAL_PINTYPE::PT_OUTPUT, _HKI( "Output" ) )
2114 .Map( ELECTRICAL_PINTYPE::PT_BIDI, _HKI( "Bidirectional" ) )
2115 .Map( ELECTRICAL_PINTYPE::PT_TRISTATE, _HKI( "Tri-state" ) )
2116 .Map( ELECTRICAL_PINTYPE::PT_PASSIVE, _HKI( "Passive" ) )
2117 .Map( ELECTRICAL_PINTYPE::PT_NIC, _HKI( "Free" ) )
2118 .Map( ELECTRICAL_PINTYPE::PT_UNSPECIFIED, _HKI( "Unspecified" ) )
2119 .Map( ELECTRICAL_PINTYPE::PT_POWER_IN, _HKI( "Power input" ) )
2120 .Map( ELECTRICAL_PINTYPE::PT_POWER_OUT, _HKI( "Power output" ) )
2121 .Map( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, _HKI( "Open collector" ) )
2122 .Map( ELECTRICAL_PINTYPE::PT_OPENEMITTER, _HKI( "Open emitter" ) )
2123 .Map( ELECTRICAL_PINTYPE::PT_NC, _HKI( "Unconnected" ) );
2124 }
2125
2126 auto& pinShapeEnum = ENUM_MAP<GRAPHIC_PINSHAPE>::Instance();
2127
2128 if( pinShapeEnum.Choices().GetCount() == 0 )
2129 {
2130 pinShapeEnum.Map( GRAPHIC_PINSHAPE::LINE, _HKI( "Line" ) )
2131 .Map( GRAPHIC_PINSHAPE::INVERTED, _HKI( "Inverted" ) )
2132 .Map( GRAPHIC_PINSHAPE::CLOCK, _HKI( "Clock" ) )
2133 .Map( GRAPHIC_PINSHAPE::INVERTED_CLOCK, _HKI( "Inverted clock" ) )
2134 .Map( GRAPHIC_PINSHAPE::INPUT_LOW, _HKI( "Input low" ) )
2135 .Map( GRAPHIC_PINSHAPE::CLOCK_LOW, _HKI( "Clock low" ) )
2136 .Map( GRAPHIC_PINSHAPE::OUTPUT_LOW, _HKI( "Output low" ) )
2137 .Map( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, _HKI( "Falling edge clock" ) )
2138 .Map( GRAPHIC_PINSHAPE::NONLOGIC, _HKI( "NonLogic" ) );
2139 }
2140
2141 auto& orientationEnum = ENUM_MAP<PIN_ORIENTATION>::Instance();
2142
2143 if( orientationEnum.Choices().GetCount() == 0 )
2144 {
2145 orientationEnum.Map( PIN_ORIENTATION::PIN_RIGHT, _HKI( "Right" ) )
2146 .Map( PIN_ORIENTATION::PIN_LEFT, _HKI( "Left" ) )
2147 .Map( PIN_ORIENTATION::PIN_UP, _HKI( "Up" ) )
2148 .Map( PIN_ORIENTATION::PIN_DOWN, _HKI( "Down" ) );
2149 }
2150
2151 auto isSymbolEditor =
2152 []( INSPECTABLE* aItem ) -> bool
2153 {
2154 if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aItem ) )
2155 return dynamic_cast<LIB_SYMBOL*>( pin->GetParentSymbol() ) != nullptr;
2156
2157 return false;
2158 };
2159
2164
2165 // Lock state is inherited from parent symbol (no independent locking of child items)
2166 propMgr.Mask( TYPE_HASH( SCH_PIN ), TYPE_HASH( SCH_ITEM ), _HKI( "Locked" ) );
2167
2168 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Name" ),
2170 .SetWriteableFunc( isSymbolEditor );
2171
2172 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Number" ),
2174 .SetWriteableFunc( isSymbolEditor );
2175
2176 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, ELECTRICAL_PINTYPE>( _HKI( "Electrical Type" ),
2178 .SetWriteableFunc( isSymbolEditor );
2179
2180 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, GRAPHIC_PINSHAPE>( _HKI( "Graphic Style" ),
2182 .SetWriteableFunc( isSymbolEditor );
2183
2184 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position X" ),
2186 .SetAvailableFunc( isSymbolEditor );
2187
2188 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position Y" ),
2190 .SetAvailableFunc( isSymbolEditor );
2191
2192 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, PIN_ORIENTATION>( _HKI( "Orientation" ),
2194 .SetWriteableFunc( isSymbolEditor );
2195
2196 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Length" ),
2199 .SetWriteableFunc( isSymbolEditor );
2200
2201 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Name Text Size" ),
2204 .SetAvailableFunc( isSymbolEditor );
2205
2206 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Number Text Size" ),
2209 .SetAvailableFunc( isSymbolEditor );
2210
2211 propMgr.AddProperty( new PROPERTY<SCH_PIN, bool>( _HKI( "Visible" ),
2213 .SetAvailableFunc( isSymbolEditor );
2214
2215 }
2217
2218
const char * name
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:47
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:554
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:164
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:307
static const COLOR4D WHITE
Definition color4d.h:401
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:531
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:542
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:416
EDA_ITEM * GetParent() const
Definition eda_item.h:110
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:543
static bool Replace(const EDA_SEARCH_DATA &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition eda_item.cpp:261
bool IsMoving() const
Definition eda_item.h:130
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
static ENUM_MAP< T > & Instance()
Definition property.h:721
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:38
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
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:143
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:447
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
std::shared_ptr< wxString > m_text
Definition color4d.h:395
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition color4d.cpp:528
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:292
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const wxString & GetDefaultFont() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
Definition kiid.h:44
wxString AsString() const
Definition kiid.cpp:242
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
Define a library symbol object.
Definition lib_symbol.h:80
const std::vector< ASSOCIATED_FOOTPRINT > & GetEffectiveAssociatedFootprints() const
Definition lib_symbol.h:256
const PIN_MAP_SET & GetEffectivePinMaps() const
Definition lib_symbol.h:241
Definition line.h:32
A pin layout helper is a class that manages the layout of the parts of a pin on a schematic symbol:
BOX2I GetPinBoundingBox(bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber, bool aIncludeElectricalType)
Get the bounding box of the pin itself.
const PIN_MAP * FindByName(const wxString &aName) const
Definition pin_map.cpp:133
A named pin map.
Definition pin_map.h:64
const wxString & GetPadNumber(const wxString &aPinNumber) const
Definition pin_map.cpp:85
bool HasEntry(const wxString &aPinNumber) const
Definition pin_map.cpp:79
Base plotter engine class.
Definition plotter.h:133
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width)=0
void MoveTo(const VECTOR2I &pos)
Definition plotter.h:305
void FinishTo(const VECTOR2I &pos)
Definition plotter.h:315
RENDER_SETTINGS * RenderSettings()
Definition plotter.h:164
bool GetColorMode() const
Definition plotter.h:161
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
void LineTo(const VECTOR2I &pos)
Definition plotter.h:310
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont=nullptr, const KIFONT::METRICS &aFontMetrics=KIFONT::METRICS::Default(), void *aData=nullptr)
Definition plotter.cpp:712
virtual void SetColor(const COLOR4D &color)=0
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:262
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition property.h:287
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString GetNetName() const
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:128
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition sch_item.cpp:825
int m_unit
Definition sch_item.h:776
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition sch_item.cpp:78
int m_bodyStyle
Definition sch_item.h:777
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.h:724
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:274
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:268
int GetBodyStyle() const
Definition sch_item.h:242
bool IsLocked() const override
Definition sch_item.cpp:148
friend class LIB_SYMBOL
Definition sch_item.h:797
@ SKIP_TST_POS
Definition sch_item.h:707
int GetUnit() const
Definition sch_item.h:233
virtual int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const
Provide the draw object specific comparison called by the == and < operators.
Definition sch_item.cpp:720
bool IsConnectivityDirty() const
Definition sch_item.h:585
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:52
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:487
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:377
const KIFONT::METRICS & GetFontMetrics() const
Definition sch_item.cpp:781
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:790
SCH_LAYER_ID m_layer
Definition sch_item.h:775
double SimilarityBase(const SCH_ITEM &aItem) const
Calculate the boilerplate similarity for all LIB_ITEMs without preventing the use above of a pure vir...
Definition sch_item.h:377
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition sch_pin.cpp:1524
std::ostream & operator<<(std::ostream &aStream)
Definition sch_pin.cpp:2068
void SetAlt(const wxString &aAlt)
Set the name of the alternate pin.
Definition sch_pin.cpp:532
void PlotPinTexts(PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed) const
Plot the pin name and number.
Definition sch_pin.cpp:1050
int GetNumberTextSize() const
Definition sch_pin.cpp:850
int GetLength() const
Definition sch_pin.cpp:393
std::optional< bool > m_hidden
Definition sch_pin.h:455
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition sch_pin.cpp:598
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition sch_pin.cpp:1552
std::unique_ptr< PIN_LAYOUT_CACHE > m_layoutCache
The layout cache for this pin.
Definition sch_pin.h:474
void MirrorVerticallyPin(int aCenter)
Definition sch_pin.cpp:1473
void validateExtentsCache(KIFONT::FONT *aFont, int aSize, const wxString &aText, EXTENTS_CACHE *aCache) const
Definition sch_pin.cpp:1733
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition sch_pin.cpp:1720
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition sch_pin.cpp:1726
const std::map< wxString, ALT > & GetAlternates() const
Definition sch_pin.h:203
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition sch_pin.cpp:2097
void SetNumber(const wxString &aNumber)
Definition sch_pin.cpp:810
std::optional< int > m_nameTextSize
Definition sch_pin.h:459
PIN_ORIENTATION PinDrawOrient(const TRANSFORM &aTransform) const
Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation...
Definition sch_pin.cpp:1375
void SetVisible(bool aVisible)
Definition sch_pin.h:120
int GetX() const
Definition sch_pin.h:297
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition sch_pin.cpp:1419
void SetX(int aX)
Definition sch_pin.h:298
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
Definition sch_pin.cpp:1773
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition sch_pin.cpp:247
SCH_PIN * m_libPin
Definition sch_pin.h:444
std::optional< wxString > GetSmallestLogicalNumber() const
Return the smallest logical pin number if this pin uses stacked notation and it is valid.
Definition sch_pin.cpp:706
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
Definition sch_pin.cpp:1447
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition sch_pin.h:478
PIN_ORIENTATION m_orientation
Definition sch_pin.h:452
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition sch_pin.h:99
void SetName(const wxString &aName)
Definition sch_pin.cpp:517
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:453
wxString getItemDescription(ALT *aAlt) const
Definition sch_pin.cpp:1867
bool IsVisible() const
Definition sch_pin.cpp:485
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition sch_pin.cpp:1807
bool IsLocked() const override
Definition sch_pin.cpp:1813
std::optional< int > m_numTextSize
Definition sch_pin.h:458
VECTOR2I GetPinRoot() const
Definition sch_pin.cpp:876
bool IsLocalPower() const
Local power pin is the same except that it is sheet-local and it does not support the legacy hidden p...
Definition sch_pin.cpp:472
ELECTRICAL_PINTYPE m_type
Definition sch_pin.h:454
PAD_RESOLUTION
Outcome of pin-to-pad resolution (issue #2282).
Definition sch_pin.h:161
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition sch_pin.cpp:1486
SCH_PIN * GetLibPin() const
Definition sch_pin.h:95
void SetPosition(const VECTOR2I &aPos) override
Definition sch_pin.h:294
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition sch_pin.cpp:2008
bool m_isDangling
Definition sch_pin.h:467
void SetIsDangling(bool aIsDangling)
Definition sch_pin.cpp:569
wxString GetElectricalTypeName() const
Definition sch_pin.cpp:446
std::vector< wxString > GetStackedPinNumbers(bool *aValid=nullptr) const
Definition sch_pin.cpp:693
std::map< wxString, ALT > m_alternates
Definition sch_pin.h:447
const wxString & GetName() const
Definition sch_pin.cpp:499
int GetStackedPinCount(bool *aValid=nullptr) const
Return the count of logical pins represented by this pin's stacked notation.
Definition sch_pin.cpp:699
void SetLength(int aLength)
Definition sch_pin.h:105
bool IsDangling() const override
Definition sch_pin.cpp:560
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition sch_pin.cpp:1531
void MirrorHorizontally(int aCenter) override
These transforms have effect only if the pin has a LIB_SYMBOL as parent.
Definition sch_pin.cpp:1466
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition sch_pin.h:477
PIN_ORIENTATION GetOrientation() const
Definition sch_pin.cpp:358
wxString GetClass() const override
Return the class name.
Definition sch_pin.h:80
void SetNumberTextSize(int aSize)
Definition sch_pin.cpp:864
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition sch_pin.h:102
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition sch_pin.cpp:1493
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:350
wxString GetCanonicalElectricalTypeName() const
Definition sch_pin.cpp:439
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition sch_pin.cpp:625
int GetNameTextSize() const
Definition sch_pin.cpp:824
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition sch_pin.cpp:1840
VECTOR2I m_position
Definition sch_pin.h:450
GRAPHIC_PINSHAPE m_shape
Definition sch_pin.h:453
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition sch_pin.cpp:307
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
The pin specific sort order is as follows:
Definition sch_pin.cpp:1912
const wxString & GetShownName() const
Definition sch_pin.cpp:676
void MirrorHorizontallyPin(int aCenter)
These transforms have always effects.
Definition sch_pin.cpp:1453
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition sch_pin.cpp:646
PIN_LAYOUT_CACHE & GetLayoutCache() const
Get the layout cache associated with this pin.
Definition sch_pin.cpp:1764
wxString m_name
Definition sch_pin.h:456
wxString m_alt
Definition sch_pin.h:460
void SetType(ELECTRICAL_PINTYPE aType)
Definition sch_pin.cpp:427
const wxString & GetBaseName() const
Get the name without any alternates.
Definition sch_pin.cpp:508
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition sch_pin.cpp:1599
void SetY(int aY)
Definition sch_pin.h:300
SCH_PIN(LIB_SYMBOL *aParentSymbol)
Definition sch_pin.cpp:137
wxString GetEffectivePadNumber(const SCH_SHEET_PATH &aSheet, const wxString &aVariantName, const LIB_ID &aFootprintLibId, const std::set< wxString > *aFootprintPadNumbers, PAD_RESOLUTION *aState=nullptr) const
Resolve the footprint pad number this symbol pin lands on (issue #2282).
Definition sch_pin.cpp:727
const wxString & GetShownNumber() const
Definition sch_pin.cpp:687
bool IsStacked(const SCH_PIN *aPin) const
Definition sch_pin.cpp:575
const wxString & GetNumber() const
Definition sch_pin.h:130
wxString m_number
Definition sch_pin.h:457
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_pin.cpp:1410
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_pin.h:258
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_pin.cpp:271
wxString GetSmallestStackedPadNumber() const
Return the pin number to be used for deterministic operations such as auto‑generated net names.
Definition sch_pin.cpp:718
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition sch_pin.cpp:1610
std::optional< int > m_length
Definition sch_pin.h:451
GRAPHIC_PINSHAPE GetShape() const
Definition sch_pin.cpp:372
void PlotPinType(PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed) const
Definition sch_pin.cpp:899
int GetY() const
Definition sch_pin.h:299
bool IsPower() const
Check if the pin is either a global or local power pin.
Definition sch_pin.cpp:479
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:407
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition sch_pin.cpp:1825
void SetNameTextSize(int aSize)
Definition sch_pin.cpp:838
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:69
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, const wxString &aVariantName=wxEmptyString) const override
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:59
virtual bool IsGlobalPower() const =0
virtual bool IsLocalPower() const =0
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
int GetPinNameOffset() const
Definition symbol.h:159
virtual bool GetShowPinNames() const
Definition symbol.h:165
virtual bool GetShowPinNumbers() const
Definition symbol.h:171
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
for transforming drawing coordinates for a wxDC device context.
Definition transform.h:42
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition transform.cpp:40
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
#define DEFAULT_PINNUM_SIZE
The default pin name size when creating pins(can be changed in preference menu)
#define DEFAULT_PINNAME_SIZE
The default selection highlight thickness (can be changed in preference menu)
#define DEFAULT_PIN_LENGTH
The default pin number size when creating pins(can be changed in preference menu)
#define _(s)
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
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define SHOW_ELEC_TYPE
Show pin electrical type.
@ NO_FILL
Definition eda_shape.h:60
int GetPenSizeForNormal(int aTextSize)
Definition gr_text.cpp:57
const wxChar *const traceStackedPins
Flag to enable debug output for stacked pins handling in symbol/pin code.
@ LAYER_DANGLING
Definition layer_ids.h:475
@ LAYER_PINNUM
Definition layer_ids.h:456
@ LAYER_DEVICE
Definition layer_ids.h:464
@ LAYER_PINNAM
Definition layer_ids.h:457
@ LAYER_PIN
Definition layer_ids.h:468
@ LAYER_OP_CURRENTS
Definition layer_ids.h:500
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:493
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
#define _HKI(x)
Definition page_info.cpp:40
see class PGM_BASE
static int externalPinDecoSize(const SCHEMATIC_SETTINGS *aSettings, const SCH_PIN &aPin)
static int internalPinDecoSize(const SCHEMATIC_SETTINGS *aSettings, const SCH_PIN &aPin)
wxString FormatStackedPinForDisplay(const wxString &aPinNumber, int aPinLength, int aTextSize, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Definition sch_pin.cpp:49
wxString PinShapeGetText(GRAPHIC_PINSHAPE shape)
Definition pin_type.cpp:231
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition pin_type.h:32
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
@ PT_NC
not connected (must be left open)
Definition pin_type.h:46
@ PT_OUTPUT
usual output
Definition pin_type.h:34
@ PT_TRISTATE
tri state bus pin
Definition pin_type.h:36
@ PT_NIC
not internally connected (may be connected to anything)
Definition pin_type.h:40
@ PT_BIDI
input or output (like port for a microprocessor)
Definition pin_type.h:35
@ PT_OPENEMITTER
pin type open emitter
Definition pin_type.h:45
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
Definition pin_type.h:43
@ PT_OPENCOLLECTOR
pin type open collector
Definition pin_type.h:44
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
Definition pin_type.h:41
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE)
Definition pin_type.cpp:217
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE)
Definition pin_type.cpp:203
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition pin_type.cpp:259
PIN_ORIENTATION
The symbol library pin object orientations.
Definition pin_type.h:101
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
Definition pin_type.h:123
@ PIN_RIGHT
The pin extends rightwards from the connection point.
Definition pin_type.h:107
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
Definition pin_type.h:114
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
Definition pin_type.h:131
GRAPHIC_PINSHAPE
Definition pin_type.h:80
#define TYPE_HASH(x)
Definition property.h:74
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition property.h:828
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
wxString FormatStackedPinForDisplay(const wxString &aPinNumber, int aPinLength, int aTextSize, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Definition sch_pin.cpp:49
static int externalPinDecoSize(const RENDER_SETTINGS *aSettings, const SCH_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius) i.e.
Definition sch_pin.cpp:126
#define PIN_TEXT_MARGIN
Definition sch_pin.cpp:107
static int internalPinDecoSize(const RENDER_SETTINGS *aSettings, const SCH_PIN &aPin)
Utility for getting the size of the 'internal' pin decorators (as a radius) i.e.
Definition sch_pin.cpp:112
static struct SCH_PIN_DESC _SCH_PIN_DESC
#define TARGET_PIN_RADIUS
Definition sch_pin.h:40
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
T * GetAppSettings(const char *aFilename)
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
std::vector< wxString > ExpandStackedPinNotation(const wxString &aPinName, bool *aValid)
Expand stacked pin notation like [1,2,3], [1-4], [A1-A4], or [AA1-AA3,AB4,CD12-CD14] into individual ...
wxString UnescapeString(const wxString &aSource)
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
std::vector< wxString > SplitStackedPinDisplayItems(const wxString &aInner)
Split the inner part of a stacked notation string (the text between the brackets) into its individual...
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
int CountStackedPinNotation(const wxString &aPinName, bool *aValid)
Count the number of pins represented by stacked pin notation.
@ CTX_NETNAME
A first-class footprint choice on a LIB_SYMBOL, tied to a named pin map.
Definition pin_map.h:158
One symbol-pin to footprint-pad mapping inside a PIN_MAP.
Definition pin_map.h:41
Per-instance override of the active pin map and a sparse delta on top.
Definition pin_map.h:199
std::vector< PIN_MAP_ENTRY > m_Edits
Definition pin_map.h:202
PIN_MAP_OVERRIDE_MODE m_Mode
Definition pin_map.h:200
wxString m_Name
Definition sch_pin.h:48
GRAPHIC_PINSHAPE m_Shape
Definition sch_pin.h:49
ELECTRICAL_PINTYPE m_Type
Definition sch_pin.h:50
KIFONT::FONT * m_Font
Definition sch_pin.h:414
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
KIBIS top(path, &reporter)
KIBIS_PIN * pin
int radius
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_BOTTOM
@ 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:225
@ SCH_PIN_T
Definition typeinfo.h:150
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682