main
John Lauer Add provenance, manifests, verification log, licenses and README fbc6889 5h ago
#!/usr/bin/env python3
"""Post-edit the adom-symbol 1.2.6 output for SM04B-GHS-TB(LF)(SN).
adom-symbol 1.2.6 places pins at y = -2.00, -4.54, ... (off the 2.54 mm grid, so wires do not land on them)
and sizes the body for IC pin names. This keeps every property adom-symbol wrote and only:
  * puts the pins on the 2.54 mm grid (1..4 left at y 0, -2.54, -5.08, -7.62; MP right at y 0),
  * narrows the body to suit one-character pin names (x -10.16 .. 10.16),
  * moves the group captions, Reference and Value to match,
  * sets Footprint to KiCad's stock land pattern, which is pad-identical to this page's footprint,
  * trims the generator's layout sentence from Description.
usage: symbol_post.py in.kicad_sym out.kicad_sym"""
import re, sys
src, out = sys.argv[1], sys.argv[2]
t = open(src).read()
name = 'SM04B-GHS-TB(LF)(SN)'
t = t.replace('(property "Footprint" ""', '(property "Footprint" "Connector_JST:JST_GH_SM04B-GHS-TB_1x04-1MP_P1.25mm_Horizontal"')
t = t.replace(' 2-column symbol, pins grouped by function.', '')
t = re.sub(r'\(property "Reference" "J"\n\s+\(at [^)]*\)', '(property "Reference" "J"\n      (at 0.00 5.08 0)', t)
t = re.sub(r'\(property "Value" "([^"]*)"\n\s+\(at [^)]*\)', r'(property "Value" "\1"\n      (at 0.00 -12.70 0)', t)
t = re.sub(r'\(rectangle \(start [^)]*\) \(end [^)]*\)', '(rectangle (start -10.16 2.54) (end 10.16 -10.16)', t)
t = re.sub(r'\(text "Contacts" \(at [^)]*\)', '(text "Contacts" (at -9.14 1.85 0)', t)
t = re.sub(r'\(text "Mounting tabs" \(at [^)]*\)', '(text "Mounting tabs" (at 9.14 1.85 0)', t)
ys = {'1': 0.0, '2': -2.54, '3': -5.08, '4': -7.62}
def pin(m):
    kind, num = m.group(1), m.group(3)
    if num == 'MP':
        return f'(pin {kind} line (at 12.70 0.00 180) (length 2.54) (name "MP") (number "MP"))'
    return f'(pin {kind} line (at -12.70 {ys[num]:.2f} 0) (length 2.54) (name "{num}") (number "{num}"))'
t = re.sub(r'\(pin (\w+) line \(at [^)]*\) \(length [^)]*\) \(name "([^"]*)"\) \(number "([^"]*)"\)\)', pin, t)
# hidden property column under the shorter body
def shift(m):
    y = float(m.group(2))
    return f'{m.group(1)}{y + 2.54 + 2.46:.2f} 0)'
t = re.sub(r'(\(property "(?:Footprint|Datasheet|Description|Manufacturer|MPN|Adom Wiki|DigiKey|LCSC|Mouser)" "[^"]*"\n\s+\(at 0 )(-?[\d.]+) 0\)', shift, t)
for k in ys: assert f'(number "{k}")' in t
assert '(number "MP")' in t
open(out, 'w').write(t)
print('OK', out)