From f9f0f6fe245118ae2b390839b8701bbcc57802a1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 7 May 2022 21:09:06 +0100 Subject: [PATCH] Implement cross-references for labels. Fixes https://gitlab.com/kicad/code/kicad/issues/11564 --- eeschema/dialogs/dialog_label_properties.cpp | 10 +++++++++- eeschema/sch_label.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/eeschema/dialogs/dialog_label_properties.cpp b/eeschema/dialogs/dialog_label_properties.cpp index 2eb68d0651..8d07f06f83 100644 --- a/eeschema/dialogs/dialog_label_properties.cpp +++ b/eeschema/dialogs/dialog_label_properties.cpp @@ -228,7 +228,12 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataToWindow() if( m_activeTextEntry ) { // show control characters in a human-readable format - m_activeTextEntry->SetValue( UnescapeString( m_currentLabel->GetText() ) ); + wxString text = UnescapeString( m_currentLabel->GetText() ); + + // show text variable cross-references in a human-readable format + text = m_currentLabel->Schematic()->ConvertKIIDsToRefs( text ); + + m_activeTextEntry->SetValue( text ); } if( m_currentLabel->Type() == SCH_GLOBAL_LABEL_T || m_currentLabel->Type() == SCH_LABEL_T ) @@ -403,6 +408,9 @@ bool DIALOG_LABEL_PROPERTIES::TransferDataFromWindow() // labels need escaping text = EscapeString( m_activeTextEntry->GetValue(), CTX_NETNAME ); + // convert any text variable cross-references to their UUIDs + text = m_currentLabel->Schematic()->ConvertRefsToKIIDs( text ); + #ifdef __WXMAC__ // On macOS CTRL+Enter produces '\r' instead of '\n' regardless of EOL setting text.Replace( "\r", "\n" ); diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 2a79a21322..f931002cce 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -447,6 +447,12 @@ void SCH_LABEL_BASE::AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const { + if( token->Contains( ':' ) ) + { + if( Schematic()->ResolveCrossReference( token, aDepth ) ) + return true; + } + if( ( Type() == SCH_GLOBAL_LABEL_T || Type() == SCH_HIER_LABEL_T || Type() == SCH_SHEET_PIN_T ) && token->IsSameAs( wxT( "CONNECTION_TYPE" ) ) ) {