From 93fdd35b31387ff2f2dbc83404d79efc3b99b86a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 30 Aug 2023 11:43:21 +0100 Subject: [PATCH] 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 d74e9ba0409d39f78794ae03c97314de3100f5b8) --- eeschema/sch_symbol.cpp | 37 +++++++++++++++++++++++++++++++++++++ pcbnew/footprint.cpp | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 3f10486e06..4f49755329 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -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()" ) ); + aVars->push_back( wxT( "NET_NAME()" ) ); + aVars->push_back( wxT( "NET_CLASS()" ) ); + aVars->push_back( wxT( "PIN_NAME()" ) ); } @@ -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) diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index e65f0530dc..d75ae7cc50 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -525,7 +525,7 @@ bool FOOTPRINT::ResolveTextVar( wxString* token, int aDepth ) const else if( token->StartsWith( wxT( "SHORT_NET_NAME(" ) ) || token->StartsWith( wxT( "NET_NAME(" ) ) || token->StartsWith( wxT( "NET_CLASS(" ) ) - || token->StartsWith( wxT( "PIN_NAME(" ) ) ) + || token->StartsWith( wxT( "PIN_NAME(" ) ) ) { wxString padNumber = token->AfterFirst( '(' ); padNumber = padNumber.BeforeLast( ')' );