main
John Lauer Verify current IC catalog lineage and resolve DGS manufacturer land patterns 9f7dac2
"""Check selected DGS copper against the visually reviewed TI drawing, not generic catalog lands."""
from pathlib import Path
import hashlib
import json
import sexp

ROOT = Path(__file__).resolve().parents[1]
OUT = ROOT / 'checkpoints/board31-ic-library-review'
board = ROOT / 'aiflow/run/board-31.kicad_pcb'
sha = lambda p: hashlib.sha256(p.read_bytes()).hexdigest()
assert sha(board) == 'a2b7fda1783e8b519a8819d93837c8d6fa5acb57dfde4f43abd2b3fd1b405bc5'
rows = []
for footprint in sexp.find(sexp.parse(board.read_text()), 'footprint'):
    ref = next(p[2] for p in sexp.find(footprint, 'property') if p[1] == 'Reference')
    if ref not in ['U2', 'U4']:
        continue
    pads = sexp.find(footprint, 'pad')
    assert len(pads) == 10
    for pad in pads:
        number = int(pad[1])
        expected = (-2.2, -1 + (number - 1) * .5) if number <= 5 else (2.2, 1 - (number - 6) * .5)
        actual = tuple(map(float, sexp.first(pad, 'at')[1:3]))
        assert all(abs(a-b) < 1e-8 for a,b in zip(actual, expected))
        assert tuple(map(float, sexp.first(pad, 'size')[1:3])) == (1.45, .3)
        assert pad[3] == 'roundrect'
        assert abs(float(sexp.first(pad, 'roundrect_rratio')[1]) * .3 - .05) < 1e-6
    source = ROOT / ('datasheets/dacx0501.pdf' if ref == 'U2' else 'datasheets/ina226.pdf')
    rows.append({'reference': ref, 'datasheet': str(source.relative_to(ROOT)),
                 'datasheetSha256': sha(source), 'pdfPageOneBased': 46 if ref == 'U2' else 39,
                 'drawing': 'DGS0010A 4221984/A 05/2015 example board layout',
                 'padCount': 10, 'padSizeMm': [1.45, .3], 'rowSpacingMm': 4.4,
                 'pitchMm': .5, 'cornerRadiusMm': .05, 'adjacentCopperGapMm': .2,
                 'selectedCopperMatchesDrawing': True})
assert len(rows) == 2
report = {'boardSha256': sha(board), 'reviews': rows,
          'correction': 'The shared catalog uses a different generic footprint. Earlier catalog-rectangle comparisons were incorrectly described as manufacturer-example comparisons for U2/U4.',
          'decision': 'Retain selected TI_DGS0010A copper unchanged.',
          'limits': ['No mask, paste, placement tolerance or physical process qualification.',
                     'No component status or acceptance gate advanced.']}
(OUT / 'dgs-manufacturer-land-review.json').write_text(json.dumps(report, indent=2) + '\n')
print(json.dumps(report, indent=2))