main
John Lauer Add symbol, footprint, Fusion and Altium libraries, viewers, provenance, README ab389b2 3h ago
#!/usr/bin/env python3
"""Finish the adom-footprint 1.0.26 output for TI DVG0010A: set each pad's corner radius to the drawing's R0.05
(adom-footprint writes roundrect_rratio 0.25), draw a pin-1 chamfer on F.Fab, add the isolation-barrier keepout
(rule area, all copper layers, between the inner pad edges x = -4.05 .. +4.05 across the courtyard height) with a
Cmts.User note, and bind the 3D model. usage: fp_finish.py in.kicad_mod out.kicad_mod"""
import re, sys
s = open(sys.argv[1]).read()
def rr(m):
    w, h = float(m.group(2)), float(m.group(3))
    return f"{m.group(1)}(size {m.group(2)} {m.group(3)}){m.group(4)}(roundrect_rratio {0.05 / min(w, h):.4f})"
s = re.sub(r"(\(pad \"\d+\" smd roundrect \(at [^)]*\) )\(size ([\d.]+) ([\d.]+)\)(\s*\(layers [^)]*\) )\(roundrect_rratio [\d.]+\)", rr, s)
s = s.replace('(fp_rect (start -3.75 -5.15) (end 3.75 5.15)\n    (stroke (width 0.1) (type default)) (fill none) (layer "F.Fab"))',
 '(fp_poly (pts (xy -2.75 -5.15) (xy 3.75 -5.15) (xy 3.75 5.15) (xy -3.75 5.15) (xy -3.75 -4.15))\n'
 '    (stroke (width 0.1) (type default)) (fill none) (layer "F.Fab"))\n'
 '  (fp_line (start 0 -5.15) (end 0 5.15)\n    (stroke (width 0.1) (type dash)) (layer "F.Fab"))\n'
 '  (fp_text user "ISOLATION KEEPOUT 8.1 mm" (at 0 0 90) (layer "Cmts.User")\n    (effects (font (size 0.6 0.6) (thickness 0.09))))')
s = s.replace('(fp_text value "tmcs1123b1aqdvgr"', '(fp_text value "TMCS1123B1AQDVGR"')
zone = '''  (zone (net 0) (net_name "") (layers "*.Cu") (name "Isolation keepout")
    (hatch edge 0.5)
    (connect_pads (clearance 0))
    (min_thickness 0.25)
    (keepout (tracks not_allowed) (vias not_allowed) (pads not_allowed) (copperpour not_allowed) (footprints allowed))
    (fill (thermal_gap 0.5) (thermal_bridge_width 0.5))
    (polygon (pts (xy -4.05 -5.5) (xy 4.05 -5.5) (xy 4.05 5.5) (xy -4.05 5.5))))
  (model "${KIPRJMOD}/tmcs1123b1aqdvgr-etched.step"
    (offset (xyz 0 0 0)) (scale (xyz 1 1 1)) (rotate (xyz 0 0 0)))
)'''
s = s.rstrip()
assert s.endswith(")")
s = s[:-1].rstrip() + "\n" + zone + "\n"
open(sys.argv[2], "w").write(s)
print("ok")