From 7f690d596bf83e95f2fb1e438f757596dad8304b Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sat, 20 Apr 2024 13:38:35 -0700 Subject: [PATCH] Resolve worksheet variables in SCH_FIELD Sheet fields should also resolve the worksheet of that sheet and not the parent sheet Fixes https://gitlab.com/kicad/code/kicad/-/issues/17723 (cherry picked from commit 6540c3ec9f2ab62c6b5a0b52b54ed9e52bdca6ff) --- eeschema/sch_field.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 8aa12b2069..ea71f92ff3 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -195,15 +195,30 @@ wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraT return symbol->ResolveTextVar( aPath, token, aDepth + 1 ); }; + std::function schematicResolver = + [&]( wxString* token ) -> bool + { + if( SCHEMATIC* schematic = Schematic() ) + return schematic->ResolveTextVar( aPath, token, aDepth + 1 ); + + return false; + }; + std::function sheetResolver = [&]( wxString* token ) -> bool { SCH_SHEET* sheet = static_cast( m_parent ); + SCHEMATIC* schematic = Schematic(); SCH_SHEET_PATH path = *aPath; path.push_back( sheet ); - return sheet->ResolveTextVar( &path, token, aDepth + 1 ); + bool retval = sheet->ResolveTextVar( &path, token, aDepth + 1 ); + + if( schematic ) + retval |= schematic->ResolveTextVar( &path, token, aDepth + 1 ); + + return retval; }; std::function labelResolver = @@ -222,7 +237,8 @@ wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraT { text = wxS( "" ); } - else if( HasTextVars() ) + + for( int ii = 0; ii < 10 && text.Contains( wxT( "${" ) ); ++ii ) { if( aDepth < 10 ) { @@ -233,7 +249,10 @@ wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraT else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) text = ExpandTextVars( text, &labelResolver ); else if( Schematic() ) + { text = ExpandTextVars( text, &Schematic()->Prj() ); + text = ExpandTextVars( text, &schematicResolver ); + } } }