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:
parent
f0b2902b8c
commit
9315e885ee
|
@ -60,6 +60,7 @@ bool substituteVariable( wxString* aText )
|
||||||
else if( *aText == wxT( ">SHEETNR_TOTAL" ) ) *aText = wxT( "${#}" );
|
else if( *aText == wxT( ">SHEETNR_TOTAL" ) ) *aText = wxT( "${#}" );
|
||||||
else if( *aText == wxT( ">SHEETS_TOTAL" ) ) *aText = wxT( "${##}" );
|
else if( *aText == wxT( ">SHEETS_TOTAL" ) ) *aText = wxT( "${##}" );
|
||||||
else if( *aText == wxT( ">SHEET_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( ">ASSEMBLY_VARIANT" ) ) *aText = wxT( "${ASSEMBLY_VARIANT}" );
|
||||||
else if( *aText == wxT( ">DRAWING_NAME" ) ) *aText = wxT( "${TITLE}" );
|
else if( *aText == wxT( ">DRAWING_NAME" ) ) *aText = wxT( "${TITLE}" );
|
||||||
else if( *aText == wxT( ">LAST_DATE_TIME" ) ) *aText = wxT( "${ISSUE_DATE}" );
|
else if( *aText == wxT( ">LAST_DATE_TIME" ) ) *aText = wxT( "${ISSUE_DATE}" );
|
||||||
|
|
|
@ -2355,16 +2355,26 @@ LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol
|
||||||
libtext->SetUnit( aGateNumber );
|
libtext->SetUnit( aGateNumber );
|
||||||
libtext->SetPosition( VECTOR2I( etext.x.ToSchUnits(), etext.y.ToSchUnits() ) );
|
libtext->SetPosition( VECTOR2I( etext.x.ToSchUnits(), etext.y.ToSchUnits() ) );
|
||||||
|
|
||||||
// Eagle supports multiple line text in library symbols. Legacy library symbol text cannot
|
const wxString& eagleText = aLibText->GetNodeContent();
|
||||||
// contain CRs or LFs.
|
wxString adjustedText;
|
||||||
//
|
wxStringTokenizer tokenizer( eagleText, "\r\n" );
|
||||||
// @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', '_' );
|
|
||||||
|
|
||||||
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 );
|
loadTextAttributes( libtext.get(), etext );
|
||||||
|
|
||||||
return libtext.release();
|
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>();
|
std::unique_ptr<SCH_TEXT> schtext = std::make_unique<SCH_TEXT>();
|
||||||
ETEXT etext = ETEXT( aSchText );
|
ETEXT etext = ETEXT( aSchText );
|
||||||
|
|
||||||
const wxString& thetext = aSchText->GetNodeContent();
|
const wxString& eagleText = aSchText->GetNodeContent();
|
||||||
|
wxString adjustedText;
|
||||||
wxString adjustedText;
|
wxStringTokenizer tokenizer( eagleText, "\r\n" );
|
||||||
wxStringTokenizer tokenizer( thetext, "\r\n" );
|
|
||||||
|
|
||||||
// Strip the whitespace from both ends of each line.
|
// Strip the whitespace from both ends of each line.
|
||||||
while( tokenizer.HasMoreTokens() )
|
while( tokenizer.HasMoreTokens() )
|
||||||
|
|
Loading…
Reference in New Issue