From 55784afbfeb3756be123309d7d4568de824bd10d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 28 Jul 2020 13:11:11 +0100 Subject: [PATCH] Allow text variables to reference parent sheet's fields. Fixes https://gitlab.com/kicad/code/kicad/issues/2466 --- eeschema/dialogs/dialog_edit_label.cpp | 5 +++++ eeschema/dialogs/dialog_edit_one_field.cpp | 10 +++++++++- eeschema/sch_field.cpp | 12 +++++++++++- eeschema/sch_sheet.cpp | 5 ++++- eeschema/sch_text.cpp | 8 ++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index 00b8bb486c..5dd74f58ab 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -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 entry : Prj().GetTextVars() ) autocompleteTokens.push_back( entry.first ); } diff --git a/eeschema/dialogs/dialog_edit_one_field.cpp b/eeschema/dialogs/dialog_edit_one_field.cpp index 83b59393a6..e87eae68cb 100644 --- a/eeschema/dialogs/dialog_edit_one_field.cpp +++ b/eeschema/dialogs/dialog_edit_one_field.cpp @@ -363,8 +363,16 @@ void DIALOG_SCH_EDIT_ONE_FIELD::onScintillaCharAdded( wxStyledTextEvent &aEvent SCH_SHEET* sheet = dynamic_cast( 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 entry : Prj().GetTextVars() ) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 3bf524b238..7ce5a6761b 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -105,7 +105,17 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const [&]( wxString* token ) -> bool { SCH_COMPONENT* component = static_cast( 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 sheetResolver = diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 293b8fbe21..0b3348203e 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -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( "##" ) ); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 7cab5c13c7..443ef4d428 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -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;