Allow ':'s in field name references in text variables.

Fixes https://gitlab.com/kicad/code/kicad/issues/2458
This commit is contained in:
Jeff Young 2020-04-11 20:12:49 +01:00
parent c66fe5e91e
commit 505d8bf56e
4 changed files with 29 additions and 23 deletions

View File

@ -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<SCH_COMPONENT*>( 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;
}
}

View File

@ -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<SCH_COMPONENT*>( 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<SCH_SHEET*>( refItem );
if( refSheet->ResolveTextVar( &parts[1], aDepth + 1 ) )
if( refSheet->ResolveTextVar( &remainder, aDepth + 1 ) )
{
*token = parts[1];
*token = remainder;
return true;
}
}

View File

@ -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<MODULE*>( refItem );
if( refModule->ResolveTextVar( &parts[1], aDepth + 1 ) )
if( refModule->ResolveTextVar( &remainder, aDepth + 1 ) )
{
*token = parts[1];
*token = remainder;
return true;
}
}

View File

@ -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<MODULE*>( refItem )->GetReference() + ":" + parts[1];
token = static_cast<MODULE*>( 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;
}
}