TousstNicolas / JLC2KiCad_lib

JLC2KICAD_lib is a python script that generate a component library (schematic, footprint and 3D model ) for KiCad from the JLCPCB/easyEDA library.
MIT License
228 stars 42 forks source link

Handle colon character in component title #74

Closed cristian-bicheru closed 2 months ago

cristian-bicheru commented 2 months ago

Hi, Great work on this awesome library!

I recently ran into an issue converting LCSC parts with colons in the name (e.g, C2838450). It appears that KiCad does not allow the colon character in symbol names, thus the generated symbol library cannot be imported.

As an experiment, I went into KiCad and created a symbol with the colon character in the title. To my surprise, this seemed to work without any issues. When I inspected the symbol library, I found that KiCad had inserted the text {colon} in place of the character.

Thus, I added another operation to replace all occurances of : with {colon} in the component title. Now, the generated symbol library appears to load as expected.

TousstNicolas commented 2 months ago

Hi,

Very nice catch !

I couldn't find any reference to this in either the Symbol Library File Format or the S-Expression Format documentation.

So I delved into the KiCad source code and discovered the code that handles the escaping of this sequence in the string_utils.cpp file.

Within, additional escape expressions are revealed:

        else if( aContext == CTX_LIBID || aContext == CTX_LEGACY_LIBID )
        {
            // We no longer escape '/' in LIB_IDs, but we used to
            if( c == '/' && aContext == CTX_LEGACY_LIBID )
                converted += wxT( "{slash}" );
            else if( c == '\\' )
                converted += wxT( "{backslash}" );
            else if( c == '<' )
                converted += wxT( "{lt}" );
            else if( c == '>' )
                converted += wxT( "{gt}" );
            else if( c == ':' )
                converted += wxT( "{colon}" );
            else if( c == '\"' )
                converted += wxT( "{dblquote}" );
            else if( c == '\n' || c == '\r' )
                converted += wxEmptyString;    // drop
            else
                converted += c;
        }

I will check this tomorrow and add the missing escape sequences.

Thanks for your PR ;)

cristian-bicheru commented 2 months ago

Ah, nice catch -- I took a peek in the source as well but didn't find that code block. Sounds good, I will close this PR then!

TousstNicolas commented 2 months ago

Available on the 1.0.32 release :)