Allow text variables to reference parent sheet's fields.

Fixes https://gitlab.com/kicad/code/kicad/issues/2466
This commit is contained in:
Jeff Young 2020-07-28 13:11:11 +01:00
parent 46602148dc
commit 55784afbfe
5 changed files with 37 additions and 3 deletions

View File

@ -373,6 +373,11 @@ void DIALOG_LABEL_EDITOR::onScintillaCharAdded( wxStyledTextEvent &aEvent )
m_CurrentText->GetContextualTextVars( &autocompleteTokens );
SCHEMATIC* schematic = m_CurrentText->Schematic();
if( schematic && schematic->CurrentSheet().Last() )
schematic->CurrentSheet().Last()->GetContextualTextVars( &autocompleteTokens );
for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )
autocompleteTokens.push_back( entry.first );
}

View File

@ -363,8 +363,16 @@ void DIALOG_SCH_EDIT_ONE_FIELD::onScintillaCharAdded( wxStyledTextEvent &aEvent
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( m_field->GetParent() );
if( comp )
{
comp->GetContextualTextVars( &autocompleteTokens );
else if( sheet )
SCHEMATIC* schematic = comp->Schematic();
if( schematic && schematic->CurrentSheet().Last() )
schematic->CurrentSheet().Last()->GetContextualTextVars( &autocompleteTokens );
}
if( sheet )
sheet->GetContextualTextVars( &autocompleteTokens );
for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )

View File

@ -105,7 +105,17 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
[&]( wxString* token ) -> bool
{
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( m_Parent );
return component->ResolveTextVar( token, aDepth + 1 );
if( component->ResolveTextVar( token, aDepth + 1 ) )
return true;
SCHEMATIC* schematic = component->Schematic();
SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
return true;
return false;
};
std::function<bool( wxString* )> sheetResolver =

View File

@ -191,7 +191,10 @@ bool SCH_SHEET::IsRootSheet() const
void SCH_SHEET::GetContextualTextVars( wxArrayString* aVars ) const
{
for( int i = 0; i < SHEET_MANDATORY_FIELDS; ++i )
aVars->push_back( m_fields[i].GetCanonicalName() );
aVars->push_back( m_fields[i].GetCanonicalName().Upper() );
for( size_t i = SHEET_MANDATORY_FIELDS; i < m_fields.size(); ++i )
aVars->push_back( m_fields[i].GetName() );
aVars->push_back( wxT( "#" ) );
aVars->push_back( wxT( "##" ) );

View File

@ -537,6 +537,14 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const
}
}
}
else
{
SCHEMATIC* schematic = Schematic();
SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr;
if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) )
return true;
}
}
return false;