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_render_settings.h>
25#include "sch_pin.h"
26
28#include <lib_id.h>
29#include <lib_symbol.h>
30#include <pin_map.h>
31#include <sch_symbol.h>
32#include <sch_sheet_path.h>
33#include <api/api_enums.h>
34#include <api/api_utils.h>
35#include <base_units.h>
36#include <pgm_base.h>
37#include <pin_layout_cache.h>
38#include <plotters/plotter.h>
39#include <sch_draw_panel.h>
40#include <sch_edit_frame.h>
41#include <symbol_edit_frame.h>
44#include <trace_helpers.h>
45#include <trigo.h>
46#include <string_utils.h>
47#include <properties/property.h>
49#include <api/schematic/schematic_types.pb.h>
50
51wxString FormatStackedPinForDisplay( const wxString& aPinNumber, int aPinLength, int aTextSize, KIFONT::FONT* aFont,
52 const KIFONT::METRICS& aFontMetrics )
53{
54 // Check if this is stacked pin notation: [A,B,C]
55 if( !aPinNumber.StartsWith( "[" ) || !aPinNumber.EndsWith( "]" ) )
56 return aPinNumber;
57
58 // Escaping must never reach the user, so every display form below is built from the unescaped
59 // items. Range notation (e.g. 1-5) is preserved rather than expanded.
60 wxString inner = aPinNumber.Mid( 1, aPinNumber.Length() - 2 );
61 std::vector<wxString> parts = SplitStackedPinDisplayItems( inner );
62
63 if( parts.empty() )
64 return aPinNumber; // malformed; fallback
65
66 for( wxString& part : parts )
67 part.Trim( true ).Trim( false );
68
69 // Build the single-line (unescaped) form and check whether it fits along the pin.
70 wxString singleLine = "[";
71
72 for( size_t i = 0; i < parts.size(); ++i )
73 {
74 if( i > 0 )
75 singleLine += ",";
76
77 singleLine += parts[i];
78 }
79
80 singleLine += "]";
81
82 const int minPinTextWidth = schIUScale.MilsToIU( 50 );
83 const int maxPinTextWidth = std::max( aPinLength, minPinTextWidth );
84
85 VECTOR2D fontSize( aTextSize, aTextSize );
86 int penWidth = GetPenSizeForNormal( aTextSize );
87 VECTOR2I textExtents = aFont->StringBoundaryLimits( singleLine, fontSize, penWidth, false, false, aFontMetrics );
88
89 if( textExtents.x <= maxPinTextWidth )
90 return singleLine; // Fits already
91
92 // Build multi-line representation inside braces.
93 wxString result = "[";
94
95 for( size_t i = 0; i < parts.size(); ++i )
96 {
97 if( i > 0 )
98 result += "\n";
99
100 result += parts[i];
101 }
102
103 result += "]";
104 return result;
105}
106
107
108// small margin in internal units between the pin text and the pin line
109#define PIN_TEXT_MARGIN 4
110
114static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
115{
116 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
117
118 if( settings && settings->m_PinSymbolSize )
119 return settings->m_PinSymbolSize;
120
121 return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
122}
123
124
128static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
129{
130 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
131
132 if( settings && settings->m_PinSymbolSize )
133 return settings->m_PinSymbolSize;
134
135 return aPin.GetNumberTextSize() / 2;
136}
137
138
139SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol ) :
140 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
141 m_libPin( nullptr ),
142 m_position( { 0, 0 } ),
143 m_length( schIUScale.MilsToIU( DEFAULT_PIN_LENGTH ) ),
144 m_orientation( PIN_ORIENTATION::PIN_RIGHT ),
145 m_shape( GRAPHIC_PINSHAPE::LINE ),
147 m_hidden( false ),
148 m_numTextSize( schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE ) ),
149 m_nameTextSize( schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE ) ),
150 m_isDangling( true )
151{
153 {
154 m_length = schIUScale.MilsToIU( cfg->m_Defaults.pin_length );
155 m_numTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_num_size );
156 m_nameTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_name_size );
157 }
158
159 m_layer = LAYER_DEVICE;
160}
161
162
163SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol, const wxString& aName, const wxString& aNumber,
164 PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength,
165 int aNameTextSize, int aNumTextSize, int aBodyStyle, const VECTOR2I& aPos,
166 int aUnit ) :
167 SCH_ITEM( aParentSymbol, SCH_PIN_T, aUnit, aBodyStyle ),
168 m_libPin( nullptr ),
169 m_position( aPos ),
170 m_length( aLength ),
171 m_orientation( aOrientation ),
173 m_type( aPinType ),
174 m_hidden( false ),
175 m_numTextSize( aNumTextSize ),
176 m_nameTextSize( aNameTextSize ),
177 m_isDangling( true )
178{
179 SetName( aName );
180 SetNumber( aNumber );
181
183}
184
185
186SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, SCH_PIN* aLibPin ) :
187 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
188 m_libPin( aLibPin ),
192 m_isDangling( true )
193{
194 wxASSERT( aParentSymbol );
195
196 SetName( m_libPin->GetName() );
197 SetNumber( m_libPin->GetNumber() );
198 SetCustomProperties( m_libPin->GetCustomProperties() );
199 m_position = m_libPin->GetPosition();
200
202}
203
204
205SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt,
206 const KIID& aUuid ) :
207 SCH_ITEM( aParentSymbol, SCH_PIN_T ),
208 m_libPin( nullptr ),
212 m_number( aNumber ),
213 m_alt( aAlt ),
214 m_isDangling( true )
215{
216 wxASSERT( aParentSymbol );
217
218 const_cast<KIID&>( m_Uuid ) = aUuid;
220}
221
222
223SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
224 SCH_ITEM( aPin ),
225 m_libPin( aPin.m_libPin ),
227 m_position( aPin.m_position ),
228 m_length( aPin.m_length ),
230 m_shape( aPin.m_shape ),
231 m_type( aPin.m_type ),
232 m_hidden( aPin.m_hidden ),
235 m_alt( aPin.m_alt ),
237{
238 SetName( aPin.m_name );
239 SetNumber( aPin.m_number );
240
241 m_layer = aPin.m_layer;
242}
243
244
248
249
251{
252 SCH_ITEM::operator=( aPin );
253
254 m_libPin = aPin.m_libPin;
256 m_alt = aPin.m_alt;
257 m_name = aPin.m_name;
258 m_number = aPin.m_number;
259 m_position = aPin.m_position;
260 m_length = aPin.m_length;
262 m_shape = aPin.m_shape;
263 m_type = aPin.m_type;
264 m_hidden = aPin.m_hidden;
268 m_layoutCache.reset();
269
270 return *this;
271}
272
273
275{
276 wxCHECK( aItem && aItem->Type() == SCH_PIN_T, /* void */ );
277
278 SCH_PIN* pin = static_cast<SCH_PIN*>( aItem );
279
280 std::swap( m_libPin, pin->m_libPin );
281 std::swap( m_alternates, pin->m_alternates );
282 std::swap( m_alt, pin->m_alt );
283 std::swap( m_name, pin->m_name );
284 std::swap( m_number, pin->m_number );
285 std::swap( m_position, pin->m_position );
286 std::swap( m_length, pin->m_length );
287 std::swap( m_orientation, pin->m_orientation );
288 std::swap( m_shape, pin->m_shape );
289 std::swap( m_type, pin->m_type );
290 std::swap( m_hidden, pin->m_hidden );
291 std::swap( m_numTextSize, pin->m_numTextSize );
292 std::swap( m_nameTextSize, pin->m_nameTextSize );
293 std::swap( m_isDangling, pin->m_isDangling );
294}
295
296
297void SCH_PIN::Serialize( google::protobuf::Any& aContainer ) const
298{
299 using namespace kiapi::common;
300 using namespace kiapi::schematic::types;
301 SchematicPin pin;
302
303 pin.mutable_id()->set_value( m_Uuid.AsStdString() );
304 pin.set_name( GetBaseName().ToUTF8() );
305 pin.set_number( GetNumber().ToUTF8() );
306
307 PackVector2( *pin.mutable_position(), GetLocalPosition(), schIUScale );
308 PackDistance( *pin.mutable_length(), GetLength(), schIUScale );
310
313 pin.set_visible( IsVisible() );
314
315 PackDistance( *pin.mutable_name_text_size(), GetNameTextSize(), schIUScale );
316 PackDistance( *pin.mutable_number_text_size(), GetNumberTextSize(), schIUScale );
317
318 for( const ALT& alt : GetAlternates() | std::views::values )
319 {
320 SchematicPinAlternate* altProto = pin.add_alternates();
321 altProto->set_name( alt.m_Name.ToUTF8() );
322 altProto->set_shape( ToProtoEnum<GRAPHIC_PINSHAPE, SchematicPinShape>( alt.m_Shape ) );
323 altProto->set_electrical_type( ToProtoEnum<ELECTRICAL_PINTYPE, types::ElectricalPinType>( alt.m_Type ) );
324 }
325
326 if( !m_alt.IsEmpty() && m_alt != GetBaseName() )
327 pin.set_active_alternate( m_alt.ToUTF8() );
328
329 kiapi::common::PackCustomProperties( pin.mutable_custom_properties(), *this );
330
331 if( !aContainer.PackFrom( pin ) )
332 wxFAIL_MSG( wxT( "Failed to pack SCH_PIN" ) );
333}
334
335
336bool SCH_PIN::Deserialize( const google::protobuf::Any& aContainer )
337{
338 using namespace kiapi::common;
339 using namespace kiapi::schematic::types;
340
341 SchematicPin pin;
342
343 if( !aContainer.UnpackTo( &pin ) )
344 return false;
345
346 const_cast<KIID&>( m_Uuid ) = KIID( pin.id().value() );
347 m_name = wxString::FromUTF8( pin.name() );
348 m_number = wxString::FromUTF8( pin.number() );
349
350 SetPosition( UnpackVector2( pin.position(), schIUScale ) );
351 SetLength( UnpackDistance( pin.length(), schIUScale ) );
353
354 m_type = FromProtoEnum<ELECTRICAL_PINTYPE>( pin.electrical_type() );
356 SetVisible( pin.visible() );
357
358 m_nameTextSize = UnpackDistance( pin.name_text_size(), schIUScale );
359 m_numTextSize = UnpackDistance( pin.number_text_size(), schIUScale );
360
361 std::map<wxString, ALT>& alts = GetAlternates();
362
363 for( const SchematicPinAlternate& altProto : pin.alternates() )
364 {
365 ALT alt;
366 alt.m_Name = wxString::FromUTF8( altProto.name() );
367 alt.m_Shape = FromProtoEnum<GRAPHIC_PINSHAPE>( altProto.shape() );
368 alt.m_Type = FromProtoEnum<ELECTRICAL_PINTYPE>( altProto.electrical_type() );
369 alts.emplace( alt.m_Name, alt );
370 }
371
372 kiapi::common::UnpackCustomProperties( pin.custom_properties(), *this );
373
374 if( m_layoutCache )
376
377 return true;
378}
379
380
382{
383 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
384 return symbol->GetTransform().TransformCoordinate( m_position ) + symbol->GetPosition();
385 else
386 return m_position;
387}
388
390{
392 {
393 if( !m_libPin )
395
396 return m_libPin->GetOrientation();
397 }
398
399 return m_orientation;
400}
401
402
404{
405 if( !m_alt.IsEmpty() )
406 {
407 if( !m_libPin )
409
410 return m_libPin->GetAlt( m_alt ).m_Shape;
411 }
413 {
414 if( !m_libPin )
416
417 return m_libPin->GetShape();
418 }
419
420 return m_shape;
421}
422
423
425{
426 if( !m_length.has_value() )
427 {
428 if( !m_libPin )
429 return 0;
430
431 return m_libPin->GetLength();
432 }
433
434 return m_length.value();
435}
436
437
439{
440 if( !m_alt.IsEmpty() )
441 {
442 if( !m_libPin )
444
445 return m_libPin->GetAlt( m_alt ).m_Type;
446 }
448 {
449 if( !m_libPin )
451
452 return m_libPin->GetType();
453 }
454
455 return m_type;
456}
457
459{
460 if( aType == m_type )
461 return;
462
463 m_type = aType;
464
465 if( m_layoutCache )
467}
468
469
471{
472 // Use GetType() which correctly handles alternates
473 return ::GetCanonicalElectricalTypeName( GetType() );
474}
475
476
478{
479 // Use GetType() which correctly handles alternates
481}
482
483
485{
487 return false;
488
489 const SYMBOL* parent = GetParentSymbol();
490
491 if( parent->IsGlobalPower() )
492 return true;
493
494 // Local power symbols are never global, even with invisible pins
495 if( parent->IsLocalPower() )
496 return false;
497
498 // Legacy support: invisible power-in pins on non-power symbols act as global power
499 return !IsVisible();
500}
501
502
508
509
511{
512 return IsLocalPower() || IsGlobalPower();
513}
514
515
517{
518 if( !m_hidden.has_value() )
519 {
520 if( !m_libPin )
521 return true;
522
523 return m_libPin->IsVisible();
524 }
525
526 return !m_hidden.value();
527}
528
529
530const wxString& SCH_PIN::GetName() const
531{
532 if( !m_alt.IsEmpty() )
533 return m_alt;
534
535 return GetBaseName();
536}
537
538
539const wxString& SCH_PIN::GetBaseName() const
540{
541 if( m_libPin )
542 return m_libPin->GetBaseName();
543
544 return m_name;
545}
546
547
548void SCH_PIN::SetName( const wxString& aName )
549{
550 if( m_name == aName )
551 return;
552
553 m_name = aName;
554
555 // pin name string does not support spaces
556 m_name.Replace( wxT( " " ), wxT( "_" ) );
557
558 if( m_layoutCache )
560}
561
562
563void SCH_PIN::SetAlt( const wxString& aAlt )
564{
565 // Do not set the alternate pin definition to the default pin name. This breaks the library
566 // symbol comparison for the ERC and the library diff tool. It also incorrectly causes the
567 // schematic symbol pin alternate to be set.
568 if( aAlt.IsEmpty() || aAlt == GetBaseName() )
569 {
570 m_alt = wxEmptyString;
571 return;
572 }
573
574 if( !m_libPin )
575 {
576 wxFAIL_MSG( wxString::Format( wxS( "Pin '%s' has no corresponding lib_pin" ), m_number ) );
577 m_alt = wxEmptyString;
578 return;
579 }
580
581 if( !m_libPin->GetAlternates().contains( aAlt ) )
582 {
583 wxFAIL_MSG( wxString::Format( wxS( "Pin '%s' has no alterate '%s'" ), m_number, aAlt ) );
584 m_alt = wxEmptyString;
585 return;
586 }
587
588 m_alt = aAlt;
589}
590
592{
594 return false;
595
596 return m_isDangling;
597}
598
599
600bool SCH_PIN::SetIsDangling( bool aIsDangling )
601{
602 const bool changed = m_isDangling != aIsDangling;
603 m_isDangling = aIsDangling;
604 return changed;
605}
606
607
608bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const
609{
610 const auto isPassiveOrNic = []( ELECTRICAL_PINTYPE t )
611 {
613 };
614
615 const bool sameParent = m_parent == aPin->GetParent();
616 const bool samePos = GetPosition() == aPin->GetPosition();
617 const bool sameName = GetName() == aPin->GetName();
618 const bool typeCompat = GetType() == aPin->GetType()
619 || isPassiveOrNic( GetType() )
620 || isPassiveOrNic( aPin->GetType() );
621
622 wxLogTrace( traceStackedPins,
623 wxString::Format( "IsStacked: this='%s/%s' other='%s/%s' sameParent=%d samePos=%d sameName=%d typeCompat=%d",
624 GetName(), GetNumber(), aPin->GetName(), aPin->GetNumber(), sameParent,
625 samePos, sameName, typeCompat ) );
626
627 return sameParent && samePos && sameName && typeCompat;
628}
629
630
631bool SCH_PIN::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
632{
633 const SCH_SEARCH_DATA& schSearchData =
634 dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
635
636 if( schSearchData.searchAllPins
637 && ( EDA_ITEM::Matches( GetName(), aSearchData )
638 || EDA_ITEM::Matches( GetNumber(), aSearchData ) ) )
639 {
640 return true;
641 }
642
643 SCH_SHEET_PATH* sheetPath = reinterpret_cast<SCH_SHEET_PATH*>( aAuxData );
644
645 return schSearchData.searchNetNames && sheetPath && MatchesNetName( aSearchData, sheetPath );
646}
647
648
649bool SCH_PIN::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
650{
651 bool isReplaced = false;
652
653 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
654 {
655 isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
656 isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
657 }
658 else
659 {
660 /* TODO: waiting on a way to override pins in the schematic...
661 isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
662 isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
663 */
664 }
665
666 return isReplaced;
667}
668
669
670bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
671{
672 // When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has
673 // no pin number or name. Give it a floor.
674 if( Schematic() )
675 aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 );
676
677 BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
678
679 return rect.Inflate( aAccuracy ).Contains( aPosition );
680}
681
682
683bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
684{
686 return false;
687
688 BOX2I sel = aRect;
689
690 if ( aAccuracy )
691 sel.Inflate( aAccuracy );
692
693 if( aContained )
694 return sel.Contains( GetBoundingBox( false, false, false ) );
695
696 return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) );
697}
698
699
700const wxString& SCH_PIN::GetShownName() const
701{
702 if( !m_alt.IsEmpty() )
703 return m_alt;
704 else if( m_libPin )
705 return m_libPin->GetShownName();
706
707 return m_name;
708}
709
710
711const wxString& SCH_PIN::GetShownNumber() const
712{
713 return m_number;
714}
715
716
717std::vector<wxString> SCH_PIN::GetStackedPinNumbers( bool* aValid ) const
718{
719 return ExpandStackedPinNotation( GetShownNumber(), aValid );
720}
721
722
723int SCH_PIN::GetStackedPinCount( bool* aValid ) const
724{
725 const wxString& shown = GetShownNumber();
726 return CountStackedPinNotation( shown, aValid );
727}
728
729
730std::optional<wxString> SCH_PIN::GetSmallestLogicalNumber() const
731{
732 bool valid = false;
733 auto numbers = GetStackedPinNumbers( &valid );
734
735 if( valid && !numbers.empty() )
736 return numbers.front(); // Already in ascending order
737
738 return std::nullopt;
739}
740
741
743{
744 if( auto smallest = GetSmallestLogicalNumber() )
745 return *smallest;
746
747 return GetShownNumber();
748}
749
750
751wxString SCH_PIN::GetEffectivePadNumber( const SCH_SHEET_PATH& aSheet, const wxString& aVariantName,
752 const LIB_ID& aFootprintLibId, const std::set<wxString>* aFootprintPadNumbers,
753 PAD_RESOLUTION* aState ) const
754{
755 const wxString& pinNumber = GetNumber();
756 const PIN_MAP* map = nullptr;
757
758 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
759 {
760 PIN_MAP_INSTANCE_OVERRIDE ovr = symbol->GetPinMapOverride( &aSheet, aVariantName );
761
762 const LIB_SYMBOL* lib = symbol->GetLibSymbolRef().get();
763
766
767 // Library default, or a named map that no longer exists, resolves through the footprint.
768 if( !map && ovr.m_Mode != PIN_MAP_OVERRIDE_MODE::FORCE_IDENTITY && lib )
769 {
770 for( const ASSOCIATED_FOOTPRINT& assoc : lib->GetEffectiveAssociatedFootprints() )
771 {
772 if( assoc.m_FootprintLibId == aFootprintLibId )
773 {
774 map = lib->GetEffectivePinMaps().FindByName( assoc.m_MapName );
775 break;
776 }
777 }
778 }
779
780 // Instance-local sparse edits patch the resolved map, but are ignored under forced
781 // identity per the PIN_MAP_INSTANCE_OVERRIDE contract.
783 {
784 for( const PIN_MAP_ENTRY& edit : ovr.m_Edits )
785 {
786 if( edit.m_PinNumber == pinNumber )
787 {
788 if( aState )
789 *aState = PAD_RESOLUTION::MAPPED;
790
791 return edit.m_PadNumber;
792 }
793 }
794 }
795 }
796
797 // 1. MAPPED - an explicit entry wins and needs no footprint.
798 if( map && map->HasEntry( pinNumber ) )
799 {
800 if( aState )
801 *aState = PAD_RESOLUTION::MAPPED;
802
803 return map->GetPadNumber( pinNumber );
804 }
805
806 if( aFootprintPadNumbers && HasIdentityPad( pinNumber, *aFootprintPadNumbers ) )
807 {
808 if( aState )
809 *aState = PAD_RESOLUTION::IDENTITY;
810
811 return pinNumber;
812 }
813
814 // 3. UNMAPPED, or assumed identity when no footprint is available (the painter path).
815 if( aState )
816 *aState = aFootprintPadNumbers ? PAD_RESOLUTION::UNMAPPED : PAD_RESOLUTION::IDENTITY;
817
818 return aFootprintPadNumbers ? wxString() : pinNumber;
819}
820
821
822bool SCH_PIN::HasIdentityPad( const wxString& aPinNumber, const std::set<wxString>& aPads )
823{
824 if( aPads.contains( aPinNumber ) )
825 return true;
826
827 bool valid = false;
828 const auto numbers = ExpandStackedPinNotation( aPinNumber, &valid );
829 return valid && std::any_of( numbers.begin(), numbers.end(),
830 [&]( const wxString& number ) { return aPads.contains( number ); } );
831}
832
833
834wxString SCH_PIN::GetEffectivePadNumber( const SCH_SHEET_PATH& aSheet, const wxString& aVariantName ) const
835{
836 LIB_ID footprintLibId;
837
838 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
839 footprintLibId.Parse( symbol->GetFootprintFieldText( &aSheet, RESOLVED, aVariantName ) );
840
841 return GetEffectivePadNumber( aSheet, aVariantName, footprintLibId, nullptr );
842}
843
844
845void SCH_PIN::SetNumber( const wxString& aNumber )
846{
847 if( m_number == aNumber )
848 return;
849
850 m_number = aNumber;
851 // pin number string does not support spaces
852 m_number.Replace( wxT( " " ), wxT( "_" ) );
853
854 if( m_layoutCache )
856}
857
858
860{
861 if( !m_nameTextSize.has_value() )
862 {
863 if( !m_libPin )
864 return schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE );
865
866 return m_libPin->GetNameTextSize();
867 }
868
869 return m_nameTextSize.value();
870}
871
872
874{
875 if( aSize == m_nameTextSize )
876 return;
877
878 m_nameTextSize = aSize;
879
880 if( m_layoutCache )
882}
883
884
886{
887 if( !m_numTextSize.has_value() )
888 {
889 if( !m_libPin )
890 return schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE );
891
892 return m_libPin->GetNumberTextSize();
893 }
894
895 return m_numTextSize.value();
896}
897
898
900{
901 if( aSize == m_numTextSize )
902 return;
903
904 m_numTextSize = aSize;
905
906 if( m_layoutCache )
908}
909
910
912{
913 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
914 {
915 const TRANSFORM& t = symbol->GetTransform();
916
917 if( !m_libPin )
918 return GetPosition();
919
920 return t.TransformCoordinate( m_libPin->GetPinRoot() ) + symbol->GetPosition();
921 }
922
923 switch( GetOrientation() )
924 {
925 default:
930 }
931}
932
933
934void SCH_PIN::PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition,
935 PIN_ORIENTATION aOrientation, bool aDimmed ) const
936{
937 int MapX1, MapY1, x1, y1;
938 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
939 COLOR4D color = renderSettings->GetLayerColor( LAYER_PIN );
940 COLOR4D bg = renderSettings->GetBackgroundColor();
941 int penWidth = GetEffectivePenWidth( renderSettings );
942 int pinLength = GetLength();
943
944 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
945 bg = COLOR4D::WHITE;
946
947 if( color.m_text && Schematic() )
948 color = COLOR4D( ResolveText( *color.m_text, &Schematic()->CurrentSheet() ) );
949
950 if( aDimmed )
951 {
952 color.Desaturate( );
953 color = color.Mix( bg, 0.5f );
954 }
955
956 aPlotter->SetColor( color );
957 aPlotter->SetCurrentLineWidth( penWidth );
958
959 MapX1 = MapY1 = 0;
960 x1 = aPosition.x; y1 = aPosition.y;
961
962 switch( aOrientation )
963 {
964 case PIN_ORIENTATION::PIN_UP: y1 = aPosition.y - pinLength; MapY1 = 1; break;
965 case PIN_ORIENTATION::PIN_DOWN: y1 = aPosition.y + pinLength; MapY1 = -1; break;
966 case PIN_ORIENTATION::PIN_LEFT: x1 = aPosition.x - pinLength; MapX1 = 1; break;
967 case PIN_ORIENTATION::PIN_RIGHT: x1 = aPosition.x + pinLength; MapX1 = -1; break;
968 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break;
969 }
970
972 {
973 const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
974 aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
975 FILL_T::NO_FILL, penWidth );
976
977 aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
978 aPlotter->FinishTo( aPosition );
979 }
981 {
982 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
983 if( MapY1 == 0 ) /* MapX1 = +- 1 */
984 {
985 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
986 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
987 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
988 }
989 else /* MapX1 = 0 */
990 {
991 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
992 aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
993 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
994 }
995
996 aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
997 aPlotter->FinishTo( aPosition );
998 }
999 else
1000 {
1001 aPlotter->MoveTo( VECTOR2I( x1, y1 ) );
1002 aPlotter->FinishTo( aPosition );
1003 }
1004
1008 {
1009 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
1010
1011 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1012 {
1013 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
1014 aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) );
1015 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
1016 }
1017 else /* MapX1 = 0 */
1018 {
1019 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
1020 aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) );
1021 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
1022 }
1023 }
1024
1026 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
1027 {
1028 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1029
1030 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1031 {
1032 aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
1033 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
1034 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
1035 }
1036 else /* MapX1 = 0 */
1037 {
1038 aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
1039 aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
1040 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
1041 }
1042 }
1043
1044 if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1045 {
1046 const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1047
1048 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1049 {
1050 aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) );
1051 aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) );
1052 }
1053 else /* MapX1 = 0 */
1054 {
1055 aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) );
1056 aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) );
1057 }
1058 }
1059 else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
1060 {
1061 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1062 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size,
1063 y1 - ( MapY1 - MapX1 ) * deco_size ) );
1064 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size,
1065 y1 + ( MapY1 - MapX1 ) * deco_size ) );
1066 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size,
1067 y1 - ( MapY1 + MapX1 ) * deco_size ) );
1068 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size,
1069 y1 + ( MapY1 + MapX1 ) * deco_size ) );
1070 }
1071
1072 if( GetType() == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
1073 {
1074 const int deco_size = TARGET_PIN_RADIUS;
1075 const int ex1 = aPosition.x;
1076 const int ey1 = aPosition.y;
1077 aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) );
1078 aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) );
1079 aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) );
1080 aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) );
1081 }
1082}
1083
1084
1085void SCH_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient,
1086 int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const
1087{
1088 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
1089 KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false );
1090 wxString name = GetShownName();
1091 wxString number = GetShownNumber();
1092
1093 // Apply stacked pin display formatting (reuse helper from pin_layout_cache)
1094 if( aDrawPinNum && !number.IsEmpty() )
1095 {
1096 const KIFONT::METRICS& metrics = GetFontMetrics();
1097 number = FormatStackedPinForDisplay( number, GetLength(), GetNumberTextSize(), font, metrics );
1098 }
1099
1100 if( name.IsEmpty() || m_nameTextSize == 0 )
1101 aDrawPinName = false;
1102
1103 if( number.IsEmpty() || m_numTextSize == 0 )
1104 aDrawPinNum = false;
1105
1106 if( !aDrawPinNum && !aDrawPinName )
1107 return;
1108
1109 int namePenWidth = settings->GetDefaultPenWidth();
1110 int numPenWidth = settings->GetDefaultPenWidth();
1111
1112 // Include the painter's clearance (PIN_LAYOUT_CACHE::getPinTextOffset()) so plotted pin text
1113 // sits where it's drawn on screen, not a few mils closer to the pin.
1114 int pinTextOffset = schIUScale.MilsToIU( KiROUND( 24 * getRenderSettings( aPlotter )->m_TextOffsetRatio ) );
1115 int name_offset = pinTextOffset + schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + namePenWidth;
1116 int num_offset = pinTextOffset + schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numPenWidth;
1117
1118 COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM );
1119 COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM );
1120 COLOR4D bg = settings->GetBackgroundColor();
1121
1122 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1123 bg = COLOR4D::WHITE;
1124
1125 if( nameColor.m_text && Schematic() )
1126 nameColor = COLOR4D( ResolveText( *nameColor.m_text, &Schematic()->CurrentSheet() ) );
1127
1128 if( numColor.m_text && Schematic() )
1129 numColor = COLOR4D( ResolveText( *numColor.m_text, &Schematic()->CurrentSheet() ) );
1130
1131 if( aDimmed )
1132 {
1133 nameColor.Desaturate();
1134 numColor.Desaturate();
1135 nameColor = nameColor.Mix( bg, 0.5f );
1136 numColor = numColor.Mix( bg, 0.5f );
1137 }
1138
1139 int x1 = aPinPos.x;
1140 int y1 = aPinPos.y;
1141
1142 switch( aPinOrient )
1143 {
1144 case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break;
1145 case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break;
1146 case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break;
1147 case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break;
1148 default: break;
1149 }
1150
1151 // Keep a multi-line stacked block on the authored side of a mirrored symbol (issue 24894)
1152 const bool flipStacked =
1153 number.Contains( wxT( "\n" ) ) && StackedTextSideFlipped( getRenderSettings( aPlotter )->m_Transform );
1154
1155 auto plotSimpleText =
1156 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify, GR_TEXT_V_ALIGN_T vJustify,
1157 const wxString& txt, int size, int penWidth, const COLOR4D& col )
1158 {
1159 TEXT_ATTRIBUTES attrs;
1160 attrs.m_StrokeWidth = penWidth;
1161 attrs.m_Angle = angle;
1162 attrs.m_Size = VECTOR2I( size, size );
1163 attrs.m_Halign = hJustify;
1164 attrs.m_Valign = vJustify;
1165 attrs.m_Multiline = false; // we'll manage multi-line manually
1166 aPlotter->PlotText( VECTOR2I( x, y ), col, txt, attrs, font, GetFontMetrics() );
1167 };
1168
1169 auto plotMultiLineWithBraces =
1170 [&]( int anchorX, int anchorY, EDA_ANGLE angle, GR_TEXT_V_ALIGN_T vAlign, bool aAllowFlip )
1171 {
1172 // If not multi-line formatted, just plot single line centered.
1173 if( !number.StartsWith( "[" ) || !number.EndsWith( "]" ) || !number.Contains( "\n" ) )
1174 {
1175 plotSimpleText( anchorX, anchorY, angle, GR_TEXT_H_ALIGN_CENTER, vAlign, number, GetNumberTextSize(),
1176 numPenWidth, numColor );
1177 return;
1178 }
1179
1180 wxString content = number.Mid( 1, number.Length() - 2 );
1181 wxArrayString lines;
1182 wxStringSplit( content, lines, '\n' );
1183
1184 if( lines.size() <= 1 )
1185 {
1186 plotSimpleText( anchorX, anchorY, angle, GR_TEXT_H_ALIGN_CENTER, vAlign, content, GetNumberTextSize(),
1187 numPenWidth, numColor );
1188 return;
1189 }
1190
1191 const int textSize = GetNumberTextSize();
1192 const int lineSpacing = KiROUND( textSize * 1.3 );
1193 const int numLines = (int) lines.size();
1194 const bool verticalText = ( angle == ANGLE_VERTICAL );
1195 const KIFONT::METRICS& metrics = GetFontMetrics();
1196
1197 if( aAllowFlip && flipStacked )
1198 {
1199 // Reflect the anchor about the pin line
1200 if( verticalText )
1201 anchorX = 2 * aPinPos.x - anchorX;
1202 else
1203 anchorY = 2 * aPinPos.y - anchorY;
1204
1205 if( vAlign == GR_TEXT_V_ALIGN_BOTTOM )
1206 vAlign = GR_TEXT_V_ALIGN_TOP;
1207 else if( vAlign == GR_TEXT_V_ALIGN_TOP )
1208 vAlign = GR_TEXT_V_ALIGN_BOTTOM;
1209 }
1210
1211 // Centre each line and align the stacked block's edge to the anchor, matching the
1212 // on-screen painter (PIN_LAYOUT_CACHE) so stacked numbers plot where they're drawn.
1213 int firstLineCentre;
1214
1215 switch( vAlign )
1216 {
1217 case GR_TEXT_V_ALIGN_BOTTOM: firstLineCentre = -( 2 * numLines - 1 ) * lineSpacing / 2; break;
1218 case GR_TEXT_V_ALIGN_TOP: firstLineCentre = lineSpacing / 2; break;
1219 default: // GR_TEXT_V_ALIGN_CENTER
1220 firstLineCentre = -( numLines - 1 ) * lineSpacing / 2;
1221 break;
1222 }
1223
1224 firstLineCentre += verticalText ? anchorX : anchorY;
1225
1226 // Plot each line centred; track the widest for brace spacing.
1227 int maxLineWidth = 0;
1228
1229 for( int i = 0; i < numLines; ++i )
1230 {
1231 wxString l = lines[i];
1232 l.Trim( true ).Trim( false );
1233
1234 VECTOR2I ext = font->StringBoundaryLimits( l, VECTOR2D( textSize, textSize ),
1235 GetPenSizeForNormal( textSize ), false, false, metrics );
1236 maxLineWidth = std::max( maxLineWidth, ext.x );
1237
1238 int stack = firstLineCentre + i * lineSpacing;
1239 int lx = verticalText ? stack : anchorX;
1240 int ly = verticalText ? anchorY : stack;
1241 plotSimpleText( lx, ly, angle, GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, l, textSize, numPenWidth,
1242 numColor );
1243 }
1244
1245 // Now draw braces emulating SCH_PAINTER brace geometry
1246 auto plotBrace = [&]( const VECTOR2I& top, const VECTOR2I& bottom, bool leftOrTop, bool isVerticalText )
1247 {
1248 // Build 4 small segments approximating curly brace
1249 VECTOR2I mid = ( top + bottom ) / 2;
1250 int braceWidth = textSize / 3; // same scale as painter
1251 VECTOR2I p1 = top;
1252 VECTOR2I p5 = bottom;
1253 VECTOR2I p2 = top;
1254 VECTOR2I p3 = mid;
1255 VECTOR2I p4 = bottom;
1256 int offset = leftOrTop ? -braceWidth : braceWidth;
1257
1258 if( isVerticalText )
1259 {
1260 // Text vertical => brace extends in Y (horizontal brace lines across X axis set)
1261 // For vertical orientation we offset Y for p2/p3/p4
1262 p2.y += offset / 2;
1263 p3.y += offset;
1264 p4.y += offset / 2;
1265 }
1266 else
1267 {
1268 // Horizontal text => brace extends in X
1269 p2.x += offset / 2;
1270 p3.x += offset;
1271 p4.x += offset / 2;
1272 }
1273
1274 aPlotter->MoveTo( p1 );
1275 aPlotter->FinishTo( p2 );
1276 aPlotter->MoveTo( p2 );
1277 aPlotter->FinishTo( p3 );
1278 aPlotter->MoveTo( p3 );
1279 aPlotter->FinishTo( p4 );
1280 aPlotter->MoveTo( p4 );
1281 aPlotter->FinishTo( p5 );
1282 };
1283
1284 aPlotter->SetCurrentLineWidth( numPenWidth );
1285
1286 const int braceWidth = textSize / 3;
1287 const int extraHeight = textSize / 3; // extend beyond text block
1288 const int braceSpacing = maxLineWidth / 2 + braceWidth;
1289 const int blockSpan = ( numLines - 1 ) * lineSpacing;
1290
1291 if( verticalText )
1292 {
1293 VECTOR2I braceStart( firstLineCentre - 2 * extraHeight, anchorY );
1294 VECTOR2I braceEnd( firstLineCentre + blockSpan, anchorY );
1295
1296 VECTOR2I topStart = braceStart;
1297 topStart.y -= braceSpacing;
1298 VECTOR2I topEnd = braceEnd;
1299 topEnd.y -= braceSpacing;
1300 VECTOR2I bottomStart = braceStart;
1301 bottomStart.y += braceSpacing;
1302 VECTOR2I bottomEnd = braceEnd;
1303 bottomEnd.y += braceSpacing;
1304
1305 plotBrace( topStart, topEnd, true, true ); // leftOrTop=true
1306 plotBrace( bottomStart, bottomEnd, false, true );
1307 }
1308 else
1309 {
1310 VECTOR2I braceStart( anchorX, firstLineCentre - 2 * extraHeight );
1311 VECTOR2I braceEnd( anchorX, firstLineCentre + blockSpan );
1312
1313 VECTOR2I leftTop = braceStart;
1314 leftTop.x -= braceSpacing;
1315 VECTOR2I leftBot = braceEnd;
1316 leftBot.x -= braceSpacing;
1317 VECTOR2I rightTop = braceStart;
1318 rightTop.x += braceSpacing;
1319 VECTOR2I rightBot = braceEnd;
1320 rightBot.x += braceSpacing;
1321
1322 plotBrace( leftTop, leftBot, true, false );
1323 plotBrace( rightTop, rightBot, false, false );
1324 }
1325 };
1326
1327 // Logic largely mirrors original single-line placement but calls multi-line path for numbers
1328 if( aTextInside )
1329 {
1330 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
1331 {
1332 if( aDrawPinName )
1333 {
1334 if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT )
1335 {
1336 plotSimpleText( x1 + aTextInside, y1, ANGLE_HORIZONTAL, GR_TEXT_H_ALIGN_LEFT,
1337 GR_TEXT_V_ALIGN_CENTER, name, GetNameTextSize(), namePenWidth, nameColor );
1338 }
1339 else
1340 {
1341 plotSimpleText( x1 - aTextInside, y1, ANGLE_HORIZONTAL, GR_TEXT_H_ALIGN_RIGHT,
1342 GR_TEXT_V_ALIGN_CENTER, name, GetNameTextSize(), namePenWidth, nameColor );
1343 }
1344 }
1345
1346 if( aDrawPinNum )
1347 {
1348 plotMultiLineWithBraces( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
1349 GR_TEXT_V_ALIGN_BOTTOM, true );
1350 }
1351 }
1352 else
1353 {
1354 if( aPinOrient == PIN_ORIENTATION::PIN_DOWN )
1355 {
1356 if( aDrawPinName )
1357 {
1358 plotSimpleText( x1, y1 + aTextInside, ANGLE_VERTICAL, GR_TEXT_H_ALIGN_RIGHT,
1359 GR_TEXT_V_ALIGN_CENTER, name, GetNameTextSize(), namePenWidth, nameColor );
1360 }
1361
1362 if( aDrawPinNum )
1363 {
1364 plotMultiLineWithBraces( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1365 GR_TEXT_V_ALIGN_BOTTOM, true );
1366 }
1367 }
1368 else // PIN_UP
1369 {
1370 if( aDrawPinName )
1371 {
1372 plotSimpleText( x1, y1 - aTextInside, ANGLE_VERTICAL, GR_TEXT_H_ALIGN_LEFT,
1373 GR_TEXT_V_ALIGN_CENTER, name, GetNameTextSize(), namePenWidth, nameColor );
1374 }
1375
1376 if( aDrawPinNum )
1377 {
1378 plotMultiLineWithBraces( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1379 GR_TEXT_V_ALIGN_BOTTOM, true );
1380 }
1381 }
1382 }
1383 }
1384 else
1385 {
1386 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
1387 {
1388 if( aDrawPinName && aDrawPinNum )
1389 {
1390 plotSimpleText( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1392 GetNameTextSize(), namePenWidth, nameColor );
1393 plotMultiLineWithBraces( ( x1 + aPinPos.x ) / 2, y1 + num_offset, ANGLE_HORIZONTAL, GR_TEXT_V_ALIGN_TOP,
1394 false );
1395 }
1396 else if( aDrawPinName )
1397 {
1398 plotSimpleText( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1400 GetNameTextSize(), namePenWidth, nameColor );
1401 }
1402 else if( aDrawPinNum )
1403 {
1404 plotMultiLineWithBraces( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1405 GR_TEXT_V_ALIGN_BOTTOM, true );
1406 }
1407 }
1408 else
1409 {
1410 if( aDrawPinName && aDrawPinNum )
1411 {
1412 plotSimpleText( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1414 GetNameTextSize(), namePenWidth, nameColor );
1415 plotMultiLineWithBraces( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, GR_TEXT_V_ALIGN_TOP,
1416 false );
1417 }
1418 else if( aDrawPinName )
1419 {
1420 plotSimpleText( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1422 GetNameTextSize(), namePenWidth, nameColor );
1423 }
1424 else if( aDrawPinNum )
1425 {
1426 plotMultiLineWithBraces( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1427 GR_TEXT_V_ALIGN_BOTTOM, true );
1428 }
1429 }
1430 }
1431}
1432
1433
1435{
1436 PIN_ORIENTATION orient;
1437 VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1
1438
1439 switch( GetOrientation() )
1440 {
1441 default:
1442 case PIN_ORIENTATION::PIN_RIGHT: end.x = 1; break;
1443 case PIN_ORIENTATION::PIN_UP: end.y = -1; break;
1444 case PIN_ORIENTATION::PIN_DOWN: end.y = 1; break;
1445 case PIN_ORIENTATION::PIN_LEFT: end.x = -1; break;
1446 }
1447
1448 // = pos of end point, according to the symbol orientation.
1449 end = aTransform.TransformCoordinate( end );
1450 orient = PIN_ORIENTATION::PIN_UP;
1451
1452 if( end.x == 0 )
1453 {
1454 if( end.y > 0 )
1456 }
1457 else
1458 {
1460
1461 if( end.x < 0 )
1463 }
1464
1465 return orient;
1466}
1467
1468
1469bool SCH_PIN::StackedTextSideFlipped( const TRANSFORM& aTransform ) const
1470{
1471 // Side the number block is drawn on (above horizontal pins, left of vertical pins)
1472 auto ruleSide = []( PIN_ORIENTATION aOrient ) -> VECTOR2I
1473 {
1474 if( aOrient == PIN_ORIENTATION::PIN_UP || aOrient == PIN_ORIENTATION::PIN_DOWN )
1475 return VECTOR2I( -1, 0 );
1476
1477 return VECTOR2I( 0, -1 );
1478 };
1479
1480 VECTOR2I mapped = aTransform.TransformCoordinate( ruleSide( GetOrientation() ) );
1481
1482 return mapped == -ruleSide( PinDrawOrient( aTransform ) );
1483}
1484
1485
1487{
1488 //return new SCH_PIN( *this );
1489 SCH_ITEM* newPin = new SCH_PIN( *this );
1490 wxASSERT( newPin->GetUnit() == m_unit && newPin->GetBodyStyle() == m_bodyStyle );
1491 return newPin;
1492}
1493
1494
1495void SCH_PIN::ChangeLength( int aLength )
1496{
1497 int lengthChange = GetLength() - aLength;
1498 int offsetX = 0;
1499 int offsetY = 0;
1500
1501 switch( GetOrientation() )
1502 {
1503 default:
1505 offsetX = lengthChange;
1506 break;
1508 offsetX = -1 * lengthChange;
1509 break;
1511 offsetY = -1 * lengthChange;
1512 break;
1514 offsetY = lengthChange;
1515 break;
1516 }
1517
1518 m_position += VECTOR2I( offsetX, offsetY );
1519 m_length = aLength;
1520}
1521
1522
1523void SCH_PIN::Move( const VECTOR2I& aOffset )
1524{
1525 m_position += aOffset;
1526}
1527
1528
1530{
1531 m_position.x -= aCenter;
1532 m_position.x *= -1;
1533 m_position.x += aCenter;
1534
1539}
1540
1541
1543{
1544 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1545 MirrorHorizontallyPin( aCenter );
1546}
1547
1548
1550{
1551 m_position.y -= aCenter;
1552 m_position.y *= -1;
1553 m_position.y += aCenter;
1554
1559}
1560
1561
1562void SCH_PIN::MirrorVertically( int aCenter )
1563{
1564 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1565 MirrorVerticallyPin( aCenter );
1566}
1567
1568
1569void SCH_PIN::RotatePin( const VECTOR2I& aCenter, bool aRotateCCW )
1570{
1571 if( aRotateCCW )
1572 {
1573 RotatePoint( m_position, aCenter, ANGLE_90 );
1574
1575 switch( GetOrientation() )
1576 {
1577 default:
1582 }
1583 }
1584 else
1585 {
1586 RotatePoint( m_position, aCenter, -ANGLE_90 );
1587
1588 switch( GetOrientation() )
1589 {
1590 default:
1595 }
1596 }
1597}
1598
1599
1600void SCH_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
1601{
1602 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1603 RotatePin( aCenter, aRotateCCW );
1604}
1605
1606
1607void SCH_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
1608 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
1609{
1610 if( aBackground )
1611 return;
1612
1613 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1614
1615 if( !IsVisible() && !renderSettings->m_ShowHiddenPins )
1616 return;
1617
1618 const SYMBOL* part = GetParentSymbol();
1619 PIN_ORIENTATION orient = PinDrawOrient( renderSettings->m_Transform );
1620 VECTOR2I pos = renderSettings->TransformCoordinate( m_position ) + aOffset;
1621
1622 PlotPinType( aPlotter, pos, orient, aDimmed );
1623 PlotPinTexts( aPlotter, pos, orient, part->GetPinNameOffset(), part->GetShowPinNumbers(),
1624 part->GetShowPinNames(), aDimmed );
1625}
1626
1627
1628void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1629{
1630 SYMBOL* symbol = GetParentSymbol();
1631
1632 aList.emplace_back( _( "Type" ), _( "Pin" ) );
1633
1634 SCH_ITEM::GetMsgPanelInfo( aFrame, aList );
1635
1636 aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) );
1637 aList.emplace_back( _( "Number" ), GetShownNumber() );
1638 aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( GetType() ) );
1639 aList.emplace_back( _( "Style" ), PinShapeGetText( GetShape() ) );
1640
1641 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
1642
1643 // Display pin length
1644 aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength(), true ) );
1645
1646 aList.emplace_back( _( "Orientation" ), PinOrientationName( GetOrientation() ) );
1647
1648 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1649 {
1650 aList.emplace_back( _( "Pos X" ), aFrame->MessageTextFromValue( GetPosition().x, true ) );
1651 aList.emplace_back( _( "Pos Y" ), aFrame->MessageTextFromValue( GetPosition().y, true ) );
1652 }
1653 else if( SCH_SYMBOL* schsymbol = dynamic_cast<SCH_SYMBOL*>( symbol ) )
1654 {
1655 SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
1656 SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
1657
1658 // Don't use GetShownText(); we want to see the variable references here
1659 aList.emplace_back( symbol->GetRef( currentSheet ),
1660 UnescapeString( schsymbol->GetField( FIELD_T::VALUE )->GetText() ) );
1661 }
1662
1663#if defined(DEBUG)
1664 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
1665 {
1666 SCH_CONNECTION* conn = Connection();
1667
1668 if( conn )
1669 conn->AppendInfoToMsgPanel( aList );
1670 }
1671#endif
1672}
1673
1674
1676{
1677 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1678
1679 if( aPath )
1680 m_net_name_map.erase( *aPath );
1681 else
1682 m_net_name_map.clear();
1683}
1684
1685
1686wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect )
1687{
1688 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1689
1690 // Need to check for parent as power symbol to make sure we aren't dealing
1691 // with legacy global power pins on non-power symbols
1692 if( IsGlobalPower() || IsLocalPower() )
1693 {
1694 SYMBOL* parent = GetLibPin() ? GetLibPin()->GetParentSymbol() : nullptr;
1695
1696 if( parent && ( parent->IsGlobalPower() || parent->IsLocalPower() ) )
1697 {
1698 return EscapeString( symbol->GetValue( &aPath, FOR_NETNAME ), CTX_NETNAME );
1699 }
1700 else
1701 {
1702 wxString tmp = m_libPin ? m_libPin->GetName() : wxString( "??" );
1703
1704 return EscapeString( tmp, CTX_NETNAME );
1705 }
1706 }
1707
1708 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1709
1710 auto it = m_net_name_map.find( aPath );
1711
1712 if( it != m_net_name_map.end() )
1713 {
1714 if( it->second.second == aForceNoConnect )
1715 return it->second.first;
1716 }
1717
1719 fact.name = m_libPin ? m_libPin->GetShownName() : wxString( "??" );
1720 fact.shownNumber = m_libPin ? m_libPin->GetShownNumber() : wxString( "??" );
1721 fact.number = m_libPin ? m_libPin->GetNumber() : wxString( "??" );
1722 fact.padNumber = m_libPin ? m_libPin->GetSmallestStackedPadNumber() : fact.shownNumber;
1724
1725 if( !aForceNoConnect && !fact.noConnect )
1726 {
1727 for( const SCH_PIN* pin : symbol->GetPins( &aPath ) )
1728 {
1729 if( pin->GetShownName() == GetShownName()
1730 && pin->GetShownNumber() != GetShownNumber()
1731 && pin->GetType() != ELECTRICAL_PINTYPE::PT_NC )
1732 {
1733 fact.hasDuplicateName = true;
1734 break;
1735 }
1736 }
1737 }
1738
1739 if( fact.padNumber != fact.shownNumber )
1740 {
1741 wxLogTrace( traceStackedPins,
1742 wxString::Format( "GetDefaultNetName: stacked pin shown='%s' -> using smallest logical='%s'",
1743 fact.shownNumber, fact.padNumber ) );
1744 }
1745
1747 symbol->GetRef( &aPath, false ), symbol->GetRef( &aPath, true ), symbol->m_Uuid.AsString()
1748 };
1749 const wxString name = SCH_CONNECTIVITY::RenderPinNetName( fact, reference, aForceNoConnect );
1750
1751 if( !reference.reference.IsEmpty() && reference.reference.Last() != '?' )
1752 m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );
1753
1754 return name;
1755}
1756
1757
1759{
1760 return GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
1761}
1762
1763
1769
1770
1771void SCH_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText,
1772 EXTENTS_CACHE* aCache ) const
1773{
1774 if( aCache->m_Font == aFont
1775 && aCache->m_FontSize == aSize
1776 && aCache->m_Extents != VECTOR2I() )
1777 {
1778 return;
1779 }
1780
1781 aCache->m_Font = aFont;
1782 aCache->m_FontSize = aSize;
1783
1784 VECTOR2D fontSize( aSize, aSize );
1785 int penWidth = GetPenSizeForNormal( aSize );
1786
1787 aCache->m_Extents = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false,
1788 GetFontMetrics() );
1789}
1790
1791
1792BOX2I SCH_PIN::GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber,
1793 bool aIncludeElectricalType ) const
1794{
1795 // Just defer to the cache
1796 return GetLayoutCache().GetPinBoundingBox( aIncludeLabelsOnInvisiblePins,
1797 aIncludeNameAndNumber,
1798 aIncludeElectricalType );
1799}
1800
1801
1803{
1804 if( !m_layoutCache )
1805 m_layoutCache = std::make_unique<PIN_LAYOUT_CACHE>( *this );
1806
1807 return *m_layoutCache;
1808}
1809
1810
1812 const SCH_SHEET_PATH* aInstance ) const
1813{
1814 // Do not compare to ourself.
1815 if( aItem == this )
1816 return false;
1817
1818 const SCH_PIN* pin = dynamic_cast<const SCH_PIN*>( aItem );
1819
1820 // Don't compare against a different SCH_ITEM.
1821 wxCHECK( pin, false );
1822
1823 if( GetPosition() != pin->GetPosition() )
1824 return true;
1825
1826 if( GetNumber() != pin->GetNumber() )
1827 return true;
1828
1829 if( GetName() != pin->GetName() )
1830 return true;
1831
1832 // For power input pins, visibility changes affect IsGlobalPower() which changes
1833 // connectivity semantics. Hidden power pins create implicit global net connections.
1834 // Also check if a pin changed type to/from PT_POWER_IN.
1836 {
1837 if( IsVisible() != pin->IsVisible() || GetType() != pin->GetType() )
1838 return true;
1839 }
1840
1841 // Similarly, changing to/from PT_NC affects whether or not the pin participates
1842 // in the connectivity graph.
1844 {
1845 if( GetType() != pin->GetType() )
1846 return true;
1847 }
1848
1849 return false;
1850}
1851
1852
1854{
1856}
1857
1858
1860{
1861 if( const SYMBOL* parentSymbol = GetParentSymbol() )
1862 {
1863 if( parentSymbol->IsLocked() )
1864 return true;
1865 }
1866
1867 return SCH_ITEM::IsLocked();
1868}
1869
1870
1872{
1873 if( m_libPin )
1874 return m_libPin->GetMenuImage();
1875
1877}
1878
1879
1880wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const
1881{
1882 return getItemDescription( aAlt );
1883}
1884
1885
1886wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1887{
1888 if( m_libPin )
1889 {
1890 SCH_PIN::ALT localStorage;
1891 SCH_PIN::ALT* alt = nullptr;
1892
1893 if( !m_alt.IsEmpty() )
1894 {
1895 localStorage = m_libPin->GetAlt( m_alt );
1896 alt = &localStorage;
1897 }
1898
1899 wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt )
1900 : wxString( wxS( "Undefined library pin." ) );
1901
1902 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1903
1904 return wxString::Format( "Symbol %s %s",
1906 itemDesc );
1907 }
1908
1909 return getItemDescription( nullptr );
1910}
1911
1912
1913wxString SCH_PIN::getItemDescription( ALT* aAlt ) const
1914{
1915 wxString name = UnescapeString( aAlt ? aAlt->m_Name : GetShownName() );
1916 wxString electricalTypeName = ElectricalPinTypeGetText( aAlt ? aAlt->m_Type : m_type );
1917 wxString pinShapeName = PinShapeGetText( aAlt ? aAlt->m_Shape : m_shape );
1918
1919 if( IsVisible() )
1920 {
1921 if ( !name.IsEmpty() )
1922 {
1923 return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1925 name,
1926 electricalTypeName,
1927 pinShapeName );
1928 }
1929 else
1930 {
1931 return wxString::Format( _( "Pin %s [%s, %s]" ),
1933 electricalTypeName,
1934 pinShapeName );
1935 }
1936 }
1937 else
1938 {
1939 if( !name.IsEmpty() )
1940 {
1941 return wxString::Format( _( "Hidden pin %s [%s, %s, %s]" ),
1943 name,
1944 electricalTypeName,
1945 pinShapeName );
1946 }
1947 else
1948 {
1949 return wxString::Format( _( "Hidden pin %s [%s, %s]" ),
1951 electricalTypeName,
1952 pinShapeName );
1953 }
1954 }
1955}
1956
1957
1958namespace
1959{
1960struct PIN_COMPARISON_VIEW
1961{
1962 int unit;
1963 int bodyStyle;
1964 bool isPrivate;
1965 VECTOR2I position;
1966 const wxString& number;
1967 std::optional<int> length;
1969 GRAPHIC_PINSHAPE shape;
1970 ELECTRICAL_PINTYPE type;
1971 std::optional<bool> hidden;
1972 std::optional<int> numberTextSize;
1973 std::optional<int> nameTextSize;
1974 const std::map<wxString, PIN_ALTERNATE>& alternates;
1975
1976 int Compare( const PIN_COMPARISON_VIEW& aOther, int aCompareFlags ) const
1977 {
1978 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT )
1979 {
1980 if( unit != aOther.unit )
1981 return unit - aOther.unit;
1982
1983 if( bodyStyle != aOther.bodyStyle )
1984 return bodyStyle - aOther.bodyStyle;
1985 }
1986
1987 if( isPrivate != aOther.isPrivate )
1988 return isPrivate ? 1 : -1;
1989
1990 if( number != aOther.number )
1991 return StrNumCmp( number, aOther.number );
1992
1993 if( position.x != aOther.position.x )
1994 return position.x - aOther.position.x;
1995
1996 if( position.y != aOther.position.y )
1997 return position.y - aOther.position.y;
1998
1999 if( length != aOther.length )
2000 return length.value_or( 0 ) - aOther.length.value_or( 0 );
2001
2002 if( orientation != aOther.orientation )
2003 return static_cast<int>( orientation ) - static_cast<int>( aOther.orientation );
2004
2005 if( shape != aOther.shape )
2006 return static_cast<int>( shape ) - static_cast<int>( aOther.shape );
2007
2008 if( type != aOther.type )
2009 return static_cast<int>( type ) - static_cast<int>( aOther.type );
2010
2011 if( ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::PIN_VISIBILITIES ) && hidden != aOther.hidden )
2012 return hidden.value_or( false ) - aOther.hidden.value_or( false );
2013
2014 if( numberTextSize != aOther.numberTextSize )
2015 return numberTextSize.value_or( 0 ) - aOther.numberTextSize.value_or( 0 );
2016
2017 if( nameTextSize != aOther.nameTextSize )
2018 return nameTextSize.value_or( 0 ) - aOther.nameTextSize.value_or( 0 );
2019
2020 if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::PIN_ALT_DEFS ) )
2021 return 0;
2022
2023 if( alternates.size() != aOther.alternates.size() )
2024 return static_cast<int>( alternates.size() - aOther.alternates.size() );
2025
2026 auto lhsItem = alternates.begin();
2027 auto rhsItem = aOther.alternates.begin();
2028
2029 while( lhsItem != alternates.end() )
2030 {
2031 const PIN_ALTERNATE& lhsAlt = lhsItem->second;
2032 const PIN_ALTERNATE& rhsAlt = rhsItem->second;
2033
2034 int retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
2035
2036 if( retv )
2037 return retv;
2038
2039 if( lhsAlt.m_Type != rhsAlt.m_Type )
2040 return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
2041
2042 if( lhsAlt.m_Shape != rhsAlt.m_Shape )
2043 return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
2044
2045 ++lhsItem;
2046 ++rhsItem;
2047 }
2048
2049 return 0;
2050 }
2051};
2052
2053PIN_COMPARISON_VIEW pinComparisonView( const PIN_COMPARISON_DATA& aData )
2054{
2055 return { aData.unit, aData.bodyStyle, aData.isPrivate, aData.position, aData.number,
2056 aData.length, aData.orientation, aData.shape, aData.type, aData.hidden,
2057 aData.numberTextSize, aData.nameTextSize, aData.alternates };
2058}
2059}
2060
2061int PIN_COMPARISON_DATA::Compare( const PIN_COMPARISON_DATA& aOther, int aCompareFlags ) const
2062{
2063 return pinComparisonView( *this ).Compare( pinComparisonView( aOther ), aCompareFlags );
2064}
2065
2072
2073
2074int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
2075{
2076 // Ignore the UUID here
2077 // And the position, which we'll do after the number.
2078 int retv = SCH_ITEM::compare( aOther, aCompareFlags & ~( COMPARE_FLAGS::UUID | COMPARE_FLAGS::POSITION ) );
2079
2080 if( retv )
2081 return retv;
2082
2083 const SCH_PIN* tmp = static_cast<const SCH_PIN*>( &aOther );
2084
2085 wxCHECK( tmp, -1 );
2086
2087 if( dynamic_cast<const LIB_SYMBOL*>( GetParentSymbol() ) )
2088 {
2089 const PIN_COMPARISON_VIEW lhs{ GetUnit(), GetBodyStyle(), IsPrivate(), m_position, m_number,
2092 const PIN_COMPARISON_VIEW rhs{ tmp->GetUnit(), tmp->GetBodyStyle(), tmp->IsPrivate(), tmp->m_position,
2093 tmp->m_number, tmp->m_length, tmp->m_orientation, tmp->m_shape, tmp->m_type,
2094 tmp->m_hidden, tmp->m_numTextSize, tmp->m_nameTextSize, tmp->m_alternates };
2095 return lhs.Compare( rhs, aCompareFlags );
2096 }
2097
2098 if( m_number != tmp->m_number )
2099 {
2100 // Sort based on natural sort (same as pads in the footprint file), but don't consider
2101 // naturally-equivalent values to be equal. Run them through a second, non-natural compare.
2102
2103 // StrNumCmp: sort the same as the pads in the footprint file
2105
2106 if( retv != 0 )
2107 return retv;
2108
2109 // Don't make the mistake of conflating naturally-equivalent with equal. Run them through
2110 // a second, non-natural compare.
2111 retv = m_number.Cmp( tmp->m_number );
2112
2113 if( retv != 0 )
2114 return retv;
2115 }
2116
2117 if( m_name != tmp->m_name )
2118 {
2119 // Sort based on natural sort (same as pads in the footprint file), but don't consider
2120 // naturally-equivalent values to be equal. Run them through a second, non-natural compare.
2121
2123
2124 if( retv != 0 )
2125 return retv;
2126
2127 // Don't make the mistake of conflating naturally-equivalent with equal. Run them through
2128 // a second, non-natural compare.
2129 retv = m_name.Cmp( tmp->m_name );
2130
2131 if( retv != 0 )
2132 return retv;
2133 }
2134
2135 if( m_position.x != tmp->m_position.x )
2136 return m_position.x - tmp->m_position.x;
2137
2138 if( m_position.y != tmp->m_position.y )
2139 return m_position.y - tmp->m_position.y;
2140
2141 if( dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
2142 {
2143 if( m_libPin && !tmp->m_libPin )
2144 return 1;
2145 else if( !m_libPin && tmp->m_libPin )
2146 return -1;
2147 else if( m_libPin )
2148 retv = m_libPin->compare( *tmp->m_libPin, aCompareFlags );
2149
2150 if( retv )
2151 return retv;
2152
2153 retv = m_alt.Cmp( tmp->m_alt );
2154
2155 if( retv )
2156 return retv;
2157 }
2158
2159 return 0;
2160}
2161
2162
2163bool SCH_PIN::operator==( const SCH_ITEM& aOther ) const
2164{
2165 if( Type() != aOther.Type() )
2166 return false;
2167
2168 return *this == static_cast<const SCH_PIN&>( aOther );
2169}
2170
2171
2172bool SCH_PIN::operator==( const SCH_PIN& aPin ) const
2173{
2174 // Compare local positions below. SCH_ITEM's position compare uses global coordinates
2175 if( SCH_ITEM::compare( aPin, -1 & ~( COMPARE_FLAGS::UUID | COMPARE_FLAGS::POSITION ) ) != 0 )
2176 return false;
2177
2178 if( m_libPin && aPin.m_libPin )
2179 {
2180 // Both have a libPin; pins are children of a SCH_SYMBOL.
2181 if( !m_libPin->operator==( *aPin.m_libPin ) )
2182 return false;
2183
2184 if( m_alt != aPin.m_alt )
2185 return false;
2186 }
2187 else if( m_libPin != aPin.m_libPin )
2188 {
2189 // One has a libPin but the other doesn't.
2190 return false;
2191 }
2192 else
2193 {
2194 // Both libPins are nullptr; pins are children of a LIB_SYMBOL. Alternates are valid here.
2195 if( m_alternates != aPin.m_alternates )
2196 return false;
2197 }
2198
2199 if( GetName() != aPin.GetName() )
2200 return false;
2201
2202 if( GetNumber() != aPin.GetNumber() )
2203 return false;
2204
2205 // Don't use GetPosition(); it will return the global coordinates rather than the local ones
2206 if( m_position != aPin.m_position )
2207 return false;
2208
2209 if( GetLength() != aPin.GetLength() )
2210 return false;
2211
2212 if( GetOrientation() != aPin.GetOrientation() )
2213 return false;
2214
2215 if( GetShape() != aPin.GetShape() )
2216 return false;
2217
2218 if( GetType() != aPin.GetType() ) // Electrical type
2219 return false;
2220
2221 if( IsVisible() != aPin.IsVisible() )
2222 return false;
2223
2224 if( GetNumberTextSize() != aPin.GetNumberTextSize() )
2225 return false;
2226
2227 if( GetNameTextSize() != aPin.GetNameTextSize() )
2228 return false;
2229
2230 return true;
2231}
2232
2233
2234double SCH_PIN::Similarity( const SCH_ITEM& aOther ) const
2235{
2236 if( aOther.m_Uuid == m_Uuid )
2237 return 1.0;
2238
2239 if( aOther.Type() != SCH_PIN_T )
2240 return 0.0;
2241
2242 const SCH_PIN* other = static_cast<const SCH_PIN*>( &aOther );
2243
2244 if( m_libPin && !other->m_libPin )
2245 return 0.0;
2246 else if( !m_libPin && other->m_libPin )
2247 return 0.0;
2248 else if( m_libPin )
2249 return m_libPin->Similarity( *other->m_libPin );
2250
2251 double similarity = SimilarityBase( aOther );
2252
2253 if( m_name != other->m_name )
2254 similarity *= 0.9;
2255
2256 if( m_number != other->m_number )
2257 similarity *= 0.9;
2258
2259 if( m_position != other->m_position )
2260 similarity *= 0.9;
2261
2262 if( m_length != other->m_length )
2263 similarity *= 0.9;
2264
2265 if( m_orientation != other->m_orientation )
2266 similarity *= 0.9;
2267
2268 if( m_shape != other->m_shape )
2269 similarity *= 0.9;
2270
2271 if( m_type != other->m_type )
2272 similarity *= 0.9;
2273
2274 if( m_hidden != other->m_hidden )
2275 similarity *= 0.9;
2276
2277 if( m_numTextSize != other->m_numTextSize )
2278 similarity *= 0.9;
2279
2280 if( m_nameTextSize != other->m_nameTextSize )
2281 similarity *= 0.9;
2282
2283 if( m_alternates.size() != other->m_alternates.size() )
2284 similarity *= 0.9;
2285
2286 return similarity;
2287}
2288
2289
2290std::ostream& SCH_PIN::operator<<( std::ostream& aStream )
2291{
2292 aStream << "SCH_PIN:" << std::endl
2293 << " Name: \"" << m_name << "\"" << std::endl
2294 << " Number: \"" << m_number << "\"" << std::endl
2295 << " Position: " << m_position << std::endl
2296 << " Length: " << GetLength() << std::endl
2297 << " Orientation: " << PinOrientationName( m_orientation ) << std::endl
2298 << " Shape: " << PinShapeGetText( m_shape ) << std::endl
2299 << " Type: " << ElectricalPinTypeGetText( m_type ) << std::endl
2300 << " Name Text Size: " << GetNameTextSize() << std::endl
2301 << " Number Text Size: " << GetNumberTextSize() << std::endl;
2302
2303 return aStream;
2304}
2305
2306
2307#if defined(DEBUG)
2308
2309void SCH_PIN::Show( int nestLevel, std::ostream& os ) const
2310{
2311 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
2312 << " num=\"" << m_number.mb_str()
2313 << '"' << "/>\n";
2314}
2315
2316#endif
2317
2318
2319void SCH_PIN::CalcEdit( const VECTOR2I& aPosition )
2320{
2321 if( IsMoving() )
2322 SetPosition( aPosition );
2323}
2324
2325
2326static struct SCH_PIN_DESC
2327{
2329 {
2330 auto& pinTypeEnum = ENUM_MAP<ELECTRICAL_PINTYPE>::Instance();
2331
2332 if( pinTypeEnum.Choices().GetCount() == 0 )
2333 {
2334 pinTypeEnum.Map( ELECTRICAL_PINTYPE::PT_INPUT, _HKI( "Input" ) )
2335 .Map( ELECTRICAL_PINTYPE::PT_OUTPUT, _HKI( "Output" ) )
2336 .Map( ELECTRICAL_PINTYPE::PT_BIDI, _HKI( "Bidirectional" ) )
2337 .Map( ELECTRICAL_PINTYPE::PT_TRISTATE, _HKI( "Tri-state" ) )
2338 .Map( ELECTRICAL_PINTYPE::PT_PASSIVE, _HKI( "Passive" ) )
2339 .Map( ELECTRICAL_PINTYPE::PT_NIC, _HKI( "Free" ) )
2340 .Map( ELECTRICAL_PINTYPE::PT_UNSPECIFIED, _HKI( "Unspecified" ) )
2341 .Map( ELECTRICAL_PINTYPE::PT_POWER_IN, _HKI( "Power input" ) )
2342 .Map( ELECTRICAL_PINTYPE::PT_POWER_OUT, _HKI( "Power output" ) )
2343 .Map( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, _HKI( "Open collector" ) )
2344 .Map( ELECTRICAL_PINTYPE::PT_OPENEMITTER, _HKI( "Open emitter" ) )
2345 .Map( ELECTRICAL_PINTYPE::PT_NC, _HKI( "Unconnected" ) );
2346 }
2347
2348 auto& pinShapeEnum = ENUM_MAP<GRAPHIC_PINSHAPE>::Instance();
2349
2350 if( pinShapeEnum.Choices().GetCount() == 0 )
2351 {
2352 pinShapeEnum.Map( GRAPHIC_PINSHAPE::LINE, _HKI( "Line" ) )
2353 .Map( GRAPHIC_PINSHAPE::INVERTED, _HKI( "Inverted" ) )
2354 .Map( GRAPHIC_PINSHAPE::CLOCK, _HKI( "Clock" ) )
2355 .Map( GRAPHIC_PINSHAPE::INVERTED_CLOCK, _HKI( "Inverted clock" ) )
2356 .Map( GRAPHIC_PINSHAPE::INPUT_LOW, _HKI( "Input low" ) )
2357 .Map( GRAPHIC_PINSHAPE::CLOCK_LOW, _HKI( "Clock low" ) )
2358 .Map( GRAPHIC_PINSHAPE::OUTPUT_LOW, _HKI( "Output low" ) )
2359 .Map( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, _HKI( "Falling edge clock" ) )
2360 .Map( GRAPHIC_PINSHAPE::NONLOGIC, _HKI( "NonLogic" ) );
2361 }
2362
2363 auto& orientationEnum = ENUM_MAP<PIN_ORIENTATION>::Instance();
2364
2365 if( orientationEnum.Choices().GetCount() == 0 )
2366 {
2367 orientationEnum.Map( PIN_ORIENTATION::PIN_RIGHT, _HKI( "Right" ) )
2368 .Map( PIN_ORIENTATION::PIN_LEFT, _HKI( "Left" ) )
2369 .Map( PIN_ORIENTATION::PIN_UP, _HKI( "Up" ) )
2370 .Map( PIN_ORIENTATION::PIN_DOWN, _HKI( "Down" ) );
2371 }
2372
2373 auto isSymbolEditor =
2374 []( INSPECTABLE* aItem ) -> bool
2375 {
2376 if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aItem ) )
2377 return dynamic_cast<LIB_SYMBOL*>( pin->GetParentSymbol() ) != nullptr;
2378
2379 return false;
2380 };
2381
2386
2387 // Lock state is inherited from parent symbol (no independent locking of child items)
2388 propMgr.Mask( TYPE_HASH( SCH_PIN ), TYPE_HASH( SCH_ITEM ), _HKI( "Locked" ) );
2389
2390 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Name" ),
2392 .SetWriteableFunc( isSymbolEditor );
2393
2394 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Number" ),
2396 .SetWriteableFunc( isSymbolEditor );
2397
2398 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, ELECTRICAL_PINTYPE>( _HKI( "Electrical Type" ),
2400 .SetWriteableFunc( isSymbolEditor );
2401
2402 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, GRAPHIC_PINSHAPE>( _HKI( "Graphic Style" ),
2404 .SetWriteableFunc( isSymbolEditor );
2405
2406 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position X" ),
2408 .SetAvailableFunc( isSymbolEditor );
2409
2410 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position Y" ),
2412 .SetAvailableFunc( isSymbolEditor );
2413
2414 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, PIN_ORIENTATION>( _HKI( "Orientation" ),
2416 .SetWriteableFunc( isSymbolEditor );
2417
2418 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Length" ),
2421 .SetWriteableFunc( isSymbolEditor );
2422
2423 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Name Text Size" ),
2426 .SetAvailableFunc( isSymbolEditor );
2427
2428 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Number Text Size" ),
2431 .SetAvailableFunc( isSymbolEditor );
2432
2433 propMgr.AddProperty( new PROPERTY<SCH_PIN, bool>( _HKI( "Visible" ),
2435 .SetAvailableFunc( isSymbolEditor );
2436
2437 }
2439
2440
const char * name
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:56
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:314
static const COLOR4D WHITE
Definition color4d.h:403
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:608
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:484
void SetCustomProperties(const std::map< wxString, wxString > &aProps)
Definition eda_item.h:247
EDA_ITEM * GetParent() const
Definition eda_item.h:112
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:609
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:406
bool IsMoving() const
Definition eda_item.h:132
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
static ENUM_MAP< T > & Instance()
Definition property.h:811
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
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:144
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:442
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
std::shared_ptr< wxString > m_text
Definition color4d.h:397
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition color4d.cpp:530
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:293
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:46
wxString AsString() const
Definition kiid.cpp:264
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:114
const std::vector< ASSOCIATED_FOOTPRINT > & GetEffectiveAssociatedFootprints() const
Definition lib_symbol.h:302
const PIN_MAP_SET & GetEffectivePinMaps() const
Definition lib_symbol.h:287
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:65
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:138
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width)=0
void MoveTo(const VECTOR2I &pos)
Definition plotter.h:325
void FinishTo(const VECTOR2I &pos)
Definition plotter.h:335
RENDER_SETTINGS * RenderSettings()
Definition plotter.h:169
bool GetColorMode() const
Definition plotter.h:166
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:330
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:618
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:275
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition property.h:305
Provide class metadata.
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).
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
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
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.
bool MatchesNetName(const EDA_SEARCH_DATA &aSearchData, const SCH_SHEET_PATH *aSheet) const
Match aSearchData against the connection of this item on aSheet.
Definition sch_item.cpp:676
int m_unit
Definition sch_item.h:844
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition sch_item.cpp:91
int m_bodyStyle
Definition sch_item.h:845
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.cpp:46
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:350
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:302
int GetBodyStyle() const
Definition sch_item.h:253
bool IsLocked() const override
Definition sch_item.cpp:179
friend class LIB_SYMBOL
Definition sch_item.h:822
@ PIN_ALT_DEFS
Definition sch_item.h:760
@ PIN_VISIBILITIES
Definition sch_item.h:759
int GetUnit() const
Definition sch_item.h:243
bool IsPrivate() const
Definition sch_item.h:259
bool IsConnectivityDirty() const
Definition sch_item.h:635
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:65
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:580
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:464
virtual int compare(const SCH_ITEM &aOther, int aCompareFlags=~COMPARE_FLAGS::UNIT) const
Provide the draw object specific comparison called by the == and < operators.
Definition sch_item.cpp:935
const KIFONT::METRICS & GetFontMetrics() const
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
SCH_LAYER_ID m_layer
Definition sch_item.h:843
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:403
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition sch_pin.cpp:1600
std::ostream & operator<<(std::ostream &aStream)
Definition sch_pin.cpp:2290
void SetAlt(const wxString &aAlt)
Set the name of the alternate pin.
Definition sch_pin.cpp:563
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:1085
VECTOR2I GetLocalPosition() const
Definition sch_pin.h:317
int GetNumberTextSize() const
Definition sch_pin.cpp:885
int GetLength() const
Definition sch_pin.cpp:424
std::optional< bool > m_hidden
Definition sch_pin.h:497
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition sch_pin.cpp:631
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:1628
std::unique_ptr< PIN_LAYOUT_CACHE > m_layoutCache
The layout cache for this pin.
Definition sch_pin.h:519
void MirrorVerticallyPin(int aCenter)
Definition sch_pin.cpp:1549
void validateExtentsCache(KIFONT::FONT *aFont, int aSize, const wxString &aText, EXTENTS_CACHE *aCache) const
Definition sch_pin.cpp:1771
const BOX2I ViewBBox() const override
The view bounds of text that shows a net name must match the drawing, so this reads connectivity insi...
Definition sch_pin.cpp:1758
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:1764
const std::map< wxString, ALT > & GetAlternates() const
Definition sch_pin.h:219
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition sch_pin.cpp:2319
void SetNumber(const wxString &aNumber)
Definition sch_pin.cpp:845
std::optional< int > m_nameTextSize
Definition sch_pin.h:501
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:1434
void SetVisible(bool aVisible)
Definition sch_pin.h:134
int GetX() const
Definition sch_pin.h:321
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition sch_pin.cpp:1495
void SetX(int aX)
Definition sch_pin.h:322
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:1811
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition sch_pin.cpp:250
SCH_PIN * m_libPin
Definition sch_pin.h:486
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:730
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
Definition sch_pin.cpp:1523
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition sch_pin.h:523
PIN_ORIENTATION m_orientation
Definition sch_pin.h:494
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition sch_pin.h:113
void SetName(const wxString &aName)
Definition sch_pin.cpp:548
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:484
bool SetIsDangling(bool aIsDangling)
Definition sch_pin.cpp:600
wxString getItemDescription(ALT *aAlt) const
Definition sch_pin.cpp:1913
bool IsVisible() const
Definition sch_pin.cpp:516
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition sch_pin.cpp:1853
bool IsLocked() const override
Definition sch_pin.cpp:1859
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition sch_pin.cpp:274
std::optional< int > m_numTextSize
Definition sch_pin.h:500
VECTOR2I GetPinRoot() const
Definition sch_pin.cpp:911
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:503
ELECTRICAL_PINTYPE m_type
Definition sch_pin.h:496
PAD_RESOLUTION
Outcome of pin-to-pad resolution (issue #2282).
Definition sch_pin.h:175
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition sch_pin.cpp:1562
SCH_PIN * GetLibPin() const
Definition sch_pin.h:109
void SetPosition(const VECTOR2I &aPos) override
Definition sch_pin.h:318
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:2234
bool m_isDangling
Definition sch_pin.h:512
wxString GetElectricalTypeName() const
Definition sch_pin.cpp:477
std::vector< wxString > GetStackedPinNumbers(bool *aValid=nullptr) const
Definition sch_pin.cpp:717
std::map< wxString, ALT > m_alternates
Definition sch_pin.h:489
const wxString & GetName() const
Definition sch_pin.cpp:530
int GetStackedPinCount(bool *aValid=nullptr) const
Return the count of logical pins represented by this pin's stacked notation.
Definition sch_pin.cpp:723
bool operator==(const SCH_ITEM &aPin) const override
Definition sch_pin.cpp:2163
void SetLength(int aLength)
Definition sch_pin.h:119
bool IsDangling() const override
Definition sch_pin.cpp:591
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:1607
void MirrorHorizontally(int aCenter) override
These transforms have effect only if the pin has a LIB_SYMBOL as parent.
Definition sch_pin.cpp:1542
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition sch_pin.h:522
PIN_ORIENTATION GetOrientation() const
Definition sch_pin.cpp:389
wxString GetClass() const override
Return the class name.
Definition sch_pin.h:94
void SetNumberTextSize(int aSize)
Definition sch_pin.cpp:899
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition sch_pin.h:116
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition sch_pin.cpp:1569
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:381
bool StackedTextSideFlipped(const TRANSFORM &aTransform) const
Return true when aTransform maps the side the stacked number block is drawn on (above horizontal pins...
Definition sch_pin.cpp:1469
wxString GetCanonicalElectricalTypeName() const
Definition sch_pin.cpp:470
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:649
int GetNameTextSize() const
Definition sch_pin.cpp:859
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition sch_pin.cpp:1886
VECTOR2I m_position
Definition sch_pin.h:492
GRAPHIC_PINSHAPE m_shape
Definition sch_pin.h:495
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition sch_pin.cpp:336
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
The pin specific sort order is as follows:
Definition sch_pin.cpp:2074
const wxString & GetShownName() const
Definition sch_pin.cpp:700
PIN_ALTERNATE ALT
Definition sch_pin.h:63
void MirrorHorizontallyPin(int aCenter)
These transforms have always effects.
Definition sch_pin.cpp:1529
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:670
PIN_LAYOUT_CACHE & GetLayoutCache() const
Get the layout cache associated with this pin.
Definition sch_pin.cpp:1802
wxString m_name
Definition sch_pin.h:498
wxString m_alt
Definition sch_pin.h:502
void SetType(ELECTRICAL_PINTYPE aType)
Definition sch_pin.cpp:458
const wxString & GetBaseName() const
Get the name without any alternates.
Definition sch_pin.cpp:539
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition sch_pin.cpp:1675
PIN_COMPARISON_DATA ComparisonData() const
Definition sch_pin.cpp:2066
void SetY(int aY)
Definition sch_pin.h:324
SCH_PIN(LIB_SYMBOL *aParentSymbol)
Definition sch_pin.cpp:139
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:751
const wxString & GetShownNumber() const
Definition sch_pin.cpp:711
bool IsStacked(const SCH_PIN *aPin) const
Definition sch_pin.cpp:608
const wxString & GetNumber() const
Definition sch_pin.h:144
wxString m_number
Definition sch_pin.h:499
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_pin.cpp:1486
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_pin.h:280
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition sch_pin.cpp:297
static bool HasIdentityPad(const wxString &aPinNumber, const std::set< wxString > &aPads)
Definition sch_pin.cpp:822
wxString GetSmallestStackedPadNumber() const
Return the pin number to be used for deterministic operations such as auto‑generated net names.
Definition sch_pin.cpp:742
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition sch_pin.cpp:1686
std::optional< int > m_length
Definition sch_pin.h:493
GRAPHIC_PINSHAPE GetShape() const
Definition sch_pin.cpp:403
void PlotPinType(PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed) const
Definition sch_pin.cpp:934
int GetY() const
Definition sch_pin.h:323
bool IsPower() const
Check if the pin is either a global or local power pin.
Definition sch_pin.cpp:510
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:438
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition sch_pin.cpp:1871
void SetNameTextSize(int aSize)
Definition sch_pin.cpp:873
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:76
wxString GetCurrentSheetRef() const
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(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const override
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:60
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:163
virtual bool GetShowPinNames() const
Definition symbol.h:169
virtual bool GetShowPinNumbers() const
Definition symbol.h:175
EDA_ORIENTATION m_Angle
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().
@ FOR_NETNAME
Definition common.h:94
@ RESOLVED
Definition common.h:97
#define DEFAULT_PINNUM_SIZE
The default pin number size when creating pins(can be changed in preference menu)
#define DEFAULT_PINNAME_SIZE
The default pin name size when creating pins(can be changed in preference menu)
#define DEFAULT_PIN_LENGTH
The default pin len value when creating pins(can be changed in preference menu)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:469
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:468
@ NO_FILL
Definition eda_fill.h:30
#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.
int GetPenSizeForNormal(int aTextSize)
Definition gr_text.cpp:58
const wxChar *const traceStackedPins
Flag to enable debug output for stacked pins handling in symbol/pin code.
@ LAYER_DANGLING
Definition layer_ids.h:508
@ LAYER_PINNUM
Definition layer_ids.h:489
@ LAYER_DEVICE
Definition layer_ids.h:497
@ LAYER_PINNAM
Definition layer_ids.h:490
@ LAYER_PIN
Definition layer_ids.h:501
@ LAYER_OP_CURRENTS
Definition layer_ids.h:533
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:526
wxString RenderPinNetName(const PIN_NAME_FACT &aPin, const PIN_NAME_REFERENCE &aReference, bool aForceNoConnect)
Render a non-power pin name from unescaped values; an absent reference uses the symbol UUID.
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
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)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
#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 PinShapeGetText(GRAPHIC_PINSHAPE shape)
Definition pin_type.cpp:232
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:218
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE)
Definition pin_type.cpp:204
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition pin_type.cpp:260
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)
Macro to generate unique identifier for a type.
Definition property.h:74
#define ENUM_TO_WXANY(type)
Definition property.h:918
@ 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)
Helper macro to map type hashes to names.
wxString FormatStackedPinForDisplay(const wxString &aPinNumber, int aPinLength, int aTextSize, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Break a stacked pin number of the form "[A,B,C]" into one number per line when it is too wide to sit ...
Definition sch_pin.cpp:51
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:128
#define PIN_TEXT_MARGIN
Definition sch_pin.cpp:109
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:114
static struct SCH_PIN_DESC _SCH_PIN_DESC
wxString FormatStackedPinForDisplay(const wxString &aPinNumber, int aPinLength, int aTextSize, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Break a stacked pin number of the form "[A,B,C]" into one number per line when it is too wide to sit ...
Definition sch_pin.cpp:51
#define TARGET_PIN_RADIUS
Definition sch_pin.h:48
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, CMP_T aCaseSensitivity)
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.
@ CASE_SENSITIVE
@ CTX_NETNAME
A first-class footprint choice on a LIB_SYMBOL, tied to a named pin map.
Definition pin_map.h:159
GRAPHIC_PINSHAPE m_Shape
ELECTRICAL_PINTYPE m_Type
Owned library-pin inputs; no parent, layout cache or schematic pointers.
std::map< wxString, PIN_ALTERNATE > alternates
ELECTRICAL_PINTYPE type
PIN_ORIENTATION orientation
std::optional< int > numberTextSize
std::optional< int > nameTextSize
std::optional< int > length
GRAPHIC_PINSHAPE shape
int Compare(const PIN_COMPARISON_DATA &aOther, int aCompareFlags) const
Definition sch_pin.cpp:2061
std::optional< bool > hidden
One symbol-pin to footprint-pad mapping inside a PIN_MAP.
Definition pin_map.h:42
Per-instance override of the active pin map and a sparse delta on top.
Definition pin_map.h:200
std::vector< PIN_MAP_ENTRY > m_Edits
Definition pin_map.h:203
PIN_MAP_OVERRIDE_MODE m_Mode
Definition pin_map.h:201
KIFONT::FONT * m_Font
Definition sch_pin.h:457
@ VALUE
Field Value of part, i.e. "3.3K".
static EDA_ORIENTATION orientation(double d)
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:227
@ SCH_PIN_T
Definition typeinfo.h:149
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)