Fixing Eagle refs that do not work with KiCad

KiCad has stricter requirements for what consititutes an annotated
symbol.  This checks for and corrects annotations that begin with '#',
do not begin with a non-numeric character or do not end with a number

(cherry picked from commit 78620347c8)

Fixes https://gitlab.com/kicad/code/kicad/issues/10760
This commit is contained in:
Steffen Mauch 2022-02-25 23:42:47 +00:00 committed by Seth Hillbrand
parent b17eb3a584
commit ab835937a7
2 changed files with 30 additions and 13 deletions

View File

@ -1352,11 +1352,20 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
// with a hash character to mute netlist updater complaints // with a hash character to mute netlist updater complaints
wxString reference = package.IsEmpty() ? '#' + einstance.part : einstance.part; wxString reference = package.IsEmpty() ? '#' + einstance.part : einstance.part;
// reference must end with a number but EAGLE does not enforce this
if( reference.find_last_not_of( "0123456789" ) == (reference.Length()-1) )
reference.Append( "0" );
// EAGLE allows references to be single digits. This breaks KiCad netlisting, which requires // EAGLE allows references to be single digits. This breaks KiCad netlisting, which requires
// parts to have non-digit + digit annotation. If the reference begins with a number, // parts to have non-digit + digit annotation. If the reference begins with a number,
// we prepend 'UNK' (unknown) for the symbol designator // we prepend 'UNK' (unknown) for the symbol designator
if( reference.find_first_not_of( wxT( "0123456789" ) ) == wxString::npos ) if( reference.find_first_not_of( "0123456789" ) != 0 )
reference.Prepend( wxT( "UNK" ) ); reference.Prepend( "UNK" );
// EAGLE allows designator to start with # but that is used in KiCad
// for symbols which do not have a footprint
if( einstance.part.find_first_not_of( "#" ) != 0 )
reference.Prepend( "UNK" );
SCH_SHEET_PATH sheetpath; SCH_SHEET_PATH sheetpath;
m_rootSheet->LocatePathOfScreen( screen, &sheetpath ); m_rootSheet->LocatePathOfScreen( screen, &sheetpath );

View File

@ -1202,7 +1202,25 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
valueNamePresetInPackageLayout = false; valueNamePresetInPackageLayout = false;
} }
footprint->SetReference( FROM_UTF8( e.name.c_str() ) ); wxString reference = e.name;
// EAGLE allows references to be single digits. This breaks KiCad
// netlisting, which requires parts to have non-digit + digit
// annotation. If the reference begins with a number, we prepend
// 'UNK' (unknown) for the symbol designator.
if( reference.find_first_not_of( "0123456789" ) != 0 )
reference.Prepend( "UNK" );
// EAGLE allows designator to start with # but that is used in KiCad
// for symbols which do not have a footprint
if( reference.find_first_not_of( "#" ) != 0 )
reference.Prepend( "UNK" );
// reference must end with a number but EAGLE does not enforce this
if( reference.find_last_not_of( "0123456789" ) == (reference.Length()-1) )
reference.Append( "0" );
footprint->SetReference( reference );
footprint->SetValue( FROM_UTF8( e.value.c_str() ) ); footprint->SetValue( FROM_UTF8( e.value.c_str() ) );
if( !e.smashed ) if( !e.smashed )
@ -1256,17 +1274,7 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
{ {
case EATTR::VALUE : case EATTR::VALUE :
{ {
wxString reference = e.name;
// EAGLE allows references to be single digits. This breaks KiCad
// netlisting, which requires parts to have non-digit + digit
// annotation. If the reference begins with a number, we prepend
// 'UNK' (unknown) for the symbol designator.
if( reference.find_first_not_of( "0123456789" ) == wxString::npos )
reference.Prepend( wxT( "UNK" ) );
nameAttr->name = reference; nameAttr->name = reference;
footprint->SetReference( reference );
if( refanceNamePresetInPackageLayout ) if( refanceNamePresetInPackageLayout )
footprint->Reference().SetVisible( true ); footprint->Reference().SetVisible( true );