Support SHORT_NET_NAME(pin_number) and friends on symbols.

While it's of debatable use in the schematic, some users want to
author them there so that they're then copied onto the board.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15544

(cherry picked from commit d74e9ba040)
This commit is contained in:
Jeff Young 2023-08-30 11:43:21 +01:00
parent 70d5fccb54
commit 93fdd35b31
2 changed files with 38 additions and 1 deletions

View File

@ -1154,6 +1154,10 @@ void SCH_SYMBOL::GetContextualTextVars( wxArrayString* aVars ) const
aVars->push_back( wxT( "EXCLUDE_FROM_BOM" ) );
aVars->push_back( wxT( "EXCLUDE_FROM_BOARD" ) );
aVars->push_back( wxT( "DNP" ) );
aVars->push_back( wxT( "SHORT_NET_NAME(<pin_number>)" ) );
aVars->push_back( wxT( "NET_NAME(<pin_number>)" ) );
aVars->push_back( wxT( "NET_CLASS(<pin_number>)" ) );
aVars->push_back( wxT( "PIN_NAME(<pin_number>)" ) );
}
@ -1275,6 +1279,39 @@ bool SCH_SYMBOL::ResolveTextVar( wxString* token, int aDepth, const SCH_SHEET_PA
*token = this->GetDNP() ? _( "DNP" ) : wxT( "" );
return true;
}
else if( token->StartsWith( wxT( "SHORT_NET_NAME(" ) )
|| token->StartsWith( wxT( "NET_NAME(" ) )
|| token->StartsWith( wxT( "NET_CLASS(" ) )
|| token->StartsWith( wxT( "PIN_NAME(" ) ) )
{
wxString pinNumber = token->AfterFirst( '(' );
pinNumber = pinNumber.BeforeLast( ')' );
for( SCH_PIN* pin : GetPins( aPath ) )
{
if( pin->GetNumber() == pinNumber )
{
if( token->StartsWith( wxT( "PIN_NAME" ) ) )
{
*token = pin->GetAlt().IsEmpty() ? pin->GetName() : pin->GetAlt();
return true;
}
SCH_CONNECTION* conn = pin->Connection( aPath );
if( !conn )
*token = wxEmptyString;
else if( token->StartsWith( wxT( "SHORT_NET_NAME" ) ) )
*token = conn->LocalName();
else if( token->StartsWith( wxT( "NET_NAME" ) ) )
*token = conn->Name();
else if( token->StartsWith( wxT( "NET_CLASS" ) ) )
*token = pin->GetEffectiveNetClass( aPath )->GetName();
return true;
}
}
}
// See if parent can resolve it (this will recurse to ancestors)