From 505d8bf56ef2991827fcb205823dfc9864b46a8e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 11 Apr 2020 20:12:49 +0100 Subject: [PATCH] Allow ':'s in field name references in text variables. Fixes https://gitlab.com/kicad/code/kicad/issues/2458 --- eeschema/dialogs/dialog_edit_label.cpp | 16 +++++++++------- eeschema/sch_text.cpp | 13 +++++++------ pcbnew/class_pcb_text.cpp | 9 +++++---- pcbnew/dialogs/dialog_text_properties.cpp | 14 ++++++++------ 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index 3ede422a21..07db1c8211 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -208,14 +208,16 @@ wxString convertKIIDsToReferences( const wxString& aSource ) if( isCrossRef ) { SCH_SHEET_LIST sheetList( g_RootSheet ); - wxArrayString parts = wxSplit( token, ':' ); + wxString remainder; + wxString ref = token.BeforeFirst( ':', &remainder ); + SCH_SHEET_PATH refSheetPath; - SCH_ITEM* refItem = sheetList.GetItem( KIID( parts[0] ), &refSheetPath ); + SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &refSheetPath ); if( refItem && refItem->Type() == SCH_COMPONENT_T ) { SCH_COMPONENT* refComponent = static_cast( refItem ); - token = refComponent->GetRef( &refSheetPath, true ) + ":" + parts[1]; + token = refComponent->GetRef( &refSheetPath, true ) + ":" + remainder; } } @@ -257,7 +259,8 @@ wxString convertReferencesToKIIDs( const wxString& aSource ) if( isCrossRef ) { SCH_SHEET_LIST sheets( g_RootSheet ); - wxArrayString parts = wxSplit( token, ':' ); + wxString remainder; + wxString ref = token.BeforeFirst( ':', &remainder ); SCH_REFERENCE_LIST references; sheets.GetComponents( references ); @@ -265,11 +268,10 @@ wxString convertReferencesToKIIDs( const wxString& aSource ) for( size_t jj = 0; jj < references.GetCount(); jj++ ) { SCH_COMPONENT* refComponent = references[ jj ].GetComp(); - wxString ref = refComponent->GetRef( &references[ jj ].GetSheetPath() ); - if( ref == parts[0] ) + if( ref == refComponent->GetRef( &references[ jj ].GetSheetPath() ) ) { - token = refComponent->m_Uuid.AsString() + ":" + parts[1]; + token = refComponent->m_Uuid.AsString() + ":" + remainder; break; } } diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 4f621846c6..87bc7b6d05 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -478,17 +478,18 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const if( token->Contains( ':' ) ) { SCH_SHEET_LIST sheetList( g_RootSheet ); - wxArrayString parts = wxSplit( *token, ':' ); + wxString remainder; + wxString ref = token->BeforeFirst( ':', &remainder ); SCH_SHEET_PATH dummy; - SCH_ITEM* refItem = sheetList.GetItem( KIID( parts[0] ), &dummy ); + SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &dummy ); if( refItem && refItem->Type() == SCH_COMPONENT_T ) { SCH_COMPONENT* refComponent = static_cast( refItem ); - if( refComponent->ResolveTextVar( &parts[1], aDepth + 1 ) ) + if( refComponent->ResolveTextVar( &remainder, aDepth + 1 ) ) { - *token = parts[1]; + *token = remainder; return true; } } @@ -496,9 +497,9 @@ wxString SCH_TEXT::GetShownText( int aDepth ) const { SCH_SHEET* refSheet = static_cast( refItem ); - if( refSheet->ResolveTextVar( &parts[1], aDepth + 1 ) ) + if( refSheet->ResolveTextVar( &remainder, aDepth + 1 ) ) { - *token = parts[1]; + *token = remainder; return true; } } diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp index d548c4916e..560132a096 100644 --- a/pcbnew/class_pcb_text.cpp +++ b/pcbnew/class_pcb_text.cpp @@ -77,16 +77,17 @@ wxString TEXTE_PCB::GetShownText( int aDepth ) const if( token->Contains( ':' ) ) { - wxArrayString parts = wxSplit( *token, ':' ); - BOARD_ITEM* refItem = board->GetItem( KIID( parts[0] ) ); + wxString remainder; + wxString ref = token->BeforeFirst( ':', &remainder ); + BOARD_ITEM* refItem = board->GetItem( KIID( ref ) ); if( refItem && refItem->Type() == PCB_MODULE_T ) { MODULE* refModule = static_cast( refItem ); - if( refModule->ResolveTextVar( &parts[1], aDepth + 1 ) ) + if( refModule->ResolveTextVar( &remainder, aDepth + 1 ) ) { - *token = parts[1]; + *token = remainder; return true; } } diff --git a/pcbnew/dialogs/dialog_text_properties.cpp b/pcbnew/dialogs/dialog_text_properties.cpp index 04d08e18bc..779ae6c845 100644 --- a/pcbnew/dialogs/dialog_text_properties.cpp +++ b/pcbnew/dialogs/dialog_text_properties.cpp @@ -316,11 +316,12 @@ wxString DIALOG_TEXT_PROPERTIES::convertKIIDsToReferences( const wxString& aSour if( isCrossRef ) { - wxArrayString parts = wxSplit( token, ':' ); - BOARD_ITEM* refItem = m_Parent->GetBoard()->GetItem( KIID( parts[0] ) ); + wxString remainder; + wxString ref = token.BeforeFirst( ':', &remainder ); + BOARD_ITEM* refItem = m_Parent->GetBoard()->GetItem( KIID( ref ) ); if( refItem && refItem->Type() == PCB_MODULE_T ) - token = static_cast( refItem )->GetReference() + ":" + parts[1]; + token = static_cast( refItem )->GetReference() + ":" + remainder; } newbuf.append( "${" + token + "}" ); @@ -360,13 +361,14 @@ wxString DIALOG_TEXT_PROPERTIES::convertReferencesToKIIDs( const wxString& aSour if( isCrossRef ) { - wxArrayString parts = wxSplit( token, ':' ); + wxString remainder; + wxString ref = token.BeforeFirst( ':', &remainder ); for( MODULE* mod : m_Parent->GetBoard()->Modules() ) { - if( mod->GetReference().CmpNoCase( parts[0] ) == 0 ) + if( mod->GetReference().CmpNoCase( ref ) == 0 ) { - token = mod->m_Uuid.AsString() + ":" + parts[1]; + token = mod->m_Uuid.AsString() + ":" + remainder; break; } }