Handle Eagle user-defined attributes.

(We map these to text variables.)

Fixes https://gitlab.com/kicad/code/kicad/issues/13798
This commit is contained in:
Jeff Young 2023-05-06 21:09:44 +01:00
parent 5d116245c6
commit 8fe02ee83c
2 changed files with 27 additions and 22 deletions

View File

@ -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;
}

View File

@ -1726,9 +1726,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 )
@ -1736,8 +1736,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 );