From 8524042352e217bb5bffb1556807c02e91798598 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 (cherry picked from commit f9f0f6fe245118ae2b390839b8701bbcc57802a1) --- .../dialog_text_and_label_properties.cpp | 20 +++++++++++----- eeschema/sch_text.cpp | 23 ++++++++----------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/eeschema/dialogs/dialog_text_and_label_properties.cpp b/eeschema/dialogs/dialog_text_and_label_properties.cpp index 9a341d24db..17af78293c 100644 --- a/eeschema/dialogs/dialog_text_and_label_properties.cpp +++ b/eeschema/dialogs/dialog_text_and_label_properties.cpp @@ -176,17 +176,22 @@ bool DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataToWindow() if( !wxDialog::TransferDataToWindow() ) return false; + SCHEMATIC& schematic = m_Parent->Schematic(); + if( m_CurrentText->Type() == SCH_TEXT_T ) { - SCHEMATIC& schematic = m_Parent->Schematic(); - // show text variable cross-references in a human-readable format m_valueMultiLine->SetValue( schematic.ConvertKIIDsToRefs( m_CurrentText->GetText() ) ); } else { // show control characters in a human-readable format - m_activeTextEntry->SetValue( UnescapeString( m_CurrentText->GetText() ) ); + wxString text = UnescapeString( m_CurrentText->GetText() ); + + // show text variable cross-references in a human-readable format + text = schematic.ConvertKIIDsToRefs( text ); + + m_activeTextEntry->SetValue( text ); } if( m_valueCombo->IsShown() ) @@ -315,7 +320,8 @@ bool DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataFromWindow() if( !m_textSize.Validate( 0.01, 1000.0, EDA_UNITS::MILLIMETRES ) ) return false; - wxString text; + SCHEMATIC& schematic = m_Parent->Schematic(); + wxString text; /* save old text in undo list if not already in edit */ if( m_CurrentText->GetEditFlags() == 0 ) @@ -325,8 +331,7 @@ bool DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataFromWindow() if( m_CurrentText->Type() == SCH_TEXT_T ) { - // convert any text variable cross-references to their UUIDs - text = m_Parent->Schematic().ConvertRefsToKIIDs( m_valueMultiLine->GetValue() ); + text = m_valueMultiLine->GetValue(); } else { @@ -334,6 +339,9 @@ bool DIALOG_TEXT_AND_LABEL_PROPERTIES::TransferDataFromWindow() text = EscapeString( m_activeTextEntry->GetValue(), CTX_NETNAME ); } + // convert any text variable cross-references to their UUIDs + text = schematic.ConvertRefsToKIIDs( text ); + if( !text.IsEmpty() ) { #ifdef __WXMAC__ diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 6b6b09a0ad..518d2499d4 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -619,21 +619,18 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const return true; } - if( Type() == SCH_TEXT_T ) + if( token->Contains( ':' ) ) { - if( token->Contains( ':' ) ) - { - if( Schematic()->ResolveCrossReference( token, aDepth ) ) - return true; - } - else - { - SCHEMATIC* schematic = Schematic(); - SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr; + if( Schematic()->ResolveCrossReference( token, aDepth ) ) + return true; + } + else + { + SCHEMATIC* schematic = Schematic(); + SCH_SHEET* sheet = schematic ? schematic->CurrentSheet().Last() : nullptr; - if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) ) - return true; - } + if( sheet && sheet->ResolveTextVar( token, aDepth + 1 ) ) + return true; } return false;