From 5a3dfe598f3bc56717bc92de6a2f0ad1801e6108 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 6 May 2023 21:09:44 +0100 Subject: [PATCH] Handle Eagle user-defined attributes. (We map these to text variables.) Fixes https://gitlab.com/kicad/code/kicad/issues/13798 (cherry picked from commit 8fe02ee83cda897980f3f883c40d5ec1362064ce) --- common/plugins/eagle/eagle_parser.cpp | 41 +++++++++++-------- .../sch_plugins/eagle/sch_eagle_plugin.cpp | 8 ++-- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/common/plugins/eagle/eagle_parser.cpp b/common/plugins/eagle/eagle_parser.cpp index 61120ee7d5..dc4b39595a 100644 --- a/common/plugins/eagle/eagle_parser.cpp +++ b/common/plugins/eagle/eagle_parser.cpp @@ -116,25 +116,30 @@ wxString interpretText( const wxString& aText ) bool substituteVariable( wxString* aText ) { - if ( *aText == wxT( ">NAME" ) ) *aText = wxT( "${REFERENCE}" ); - else if( *aText == wxT( ">VALUE" ) ) *aText = wxT( "${VALUE}" ); - else if( *aText == wxT( ">PART" ) ) *aText = wxT( "${REFERENCE}" ); - else if( *aText == wxT( ">GATE" ) ) *aText = wxT( "${UNIT}" ); - else if( *aText == wxT( ">MODULE" ) ) *aText = wxT( "${FOOTPRINT_NAME}" ); - else if( *aText == wxT( ">SHEETNR" ) ) *aText = wxT( "${#}" ); - else if( *aText == wxT( ">SHEETS" ) ) *aText = wxT( "${##}" ); - else if( *aText == wxT( ">SHEET" ) ) *aText = wxT( "${#}/${##}" ); - 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( "${PROJECTNAME}" ); - else if( *aText == wxT( ">LAST_DATE_TIME" ) ) *aText = wxT( "${CURRENT_DATE}" ); - else if( *aText == wxT( ">PLOT_DATE_TIME" ) ) *aText = wxT( "${CURRENT_DATE}" ); - else return false; + if( aText->StartsWith( '>' ) && aText->AfterFirst( ' ' ).IsEmpty() ) + { + if ( *aText == wxT( ">NAME" ) ) *aText = wxT( "${REFERENCE}" ); + else if( *aText == wxT( ">VALUE" ) ) *aText = wxT( "${VALUE}" ); + else if( *aText == wxT( ">PART" ) ) *aText = wxT( "${REFERENCE}" ); + else if( *aText == wxT( ">GATE" ) ) *aText = wxT( "${UNIT}" ); + else if( *aText == wxT( ">MODULE" ) ) *aText = wxT( "${FOOTPRINT_NAME}" ); + else if( *aText == wxT( ">SHEETNR" ) ) *aText = wxT( "${#}" ); + else if( *aText == wxT( ">SHEETS" ) ) *aText = wxT( "${##}" ); + else if( *aText == wxT( ">SHEET" ) ) *aText = wxT( "${#}/${##}" ); + 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( "${PROJECTNAME}" ); + else if( *aText == wxT( ">LAST_DATE_TIME" ) ) *aText = wxT( "${CURRENT_DATE}" ); + else if( *aText == wxT( ">PLOT_DATE_TIME" ) ) *aText = wxT( "${CURRENT_DATE}" ); + else *aText = wxString::Format( wxS( "${%s}" ), aText->Mid( 1 ).Trim() ); - return true; + return true; + } + + return false; } diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index 13af185b52..204c3cef82 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -1715,9 +1715,9 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) valueField->SetVisible( false ); } - for( const auto& a : epart->attribute ) + for( const auto& [ attrName, attrValue ] : epart->attribute ) { - VECTOR2I newFieldPosition( 0, 0 ); + VECTOR2I newFieldPosition( 0, 0 ); SCH_FIELD* lastField = symbol->GetFieldById( symbol->GetFieldCount() - 1 ); if( lastField ) @@ -1725,8 +1725,8 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) SCH_FIELD newField( newFieldPosition, symbol->GetFieldCount(), symbol.get() ); - newField.SetName( a.first ); - newField.SetText( a.second ); + newField.SetName( attrName ); + newField.SetText( attrValue ); newField.SetVisible( false ); symbol->AddField( newField );