45#include <api/schematic/schematic_types.pb.h>
65 std::string ret =
TO_UTF8( txt );
69 if( (
unsigned char) c <=
' ' )
96 std::unique_ptr<LIB_SYMBOL> part;
127 SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.
Convert, aPosition, aParent )
130 for(
const auto& [fieldId, fieldValue] : aSel.
Fields )
132 if( fieldId == FIELD_T::REFERENCE )
133 SetRef( aSheet, fieldValue );
134 else if( SCH_FIELD* field = GetField( fieldId ) )
135 field->SetText( fieldValue );
163 field.SetParent(
this );
168 for(
const std::unique_ptr<SCH_PIN>&
pin : aSymbol.
m_pins )
170 m_pins.emplace_back( std::make_unique<SCH_PIN>( *pin ) );
171 m_pins.back()->SetParent( this );
227 using namespace kiapi::schematic::types;
229 SchematicSymbolInstance symbol;
231 symbol.mutable_id()->set_value(
m_Uuid.AsStdString() );
233 symbol.set_locked(
IsLocked() ? types::LockedState::LS_LOCKED : types::LockedState::LS_UNLOCKED );
235 SchematicSymbolTransform* transform = symbol.mutable_transform();
236 transform->set_orientation(
242 symbol.mutable_body_style()->set_style(
GetBodyStyle() );
244 SchematicSymbol* def = symbol.mutable_definition();
247 google::protobuf::Any
any;
250 any.UnpackTo( symbol.mutable_reference_field() );
253 any.UnpackTo( symbol.mutable_value_field() );
256 any.UnpackTo( symbol.mutable_footprint_field() );
259 any.UnpackTo( symbol.mutable_datasheet_field() );
262 any.UnpackTo( symbol.mutable_description_field() );
266 if( field.IsMandatory() )
269 field.Serialize(
any );
270 any.UnpackTo( symbol.add_user_fields() );
276 any.UnpackTo( def->mutable_reference_field() );
279 any.UnpackTo( def->mutable_value_field() );
282 any.UnpackTo( def->mutable_footprint_field() );
285 any.UnpackTo( def->mutable_datasheet_field() );
288 any.UnpackTo( def->mutable_description_field() );
300 SchematicSymbolChild* item = def->add_items();
301 item->mutable_unit()->set_unit( drawItem.GetUnit() );
302 item->mutable_body_style()->set_style( drawItem.GetBodyStyle() );
303 item->set_is_private( drawItem.IsPrivate() );
304 drawItem.Serialize( *item->mutable_item() );
307 def->set_unit_count(
m_part->GetUnitCount() );
308 def->set_body_style_count(
m_part->GetBodyStyleCount() );
309 def->set_keywords(
m_part->GetKeyWords().ToUTF8() );
312 def->add_footprint_filters(
filter.ToUTF8() );
320 aContainer.PackFrom( symbol );
327 using namespace kiapi::common::types;
328 using namespace kiapi::schematic::types;
330 SchematicSymbolInstance symbol;
332 if( !aContainer.UnpackTo( &symbol ) )
337 SetLocked( symbol.locked() == LockedState::LS_LOCKED );
343 const SchematicSymbol& def = symbol.definition();
351 google::protobuf::Any
any;
353 any.PackFrom( def.reference_field() );
356 any.PackFrom( def.value_field() );
359 any.PackFrom( def.footprint_field() );
362 any.PackFrom( def.datasheet_field() );
365 any.PackFrom( def.description_field() );
368 std::unordered_map<::KIID, wxString> pinAltMap;
370 for(
const SchematicSymbolChild& child : def.items() )
379 if( !item || !item->Deserialize( child.item() ) )
386 SchematicPin pinProto;
388 if( child.item().UnpackTo( &pinProto ) )
390 if( pinProto.has_active_alternate() )
391 pinAltMap[schItem->
m_Uuid] = wxString::FromUTF8( pinProto.active_alternate() );
395 if( child.has_unit() )
396 schItem->
SetUnit( child.unit().unit() );
398 if( child.has_body_style() )
406 if( def.unit_count() > 0 )
409 if( def.body_style_count() > 0 )
412 if( !def.keywords().empty() )
413 libSymbol->
SetKeyWords( wxString::FromUTF8( def.keywords() ) );
415 if( def.footprint_filters_size() > 0 )
417 wxArrayString filters;
419 for(
const std::string&
filter : def.footprint_filters() )
420 filters.Add( wxString::FromUTF8(
filter ) );
427 if( symbol.has_body_style() )
430 any.PackFrom( symbol.reference_field() );
433 any.PackFrom( symbol.value_field() );
436 any.PackFrom( symbol.footprint_field() );
439 any.PackFrom( symbol.datasheet_field() );
442 any.PackFrom( symbol.description_field() );
445 std::set<wxString> incoming;
447 for(
const SchematicField& fieldProto : symbol.user_fields() )
449 wxString
name = wxString::FromUTF8( fieldProto.name() );
456 incoming.insert(
name );
457 any.PackFrom( fieldProto );
465 std::vector<wxString> toRemove;
469 if( !field.IsMandatory() && !incoming.count( field.GetName(
false ) ) )
470 toRemove.push_back( field.GetName(
false ) );
473 for(
const wxString&
name : toRemove )
491 m_pins.emplace_back( std::make_unique<SCH_PIN>( *
pin ) );
492 m_pins.back()->SetParent(
this );
503 if( pinAltMap.contains(
pin->m_Uuid ) )
504 pin->SetAlt( pinAltMap.at(
pin->m_Uuid ) );
523 const int min_grid_size =
schIUScale.MilsToIU( 25 );
525 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
527 if( ( (
pin->GetPosition().x -
m_pos.x ) % min_grid_size ) != 0 )
530 if( ( (
pin->GetPosition().y -
m_pos.y ) % min_grid_size ) != 0 )
555 wxCHECK2( !aLibSymbol || aLibSymbol->
IsRoot(), aLibSymbol =
nullptr );
557 m_part.reset( aLibSymbol );
565 pin->SetLibPin(
nullptr );
574 return m_part->GetDescription();
576 return wxEmptyString;
583 return m_part->GetShownDescription( aDepth );
585 return wxEmptyString;
592 return m_part->GetKeyWords();
594 return wxEmptyString;
601 return m_part->GetShownKeyWords( aDepth );
603 return wxEmptyString;
610 return m_part->GetDatasheetField().GetText();
612 return wxEmptyString;
618 std::map<wxString, wxString> altPinMap;
619 std::map<wxString, SCH_PIN::ALT> altPinDefs;
620 std::map<wxString, std::set<SCH_PIN*>> pinUuidMap;
621 std::set<SCH_PIN*> unassignedSchPins;
622 std::set<SCH_PIN*> unassignedLibPins;
624 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
626 pinUuidMap[
pin->GetNumber()].insert(
pin.get() );
628 unassignedSchPins.insert(
pin.get() );
630 if( !
pin->GetAlt().IsEmpty() )
632 altPinMap[
pin->GetNumber()] =
pin->GetAlt();
633 auto altDefIt =
pin->GetAlternates().find(
pin->GetAlt() );
635 if( altDefIt !=
pin->GetAlternates().end() )
636 altPinDefs[
pin->GetNumber()] = altDefIt->second;
639 pin->SetLibPin(
nullptr );
656 auto ii = pinUuidMap.find( libPin->GetNumber() );
658 if( ii == pinUuidMap.end() || ii->second.empty() )
660 unassignedLibPins.insert( libPin );
664 auto it = ii->second.begin();
666 ii->second.erase( it );
667 pin->GetAlternates() = libPin->GetAlternates();
668 pin->SetLibPin( libPin );
669 pin->SetPosition( libPin->GetPosition() );
670 pin->SetUnit( libPin->GetUnit() );
671 pin->SetBodyStyle( libPin->GetBodyStyle() );
673 unassignedSchPins.erase(
pin );
675 auto iii = altPinMap.find( libPin->GetNumber() );
677 if( iii != altPinMap.end() )
679 wxString altName = iii->second;
681 if(
pin->GetAlternates().find( altName ) ==
pin->GetAlternates().end() )
683 auto defIt = altPinDefs.find( libPin->GetNumber() );
685 if( defIt != altPinDefs.end() )
687 for(
const auto& [
name, alt] :
pin->GetAlternates() )
689 if( alt.m_Shape == defIt->second.m_Shape && alt.m_Type == defIt->second.m_Type )
698 pin->SetAlt( altName );
705 for(
SCH_PIN* libPin : unassignedLibPins )
710 if( !unassignedSchPins.empty() )
712 auto it = unassignedSchPins.begin();
714 unassignedSchPins.erase( it );
719 pin =
m_pins.emplace_back( std::make_unique<SCH_PIN>(
SCH_PIN(
this, libPin ) ) ).get();
723 pin->GetAlternates() = libPin->GetAlternates();
724 pin->SetLibPin( libPin );
725 pin->SetPosition( libPin->GetPosition() );
726 pin->SetUnit( libPin->GetUnit() );
727 pin->SetBodyStyle( libPin->GetBodyStyle() );
728 pin->SetNumber( libPin->GetNumber() );
730 auto iii = altPinMap.find( libPin->GetNumber() );
732 if( iii != altPinMap.end() )
734 wxString altName = iii->second;
736 if(
pin->GetAlternates().find( altName ) ==
pin->GetAlternates().end() )
738 auto defIt = altPinDefs.find( libPin->GetNumber() );
740 if( defIt != altPinDefs.end() )
742 for(
const auto& [
name, alt] :
pin->GetAlternates() )
744 if( alt.m_Shape == defIt->second.m_Shape && alt.m_Type == defIt->second.m_Type )
753 pin->SetAlt( altName );
758 for(
auto it1 =
m_pins.begin(); it1 !=
m_pins.end() && !unassignedSchPins.empty(); )
760 auto it2 = unassignedSchPins.find( it1->get() );
762 if( it2 != unassignedSchPins.end() )
764 it1 =
m_pins.erase( it1 );
765 unassignedSchPins.erase( it2 );
776 for( std::unique_ptr<SCH_PIN>&
pin :
m_pins )
797 return m_part->GetUnitCount();
806 return m_part->GetBodyStyleCount();
815 return m_part->HasDeMorganBodyStyles();
824 return m_part->GetUnitDisplayName( aUnit, aLabel );
826 return wxString::Format(
_(
"Unit %s" ),
SubReference( aUnit ) );
835 return m_part->GetBodyStyleDescription( aBodyStyle, aLabel );
858 if( instance.m_Path.EndsWith( aSheetPath ) )
860 aInstance = instance;
877 bool removed =
false;
881 for(
int ii =
m_instances.size() - 1; ii >= 0; --ii )
886 wxS(
"Removing symbol instance:\n"
888 " reference %s, unit %d from symbol %s." ),
930 wxS(
"Adding symbol '%s' instance:\n"
955 wxLogTrace(
traceSchSymbolRef,
"GetRef for symbol %s on path %s (sheet path has %zu sheets)",
976 wxLogTrace(
traceSchSymbolRef,
" Using fallback from REFERENCE field: %s", ref );
998 if(
validator.DoValidate( aRef,
nullptr ) )
1019 for( std::unique_ptr<SCH_PIN>&
pin :
m_pins )
1020 pin->ClearDefaultNetName( sheet );
1037 const wxString& aVariantName )
1039 wxCHECK( !aFieldName.IsEmpty(), );
1045 switch( field->
GetId() )
1049 SetRef( aPath, aFieldText );
1054 wxString defaultText = field->
GetText( aPath );
1056 if( aVariantName.IsEmpty() )
1058 if( aFieldText != defaultText )
1065 wxCHECK( instance, );
1071 const SCH_FIELD* altField = altSymbol->GetField( aFieldName );
1073 if( altField && !altField->
GetText().IsEmpty() )
1074 defaultText = altField->
GetText();
1077 if( instance->
m_Variants.contains( aVariantName ) )
1079 if( aFieldText != defaultText )
1080 instance->
m_Variants[aVariantName].m_Fields[aFieldName] = aFieldText;
1082 instance->
m_Variants[aVariantName].m_Fields.erase( aFieldName );
1084 else if( aFieldText != defaultText )
1089 newVariant.
m_Fields[aFieldName] = aFieldText;
1090 instance->
m_Variants.insert( std::make_pair( aVariantName, newVariant ) );
1101 const wxString& aVariantName )
const
1103 wxCHECK( !aFieldName.IsEmpty(), wxEmptyString );
1107 wxCHECK( field, wxEmptyString );
1109 switch( field->
GetId() )
1112 wxCHECK( aPath, field->
GetText() );
1113 return GetRef( aPath,
false );
1117 if( !aVariantName.IsEmpty() && aPath )
1121 if( instance && instance->
m_Variants.contains( aVariantName )
1122 && instance->
m_Variants.at( aVariantName ).m_Fields.contains( aFieldName ) )
1124 return instance->
m_Variants.at( aVariantName ).m_Fields.at( aFieldName );
1133 if( altField && !altField->
GetText().IsEmpty() )
1141 if( aVariantName.IsEmpty() )
1149 if( instance && instance->
m_Variants.contains( aVariantName ) )
1153 if( variant.
m_Fields.contains( aFieldName ) )
1154 return variant.
m_Fields.at( aFieldName );
1162 if( altField && !altField->
GetText().IsEmpty() )
1181 if( instance.m_Path ==
path )
1182 return !instance.m_Reference.IsEmpty() && instance.m_Reference.Last() !=
'?';
1193 refDesignator.Replace(
"~",
" " );
1195 wxString prefix = refDesignator;
1197 while( prefix.Length() )
1199 wxUniCharRef last = prefix.Last();
1201 if( ( last >=
'0' && last <=
'9' ) || last ==
'?' || last ==
'*' )
1202 prefix.RemoveLast();
1208 prefix.Trim(
true );
1209 prefix.Trim(
false );
1211 if( !prefix.IsEmpty() )
1221 const std::map<int, wxString>& names =
m_part->GetUnitDisplayNames();
1222 auto it = names.find( aUnit );
1224 if( it != names.end() && !it->second.IsEmpty() )
1230 int sep = schematic->Settings().m_SubpartIdSeparator;
1232 if( sep != 0 && aAddSeparator )
1233 subRef << wxChar( sep );
1236 subRef << it->second;
1242 return schematic->Settings().SubReference( aUnit, aAddSeparator );
1278 if( !aInstance || aVariantName.IsEmpty() )
1286 wxCHECK_MSG( instance, ,
1287 wxString::Format( wxS(
"Cannot get DNP attribute for invalid sheet path '%s'." ),
1290 if( aVariantName.IsEmpty() )
1296 if( instance->
m_Variants.contains( aVariantName ) )
1298 instance->
m_Variants[aVariantName].m_DNP = aEnable;
1300 else if( aEnable !=
m_DNP )
1305 variant.
m_DNP = aEnable;
1314 if( !aInstance || aVariantName.IsEmpty() )
1322 if( instance.
m_Variants.contains( aVariantName ) )
1323 return instance.
m_Variants[aVariantName].m_DNP;
1330 const wxString& aVariantName )
1332 if( !aInstance || aVariantName.IsEmpty() )
1340 wxCHECK_MSG( instance, ,
1341 wxString::Format( wxS(
"Cannot set pin map override for invalid sheet path '%s'." ),
1344 if( instance->
m_Variants.contains( aVariantName ) )
1346 instance->
m_Variants[aVariantName].m_PinMapOverride = aOverride;
1360 const wxString& aVariantName )
const
1364 if( aInstance && !aVariantName.IsEmpty() )
1373 if(
result.IsDelegate() && aInstance )
1381 const wxString& aVariantName )
const
1386 wxString ref =
GetRef( &aSheet );
1394 if( sibling ==
this || sibling->
GetUnit() != 1 )
1397 if( sibling->
GetRef( &sheet ).CmpNoCase( ref ) != 0 )
1416 if( !aInstance || aVariantName.IsEmpty() )
1424 wxCHECK_MSG( instance, ,
1425 wxString::Format( wxS(
"Cannot get DNP attribute for invalid sheet path '%s'." ),
1428 if( aVariantName.IsEmpty() )
1434 if( instance->
m_Variants.contains( aVariantName ) )
1436 instance->
m_Variants[aVariantName].m_ExcludedFromBOM = aEnable;
1452 if( !aInstance || aVariantName.IsEmpty() )
1460 if( instance.
m_Variants.contains( aVariantName ) )
1461 return instance.
m_Variants[aVariantName].m_ExcludedFromBOM;
1470 if( !aInstance || aVariantName.IsEmpty() )
1478 wxCHECK_MSG( instance, ,
1479 wxString::Format( wxS(
"Cannot get DNP attribute for invalid sheet path '%s'." ),
1482 if( aVariantName.IsEmpty() )
1488 if( instance->
m_Variants.contains( aVariantName ) )
1490 instance->
m_Variants[aVariantName].m_ExcludedFromSim = aEnable;
1506 if( !aInstance || aVariantName.IsEmpty() )
1514 if( instance.
m_Variants.contains( aVariantName ) )
1515 return instance.
m_Variants[aVariantName].m_ExcludedFromSim;
1523 const wxString& aVariantName )
1525 if( !aInstance || aVariantName.IsEmpty() )
1533 wxCHECK_MSG( instance, ,
1534 wxString::Format( wxS(
"Cannot set exclude from board for invalid sheet path '%s'." ),
1537 if( aVariantName.IsEmpty() )
1543 if( instance->
m_Variants.contains( aVariantName ) )
1545 instance->
m_Variants[aVariantName].m_ExcludedFromBoard = aEnable;
1560 const wxString& aVariantName )
const
1562 if( !aInstance || aVariantName.IsEmpty() )
1570 if( instance.
m_Variants.contains( aVariantName ) )
1571 return instance.
m_Variants[aVariantName].m_ExcludedFromBoard;
1579 const wxString& aVariantName )
1581 if( !aInstance || aVariantName.IsEmpty() )
1589 wxCHECK_MSG( instance, ,
1590 wxString::Format( wxS(
"Cannot set exclude from pos files for invalid sheet path '%s'." ),
1593 if( aVariantName.IsEmpty() )
1599 if( instance->
m_Variants.contains( aVariantName ) )
1601 instance->
m_Variants[aVariantName].m_ExcludedFromPosFiles = aEnable;
1616 const wxString& aVariantName )
const
1618 if( !aInstance || aVariantName.IsEmpty() )
1626 if( instance.
m_Variants.contains( aVariantName ) )
1627 return instance.
m_Variants[aVariantName].m_ExcludedFromPosFiles;
1637 instance.m_Unit = aUnitSelection;
1642 bool aAllowExtraText,
const wxString& aVariantName )
const
1644 if( aVariantName.IsEmpty() || !aInstance )
1652 std::optional variant =
GetVariant( *aInstance, aVariantName );
1658 if( variant->m_Fields.contains( fieldName ) )
1659 return variant->m_Fields[fieldName];
1667 if( altField && !altField->
GetText().IsEmpty() )
1681 const wxString& aVariantName )
1683 if( !aInstance || aVariantName.IsEmpty() )
1691 wxCHECK( instance, );
1695 if( instance->
m_Variants.contains( aVariantName ) )
1697 instance->
m_Variants[aVariantName].m_Fields[fieldName] = aValue;
1704 newVariant.
m_Fields[fieldName] = aValue;
1705 instance->
m_Variants.insert( std::make_pair( aVariantName, newVariant ) );
1711 bool aAllowExtraText,
const wxString& aVariantName )
const
1731 m_fields.emplace_back(
this, aFieldType );
1760 if( !field.IsVisible() || field.GetText().IsEmpty() )
1764 aVector.push_back(
const_cast<SCH_FIELD*
>( &field ) );
1767 std::sort( aVector.begin(), aVector.end(),
1770 return lhs->GetOrdinal() < rhs->GetOrdinal();
1790 for(
unsigned ii = 0; ii <
m_fields.size(); ++ii )
1795 if( aFieldName ==
m_fields[ii].GetName(
false ) )
1808 if( field.GetName().IsSameAs( aFieldName,
false ) )
1820 if( field.GetName().IsSameAs( aFieldName,
false ) )
1829 bool aResetRef,
bool aResetOtherFields )
1833 std::vector<SCH_FIELD*> fields;
1834 m_part->GetFields( fields );
1836 for(
const SCH_FIELD* libField : fields )
1841 if( libField->IsMandatory() )
1843 fieldType = libField->GetId();
1848 schField =
GetField( libField->GetCanonicalName() );
1858 schField->
SetPrivate( libField->IsPrivate() );
1870 else if( aUpdateRef )
1871 SetRef( aPath, libField->GetText() );
1879 if( aResetOtherFields )
1881 else if( aUpdateOtherFields )
1882 schField->
SetText( libField->GetText() );
1886 if( aResetOtherFields || aUpdateOtherFields )
1887 schField->
SetText( libField->GetText() );
1897 bool updateValue =
true;
1898 bool updateExclFromBOM =
true;
1899 bool updateExclFromBoard =
true;
1900 bool updateExclFromPosFiles =
true;
1901 bool updateDNP =
true;
1902 bool updateOtherFields =
true;
1903 bool updatePins =
true;
1904 bool updatePinMapOverride =
true;
1908 updateValue = aProperty->
Name() ==
_HKI(
"Value" );
1909 updateExclFromBoard = aProperty->
Name() ==
_HKI(
"Exclude From Board" );
1910 updateExclFromBOM = aProperty->
Name() ==
_HKI(
"Exclude From Bill of Materials" );
1911 updateExclFromPosFiles = aProperty->
Name() ==
_HKI(
"Exclude From Position Files" );
1912 updateDNP = aProperty->
Name() ==
_HKI(
"Do not Populate" );
1913 updatePinMapOverride = aProperty->
Name() == wxS(
"Pin Map Mode" ) || aProperty->
Name() == wxS(
"Pin Map Name" );
1914 updateOtherFields =
false;
1918 if( !updateValue && !updateExclFromBOM && !updateExclFromBoard && !updateExclFromPosFiles && !updateDNP
1919 && !updateOtherFields && !updatePins && !updatePinMapOverride )
1928 wxString ref =
GetRef( &aSourceSheet );
1933 std::vector<SCH_SYMBOL*> otherUnits;
1939 aCommit.
Modify( otherUnit, screen );
1944 GetValue(
false, &aSourceSheet,
false, aVariantName ), &sheet,
1948 if( updateOtherFields )
1960 if( field.IsMandatory() )
1961 otherField = otherUnit->GetField( field.GetId() );
1963 otherField = otherUnit->GetField( field.GetName() );
1967 otherField->
SetText( field.GetText( &aSourceSheet, aVariantName ), &sheet, aVariantName );
1975 newField.
Offset( otherUnit->GetPosition() );
1978 SCH_FIELD* addedField = otherUnit->AddField( newField );
1980 if( !aVariantName.IsEmpty() )
1982 addedField->
SetText( field.GetText( &aSourceSheet, aVariantName ), &sheet,
1988 for(
int ii = (
int) otherUnit->GetFields().size() - 1; ii >= 0; ii-- )
1990 SCH_FIELD& otherField = otherUnit->GetFields()[ii];
1993 otherUnit->GetFields().erase( otherUnit->GetFields().begin() + ii );
1997 if( updateExclFromBOM )
1999 otherUnit->SetExcludedFromBOM(
GetExcludedFromBOM( &aSourceSheet, aVariantName ), &sheet,
2003 if( updateExclFromBoard )
2009 if( updateExclFromPosFiles )
2016 otherUnit->SetDNP(
GetDNP( &aSourceSheet, aVariantName ), &sheet, aVariantName );
2018 if( updatePinMapOverride )
2019 otherUnit->SetPinMapOverride(
GetPinMapOverride( &aSourceSheet, aVariantName ), &sheet,
2024 for(
const std::unique_ptr<SCH_PIN>& model_pin :
m_pins )
2026 for(
SCH_PIN* src_pin : otherUnit->GetPinsByNumber( model_pin->GetNumber() ) )
2027 src_pin->SetAlt( model_pin->GetAlt() );
2038 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2039 aFunction(
pin.get() );
2042 aFunction( &field );
2055 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2057 if(
pin->GetNumber() == aNumber )
2066 const wxString& aVariantName )
const
2071 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2075 if(
pad == aPadNumber )
2086 std::vector<SCH_PIN*> pins;
2088 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2090 if(
pin->GetNumber() == aNumber )
2091 pins.push_back(
pin.get() );
2100 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2102 int pin_unit =
pin->GetLibPin() ?
pin->GetLibPin()->GetUnit() :
GetUnit();
2103 int pin_bodyStyle =
pin->GetLibPin() ?
pin->GetLibPin()->GetBodyStyle() :
GetBodyStyle();
2105 if( pin_unit > 0 && pin_unit !=
GetUnit() )
2108 if( pin_bodyStyle > 0 && pin_bodyStyle !=
GetBodyStyle() )
2111 if(
pin->GetPosition() == aPos )
2124 return std::vector<SCH_PIN*>();
2131 return m_part->GetPins();
2133 return std::vector<SCH_PIN*>();
2145 auto it =
m_pinMap.find( aLibPin );
2150 wxFAIL_MSG_AT(
"Pin not found", __FILE__, __LINE__, __FUNCTION__ );
2157 std::vector<const SCH_PIN*> pins;
2166 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2168 if( unit &&
pin->GetUnit() &&
pin->GetUnit() != unit )
2171 pins.push_back(
pin.get() );
2180 std::vector<SCH_PIN*> pins;
2189 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2191 if( unit &&
pin->GetUnit() &&
pin->GetUnit() != unit )
2194 pins.push_back(
pin.get() );
2210 wxCHECK_RET( aItem !=
nullptr && aItem->
Type() ==
SCH_SYMBOL_T, wxT(
"Cannot swap data with invalid symbol." ) );
2218 for( std::unique_ptr<SCH_PIN>&
pin : symbol->
m_pins )
2219 pin->SetParent( symbol );
2221 for( std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2222 pin->SetParent(
this );
2227 m_part.reset( libSymbol );
2265 if( field.IsPrivate() )
2268 if( field.IsMandatory() )
2269 aVars->push_back( field.GetCanonicalName().Upper() );
2271 aVars->push_back( field.GetName() );
2274 aVars->push_back( wxT(
"OP" ) );
2275 aVars->push_back( wxT(
"FOOTPRINT_LIBRARY" ) );
2276 aVars->push_back( wxT(
"FOOTPRINT_NAME" ) );
2277 aVars->push_back( wxT(
"UNIT" ) );
2278 aVars->push_back( wxT(
"SHORT_REFERENCE" ) );
2279 aVars->push_back( wxT(
"SYMBOL_LIBRARY" ) );
2280 aVars->push_back( wxT(
"SYMBOL_NAME" ) );
2281 aVars->push_back( wxT(
"SYMBOL_DESCRIPTION" ) );
2282 aVars->push_back( wxT(
"SYMBOL_KEYWORDS" ) );
2283 aVars->push_back( wxT(
"EXCLUDE_FROM_BOM" ) );
2284 aVars->push_back( wxT(
"EXCLUDE_FROM_BOARD" ) );
2285 aVars->push_back( wxT(
"EXCLUDE_FROM_SIM" ) );
2286 aVars->push_back( wxT(
"DNP" ) );
2287 aVars->push_back( wxT(
"SHORT_NET_NAME(<pin_number>)" ) );
2288 aVars->push_back( wxT(
"NET_NAME(<pin_number>)" ) );
2289 aVars->push_back( wxT(
"NET_CLASS(<pin_number>)" ) );
2290 aVars->push_back( wxT(
"PIN_NAME(<pin_number>)" ) );
2291 aVars->push_back( wxT(
"REFERENCE(<pin_number>)" ) );
2292 aVars->push_back( wxT(
"SHORT_REFERENCE(<pin_number>)" ) );
2293 aVars->push_back( wxT(
"UNIT(<pin_number>)" ) );
2304 const wxString& aVariantName,
int aDepth )
const
2308 thread_local wxRegEx operatingPoint( wxT(
"^"
2323 wxString variant = aVariantName.IsEmpty() ? schematic->GetCurrentVariant() : aVariantName;
2325 if( operatingPoint.Matches( *token ) )
2327 wxString
pin( operatingPoint.GetMatch( *token, 1 ).Lower() );
2328 wxString precisionStr( operatingPoint.GetMatch( *token, 3 ) );
2329 wxString rangeStr( operatingPoint.GetMatch( *token, 4 ) );
2331 int precision = precisionStr.IsEmpty() ? 3 : precisionStr[0] -
'0';
2332 wxString range = rangeStr.IsEmpty() ? wxString( wxS(
"~A" ) ) : rangeStr;
2336 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
2337 embeddedFilesStack.push_back( schematic->GetEmbeddedFiles() );
2340 embeddedFilesStack.push_back(
m_part->GetEmbeddedFiles() );
2346 aVariantName, devnull ).model;
2350 wxString spiceRef =
model.SpiceGenerator().ItemName( spiceItem );
2351 spiceRef = spiceRef.Lower();
2355 *token = schematic->GetOperatingPoint( spiceRef, precision, range );
2358 else if(
pin == wxS(
":power" ) )
2360 if( rangeStr.IsEmpty() )
2361 range = wxS(
"~W" );
2363 *token = schematic->GetOperatingPoint( spiceRef + wxS(
":power" ), precision, range );
2368 pin =
pin.SubString( 1, -1 );
2370 for(
const std::reference_wrapper<const SIM_MODEL_PIN>& modelPin :
model.GetPins() )
2372 SCH_PIN* symbolPin =
GetPin( modelPin.get().symbolPinNumber );
2376 if(
model.GetPins().size() == 2 )
2378 *token = schematic->GetOperatingPoint( spiceRef, precision, range );
2382 wxString netChainName = spiceRef + wxS(
":" ) + modelPin.get().modelPinName;
2383 *token = schematic->GetOperatingPoint( netChainName, precision, range );
2391 *token = wxS(
"?" );
2395 if( token->Contains(
':' ) )
2397 if( schematic->ResolveCrossReference( token, aDepth + 1 ) )
2403 wxString fieldName = field.IsMandatory() ? field.GetCanonicalName() : field.GetName();
2405 wxString textToken = field.GetText();
2406 textToken.Replace(
" ", wxEmptyString );
2407 wxString tokenString =
"${" + fieldName +
"}";
2410 if( textToken.IsSameAs( tokenString,
false ) )
2413 if( token->IsSameAs( fieldName,
false ) )
2417 *token =
GetRef( aPath,
true );
2419 else if( !aVariantName.IsEmpty() )
2422 std::optional<SCH_SYMBOL_VARIANT> symVariant =
GetVariant( *aPath, aVariantName );
2424 if( symVariant && symVariant->m_Fields.contains( fieldName ) )
2425 *token = symVariant->m_Fields.at( fieldName );
2427 *token = field.GetShownText( aPath,
false, aDepth + 1 );
2431 *token = field.GetShownText( aPath,
false, aDepth + 1 );
2439 if( token->IsSameAs( wxT(
"SIM.DEVICE" ) ) || token->IsSameAs( wxT(
"SIM.TYPE" ) )
2440 || token->IsSameAs( wxT(
"SIM.PINS" ) ) || token->IsSameAs( wxT(
"SIM.PARAMS" ) )
2441 || token->IsSameAs( wxT(
"SIM.LIBRARY" ) ) || token->IsSameAs( wxT(
"SIM.NAME" ) ) )
2443 *token = wxEmptyString;
2448 schematic->Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
2450 if( token->IsSameAs( templateFieldname.m_Name ) || token->IsSameAs( templateFieldname.m_Name.Upper() ) )
2454 *token = wxEmptyString;
2459 if( token->IsSameAs( wxT(
"FOOTPRINT_LIBRARY" ) ) )
2463 wxArrayString parts = wxSplit( footprint,
':' );
2465 if( parts.Count() > 0 )
2468 *token = wxEmptyString;
2472 else if( token->IsSameAs( wxT(
"FOOTPRINT_NAME" ) ) )
2476 wxArrayString parts = wxSplit( footprint,
':' );
2478 if( parts.Count() > 1 )
2479 *token = parts[std::min( 1, (
int) parts.size() - 1 )];
2481 *token = wxEmptyString;
2485 else if( token->IsSameAs( wxT(
"UNIT" ) ) )
2490 else if( token->IsSameAs( wxT(
"SHORT_REFERENCE" ) ) )
2492 *token =
GetRef( aPath,
false );
2495 else if( token->IsSameAs( wxT(
"SYMBOL_LIBRARY" ) ) )
2497 *token =
m_lib_id.GetUniStringLibNickname();
2500 else if( token->IsSameAs( wxT(
"SYMBOL_NAME" ) ) )
2502 *token =
m_lib_id.GetUniStringLibItemName();
2505 else if( token->IsSameAs( wxT(
"SYMBOL_DESCRIPTION" ) ) )
2510 else if( token->IsSameAs( wxT(
"SYMBOL_KEYWORDS" ) ) )
2515 else if( token->IsSameAs( wxT(
"EXCLUDE_FROM_BOM" ) ) )
2517 *token = wxEmptyString;
2519 if( aPath->
GetExcludedFromBOM( variant ) || this->ResolveExcludedFromBOM( aPath, variant ) )
2520 *token =
_(
"Excluded from BOM" );
2524 else if( token->IsSameAs( wxT(
"EXCLUDE_FROM_BOARD" ) ) )
2526 *token = wxEmptyString;
2528 if( aPath->
GetExcludedFromBoard( variant ) || this->ResolveExcludedFromBoard( aPath, variant ) )
2529 *token =
_(
"Excluded from board" );
2533 else if( token->IsSameAs( wxT(
"EXCLUDE_FROM_SIM" ) ) )
2535 *token = wxEmptyString;
2537 if( aPath->
GetExcludedFromSim( variant ) || this->ResolveExcludedFromSim( aPath, variant ) )
2538 *token =
_(
"Excluded from simulation" );
2542 else if( token->IsSameAs( wxT(
"DNP" ) ) )
2544 *token = wxEmptyString;
2546 if( aPath->
GetDNP( variant ) || this->ResolveDNP( aPath, variant ) )
2547 *token =
_(
"DNP" );
2551 else if( token->StartsWith( wxT(
"SHORT_NET_NAME(" ) ) || token->StartsWith( wxT(
"NET_NAME(" ) )
2552 || token->StartsWith( wxT(
"NET_CLASS(" ) ) || token->StartsWith( wxT(
"PIN_NAME(" ) )
2553 || token->StartsWith( wxT(
"PIN_BASE_NAME(" ) ) || token->StartsWith( wxT(
"PIN_ALT_LIST(" ) )
2554 || token->StartsWith( wxT(
"REFERENCE(" ) ) || token->StartsWith( wxT(
"SHORT_REFERENCE(" ) )
2555 || token->StartsWith( wxT(
"UNIT(" ) ) )
2557 wxString pinNumber = token->AfterFirst(
'(' );
2558 pinNumber = pinNumber.BeforeLast(
')' );
2560 bool isReferenceFunction = token->StartsWith( wxT(
"REFERENCE(" ) );
2561 bool isShortReferenceFunction = token->StartsWith( wxT(
"SHORT_REFERENCE(" ) );
2562 bool isUnitFunction = token->StartsWith( wxT(
"UNIT(" ) );
2566 std::vector<const SCH_PIN*> pinsToSearch;
2567 std::vector<const SCH_PIN*> altPinsToSearch;
2569 if( isReferenceFunction || isShortReferenceFunction || isUnitFunction )
2572 pinsToSearch.push_back(
pin );
2577 pinsToSearch.push_back(
pin );
2580 altPinsToSearch.push_back(
pin );
2585 if(
pin->GetNumber() == pinNumber )
2587 if( isReferenceFunction || isShortReferenceFunction || isUnitFunction )
2589 int pinUnit =
pin->GetUnit();
2592 if( isReferenceFunction )
2600 else if( isShortReferenceFunction )
2605 else if( isUnitFunction )
2614 *token = std::move(
result );
2617 else if( token->StartsWith( wxT(
"PIN_NAME" ) ) )
2619 *token =
pin->GetAlt().IsEmpty() ?
pin->GetName() :
pin->GetAlt();
2622 else if( token->StartsWith( wxT(
"PIN_BASE_NAME" ) ) )
2624 *token =
pin->GetBaseName();
2627 else if( token->StartsWith( wxT(
"PIN_ALT_LIST" ) ) )
2632 const std::map<wxString, SCH_PIN::ALT>& alts =
pin->GetAlternates();
2634 for(
const auto& [altName, altDef] : alts )
2636 if( !altList.IsEmpty() )
2637 altList += wxT(
", " );
2642 *token = std::move( altList );
2650 *token = wxEmptyString;
2652 else if( token->StartsWith( wxT(
"SHORT_NET_NAME" ) ) )
2656 if( netName.Lower().StartsWith( wxT(
"unconnected" ) ) )
2657 *token = wxT(
"NC" );
2659 *token = std::move( netName );
2661 else if( token->StartsWith( wxT(
"NET_NAME" ) ) )
2663 *token = conn->
Name();
2665 else if( token->StartsWith( wxT(
"NET_CLASS" ) ) )
2667 *token =
pin->GetEffectiveNetClass( aPath )->GetName();
2677 if(
pin->GetNumber() == pinNumber )
2680 if( token->StartsWith( wxT(
"PIN_BASE_NAME" ) ) )
2682 *token =
pin->GetBaseName();
2685 else if( token->StartsWith( wxT(
"PIN_ALT_LIST" ) ) )
2690 const std::map<wxString, SCH_PIN::ALT>& alts =
pin->GetAlternates();
2692 for(
const auto& [altName, altDef] : alts )
2694 if( !altList.IsEmpty() )
2695 altList += wxT(
", " );
2704 int pinUnit =
pin->GetUnit();
2720 if( symbol->
GetRef( &sheetPath,
false ) ==
GetRef( aPath,
false )
2723 targetPath = sheetPath;
2724 targetSymbol = symbol;
2737 *token = wxString::Format( wxT(
"<Unit %s not placed>" ),
SubReference( pinUnit,
false ) );
2743 SCH_PIN* instancePin =
nullptr;
2747 if( candidate->GetNumber() == pinNumber )
2749 instancePin = candidate;
2756 *token = wxEmptyString;
2761 if( token->StartsWith( wxT(
"PIN_NAME" ) ) )
2763 *token = instancePin->
GetAlt().IsEmpty() ? instancePin->
GetName() : instancePin->
GetAlt();
2772 *token = wxEmptyString;
2774 else if( token->StartsWith( wxT(
"SHORT_NET_NAME" ) ) )
2777 if( netName.Lower().StartsWith( wxT(
"unconnected" ) ) )
2778 *token = wxT(
"NC" );
2782 else if( token->StartsWith( wxT(
"NET_NAME" ) ) )
2784 *token = conn->
Name();
2786 else if( token->StartsWith( wxT(
"NET_CLASS" ) ) )
2796 *token = wxString::Format( wxT(
"<Unresolved: pin %s>" ), pinNumber );
2816 if( instance.m_Path ==
path )
2818 if( instance.m_Reference.IsEmpty() || aResetPrefix )
2829 if( instance.m_Reference.IsEmpty() || aResetPrefix )
2836 for( std::unique_ptr<SCH_PIN>&
pin :
m_pins )
2837 pin->ClearDefaultNetName( aSheetPath );
2847 if( currentReference.IsEmpty() || aResetPrefix )
2858 wxCHECK( aSheetPath.size() > 0,
false );
2863 if( instance.m_Path == aSheetPath )
2876 bool transform =
false;
2878 switch( aOrientation )
2999 wxFAIL_MSG(
"Invalid schematic symbol orientation type." );
3053 for(
int type_rotate : rotate_values )
3065 wxFAIL_MSG(
"Schematic symbol orientation matrix internal error." );
3073void SCH_SYMBOL::Show(
int nestLevel, std::ostream& os )
const
3076 NestedSpace( nestLevel, os ) <<
'<' <<
GetClass().Lower().mb_str() <<
" ref=\""
3082 for(
int i = 1; i < (int)
GetFields().size(); ++i )
3084 const wxString& value =
GetFields()[i].GetText();
3086 if( !value.IsEmpty() )
3088 NestedSpace( nestLevel + 1, os ) <<
"<field" <<
" name=\"" <<
TO_UTF8(
GetFields()[i].GetName() ) <<
'"'
3089 <<
" value=\"" <<
TO_UTF8( value ) <<
"\"/>\n";
3093 NestedSpace( nestLevel, os ) <<
"</" <<
TO_UTF8(
GetClass().Lower() ) <<
">\n";
3115 if( aIncludeFields )
3119 if( field.IsVisible() )
3120 bBox.
Merge( field.GetBoundingBox() );
3134 catch(
const boost::bad_pointer& e )
3136 wxFAIL_MSG( wxString::Format( wxT(
"Boost pointer exception occurred: %s" ), e.what() ) );
3162 auto addExcludes = [&]()
3167 msgs.Add(
_(
"Simulation" ) );
3170 msgs.Add(
_(
"BOM" ) );
3173 msgs.Add(
_(
"Board" ) );
3175 if(
GetDNP( currentSheet, currentVariant ) )
3176 msgs.Add(
_(
"DNP" ) );
3178 msg = wxJoin( msgs,
'|' );
3179 msg.Replace(
'|', wxS(
", " ) );
3182 aList.emplace_back(
_(
"Exclude from" ), msg );
3193 aList.emplace_back(
_(
"Power symbol" ),
3201 aList.emplace_back(
_(
"Value" ),
3208 aList.emplace_back(
_(
"flags" ), wxString::Format(
"%X",
GetEditFlags() ) );
3213 msg =
_(
"Missing parent" );
3215 std::shared_ptr<LIB_SYMBOL> parent =
m_part->GetParent().lock();
3218 msg = parent->GetName();
3222 else if( !
m_lib_id.GetLibNickname().empty() )
3224 aList.emplace_back(
_(
"Library" ),
m_lib_id.GetLibNickname() );
3228 aList.emplace_back(
_(
"Library" ),
_(
"Undefined!!!" ) );
3236 msg =
_(
"<Unknown>" );
3238 aList.emplace_back(
_(
"Footprint" ), msg );
3242 _(
"Keywords" ) + wxT(
": " ) +
m_part->GetKeyWords() );
3247 aList.emplace_back(
_(
"Reference" ),
GetRef( currentSheet ) );
3256 if( libNickname.empty() )
3257 msg =
_(
"No library defined!" );
3259 msg.Printf(
_(
"Symbol not found in %s!" ), libNickname );
3261 aList.emplace_back(
_(
"Library" ), msg );
3296 field.SetTextPos( pos );
3314 field.SetTextPos( pos );
3333 field.SetTextPos( pos );
3360 if( drawItem.Matches( aSearchData, aAuxData ) )
3371 for( std::unique_ptr<SCH_PIN>&
pin :
m_pins )
3379 aItemList.push_back( item );
3385 std::vector<DANGLING_END_ITEM>& aItemListByPos,
const SCH_SHEET_PATH* aPath )
3387 bool changed =
false;
3389 for( std::unique_ptr<SCH_PIN>&
pin :
m_pins )
3391 bool previousState =
pin->IsDangling();
3392 pin->SetIsDangling(
true );
3397 bool do_break =
false;
3399 for(
auto it = lower; it < aItemListByPos.end() && it->GetPosition() == pos; it++ )
3418 pin->SetIsDangling(
false );
3429 changed = ( changed || ( previousState !=
pin->IsDangling() ) );
3454 wxCHECK( symbol,
false );
3460 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
3462 if(
pin->IsDangling() )
3475 if(
GetRef( aInstance ) != symbol->
GetRef( aInstance ) )
3485 for(
size_t i = 0; i <
m_pins.size(); i++ )
3497 std::vector<VECTOR2I> retval;
3499 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
3503 int pin_unit =
pin->GetLibPin() ?
pin->GetLibPin()->GetUnit() :
GetUnit();
3504 int pin_bodyStyle =
pin->GetLibPin() ?
pin->GetLibPin()->GetBodyStyle() :
GetBodyStyle();
3506 if( pin_unit > 0 && pin_unit !=
GetUnit() )
3509 if( pin_bodyStyle > 0 && pin_bodyStyle !=
GetBodyStyle() )
3535 return wxString::Format(
_(
"Symbol %s [%s]" ),
3543 for(
KICAD_T scanType : aScanTypes )
3588 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
3592 int pin_unit =
pin->GetLibPin() ?
pin->GetLibPin()->GetUnit() :
GetUnit();
3593 int pin_bodyStyle =
pin->GetLibPin() ?
pin->GetLibPin()->GetBodyStyle() :
GetBodyStyle();
3595 if( pin_unit > 0 && pin_unit !=
GetUnit() )
3598 if( pin_bodyStyle > 0 && pin_bodyStyle !=
GetBodyStyle() )
3635 std::vector<SCH_FIELD*> fields, otherFields;
3638 aSymbol.
GetFields( otherFields,
false );
3640 if( fields.size() != otherFields.size() )
3643 for(
int ii = 0; ii < (int) fields.size(); ii++ )
3648 if( fields[ii]->GetText().Cmp( otherFields[ii]->GetText() ) != 0 )
3658 return !( *
this == aSymbol );
3664 wxCHECK_MSG(
Type() == aSymbol.
Type(), *
this,
3665 wxT(
"Cannot assign object type " ) + aSymbol.
GetClass() + wxT(
" to type " ) +
GetClass() );
3667 if( &aSymbol !=
this )
3685 field.SetParent(
this );
3698 bBox.
Inflate( aAccuracy / 2 );
3714 rect.
Inflate( aAccuracy / 2 );
3736 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
3749 if(
pin->GetLocalPosition() == new_pos )
3764 const VECTOR2I& aOffset,
bool aDimmed )
3774 bool usingAlternate = ( effectiveSym !=
m_part.get() );
3781 std::vector<SCH_PIN*> symbolPins =
MapLibPins( libPins, usingAlternate );
3784 for(
unsigned i = 0; i < tempPins.size(); ++i )
3786 SCH_PIN* symbolPin = symbolPins[i];
3787 SCH_PIN* tempPin = tempPins[i];
3807 text->SetText(
dummy.GetShownText(
false ) );
3817 bool dnp =
GetDNP( sheet, variant );
3819 for(
bool local_background : {
true,
false } )
3825 field.ClearRenderCache();
3829 && ( field.IsVisible() || field.IsForceVisible() ) )
3842 std::vector<wxString> properties;
3846 wxString text_field = field.GetShownText( sheet,
false, 0, variant );
3848 if( text_field.IsEmpty() )
3851 properties.emplace_back( wxString::Format( wxT(
"!%s = %s" ), field.GetName(), text_field ) );
3856 properties.emplace_back(
3857 wxString::Format( wxT(
"!%s = %s" ),
_(
"Keywords" ),
3867 if( !effectiveSym->
IsPower() )
3881 margins.
x = std::max( margins.
x * 0.6, margins.
y * 0.3 );
3882 margins.
y = std::max( margins.
y * 0.6, margins.
x * 0.3 );
3900 double lineWidth = aSize / 10.0;
3902 std::vector<SCH_SHAPE> shapeList;
3904 int tolerance = 100;
3906 for(
const SCH_SHAPE& shape : shapeList )
3912 aPlotter->
BezierCurve( shape.GetStart(), shape.GetBezierC1(), shape.GetBezierC2(), shape.GetEnd(),
3913 tolerance, lineWidth );
3915 aPlotter->
Circle( shape.getCenter(), shape.GetRadius() * 2, filled, lineWidth );
3966 bool usingAlternate = ( effectiveSym !=
m_part.get() );
3977 std::vector<SCH_PIN*> symbolPins =
MapLibPins( libPins, usingAlternate );
3981 for(
unsigned i = 0; i < tempPins.size(); ++i )
3983 SCH_PIN* symbolPin = symbolPins[i];
3984 SCH_PIN* tempPin = tempPins[i];
4002 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
4004 if(
pin->IsBrightened() )
4014 for( std::unique_ptr<SCH_PIN>&
pin :
m_pins )
4015 pin->ClearBrightened();
4033 m_part->SetShowPinNames( aShow );
4046 m_part->SetShowPinNumbers( aShow );
4052 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_pins )
4054 int pin_unit =
pin->GetLibPin() ?
pin->GetLibPin()->GetUnit() :
GetUnit();
4055 int pin_bodyStyle =
pin->GetLibPin() ?
pin->GetLibPin()->GetBodyStyle() :
GetBodyStyle();
4057 if( pin_unit > 0 && pin_unit !=
GetUnit() )
4060 if( pin_bodyStyle > 0 && pin_bodyStyle !=
GetBodyStyle() )
4063 if(
pin->IsPointClickableAnchor( aPos ) )
4082 if( pin_list.size() != 1 )
4100 if( pin_list.size() != 1 )
4112 return m_part->IsLocalPower();
4121 return m_part->IsGlobalPower();
4133 wxCHECK(
m_part,
false );
4135 return m_part->IsNormal();
4141 std::unordered_set<wxString> componentClass;
4143 auto getComponentClassFields = [&](
const std::vector<SCH_FIELD>& fields )
4147 if( field.GetCanonicalName() == wxT(
"Component Class" ) )
4149 if( field.GetShownText( aPath,
false ) != wxEmptyString )
4150 componentClass.insert( field.GetShownText( aPath,
false ) );
4156 getComponentClassFields(
m_fields );
4163 getComponentClassFields( label->GetFields() );
4167 return componentClass;
4172 const wxString& aVariantName )
const
4177 return std::nullopt;
4179 return instance.
m_Variants.find( aVariantName )->second;
4191 instance->
m_Variants.insert( std::make_pair( aVariant.
m_Name, aVariant ) );
4198 if( aVariantName.IsEmpty() )
4203 if( !instance || !instance->
m_Variants.contains( aVariantName ) )
4212 wxString libIdStr = libId.
Format();
4221 return cacheIt->second.get();
4245 cached = libSymbol->Flatten();
4253 return cached.get();
4271 if( !variantName.IsEmpty() )
4285 bool aByNumber )
const
4287 std::vector<SCH_PIN*> mapped;
4289 mapped.reserve( aLibPins.size() );
4295 std::vector<bool> matched( basePins.size(),
false );
4297 for(
const SCH_PIN* alternatePin : aLibPins )
4299 SCH_PIN* instancePin =
nullptr;
4301 for(
size_t i = 0; i < basePins.size(); ++i )
4307 instancePin =
GetPin(
const_cast<SCH_PIN*
>( basePins[i] ) );
4311 mapped.push_back( instancePin );
4316 for(
const SCH_PIN* libPin : aLibPins )
4317 mapped.push_back(
GetPin(
const_cast<SCH_PIN*
>( libPin ) ) );
4329 if( !instance || !instance->
m_Variants.contains( aVariantName ) )
4337 const wxString& aNewName )
4342 if( !instance || !instance->
m_Variants.contains( aOldName ) )
4347 variant.
m_Name = aNewName;
4349 instance->
m_Variants.insert( std::make_pair( aNewName, variant ) );
4354 const wxString& aNewVariant )
4359 if( !instance || !instance->
m_Variants.contains( aSourceVariant ) )
4364 variant.
m_Name = aNewVariant;
4365 instance->
m_Variants.insert( std::make_pair( aNewVariant, variant ) );
4370 const wxString& aVariantName,
4378 if( !instance->
m_Variants.contains( aVariantName ) )
4382 instance->
m_Variants.insert( std::make_pair( aVariantName, newVariant ) );
4385 instance->
m_Variants[aVariantName].m_SymbolOverride = aLibId;
4391 const wxString& aVariantName )
4395 if( !instance || !instance->
m_Variants.contains( aVariantName ) )
4455 for(
unsigned i = 0; i <
m_pins.size(); ++i )
4464 if( m_instanceReferences != symbol.m_instanceReferences )
4490 double aLineWidth,
bool aHorizontal )
4494 double x_right = aSize / 1.6180339887;
4495 double x_middle = x_right / 2.0;
4508 aShapeList.back().SetStart( bottomPt );
4509 aShapeList.back().SetBezierC1( bottomAnchorPt );
4510 aShapeList.back().SetBezierC2( leftSideAnchorPt1 );
4511 aShapeList.back().SetEnd( leftPt );
4515 aShapeList.back().SetStart( leftPt );
4516 aShapeList.back().SetBezierC1( leftSideAnchorPt2 );
4517 aShapeList.back().SetBezierC2( rightSideAnchorPt2 );
4518 aShapeList.back().SetEnd( rightPt );
4521 aShapeList.back().SetStart( rightPt );
4522 aShapeList.back().SetBezierC1( rightSideAnchorPt1 );
4523 aShapeList.back().SetBezierC2( bottomAnchorPt );
4524 aShapeList.back().SetEnd( bottomPt );
4527 aShapeList.back().SetCenter( ( leftPt + rightPt ) / 2.0 );
4528 aShapeList.back().SetRadius( aSize / 15.0 );
4533 shape.Rotate(
VECTOR2I( 0, 0 ),
true );
4588 auto hasLibPart = [](
INSPECTABLE* aItem ) ->
bool
4591 return symbol->GetLibSymbolRef() !=
nullptr;
4604 const wxString groupFields =
_HKI(
"Fields" );
4624 auto multiUnit = [=](
INSPECTABLE* aItem ) ->
bool
4627 return symbol->IsMultiUnit();
4632 auto multiBodyStyle = [=](
INSPECTABLE* aItem ) ->
bool
4635 return symbol->IsMultiBodyStyle();
4646 wxPGChoices choices;
4650 for(
int ii = 1; ii <= symbol->GetUnitCount(); ii++ )
4651 choices.Add( symbol->GetUnitDisplayName( ii,
false ), ii );
4663 wxPGChoices choices;
4667 for(
int ii = 1; ii <= symbol->GetBodyStyleCount(); ii++ )
4668 choices.Add( symbol->GetBodyStyleDescription( ii,
false ) );
4674 const wxString groupAttributes =
_HKI(
"Attributes" );
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
constexpr EDA_IU_SCALE schIUScale
BITMAPS
A list of all bitmap identifiers.
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr const Vec GetEnd() const
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
constexpr coord_type GetY() const
constexpr size_type GetWidth() const
constexpr coord_type GetX() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr ecoord_type GetArea() const
Return the area of the rectangle.
constexpr size_type GetHeight() const
constexpr coord_type GetLeft() const
constexpr bool Contains(const Vec &aPoint) const
constexpr const Vec & GetOrigin() const
constexpr coord_type GetRight() const
constexpr void Offset(coord_type dx, coord_type dy)
constexpr bool Intersects(const BOX2< Vec > &aRect) const
constexpr coord_type GetBottom() const
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
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...
DANGLING_END_T GetType() const
const EDA_ITEM * GetParent() const
bool IsHorizontal() const
The base class for create windows for drawing purpose.
EDA_ITEM_FLAGS GetEditFlags() const
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
virtual void SetParentGroup(EDA_GROUP *aGroup)
virtual void SetParent(EDA_ITEM *aParent)
EDA_ITEM * m_parent
Owner.
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual void SetTextPos(const VECTOR2I &aPoint)
virtual void Offset(const VECTOR2I &aOffset)
virtual EDA_ANGLE GetTextAngle() const
static ENUM_MAP< T > & Instance()
A text control validator used for validating the text allowed in fields.
Class that other classes need to inherit from, in order to be inspectable.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxString AsString() const
A logical library item identifier and consists of various portions much like a URI.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
wxString GetKeyWords() const override
std::vector< const SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
bool IsPower() const override
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
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.
static wxString LetterSubReference(int aUnit, wxChar aInitialLetter)
static LIB_SYMBOL * GetDummy()
Returns a dummy LIB_SYMBOL, used when one is missing in the schematic.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
void SetUnitCount(int aCount, bool aDuplicateDrawItems)
Set the units per symbol count.
void SetKeyWords(const wxString &aKeyWords)
void SetBodyStyleCount(int aCount, bool aDuplicateDrawItems, bool aDuplicatePins)
Set or clear the alternate body style (DeMorgan) for the symbol.
void SetFPFilters(const wxArrayString &aFilters)
const BOX2I GetBodyBoundingBox(int aUnit, int aBodyStyle, bool aIncludePins, bool aIncludePrivateItems) const
Get the symbol bounding box excluding fields.
EMBEDDED_FILES * GetEmbeddedFiles() override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
void SetLibId(const LIB_ID &aLibId)
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
A singleton reporter that reports to nowhere.
Base plotter engine class.
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.
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.
virtual void StartBlock(void *aData)
calling this function allows one to define the beginning of a group of drawing items,...
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, void *aData)
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
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...
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
const wxString & Name() const
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Holds all the data relating to one schematic.
wxString GetCurrentVariant() const
Return the current variant being edited.
SCH_SHEET_PATH & CurrentSheet() const
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString LocalName() const
wxString Name(bool aIgnoreSheet=false) const
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() 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.
void ImportValues(const SCH_FIELD &aSource)
Copy parameters from a SCH_FIELD source.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0, const wxString &aVariantName=wxEmptyString) 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,...
virtual void SetBodyStyle(int aBodyStyle)
void SetLocked(bool aLocked) override
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
void SetPrivate(bool aPrivate)
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
bool IsLocked() const override
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
virtual void ClearCaches()
void SetLayer(SCH_LAYER_ID aLayer)
virtual void SetUnit(int aUnit)
AUTOPLACE_ALGO m_fieldsAutoplaced
std::unordered_set< SCH_RULE_AREA * > m_rule_areas_cache
Store pointers to rule areas which this item is contained within.
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
ALT GetAlt(const wxString &aAlt)
void SetName(const wxString &aName)
const wxString & GetName() const
bool IsDangling() const override
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.
void SetShape(GRAPHIC_PINSHAPE aShape)
VECTOR2I GetPosition() const override
const wxString & GetShownName() const
void SetType(ELECTRICAL_PINTYPE aType)
const wxString & GetNumber() const
GRAPHIC_PINSHAPE GetShape() const
ELECTRICAL_PINTYPE GetType() const
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.
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
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
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.
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)
wxString GetUnitDisplayName(int aUnit, bool aLabel) const override
Return the display name for a given unit aUnit.
SCH_SYMBOL & operator=(const SCH_SYMBOL &aItem)
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)
bool IsSymbolLikePowerGlobalLabel() const
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SYMBOLs don't currently support embedded files, but their LIB_SYMBOL counterparts do.
wxString GetSymbolIDAsString() const
LIB_ID m_lib_id
Name and library the symbol was loaded from, i.e. 74xx:74LS00.
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)
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the symbol's fields.
BOX2I GetBodyAndPinsBoundingBox() const override
Return a bounding box for the symbol body and pins but not the fields.
wxString GetBodyStyleProp() const override
void SetRefProp(const wxString &aRef)
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.
void SetPosition(const VECTOR2I &aPosition) override
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.
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
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_variantSymbolCache
SCH_SYMBOL_INSTANCE * getInstance(const KIID_PATH &aPath)
wxString SubReference(int aUnit, bool aAddSeparator=true) const
wxString GetClass() const override
Return the class name.
void RemoveInstance(const SCH_SHEET_PATH &aInstancePath)
void SetFieldText(const wxString &aFieldName, const wxString &aFieldText, const SCH_SHEET_PATH *aPath=nullptr, const wxString &aVariantName=wxEmptyString)
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)
void SetBodyStyleProp(const wxString &aBodyStyle) override
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.
std::vector< SCH_PIN * > GetPins() const override
bool GetExcludedFromPosFilesProp() const
void RemoveField(const wxString &aFieldName)
Remove a user field from the symbol.
wxString GetFieldText(const wxString &aFieldName, const SCH_SHEET_PATH *aPath=nullptr, const wxString &aVariantName=wxEmptyString) 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
wxString GetSchSymbolLibraryName() const
void ClearCaches() override
wxString GetShownKeyWords(int aDepth=0) const override
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()
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
bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool IsGlobalPower() const override
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.
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
void SetExcludedFromBOMProp(bool aEnable)
static std::unordered_map< TRANSFORM, int > s_transformToOrientationCache
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 reference for the given sheet path for this symbol.
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, const wxString &aVariantName=wxEmptyString) const override
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.
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.
std::vector< SCH_PIN * > GetAllLibPins() const
const wxString GetFootprintFieldText(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, const wxString &aVariantName=wxEmptyString) 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...
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.
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.
std::vector< SCH_PIN * > MapLibPins(const std::vector< const SCH_PIN * > &aLibPins, bool aByNumber) const
Map pins of an effective library symbol to this symbol's instance pins.
bool IsMissingLibSymbol() const
Check to see if the library symbol is set to the dummy library symbol.
VECTOR2I GetPosition() const override
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.
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)
wxString GetShownDescription(int aDepth=0) const override
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
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)
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.
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
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
void SetDNPProp(bool aEnable)
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< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
PIN_MAP_INSTANCE_OVERRIDE m_pinMapOverride
Base (no-variant) pin-to-pad map override applied when no variant override exists for the sheet path ...
bool m_isInNetlist
True if the symbol should appear in netlist.
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)
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()
std::unordered_set< wxString > GetComponentClassNames(const SCH_SHEET_PATH *aPath) const
Return the component classes this symbol belongs in.
std::vector< std::unique_ptr< SCH_PIN > > m_pins
A SCH_PIN for every #LIB_PIN.
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
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 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, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
An interface to the global shared library manager that is schematic-specific and linked to one projec...
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.
bool m_DNP
True if symbol is set to 'Do Not Populate'.
bool m_excludedFromPosFiles
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
const TRANSFORM & GetTransform() const
int GetPinNameOffset() const
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
virtual bool GetShowPinNames() const
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
SYMBOL & operator=(const SYMBOL &aItem)
virtual bool GetShowPinNumbers() const
TRANSFORM m_transform
The rotation/mirror transformation.
std::map< wxString, wxString > m_Fields
bool m_ExcludedFromPosFiles
A type-safe container of any type.
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
static bool empty(const wxTextEntryBase *aCtrl)
T Convert(const wxString &aValue)
Convert a wxString to a generic type T.
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_VERTICAL
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
static constexpr EDA_ANGLE ANGLE_270
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
#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
@ FILLED_SHAPE
Fill with object color.
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.
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Message panel definition file.
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)
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)
@ PT_NC
not connected (must be left open)
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
#define NO_SETTER(owner, type)
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
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)
int NextFieldOrdinal(const std::vector< SCH_FIELD > &aFields)
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
static void plotLocalPowerIcon(PLOTTER *aPlotter, const VECTOR2D &aPos, double aSize, bool aRotate)
plot a local power pin indicator icon.
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.
std::vector< std::pair< FIELD_T, wxString > > Fields
Per-instance override of the active pin map and a sparse delta on top.
A simple container for schematic symbol instance information.
std::map< wxString, SCH_SYMBOL_VARIANT > m_Variants
A list of symbol variants.
Hold a name of a symbol's field, field value, and default visibility.
@ SYM_ROTATE_COUNTERCLOCKWISE
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".
wxString GetCanonicalFieldName(FIELD_T aFieldType)
nlohmann::json_schema::json_validator validator
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.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ SCH_FIELD_LOCATE_REFERENCE_T
@ SCH_FIELD_LOCATE_FOOTPRINT_T
@ SCH_FIELD_LOCATE_VALUE_T
@ SCH_FIELD_LOCATE_DATASHEET_T
@ SCH_SYMBOL_LOCATE_POWER_T
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
VECTOR2< double > VECTOR2D