Substitute variables in imported symbol text.

Also allows mulit-line text items to be imported.

Fixes https://gitlab.com/kicad/code/kicad/issues/13541
This commit is contained in:
Jeff Young 2023-01-16 15:14:39 +00:00
parent f0b2902b8c
commit 9315e885ee
2 changed files with 23 additions and 13 deletions

View File

@ -60,6 +60,7 @@ bool substituteVariable( wxString* aText )
else if( *aText == wxT( ">SHEETNR_TOTAL" ) ) *aText = wxT( "${#}" );
else if( *aText == wxT( ">SHEETS_TOTAL" ) ) *aText = wxT( "${##}" );
else if( *aText == wxT( ">SHEET_TOTAL" ) ) *aText = wxT( "${#}/${##}" );
else if( *aText == wxT( ">SHEET_HEADLINE" ) ) *aText = wxT( "${SHEETNAME}" );
else if( *aText == wxT( ">ASSEMBLY_VARIANT" ) ) *aText = wxT( "${ASSEMBLY_VARIANT}" );
else if( *aText == wxT( ">DRAWING_NAME" ) ) *aText = wxT( "${TITLE}" );
else if( *aText == wxT( ">LAST_DATE_TIME" ) ) *aText = wxT( "${ISSUE_DATE}" );

View File

@ -2355,16 +2355,26 @@ LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol
libtext->SetUnit( aGateNumber );
libtext->SetPosition( VECTOR2I( etext.x.ToSchUnits(), etext.y.ToSchUnits() ) );
// Eagle supports multiple line text in library symbols. Legacy library symbol text cannot
// contain CRs or LFs.
//
// @todo Split this into multiple text objects and offset the Y position so that it looks
// more like the original Eagle schematic.
wxString text = aLibText->GetNodeContent();
std::replace( text.begin(), text.end(), '\n', '_' );
std::replace( text.begin(), text.end(), '\r', '_' );
const wxString& eagleText = aLibText->GetNodeContent();
wxString adjustedText;
wxStringTokenizer tokenizer( eagleText, "\r\n" );
libtext->SetText( text.IsEmpty() ? wxT( "~" ) : text );
// Strip the whitespace from both ends of each line.
while( tokenizer.HasMoreTokens() )
{
wxString tmp = tokenizer.GetNextToken().Trim( true ).Trim( false );
wxString var = tmp.Upper();
if( substituteVariable( &var ) )
tmp = var;
if( tokenizer.HasMoreTokens() )
tmp += wxT( "\n" );
adjustedText += tmp;
}
libtext->SetText( adjustedText.IsEmpty() ? wxT( "~" ) : adjustedText );
loadTextAttributes( libtext.get(), etext );
return libtext.release();
@ -2565,10 +2575,9 @@ SCH_TEXT* SCH_EAGLE_PLUGIN::loadPlainText( wxXmlNode* aSchText )
std::unique_ptr<SCH_TEXT> schtext = std::make_unique<SCH_TEXT>();
ETEXT etext = ETEXT( aSchText );
const wxString& thetext = aSchText->GetNodeContent();
const wxString& eagleText = aSchText->GetNodeContent();
wxString adjustedText;
wxStringTokenizer tokenizer( thetext, "\r\n" );
wxStringTokenizer tokenizer( eagleText, "\r\n" );
// Strip the whitespace from both ends of each line.
while( tokenizer.HasMoreTokens() )