KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_symbol.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <atomic>
22
23#include <netclass.h>
24#include <api/api_enums.h>
26#include <api/api_utils.h>
27#include <schematic.h>
28#include <sch_collectors.h>
29#include <sch_commit.h>
30#include <sch_edit_frame.h>
31#include <widgets/msgpanel.h>
32#include <bitmaps.h>
33#include <common.h>
34#include <core/mirror.h>
35#include "lib_symbol.h"
36#include <pin_map.h>
37#include <sch_shape.h>
38#include <pgm_base.h>
39#include <sim/sim_model.h>
40#include <sim/spice_generator.h>
41#include <sim/sim_lib_mgr.h>
42#include <trace_helpers.h>
43#include <trigo.h>
44#include <refdes_utils.h>
45#include <wx/log.h>
47#include <sch_plotter.h>
48#include <string_utils.h>
50#include <sch_rule_area.h>
51#include <api/api_sch_utils.h>
52#include <api/schematic/schematic_types.pb.h>
53#include <project_sch.h>
58
59#include <utility>
60#include <validators.h>
61#include <properties/property.h>
64
65
66wxString SCH_SYMBOL::GetRefProp() const
67{
68 return GetBaseRef( &Schematic()->CurrentSheet() );
69}
70
71
73{
74 return GetValue( &Schematic()->CurrentSheet(), RAW_VALUE, Schematic()->GetCurrentVariant() );
75}
76
77
79{
80 return GetUnitSelection( &Schematic()->CurrentSheet() );
81}
82
83
84void SCH_SYMBOL::SetUnitProp( int aUnit )
85{
86 SetUnitSelection( &Schematic()->CurrentSheet(), aUnit );
87 SetUnit( aUnit );
88}
89
90
92{
93 return GetDNP( &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
94}
95
96
97void SCH_SYMBOL::SetDNPProp( bool aEnable )
98{
99 SetDNP( aEnable, &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
100}
101
102
104{
105 return GetExcludedFromBOM( &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
106}
107
108
110{
111 SetExcludedFromBOM( aEnable, &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
112}
113
114
116{
117 return GetExcludedFromSim( &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
118}
119
120
122{
123 SetExcludedFromSim( aEnable, &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
124}
125
126
128{
129 return GetExcludedFromBoard( &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
130}
131
132
134{
135 SetExcludedFromBoard( aEnable, &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
136}
137
138
140{
141 return GetExcludedFromPosFiles( &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
142}
143
144
146{
147 SetExcludedFromPosFiles( aEnable, &Schematic()->CurrentSheet(), Schematic()->GetCurrentVariant() );
148}
149
150
151// Stable property names and group captions for the per-object field and pin-map properties
152static const wxString PIN_MAP_GROUP = _HKI( "Pin Map" );
153static const wxString PIN_MAP_FOOTPRINT_PROP = wxS( "Pin Map Footprint" );
154static const wxString PIN_MAP_MODE_PROP = wxS( "Pin Map Mode" );
155static const wxString PIN_MAP_NAME_PROP = wxS( "Pin Map Name" );
156static const wxString PIN_MAP_TABLE_GROUP = _HKI( "Effective Pin Map" );
157static const wxString PIN_MAP_ENTRY_PREFIX = wxS( "Pin " );
158
159
166 const SCH_SHEET_PATH* aPath = nullptr,
167 const wxString& aVariant = wxEmptyString )
168{
169 const std::unique_ptr<LIB_SYMBOL>& libSymbol = aSymbol->GetLibSymbolRef();
170
171 if( !libSymbol )
172 return nullptr;
173
174 const std::vector<ASSOCIATED_FOOTPRINT>& assoc = libSymbol->GetEffectiveAssociatedFootprints();
175
176 if( assoc.empty() )
177 return nullptr;
178
179 LIB_ID fpId;
180
181 if( const SCH_FIELD* fpField = aSymbol->GetField( FIELD_T::FOOTPRINT ) )
182 fpId.Parse( fpField->GetText( aPath, aVariant ) );
183
184 for( const ASSOCIATED_FOOTPRINT& candidate : assoc )
185 {
186 if( candidate.m_FootprintLibId == fpId )
187 return &candidate;
188 }
189
190 return &assoc.front();
191}
192
193
195{
196public:
198
199 wxAny getter( const void* aObject ) const final
200 {
201 const auto* symbol = reinterpret_cast<const SCH_SYMBOL*>( aObject );
202 SCHEMATIC* schematic = symbol->Schematic();
203 return ValueForInstance( symbol, schematic ? &schematic->CurrentSheet() : nullptr,
204 schematic ? schematic->GetCurrentVariant() : wxString() );
205 }
206
207 virtual wxAny ValueForInstance( const SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH* aPath,
208 const wxString& aVariant ) const = 0;
209};
210
211
213{
214public:
215 SCH_SYMBOL_FIELD_PROPERTY( const wxString& aName ) :
217 m_name( aName )
218 {
219 SetGroup( _HKI( "Fields" ) );
220 }
221
222 size_t OwnerHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
223 size_t BaseHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
224 size_t TypeHash() const override { return TYPE_HASH( wxString ); }
225
226 void setter( void* obj, wxAny& v ) override
227 {
228 wxString value;
229
230 if( !v.GetAs( &value ) )
231 return;
232
233 SCH_SYMBOL* symbol = reinterpret_cast<SCH_SYMBOL*>( obj );
234 SCH_FIELD* field = symbol->GetField( m_name );
235
236 wxString variantName;
237 const SCH_SHEET_PATH* sheetPath = nullptr;
238
239 if( symbol->Schematic() )
240 {
241 variantName = symbol->Schematic()->GetCurrentVariant();
242 sheetPath = &symbol->Schematic()->CurrentSheet();
243 }
244
245 if( !sheetPath )
246 {
247 if( !field )
248 {
249 SCH_FIELD newField( symbol, FIELD_T::USER, m_name );
250 newField.SetText( value );
251 symbol->AddField( newField );
252 }
253 else
254 {
255 field->SetText( value );
256 }
257
258 return;
259 }
260
261 if( !field )
262 {
263 symbol->AddField( SCH_FIELD( symbol, FIELD_T::USER, m_name ) );
264 field = symbol->GetField( m_name );
265 }
266
267 field->SetText( value, sheetPath, variantName );
268 }
269
270 wxAny ValueForInstance( const SCH_SYMBOL* symbol, const SCH_SHEET_PATH* sheetPath,
271 const wxString& variantName ) const override
272 {
273 const SCH_FIELD* field = symbol->GetField( m_name );
274
275 if( !field )
276 return wxAny();
277
278 wxString text;
279
280 if( !variantName.IsEmpty() && sheetPath )
281 text = field->GetText( sheetPath, variantName );
282 else
283 text = field->GetText();
284
285 return wxAny( text );
286 }
287
288private:
289 wxString m_name;
290};
291
292
297{
298public:
304
305 size_t OwnerHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
306 size_t BaseHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
307 size_t TypeHash() const override { return TYPE_HASH( wxString ); }
308
309 bool Writeable( INSPECTABLE* aObject ) const override { return false; }
310
311 void setter( void* obj, wxAny& v ) override {}
312
313 wxAny ValueForInstance( const SCH_SYMBOL* symbol, const SCH_SHEET_PATH* sheetPath,
314 const wxString& variantName ) const override
315 {
316 if( const ASSOCIATED_FOOTPRINT* active = activeAssociatedFootprint( symbol, sheetPath, variantName ) )
317 return wxAny( active->m_FootprintLibId.Format() );
318
319 return wxAny( wxEmptyString );
320 }
321};
322
323
329{
330public:
341
342 size_t OwnerHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
343 size_t BaseHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
344 size_t TypeHash() const override { return TYPE_HASH( int ); }
345
346 static wxPGChoices BuildChoices()
347 {
348 wxPGChoices choices;
349 choices.Add( _( "Library default" ), static_cast<int>( PIN_MAP_OVERRIDE_MODE::USE_LIBRARY_DEFAULT ) );
350 choices.Add( _( "Named map" ), static_cast<int>( PIN_MAP_OVERRIDE_MODE::USE_NAMED_MAP ) );
351 choices.Add( _( "Identity" ), static_cast<int>( PIN_MAP_OVERRIDE_MODE::FORCE_IDENTITY ) );
352
353 return choices;
354 }
355
356 void setter( void* obj, wxAny& v ) override
357 {
358 int value = 0;
359
360 if( !v.GetAs( &value ) )
361 return;
362
363 SCH_SYMBOL* symbol = reinterpret_cast<SCH_SYMBOL*>( obj );
364
365 const SCH_SHEET_PATH* sheetPath = nullptr;
366 wxString variantName;
367
368 if( symbol->Schematic() )
369 {
370 sheetPath = &symbol->Schematic()->CurrentSheet();
371 variantName = symbol->Schematic()->GetCurrentVariant();
372 }
373
374 PIN_MAP_INSTANCE_OVERRIDE override = symbol->GetPinMapOverride( sheetPath, variantName );
375 override.m_Mode = static_cast<PIN_MAP_OVERRIDE_MODE>( value );
376
377 // The active-map name is meaningful only in named-map mode; seed it from
378 // the symbol's active associated footprint when switching to named-map
379 // mode and no name has been chosen yet.
380 if( override.m_Mode == PIN_MAP_OVERRIDE_MODE::USE_NAMED_MAP && override.m_ActiveMapName.IsEmpty() )
381 {
382 if( const ASSOCIATED_FOOTPRINT* active = activeAssociatedFootprint( symbol ) )
383 override.m_ActiveMapName = active->m_MapName;
384 }
385
386 symbol->SetPinMapOverride( override, sheetPath, variantName );
387 }
388
389 wxAny ValueForInstance( const SCH_SYMBOL* symbol, const SCH_SHEET_PATH* sheetPath,
390 const wxString& variantName ) const override
391 {
392 PIN_MAP_INSTANCE_OVERRIDE override = symbol->GetPinMapOverride( sheetPath, variantName );
393
394 switch( override.m_Mode )
395 {
398 case PIN_MAP_OVERRIDE_MODE::FORCE_IDENTITY: return wxAny( static_cast<int>( override.m_Mode ) );
399
400 default: return wxAny( static_cast<int>( PIN_MAP_OVERRIDE_MODE::USE_LIBRARY_DEFAULT ) );
401 }
402 }
403};
404
405
407{
408public:
411 {
414 []( INSPECTABLE* aObject )
415 {
416 const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( aObject );
417
418 return symbol && SCH_SYMBOL_PIN_MAP_NAME_PROPERTY::MapNames( symbol ).size() > 1;
419 } );
421 []( INSPECTABLE* aObject ) -> wxPGChoices
422 {
423 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( aObject ) )
425
426 return wxPGChoices();
427 } );
428 }
429
430 size_t OwnerHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
431 size_t BaseHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
432 size_t TypeHash() const override { return TYPE_HASH( int ); }
433
434 static std::vector<wxString> MapNames( const SCH_SYMBOL* aSymbol )
435 {
436 std::vector<wxString> names;
437
438 if( const std::unique_ptr<LIB_SYMBOL>& libSymbol = aSymbol->GetLibSymbolRef() )
439 {
440 for( const PIN_MAP& map : libSymbol->GetEffectivePinMaps().GetAll() )
441 names.push_back( map.GetName() );
442 }
443
444 return names;
445 }
446
447 static wxPGChoices BuildChoices( const SCH_SYMBOL* aSymbol )
448 {
449 wxPGChoices choices;
450 const std::vector<wxString> names = MapNames( aSymbol );
451
452 for( size_t ii = 0; ii < names.size(); ++ii )
453 choices.Add( names[ii], (int) ii );
454
455 return choices;
456 }
457
458 void setter( void* obj, wxAny& v ) override
459 {
460 int value = 0;
461
462 if( !v.GetAs( &value ) )
463 return;
464
465 SCH_SYMBOL* symbol = reinterpret_cast<SCH_SYMBOL*>( obj );
466 const std::vector<wxString> names = MapNames( symbol );
467
468 if( value < 0 || value >= (int) names.size() )
469 return;
470
471 const SCH_SHEET_PATH* sheetPath = nullptr;
472 wxString variantName;
473
474 if( symbol->Schematic() )
475 {
476 sheetPath = &symbol->Schematic()->CurrentSheet();
477 variantName = symbol->Schematic()->GetCurrentVariant();
478 }
479
480 PIN_MAP_INSTANCE_OVERRIDE override = symbol->GetPinMapOverride( sheetPath, variantName );
482 override.m_ActiveMapName = names[value];
483 symbol->SetPinMapOverride( override, sheetPath, variantName );
484 }
485
486 wxAny ValueForInstance( const SCH_SYMBOL* symbol, const SCH_SHEET_PATH* sheetPath,
487 const wxString& variantName ) const override
488 {
489 PIN_MAP_INSTANCE_OVERRIDE override = symbol->GetPinMapOverride( sheetPath, variantName );
490
491 wxString active;
492
493 if( override.m_Mode == PIN_MAP_OVERRIDE_MODE::USE_NAMED_MAP )
494 active = override.m_ActiveMapName;
495
496 const std::vector<wxString> names = MapNames( symbol );
497
498 if( std::find( names.begin(), names.end(), active ) == names.end() )
499 {
500 if( const ASSOCIATED_FOOTPRINT* fp = activeAssociatedFootprint( symbol, sheetPath, variantName ) )
501 active = fp->m_MapName;
502 }
503
504 for( size_t ii = 0; ii < names.size(); ++ii )
505 {
506 if( names[ii] == active )
507 return wxAny( (int) ii );
508 }
509
510 return wxAny( 0 );
511 }
512};
513
514
519{
520public:
521 SCH_SYMBOL_PIN_MAP_ENTRY_PROPERTY( const wxString& aName, const wxString& aPinNumber ) :
523 m_pinNumber( aPinNumber )
524 {
526 }
527
528 size_t OwnerHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
529 size_t BaseHash() const override { return TYPE_HASH( SCH_SYMBOL ); }
530 size_t TypeHash() const override { return TYPE_HASH( wxString ); }
531
532 bool Writeable( INSPECTABLE* aObject ) const override { return false; }
533
534 void setter( void* obj, wxAny& v ) override {}
535
536 wxAny ValueForInstance( const SCH_SYMBOL* symbol, const SCH_SHEET_PATH* sheetPath,
537 const wxString& variantName ) const override
538 {
539 if( !sheetPath )
540 return wxAny( m_pinNumber );
541
542 for( const SCH_PIN* pin : symbol->GetPins( sheetPath ) )
543 {
544 std::vector<wxString> logical = pin->GetStackedPinNumbers();
545
546 if( std::find( logical.begin(), logical.end(), m_pinNumber ) == logical.end() )
547 continue;
548
549 wxString pad = pin->GetEffectivePadNumber( *sheetPath, variantName );
550
551 if( pad == m_pinNumber )
552 return wxAny( wxString::Format( _( "%s (identity)" ), pad ) );
553
554 return wxAny( pad );
555 }
556
557 return wxAny( m_pinNumber );
558 }
559
560private:
561 wxString m_pinNumber;
562};
563
564
565std::unordered_map<TRANSFORM, int> SCH_SYMBOL::s_transformToOrientationCache;
566
567
572std::string toUTFTildaText( const wxString& txt )
573{
574 std::string ret = TO_UTF8( txt );
575
576 for( char& c : ret )
577 {
578 if( (unsigned char) c <= ' ' )
579 c = '~';
580 }
581
582 return ret;
583}
584
585
587 SYMBOL( nullptr, SCH_SYMBOL_T )
588{
589 Init( VECTOR2I( 0, 0 ) );
591 m_signalName.clear();
592}
593
594
595SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId, const SCH_SHEET_PATH* aSheet, int aUnit,
596 int aBodyStyle, const VECTOR2I& aPosition, EDA_ITEM* aParent ) :
597 SYMBOL( aParent, SCH_SYMBOL_T )
598{
599 Init( aPosition );
600
601 m_unit = aUnit;
602 m_bodyStyle = aBodyStyle;
603 m_lib_id = aLibId;
604
605 std::unique_ptr<LIB_SYMBOL> part;
606
607 part = aSymbol.Flatten();
608 part->SetParent();
609 SetLibSymbol( part.release() );
610
611 // Copy fields from the library symbol
612 UpdateFields( aSheet, true, /* update style */
613 false, /* update ref */
614 false, /* update other fields */
615 true, /* reset ref */
616 true /* reset other fields */ );
617
618 m_prefix = UTIL::GetRefDesPrefix( m_part->GetReferenceField().GetText() );
619
620 if( aSheet )
622
623 // Inherit the include in bill of materials and board netlist settings from flattened
624 // library symbol.
625 m_excludedFromSim = m_part->GetExcludedFromSim();
626 m_excludedFromBOM = m_part->GetExcludedFromBOM();
627 m_excludedFromBoard = m_part->GetExcludedFromBoard();
628 m_excludedFromPosFiles = m_part->GetExcludedFromPosFiles();
630 m_signalName.clear();
631}
632
633
634SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const SCH_SHEET_PATH* aSheet, const PICKED_SYMBOL& aSel,
635 const VECTOR2I& aPosition, EDA_ITEM* aParent ) :
636 SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.BodyStyle, aPosition, aParent )
637{
638 // Set any fields that were modified as part of the symbol selection
639 for( const auto& [fieldId, fieldValue] : aSel.Fields )
640 {
641 if( fieldId == FIELD_T::REFERENCE )
642 SetRef( aSheet, fieldValue );
643 else if( SCH_FIELD* field = GetField( fieldId ) )
644 field->SetText( fieldValue );
645 }
646}
647
648
650 SYMBOL( aSymbol )
651{
652 m_parent = aSymbol.m_parent;
653 m_pos = aSymbol.m_pos;
654 m_unit = aSymbol.m_unit;
655 m_bodyStyle = aSymbol.m_bodyStyle;
656 m_lib_id = aSymbol.m_lib_id;
657 m_doNetlist = aSymbol.m_doNetlist;
658 m_DNP = aSymbol.m_DNP;
659
660 const_cast<KIID&>( m_Uuid ) = aSymbol.m_Uuid;
661
662 m_transform = aSymbol.m_transform;
663 m_prefix = aSymbol.m_prefix;
664 m_instances = aSymbol.m_instances;
667 m_signalName = aSymbol.m_signalName;
668
669 {
670 m_fields = aSymbol.m_fields; // std::vector's operator=()
671
672 // Re-parent the fields, which before this had aSymbol as parent
673 for( SCH_FIELD& field : m_fields )
674 field.SetParent( this );
675 }
676
677 {
678 m_pins.clear();
679
680 // Copy (and re-parent) the pins
681 for( const std::unique_ptr<SCH_PIN>& pin : aSymbol.m_pins )
682 {
683 m_pins.emplace_back( std::make_unique<SCH_PIN>( *pin ) );
684 m_pins.back()->SetParent( this );
685 }
686 }
687
688 if( aSymbol.m_part )
689 {
690 m_part = std::make_unique<LIB_SYMBOL>( *aSymbol.m_part );
691 updatePins();
692 }
693
697}
698
699
703
704
706{
707 const std::unique_ptr<LIB_SYMBOL>& libSymbol = GetLibSymbolRef();
708
709 return libSymbol && !libSymbol->GetEffectiveAssociatedFootprints().empty();
710}
711
712
713std::vector<PROPERTY_BASE*> SCH_SYMBOL::GetDynamicProperties() const
714{
715 return GetDynamicProperties( Schematic() ? &Schematic()->CurrentSheet() : nullptr );
716}
717
718
719std::vector<PROPERTY_BASE*> SCH_SYMBOL::GetDynamicProperties( const SCH_SHEET_PATH* aPath ) const
720{
721 std::vector<PROPERTY_BASE*> props;
722
723 auto getOrCreateFieldProperty =
724 [&]( const wxString& aName )
725 {
726 auto it = m_fieldPropsStorageCache.find( aName );
727
728 if( it == m_fieldPropsStorageCache.end() )
729 {
730 auto prop = std::make_unique<SCH_SYMBOL_FIELD_PROPERTY>( aName );
731 it = m_fieldPropsStorageCache.emplace( aName, std::move( prop ) ).first;
732 }
733
734 return it->second.get();
735 };
736
737 auto getOrCreatePinMapProperty =
738 [&]( const wxString& aName, const std::function<std::unique_ptr<PROPERTY_BASE>()>& aCreator )
739 {
740 auto it = m_pinMapPropsStorageCache.find( aName );
741
742 if( it == m_pinMapPropsStorageCache.end() )
743 it = m_pinMapPropsStorageCache.emplace( aName, aCreator() ).first;
744
745 return it->second.get();
746 };
747
748 for( const SCH_FIELD& field : GetFields() )
749 {
750 if( !field.IsMandatory() )
751 continue;
752
753 if( field.IsPrivate() )
754 continue;
755
756 const wxString& name = field.GetUntranslatedName();
757
758 if( PROPERTY_MANAGER::Instance().GetProperty( TYPE_HASH( SCH_SYMBOL ), name ) )
759 continue;
760
761 props.push_back( getOrCreateFieldProperty( name ) );
762 }
763
764 std::vector<const SCH_FIELD*> userFields;
765
766 for( const SCH_FIELD& field : GetFields() )
767 {
768 if( field.IsMandatory() || field.IsPrivate() )
769 continue;
770
771 userFields.push_back( &field );
772 }
773
774 std::ranges::sort( userFields,
775 []( const SCH_FIELD* a, const SCH_FIELD* b )
776 {
777 return a->GetUntranslatedName().CmpNoCase( b->GetUntranslatedName() ) < 0;
778 } );
779
780 for( const SCH_FIELD* field : userFields )
781 {
782 const wxString& name = field->GetUntranslatedName();
783 props.push_back( getOrCreateFieldProperty( name ) );
784 }
785
787 props.push_back( prop );
788
789 // Pin Map group: only meaningful when the symbol carries at least one effective associated footprint.
791 {
792 props.push_back( getOrCreatePinMapProperty( PIN_MAP_FOOTPRINT_PROP,
793 []()
794 {
795 return std::make_unique<SCH_SYMBOL_PIN_MAP_FOOTPRINT_PROPERTY>();
796 } ) );
797 props.push_back( getOrCreatePinMapProperty( PIN_MAP_MODE_PROP,
798 []()
799 {
800 return std::make_unique<SCH_SYMBOL_PIN_MAP_MODE_PROPERTY>();
801 } ) );
802 props.push_back( getOrCreatePinMapProperty( PIN_MAP_NAME_PROP,
803 []()
804 {
805 return std::make_unique<SCH_SYMBOL_PIN_MAP_NAME_PROPERTY>();
806 } ) );
807
808 // One read-only row per symbol pin under a collapsible group, showing
809 // the effective pad each pin resolves to.
810 if( aPath )
811 {
812 for( const SCH_PIN* pin : GetPins( aPath ) )
813 {
814 for( const wxString& number : pin->GetStackedPinNumbers() )
815 {
816 if( number.IsEmpty() )
817 continue;
818
819 const wxString propName = PIN_MAP_ENTRY_PREFIX + number;
820
821 props.push_back( getOrCreatePinMapProperty( propName,
822 [&]()
823 {
824 return std::make_unique<SCH_SYMBOL_PIN_MAP_ENTRY_PROPERTY>( propName, number );
825 } ) );
826 }
827 }
828 }
829 }
830
831 return props;
832}
833
834
835void SCH_SYMBOL::Init( const VECTOR2I& pos )
836{
838 m_pos = pos;
839 m_unit = 1; // In multi unit chip - which unit to draw.
840 m_bodyStyle = BODY_STYLE::BASE; // De Morgan Handling
841
842 // The rotation/mirror transformation matrix. pos normal
844
845 auto addField =
846 [&]( FIELD_T id, SCH_LAYER_ID layer )
847 {
848 m_fields.emplace_back( this, id, GetDefaultFieldName( id, UNTRANSLATED ) );
849 m_fields.back().SetTextPos( pos );
850 m_fields.back().SetLayer( layer );
851 };
852
853 // construct only the mandatory fields
855 addField( FIELD_T::VALUE, LAYER_VALUEPART );
856 addField( FIELD_T::FOOTPRINT, LAYER_FIELDS );
857 addField( FIELD_T::DATASHEET, LAYER_FIELDS );
859
860 m_prefix = wxString( wxT( "U" ) );
861 m_doNetlist = true;
863 m_signalName.clear();
864}
865
866
868{
869 return new SCH_SYMBOL( *this );
870}
871
872
873void SCH_SYMBOL::Serialize( google::protobuf::Any& aContainer ) const
874{
875 kiapi::schematic::types::SchematicSymbolInstance symbol;
876 Serialize( symbol );
877
878 if( !aContainer.PackFrom( symbol ) )
879 wxFAIL_MSG( wxT( "Failed to pack SCH_SYMBOL" ) );
880}
881
882
883void SCH_SYMBOL::Serialize( kiapi::schematic::types::SchematicSymbolInstance& aSymbol ) const
884{
885 using namespace kiapi::common;
886 using namespace kiapi::schematic::types;
887
888 aSymbol.mutable_id()->set_value( m_Uuid.AsStdString() );
889 PackVector2( *aSymbol.mutable_position(), GetPosition(), schIUScale );
890 aSymbol.set_locked( IsLocked() ? types::LockedState::LS_LOCKED : types::LockedState::LS_UNLOCKED );
891 aSymbol.set_fields_autoplaced( GetFieldsAutoplaced() != AUTOPLACE_NONE );
892
893 if( !UseLibIdLookup() )
894 {
895 LIB_ID id;
897 PackLibId( aSymbol.mutable_lib_id(), id );
898 }
899
901
902 SchematicSymbolTransform* transform = aSymbol.mutable_transform();
903 transform->set_orientation(
905 transform->set_mirror_x( GetMirrorX() );
906 transform->set_mirror_y( GetMirrorY() );
907
908 if( GetBodyStyleCount() > 1 )
909 aSymbol.mutable_body_style()->set_style( GetBodyStyle() );
910
911 GetField( FIELD_T::REFERENCE )->Serialize( *aSymbol.mutable_reference_field(), schIUScale );
912 GetField( FIELD_T::VALUE )->Serialize( *aSymbol.mutable_value_field(), schIUScale );
913 GetField( FIELD_T::FOOTPRINT )->Serialize( *aSymbol.mutable_footprint_field(), schIUScale );
914 GetField( FIELD_T::DATASHEET )->Serialize( *aSymbol.mutable_datasheet_field(), schIUScale );
915 GetField( FIELD_T::DESCRIPTION )->Serialize( *aSymbol.mutable_description_field(), schIUScale );
916
917 for( const SCH_FIELD& field : GetFields() )
918 {
919 if( field.IsMandatory() )
920 continue;
921
922 field.Serialize( *aSymbol.add_user_fields(), schIUScale );
923 }
924
925 if( m_part )
926 m_part->Serialize( *aSymbol.mutable_definition(), /* aSkipPins = */ true );
927
928 aSymbol.set_show_pin_names( GetShowPinNames() );
929 aSymbol.set_show_pin_numbers( GetShowPinNumbers() );
930
931 PackDistance( *aSymbol.mutable_pin_name_offset(), GetPinNameOffset(), schIUScale );
932
933 kiapi::common::PackCustomProperties( aSymbol.mutable_custom_properties(), *this );
934}
935
936
937bool SCH_SYMBOL::Deserialize( const google::protobuf::Any& aContainer )
938{
939 kiapi::schematic::types::SchematicSymbolInstance symbol;
940
941 if( !aContainer.UnpackTo( &symbol ) )
942 return false;
943
944 return Deserialize( symbol );
945}
946
947
948bool SCH_SYMBOL::Deserialize( const kiapi::schematic::types::SchematicSymbolInstance& aSymbol )
949{
950 using namespace kiapi::common;
951 using namespace kiapi::common::types;
952 using namespace kiapi::schematic::types;
953
954 // Published rows and the item index hold this identity and its pins, so they must not outlive the change
955 if( SCH_SCREEN* screen = GetParentScreen() )
956 screen->BumpConnectivityRevision();
957
958 const_cast<::KIID&>( m_Uuid ) = ::KIID( aSymbol.id().value() );
959 SetPosition( UnpackVector2( aSymbol.position(), schIUScale ) );
960 SetLocked( aSymbol.locked() == LockedState::LS_LOCKED );
961 SetFieldsAutoplaced( aSymbol.fields_autoplaced() ? AUTOPLACE_AUTO : AUTOPLACE_NONE );
962 kiapi::common::UnpackCustomProperties( aSymbol.custom_properties(), *this );
963
964 if( aSymbol.has_lib_id() )
965 SetSchSymbolLibraryName( UnpackLibId( aSymbol.lib_id() ).Format() );
966
968 SetOrientationProp( FromProtoEnum<SYMBOL_ORIENTATION_PROP>( aSymbol.transform().orientation() ) );
969 SetMirrorX( aSymbol.transform().mirror_x() );
970 SetMirrorY( aSymbol.transform().mirror_y() );
971
972 // Generally clients should not send symbols without definitions, but if they do as an update for
973 // an existing symbol, it's better to skip deserialization than delete the existing definition,
974 // especially since definitions are cached separately
975 const bool haveDefinition = aSymbol.has_definition();
976
977 std::unordered_map<::KIID, wxString> pinAltMap;
978
979 if( haveDefinition )
980 {
981 const SchematicSymbol& def = aSymbol.definition();
982
983 LIB_ID libId = UnpackLibId( def.id() );
984 m_lib_id = libId;
985
986 for( const SchematicSymbolChild& child : def.items() )
987 {
988 if( TypeNameFromAny( child.item() ) != std::optional<KICAD_T>( SCH_PIN_T ) )
989 continue;
990
991 SchematicPin pinProto;
992
993 if( child.item().UnpackTo( &pinProto ) && pinProto.has_active_alternate() )
994 pinAltMap[::KIID( pinProto.id().value() )] = wxString::FromUTF8( pinProto.active_alternate() );
995 }
996
997 LIB_SYMBOL* libSymbol = new LIB_SYMBOL( libId.GetLibItemName() );
998
999 if( !libSymbol->Deserialize( def ) )
1000 {
1001 delete libSymbol;
1002 return false;
1003 }
1004
1005 SetLibSymbol( libSymbol );
1006 }
1007
1008 if( aSymbol.has_body_style() )
1009 SetBodyStyle( aSymbol.body_style().style() );
1010
1011 GetField( FIELD_T::REFERENCE )->Deserialize( aSymbol.reference_field(), schIUScale );
1012 GetField( FIELD_T::VALUE )->Deserialize( aSymbol.value_field(), schIUScale );
1013 GetField( FIELD_T::FOOTPRINT )->Deserialize( aSymbol.footprint_field(), schIUScale );
1014 GetField( FIELD_T::DATASHEET )->Deserialize( aSymbol.datasheet_field(), schIUScale );
1015 GetField( FIELD_T::DESCRIPTION )->Deserialize( aSymbol.description_field(), schIUScale );
1016
1017 std::set<wxString> incoming;
1018
1019 for( const SchematicField& fieldProto : aSymbol.user_fields() )
1020 {
1021 wxString name = wxString::FromUTF8( fieldProto.name() );
1022 SCH_FIELD* existing = GetField( name );
1023
1024 // Don't duplicate existing mandatory fields.
1025 if( existing && existing->IsMandatory() )
1026 continue;
1027
1028 incoming.insert( name );
1029
1030 if( existing )
1031 existing->Deserialize( fieldProto, schIUScale );
1032 else
1033 AddField( SCH_FIELD( this, FIELD_T::USER, name ) )->Deserialize( fieldProto, schIUScale );
1034 }
1035
1036 std::vector<wxString> toRemove;
1037
1038 for( const SCH_FIELD& field : GetFields() )
1039 {
1040 if( !field.IsMandatory() && !incoming.count( field.GetName( false ) ) )
1041 toRemove.push_back( field.GetName( false ) );
1042 }
1043
1044 for( const wxString& name : toRemove )
1045 RemoveField( name );
1046
1047 if( aSymbol.has_show_pin_names() )
1048 SetShowPinNames( aSymbol.show_pin_names() );
1049
1050 if( aSymbol.has_show_pin_numbers() )
1051 SetShowPinNumbers( aSymbol.show_pin_numbers() );
1052
1053 if( aSymbol.has_pin_name_offset() )
1054 SetPinNameOffset( UnpackDistance( aSymbol.pin_name_offset(), schIUScale ) );
1055
1056 // The proto is storing a single pin struct that has the UUID and alternate selection
1057 // as well as the library pin definition. Deserializing the pin will have set up most
1058 // of this, but we want to make sure that the UUIDs of the instance pins round-trip
1059 // so we have to set them up in advance so that UpdatePins links them up with the
1060 // lib pins, and then we need to set the alternates for pins if applicable
1061
1062 if( haveDefinition )
1063 {
1064 m_pins.clear();
1065
1066 for( SCH_PIN* pin : GetAllLibPins() )
1067 {
1068 m_pins.emplace_back( std::make_unique<SCH_PIN>( *pin ) );
1069 m_pins.back()->SetParent( this );
1070 const_cast<::KIID&>( m_pins.back()->m_Uuid ) = pin->m_Uuid;
1071 }
1072
1073 UpdatePins();
1074
1076 {
1077 if( pinAltMap.contains( pin->m_Uuid ) )
1078 pin->SetAlt( pinAltMap.at( pin->m_Uuid ) );
1079 }
1080 }
1081
1082 return true;
1083}
1084
1085
1087{
1088 return m_part == nullptr;
1089}
1090
1091
1093{
1094 // If a symbol's anchor is not grid-aligned to its pins then moving from the anchor is
1095 // going to end up moving the symbol's pins off-grid.
1096
1097 // The minimal grid size allowed to place a pin is 25 mils
1098 const int min_grid_size = schIUScale.MilsToIU( 25 );
1099
1100 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
1101 {
1102 if( ( ( pin->GetPosition().x - m_pos.x ) % min_grid_size ) != 0 )
1103 return false;
1104
1105 if( ( ( pin->GetPosition().y - m_pos.y ) % min_grid_size ) != 0 )
1106 return false;
1107 }
1108
1109 return true;
1110}
1111
1112
1113void SCH_SYMBOL::SetLibId( const LIB_ID& aLibId )
1114{
1115 m_lib_id = aLibId;
1117}
1118
1119
1121{
1122 if( !m_schLibSymbolName.IsEmpty() )
1123 return m_schLibSymbolName;
1124 else
1125 return m_lib_id.Format();
1126}
1127
1128
1130{
1131 wxCHECK2( !aLibSymbol || aLibSymbol->IsRoot(), aLibSymbol = nullptr );
1132
1133 m_part.reset( aLibSymbol );
1134
1135 // Library content changed, so cached flattened alternates may be stale.
1136 m_variantSymbolCache.clear();
1137
1138 // We've just reset the library symbol, so the lib_pins, which were just
1139 // pointers to the old symbol, need to be cleared.
1140 for( std::unique_ptr<SCH_PIN>& pin : m_pins )
1141 pin->SetLibPin( nullptr );
1142
1143 UpdatePins();
1144}
1145
1146
1148{
1149 if( m_part )
1150 return m_part->GetDescription();
1151
1152 return wxEmptyString;
1153}
1154
1155
1156wxString SCH_SYMBOL::GetShownDescription( RESOLUTION_CONTEXT aContext, int aDepth ) const
1157{
1158 if( m_part )
1159 return m_part->GetShownDescription( aContext, aDepth );
1160
1161 return wxEmptyString;
1162}
1163
1164
1166{
1167 if( m_part )
1168 return m_part->GetKeyWords();
1169
1170 return wxEmptyString;
1171}
1172
1173
1174wxString SCH_SYMBOL::GetShownKeyWords( RESOLUTION_CONTEXT aContext, int aDepth ) const
1175{
1176 if( m_part )
1177 return m_part->GetShownKeyWords( aContext, aDepth );
1178
1179 return wxEmptyString;
1180}
1181
1182
1184{
1185 if( m_part )
1186 return m_part->GetDatasheetField().GetText();
1187
1188 return wxEmptyString;
1189}
1190
1191
1193{
1194 if( SCH_SCREEN* screen = GetParentScreen() )
1195 screen->BumpConnectivityRevision();
1196
1197 updatePins();
1198}
1199
1200
1202{
1203 std::map<wxString, wxString> altPinMap;
1204 std::map<wxString, SCH_PIN::ALT> altPinDefs;
1205 std::map<wxString, std::vector<SCH_PIN*>> pinUuidMap;
1206 std::set<SCH_PIN*> unassignedSchPins;
1207 std::vector<SCH_PIN*> unassignedLibPins;
1208
1209 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
1210 {
1211 // Saved order keeps duplicate-number identities independent of allocation order.
1212 pinUuidMap[pin->GetNumber()].push_back( pin.get() );
1213
1214 unassignedSchPins.insert( pin.get() );
1215
1216 if( !pin->GetAlt().IsEmpty() )
1217 {
1218 altPinMap[pin->GetNumber()] = pin->GetAlt();
1219 auto altDefIt = pin->GetAlternates().find( pin->GetAlt() );
1220
1221 if( altDefIt != pin->GetAlternates().end() )
1222 altPinDefs[pin->GetNumber()] = altDefIt->second;
1223 }
1224
1225 pin->SetLibPin( nullptr );
1226 }
1227
1228 m_pinMap.clear();
1229
1230 if( !m_part )
1231 return;
1232
1233 // NB: Don't filter by unit: this data-structure is used for all instances,
1234 // some of which might have different units.
1235 for( SCH_PIN* libPin : m_part->GetGraphicalPins( ALL_UNITS, m_bodyStyle ) )
1236 {
1237 SCH_PIN* pin = nullptr;
1238
1239 auto ii = pinUuidMap.find( libPin->GetNumber() );
1240
1241 if( ii == pinUuidMap.end() || ii->second.empty() )
1242 {
1243 unassignedLibPins.push_back( libPin );
1244 continue;
1245 }
1246
1247 auto it = ii->second.begin();
1248 pin = *it;
1249 ii->second.erase( it );
1250 pin->GetAlternates() = libPin->GetAlternates();
1251 pin->SetLibPin( libPin );
1252 pin->SetCustomProperties( libPin->GetCustomProperties() );
1253 pin->SetPosition( libPin->GetPosition() );
1254 pin->SetUnit( libPin->GetUnit() );
1255 pin->SetBodyStyle( libPin->GetBodyStyle() );
1256
1257 unassignedSchPins.erase( pin );
1258
1259 auto iii = altPinMap.find( libPin->GetNumber() );
1260
1261 if( iii != altPinMap.end() )
1262 {
1263 wxString altName = iii->second;
1264
1265 if( pin->GetAlternates().find( altName ) == pin->GetAlternates().end() )
1266 {
1267 auto defIt = altPinDefs.find( libPin->GetNumber() );
1268
1269 if( defIt != altPinDefs.end() )
1270 {
1271 for( const auto& [name, alt] : pin->GetAlternates() )
1272 {
1273 if( alt.m_Shape == defIt->second.m_Shape && alt.m_Type == defIt->second.m_Type )
1274 {
1275 altName = name;
1276 break;
1277 }
1278 }
1279 }
1280 }
1281
1282 pin->SetAlt( altName );
1283 }
1284
1285 m_pinMap[libPin] = pin;
1286 }
1287
1288 // Add any pins that were not found in the symbol
1289 size_t nextUnassigned = 0;
1290
1291 for( SCH_PIN* libPin : unassignedLibPins )
1292 {
1293 SCH_PIN* pin = nullptr;
1294
1295 // First try to re-use an existing pin
1296 if( !unassignedSchPins.empty() )
1297 {
1298 while( nextUnassigned < m_pins.size()
1299 && !unassignedSchPins.contains( m_pins[nextUnassigned].get() ) )
1300 {
1301 ++nextUnassigned;
1302 }
1303
1304 pin = m_pins.at( nextUnassigned++ ).get();
1305 unassignedSchPins.erase( pin );
1306 }
1307 else
1308 {
1309 // This is a pin that was not found in the symbol, so create a new one.
1310 pin = m_pins.emplace_back( std::make_unique<SCH_PIN>( SCH_PIN( this, libPin ) ) ).get();
1311 }
1312
1313 m_pinMap[libPin] = pin;
1314 pin->GetAlternates() = libPin->GetAlternates();
1315 pin->SetLibPin( libPin );
1316 pin->SetPosition( libPin->GetPosition() );
1317 pin->SetUnit( libPin->GetUnit() );
1318 pin->SetBodyStyle( libPin->GetBodyStyle() );
1319 pin->SetNumber( libPin->GetNumber() );
1320
1321 auto iii = altPinMap.find( libPin->GetNumber() );
1322
1323 if( iii != altPinMap.end() )
1324 {
1325 wxString altName = iii->second;
1326
1327 if( pin->GetAlternates().find( altName ) == pin->GetAlternates().end() )
1328 {
1329 auto defIt = altPinDefs.find( libPin->GetNumber() );
1330
1331 if( defIt != altPinDefs.end() )
1332 {
1333 for( const auto& [name, alt] : pin->GetAlternates() )
1334 {
1335 if( alt.m_Shape == defIt->second.m_Shape && alt.m_Type == defIt->second.m_Type )
1336 {
1337 altName = name;
1338 break;
1339 }
1340 }
1341 }
1342 }
1343
1344 pin->SetAlt( altName );
1345 }
1346 }
1347
1348 // If we have any pins left in the symbol that were not found in the library, remove them.
1349 for( auto it1 = m_pins.begin(); it1 != m_pins.end() && !unassignedSchPins.empty(); )
1350 {
1351 auto it2 = unassignedSchPins.find( it1->get() );
1352
1353 if( it2 != unassignedSchPins.end() )
1354 {
1355 it1 = m_pins.erase( it1 );
1356 unassignedSchPins.erase( it2 );
1357 }
1358 else
1359 {
1360 ++it1;
1361 }
1362 }
1363
1364 // If the symbol is selected, then its pins are selected.
1365 if( IsSelected() )
1366 {
1367 for( std::unique_ptr<SCH_PIN>& pin : m_pins )
1368 pin->SetSelected();
1369 }
1370}
1371
1372
1373void SCH_SYMBOL::SetBodyStyle( int aBodyStyle )
1374{
1375 if( aBodyStyle != m_bodyStyle )
1376 {
1377 m_bodyStyle = aBodyStyle;
1378
1379 // The body style may have a different pin layout so the update the pin map.
1380 UpdatePins();
1381 }
1382}
1383
1384
1386{
1387 if( m_part )
1388 return m_part->GetUnitCount();
1389
1390 return 0;
1391}
1392
1393
1395{
1396 if( m_part )
1397 return m_part->GetBodyStyleCount();
1398
1399 return 0;
1400}
1401
1402
1404{
1405 if( m_part )
1406 return m_part->HasDeMorganBodyStyles();
1407
1408 return false;
1409}
1410
1411
1412wxString SCH_SYMBOL::GetUnitDisplayName( int aUnit, bool aLabel ) const
1413{
1414 if( m_part )
1415 return m_part->GetUnitDisplayName( aUnit, aLabel );
1416 else if( aLabel )
1417 return wxString::Format( _( "Unit %s" ), SubReference( aUnit ) );
1418 else
1419 return SubReference( aUnit );
1420}
1421
1422
1423wxString SCH_SYMBOL::GetBodyStyleDescription( int aBodyStyle, bool aLabel ) const
1424{
1425 if( m_part )
1426 return m_part->GetBodyStyleDescription( aBodyStyle, aLabel );
1427 else
1428 return wxT( "?" );
1429}
1430
1431
1432bool SCH_SYMBOL::GetInstance( SCH_SYMBOL_INSTANCE& aInstance, const KIID_PATH& aSheetPath, bool aTestFromEnd ) const
1433{
1434 if( !aTestFromEnd )
1435 {
1436 auto it = m_instancePathIndex.find( aSheetPath );
1437
1438 if( it != m_instancePathIndex.end() )
1439 {
1440 aInstance = m_instances[it->second];
1441 return true;
1442 }
1443
1444 return false;
1445 }
1446
1447 for( const SCH_SYMBOL_INSTANCE& instance : m_instances )
1448 {
1449 if( instance.m_Path.EndsWith( aSheetPath ) )
1450 {
1451 aInstance = instance;
1452 return true;
1453 }
1454 }
1455
1456 return false;
1457}
1458
1459
1460void SCH_SYMBOL::RemoveInstance( const SCH_SHEET_PATH& aInstancePath )
1461{
1462 RemoveInstance( aInstancePath.Path() );
1463}
1464
1465
1466void SCH_SYMBOL::RemoveInstance( const KIID_PATH& aInstancePath )
1467{
1468 // Search for an existing path and remove it if found
1469 auto indexIt = m_instancePathIndex.find( aInstancePath );
1470
1471 if( indexIt != m_instancePathIndex.end() )
1472 {
1473 size_t ii = indexIt->second;
1474 wxASSERT( ii < m_instances.size() );
1475 wxASSERT( m_instances[ii].m_Path == aInstancePath );
1476
1477 if( wxLog::IsAllowedTraceMask( traceSchSheetPaths ) )
1478 {
1479 wxLogTrace( traceSchSheetPaths,
1480 wxS( "Removing symbol instance:\n"
1481 " sheet path %s\n"
1482 " reference %s, unit %d from symbol %s." ),
1483 aInstancePath.AsString(), m_instances[ii].m_Reference, m_instances[ii].m_Unit,
1484 m_Uuid.AsString() );
1485 }
1486
1487 m_instances.erase( m_instances.begin() + ii );
1490 }
1491}
1492
1493
1495{
1496 m_instancePathIndex.clear();
1497 m_instancePathIndex.reserve( m_instances.size() );
1498
1499 for( size_t i = 0; i < m_instances.size(); ++i )
1500 {
1501 wxASSERT( m_instancePathIndex.find( m_instances[i].m_Path ) == m_instancePathIndex.end() );
1502 m_instancePathIndex[m_instances[i].m_Path] = i;
1503 }
1504}
1505
1506
1507void SCH_SYMBOL::AddHierarchicalReference( const KIID_PATH& aPath, const wxString& aRef, int aUnit )
1508{
1509 SCH_SYMBOL_INSTANCE instance;
1510 instance.m_Path = aPath;
1511 instance.m_Reference = aRef;
1512 instance.m_Unit = aUnit;
1513
1514 AddHierarchicalReference( instance );
1515}
1516
1517
1519{
1520 SCH_SYMBOL_INSTANCE instance = aInstance;
1521 RemoveInstance( instance.m_Path );
1522
1523 // The flag judged the copied reference against its source path's suffix
1524 instance.m_RefLacksSuffix = false;
1525
1526 wxLogTrace( traceSchSheetPaths,
1527 wxS( "Adding symbol '%s' instance:\n"
1528 " sheet path '%s'\n"
1529 " reference '%s'\n"
1530 " unit %d\n" ),
1531 m_Uuid.AsString(), instance.m_Path.AsString(), instance.m_Reference, instance.m_Unit );
1532
1533 m_instancePathIndex[instance.m_Path] = m_instances.size();
1534 m_instances.push_back( instance );
1536
1537 // This should set the default instance to the first saved instance data for each symbol
1538 // when importing sheets.
1539 if( m_instances.size() == 1 )
1540 {
1542 m_unit = instance.m_Unit;
1543 }
1544}
1545
1546
1547const wxString SCH_SYMBOL::GetRef( const SCH_SHEET_PATH* sheet, bool aIncludeUnit ) const
1548{
1549 return refFor( sheet, aIncludeUnit, true );
1550}
1551
1552
1553wxString SCH_SYMBOL::GetBaseRef( const SCH_SHEET_PATH* aSheet, bool aIncludeUnit ) const
1554{
1555 return refFor( aSheet, aIncludeUnit, false );
1556}
1557
1558
1559wxString SCH_SYMBOL::GetUnitRef( const SCH_SHEET_PATH* aSheet, int aUnit ) const
1560{
1561 return refFor( aSheet, true, true, aUnit );
1562}
1563
1564
1565static std::atomic<uint64_t> s_refGeneration{ 0 };
1566
1567
1569{
1570 return s_refGeneration.load( std::memory_order_acquire );
1571}
1572
1573
1575{
1576 s_refGeneration.fetch_add( 1, std::memory_order_acq_rel );
1577}
1578
1579
1581{
1582 if( const SCHEMATIC* schematic = Schematic() )
1583 return GetRef( &schematic->CurrentSheet() );
1584
1585 return GetField( FIELD_T::REFERENCE )->GetText();
1586}
1587
1588
1589wxString SCH_SYMBOL::refFor( const SCH_SHEET_PATH* sheet, bool aIncludeUnit, bool aCompose,
1590 std::optional<int> aUnit ) const
1591{
1592 const KIID_PATH& path = sheet->PathRef();
1593 wxString ref;
1594 int instanceUnit = 0;
1595 bool onPath = false;
1596
1597 const bool traceEnabled = wxLog::IsAllowedTraceMask( traceSchSymbolRef );
1598
1599 if( traceEnabled )
1600 {
1601 wxLogTrace( traceSchSymbolRef, "GetRef for symbol %s on path %s (sheet path has %zu sheets)",
1602 m_Uuid.AsString(), path.AsString(), sheet->size() );
1603 wxLogTrace( traceSchSymbolRef, " Symbol has %zu instance references", m_instances.size() );
1604 }
1605
1606 if( auto it = m_instancePathIndex.find( path ); it != m_instancePathIndex.end() )
1607 {
1608 const SCH_SYMBOL_INSTANCE& instance = m_instances[it->second];
1609
1610 ref = instance.m_Reference;
1611 instanceUnit = instance.m_Unit;
1612 onPath = true;
1613
1614 if( traceEnabled )
1615 wxLogTrace( traceSchSymbolRef, " MATCH FOUND: ref=%s", ref );
1616 }
1617
1618 // If it was not found in m_Paths array, then see if it is in m_Field[REFERENCE] -- if so,
1619 // use this as a default for this path. This will happen if we load a version 1 schematic
1620 // file. It will also mean that multiple instances of the same sheet by default all have
1621 // the same symbol references, but perhaps this is best.
1622 if( ref.IsEmpty() && !GetField( FIELD_T::REFERENCE )->GetText().IsEmpty() )
1623 {
1625
1626 if( traceEnabled )
1627 wxLogTrace( traceSchSymbolRef, " Using fallback from REFERENCE field: %s", ref );
1628 }
1629
1630 if( ref.IsEmpty() )
1631 {
1633
1634 if( traceEnabled )
1635 wxLogTrace( traceSchSymbolRef, " Using unannotated reference: %s", ref );
1636 }
1637
1638 // Unannotated references stay recognisable, and a symbol not on this path has no suffix there
1639 const bool compose = aCompose && onPath && ref.Last() != '?';
1640 const int unitCount = GetUnitCount();
1641 const bool withUnit = aUnit || ( aIncludeUnit && unitCount > 1 );
1642
1643 if( aUnit )
1644 ref += SubReference( *aUnit, false );
1645 else if( withUnit && onPath )
1646 ref += SubReference( instanceUnit );
1647
1648 const SCHEMATIC* schematic = compose ? Schematic() : nullptr;
1649
1650 // A unit shows its own sheet's suffix, while the package composes with the lowest suffix among its units
1651 if( schematic && schematic->HasRefSuffixes() )
1652 {
1653 if( aUnit && *aUnit != GetUnitSelection( sheet ) )
1654 ref += schematic->GetUnitRefSuffix( this, *sheet, *aUnit );
1655 else if( withUnit || unitCount < 2 )
1656 schematic->AppendRefSuffix( ref, *sheet );
1657 else
1658 ref += schematic->GetPackageRefSuffix( this, *sheet );
1659 }
1660
1661 if( traceEnabled )
1662 wxLogTrace( traceSchSymbolRef, " Final reference: %s", ref );
1663
1664 return ref;
1665}
1666
1667
1668void SCH_SYMBOL::SetRefProp( const wxString& aRef )
1669{
1671 const SCH_SHEET_PATH& sheet = Schematic()->CurrentSheet();
1672 wxString base;
1673
1674 if( validator.DoValidate( aRef, nullptr ) && BaseRefFromUser( sheet, aRef, base ).IsEmpty() )
1675 SetUserRef( sheet, base );
1676}
1677
1678
1679wxString SCH_SYMBOL::BaseRefFromUser( const SCH_SHEET_PATH& aSheet, const wxString& aText, wxString& aBase,
1680 const SCHEMATIC* aSchematic ) const
1681{
1682 const SCHEMATIC* schematic = Schematic() ? Schematic() : aSchematic;
1683
1684 aBase = aText;
1685
1686 if( !schematic )
1687 return wxEmptyString;
1688
1689 SCH_SYMBOL_INSTANCE existing;
1690 const bool onPath = GetInstance( existing, aSheet.Path() );
1691 const wxString own = schematic->GetRefSuffix( aSheet );
1692 const wxString package = schematic->GetPackageRefSuffix( this, aSheet );
1693
1694 // An unedited base may end in suffix text, as R12 with a suffix of 2
1695 if( onPath && aText == existing.m_Reference )
1696 return wxEmptyString;
1697
1698 // An echoed composed reference keeps its base even where a sibling suffix is longer
1699 if( onPath && ( ( !own.IsEmpty() && aText == existing.m_Reference + own )
1700 || ( !package.IsEmpty() && aText == existing.m_Reference + package ) ) )
1701 {
1702 aBase = existing.m_Reference;
1703 return wxEmptyString;
1704 }
1705
1706 auto endsIn =
1707 [&]( const wxString& aSuffix )
1708 {
1709 return !aSuffix.IsEmpty() && aText.length() > aSuffix.length() && aText.EndsWith( aSuffix );
1710 };
1711
1712 // A unit of a package spanning sheets shows the package's suffix, which may be another sheet's
1713 size_t matched = endsIn( own ) ? own.length() : 0;
1714
1715 if( endsIn( package ) )
1716 matched = std::max( matched, package.length() );
1717
1718 wxString sibling;
1719
1720 // The longest suffix wins, since _B_A typed on the _A channel names the _B_A channel
1721 for( const SCH_SHEET_PATH& path : schematic->Hierarchy().FindAllSheetsForScreen( aSheet.LastScreen() ) )
1722 {
1723 if( path == aSheet )
1724 continue;
1725
1726 const wxString suffix = schematic->GetRefSuffix( path );
1727
1728 if( endsIn( suffix ) && suffix.length() > matched )
1729 {
1730 matched = suffix.length();
1731 sibling = path.PathHumanReadable( false );
1732 }
1733 }
1734
1735 if( !sibling.IsEmpty() )
1736 return wxString::Format( _( "%s ends with the reference suffix of sheet %s." ), aText, sibling );
1737
1738 aBase = aText.Left( aText.length() - matched );
1739 return wxEmptyString;
1740}
1741
1742
1743void SCH_SYMBOL::SetUserRef( const SCH_SHEET_PATH& aSheet, const wxString& aBase )
1744{
1745 SetRef( &aSheet, aBase );
1746
1747 const SCHEMATIC* schematic = Schematic();
1748
1749 if( !schematic || !schematic->Settings().m_AnnotateReusedSheetSuffixes )
1750 return;
1751
1752 std::vector<SCH_SHEET_PATH> copies;
1753 const int unit = GetUnitSelection( &aSheet );
1754
1755 for( const SCH_SHEET_PATH& path : schematic->Hierarchy().FindAllSheetsForScreen( aSheet.LastScreen() ) )
1756 {
1757 if( path == aSheet )
1758 continue;
1759
1760 // Copies that select different units keep their own bases, which the annotator pairs into packages
1761 if( GetUnitCount() > 1 && GetUnitSelection( &path ) != unit )
1762 return;
1763
1764 copies.push_back( path );
1765 }
1766
1767 for( const SCH_SHEET_PATH& path : copies )
1768 SetRef( &path, aBase );
1769}
1770
1771
1772void SCH_SYMBOL::SetValueProp( const wxString& aValue )
1773{
1774 wxString currentVariant = Schematic()->GetCurrentVariant();
1775 SetValueFieldText( aValue, &Schematic()->CurrentSheet(), currentVariant );
1776}
1777
1778
1779void SCH_SYMBOL::SetRefLacksSuffix( const KIID_PATH& aPath, bool aLacksSuffix )
1780{
1781 if( auto it = m_instancePathIndex.find( aPath ); it != m_instancePathIndex.end() )
1782 m_instances[it->second].m_RefLacksSuffix = aLacksSuffix;
1783}
1784
1785
1786void SCH_SYMBOL::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref )
1787{
1788 KIID_PATH path = sheet->Path();
1789 const wxString previousPrefix = m_prefix;
1790 const bool wasDoNetlist = m_doNetlist;
1791 bool changed = false;
1792
1793 if( auto it = m_instancePathIndex.find( path ); it != m_instancePathIndex.end() )
1794 {
1795 SCH_SYMBOL_INSTANCE& instance = m_instances[it->second];
1796 changed = std::exchange( instance.m_Reference, ref ) != ref;
1797
1798 if( changed )
1799 instance.m_RefLacksSuffix = false;
1800 }
1801 else
1802 {
1804 }
1805
1806 for( std::unique_ptr<SCH_PIN>& pin : m_pins )
1807 pin->ClearDefaultNetName( sheet );
1808
1809 if( Schematic() && *sheet == Schematic()->CurrentSheet() )
1810 {
1811 changed |= GetField( FIELD_T::REFERENCE )->GetText() != ref;
1813 }
1814
1815 // Reinit the m_prefix member if needed
1817
1818 if( m_prefix.IsEmpty() )
1819 m_prefix = wxT( "U" );
1820
1821 // Power symbols have references starting with # and are not included in netlists
1822 m_doNetlist = !ref.StartsWith( wxT( "#" ) );
1823
1824 if( changed || m_prefix != previousPrefix || m_doNetlist != wasDoNetlist )
1826}
1827
1828
1829void SCH_SYMBOL::SetFieldText( SCH_FIELD* aField, const wxString& aFieldName, const wxString& aFieldText,
1830 const SCH_SHEET_PATH* aPath, const wxString& aVariantName )
1831{
1832 switch( aField->GetId() )
1833 {
1834 case FIELD_T::REFERENCE:
1835 wxCHECK( aPath, /* void */ );
1836 SetRef( aPath, aFieldText );
1837 break;
1838
1839 default:
1840 {
1841 wxString defaultText = aField->GetText( aPath );
1842
1843 if( aVariantName.IsEmpty() )
1844 {
1845 if( aFieldText != defaultText )
1846 aField->SetText( aFieldText );
1847 }
1848 else
1849 {
1850 SCH_SYMBOL_INSTANCE* instance = getInstance( *aPath );
1851
1852 wxCHECK( instance, /* void */ );
1853
1854 // Diff against the value the variant resolves to without an explicit override so
1855 // alternate symbol fields read back through the UI are not re-stored as overrides.
1856 if( LIB_SYMBOL* altSymbol = GetVariantLibSymbol( aVariantName, *aPath ) )
1857 {
1858 const SCH_FIELD* altField = altSymbol->GetField( aFieldName );
1859
1860 if( altField && !altField->GetText().IsEmpty() )
1861 defaultText = altField->GetText();
1862 }
1863
1864 bool changed = false;
1865
1866 if( instance->m_Variants.contains( aVariantName ) )
1867 {
1868 std::map<wxString, wxString>& fields = instance->m_Variants[aVariantName].m_Fields;
1869
1870 if( aFieldText != defaultText )
1871 {
1872 auto [entry, inserted] = fields.try_emplace( aFieldName, aFieldText );
1873 changed = inserted || std::exchange( entry->second, aFieldText ) != aFieldText;
1874 }
1875 else
1876 {
1877 changed = fields.erase( aFieldName ) != 0;
1878 }
1879 }
1880 else if( aFieldText != defaultText )
1881 {
1882 SCH_SYMBOL_VARIANT newVariant( aVariantName );
1883
1884 newVariant.InitializeAttributes( *this );
1885 newVariant.m_Fields[aFieldName] = aFieldText;
1886 instance->m_Variants.insert( std::make_pair( aVariantName, newVariant ) );
1887 changed = true;
1888 }
1889
1890 if( changed )
1892 }
1893
1894 break;
1895 }
1896 }
1897}
1898
1899
1900void SCH_SYMBOL::SetFieldText( const wxString& aFieldName, const wxString& aFieldText, const SCH_SHEET_PATH* aPath,
1901 const wxString& aVariantName )
1902{
1903 wxCHECK_MSG( !aFieldName.IsEmpty(), /* void */, wxT( "Can't set text on a field with no name!" ) );
1904
1905 SCH_FIELD* field = GetField( aFieldName );
1906
1907 wxCHECK_MSG( field, /* void */, wxT( "Can't set text on a field not yet added to the symbol!" ) );
1908
1909 SetFieldText( field, aFieldName, aFieldText, aPath, aVariantName );
1910}
1911
1912
1913wxString SCH_SYMBOL::GetFieldText( const SCH_FIELD* aField, const wxString& aFieldName, const SCH_SHEET_PATH* aPath,
1914 const wxString& aVariantName ) const
1915{
1916 switch( aField->GetId() )
1917 {
1918 case FIELD_T::REFERENCE:
1919 wxCHECK( aPath, aField->GetText() );
1920 return GetBaseRef( aPath );
1921 break;
1922
1923 case FIELD_T::FOOTPRINT:
1924 if( !aVariantName.IsEmpty() && aPath )
1925 {
1926 const SCH_SYMBOL_INSTANCE* instance = getInstance( *aPath );
1927
1928 if( instance && instance->m_Variants.contains( aVariantName )
1929 && instance->m_Variants.at( aVariantName ).m_Fields.contains( aFieldName ) )
1930 {
1931 return instance->m_Variants.at( aVariantName ).m_Fields.at( aFieldName );
1932 }
1933
1934 LIB_SYMBOL* altSymbol = GetVariantLibSymbol( aVariantName, *aPath );
1935
1936 if( altSymbol )
1937 {
1938 const SCH_FIELD* altField = altSymbol->GetField( FIELD_T::FOOTPRINT );
1939
1940 if( altField && !altField->GetText().IsEmpty() )
1941 return altField->GetText();
1942 }
1943 }
1944
1945 return GetFootprintFieldText( nullptr, RAW_VALUE );
1946
1947 default:
1948 if( aVariantName.IsEmpty() )
1949 {
1950 return aField->GetText();
1951 }
1952 else if( aPath )
1953 {
1954 const SCH_SYMBOL_INSTANCE* instance = getInstance( *aPath );
1955
1956 if( instance && instance->m_Variants.contains( aVariantName ) )
1957 {
1958 const SCH_SYMBOL_VARIANT& variant = instance->m_Variants.at( aVariantName );
1959
1960 if( variant.m_Fields.contains( aFieldName ) )
1961 return variant.m_Fields.at( aFieldName );
1962
1963 LIB_SYMBOL* altSymbol = GetVariantLibSymbol( aVariantName, *aPath );
1964
1965 if( altSymbol )
1966 {
1967 const SCH_FIELD* altField = altSymbol->GetField( aFieldName );
1968
1969 if( altField && !altField->GetText().IsEmpty() )
1970 return altField->GetText();
1971 }
1972 }
1973 }
1974
1975 break;
1976 }
1977
1978 return aField->GetText();
1979}
1980
1981
1982wxString SCH_SYMBOL::GetFieldText( const wxString& aFieldName, const SCH_SHEET_PATH* aPath,
1983 const wxString& aVariantName ) const
1984{
1985 wxCHECK_MSG( !aFieldName.IsEmpty(), wxEmptyString, wxT( "Can't get text from a field with no name!" ) );
1986
1987 const SCH_FIELD* field = GetField( aFieldName );
1988
1989 wxCHECK_MSG( field, wxEmptyString, wxT( "Can't get text from a field not yet added to the symbol!" ) );
1990
1991 return GetFieldText( field, aFieldName, aPath, aVariantName );
1992}
1993
1994
1995bool SCH_SYMBOL::IsAnnotated( const SCH_SHEET_PATH* aSheet ) const
1996{
1997 KIID_PATH path = aSheet->Path();
1998
1999 for( const SCH_SYMBOL_INSTANCE& instance : m_instances )
2000 {
2001 if( instance.m_Path == path )
2002 return !instance.m_Reference.IsEmpty() && instance.m_Reference.Last() != '?';
2003 }
2004
2005 return false;
2006}
2007
2008
2010{
2011 wxString refDesignator = GetField( FIELD_T::REFERENCE )->GetText();
2012
2013 refDesignator.Replace( "~", " " );
2014
2015 wxString prefix = refDesignator;
2016
2017 while( prefix.Length() )
2018 {
2019 wxUniCharRef last = prefix.Last();
2020
2021 if( ( last >= '0' && last <= '9' ) || last == '?' || last == '*' )
2022 prefix.RemoveLast();
2023 else
2024 break;
2025 }
2026
2027 // Avoid a prefix containing trailing/leading spaces
2028 prefix.Trim( true );
2029 prefix.Trim( false );
2030
2031 if( !prefix.IsEmpty() )
2032 SetPrefix( prefix );
2033}
2034
2035
2036wxString SCH_SYMBOL::SubReference( int aUnit, bool aAddSeparator ) const
2037{
2038 // A custom unit display name overrides the default A/B/C (or numeric) suffix.
2039 if( m_part )
2040 {
2041 const std::map<int, wxString>& names = m_part->GetUnitDisplayNames();
2042 auto it = names.find( aUnit );
2043
2044 if( it != names.end() )
2045 {
2046 wxString subRef;
2047
2048 if( SCHEMATIC* schematic = Schematic() )
2049 {
2050 int sep = schematic->Settings().m_SubpartIdSeparator;
2051
2052 if( sep != 0 && aAddSeparator )
2053 subRef << wxChar( sep );
2054 }
2055
2056 subRef << it->second;
2057 return subRef;
2058 }
2059 }
2060
2061 if( SCHEMATIC* schematic = Schematic() )
2062 return schematic->Settings().SubReference( aUnit, aAddSeparator );
2063
2064 return LIB_SYMBOL::LetterSubReference( aUnit, 'A' );
2065}
2066
2067
2069{
2070 KIID_PATH path = aSheet->Path();
2071
2072 if( auto it = m_instancePathIndex.find( path ); it != m_instancePathIndex.end() )
2073 return m_instances[it->second].m_Unit;
2074
2075 // If it was not found in m_Paths array, then use m_unit. This will happen if we load a
2076 // version 1 schematic file.
2077 return m_unit;
2078}
2079
2080
2081void SCH_SYMBOL::SetUnitSelection( const SCH_SHEET_PATH* aSheet, int aUnitSelection )
2082{
2083 KIID_PATH path = aSheet->Path();
2084
2085 if( auto it = m_instancePathIndex.find( path ); it != m_instancePathIndex.end() )
2086 {
2087 if( std::exchange( m_instances[it->second].m_Unit, aUnitSelection ) != aUnitSelection )
2089
2090 return;
2091 }
2092
2093 // didn't find it; better add it
2095}
2096
2097
2098void SCH_SYMBOL::setVariantAttribute( bool aEnable, const SCH_SHEET_PATH* aInstance, const wxString& aVariantName,
2099 bool SCH_SYMBOL::*aBase, bool SCH_SYMBOL_VARIANT::*aOverride )
2100{
2101 bool* attribute = &( this->*aBase );
2102
2103 if( aInstance && !aVariantName.IsEmpty() )
2104 {
2105 SCH_SYMBOL_INSTANCE* instance = getInstance( *aInstance );
2106
2107 wxCHECK_MSG( instance, /* void */,
2108 wxString::Format( wxS( "Cannot set attribute for invalid sheet path '%s'." ),
2109 aInstance->PathHumanReadable() ) );
2110
2111 auto it = instance->m_Variants.find( aVariantName );
2112
2113 if( it == instance->m_Variants.end() )
2114 {
2115 if( aEnable == this->*aBase )
2116 return;
2117
2118 SCH_SYMBOL_VARIANT newVariant( aVariantName );
2119 newVariant.InitializeAttributes( *this );
2120 newVariant.*aOverride = aEnable;
2121 AddVariant( *aInstance, newVariant );
2122 return;
2123 }
2124
2125 attribute = &( it->second.*aOverride );
2126 }
2127
2128 if( *attribute == aEnable )
2129 return;
2130
2131 *attribute = aEnable;
2133}
2134
2135
2136void SCH_SYMBOL::SetDNP( bool aEnable, const SCH_SHEET_PATH* aInstance, const wxString& aVariantName )
2137{
2138 setVariantAttribute( aEnable, aInstance, aVariantName, &SCH_SYMBOL::m_DNP, &SCH_SYMBOL_VARIANT::m_DNP );
2139}
2140
2141
2142bool SCH_SYMBOL::GetDNP( const SCH_SHEET_PATH* aInstance, const wxString& aVariantName ) const
2143{
2144 if( !aInstance || aVariantName.IsEmpty() )
2145 return m_DNP;
2146
2147 SCH_SYMBOL_INSTANCE instance;
2148
2149 if( !GetInstance( instance, aInstance->Path() ) )
2150 return m_DNP;
2151
2152 if( instance.m_Variants.contains( aVariantName ) )
2153 return instance.m_Variants[aVariantName].m_DNP;
2154
2155 return m_DNP;
2156}
2157
2158
2160 const wxString& aVariantName )
2161{
2162 if( !aInstance || aVariantName.IsEmpty() )
2163 {
2164 m_pinMapOverride = aOverride;
2165 return;
2166 }
2167
2168 SCH_SYMBOL_INSTANCE* instance = getInstance( *aInstance );
2169
2170 wxCHECK_MSG( instance, /* void */,
2171 wxString::Format( wxS( "Cannot set pin map override for invalid sheet path '%s'." ),
2172 aInstance->PathHumanReadable() ) );
2173
2174 if( instance->m_Variants.contains( aVariantName ) )
2175 {
2176 instance->m_Variants[aVariantName].m_PinMapOverride = aOverride;
2177 }
2178 else if( aOverride != m_pinMapOverride )
2179 {
2180 SCH_SYMBOL_VARIANT variant( aVariantName );
2181
2182 variant.InitializeAttributes( *this );
2183 variant.m_PinMapOverride = aOverride;
2184 AddVariant( *aInstance, variant );
2185 }
2186}
2187
2188
2190{
2192
2193 for( SCH_SYMBOL_INSTANCE& instance : m_instances )
2194 {
2195 for( auto& [name, variant] : instance.m_Variants )
2196 variant.m_PinMapOverride = PIN_MAP_INSTANCE_OVERRIDE();
2197 }
2198}
2199
2200
2202 const wxString& aVariantName ) const
2203{
2205
2206 if( aInstance && !aVariantName.IsEmpty() )
2207 {
2208 SCH_SYMBOL_INSTANCE instance;
2209
2210 if( GetInstance( instance, aInstance->Path() ) && instance.m_Variants.contains( aVariantName ) )
2211 result = instance.m_Variants[aVariantName].m_PinMapOverride;
2212 }
2213
2214 // Units 2..N follow unit 1's record; resolve that here so callers never see a delegate.
2215 if( result.IsDelegate() && aInstance )
2216 result = resolveDelegatedPinMapOverride( *aInstance, aVariantName );
2217
2218 return result;
2219}
2220
2221
2223 const wxString& aVariantName ) const
2224{
2225 if( !Schematic() )
2227
2228 wxString ref = GetRef( &aSheet );
2229
2230 for( const SCH_SHEET_PATH& sheet : Schematic()->Hierarchy() )
2231 {
2232 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2233 {
2234 SCH_SYMBOL* sibling = static_cast<SCH_SYMBOL*>( item );
2235
2236 if( sibling == this || sibling->GetUnit() != 1 )
2237 continue;
2238
2239 if( sibling->GetRef( &sheet ).CmpNoCase( ref ) != 0 )
2240 continue;
2241
2242 PIN_MAP_INSTANCE_OVERRIDE unit1 = sibling->GetPinMapOverride( &sheet, aVariantName );
2243
2244 // Guard against a unit-1 record that itself (incorrectly) delegates.
2245 if( unit1.IsDelegate() )
2247
2248 return unit1;
2249 }
2250 }
2251
2253}
2254
2255
2256void SCH_SYMBOL::SetExcludedFromBOM( bool aEnable, const SCH_SHEET_PATH* aInstance, const wxString& aVariantName )
2257{
2258 setVariantAttribute( aEnable, aInstance, aVariantName, &SCH_SYMBOL::m_excludedFromBOM,
2260}
2261
2262
2263bool SCH_SYMBOL::GetExcludedFromBOM( const SCH_SHEET_PATH* aInstance, const wxString& aVariantName ) const
2264{
2265 if( !aInstance || aVariantName.IsEmpty() )
2266 return m_excludedFromBOM;
2267
2268 SCH_SYMBOL_INSTANCE instance;
2269
2270 if( !GetInstance( instance, aInstance->Path() ) )
2271 return m_excludedFromBOM;
2272
2273 if( instance.m_Variants.contains( aVariantName ) )
2274 return instance.m_Variants[aVariantName].m_ExcludedFromBOM;
2275
2276 // If the variant has not been defined yet, return the default exclude from BOM setting.
2277 return m_excludedFromBOM;
2278}
2279
2280
2281void SCH_SYMBOL::SetExcludedFromSim( bool aEnable, const SCH_SHEET_PATH* aInstance, const wxString& aVariantName )
2282{
2283 setVariantAttribute( aEnable, aInstance, aVariantName, &SCH_SYMBOL::m_excludedFromSim,
2285}
2286
2287
2288bool SCH_SYMBOL::GetExcludedFromSim( const SCH_SHEET_PATH* aInstance, const wxString& aVariantName ) const
2289{
2290 if( !aInstance || aVariantName.IsEmpty() )
2291 return m_excludedFromSim;
2292
2293 SCH_SYMBOL_INSTANCE instance;
2294
2295 if( !GetInstance( instance, aInstance->Path() ) )
2296 return m_excludedFromSim;
2297
2298 if( instance.m_Variants.contains( aVariantName ) )
2299 return instance.m_Variants[aVariantName].m_ExcludedFromSim;
2300
2301 // If variant is not defined yet, return default exclude from simulation setting.
2302 return m_excludedFromSim;
2303}
2304
2305
2306void SCH_SYMBOL::SetExcludedFromBoard( bool aEnable, const SCH_SHEET_PATH* aInstance,
2307 const wxString& aVariantName )
2308{
2309 setVariantAttribute( aEnable, aInstance, aVariantName, &SCH_SYMBOL::m_excludedFromBoard,
2311}
2312
2313
2315 const wxString& aVariantName ) const
2316{
2317 if( !aInstance || aVariantName.IsEmpty() )
2318 return m_excludedFromBoard;
2319
2320 SCH_SYMBOL_INSTANCE instance;
2321
2322 if( !GetInstance( instance, aInstance->Path() ) )
2323 return m_excludedFromBoard;
2324
2325 if( instance.m_Variants.contains( aVariantName ) )
2326 return instance.m_Variants[aVariantName].m_ExcludedFromBoard;
2327
2328 // If variant is not defined yet, return default exclude from board setting.
2329 return m_excludedFromBoard;
2330}
2331
2332
2333void SCH_SYMBOL::SetExcludedFromPosFiles( bool aEnable, const SCH_SHEET_PATH* aInstance,
2334 const wxString& aVariantName )
2335{
2336 setVariantAttribute( aEnable, aInstance, aVariantName, &SCH_SYMBOL::m_excludedFromPosFiles,
2338}
2339
2340
2342 const wxString& aVariantName ) const
2343{
2344 if( !aInstance || aVariantName.IsEmpty() )
2346
2347 SCH_SYMBOL_INSTANCE instance;
2348
2349 if( !GetInstance( instance, aInstance->Path() ) )
2351
2352 if( instance.m_Variants.contains( aVariantName ) )
2353 return instance.m_Variants[aVariantName].m_ExcludedFromPosFiles;
2354
2355 // If variant is not defined yet, return default exclude from position files setting.
2357}
2358
2359
2360void SCH_SYMBOL::SetUnitSelection( int aUnitSelection )
2361{
2362 bool changed = false;
2363
2364 for( SCH_SYMBOL_INSTANCE& instance : m_instances )
2365 changed |= std::exchange( instance.m_Unit, aUnitSelection ) != aUnitSelection;
2366
2367 if( changed )
2369}
2370
2371
2372const wxString SCH_SYMBOL::GetValue( const SCH_SHEET_PATH* aInstance, RESOLUTION_CONTEXT aContext,
2373 const wxString& aVariantName ) const
2374{
2375 if( aVariantName.IsEmpty() || !aInstance )
2376 return GetField( FIELD_T::VALUE )->GetShownText( aInstance, aContext );
2377
2378 std::optional variant = GetVariant( *aInstance, aVariantName );
2379
2380 if( variant )
2381 {
2382 const wxString& fieldName = GetField( FIELD_T::VALUE )->GetName();
2383
2384 auto resolve =
2385 [&]( const wxString& aText ) -> wxString
2386 {
2387 std::function<bool( wxString* )> resolver =
2388 [&]( wxString* token ) -> bool
2389 {
2390 return ResolveTextVar( aInstance, token, aVariantName, 1 );
2391 };
2392
2393 return ExpandTextVars( aText, &resolver, aContext );
2394 };
2395
2396 if( variant->m_Fields.contains( fieldName ) )
2397 return resolve( variant->m_Fields[fieldName] );
2398
2399 LIB_SYMBOL* altSymbol = GetVariantLibSymbol( aVariantName, *aInstance );
2400
2401 if( altSymbol )
2402 {
2403 const SCH_FIELD* altField = altSymbol->GetField( FIELD_T::VALUE );
2404
2405 if( altField && !altField->GetText().IsEmpty() )
2406 return resolve( altField->GetText() );
2407 }
2408 }
2409
2410 // Fall back to default value when variant doesn't have an override
2411
2412 return GetField( FIELD_T::VALUE )->GetShownText( aInstance, aContext, aVariantName );
2413}
2414
2415
2416void SCH_SYMBOL::SetValueFieldText( const wxString& aValue, const SCH_SHEET_PATH* aInstance,
2417 const wxString& aVariantName )
2418{
2419 if( !aInstance || aVariantName.IsEmpty() )
2420 {
2421 GetField( FIELD_T::VALUE )->SetText( aValue );
2422 return;
2423 }
2424
2425 SCH_SYMBOL_INSTANCE* instance = getInstance( *aInstance );
2426
2427 wxCHECK( instance, /* void */ );
2428
2429 wxString fieldName = GetField( FIELD_T::VALUE )->GetName();
2430
2431 if( instance->m_Variants.contains( aVariantName ) )
2432 {
2433 instance->m_Variants[aVariantName].m_Fields[fieldName] = aValue;
2434 }
2435 else
2436 {
2437 SCH_SYMBOL_VARIANT newVariant( aVariantName );
2438
2439 newVariant.InitializeAttributes( *this );
2440 newVariant.m_Fields[fieldName] = aValue;
2441 instance->m_Variants.insert( std::make_pair( aVariantName, newVariant ) );
2442 }
2443}
2444
2445
2447 const wxString& aVariantName ) const
2448{
2449 return GetField( FIELD_T::FOOTPRINT )->GetShownText( aPath, aContext, aVariantName );
2450
2451}
2452
2453
2454void SCH_SYMBOL::SetFootprintFieldText( const wxString& aFootprint )
2455{
2456 GetField( FIELD_T::FOOTPRINT )->SetText( aFootprint );
2457}
2458
2459
2461{
2462 if( SCH_FIELD* field = FindField( m_fields, aFieldType ) )
2463 return field;
2464
2465 m_fields.emplace_back( this, aFieldType );
2466 return &m_fields.back();
2467}
2468
2469
2470const SCH_FIELD* SCH_SYMBOL::GetField( FIELD_T aFieldType ) const
2471{
2472 return FindField( m_fields, aFieldType );
2473}
2474
2475
2476SCH_FIELD* SCH_SYMBOL::GetField( const wxString& aFieldName )
2477{
2478 return FindField( m_fields, aFieldName );
2479}
2480
2481
2482const SCH_FIELD* SCH_SYMBOL::GetField( const wxString& aFieldName ) const
2483{
2484 return FindField( m_fields, aFieldName );
2485}
2486
2487
2488void SCH_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly ) const
2489{
2490 for( const SCH_FIELD& field : m_fields )
2491 {
2492 if( aVisibleOnly )
2493 {
2494 if( !field.IsVisible() || field.GetText().IsEmpty() )
2495 continue;
2496 }
2497
2498 aVector.push_back( const_cast<SCH_FIELD*>( &field ) );
2499 }
2500
2501 std::sort( aVector.begin(), aVector.end(),
2502 []( SCH_FIELD* lhs, SCH_FIELD* rhs )
2503 {
2504 return lhs->GetOrdinal() < rhs->GetOrdinal();
2505 } );
2506}
2507
2508
2510{
2511 return NextFieldOrdinal( m_fields );
2512}
2513
2514
2516{
2517 m_fields.push_back( aField );
2518
2520
2521 return &m_fields.back();
2522}
2523
2524
2525void SCH_SYMBOL::RemoveField( const wxString& aFieldName )
2526{
2527 // aFieldName may refer to the name owned by the field being removed.
2528 wxString fieldName = aFieldName;
2529
2530 for( unsigned ii = 0; ii < m_fields.size(); ++ii )
2531 {
2532 if( m_fields[ii].IsMandatory() )
2533 continue;
2534
2535 if( fieldName == m_fields[ii].GetName( false ) )
2536 {
2537 m_fields.erase( m_fields.begin() + ii );
2538
2539 for( SCH_SYMBOL_INSTANCE& instance : m_instances )
2540 {
2541 for( auto& [name, variant] : instance.m_Variants )
2542 variant.m_Fields.erase( fieldName );
2543 }
2544
2546
2547 return;
2548 }
2549 }
2550}
2551
2552
2554{
2555 for( SCH_FIELD& field : m_fields )
2556 {
2557 if( field.GetName().IsSameAs( aFieldName, false ) )
2558 return &field;
2559 }
2560
2561 return nullptr;
2562}
2563
2564
2565const SCH_FIELD* SCH_SYMBOL::FindFieldCaseInsensitive( const wxString& aFieldName ) const
2566{
2567 for( const SCH_FIELD& field : m_fields )
2568 {
2569 if( field.GetName().IsSameAs( aFieldName, false ) )
2570 return &field;
2571 }
2572
2573 return nullptr;
2574}
2575
2576
2577void SCH_SYMBOL::UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, bool aUpdateRef, bool aUpdateOtherFields,
2578 bool aResetRef, bool aResetOtherFields )
2579{
2580 if( m_part )
2581 {
2582 std::vector<SCH_FIELD*> fields;
2583 m_part->GetFields( fields );
2584
2585 for( const SCH_FIELD* libField : fields )
2586 {
2587 SCH_FIELD* schField;
2588 FIELD_T fieldType = FIELD_T::USER;
2589
2590 if( libField->IsMandatory() )
2591 {
2592 fieldType = libField->GetId();
2593 schField = GetField( fieldType );
2594 }
2595 else
2596 {
2597 schField = GetField( libField->GetUntranslatedName() );
2598
2599 if( !schField )
2600 {
2601 schField = AddField( SCH_FIELD( this, FIELD_T::USER, libField->GetUntranslatedName() ) );
2602 schField->ImportValues( *libField );
2603 schField->SetTextPos( m_pos + libField->GetTextPos() );
2604 }
2605 }
2606
2607 schField->SetPrivate( libField->IsPrivate() );
2608
2609 if( aUpdateStyle )
2610 {
2611 schField->ImportValues( *libField );
2612 schField->SetTextPos( m_pos + libField->GetTextPos() );
2613 }
2614
2615 if( fieldType == FIELD_T::REFERENCE && aPath )
2616 {
2617 if( aResetRef )
2618 SetRef( aPath, m_part->GetField( FIELD_T::REFERENCE )->GetText() );
2619 else if( aUpdateRef )
2620 SetRef( aPath, libField->GetText() );
2621 }
2622 else if( fieldType == FIELD_T::VALUE )
2623 {
2624 SetValueFieldText( UnescapeString( libField->GetText() ) );
2625 }
2626 else if( fieldType == FIELD_T::DATASHEET )
2627 {
2628 if( aResetOtherFields )
2629 schField->SetText( GetDatasheet() ); // alias-specific value
2630 else if( aUpdateOtherFields )
2631 schField->SetText( libField->GetText() );
2632 }
2633 else
2634 {
2635 if( aResetOtherFields || aUpdateOtherFields )
2636 schField->SetText( libField->GetText() );
2637 }
2638 }
2639 }
2640}
2641
2642
2643void SCH_SYMBOL::SyncOtherUnits( const SCH_SHEET_PATH& aSourceSheet, SCH_COMMIT& aCommit,
2644 PROPERTY_BASE* aProperty, const wxString& aVariantName )
2645{
2646 bool updateValue = true;
2647 bool updateExclFromBOM = true;
2648 bool updateExclFromBoard = true;
2649 bool updateExclFromPosFiles = true;
2650 bool updateDNP = true;
2651 bool updateOtherFields = true;
2652 bool updatePins = true;
2653 bool updatePinMapOverride = true;
2654
2655 if( aProperty )
2656 {
2657 updateValue = aProperty->Name() == _HKI( "Value" );
2658 updateExclFromBoard = aProperty->Name() == _HKI( "Exclude From Board" );
2659 updateExclFromBOM = aProperty->Name() == _HKI( "Exclude From Bill of Materials" );
2660 updateExclFromPosFiles = aProperty->Name() == _HKI( "Exclude From Position Files" );
2661 updateDNP = aProperty->Name() == _HKI( "Do not Populate" );
2662 updatePinMapOverride = aProperty->Name() == wxS( "Pin Map Mode" ) || aProperty->Name() == wxS( "Pin Map Name" );
2663 updateOtherFields = false;
2664 updatePins = false;
2665 }
2666
2667 if( !updateValue && !updateExclFromBOM && !updateExclFromBoard && !updateExclFromPosFiles && !updateDNP
2668 && !updateOtherFields && !updatePins && !updatePinMapOverride )
2669 {
2670 return;
2671 }
2672
2673 // Keep fields other than the reference, include/exclude flags, and alternate pin assignments
2674 // in sync in multi-unit parts.
2675 if( GetUnitCount() > 1 && IsAnnotated( &aSourceSheet ) )
2676 {
2677 wxString ref = GetRef( &aSourceSheet );
2678
2679 for( SCH_SHEET_PATH& sheet : Schematic()->Hierarchy() )
2680 {
2681 SCH_SCREEN* screen = sheet.LastScreen();
2682 std::vector<SCH_SYMBOL*> otherUnits;
2683
2684 CollectOtherUnits( ref, GetUnitSelection( &aSourceSheet ), m_lib_id, sheet, &otherUnits );
2685
2686 for( SCH_SYMBOL* otherUnit : otherUnits )
2687 {
2688 aCommit.Modify( otherUnit, screen );
2689
2690 if( updateValue )
2691 {
2692 otherUnit->SetFieldText( GetField( FIELD_T::VALUE )->GetName(),
2693 GetValue( &aSourceSheet, RAW_VALUE, aVariantName ),
2694 &sheet, aVariantName );
2695 }
2696
2697 if( updateOtherFields )
2698 {
2699 for( SCH_FIELD& field : m_fields )
2700 {
2701 if( field.GetId() == FIELD_T::REFERENCE || field.GetId() == FIELD_T::VALUE )
2702 {
2703 // already handled
2704 continue;
2705 }
2706
2707 SCH_FIELD* otherField;
2708
2709 if( field.IsMandatory() )
2710 otherField = otherUnit->GetField( field.GetId() );
2711 else
2712 otherField = otherUnit->GetField( field.GetName() );
2713
2714 if( otherField )
2715 {
2716 otherField->SetText( field.GetText( &aSourceSheet, aVariantName ), &sheet, aVariantName );
2717 }
2718 else
2719 {
2720 SCH_FIELD newField( field );
2721 const_cast<KIID&>( newField.m_Uuid ) = KIID();
2722
2723 newField.Offset( -GetPosition() );
2724 newField.Offset( otherUnit->GetPosition() );
2725
2726 newField.SetParent( otherUnit );
2727 SCH_FIELD* addedField = otherUnit->AddField( newField );
2728
2729 if( !aVariantName.IsEmpty() )
2730 {
2731 addedField->SetText( field.GetText( &aSourceSheet, aVariantName ), &sheet,
2732 aVariantName );
2733 }
2734 }
2735 }
2736
2737 for( int ii = (int) otherUnit->GetFields().size() - 1; ii >= 0; ii-- )
2738 {
2739 SCH_FIELD& otherField = otherUnit->GetFields()[ii];
2740
2741 if( !otherField.IsMandatory() && !GetField( otherField.GetName() ) )
2742 otherUnit->RemoveField( otherField.GetName() );
2743 }
2744 }
2745
2746 if( updateExclFromBOM )
2747 {
2748 otherUnit->SetExcludedFromBOM( GetExcludedFromBOM( &aSourceSheet, aVariantName ), &sheet,
2749 aVariantName );
2750 }
2751
2752 if( updateExclFromBoard )
2753 {
2754 otherUnit->SetExcludedFromBoard( GetExcludedFromBoard( &aSourceSheet, aVariantName ), &sheet,
2755 aVariantName );
2756 }
2757
2758 if( updateExclFromPosFiles )
2759 {
2760 otherUnit->SetExcludedFromPosFiles( GetExcludedFromPosFiles( &aSourceSheet, aVariantName ), &sheet,
2761 aVariantName );
2762 }
2763
2764 if( updateDNP )
2765 otherUnit->SetDNP( GetDNP( &aSourceSheet, aVariantName ), &sheet, aVariantName );
2766
2767 if( updatePinMapOverride )
2768 otherUnit->SetPinMapOverride( GetPinMapOverride( &aSourceSheet, aVariantName ), &sheet,
2769 aVariantName );
2770
2771 if( updatePins )
2772 {
2773 for( const std::unique_ptr<SCH_PIN>& model_pin : m_pins )
2774 {
2775 for( SCH_PIN* src_pin : otherUnit->GetPinsByNumber( model_pin->GetNumber() ) )
2776 src_pin->SetAlt( model_pin->GetAlt() );
2777 }
2778 }
2779 }
2780 }
2781 }
2782}
2783
2784
2785void SCH_SYMBOL::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction, RECURSE_MODE aMode )
2786{
2787 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
2788 aFunction( pin.get() );
2789
2790 for( SCH_FIELD& field : m_fields )
2791 aFunction( &field );
2792}
2793
2794
2800
2801
2802SCH_PIN* SCH_SYMBOL::GetPin( const wxString& aNumber ) const
2803{
2804 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
2805 {
2806 if( pin->GetNumber() == aNumber )
2807 return pin.get();
2808 }
2809
2810 return nullptr;
2811}
2812
2813
2814SCH_PIN* SCH_SYMBOL::GetPinByEffectivePadNumber( const wxString& aPadNumber, const SCH_SHEET_PATH* aSheet,
2815 const wxString& aVariantName ) const
2816{
2817 if( !aSheet )
2818 return nullptr;
2819
2820 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
2821 {
2822 for( const wxString& pad : ExpandStackedPinNotation( pin->GetEffectivePadNumber( *aSheet, aVariantName ) ) )
2823 {
2824 if( pad == aPadNumber )
2825 return pin.get();
2826 }
2827 }
2828
2829 return nullptr;
2830}
2831
2832
2833std::vector<SCH_PIN*> SCH_SYMBOL::GetPinsByNumber( const wxString& aNumber ) const
2834{
2835 std::vector<SCH_PIN*> pins;
2836
2837 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
2838 {
2839 if( pin->GetNumber() == aNumber )
2840 pins.push_back( pin.get() );
2841 }
2842
2843 return pins;
2844}
2845
2846
2847const SCH_PIN* SCH_SYMBOL::GetPin( const VECTOR2I& aPos ) const
2848{
2849 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
2850 {
2851 int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit() : GetUnit();
2852 int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle() : GetBodyStyle();
2853
2854 if( pin_unit != ALL_UNITS && pin_unit != GetUnit() )
2855 continue;
2856
2857 if( pin_bodyStyle != ALL_BODY_STYLES && pin_bodyStyle != GetBodyStyle() )
2858 continue;
2859
2860 if( pin->GetPosition() == aPos )
2861 return pin.get();
2862 }
2863
2864 return nullptr;
2865}
2866
2867
2868std::vector<SCH_PIN*> SCH_SYMBOL::GetLibPins() const
2869{
2870 if( m_part )
2871 return m_part->GetGraphicalPins( m_unit, m_bodyStyle );
2872
2873 return std::vector<SCH_PIN*>();
2874}
2875
2876
2877std::vector<SCH_PIN*> SCH_SYMBOL::GetAllLibPins() const
2878{
2879 if( m_part )
2880 return m_part->GetGraphicalPins( ALL_UNITS, ALL_BODY_STYLES );
2881
2882 return std::vector<SCH_PIN*>();
2883}
2884
2885
2887{
2888 return m_part ? m_part->GetPinCount() : 0;
2889}
2890
2891
2893{
2894 auto it = m_pinMap.find( aLibPin );
2895
2896 if( it != m_pinMap.end() )
2897 return it->second;
2898
2899 wxFAIL_MSG_AT( "Pin not found", __FILE__, __LINE__, __FUNCTION__ );
2900 return nullptr;
2901}
2902
2903
2904std::vector<const SCH_PIN*> SCH_SYMBOL::GetPins( const SCH_SHEET_PATH* aSheet ) const
2905{
2906 std::vector<const SCH_PIN*> pins;
2907 int unit = m_unit;
2908
2909 if( !aSheet && Schematic() )
2910 aSheet = &Schematic()->CurrentSheet();
2911
2912 if( aSheet )
2913 unit = GetUnitSelection( aSheet );
2914
2915 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
2916 {
2917 if( unit != ALL_UNITS && pin->GetUnit() != ALL_UNITS && pin->GetUnit() != unit )
2918 continue;
2919
2920 pins.push_back( pin.get() );
2921 }
2922
2923 return pins;
2924}
2925
2926
2927std::vector<SCH_PIN*> SCH_SYMBOL::GetPins( const SCH_SHEET_PATH* aSheet )
2928{
2929 std::vector<SCH_PIN*> pins;
2930 int unit = m_unit;
2931
2932 if( !aSheet && Schematic() )
2933 aSheet = &Schematic()->CurrentSheet();
2934
2935 if( aSheet )
2936 unit = GetUnitSelection( aSheet );
2937
2938 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
2939 {
2940 if( unit != ALL_UNITS && pin->GetUnit() != ALL_UNITS && pin->GetUnit() != unit )
2941 continue;
2942
2943 pins.push_back( pin.get() );
2944 }
2945
2946 return pins;
2947}
2948
2949
2950std::vector<SCH_PIN*> SCH_SYMBOL::GetGraphicalPins( int aUnit, int aBodyStyle ) const
2951{
2952 std::vector<SCH_PIN*> pins;
2953
2954 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
2955 {
2956 // Unit filtering:
2957 if( aUnit != ALL_UNITS
2958 && pin->GetUnit() != ALL_UNITS
2959 && pin->GetUnit() != aUnit )
2960 {
2961 continue;
2962 }
2963
2964 // Body style filtering:
2965 if( aBodyStyle != ALL_BODY_STYLES
2966 && pin->GetBodyStyle() != ALL_BODY_STYLES
2967 && pin->GetBodyStyle() != aBodyStyle )
2968 {
2969 continue;
2970 }
2971
2972 pins.push_back( pin.get() );
2973 }
2974
2975 return pins;
2976}
2977
2978
2980{
2981 wxCHECK_RET( aItem != nullptr && aItem->Type() == SCH_SYMBOL_T, wxT( "Cannot swap data with invalid symbol." ) );
2982
2983 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( aItem );
2984
2985 std::swap( m_pos, symbol->m_pos );
2986 std::swap( m_lib_id, symbol->m_lib_id );
2987 std::swap( m_prefix, symbol->m_prefix );
2988
2989 {
2990 m_pins.swap( symbol->m_pins ); // std::vector's swap()
2991
2992 for( std::unique_ptr<SCH_PIN>& pin : symbol->m_pins )
2993 pin->SetParent( symbol );
2994
2995 for( std::unique_ptr<SCH_PIN>& pin : m_pins )
2996 pin->SetParent( this );
2997 }
2998
2999 LIB_SYMBOL* libSymbol = symbol->m_part.release();
3000 symbol->m_part = std::move( m_part );
3001 symbol->UpdatePins();
3002 m_part.reset( libSymbol );
3003 UpdatePins();
3004
3005 {
3006 m_fields.swap( symbol->m_fields ); // std::vector's swap()
3007
3008 for( SCH_FIELD& field : symbol->m_fields )
3009 field.SetParent( symbol );
3010
3011 for( SCH_FIELD& field : m_fields )
3012 field.SetParent( this );
3013 }
3014
3015 std::swap( m_pinNameOffset, symbol->m_pinNameOffset );
3016 std::swap( m_showPinNames, symbol->m_showPinNames );
3017 std::swap( m_showPinNumbers, symbol->m_showPinNumbers );
3018
3019 TRANSFORM tmp = m_transform;
3020 m_transform = symbol->m_transform;
3021 symbol->m_transform = tmp;
3022
3023 std::swap( m_excludedFromSim, symbol->m_excludedFromSim );
3024 std::swap( m_excludedFromBOM, symbol->m_excludedFromBOM );
3025 std::swap( m_DNP, symbol->m_DNP );
3026 std::swap( m_excludedFromBoard, symbol->m_excludedFromBoard );
3027 std::swap( m_excludedFromPosFiles, symbol->m_excludedFromPosFiles );
3028 std::swap( m_pinMapOverride, symbol->m_pinMapOverride );
3029
3030 std::swap( m_instances, symbol->m_instances );
3032 std::swap( m_instancePathIndex, symbol->m_instancePathIndex );
3033 std::swap( m_schLibSymbolName, symbol->m_schLibSymbolName );
3034 std::swap( m_doNetlist, symbol->m_doNetlist );
3035 std::swap( m_passthroughMode, symbol->m_passthroughMode );
3036 std::swap( m_signalName, symbol->m_signalName );
3037
3038 m_variantSymbolCache.clear();
3039 symbol->m_variantSymbolCache.clear();
3040}
3041
3042
3043void SCH_SYMBOL::GetContextualTextVars( wxArrayString* aVars ) const
3044{
3045 for( const SCH_FIELD& field : m_fields )
3046 {
3047 if( field.IsPrivate() )
3048 continue;
3049
3050 if( field.IsMandatory() )
3051 aVars->push_back( field.GetUntranslatedName().Upper() );
3052 else
3053 aVars->push_back( field.GetName() );
3054 }
3055
3056 aVars->push_back( wxT( "OP" ) );
3057 aVars->push_back( wxT( "FOOTPRINT_LIBRARY" ) );
3058 aVars->push_back( wxT( "FOOTPRINT_NAME" ) );
3059 aVars->push_back( wxT( "UNIT" ) );
3060 aVars->push_back( wxT( "SHORT_REFERENCE" ) );
3061 aVars->push_back( wxT( "SYMBOL_LIBRARY" ) );
3062 aVars->push_back( wxT( "SYMBOL_NAME" ) );
3063 aVars->push_back( wxT( "SYMBOL_DESCRIPTION" ) );
3064 aVars->push_back( wxT( "SYMBOL_KEYWORDS" ) );
3065 aVars->push_back( wxT( "SYMBOL_IS_POWER" ) );
3066 aVars->push_back( wxT( "SYMBOL_IS_LOCAL_POWER" ) );
3067 aVars->push_back( wxT( "EXCLUDE_FROM_BOM" ) );
3068 aVars->push_back( wxT( "EXCLUDE_FROM_BOARD" ) );
3069 aVars->push_back( wxT( "EXCLUDE_FROM_SIM" ) );
3070 aVars->push_back( wxT( "DNP" ) );
3071 aVars->push_back( wxT( "SHORT_NET_NAME(<pin_number>)" ) );
3072 aVars->push_back( wxT( "NET_NAME(<pin_number>)" ) );
3073 aVars->push_back( wxT( "NET_CLASS(<pin_number>)" ) );
3074 aVars->push_back( wxT( "PIN_NAME(<pin_number>)" ) );
3075 aVars->push_back( wxT( "REFERENCE(<pin_number>)" ) );
3076 aVars->push_back( wxT( "SHORT_REFERENCE(<pin_number>)" ) );
3077 aVars->push_back( wxT( "UNIT(<pin_number>)" ) );
3078}
3079
3080
3081bool SCH_SYMBOL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const
3082{
3083 wxString variant;
3084
3085 if( Schematic() )
3086 variant = Schematic()->GetCurrentVariant();
3087
3088 return ResolveTextVar( aPath, token, variant, aDepth );
3089}
3090
3091
3092bool SCH_SYMBOL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, const wxString& aVariantName,
3093 int aDepth ) const
3094{
3095 // Per-thread regex. CONNECTION_GRAPH::resolveAllDrivers calls this from worker
3096 // threads, and wxRegEx::Matches is not safe to call concurrently on one instance.
3097 thread_local wxRegEx operatingPoint( wxT( "^"
3098 "OP"
3099 "(:[^.]*)?" // pin
3100 "(.([0-9])?" // precisionStr
3101 "([a-zA-Z]*))?" // rangeStr
3102 "$" ) );
3103
3104 if( !aPath )
3105 return false;
3106
3108
3109 if( !schematic )
3110 return false;
3111
3113 && ( operatingPoint.Matches( *token ) || token->StartsWith( wxS( "NET_NAME(" ) )
3114 || token->StartsWith( wxS( "SHORT_NET_NAME(" ) ) || token->StartsWith( wxS( "NET_CLASS(" ) ) ) )
3115 {
3116 token->clear();
3117 return true;
3118 }
3119
3120 if( operatingPoint.Matches( *token ) )
3121 {
3122 wxString pin( operatingPoint.GetMatch( *token, 1 ).Lower() );
3123 wxString precisionStr( operatingPoint.GetMatch( *token, 3 ) );
3124 wxString rangeStr( operatingPoint.GetMatch( *token, 4 ) );
3125
3126 int precision = precisionStr.IsEmpty() ? 3 : precisionStr[0] - '0';
3127 wxString range = rangeStr.IsEmpty() ? wxString( wxS( "~A" ) ) : rangeStr;
3128
3129 SIM_LIB_MGR simLibMgr( &schematic->Project() );
3130
3131 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
3132 embeddedFilesStack.push_back( schematic->GetEmbeddedFiles() );
3133
3134 if( m_part )
3135 {
3136 m_part->AppendParentEmbeddedFiles( embeddedFilesStack );
3137 embeddedFilesStack.push_back( m_part->GetEmbeddedFiles() );
3138 }
3139
3140 simLibMgr.SetFilesStack( std::move( embeddedFilesStack ) );
3141
3142 NULL_REPORTER devnull;
3143 SIM_MODEL& model = simLibMgr.CreateModel( aPath, const_cast<SCH_SYMBOL&>( *this ), true, aDepth + 1,
3144 aVariantName, devnull ).model;
3145 SPICE_ITEM spiceItem;
3146 spiceItem.refName = GetRef( aPath );
3147
3148 wxString spiceRef = model.SpiceGenerator().ItemName( spiceItem );
3149 spiceRef = spiceRef.Lower();
3150
3151 if( pin.IsEmpty() )
3152 {
3153 *token = schematic->GetOperatingPoint( spiceRef, precision, range );
3154 return true;
3155 }
3156 else if( pin == wxS( ":power" ) )
3157 {
3158 if( rangeStr.IsEmpty() )
3159 range = wxS( "~W" );
3160
3161 *token = schematic->GetOperatingPoint( spiceRef + wxS( ":power" ), precision, range );
3162 return true;
3163 }
3164 else
3165 {
3166 pin = pin.SubString( 1, -1 ); // Strip ':' from front
3167
3168 for( const std::reference_wrapper<const SIM_MODEL_PIN>& modelPin : model.GetPins() )
3169 {
3170 SCH_PIN* symbolPin = GetPin( modelPin.get().symbolPinNumber );
3171
3172 if( !symbolPin )
3173 continue;
3174
3175 if( pin == symbolPin->GetName().Lower() || pin == symbolPin->GetNumber().Lower() )
3176 {
3177 if( model.GetPins().size() == 2 )
3178 {
3179 *token = schematic->GetOperatingPoint( spiceRef, precision, range );
3180 }
3181 else
3182 {
3183 wxString netChainName = spiceRef + wxS( ":" ) + modelPin.get().modelPinName;
3184 *token = schematic->GetOperatingPoint( netChainName, precision, range );
3185 }
3186
3187 return true;
3188 }
3189 }
3190 }
3191
3192 *token = wxS( "?" );
3193 return true;
3194 }
3195
3196 if( token->Contains( ':' ) )
3197 {
3198 if( schematic->ResolveCrossReference( token, aDepth + 1 ) )
3199 return true;
3200 }
3201
3202 for( const SCH_FIELD& field : m_fields )
3203 {
3204 wxString fieldName = field.IsMandatory() ? field.GetUntranslatedName() : field.GetName();
3205
3206 wxString textToken = field.GetText();
3207 textToken.Replace( " ", wxEmptyString );
3208 wxString tokenString = "${" + fieldName + "}";
3209
3210 // If the field data is just a reference to the field, don't resolve
3211 if( textToken.IsSameAs( tokenString, false ) )
3212 return true;
3213
3214 if( token->IsSameAs( fieldName, false ) )
3215 {
3216 if( field.GetId() == FIELD_T::REFERENCE )
3217 *token = GetRef( aPath, true );
3218 else
3219 *token = field.GetShownText( aPath, INTERNAL, aVariantName, aDepth + 1 );
3220
3221 return true;
3222 }
3223 }
3224
3225 // Consider missing simulation fields as empty, not un-resolved
3226 if( token->IsSameAs( wxT( "SIM.DEVICE" ) ) || token->IsSameAs( wxT( "SIM.TYPE" ) )
3227 || token->IsSameAs( wxT( "SIM.PINS" ) ) || token->IsSameAs( wxT( "SIM.PARAMS" ) )
3228 || token->IsSameAs( wxT( "SIM.LIBRARY" ) ) || token->IsSameAs( wxT( "SIM.NAME" ) ) )
3229 {
3230 *token = wxEmptyString;
3231 return true;
3232 }
3233
3234 for( const TEMPLATE_FIELDNAME& templateFieldname :
3235 schematic->Project().GetProjectFile().m_TemplateFieldNames.GetResolvedTemplateFieldNames() )
3236 {
3237 if( token->IsSameAs( templateFieldname.m_Name ) || token->IsSameAs( templateFieldname.m_Name.Upper() ) )
3238 {
3239 // If we didn't find it in the fields list then it isn't set on this symbol.
3240 // Just return an empty string.
3241 *token = wxEmptyString;
3242 return true;
3243 }
3244 }
3245
3246 if( token->IsSameAs( wxT( "FOOTPRINT_LIBRARY" ) ) )
3247 {
3248 wxString footprint = GetFootprintFieldText( aPath, INTERNAL, aVariantName );
3249
3250 wxArrayString parts = wxSplit( footprint, ':' );
3251
3252 if( parts.Count() > 0 )
3253 *token = parts[0];
3254 else
3255 *token = wxEmptyString;
3256
3257 return true;
3258 }
3259 else if( token->IsSameAs( wxT( "FOOTPRINT_NAME" ) ) )
3260 {
3261 wxString footprint = GetFootprintFieldText( aPath, INTERNAL, aVariantName );
3262
3263 wxArrayString parts = wxSplit( footprint, ':' );
3264
3265 if( parts.Count() > 1 )
3266 *token = parts[std::min( 1, (int) parts.size() - 1 )];
3267 else
3268 *token = wxEmptyString;
3269
3270 return true;
3271 }
3272 else if( token->IsSameAs( wxT( "UNIT" ) ) )
3273 {
3274 *token = SubReference( GetUnitSelection( aPath ) );
3275 return true;
3276 }
3277 else if( token->IsSameAs( wxT( "SHORT_REFERENCE" ) ) )
3278 {
3279 *token = GetRef( aPath, false );
3280 return true;
3281 }
3282 else if( token->IsSameAs( wxT( "SYMBOL_LIBRARY" ) ) )
3283 {
3284 *token = m_lib_id.GetUniStringLibNickname();
3285 return true;
3286 }
3287 else if( token->IsSameAs( wxT( "SYMBOL_NAME" ) ) )
3288 {
3289 *token = m_lib_id.GetUniStringLibItemName();
3290 return true;
3291 }
3292 else if( token->IsSameAs( wxT( "SYMBOL_DESCRIPTION" ) ) )
3293 {
3294 *token = GetShownDescription( INTERNAL, aDepth + 1 );
3295 return true;
3296 }
3297 else if( token->IsSameAs( wxT( "SYMBOL_KEYWORDS" ) ) )
3298 {
3299 *token = GetShownKeyWords( INTERNAL, aDepth + 1 );
3300 return true;
3301 }
3302 else if( token->IsSameAs( wxT( "SYMBOL_IS_POWER" ) ) )
3303 {
3304 *token = this->IsPower() ? wxString( wxS( "Power Symbol" ) ) : wxString( "" );
3305 return true;
3306 }
3307 else if( token->IsSameAs( wxT( "SYMBOL_IS_LOCAL_POWER" ) ) )
3308 {
3309 *token = this->IsLocalPower() ? wxString( wxS( "Local Power Symbol" ) ) : wxString( "" );
3310 return true;
3311 }
3312 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOM" ) ) )
3313 {
3314 *token = wxEmptyString;
3315
3316 if( aPath->GetExcludedFromBOM( aVariantName ) || this->ResolveExcludedFromBOM( aPath, aVariantName ) )
3317 *token = wxS( "Excluded from BOM" );
3318
3319 return true;
3320 }
3321 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOARD" ) ) )
3322 {
3323 *token = wxEmptyString;
3324
3325 if( aPath->GetExcludedFromBoard( aVariantName ) || this->ResolveExcludedFromBoard( aPath, aVariantName ) )
3326 *token = wxS( "Excluded from board" );
3327
3328 return true;
3329 }
3330 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_SIM" ) ) )
3331 {
3332 *token = wxEmptyString;
3333
3334 if( aPath->GetExcludedFromSim( aVariantName ) || this->ResolveExcludedFromSim( aPath, aVariantName ) )
3335 *token = wxS( "Excluded from simulation" );
3336
3337 return true;
3338 }
3339 else if( token->IsSameAs( wxT( "DNP" ) ) )
3340 {
3341 *token = wxEmptyString;
3342
3343 if( aPath->GetDNP( aVariantName ) || this->ResolveDNP( aPath, aVariantName ) )
3344 *token = wxS( "DNP" );
3345
3346 return true;
3347 }
3348 else if( token->StartsWith( wxT( "SHORT_NET_NAME(" ) ) || token->StartsWith( wxT( "NET_NAME(" ) )
3349 || token->StartsWith( wxT( "NET_CLASS(" ) ) || token->StartsWith( wxT( "PIN_NAME(" ) )
3350 || token->StartsWith( wxT( "PIN_BASE_NAME(" ) ) || token->StartsWith( wxT( "PIN_ALT_LIST(" ) )
3351 || token->StartsWith( wxT( "REFERENCE(" ) ) || token->StartsWith( wxT( "SHORT_REFERENCE(" ) )
3352 || token->StartsWith( wxT( "UNIT(" ) ) )
3353 {
3354 wxString pinNumber = token->AfterFirst( '(' );
3355 pinNumber = pinNumber.BeforeLast( ')' );
3356
3357 auto resolvePinConnection =
3358 [&]( const SCH_PIN& pin, const SCH_SHEET_PATH& path )
3359 {
3360 const bool local = token->StartsWith( wxS( "SHORT_NET_NAME" ) );
3361 const std::optional<wxString> name = pin.GetConnectionName( &path, local );
3362
3363 if( !name )
3364 {
3365 token->clear();
3366 return;
3367 }
3368
3369 if( local )
3370 *token = name->Lower().StartsWith( wxS( "unconnected" ) ) ? wxString( "NC" ) : *name;
3371 else if( token->StartsWith( wxS( "NET_NAME" ) ) )
3372 *token = *name;
3373 else if( token->StartsWith( wxS( "NET_CLASS" ) ) )
3374 *token = pin.GetEffectiveNetClass( &path )->GetName();
3375 };
3376
3377 bool isReferenceFunction = token->StartsWith( wxT( "REFERENCE(" ) );
3378 bool isShortReferenceFunction = token->StartsWith( wxT( "SHORT_REFERENCE(" ) );
3379 bool isUnitFunction = token->StartsWith( wxT( "UNIT(" ) );
3380
3381 // First, try to find the pin in the current unit (for backward compatibility)
3382 // For REFERENCE/SHORT_REFERENCE/UNIT functions, always search all pins to find which unit the pin belongs to
3383 std::vector<const SCH_PIN*> pinsToSearch;
3384 std::vector<const SCH_PIN*> altPinsToSearch;
3385
3386 if( isReferenceFunction || isShortReferenceFunction || isUnitFunction )
3387 {
3388 for( SCH_PIN* pin : GetAllLibPins() )
3389 pinsToSearch.push_back( pin );
3390 }
3391 else
3392 {
3393 for( const SCH_PIN* pin : GetPins( aPath ) )
3394 pinsToSearch.push_back( pin );
3395
3396 for( SCH_PIN* pin : GetAllLibPins() )
3397 altPinsToSearch.push_back( pin );
3398 }
3399
3400 for( const SCH_PIN* pin : pinsToSearch )
3401 {
3402 if( pin->GetNumber() == pinNumber )
3403 {
3404 if( isReferenceFunction || isShortReferenceFunction || isUnitFunction )
3405 {
3406 int pinUnit = pin->GetUnit();
3407 wxString result;
3408
3409 if( isReferenceFunction )
3410 {
3411 // Return the full unit reference (e.g., "J601A")
3412 if( pinUnit != ALL_UNITS )
3413 result = GetUnitRef( aPath, pinUnit );
3414 else
3415 result = GetRef( aPath, false );
3416 }
3417 else if( isShortReferenceFunction )
3418 {
3419 // Return the reference without unit (e.g., "J601")
3420 result = GetRef( aPath, false );
3421 }
3422 else if( isUnitFunction )
3423 {
3424 // Return only the unit letter (e.g., "A")
3425 if( pinUnit != ALL_UNITS )
3426 result = SubReference( pinUnit, false );
3427 else
3428 result = wxEmptyString;
3429 }
3430
3431 *token = std::move( result );
3432 return true;
3433 }
3434 else if( token->StartsWith( wxT( "PIN_NAME" ) ) )
3435 {
3436 *token = pin->GetAlt().IsEmpty() ? pin->GetName() : pin->GetAlt();
3437 return true;
3438 }
3439 else if( token->StartsWith( wxT( "PIN_BASE_NAME" ) ) )
3440 {
3441 *token = pin->GetBaseName();
3442 return true;
3443 }
3444 else if( token->StartsWith( wxT( "PIN_ALT_LIST" ) ) )
3445 {
3446 // Build list of alternate names only (no base name)
3447 wxString altList;
3448
3449 const std::map<wxString, SCH_PIN::ALT>& alts = pin->GetAlternates();
3450
3451 for( const auto& [altName, altDef] : alts )
3452 {
3453 if( !altList.IsEmpty() )
3454 altList += wxT( ", " );
3455
3456 altList += altName;
3457 }
3458
3459 *token = std::move( altList );
3460 return true;
3461 }
3462
3463 resolvePinConnection( *pin, *aPath );
3464
3465 return true;
3466 }
3467 }
3468
3469 // If pin not found in current unit, search all units (auto-resolution)
3470 for( const SCH_PIN* pin : altPinsToSearch )
3471 {
3472 if( pin->GetNumber() == pinNumber )
3473 {
3474 // For PIN_BASE_NAME and PIN_ALT_LIST, we can use library data
3475 if( token->StartsWith( wxT( "PIN_BASE_NAME" ) ) )
3476 {
3477 *token = pin->GetBaseName();
3478 return true;
3479 }
3480 else if( token->StartsWith( wxT( "PIN_ALT_LIST" ) ) )
3481 {
3482 // Build list of alternate names only (no base name)
3483 wxString altList;
3484
3485 const std::map<wxString, SCH_PIN::ALT>& alts = pin->GetAlternates();
3486
3487 for( const auto& [altName, altDef] : alts )
3488 {
3489 if( !altList.IsEmpty() )
3490 altList += wxT( ", " );
3491 altList += altName;
3492 }
3493
3494 *token = altList;
3495 return true;
3496 }
3497
3498 // For net-related functions, find which sheet path has this pin's unit
3499 int pinUnit = pin->GetUnit();
3500
3501 // Search all sheets for a symbol with our reference and the correct unit
3502 // This is needed because each unit of a multi-unit symbol is a separate object
3503 SCH_SHEET_PATH targetPath;
3504 SCH_SYMBOL* targetSymbol = nullptr;
3505
3506 if( Schematic() )
3507 {
3508 for( const SCH_SHEET_PATH& sheetPath : Schematic()->Hierarchy() )
3509 {
3510 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
3511 {
3512 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
3513
3514 // Check if this symbol has the same reference designator and the correct unit
3515 if( symbol->GetRef( &sheetPath, false ) == GetRef( aPath, false )
3516 && symbol->GetUnitSelection( &sheetPath ) == pinUnit )
3517 {
3518 targetPath = sheetPath; // Copy the sheet path
3519 targetSymbol = symbol;
3520 break;
3521 }
3522 }
3523
3524 if( targetSymbol )
3525 break;
3526 }
3527 }
3528
3529 if( !targetSymbol )
3530 {
3531 // Unit not placed on any sheet
3532 *token = wxString::Format( wxT( "<Unit %s not placed>" ), SubReference( pinUnit, false ) );
3533 return true;
3534 }
3535
3536 // Get the pin from the actual instance symbol we found
3537 // Match by pin number, not by pointer, since the library pins are different objects
3538 SCH_PIN* instancePin = nullptr;
3539
3540 for( SCH_PIN* candidate : targetSymbol->GetPins( &targetPath ) )
3541 {
3542 if( candidate->GetNumber() == pinNumber )
3543 {
3544 instancePin = candidate;
3545 break;
3546 }
3547 }
3548
3549 if( !instancePin )
3550 {
3551 *token = wxEmptyString;
3552 return true;
3553 }
3554
3555 // PIN_NAME doesn't need connection data, just instance pin
3556 if( token->StartsWith( wxT( "PIN_NAME" ) ) )
3557 {
3558 *token = instancePin->GetAlt().IsEmpty() ? instancePin->GetName() : instancePin->GetAlt();
3559 return true;
3560 }
3561
3562 resolvePinConnection( *instancePin, targetPath );
3563
3564 return true;
3565 }
3566 }
3567
3568 // If we got here, no pin was found - report unresolved
3569 *token = wxString::Format( wxT( "<Unresolved: pin %s>" ), pinNumber );
3570 return true;
3571 }
3572 // The great property resolver: ${PROPERTY.My_Property}
3573 else if( token->StartsWith( wxS( "PROPERTY." ) ) )
3574 {
3575 // Get the second half, convert _ to ' '
3576 wxString propertyName = token->AfterFirst( '.' );
3577 propertyName.Replace( wxS( "_" ), wxS( " " ) );
3578
3579 // Check if the property manager knows this property
3581 PROPERTY_BASE* property = propMgr.GetProperty( TYPE_HASH( *this ), propertyName );
3582
3583 if( !property )
3584 {
3585 for( PROPERTY_BASE* candidate : GetDynamicProperties( aPath ) )
3586 {
3587 if( propertyName.CmpNoCase( candidate->Name() ) == 0 )
3588 {
3589 property = candidate;
3590 break;
3591 }
3592 }
3593 }
3594
3595 if( !property || property->IsHiddenFromPropertiesManager() )
3596 return false;
3597
3598 if( !propMgr.IsAvailableFor( TYPE_HASH( *this ), property, const_cast<SCH_SYMBOL*>( this ) ) )
3599 return false;
3600
3601 // Property-panel getters use the displayed instance, which may differ from this text's path.
3602 wxAny sourceValue;
3603 const wxString& name = property->Name();
3604
3605 if( name == wxS( "Reference" ) )
3606 sourceValue = GetRef( aPath );
3607 else if( name == wxS( "Value" ) )
3608 sourceValue = GetValue( aPath, RAW_VALUE, aVariantName );
3609 else if( name == wxS( "Unit" ) )
3610 sourceValue = GetUnitSelection( aPath );
3611 else if( name == wxS( "Exclude From Simulation" ) )
3612 sourceValue = GetExcludedFromSim( aPath, aVariantName );
3613 else if( name == wxS( "Exclude From Bill of Materials" ) )
3614 sourceValue = GetExcludedFromBOM( aPath, aVariantName );
3615 else if( name == wxS( "Exclude From Board" ) )
3616 sourceValue = GetExcludedFromBoard( aPath, aVariantName );
3617 else if( name == wxS( "Exclude From Position Files" ) )
3618 sourceValue = GetExcludedFromPosFiles( aPath, aVariantName );
3619 else if( name == wxS( "Do not Populate" ) )
3620 sourceValue = GetDNP( aPath, aVariantName );
3621 else if( auto* instanceProperty = dynamic_cast<SCH_SYMBOL_INSTANCE_PROPERTY*>( property ) )
3622 sourceValue = instanceProperty->ValueForInstance( this, aPath, aVariantName );
3623 else
3624 sourceValue = Get( property );
3625
3626 KICAD_DIFF::DIFF_VALUE value = KICAD_DIFF::WxAnyToDiffValue( sourceValue, property );
3627
3629 return false;
3630
3631 *token = value.ToDisplayString( EDA_UNITS::MILS, schIUScale );
3632 return true;
3633 }
3634
3635 // See if parent can resolve it (this will recurse to ancestors)
3636 if( aPath->Last() && aPath->Last()->ResolveTextVar( aPath, token, aDepth + 1 ) )
3637 return true;
3638
3639 return false;
3640}
3641
3642
3643void SCH_SYMBOL::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath, bool aResetPrefix )
3644{
3645 if( aSheetPath )
3646 {
3647 KIID_PATH path = aSheetPath->Path();
3648
3649 for( SCH_SYMBOL_INSTANCE& instance : m_instances )
3650 {
3651 if( instance.m_Path == path )
3652 {
3653 if( instance.m_Reference.IsEmpty() || aResetPrefix )
3654 instance.m_Reference = UTIL::GetRefDesUnannotated( m_prefix );
3655 else
3656 instance.m_Reference = UTIL::GetRefDesUnannotated( instance.m_Reference );
3657
3658 instance.m_RefLacksSuffix = false;
3659 }
3660 }
3661 }
3662 else
3663 {
3664 for( SCH_SYMBOL_INSTANCE& instance : m_instances )
3665 {
3666 if( instance.m_Reference.IsEmpty() || aResetPrefix )
3667 instance.m_Reference = UTIL::GetRefDesUnannotated( m_prefix );
3668 else
3669 instance.m_Reference = UTIL::GetRefDesUnannotated( instance.m_Reference );
3670
3671 instance.m_RefLacksSuffix = false;
3672 }
3673 }
3674
3675 for( std::unique_ptr<SCH_PIN>& pin : m_pins )
3676 pin->ClearDefaultNetName( aSheetPath );
3677
3679
3680 // Only modify the REFERENCE field text when clearing ALL annotations (aSheetPath is NULL).
3681 // When clearing for a specific sheet path, we must preserve the field text because it serves
3682 // as a fallback for GetRef() when instances for other sheet paths are looked up.
3683 // See issue #20173: modifying field text here corrupts references in shared screens.
3684 if( !aSheetPath )
3685 {
3686 wxString currentReference = GetField( FIELD_T::REFERENCE )->GetText();
3687
3688 if( currentReference.IsEmpty() || aResetPrefix )
3690 else
3692 }
3693}
3694
3695
3697{
3698 // An empty sheet path is illegal, at a minimum the root sheet UUID must be present.
3699 wxCHECK( aSheetPath.size() > 0, false );
3700
3701 for( const SCH_SYMBOL_INSTANCE& instance : m_instances )
3702 {
3703 // if aSheetPath is found, nothing to do:
3704 if( instance.m_Path == aSheetPath )
3705 return false;
3706 }
3707
3708 // This entry does not exist: add it, with its last-used reference
3709 AddHierarchicalReference( aSheetPath, GetField( FIELD_T::REFERENCE )->GetText(), m_unit );
3710 return true;
3711}
3712
3713
3714bool SCH_SYMBOL::SetInstanceProjectName( const KIID_PATH& aSheetPath, const wxString& aProjectName )
3715{
3716 SCH_SYMBOL_INSTANCE* instance = getInstance( aSheetPath );
3717
3718 if( !instance )
3719 return false;
3720
3721 instance->m_ProjectName = aProjectName;
3722 return true;
3723}
3724
3725
3726void SCH_SYMBOL::SetOrientation( int aOrientation )
3727{
3728 TRANSFORM temp = TRANSFORM();
3729 bool transform = false;
3730
3731 switch( aOrientation )
3732 {
3733 case SYM_ORIENT_0:
3734 case SYM_NORMAL: // default transform matrix
3736 break;
3737
3738 case SYM_ROTATE_COUNTERCLOCKWISE: // Rotate + (incremental rotation)
3739 temp.x1 = 0;
3740 temp.y1 = 1;
3741 temp.x2 = -1;
3742 temp.y2 = 0;
3743 transform = true;
3744 break;
3745
3746 case SYM_ROTATE_CLOCKWISE: // Rotate - (incremental rotation)
3747 temp.x1 = 0;
3748 temp.y1 = -1;
3749 temp.x2 = 1;
3750 temp.y2 = 0;
3751 transform = true;
3752 break;
3753
3754 case SYM_MIRROR_Y: // Mirror Y (incremental transform)
3755 temp.x1 = -1;
3756 temp.y1 = 0;
3757 temp.x2 = 0;
3758 temp.y2 = 1;
3759 transform = true;
3760 break;
3761
3762 case SYM_MIRROR_X: // Mirror X (incremental transform)
3763 temp.x1 = 1;
3764 temp.y1 = 0;
3765 temp.x2 = 0;
3766 temp.y2 = -1;
3767 transform = true;
3768 break;
3769
3770 case SYM_ORIENT_90:
3773 break;
3774
3775 case SYM_ORIENT_180:
3779 break;
3780
3781 case SYM_ORIENT_270:
3784 break;
3785
3786 case( SYM_ORIENT_0 + SYM_MIRROR_X ):
3789 break;
3790
3791 case( SYM_ORIENT_0 + SYM_MIRROR_Y ):
3794 break;
3795
3800 break;
3801
3802 case( SYM_ORIENT_90 + SYM_MIRROR_X ):
3805 break;
3806
3807 case( SYM_ORIENT_90 + SYM_MIRROR_Y ):
3810 break;
3811
3816 break;
3817
3818 case( SYM_ORIENT_180 + SYM_MIRROR_X ):
3821 break;
3822
3823 case( SYM_ORIENT_180 + SYM_MIRROR_Y ):
3826 break;
3827
3832 break;
3833
3834 case( SYM_ORIENT_270 + SYM_MIRROR_X ):
3837 break;
3838
3839 case( SYM_ORIENT_270 + SYM_MIRROR_Y ):
3842 break;
3843
3848 break;
3849
3850 default:
3851 transform = false;
3852 wxFAIL_MSG( "Invalid schematic symbol orientation type." );
3853 break;
3854 }
3855
3856 if( transform )
3857 {
3858 /* The new matrix transform is the old matrix transform modified by the
3859 * requested transformation, which is the temp transform (rot,
3860 * mirror ..) in order to have (in term of matrix transform):
3861 * transform coord = new_m_transform * coord
3862 * where transform coord is the coord modified by new_m_transform from
3863 * the initial value coord.
3864 * new_m_transform is computed (from old_m_transform and temp) to
3865 * have:
3866 * transform coord = old_m_transform * temp
3867 */
3868 TRANSFORM newTransform;
3869
3870 newTransform.x1 = m_transform.x1 * temp.x1 + m_transform.x2 * temp.y1;
3871 newTransform.y1 = m_transform.y1 * temp.x1 + m_transform.y2 * temp.y1;
3872 newTransform.x2 = m_transform.x1 * temp.x2 + m_transform.x2 * temp.y2;
3873 newTransform.y2 = m_transform.y1 * temp.x2 + m_transform.y2 * temp.y2;
3874 m_transform = newTransform;
3875 }
3876}
3877
3878
3880{
3881 /*
3882 * This is slow, but also a bizarre algorithm. I don't feel like unteasing the algorithm right
3883 * now, so let's just cache it for the moment.
3884 */
3887
3888 int rotate_values[] = { SYM_ORIENT_0,
3900
3901 // Try to find the current transform option:
3902 TRANSFORM transform = m_transform;
3903 SCH_SYMBOL temp( *this );
3904 temp.SetParentGroup( nullptr );
3905
3906 for( int type_rotate : rotate_values )
3907 {
3908 temp.SetOrientation( type_rotate );
3909
3910 if( transform == temp.GetTransform() )
3911 {
3913 return type_rotate;
3914 }
3915 }
3916
3917 // Error: orientation not found in list (should not happen)
3918 wxFAIL_MSG( "Schematic symbol orientation matrix internal error." );
3919
3920 return SYM_NORMAL;
3921}
3922
3923
3924#if defined( DEBUG )
3925
3926void SCH_SYMBOL::Show( int nestLevel, std::ostream& os ) const
3927{
3928 // for now, make it look like XML:
3929 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << " ref=\""
3930 << TO_UTF8( GetField( FIELD_T::REFERENCE )->GetName() ) << '"' << " chipName=\""
3931 << GetLibId().Format().wx_str() << '"' << m_pos << " layer=\"" << m_layer << '"'
3932 << ">\n";
3933
3934 // skip the reference, it's been output already.
3935 for( int i = 1; i < (int) GetFields().size(); ++i )
3936 {
3937 const wxString& value = GetFields()[i].GetText();
3938
3939 if( !value.IsEmpty() )
3940 {
3941 NestedSpace( nestLevel + 1, os ) << "<field" << " name=\"" << TO_UTF8( GetFields()[i].GetName() ) << '"'
3942 << " value=\"" << TO_UTF8( value ) << "\"/>\n";
3943 }
3944 }
3945
3946 NestedSpace( nestLevel, os ) << "</" << TO_UTF8( GetClass().Lower() ) << ">\n";
3947}
3948
3949#endif
3950
3951
3952BOX2I SCH_SYMBOL::doGetBoundingBox( bool aIncludePins, bool aIncludeFields ) const
3953{
3954 BOX2I bBox;
3955 const SCH_SHEET_PATH* sheetPath = Schematic() ? &Schematic()->CurrentSheet() : nullptr;
3956 const LIB_SYMBOL* effSym = GetEffectiveLibSymbol( sheetPath );
3957
3958 if( effSym )
3959 bBox = effSym->GetBodyBoundingBox( m_unit, m_bodyStyle, aIncludePins, false );
3960 else
3961 bBox = LIB_SYMBOL::GetDummy()->GetBodyBoundingBox( m_unit, m_bodyStyle, aIncludePins, false );
3962
3963 bBox = m_transform.TransformCoordinate( bBox );
3964 bBox.Normalize();
3965
3966 bBox.Offset( m_pos );
3967
3968 if( aIncludeFields )
3969 {
3970 for( const SCH_FIELD& field : m_fields )
3971 {
3972 if( field.IsVisible() )
3973 bBox.Merge( field.GetBoundingBox() );
3974 }
3975 }
3976
3977 return bBox;
3978}
3979
3980
3982{
3983 try
3984 {
3985 return doGetBoundingBox( false, false );
3986 }
3987 catch( const boost::bad_pointer& e )
3988 {
3989 wxFAIL_MSG( wxString::Format( wxT( "Boost pointer exception occurred: %s" ), e.what() ) );
3990 return BOX2I();
3991 }
3992}
3993
3994
3996{
3997 return doGetBoundingBox( true, false );
3998}
3999
4000
4002{
4003 return doGetBoundingBox( true, true );
4004}
4005
4006
4007void SCH_SYMBOL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
4008{
4009 wxString msg;
4010
4011 SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
4012 SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
4013 wxString currentVariant = Schematic() ? Schematic()->GetCurrentVariant() : wxString();
4014
4015 auto addExcludes =
4016 [&]()
4017 {
4018 wxArrayString msgs;
4019
4020 if( GetExcludedFromSim() )
4021 msgs.Add( _( "Simulation" ) );
4022
4023 if( GetExcludedFromBOM() )
4024 msgs.Add( _( "BOM" ) );
4025
4026 if( GetExcludedFromBoard() )
4027 msgs.Add( _( "Board" ) );
4028
4029 if( GetDNP( currentSheet, currentVariant ) )
4030 msgs.Add( _( "DNP" ) );
4031
4032 msg = wxJoin( msgs, '|' );
4033 msg.Replace( '|', wxS( ", " ) );
4034
4035 if( !msg.empty() )
4036 aList.emplace_back( _( "Exclude from" ), msg );
4037 };
4038
4039 // part and alias can differ if alias is not the root
4040 if( m_part )
4041 {
4042 if( m_part.get() != LIB_SYMBOL::GetDummy() )
4043 {
4044 if( m_part->IsPower() )
4045 {
4046 // Don't use GetShownText(); we want to see the variable references here
4047 aList.emplace_back( _( "Power symbol" ),
4048 KIUI::EllipsizeStatusText( aFrame, GetField( FIELD_T::VALUE )->GetText() ) );
4049 }
4050 else
4051 {
4052 aList.emplace_back( _( "Reference" ), UnescapeString( GetRef( currentSheet ) ) );
4053
4054 // Don't use GetShownText(); we want to see the variable references here
4055 aList.emplace_back( _( "Value" ),
4056 KIUI::EllipsizeStatusText( aFrame, GetField( FIELD_T::VALUE )->GetText() ) );
4057 addExcludes();
4058 aList.emplace_back( _( "Name" ), KIUI::EllipsizeStatusText( aFrame, GetLibId().GetLibItemName() ) );
4059 }
4060
4061#if 0 // Display symbol flags, for debug only
4062 aList.emplace_back( _( "flags" ), wxString::Format( "%X", GetEditFlags() ) );
4063#endif
4064
4065 if( !m_part->IsRoot() )
4066 {
4067 msg = _( "Missing parent" );
4068
4069 std::shared_ptr<LIB_SYMBOL> parent = m_part->GetParent().lock();
4070
4071 if( parent )
4072 msg = parent->GetName();
4073
4074 aList.emplace_back( _( "Derived from" ), UnescapeString( msg ) );
4075 }
4076 else if( !m_lib_id.GetLibNickname().empty() )
4077 {
4078 aList.emplace_back( _( "Library" ), m_lib_id.GetLibNickname() );
4079 }
4080 else
4081 {
4082 aList.emplace_back( _( "Library" ), _( "Undefined!!!" ) );
4083 }
4084
4085 // Display the current associated footprint, if exists.
4086 // Don't use GetShownText(); we want to see the variable references here
4087 msg = KIUI::EllipsizeStatusText( aFrame, GetField( FIELD_T::FOOTPRINT )->GetText() );
4088
4089 if( msg.IsEmpty() )
4090 msg = _( "<Unknown>" );
4091
4092 aList.emplace_back( _( "Footprint" ), msg );
4093
4094 // Display description of the symbol, and keywords found in lib
4095 aList.emplace_back( _( "Description" ) + wxT( ": " ) + GetField( FIELD_T::DESCRIPTION )->GetText(),
4096 _( "Keywords" ) + wxT( ": " ) + m_part->GetKeyWords() );
4097 }
4098 }
4099 else
4100 {
4101 aList.emplace_back( _( "Reference" ), GetRef( currentSheet ) );
4102
4103 // Don't use GetShownText(); we want to see the variable references here
4104 aList.emplace_back( _( "Value" ), KIUI::EllipsizeStatusText( aFrame, GetField( FIELD_T::VALUE )->GetText() ) );
4105 addExcludes();
4106 aList.emplace_back( _( "Name" ), KIUI::EllipsizeStatusText( aFrame, GetLibId().GetLibItemName() ) );
4107
4108 wxString libNickname = GetLibId().GetLibNickname();
4109
4110 if( libNickname.empty() )
4111 msg = _( "No library defined!" );
4112 else
4113 msg.Printf( _( "Symbol not found in %s!" ), libNickname );
4114
4115 aList.emplace_back( _( "Library" ), msg );
4116 }
4117}
4118
4119
4124
4125
4127{
4128 if( std::unique_ptr<LIB_SYMBOL>& libSymbol = GetLibSymbolRef() )
4129 return libSymbol->GetEmbeddedFiles();
4130
4131 return nullptr;
4132}
4133
4134
4136{
4137 int dx = m_pos.x;
4138
4140 MIRROR( m_pos.x, aCenter );
4141 dx -= m_pos.x; // dx,0 is the move vector for this transform
4142
4143 for( SCH_FIELD& field : m_fields )
4144 {
4145 // Move the fields to the new position because the symbol itself has moved.
4146 VECTOR2I pos = field.GetTextPos();
4147 pos.x -= dx;
4148 field.SetTextPos( pos );
4149 }
4150}
4151
4152
4154{
4155 int dy = m_pos.y;
4156
4158 MIRROR( m_pos.y, aCenter );
4159 dy -= m_pos.y; // 0,dy is the move vector for this transform
4160
4161 for( SCH_FIELD& field : m_fields )
4162 {
4163 // Move the fields to the new position because the symbol itself has moved.
4164 VECTOR2I pos = field.GetTextPos();
4165 pos.y -= dy;
4166 field.SetTextPos( pos );
4167 }
4168}
4169
4170
4171void SCH_SYMBOL::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
4172{
4173 VECTOR2I prev = m_pos;
4174
4175 RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
4176
4178
4179 for( SCH_FIELD& field : m_fields )
4180 {
4181 // Move the fields to the new position because the symbol itself has moved.
4182 VECTOR2I pos = field.GetTextPos();
4183 pos.x -= prev.x - m_pos.x;
4184 pos.y -= prev.y - m_pos.y;
4185 field.SetTextPos( pos );
4186 }
4187}
4188
4189
4190bool SCH_SYMBOL::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
4191{
4192 if( aSearchData.searchMetadata )
4193 {
4194 if( EDA_ITEM::Matches( GetSchSymbolLibraryName(), aSearchData ) )
4195 return true;
4196
4197 if( EDA_ITEM::Matches( GetShownDescription( FOR_GUI ), aSearchData ) )
4198 return true;
4199
4200 if( EDA_ITEM::Matches( GetShownKeyWords( FOR_GUI ), aSearchData ) )
4201 return true;
4202 }
4203
4204 // Fields are searched as separate items
4205
4206 // Search non-field lib draw items (pins, graphical text) for completeness.
4207 if( const std::unique_ptr<LIB_SYMBOL>& libSymbol = GetLibSymbolRef() )
4208 {
4209 for( const SCH_ITEM& drawItem : libSymbol->GetDrawItems() )
4210 {
4211 if( drawItem.Type() == SCH_FIELD_T )
4212 continue;
4213
4214 if( drawItem.Matches( aSearchData, aAuxData ) )
4215 return true;
4216 }
4217 }
4218
4219 // Symbols are searchable via the child field and pin item text.
4220 return false;
4221}
4222
4223
4224void SCH_SYMBOL::GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList )
4225{
4226 for( std::unique_ptr<SCH_PIN>& pin : m_pins )
4227 {
4228 if( SCH_PIN* lib_pin = pin->GetLibPin() )
4229 {
4230 if( lib_pin->GetUnit() != ALL_UNITS && m_unit != ALL_UNITS && m_unit != lib_pin->GetUnit() )
4231 continue;
4232
4233 DANGLING_END_ITEM item( PIN_END, lib_pin, GetPinPhysicalPosition( lib_pin ), this );
4234 aItemList.push_back( item );
4235 }
4236 }
4237}
4238
4239
4240bool SCH_SYMBOL::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
4241 std::vector<DANGLING_END_ITEM>& aItemListByPos, const SCH_SHEET_PATH* aPath )
4242{
4243 bool changed = false;
4244
4245 for( std::unique_ptr<SCH_PIN>& pin : m_pins )
4246 {
4247 bool previousState = pin->IsDangling();
4248 pin->SetIsDangling( true );
4249
4250 VECTOR2I pos = m_transform.TransformCoordinate( pin->GetLocalPosition() ) + m_pos;
4251
4252 auto lower = DANGLING_END_ITEM_HELPER::get_lower_pos( aItemListByPos, pos );
4253 bool do_break = false;
4254
4255 for( auto it = lower; it < aItemListByPos.end() && it->GetPosition() == pos; it++ )
4256 {
4257 DANGLING_END_ITEM& each_item = *it;
4258
4259 // Some people like to stack pins on top of each other in a symbol to indicate
4260 // internal connection. While technically connected, it is not particularly useful
4261 // to display them that way, so skip any pins that are in the same symbol as this
4262 // one.
4263 if( each_item.GetParent() == this )
4264 continue;
4265
4266 switch( each_item.GetType() )
4267 {
4268 case PIN_END:
4269 case LABEL_END:
4270 case SHEET_LABEL_END:
4271 case WIRE_END:
4272 case NO_CONNECT_END:
4273 case JUNCTION_END:
4274 pin->SetIsDangling( false );
4275 do_break = true;
4276 break;
4277
4278 default: break;
4279 }
4280
4281 if( do_break )
4282 break;
4283 }
4284
4285 changed = ( changed || ( previousState != pin->IsDangling() ) );
4286 }
4287
4288 return changed;
4289}
4290
4291
4293{
4294 if( ( aPin == nullptr ) || ( aPin->Type() != SCH_PIN_T ) )
4295 return VECTOR2I( 0, 0 );
4296
4297 return m_transform.TransformCoordinate( aPin->GetPosition() ) + m_pos;
4298}
4299
4300
4301bool SCH_SYMBOL::HasConnectivityChanges( const SCH_ITEM* aItem, const SCH_SHEET_PATH* aInstance ) const
4302{
4303 // Do not compare to ourself.
4304 if( aItem == this )
4305 return false;
4306
4307 const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( aItem );
4308
4309 // Don't compare against a different SCH_ITEM.
4310 wxCHECK( symbol, false );
4311
4312 // The move algorithm marks any pins that are being moved without something attached
4313 // (during the move) as dangling. We always need to recheck connectivity in this case
4314 // or we will not notice changes when the user places the symbol back in the same position
4315 // it started.
4316 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
4317 {
4318 if( pin->IsDangling() )
4319 return true;
4320 }
4321
4322 if( GetPosition() != symbol->GetPosition() )
4323 return true;
4324
4325 if( GetLibId() != symbol->GetLibId() )
4326 return true;
4327
4328 if( GetPassthroughMode() != symbol->GetPassthroughMode() )
4329 return true;
4330
4331 if( GetUnitSelection( aInstance ) != symbol->GetUnitSelection( aInstance ) )
4332 return true;
4333
4334 // Both sit on one path, so their bases differ exactly when their references do
4335 if( GetBaseRef( aInstance ) != symbol->GetBaseRef( aInstance ) )
4336 return true;
4337
4338 // Power symbol value field changes are connectivity changes.
4339 if( IsPower() && ( GetValue( aInstance, FOR_NETNAME ) != symbol->GetValue( aInstance, FOR_NETNAME ) ) )
4340 return true;
4341
4342 if( IsLocalPower() != symbol->IsLocalPower() )
4343 return true;
4344
4345 if( m_pins.size() != symbol->m_pins.size() )
4346 return true;
4347
4348 for( size_t i = 0; i < m_pins.size(); i++ )
4349 {
4350 if( m_pins[i]->HasConnectivityChanges( symbol->m_pins[i].get() ) )
4351 return true;
4352 }
4353
4354 return false;
4355}
4356
4357
4358std::vector<VECTOR2I> SCH_SYMBOL::GetConnectionPoints() const
4359{
4360 std::vector<VECTOR2I> retval;
4361
4362 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
4363 {
4364 // Collect only pins attached to the current unit and convert.
4365 // others are not associated to this symbol instance
4366 int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit() : GetUnit();
4367 int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle() : GetBodyStyle();
4368
4369 if( pin_unit != ALL_UNITS && pin_unit != GetUnit() )
4370 continue;
4371
4372 if( pin_bodyStyle != ALL_BODY_STYLES && pin_bodyStyle != GetBodyStyle() )
4373 continue;
4374
4375 retval.push_back( m_transform.TransformCoordinate( pin->GetLocalPosition() ) + m_pos );
4376 }
4377
4378 return retval;
4379}
4380
4381
4383{
4384 const SCH_SHEET_PATH* sheet = Schematic() ? &Schematic()->CurrentSheet() : nullptr;
4385 LIB_SYMBOL* effectiveSymbol = const_cast<LIB_SYMBOL*>( GetEffectiveLibSymbol( sheet ) );
4386
4387 if( effectiveSymbol )
4388 {
4389 // Calculate the position relative to the symbol.
4390 VECTOR2I libPosition = aPosition - m_pos;
4391
4392 return effectiveSymbol->LocateDrawItem( m_unit, m_bodyStyle, aType, libPosition, m_transform );
4393 }
4394
4395 return nullptr;
4396}
4397
4398
4399wxString SCH_SYMBOL::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
4400{
4401 return wxString::Format( _( "Symbol %s [%s]" ),
4403 KIUI::EllipsizeMenuText( GetLibId().GetLibItemName() ) );
4404}
4405
4406
4407INSPECT_RESULT SCH_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData, const std::vector<KICAD_T>& aScanTypes )
4408{
4409 for( KICAD_T scanType : aScanTypes )
4410 {
4411 if( scanType == SCH_LOCATE_ANY_T || ( scanType == SCH_SYMBOL_T )
4412 || ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
4413 {
4414 if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) )
4415 return INSPECT_RESULT::QUIT;
4416 }
4417
4418 if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_FIELD_T )
4419 {
4420 for( SCH_FIELD& field : m_fields )
4421 {
4422 if( INSPECT_RESULT::QUIT == aInspector( &field, (void*) this ) )
4423 return INSPECT_RESULT::QUIT;
4424 }
4425 }
4426
4427 if( scanType == SCH_FIELD_LOCATE_REFERENCE_T )
4428 {
4429 if( INSPECT_RESULT::QUIT == aInspector( GetField( FIELD_T::REFERENCE ), (void*) this ) )
4430 return INSPECT_RESULT::QUIT;
4431 }
4432
4433 if( scanType == SCH_FIELD_LOCATE_VALUE_T
4434 || ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
4435 {
4436 if( INSPECT_RESULT::QUIT == aInspector( GetField( FIELD_T::VALUE ), (void*) this ) )
4437 return INSPECT_RESULT::QUIT;
4438 }
4439
4440 if( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T )
4441 {
4442 if( INSPECT_RESULT::QUIT == aInspector( GetField( FIELD_T::FOOTPRINT ), (void*) this ) )
4443 return INSPECT_RESULT::QUIT;
4444 }
4445
4446 if( scanType == SCH_FIELD_LOCATE_DATASHEET_T )
4447 {
4448 if( INSPECT_RESULT::QUIT == aInspector( GetField( FIELD_T::DATASHEET ), (void*) this ) )
4449 return INSPECT_RESULT::QUIT;
4450 }
4451
4452 if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_PIN_T )
4453 {
4454 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
4455 {
4456 // Collect only pins attached to the current unit and convert.
4457 // others are not associated to this symbol instance
4458 int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit() : GetUnit();
4459 int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle() : GetBodyStyle();
4460
4461 if( pin_unit != ALL_UNITS && pin_unit != GetUnit() )
4462 continue;
4463
4464 if( pin_bodyStyle != ALL_BODY_STYLES && pin_bodyStyle != GetBodyStyle() )
4465 continue;
4466
4467 if( INSPECT_RESULT::QUIT == aInspector( pin.get(), (void*) this ) )
4468 return INSPECT_RESULT::QUIT;
4469 }
4470 }
4471 }
4472
4474}
4475
4476
4477bool SCH_SYMBOL::operator<( const SCH_ITEM& aItem ) const
4478{
4479 if( Type() != aItem.Type() )
4480 return Type() < aItem.Type();
4481
4482 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( &aItem );
4483
4485
4486 if( rect.GetArea() != symbol->GetBodyAndPinsBoundingBox().GetArea() )
4487 return rect.GetArea() < symbol->GetBodyAndPinsBoundingBox().GetArea();
4488
4489 if( m_pos.x != symbol->m_pos.x )
4490 return m_pos.x < symbol->m_pos.x;
4491
4492 if( m_pos.y != symbol->m_pos.y )
4493 return m_pos.y < symbol->m_pos.y;
4494
4495 if( m_prefix != symbol->m_prefix )
4496 return m_prefix < symbol->m_prefix;
4497
4498 if( m_schLibSymbolName != symbol->m_schLibSymbolName )
4499 return m_schLibSymbolName < symbol->m_schLibSymbolName;
4500
4501 return m_Uuid < aItem.m_Uuid; // Ensure deterministic sort
4502}
4503
4504
4505bool SCH_SYMBOL::operator==( const SCH_SYMBOL& aSymbol ) const
4506{
4507 // Don't compare m_lib_id: it may be instance-specific. Compare m_schLibSymbolName
4508 // instead.
4509 if( m_schLibSymbolName != aSymbol.m_schLibSymbolName )
4510 return false;
4511
4512 // m_prefix is an interesting one. It's sort of part of the annotation, which we don't
4513 // compare, but it's also sort of a higher level than the annotation itself. For now,
4514 // we skip it along with the annotation (FIELD_T::REFERENCE).
4515#if 0
4516 if( m_prefix != aSymbol.m_prefix )
4517 return false;
4518#endif
4519
4520 std::vector<SCH_FIELD*> fields, otherFields;
4521
4522 GetFields( fields, false );
4523 aSymbol.GetFields( otherFields, false );
4524
4525 if( fields.size() != otherFields.size() )
4526 return false;
4527
4528 for( int ii = 0; ii < (int) fields.size(); ii++ )
4529 {
4530 if( fields[ii]->GetId() == FIELD_T::REFERENCE )
4531 continue;
4532
4533 if( fields[ii]->GetText().Cmp( otherFields[ii]->GetText() ) != 0 )
4534 return false;
4535 }
4536
4537 if( m_doNetlist != aSymbol.m_doNetlist )
4538 return false;
4539
4540 if( m_passthroughMode != aSymbol.m_passthroughMode )
4541 return false;
4542
4543 // m_signalName has more to do with the placement on the schematic than the symbol itself
4544#if 0
4545 if( m_signalName != aSymbol.m_signalName )
4546 return false;
4547#endif
4548
4549 // Running the pin compare on matched pins found with GetPin( number) will match all same-numbered
4550 // pins in the first symbol with the first pin of that number in the second symbol. Sort the pins
4551 // instead, which results in a more "complete" matching of source and other pins.
4552 std::set<SCH_PIN*, SCH_SYMBOL::cmp_pins> sortedPins;
4553 std::set<SCH_PIN*, SCH_SYMBOL::cmp_pins> sortedOtherPins;
4554
4555 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
4556 sortedPins.insert( pin.get() );
4557
4558 for( const std::unique_ptr<SCH_PIN>& pin : aSymbol.m_pins )
4559 sortedOtherPins.insert( pin.get() );
4560
4561 if( sortedPins.size() != sortedOtherPins.size() )
4562 return false;
4563
4564 for( auto aIt = sortedPins.begin(), bIt = sortedOtherPins.begin(); aIt != sortedPins.end(); ++aIt, ++bIt )
4565 {
4566 if( !( *aIt )->operator==( *( *bIt ) ) )
4567 return false;
4568 }
4569
4570 return true;
4571}
4572
4573
4574bool SCH_SYMBOL::operator!=( const SCH_SYMBOL& aSymbol ) const
4575{
4576 return !( *this == aSymbol );
4577}
4578
4579
4581{
4582 wxCHECK_MSG( Type() == aSymbol.Type(), *this,
4583 wxT( "Cannot assign object type " ) + aSymbol.GetClass() + wxT( " to type " ) + GetClass() );
4584
4585 if( &aSymbol != this )
4586 {
4587 SYMBOL::operator=( aSymbol );
4588
4589 m_pos = aSymbol.m_pos;
4590 m_lib_id = aSymbol.m_lib_id;
4591 m_prefix = aSymbol.m_prefix;
4592
4593 // Pin relinking still needs the previous library's alternate definitions.
4594 auto oldPart = std::exchange( m_part, aSymbol.m_part ? std::make_unique<LIB_SYMBOL>( *aSymbol.m_part )
4595 : nullptr );
4596
4597 m_unit = aSymbol.m_unit;
4598 m_bodyStyle = aSymbol.m_bodyStyle;
4599 m_transform = aSymbol.m_transform;
4600
4601 m_instances = aSymbol.m_instances;
4604 m_doNetlist = aSymbol.m_doNetlist;
4606 m_signalName = aSymbol.m_signalName;
4608
4609 {
4610 m_fields = aSymbol.m_fields; // std::vector's assignment operator
4611
4612 // Reparent fields after assignment to new symbol.
4613 for( SCH_FIELD& field : m_fields )
4614 field.SetParent( this );
4615 }
4616
4617 UpdatePins();
4618 m_variantSymbolCache.clear();
4619 }
4620
4621 return *this;
4622}
4623
4624
4625bool SCH_SYMBOL::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
4626{
4627 BOX2I bBox = GetBodyBoundingBox();
4628 bBox.Inflate( aAccuracy / 2 );
4629
4630 if( bBox.Contains( aPosition ) )
4631 return true;
4632
4633 return false;
4634}
4635
4636
4637bool SCH_SYMBOL::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
4638{
4640 return false;
4641
4642 BOX2I rect = aRect;
4643
4644 rect.Inflate( aAccuracy / 2 );
4645
4646 if( aContained )
4647 return rect.Contains( GetBodyBoundingBox() );
4648
4649 return rect.Intersects( GetBodyBoundingBox() );
4650}
4651
4652
4653bool SCH_SYMBOL::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
4654{
4656 return false;
4657
4658 return KIGEOM::BoxHitTest( aPoly, GetBodyBoundingBox(), aContained );
4659}
4660
4661
4662bool SCH_SYMBOL::doIsConnected( const VECTOR2I& aPosition ) const
4663{
4664 VECTOR2I new_pos = m_transform.InverseTransform().TransformCoordinate( aPosition - m_pos );
4665
4666 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
4667 {
4668 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
4669 continue;
4670
4671 // Collect only pins attached to the current unit and convert.
4672 // others are not associated to this symbol instance
4673 if( pin->GetUnit() != ALL_UNITS && pin->GetUnit() != GetUnit() )
4674 continue;
4675
4676 if( pin->GetBodyStyle() != ALL_BODY_STYLES && pin->GetBodyStyle() != GetBodyStyle() )
4677 continue;
4678
4679 if( pin->GetLocalPosition() == new_pos )
4680 return true;
4681 }
4682
4683 return false;
4684}
4685
4686
4688{
4689 return m_doNetlist;
4690}
4691
4692
4693void SCH_SYMBOL::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, int aUnit, int aBodyStyle,
4694 const VECTOR2I& aOffset, bool aDimmed )
4695{
4696 if( aBackground )
4697 return;
4698
4699 SCH_SHEET_PATH* sheet = Schematic() ? &Schematic()->CurrentSheet() : nullptr;
4700 const LIB_SYMBOL* effectiveSym = GetEffectiveLibSymbol( sheet );
4701
4702 if( effectiveSym )
4703 {
4704 bool usingAlternate = ( effectiveSym != m_part.get() );
4705
4706 std::vector<SCH_PIN*> libPins = effectiveSym->GetGraphicalPins( GetUnit(), GetBodyStyle() );
4707
4708 // Copy the source so we can re-orient and translate it.
4709 LIB_SYMBOL tempSymbol( *effectiveSym );
4710 std::vector<SCH_PIN*> tempPins = tempSymbol.GetGraphicalPins( GetUnit(), GetBodyStyle() );
4711 std::vector<SCH_PIN*> symbolPins = MapLibPins( libPins, usingAlternate );
4712
4713 // Copy the pin info from the symbol to the temp pins.
4714 for( unsigned i = 0; i < tempPins.size(); ++i )
4715 {
4716 SCH_PIN* symbolPin = symbolPins[i];
4717 SCH_PIN* tempPin = tempPins[i];
4718
4719 if( !symbolPin )
4720 continue;
4721
4722 tempPin->SetName( symbolPin->GetShownName() );
4723 tempPin->SetType( symbolPin->GetType() );
4724 tempPin->SetShape( symbolPin->GetShape() );
4725
4726 if( symbolPin->IsDangling() )
4727 tempPin->SetFlags( IS_DANGLING );
4728 }
4729
4730 for( SCH_ITEM& item : tempSymbol.GetDrawItems() )
4731 {
4732 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( &item ) )
4733 {
4734 // Use SCH_FIELD's text resolver
4735 SCH_FIELD dummy( this, FIELD_T::USER );
4736 dummy.SetText( text->GetText() );
4737 text->SetText( dummy.GetShownText( FOR_CANVAS ) );
4738 }
4739 }
4740
4741 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
4742 TRANSFORM savedTransform = renderSettings->m_Transform;
4743 renderSettings->m_Transform = GetTransform();
4744 aPlotter->StartBlock( nullptr );
4745
4746 wxString variant = Schematic() ? Schematic()->GetCurrentVariant() : wxString();
4747 bool dnp = GetDNP( sheet, variant );
4748
4749 for( bool local_background : { true, false } )
4750 {
4751 tempSymbol.Plot( aPlotter, local_background, aPlotOpts, GetUnit(), GetBodyStyle(), m_pos, dnp );
4752
4753 for( SCH_FIELD field : m_fields )
4754 {
4755 field.ClearRenderCache();
4756 field.Plot( aPlotter, local_background, aPlotOpts, GetUnit(), GetBodyStyle(), m_pos, dnp );
4757
4759 && field.GetId() == FIELD_T::VALUE
4760 && ( field.IsVisible() || field.IsForceVisible() )
4761 && !local_background )
4762 {
4763 PlotLocalPowerIconShape( aPlotter );
4764 }
4765 }
4766 }
4767
4768 if( dnp && renderSettings->m_ShowDNPMarkers )
4769 PlotDNP( aPlotter );
4770
4771 // Plot attributes to a hypertext menu
4772 if( aPlotOpts.m_PDFPropertyPopups )
4773 {
4774 std::vector<wxString> properties;
4775
4776 for( const SCH_FIELD& field : GetFields() )
4777 {
4778 wxString text_field = field.GetShownText( sheet, FOR_GUI, variant );
4779
4780 if( text_field.IsEmpty() )
4781 continue;
4782
4783 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), field.GetName(), text_field ) );
4784 }
4785
4786 if( !effectiveSym->GetKeyWords().IsEmpty() )
4787 {
4788 properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
4789 _( "Keywords" ),
4790 effectiveSym->GetShownKeyWords( FOR_GUI ) ) );
4791 }
4792
4793 aPlotter->HyperlinkMenu( GetBoundingBox(), properties );
4794 }
4795
4796 aPlotter->EndBlock( nullptr );
4797 renderSettings->m_Transform = savedTransform;
4798
4799 if( !effectiveSym->IsPower() )
4800 aPlotter->Bookmark( GetBoundingBox(), GetRef( sheet ), _( "Symbols" ) );
4801 }
4802}
4803
4804
4805void SCH_SYMBOL::PlotDNP( PLOTTER* aPlotter ) const
4806{
4807 BOX2I bbox = GetBodyBoundingBox();
4809 VECTOR2D margins( std::max( bbox.GetX() - pins.GetX(), pins.GetEnd().x - bbox.GetEnd().x ),
4810 std::max( bbox.GetY() - pins.GetY(), pins.GetEnd().y - bbox.GetEnd().y ) );
4811 int strokeWidth = 3.0 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
4812
4813 margins.x = std::max( margins.x * 0.6, margins.y * 0.3 );
4814 margins.y = std::max( margins.y * 0.6, margins.x * 0.3 );
4815 bbox.Inflate( KiROUND( margins.x ), KiROUND( margins.y ) );
4816
4817 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
4818 aPlotter->SetColor( renderSettings->GetLayerColor( LAYER_DNP_MARKER ) );
4819
4820 aPlotter->ThickSegment( bbox.GetOrigin(), bbox.GetEnd(), strokeWidth, nullptr );
4821
4822 aPlotter->ThickSegment( bbox.GetOrigin() + VECTOR2I( bbox.GetWidth(), 0 ),
4823 bbox.GetOrigin() + VECTOR2I( 0, bbox.GetHeight() ), strokeWidth, nullptr );
4824}
4825
4826
4830static void plotLocalPowerIcon( PLOTTER* aPlotter, const VECTOR2D& aPos, double aSize, bool aRotate )
4831{
4832 double lineWidth = aSize / 10.0;
4833
4834 std::vector<SCH_SHAPE> shapeList;
4835 SCH_SYMBOL::BuildLocalPowerIconShape( shapeList, aPos, aSize, lineWidth, aRotate );
4836 int tolerance = 100; // approx error to approximate a Bezier curve by segments
4837
4838 for( const SCH_SHAPE& shape : shapeList )
4839 {
4840 // Currently there are only 2 shapes: BEZIER and CIRCLE
4841 FILL_T filled = shape.GetFillMode() == FILL_T::NO_FILL ? FILL_T::NO_FILL : FILL_T::FILLED_SHAPE;
4842
4843 if( shape.GetShape() == SHAPE_T::BEZIER )
4844 {
4845 aPlotter->BezierCurve( shape.GetStart(), shape.GetBezierC1(), shape.GetBezierC2(), shape.GetEnd(),
4846 tolerance, lineWidth );
4847 }
4848 else if( shape.GetShape() == SHAPE_T::CIRCLE )
4849 {
4850 aPlotter->Circle( shape.getCenter(), shape.GetRadius() * 2, filled, lineWidth );
4851 }
4852 }
4853}
4854
4855
4857{
4858 const SCH_FIELD* field = GetField( FIELD_T::VALUE );
4859
4860 // Plot the local power pin indicator icon shape
4861 BOX2I bbox = field->GetBoundingBox();
4862
4863 // Calculate the text orientation according to the parent orientation.
4864 EDA_ANGLE orient = field->GetTextAngle();
4865
4866 if( GetTransform().y1 )
4867 {
4868 // Rotate symbol 90 degrees.
4869 if( orient.IsHorizontal() )
4870 orient = ANGLE_VERTICAL;
4871 else
4872 orient = ANGLE_HORIZONTAL;
4873 }
4874
4875 bool rotated = !orient.IsHorizontal();
4876
4877 VECTOR2D pos;
4878 double size = bbox.GetHeight() / 1.5;
4879
4880 if( rotated )
4881 {
4882 pos = VECTOR2D( bbox.GetRight() - bbox.GetWidth() / 6.0, bbox.GetBottom() + bbox.GetWidth() / 2.0 );
4883 size = bbox.GetWidth() / 1.5;
4884 }
4885 else
4886 {
4887 pos = VECTOR2D( bbox.GetLeft() - bbox.GetHeight() / 2.0, bbox.GetBottom() - bbox.GetHeight() / 6.0 );
4888 }
4889
4890 plotLocalPowerIcon( aPlotter, pos, size, rotated );
4891}
4892
4893
4894void SCH_SYMBOL::PlotPins( PLOTTER* aPlotter, bool aDnp ) const
4895{
4896 SCH_SHEET_PATH* sheet = Schematic() ? &Schematic()->CurrentSheet() : nullptr;
4897 const LIB_SYMBOL* effectiveSym = GetEffectiveLibSymbol( sheet );
4898
4899 if( effectiveSym )
4900 {
4901 bool usingAlternate = ( effectiveSym != m_part.get() );
4902
4903 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
4904 TRANSFORM savedTransform = renderSettings->m_Transform;
4905 renderSettings->m_Transform = GetTransform();
4906
4907 std::vector<SCH_PIN*> libPins = effectiveSym->GetGraphicalPins( GetUnit(), GetBodyStyle() );
4908
4909 // Copy the source to stay const
4910 LIB_SYMBOL tempSymbol( *effectiveSym );
4911 std::vector<SCH_PIN*> tempPins = tempSymbol.GetGraphicalPins( GetUnit(), GetBodyStyle() );
4912 std::vector<SCH_PIN*> symbolPins = MapLibPins( libPins, usingAlternate );
4913 SCH_PLOT_OPTS plotOpts;
4914
4915 // Copy the pin info from the symbol to the temp pins.
4916 for( unsigned i = 0; i < tempPins.size(); ++i )
4917 {
4918 SCH_PIN* symbolPin = symbolPins[i];
4919 SCH_PIN* tempPin = tempPins[i];
4920
4921 if( !symbolPin )
4922 continue;
4923
4924 tempPin->SetName( symbolPin->GetShownName() );
4925 tempPin->SetType( symbolPin->GetType() );
4926 tempPin->SetShape( symbolPin->GetShape() );
4927 tempPin->Plot( aPlotter, false, plotOpts, GetUnit(), GetBodyStyle(), m_pos, aDnp );
4928 }
4929
4930 renderSettings->m_Transform = savedTransform;
4931 }
4932}
4933
4934
4936{
4937 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
4938 {
4939 if( pin->IsBrightened() )
4940 return true;
4941 }
4942
4943 return false;
4944}
4945
4946
4948{
4949 for( std::unique_ptr<SCH_PIN>& pin : m_pins )
4950 pin->ClearBrightened();
4951}
4952
4953
4954/*
4955 * When modified at the schematic level, we still store the values of these flags in the
4956 * associated m_part. If m_part now diverges from other usages, a new derived LIB_SYMBOL
4957 * will be created and stored locally in the schematic.
4958 */
4960{
4961 return m_part && m_part->GetShowPinNames();
4962}
4963
4964
4966{
4967 if( m_part )
4968 m_part->SetShowPinNames( aShow );
4969}
4970
4971
4973{
4974 return m_part && m_part->GetShowPinNumbers();
4975}
4976
4977
4979{
4980 if( m_part )
4981 m_part->SetShowPinNumbers( aShow );
4982}
4983
4984
4986{
4987 for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
4988 {
4989 int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit() : GetUnit();
4990 int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle() : GetBodyStyle();
4991
4992 if( pin_unit != ALL_UNITS && pin_unit != GetUnit() )
4993 continue;
4994
4995 if( pin_bodyStyle != ALL_BODY_STYLES && pin_bodyStyle != GetBodyStyle() )
4996 continue;
4997
4998 if( pin->IsPointClickableAnchor( aPos ) )
4999 return true;
5000 }
5001
5002 return false;
5003}
5004
5005
5007{
5008 // return true if the symbol is equivalent to a global label:
5009 // It is a Power symbol
5010 // It has only one pin type Power input
5011
5013 return false;
5014
5015 std::vector<SCH_PIN*> pin_list = GetAllLibPins();
5016
5017 if( pin_list.size() != 1 )
5018 return false;
5019
5020 return pin_list[0]->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN;
5021}
5022
5023
5025{
5026 // return true if the symbol is equivalent to a local label:
5027 // It is a Power symbol
5028 // It has only one pin type Power input
5029
5031 return false;
5032
5033 std::vector<SCH_PIN*> pin_list = GetAllLibPins();
5034
5035 if( pin_list.size() != 1 )
5036 return false;
5037
5038 return pin_list[0]->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN;
5039}
5040
5041
5043{
5044 if( !m_part )
5045 return false;
5046
5047 return m_part->IsLocalPower();
5048}
5049
5050
5052{
5053 if( !m_part )
5054 return false;
5055
5056 return m_part->IsGlobalPower();
5057}
5058
5059
5061{
5062 if( !m_part || !m_part->IsPower() )
5063 return;
5064
5065 if( aLocal )
5066 m_part->SetLocalPower();
5067 else
5068 m_part->SetGlobalPower();
5069}
5070
5071
5073{
5074 return IsLocalPower() || IsGlobalPower();
5075}
5076
5077
5079{
5080 wxCHECK( m_part, false );
5081
5082 return m_part->IsNormal();
5083}
5084
5085
5086std::unordered_set<wxString> SCH_SYMBOL::GetComponentClassNames( const SCH_SHEET_PATH* aPath,
5087 const wxString& aVariantName ) const
5088{
5089 std::unordered_set<wxString> componentClass;
5090
5091 auto getComponentClassFields =
5092 [&]( const std::vector<SCH_FIELD>& fields )
5093 {
5094 for( const SCH_FIELD& field : fields )
5095 {
5096 if( field.GetUntranslatedName() == wxT( "Component Class" ) )
5097 {
5098 const wxString classname = field.GetShownText( aPath, INTERNAL, aVariantName );
5099
5100 if( classname != wxEmptyString )
5101 componentClass.insert( classname );
5102 }
5103 }
5104 };
5105
5106 // First get component classes set on the symbol itself
5107 getComponentClassFields( m_fields );
5108
5109 // Now get component classes set on any enclosing rule areas
5110 for( const SCH_RULE_AREA* ruleArea : m_rule_areas_cache )
5111 {
5112 for( const SCH_DIRECTIVE_LABEL* label : ruleArea->GetDirectives() )
5113 getComponentClassFields( label->GetFields() );
5114 }
5115
5116 return componentClass;
5117}
5118
5119
5120std::optional<SCH_SYMBOL_VARIANT> SCH_SYMBOL::GetVariant( const SCH_SHEET_PATH& aInstance,
5121 const wxString& aVariantName ) const
5122{
5123 SCH_SYMBOL_INSTANCE instance;
5124
5125 if( !GetInstance( instance, aInstance.Path() ) || !instance.m_Variants.contains( aVariantName ) )
5126 return std::nullopt;
5127
5128 return instance.m_Variants.find( aVariantName )->second;
5129}
5130
5131
5132void SCH_SYMBOL::AddVariant( const SCH_SHEET_PATH& aInstance, const SCH_SYMBOL_VARIANT& aVariant )
5133{
5134 SCH_SYMBOL_INSTANCE* instance = getInstance( aInstance );
5135
5136 // The instance path must already exist.
5137 if( !instance )
5138 return;
5139
5140 if( instance->m_Variants.insert( std::make_pair( aVariant.m_Name, aVariant ) ).second )
5142}
5143
5144
5145LIB_SYMBOL* SCH_SYMBOL::GetVariantLibSymbol( const wxString& aVariantName,
5146 const SCH_SHEET_PATH& aPath ) const
5147{
5148 if( aVariantName.IsEmpty() )
5149 return nullptr;
5150
5151 const SCH_SYMBOL_INSTANCE* instance = getInstance( aPath );
5152
5153 if( !instance || !instance->m_Variants.contains( aVariantName ) )
5154 return nullptr;
5155
5156 const SCH_SYMBOL_VARIANT& variant = instance->m_Variants.at( aVariantName );
5157
5158 if( !variant.m_SymbolOverride )
5159 return nullptr;
5160
5161 const LIB_ID& libId = *variant.m_SymbolOverride;
5162 wxString libIdStr = libId.Format();
5163
5164 // Cache by LIB_ID string so hierarchical instances sharing the same alternate symbol
5165 // reuse a single flattened copy regardless of sheet path or variant name. Failed
5166 // resolutions are cached as nullptr to keep unresolvable overrides from hitting the
5167 // library adapter on every paint.
5168 auto cacheIt = m_variantSymbolCache.find( libIdStr );
5169
5170 if( cacheIt != m_variantSymbolCache.end() )
5171 return cacheIt->second.get();
5172
5173 if( libId == m_lib_id )
5174 {
5175 m_variantSymbolCache[libIdStr] = nullptr;
5176 return nullptr;
5177 }
5178
5179 std::unique_ptr<LIB_SYMBOL> resolved;
5180
5181 // The schematic's copy wins so library edits only apply through an explicit update
5182 if( GetParent() && GetParent()->Type() == SCH_SCREEN_T )
5183 {
5184 const auto& libSymbols = static_cast<const SCH_SCREEN*>( GetParent() )->GetLibSymbols();
5185
5186 if( auto it = libSymbols.find( libIdStr ); it != libSymbols.end() && it->second )
5187 resolved = it->second->Flatten();
5188 }
5189
5190 if( !resolved )
5191 {
5192 if( !Schematic() )
5193 return nullptr;
5194
5195 resolved = LoadAlternateFromLibrary( libId );
5196 }
5197
5198 if( !resolved )
5199 {
5200 m_variantSymbolCache[libIdStr] = nullptr;
5201 return nullptr;
5202 }
5203
5204 std::unique_ptr<LIB_SYMBOL>& cached = m_variantSymbolCache[libIdStr];
5205
5206 cached = std::move( resolved );
5207
5208 if( m_part && !ValidateVariantSymbolCompatibility( *m_part, *cached ).empty() )
5209 {
5210 cached.reset();
5211 return nullptr;
5212 }
5213
5214 return cached.get();
5215}
5216
5217
5218std::vector<LIB_ID> SCH_SYMBOL::GetVariantSymbolOverrides() const
5219{
5220 std::vector<LIB_ID> overrides;
5221
5222 for( const SCH_SYMBOL_INSTANCE& instance : GetInstances() )
5223 {
5224 for( const auto& [name, variant] : instance.m_Variants )
5225 {
5226 if( variant.m_SymbolOverride
5227 && std::find( overrides.begin(), overrides.end(), *variant.m_SymbolOverride ) == overrides.end() )
5228 {
5229 overrides.push_back( *variant.m_SymbolOverride );
5230 }
5231 }
5232 }
5233
5234 return overrides;
5235}
5236
5237
5238std::unique_ptr<LIB_SYMBOL> SCH_SYMBOL::LoadAlternateFromLibrary( const LIB_ID& aLibId ) const
5239{
5241
5242 if( !schematic )
5243 return nullptr;
5244
5246
5247 if( !adapter )
5248 return nullptr;
5249
5250 try
5251 {
5252 const wxString nickname = aLibId.GetLibNickname().wx_str();
5253
5254 if( adapter->GetRow( nickname ) && !adapter->HasLibrary( nickname ) )
5255 adapter->LoadOne( nickname );
5256
5257 if( LIB_SYMBOL* libSymbol = adapter->LoadSymbol( aLibId ) )
5258 return libSymbol->Flatten();
5259 }
5260 catch( const IO_ERROR& )
5261 {
5262 }
5263
5264 return nullptr;
5265}
5266
5267
5269{
5270 if( aPath && Schematic() )
5271 {
5272 const wxString& variantName = Schematic()->GetCurrentVariant();
5273
5274 if( !variantName.IsEmpty() )
5275 {
5276 LIB_SYMBOL* altSymbol = GetVariantLibSymbol( variantName, *aPath );
5277
5278 if( altSymbol )
5279 return altSymbol;
5280 }
5281 }
5282
5283 return m_part.get();
5284}
5285
5286
5287std::vector<SCH_PIN*> SCH_SYMBOL::MapLibPins( const std::vector<SCH_PIN*>& aLibPins, bool aByNumber ) const
5288{
5289 std::vector<SCH_PIN*> mapped;
5290
5291 mapped.reserve( aLibPins.size() );
5292
5293 if( aByNumber )
5294 {
5295 const LIB_SYMBOL* baseSymbol = m_part.get();
5296
5297 if( !baseSymbol )
5298 {
5299 mapped.resize( aLibPins.size(), nullptr );
5300 return mapped;
5301 }
5302
5303 std::vector<SCH_PIN*> basePins = baseSymbol->GetGraphicalPins( GetUnit(), GetBodyStyle() );
5304 std::vector<bool> matched( basePins.size(), false );
5305
5306 for( const SCH_PIN* alternatePin : aLibPins )
5307 {
5308 SCH_PIN* instancePin = nullptr;
5309
5310 for( size_t i = 0; i < basePins.size(); ++i )
5311 {
5312 if( matched[i] || !VariantSymbolPinsMatch( *basePins[i], *alternatePin ) )
5313 continue;
5314
5315 matched[i] = true;
5316 instancePin = GetPin( const_cast<SCH_PIN*>( basePins[i] ) );
5317 break;
5318 }
5319
5320 mapped.push_back( instancePin );
5321 }
5322 }
5323 else
5324 {
5325 for( const SCH_PIN* libPin : aLibPins )
5326 mapped.push_back( GetPin( const_cast<SCH_PIN*>( libPin ) ) );
5327 }
5328
5329 return mapped;
5330}
5331
5332
5333void SCH_SYMBOL::DeleteVariant( const KIID_PATH& aPath, const wxString& aVariantName )
5334{
5335 SCH_SYMBOL_INSTANCE* instance = getInstance( aPath );
5336
5337 // The instance path must already exist.
5338 if( !instance || !instance->m_Variants.contains( aVariantName ) )
5339 return;
5340
5341 instance->m_Variants.erase( aVariantName );
5342
5344}
5345
5346
5347void SCH_SYMBOL::ClearVariantField( const KIID_PATH& aPath, const wxString& aVariantName,
5348 const wxString& aFieldName )
5349{
5350 SCH_SYMBOL_INSTANCE* instance = getInstance( aPath );
5351
5352 if( !instance || !instance->m_Variants.contains( aVariantName ) )
5353 return;
5354
5355 if( instance->m_Variants[aVariantName].m_Fields.erase( aFieldName ) )
5357}
5358
5359
5360void SCH_SYMBOL::RenameVariant( const KIID_PATH& aPath, const wxString& aOldName,
5361 const wxString& aNewName )
5362{
5363 SCH_SYMBOL_INSTANCE* instance = getInstance( aPath );
5364
5365 // The instance path must already exist and contain the old variant.
5366 if( aOldName == aNewName || !instance || !instance->m_Variants.contains( aOldName ) )
5367 return;
5368
5369 // Get the variant data, update the name, and re-insert with new key
5370 SCH_SYMBOL_VARIANT variant = instance->m_Variants[aOldName];
5371 variant.m_Name = aNewName;
5372 instance->m_Variants.erase( aOldName );
5373 instance->m_Variants.insert( std::make_pair( aNewName, variant ) );
5374
5376}
5377
5378
5379void SCH_SYMBOL::CopyVariant( const KIID_PATH& aPath, const wxString& aSourceVariant,
5380 const wxString& aNewVariant )
5381{
5382 SCH_SYMBOL_INSTANCE* instance = getInstance( aPath );
5383
5384 // The instance path must already exist and contain the source variant.
5385 if( !instance || !instance->m_Variants.contains( aSourceVariant ) )
5386 return;
5387
5388 // Copy the variant data with a new name
5389 SCH_SYMBOL_VARIANT variant = instance->m_Variants[aSourceVariant];
5390 variant.m_Name = aNewVariant;
5391
5392 if( instance->m_Variants.insert( std::make_pair( aNewVariant, variant ) ).second )
5394}
5395
5396
5398 const wxString& aVariantName,
5399 const LIB_ID& aLibId )
5400{
5401 SCH_SYMBOL_INSTANCE* instance = getInstance( aPath );
5402
5403 if( !instance )
5404 return;
5405
5406 if( !instance->m_Variants.contains( aVariantName ) )
5407 {
5408 SCH_SYMBOL_VARIANT newVariant( aVariantName );
5409 newVariant.InitializeAttributes( *this );
5410 instance->m_Variants.insert( std::make_pair( aVariantName, newVariant ) );
5411 }
5412
5413 const bool changed = std::exchange( instance->m_Variants[aVariantName].m_SymbolOverride, aLibId ) != aLibId;
5414 m_variantSymbolCache.clear();
5415
5416 if( changed )
5418}
5419
5420
5422 const wxString& aVariantName )
5423{
5424 SCH_SYMBOL_INSTANCE* instance = getInstance( aPath );
5425
5426 if( !instance || !instance->m_Variants.contains( aVariantName ) )
5427 return false;
5428
5429 SCH_SYMBOL_VARIANT& variant = instance->m_Variants[aVariantName];
5430
5431 if( !variant.m_SymbolOverride )
5432 return false;
5433
5434 variant.m_SymbolOverride.reset();
5435 m_variantSymbolCache.clear();
5436
5438
5439 return true;
5440}
5441
5442
5443bool SCH_SYMBOL::operator==( const SCH_ITEM& aOther ) const
5444{
5445 if( Type() != aOther.Type() )
5446 return false;
5447
5448 const SCH_SYMBOL& symbol = static_cast<const SCH_SYMBOL&>( aOther );
5449
5450 if( GetLibId() != symbol.GetLibId() )
5451 return false;
5452
5453 if( GetPosition() != symbol.GetPosition() )
5454 return false;
5455
5456 if( GetUnit() != symbol.GetUnit() )
5457 return false;
5458
5459 if( GetBodyStyle() != symbol.GetBodyStyle() )
5460 return false;
5461
5462 if( GetTransform() != symbol.GetTransform() )
5463 return false;
5464
5465 if( GetFields() != symbol.GetFields() )
5466 return false;
5467
5468 if( m_pins.size() != symbol.m_pins.size() )
5469 return false;
5470
5471 if( m_excludedFromSim != symbol.m_excludedFromSim )
5472 return false;
5473
5474 if( m_excludedFromBOM != symbol.m_excludedFromBOM )
5475 return false;
5476
5477 if( m_DNP != symbol.m_DNP )
5478 return false;
5479
5481 return false;
5482
5484 return false;
5485
5487 return false;
5488
5489 for( unsigned i = 0; i < m_pins.size(); ++i )
5490 {
5491 if( *m_pins[i] != *symbol.m_pins[i] )
5492 return false;
5493 }
5494
5495#if 0
5496 // This has historically been a compare of the current instance, rather than a compare
5497 // of all instances. Probably better to keep it that way for now.
5498 if( m_instanceReferences != symbol.m_instanceReferences )
5499 return false;
5500#endif
5501
5502 return true;
5503}
5504
5505
5506double SCH_SYMBOL::Similarity( const SCH_ITEM& aOther ) const
5507{
5508 if( Type() != aOther.Type() )
5509 return 0.0;
5510
5511 const SCH_SYMBOL& symbol = static_cast<const SCH_SYMBOL&>( aOther );
5512
5513 if( GetLibId() != symbol.GetLibId() )
5514 return 0.0;
5515
5516 if( GetPosition() == symbol.GetPosition() )
5517 return 1.0;
5518
5519 return 0.0;
5520}
5521
5522
5523void SCH_SYMBOL::BuildLocalPowerIconShape( std::vector<SCH_SHAPE>& aShapeList, const VECTOR2D& aPos, double aSize,
5524 double aLineWidth, bool aHorizontal )
5525{
5526 SCH_LAYER_ID layer = LAYER_DEVICE; //dummy param
5527
5528 double x_right = aSize / 1.6180339887;
5529 double x_middle = x_right / 2.0;
5530
5531 VECTOR2D bottomPt = VECTOR2D{ x_middle, 0 };
5532 VECTOR2D leftPt = VECTOR2D{ 0, 2.0 * -aSize / 3.0 };
5533 VECTOR2D rightPt = VECTOR2D{ x_right, 2.0 * -aSize / 3.0 };
5534
5535 VECTOR2D bottomAnchorPt = VECTOR2D{ x_middle, -aSize / 4.0 };
5536 VECTOR2D leftSideAnchorPt1 = VECTOR2D{ 0, -aSize / 2.5 };
5537 VECTOR2D leftSideAnchorPt2 = VECTOR2D{ 0, -aSize * 1.15 };
5538 VECTOR2D rightSideAnchorPt1 = VECTOR2D{ x_right, -aSize / 2.5 };
5539 VECTOR2D rightSideAnchorPt2 = VECTOR2D{ x_right, -aSize * 1.15 };
5540
5541 aShapeList.emplace_back( SHAPE_T::BEZIER, layer, aLineWidth, FILL_T::NO_FILL );
5542 aShapeList.back().SetStart( bottomPt );
5543 aShapeList.back().SetBezierC1( bottomAnchorPt );
5544 aShapeList.back().SetBezierC2( leftSideAnchorPt1 );
5545 aShapeList.back().SetEnd( leftPt );
5546
5547
5548 aShapeList.emplace_back( SHAPE_T::BEZIER, layer, aLineWidth, FILL_T::NO_FILL );
5549 aShapeList.back().SetStart( leftPt );
5550 aShapeList.back().SetBezierC1( leftSideAnchorPt2 );
5551 aShapeList.back().SetBezierC2( rightSideAnchorPt2 );
5552 aShapeList.back().SetEnd( rightPt );
5553
5554 aShapeList.emplace_back( SHAPE_T::BEZIER, layer, aLineWidth, FILL_T::NO_FILL );
5555 aShapeList.back().SetStart( rightPt );
5556 aShapeList.back().SetBezierC1( rightSideAnchorPt1 );
5557 aShapeList.back().SetBezierC2( bottomAnchorPt );
5558 aShapeList.back().SetEnd( bottomPt );
5559
5560 aShapeList.emplace_back( SHAPE_T::CIRCLE, layer, 0, FILL_T::FILLED_SHAPE );
5561 aShapeList.back().SetCenter( ( leftPt + rightPt ) / 2.0 );
5562 aShapeList.back().SetRadius( aSize / 15.0 );
5563
5564 for( SCH_SHAPE& shape : aShapeList )
5565 {
5566 if( aHorizontal )
5567 shape.Rotate( VECTOR2I( 0, 0 ), true );
5568
5569 shape.Move( aPos );
5570 }
5571}
5572
5573
5575{
5576 if( auto it = m_instancePathIndex.find( aSheetPath ); it != m_instancePathIndex.end() )
5577 return &m_instances[it->second];
5578
5579 return nullptr;
5580}
5581
5582
5584{
5585 if( auto it = m_instancePathIndex.find( aSheetPath ); it != m_instancePathIndex.end() )
5586 return &m_instances[it->second];
5587
5588 return nullptr;
5589}
5590
5591
5592static struct SCH_SYMBOL_DESC
5593{
5595 {
5597 .Map( SYMBOL_ANGLE_0, wxS( "0" ) )
5598 .Map( SYMBOL_ANGLE_90, wxS( "90" ) )
5599 .Map( SYMBOL_ANGLE_180, wxS( "180" ) )
5600 .Map( SYMBOL_ANGLE_270, wxS( "270" ) );
5601
5607
5608 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Position X" ),
5611 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Position Y" ),
5614
5617 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Mirror X" ),
5619 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Mirror Y" ),
5621
5622 auto hasLibPart =
5623 []( INSPECTABLE* aItem ) -> bool
5624 {
5625 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
5626 return symbol->GetLibSymbolRef() != nullptr;
5627
5628 return false;
5629 };
5630
5631 propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Pin numbers" ),
5633 .SetAvailableFunc( hasLibPart );
5634
5635 propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Pin names" ),
5637 .SetAvailableFunc( hasLibPart );
5638
5639 const wxString groupFields = _HKI( "Fields" );
5640
5641 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Reference" ),
5643 groupFields )
5644 .SetValidator( []( const wxAny&& aValue, EDA_ITEM* aItem ) -> VALIDATOR_RESULT
5645 {
5646 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem );
5647 wxString value;
5648 wxString base;
5649
5650 if( !symbol || !symbol->Schematic() || !aValue.GetAs( &value ) )
5651 return {};
5652
5653 wxString msg = symbol->BaseRefFromUser( symbol->Schematic()->CurrentSheet(),
5654 value, base );
5655
5656 if( msg.IsEmpty() )
5657 return {};
5658
5659 return std::make_unique<VALIDATION_ERROR_MSG>( msg );
5660 } );
5661 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Composed Reference" ),
5663 groupFields )
5664 .SetAvailableFunc( []( INSPECTABLE* aObject )
5665 {
5666 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aObject );
5667
5668 return symbol && symbol->Schematic()
5669 && !symbol->Schematic()->GetRefSuffix(
5670 symbol->Schematic()->CurrentSheet() ).IsEmpty();
5671 } );
5672 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Value" ),
5674 groupFields );
5675 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Library Link" ),
5677 groupFields );
5678 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Library Description" ),
5680 groupFields );
5681 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Keywords" ),
5683 groupFields );
5684
5685 auto multiUnit =
5686 [=]( INSPECTABLE* aItem ) -> bool
5687 {
5688 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
5689 return symbol->IsMultiUnit();
5690
5691 return false;
5692 };
5693
5694 auto multiBodyStyle =
5695 [=]( INSPECTABLE* aItem ) -> bool
5696 {
5697 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
5698 return symbol->IsMultiBodyStyle();
5699
5700 return false;
5701 };
5702
5703 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Unit" ),
5705 .SetAvailableFunc( multiUnit )
5707 []( INSPECTABLE* aItem )
5708 {
5709 wxPGChoices choices;
5710
5711 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
5712 {
5713 for( int ii = 1; ii <= symbol->GetUnitCount(); ii++ )
5714 choices.Add( symbol->GetUnitDisplayName( ii, false ), ii );
5715 }
5716
5717 return choices;
5718 } );
5719
5720 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Body Style" ),
5722 .SetAvailableFunc( multiBodyStyle )
5724 []( INSPECTABLE* aItem )
5725 {
5726 wxPGChoices choices;
5727
5728 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
5729 {
5730 for( int ii = 1; ii <= symbol->GetBodyStyleCount(); ii++ )
5731 choices.Add( symbol->GetBodyStyleDescription( ii, false ) );
5732 }
5733
5734 return choices;
5735 } );
5736
5740 []( INSPECTABLE* aItem ) -> bool
5741 {
5742 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
5743 return symbol->IsPower();
5744
5745 return false;
5746 } );
5747
5748 const wxString groupAttributes = _HKI( "Attributes" );
5749
5750 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Exclude From Simulation" ),
5752 groupAttributes );
5753 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Exclude From Bill of Materials" ),
5755 groupAttributes );
5756 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Exclude From Board" ),
5758 groupAttributes );
5759 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Exclude From Position Files" ),
5761 groupAttributes );
5762 propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Do not Populate" ),
5764 groupAttributes );
5765 }
5767
5768
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.
@ add_component
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 const Vec GetEnd() const
Definition box2.h:215
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:149
constexpr coord_type GetY() const
Definition box2.h:211
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr coord_type GetX() const
Definition box2.h:210
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr ecoord_type GetArea() const
Return the area of the rectangle.
Definition box2.h:700
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr void Offset(coord_type dx, coord_type dy)
Definition box2.h:262
constexpr coord_type GetBottom() const
Definition box2.h:225
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
static std::vector< DANGLING_END_ITEM >::iterator get_lower_pos(std::vector< DANGLING_END_ITEM > &aItemListByPos, const VECTOR2I &aPos)
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition sch_item.h:101
DANGLING_END_T GetType() const
Definition sch_item.h:137
const EDA_ITEM * GetParent() const
Definition sch_item.h:136
bool IsHorizontal() const
Definition eda_angle.h:141
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:170
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
std::vector< PROPERTY_BASE * > GetCustomPropertiesAsInspectables() const
Definition eda_item.cpp:210
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
virtual void SetParentGroup(EDA_GROUP *aGroup)
Definition eda_item.h:115
bool IsSelected() const
Definition eda_item.h:134
EDA_ITEM * GetParent() const
Definition eda_item.h:112
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:609
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:557
virtual void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:576
virtual EDA_ANGLE GetTextAngle() const
Definition eda_text.h:178
static ENUM_MAP< T > & Instance()
Definition property.h:811
A text control validator used for validating the text allowed in fields.
Definition validators.h:137
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
wxAny Get(PROPERTY_BASE *aProperty) const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
A typed sum value used to carry the before/after of any single property.
wxString ToDisplayString() const
Human-readable representation with no unit context.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxString AsString() const
Definition kiid.cpp:423
Definition kiid.h:46
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library tables.
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
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
UTF8 Format() const
Definition lib_id.cpp:132
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
wxString GetKeyWords() const override
Definition lib_symbol.h:220
bool IsPower() const override
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition lib_symbol.h:240
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.
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
SCH_ITEM * LocateDrawItem(int aUnit, int aBodyStyle, KICAD_T aType, const VECTOR2I &aPoint)
Locate a draw object.
static wxString LetterSubReference(int aUnit, wxChar aInitialLetter)
static LIB_SYMBOL * GetDummy()
Return a dummy LIB_SYMBOL, used when one is missing in the schematic.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:845
const BOX2I GetBodyBoundingBox(int aUnit, int aBodyStyle, bool aIncludePins, bool aIncludePrivateItems) const
Get the symbol bounding box excluding fields.
wxString GetShownKeyWords(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
bool Deserialize(const kiapi::schematic::types::SchematicSymbol &aInput)
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const override
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
A singleton reporter that reports to nowhere.
Definition reporter.h:267
A named pin map.
Definition pin_map.h:65
Base plotter engine class.
Definition plotter.h:138
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width)=0
virtual void Bookmark(const BOX2I &aBox, const wxString &aName, const wxString &aGroupName=wxEmptyString)
Create a bookmark to a symbol.
Definition plotter.h:550
virtual void BezierCurve(const VECTOR2I &aStart, const VECTOR2I &aControl1, const VECTOR2I &aControl2, const VECTOR2I &aEnd, int aTolerance, int aLineThickness)
Generic fallback: Cubic Bezier curve rendered as a polyline.
Definition plotter.cpp:230
virtual void StartBlock(void *aData)
calling this function allows one to define the beginning of a group of drawing items,...
Definition plotter.h:623
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, void *aData)
Definition plotter.cpp:442
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition plotter.h:538
virtual void SetColor(const COLOR4D &color)=0
virtual void EndBlock(void *aData)
calling this function allows one to define the end of a group of drawing items for instance in SVG or...
Definition plotter.h:632
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
Definition property.h:289
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(const wxString &aName, PROPERTY_DISPLAY aDisplay=PT_DEFAULT, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType=ORIGIN_TRANSFORMS::NOT_A_COORD)
Used to generate unique IDs. Must come up front so it's initialized before ctor.
Definition property.h:201
PROPERTY_BASE & SetGroup(const wxString &aGroup)
Definition property.h:395
PROPERTY_BASE & SetValidator(PROPERTY_VALIDATOR_FN &&aValidator)
Definition property.h:397
friend class INSPECTABLE
Definition property.h:520
const wxString & Name() const
Definition property.h:221
Provide class metadata.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
bool IsAvailableFor(TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
Checks overriden availability and original availability of a property, returns false if the property ...
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Holds all the data relating to one schematic.
Definition schematic.h:155
wxString GetCurrentVariant() const
Return the current variant being edited.
wxString GetRefSuffix(const SCH_SHEET_PATH &aPath) const
Return the composed reference suffix of aPath as of the last RefreshHierarchy().
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:399
Commit for the schematic and symbol editors.
Definition sch_commit.h:54
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
bool IsMandatory() const
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
FIELD_T GetId() const
Definition sch_field.h:143
void ImportValues(const SCH_FIELD &aSource)
Copy parameters from a SCH_FIELD source.
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetText(const wxString &aText) override
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
void SetLocked(bool aLocked) override
Definition sch_item.h:262
int m_unit
Definition sch_item.h:844
SCH_SCREEN * GetParentScreen() const
Definition sch_item.cpp:308
int m_bodyStyle
Definition sch_item.h:845
void invalidateConnectivity(KICAD_T aChangedType=TYPE_NOT_INIT)
Bump the parent screen's connectivity revision when this item, or the item owning it as a child,...
Definition sch_item.cpp:323
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.cpp:46
void SetPrivate(bool aPrivate)
Definition sch_item.h:258
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
int GetUnit() const
Definition sch_item.h:243
virtual void ClearCaches()
Definition sch_item.cpp:891
void SetConnectivityDirty(bool aDirty=true)
Set the dirty flag.
Definition sch_item.cpp:314
void SetFieldsAutoplaced(AUTOPLACE_ALGO aAlgo)
Definition sch_item.h:679
virtual void SetUnit(int aUnit)
Definition sch_item.h:242
AUTOPLACE_ALGO m_fieldsAutoplaced
Definition sch_item.h:847
std::unordered_set< SCH_RULE_AREA * > m_rule_areas_cache
Store pointers to rule areas which this item is contained within.
Definition sch_item.h:860
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:65
AUTOPLACE_ALGO GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition sch_item.h:678
SCH_LAYER_ID m_layer
Definition sch_item.h:843
ALT GetAlt(const wxString &aAlt)
Definition sch_pin.h:233
void SetName(const wxString &aName)
Definition sch_pin.cpp:548
const wxString & GetName() const
Definition sch_pin.cpp:530
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 SetShape(GRAPHIC_PINSHAPE aShape)
Definition sch_pin.h:116
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:381
const wxString & GetShownName() const
Definition sch_pin.cpp:700
void SetType(ELECTRICAL_PINTYPE aType)
Definition sch_pin.cpp:458
const wxString & GetNumber() const
Definition sch_pin.h:144
GRAPHIC_PINSHAPE GetShape() const
Definition sch_pin.cpp:403
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:438
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool GetExcludedFromBOM() const
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false, bool aEscapeSheetNames=false) const
Return the sheet path in a human readable form made from the sheet names.
bool GetExcludedFromSim() const
bool GetExcludedFromBoard() const
bool GetDNP() const
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
const KIID_PATH & PathRef() const
Borrow the cached path until this sheet path is modified or destroyed.
size_t size() const
Forwarded method from std::vector.
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
size_t BaseHash() const override
Return type-id of the Base class.
size_t OwnerHash() const override
Return type-id of the Owner class.
size_t TypeHash() const override
Return type-id of the property type.
SCH_SYMBOL_FIELD_PROPERTY(const wxString &aName)
void setter(void *obj, wxAny &v) override
wxAny ValueForInstance(const SCH_SYMBOL *symbol, const SCH_SHEET_PATH *sheetPath, const wxString &variantName) const override
wxAny getter(const void *aObject) const final
PROPERTY_BASE(const wxString &aName, PROPERTY_DISPLAY aDisplay=PT_DEFAULT, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType=ORIGIN_TRANSFORMS::NOT_A_COORD)
Used to generate unique IDs. Must come up front so it's initialized before ctor.
Definition property.h:201
virtual wxAny ValueForInstance(const SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH *aPath, const wxString &aVariant) const =0
size_t TypeHash() const override
Return type-id of the property type.
size_t BaseHash() const override
Return type-id of the Base class.
SCH_SYMBOL_PIN_MAP_ENTRY_PROPERTY(const wxString &aName, const wxString &aPinNumber)
bool Writeable(INSPECTABLE *aObject) const override
wxAny ValueForInstance(const SCH_SYMBOL *symbol, const SCH_SHEET_PATH *sheetPath, const wxString &variantName) const override
wxString m_pinNumber
size_t OwnerHash() const override
Return type-id of the Owner class.
void setter(void *obj, wxAny &v) override
wxAny ValueForInstance(const SCH_SYMBOL *symbol, const SCH_SHEET_PATH *sheetPath, const wxString &variantName) const override
size_t OwnerHash() const override
Return type-id of the Owner class.
void setter(void *obj, wxAny &v) override
size_t TypeHash() const override
Return type-id of the property type.
size_t BaseHash() const override
Return type-id of the Base class.
bool Writeable(INSPECTABLE *aObject) const override
wxAny ValueForInstance(const SCH_SYMBOL *symbol, const SCH_SHEET_PATH *sheetPath, const wxString &variantName) const override
void setter(void *obj, wxAny &v) override
size_t TypeHash() const override
Return type-id of the property type.
size_t OwnerHash() const override
Return type-id of the Owner class.
static wxPGChoices BuildChoices()
size_t BaseHash() const override
Return type-id of the Base class.
size_t TypeHash() const override
Return type-id of the property type.
static wxPGChoices BuildChoices(const SCH_SYMBOL *aSymbol)
static std::vector< wxString > MapNames(const SCH_SYMBOL *aSymbol)
size_t OwnerHash() const override
Return type-id of the Owner class.
void setter(void *obj, wxAny &v) override
wxAny ValueForInstance(const SCH_SYMBOL *symbol, const SCH_SHEET_PATH *sheetPath, const wxString &variantName) const override
size_t BaseHash() const override
Return type-id of the Base class.
Variant information for a schematic symbol.
PIN_MAP_INSTANCE_OVERRIDE m_PinMapOverride
Per-instance pin-to-pad map override for this variant (issue #2282).
std::optional< LIB_ID > m_SymbolOverride
Alternate library symbol to substitute for the base symbol in this variant, if any.
void InitializeAttributes(const SCH_SYMBOL &aSymbol)
Schematic symbol object.
Definition sch_symbol.h:76
wxString GetUnitDisplayName(int aUnit, bool aLabel) const override
Return the display name for a given unit aUnit.
SCH_SYMBOL & operator=(const SCH_SYMBOL &aItem)
wxString refFor(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit, bool aCompose, std::optional< int > aUnit=std::nullopt) const
int GetUnitProp() const
size_t GetFullPinCount() const
std::vector< SCH_SYMBOL_INSTANCE > m_instances
Define the hierarchical path and reference of the symbol.
void UpdatePrefix()
Set the prefix based on the current reference designator.
wxString m_prefix
C, R, U, Q etc - the first character(s) which typically indicate what the symbol is.
wxString GetDescription() const override
std::unordered_map< SCH_PIN *, SCH_PIN * > m_pinMap
Library pin pointer : SCH_PIN indices.
void SetMirrorX(bool aMirror)
Definition sch_symbol.h:325
bool IsSymbolLikePowerGlobalLabel() const
VECTOR2I m_pos
PASSTHROUGH_MODE GetPassthroughMode() const
Definition sch_symbol.h:918
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SYMBOLs don't currently support embedded files, but their LIB_SYMBOL counterparts do.
wxString GetSymbolIDAsString() const
Definition sch_symbol.h:168
std::map< wxString, std::unique_ptr< PROPERTY_BASE > > m_pinMapPropsStorageCache
Same for effective pin-map entries.
LIB_ID m_lib_id
Name and library the symbol was loaded from, i.e. 74xx:74LS00.
void ClearPinMapOverrides()
Clear the base pin-to-pad map override and every variant's override.
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
bool GetShowPinNumbers() const override
wxString GetDatasheet() const
Return the documentation text for the given part alias.
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void SetLibId(const LIB_ID &aName)
bool HasBrightenedPins()
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the symbol's fields.
Definition sch_symbol.h:464
BOX2I GetBodyAndPinsBoundingBox() const override
Return a bounding box for the symbol body and pins but not the fields.
wxString GetBodyStyleProp() const override
Definition sch_symbol.h:576
void SetRefProp(const wxString &aRef)
void SetFieldText(SCH_FIELD *aField, const wxString &aFieldName, const wxString &aFieldText, const SCH_SHEET_PATH *aPath, const wxString &aVariantName)
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &aScanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
virtual void SetDNP(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
SCH_ITEM * GetDrawItem(const VECTOR2I &aPosition, KICAD_T aType=TYPE_NOT_INIT)
Return the symbol library item at aPosition that is part of this symbol.
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.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition sch_symbol.h:136
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_symbol.h:959
void PlotDNP(PLOTTER *aPlotter) const
Plot the red 'X' over the symbol.
bool operator!=(const SCH_SYMBOL &aSymbol) const
void SetShowPinNumbers(bool aShow) override
Set or clear the pin number visibility flag.
wxString m_signalName
bool ClearVariantSymbolOverride(const SCH_SHEET_PATH &aPath, const wxString &aVariantName)
Remove the alternate-symbol override for a given variant and sheet instance.
SYMBOL_ORIENTATION_PROP GetOrientationProp() const
Definition sch_symbol.h:308
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_variantSymbolCache
int GetY() const
Definition sch_symbol.h:964
SCH_SYMBOL_INSTANCE * getInstance(const KIID_PATH &aPath)
wxString SubReference(int aUnit, bool aAddSeparator=true) const
bool m_doNetlist
True if the symbol should appear in netlist.
wxString GetClass() const override
Return the class name.
Definition sch_symbol.h:116
void setVariantAttribute(bool aEnable, const SCH_SHEET_PATH *aInstance, const wxString &aVariantName, bool SCH_SYMBOL::*aBase, bool SCH_SYMBOL_VARIANT::*aOverride)
void RemoveInstance(const SCH_SHEET_PATH &aInstancePath)
bool IsAnnotated(const SCH_SHEET_PATH *aSheet) const
Check if the symbol has a valid annotation (reference) for the given sheet path.
void SetMirrorY(bool aMirror)
Definition sch_symbol.h:342
wxString GetCurrentSheetRef() const
void SetBodyStyleProp(const wxString &aBodyStyle) override
Definition sch_symbol.h:581
void SetVariantSymbolOverride(const SCH_SHEET_PATH &aPath, const wxString &aVariantName, const LIB_ID &aLibId)
Set the alternate-symbol override for a given variant and sheet instance.
bool UseLibIdLookup() const
Definition sch_symbol.h:183
wxString BaseRefFromUser(const SCH_SHEET_PATH &aSheet, const wxString &aText, wxString &aBase, const SCHEMATIC *aSchematic=nullptr) const
Convert a reference typed on aSheet to the base reference.
int GetX() const
Definition sch_symbol.h:961
bool GetExcludedFromPosFilesProp() const
void RemoveField(const wxString &aFieldName)
Remove a user field from the symbol.
std::vector< LIB_ID > GetVariantSymbolOverrides() const
void SetExcludedFromSim(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from simulation flag.
void SetExcludedFromSimProp(bool aEnable)
void SetBodyStyle(int aBodyStyle) override
void SetShowPinNames(bool aShow) override
Set or clear the pin name visibility flag.
wxString GetKeyWords() const override
bool SetInstanceProjectName(const KIID_PATH &aSheetPath, const wxString &aProjectName)
Set the owning project of the instance stored for aSheetPath.
wxString GetSchSymbolLibraryName() const
void ClearCaches() override
const wxString GetFootprintFieldText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const
PASSTHROUGH_MODE m_passthroughMode
std::optional< SCH_SYMBOL_VARIANT > GetVariant(const SCH_SHEET_PATH &aInstance, const wxString &aVariantName) const
PIN_MAP_INSTANCE_OVERRIDE GetPinMapOverride(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
bool GetExcludedFromBoardProp() const
void ClearBrightenedPins()
void SetY(int aY)
Definition sch_symbol.h:965
std::vector< SCH_PIN * > MapLibPins(const std::vector< SCH_PIN * > &aLibPins, bool aByNumber) const
Map pins of an effective library symbol to this symbol's instance pins.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
bool GetExcludedFromSimProp() const
wxString GetBaseRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool DoNetList() const
bool IsGlobalPower() const override
bool GetMirrorX() const
Definition sch_symbol.h:337
wxString GetRefProp() const
void SetPinMapOverride(const PIN_MAP_INSTANCE_OVERRIDE &aOverride, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString)
Set the per-instance pin-to-pad map override (issue #2282).
wxString GetBodyStyleDescription(int aBodyStyle, bool aLabel) const override
bool AddSheetPathReferenceEntryIfMissing(const KIID_PATH &aSheetPath)
Add an instance to the alternate references list (m_instances), if this entry does not already exist.
wxString GetShownKeyWords(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
void SetLocalPowerProp(bool aLocal)
void SetExcludedFromBOMProp(bool aEnable)
void ClearVariantField(const KIID_PATH &aPath, const wxString &aVariantName, const wxString &aFieldName)
static std::unordered_map< TRANSFORM, int > s_transformToOrientationCache
void SetRefLacksSuffix(const KIID_PATH &aPath, bool aLacksSuffix=true)
Flag the reference loaded for aPath as saved without its sheet suffix.
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
SCH_FIELD * FindFieldCaseInsensitive(const wxString &aFieldName)
Search for a SCH_FIELD with aFieldName.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
bool IsPointClickableAnchor(const VECTOR2I &aPos) const override
void UpdateFields(const SCH_SHEET_PATH *aPath, bool aUpdateStyle, bool aUpdateRef, bool aUpdateOtherFields, bool aResetRef, bool aResetOtherFields)
Restore fields to the original library values.
wxString m_schLibSymbolName
The name used to look up a symbol in the symbol library embedded in a schematic.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the base reference for the given sheet path for this symbol.
void ClearAnnotation(const SCH_SHEET_PATH *aSheetPath, bool aResetPrefix)
Clear exiting symbol annotation.
SCH_PIN * GetPinByEffectivePadNumber(const wxString &aPadNumber, const SCH_SHEET_PATH *aSheet, const wxString &aVariantName=wxEmptyString) const
Find the pin whose effective footprint pad number (issue #2282) is aPadNumber on aSheet,...
void RenameVariant(const KIID_PATH &aPath, const wxString &aOldName, const wxString &aNewName)
void SetOrientationProp(SYMBOL_ORIENTATION_PROP aAngle)
Orientation/mirroring access for property manager.
Definition sch_symbol.h:299
bool GetShowPinNames() const override
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
bool HasDeMorganBodyStyles() const override
std::vector< SCH_FIELD > m_fields
Variable length list of fields.
wxString GetUnitRef(const SCH_SHEET_PATH *aSheet, int aUnit) const
std::vector< SCH_PIN * > GetAllLibPins() const
int GetBodyStyleCount() const override
Return the number of body styles of the symbol.
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...
std::unique_ptr< LIB_SYMBOL > LoadAlternateFromLibrary(const LIB_ID &aLibId) const
Load a flattened copy of an alternate symbol from the project's symbol libraries.
bool GetDNPProp() const
void PlotPins(PLOTTER *aPlotter, bool aDnp) const
Plot just the symbol pins.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void SetFootprintFieldText(const wxString &aFootprint)
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
wxString GetShownDescription(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
std::unordered_map< KIID_PATH, size_t > m_instancePathIndex
Index from an instance's sheet path to its position in m_instances for O(1) lookups.
bool IsMissingLibSymbol() const
Check to see if the library symbol is set to the dummy library symbol.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:958
PIN_MAP_INSTANCE_OVERRIDE resolveDelegatedPinMapOverride(const SCH_SHEET_PATH &aSheet, const wxString &aVariantName) const
Return unit 1's pin-map override for a unit that delegates to it (issue #2282).
std::unique_ptr< LIB_SYMBOL > m_part
A flattened copy of the LIB_SYMBOL from the PROJECT object's libraries.
int GetNextFieldOrdinal() const
Return the next ordinal for a user field for this symbol.
void SetExcludedFromPosFiles(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void rebuildInstancePathIndex()
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
std::unordered_set< wxString > GetComponentClassNames(const SCH_SHEET_PATH *aPath, const wxString &aVariantName) const
Return the component classes this symbol belongs in.
void SyncOtherUnits(const SCH_SHEET_PATH &aSourceSheet, SCH_COMMIT &aCommit, PROPERTY_BASE *aProperty, const wxString &aVariantName=wxEmptyString)
Keep fields other than the reference, include/exclude flags, and alternate pin assignments in sync in...
void Init(const VECTOR2I &pos=VECTOR2I(0, 0))
void SetExcludedFromPosFilesProp(bool aEnable)
void updatePins()
const LIB_SYMBOL * GetEffectiveLibSymbol(const SCH_SHEET_PATH *aPath=nullptr) const
Return the library symbol to use for rendering and bounding box calculations.
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:166
bool operator<(const SCH_ITEM &aItem) const override
static void BuildLocalPowerIconShape(std::vector< SCH_SHAPE > &aShapeList, const VECTOR2D &aPos, double aSize, double aLineWidth, bool aHorizontal)
Build the local power pin indicator icon shape, at coordinate aPos.
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this symbol.
LIB_SYMBOL * GetVariantLibSymbol(const wxString &aVariantName, const SCH_SHEET_PATH &aPath) const
Resolve the alternate library symbol for a given variant.
void SetValueProp(const wxString &aValue)
void SetUnitProp(int aUnit)
void SetUserRef(const SCH_SHEET_PATH &aSheet, const wxString &aBase)
Set a base reference chosen by the user on aSheet.
void SetSchSymbolLibraryName(const wxString &aName)
The name of the symbol in the schematic library symbol list.
Definition sch_symbol.h:181
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
void SetValueFieldText(const wxString &aValue, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString)
std::vector< SCH_PIN * > GetLibPins() const
Populate a vector with all the pins from the library object that match the current unit and bodyStyle...
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos, const SCH_SHEET_PATH *aPath=nullptr) override
Test if the symbol's dangling state has changed for all pins.
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit, int aBodyStyle) const override
bool GetExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
void AddVariant(const SCH_SHEET_PATH &aInstance, const SCH_SYMBOL_VARIANT &aVariant)
BOX2I doGetBoundingBox(bool aIncludePins, bool aIncludeFields) const
bool GetMirrorY() const
Definition sch_symbol.h:354
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
void SetDNPProp(bool aEnable)
static uint64_t RefGeneration()
Count of changes to any symbol's references, units, library links or placement.
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
std::vector< SCH_PIN * > GetPinsByNumber(const wxString &aNumber) const
Find all symbol pins with the given number.
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
std::vector< PROPERTY_BASE * > GetDynamicProperties() const override
Return dynamically-computed properties specific to this object instance (e.g.
void SetPassthroughMode(PASSTHROUGH_MODE aMode)
Definition sch_symbol.h:919
void SetX(int aX)
Definition sch_symbol.h:962
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
const wxString GetValue(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const override
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
static void BumpRefGeneration()
Mark every cache built from references as stale.
PIN_MAP_INSTANCE_OVERRIDE m_pinMapOverride
Base (no-variant) pin-to-pad map override applied when no variant override exists for the sheet path ...
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
wxString GetValueProp() const
bool IsLocalPower() const override
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
int GetUnitCount() const override
Return the number of units per package of the symbol.
void SetPrefix(const wxString &aPrefix)
Definition sch_symbol.h:242
int GetOrientation() const override
Get the display symbol orientation.
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.
bool IsSymbolLikePowerLocalLabel() const
bool GetExcludedFromBOMProp() const
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
void SetExcludedFromBoardProp(bool aEnable)
void SetExcludedFromBOM(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from schematic bill of materials flag.
void PlotLocalPowerIconShape(PLOTTER *aPlotter) const
Plot the local power pin indicator icon shape.
bool IsNormal() const override
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:185
std::vector< std::unique_ptr< SCH_PIN > > m_pins
A copy of SCH_PIN objects from the library symbol.
void DeleteVariant(const KIID_PATH &aPath, const wxString &aVariantName)
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
VECTOR2I GetPinPhysicalPosition(const SCH_PIN *Pin) const
BOX2I GetBodyBoundingBox() const override
Return a bounding box for the symbol body but not the pins or fields.
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
wxString GetFieldText(const SCH_FIELD *aField, const wxString &aFieldName, const SCH_SHEET_PATH *aPath, const wxString &aVariantName) const
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
bool IsMovableFromAnchorPoint() const override
Return true for items which are moved with the anchor point at mouse cursor and false for items moved...
bool IsPower() const override
void SetExcludedFromBoard(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
void CopyVariant(const KIID_PATH &aPath, const wxString &aSourceVariant, const wxString &aNewVariant)
bool HasEffectiveAssociatedFootprint() const
std::map< wxString, std::unique_ptr< SCH_SYMBOL_FIELD_PROPERTY > > m_fieldPropsStorageCache
Per-object cache of dynamic property descriptors for custom fields, keyed by descriptor name and popu...
bool operator==(const SCH_SYMBOL &aSymbol) const
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, std::span< const wxString > aPins, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
Definition sim_lib_mgr.h:45
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:60
bool m_DNP
True if symbol is set to 'Do Not Populate'.
Definition symbol.h:278
bool m_showPinNumbers
Definition symbol.h:272
bool m_excludedFromPosFiles
Definition symbol.h:277
SYMBOL(KICAD_T idType)
Definition symbol.h:62
bool m_excludedFromSim
Definition symbol.h:274
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
Definition symbol.h:174
bool m_showPinNames
Definition symbol.h:271
const TRANSFORM & GetTransform() const
Definition symbol.h:247
int GetPinNameOffset() const
Definition symbol.h:163
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
Definition symbol.h:168
bool m_excludedFromBOM
Definition symbol.h:275
bool m_excludedFromBoard
Definition symbol.h:276
virtual bool GetShowPinNames() const
Definition symbol.h:169
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
Definition symbol.h:162
SYMBOL & operator=(const SYMBOL &aItem)
Definition symbol.h:90
virtual bool GetShowPinNumbers() const
Definition symbol.h:175
TRANSFORM m_transform
The rotation/mirror transformation.
Definition symbol.h:267
int m_pinNameOffset
The offset in mils to draw the pin name.
Definition symbol.h:269
for transforming drawing coordinates for a wxDC device context.
Definition transform.h:42
wxString wx_str() const
Definition utf8.cpp:41
wxString m_Name
bool m_ExcludedFromBOM
std::map< wxString, wxString > m_Fields
bool m_ExcludedFromPosFiles
bool m_ExcludedFromSim
bool m_ExcludedFromBoard
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
Definition common.cpp:60
RESOLUTION_CONTEXT
Definition common.h:91
@ FOR_GUI
Definition common.h:93
@ FOR_CANVAS
Definition common.h:92
@ FOR_NETNAME
Definition common.h:94
@ RAW_VALUE
Definition common.h:98
@ INTERNAL
Definition common.h:96
#define DEFAULT_LINE_WIDTH_MILS
The default line width in mils. (can be changed in preference menu)
static bool empty(const wxTextEntryBase *aCtrl)
#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
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:477
FILL_T
Definition eda_fill.h:29
@ NO_FILL
Definition eda_fill.h:30
@ FILLED_SHAPE
Fill with object color.
Definition eda_fill.h:31
RECURSE_MODE
Definition eda_item.h:50
INSPECT_RESULT
Definition eda_item.h:44
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition eda_item.h:91
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define IS_DANGLING
indicates a pin is dangling
a few functions useful in geometry calculations.
const wxChar *const traceSchSymbolRef
Flag to enable debug output of schematic symbol reference resolution.
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:480
@ LAYER_DEVICE
Definition layer_ids.h:497
@ LAYER_VALUEPART
Definition layer_ids.h:492
@ LAYER_FIELDS
Definition layer_ids.h:493
@ LAYER_REFERENCEPART
Definition layer_ids.h:491
@ LAYER_DNP_MARKER
Definition layer_ids.h:509
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:44
Message panel definition file.
DIFF_VALUE WxAnyToDiffValue(const wxAny &aValue, PROPERTY_BASE *aProperty)
Convert a wxAny value read from a PROPERTY_BASE getter into a DIFF_VALUE that the engine can store,...
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
wxString GetRefDesUnannotated(const wxString &aSource)
Return an unannotated refdes from either a prefix or an existing refdes.
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
Definition api_utils.cpp:50
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 PackLibId(types::LibraryIdentifier *aOutput, const LIB_ID &aId)
KICOMMON_API LIB_ID UnpackLibId(const types::LibraryIdentifier &aId)
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
PIN_MAP_OVERRIDE_MODE
Override mode stored on a SCH_SYMBOL_INSTANCE.
Definition pin_map.h:178
@ PT_NC
not connected (must be left open)
Definition pin_type.h:46
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define NO_SETTER(owner, type)
Macro to define read-only fields (no setter method available)
Definition property.h:923
#define ENUM_TO_WXANY(type)
Definition property.h:918
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
std::optional< std::unique_ptr< VALIDATION_ERROR > > VALIDATOR_RESULT
Null optional means validation succeeded.
Collection of utility functions for component reference designators (refdes)
void CollectOtherUnits(const wxString &aRef, int aUnit, const LIB_ID &aLibId, SCH_SHEET_PATH &aSheet, std::vector< SCH_SYMBOL * > *otherUnits)
const SCH_FIELD * FindField(const std::vector< SCH_FIELD > &aFields, FIELD_T aFieldId)
Definition sch_field.h:390
int NextFieldOrdinal(const std::vector< SCH_FIELD > &aFields)
Definition sch_field.h:379
@ AUTOPLACE_NONE
Definition sch_item.h:74
@ AUTOPLACE_AUTO
Definition sch_item.h:75
@ NO_CONNECT_END
Definition sch_item.h:92
@ SHEET_LABEL_END
Definition sch_item.h:91
@ LABEL_END
Definition sch_item.h:88
@ JUNCTION_END
Definition sch_item.h:86
@ PIN_END
Definition sch_item.h:87
@ WIRE_END
Definition sch_item.h:84
@ BASE
Definition sch_item.h:64
static const wxString PIN_MAP_GROUP
static const wxString PIN_MAP_MODE_PROP
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
static const wxString PIN_MAP_FOOTPRINT_PROP
static const ASSOCIATED_FOOTPRINT * activeAssociatedFootprint(const SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH *aPath=nullptr, const wxString &aVariant=wxEmptyString)
static const wxString PIN_MAP_ENTRY_PREFIX
static const wxString PIN_MAP_NAME_PROP
static void plotLocalPowerIcon(PLOTTER *aPlotter, const VECTOR2D &aPos, double aSize, bool aRotate)
plot a local power pin indicator icon.
static const wxString PIN_MAP_TABLE_GROUP
static std::atomic< uint64_t > s_refGeneration
static struct SCH_SYMBOL_DESC _SCH_SYMBOL_DESC
std::vector< FAB_LAYER_COLOR > dummy
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)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
A first-class footprint choice on a LIB_SYMBOL, tied to a named pin map.
Definition pin_map.h:159
std::vector< std::pair< FIELD_T, wxString > > Fields
Definition sch_screen.h:91
Per-instance override of the active pin map and a sparse delta on top.
Definition pin_map.h:200
PIN_MAP_OVERRIDE_MODE m_Mode
Definition pin_map.h:201
bool IsDelegate() const
Definition pin_map.h:219
bool m_PDFPropertyPopups
Definition sch_plotter.h:66
A simple container for schematic symbol instance information.
std::map< wxString, SCH_SYMBOL_VARIANT > m_Variants
A list of symbol variants.
bool m_RefLacksSuffix
Set at load when the saved reference lacked its sheet suffix, cleared when the reference changes.
std::string refName
Hold a name of a symbol's field, field value, and default visibility.
#define ALL_UNITS
Definition symbol.h:150
SYMBOL_ORIENTATION_PROP
Definition symbol.h:48
@ SYMBOL_ANGLE_180
Definition symbol.h:51
@ SYMBOL_ANGLE_0
Definition symbol.h:49
@ SYMBOL_ANGLE_90
Definition symbol.h:50
@ SYMBOL_ANGLE_270
Definition symbol.h:52
#define ALL_BODY_STYLES
Definition symbol.h:151
@ SYM_ORIENT_270
Definition symbol.h:39
@ SYM_ROTATE_CLOCKWISE
Definition symbol.h:34
@ SYM_ROTATE_COUNTERCLOCKWISE
Definition symbol.h:35
@ SYM_MIRROR_Y
Definition symbol.h:41
@ SYM_ORIENT_180
Definition symbol.h:38
@ SYM_MIRROR_X
Definition symbol.h:40
@ SYM_NORMAL
Definition symbol.h:33
@ SYM_ORIENT_90
Definition symbol.h:37
@ SYM_ORIENT_0
Definition symbol.h:36
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ USER
The field ID hasn't been set yet; field is invalid.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
@ UNTRANSLATED
JSON_SCHEMA_VALIDATOR validator(schema)
std::string path
KIBIS_MODEL * model
KIBIS_PIN * pin
wxString result
Test unit parsing edge cases and error handling.
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
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ SCH_FIELD_LOCATE_REFERENCE_T
Definition typeinfo.h:176
@ SCH_FIELD_LOCATE_FOOTPRINT_T
Definition typeinfo.h:178
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_FIELD_T
Definition typeinfo.h:146
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:195
@ SCH_FIELD_LOCATE_VALUE_T
Definition typeinfo.h:177
@ SCH_SCREEN_T
Definition typeinfo.h:198
@ SCH_FIELD_LOCATE_DATASHEET_T
Definition typeinfo.h:179
@ SCH_SYMBOL_LOCATE_POWER_T
Definition typeinfo.h:192
@ SCH_PIN_T
Definition typeinfo.h:149
Custom text control validator definitions.
std::vector< VARIANT_COMPAT_RESULT > ValidateVariantSymbolCompatibility(const LIB_SYMBOL &aBase, const LIB_SYMBOL &aCandidate)
Check whether aCandidate can be used as a variant symbol override for aBase.
bool VariantSymbolPinsMatch(const SCH_PIN &aBase, const SCH_PIN &aCandidate)
Check whether two graphical pins occupy the same variant-symbol connection slot.
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)