From 78620347c827001e9872b4d93b7a3c239e745162 Mon Sep 17 00:00:00 2001 From: Steffen Mauch Date: Fri, 25 Feb 2022 23:42:47 +0000 Subject: [PATCH] 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 --- .../sch_plugins/eagle/sch_eagle_plugin.cpp | 11 ++++++- pcbnew/plugins/eagle/eagle_plugin.cpp | 30 ++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index b73cd50106..1cbad53884 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -1351,10 +1351,19 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) // with a hash character to mute netlist updater complaints 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 // 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 ) + 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( einstance.part.find_first_not_of( "#" ) != 0 ) reference.Prepend( "UNK" ); SCH_SHEET_PATH sheetpath; diff --git a/pcbnew/plugins/eagle/eagle_plugin.cpp b/pcbnew/plugins/eagle/eagle_plugin.cpp index 70f71af391..0ee5fd1d67 100644 --- a/pcbnew/plugins/eagle/eagle_plugin.cpp +++ b/pcbnew/plugins/eagle/eagle_plugin.cpp @@ -1206,7 +1206,25 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) 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() ) ); if( !e.smashed ) @@ -1260,17 +1278,7 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) { 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; - footprint->SetReference( reference ); if( refanceNamePresetInPackageLayout ) footprint->Reference().SetVisible( true );