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
This commit is contained in:
Seth Hillbrand 2024-04-20 13:38:35 -07:00
parent 9f691d063c
commit 6540c3ec9f
1 changed files with 21 additions and 2 deletions

View File

@ -204,15 +204,30 @@ wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraT
return symbol->ResolveTextVar( aPath, token, aDepth + 1 );
};
std::function<bool( wxString* )> schematicResolver =
[&]( wxString* token ) -> bool
{
if( SCHEMATIC* schematic = Schematic() )
return schematic->ResolveTextVar( aPath, token, aDepth + 1 );
return false;
};
std::function<bool( wxString* )> sheetResolver =
[&]( wxString* token ) -> bool
{
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( 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<bool( wxString* )> labelResolver =
@ -234,7 +249,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 )
{
@ -245,7 +261,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 );
}
}
}