← Commit history

0.2.138: dimension pictures scaled to the part, reruns replace them (altium-bridge 0.2.122)

Colby Knox ·45d3a5550a · ·parent 652d207
9 files changed +56−26
Cargo.lock+11−11
@@ -4,7 +4,7 @@ version = 4  [[package]] name = "adom-aiflow"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-analyze",  "aiflow-board",@@ -28,7 +28,7 @@ dependencies = [  [[package]] name = "aiflow-analyze"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-board",  "aiflow-sys",@@ -39,7 +39,7 @@ dependencies = [  [[package]] name = "aiflow-board"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-sys",  "roxmltree",@@ -49,7 +49,7 @@ dependencies = [  [[package]] name = "aiflow-bridge"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-board",  "aiflow-sys",@@ -59,7 +59,7 @@ dependencies = [  [[package]] name = "aiflow-copper"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-board",  "aiflow-grid",@@ -70,7 +70,7 @@ dependencies = [  [[package]] name = "aiflow-grid"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-board",  "serde",@@ -79,7 +79,7 @@ dependencies = [  [[package]] name = "aiflow-place"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-board",  "aiflow-sys",@@ -89,7 +89,7 @@ dependencies = [  [[package]] name = "aiflow-pours"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-board",  "aiflow-copper",@@ -100,7 +100,7 @@ dependencies = [  [[package]] name = "aiflow-router"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-board",  "aiflow-grid",@@ -111,7 +111,7 @@ dependencies = [  [[package]] name = "aiflow-run"-version = "0.2.137"+version = "0.2.138" dependencies = [  "aiflow-sys",  "serde",@@ -120,7 +120,7 @@ dependencies = [  [[package]] name = "aiflow-sys"-version = "0.2.137"+version = "0.2.138" dependencies = [  "serde_json", ]
Cargo.toml+1−1
@@ -15,7 +15,7 @@ members = [ ]  [workspace.package]-version = "0.2.137"+version = "0.2.138" edition = "2021" license = "MIT" repository = "https://wiki.adom.inc/adom/adom-aiflow"
docs/altium-lane.md+1−1
@@ -186,5 +186,5 @@ After the library step imports footprints, `altium_check_silkscreen` measures ea  ## Footprints checked against their datasheets (altium-bridge 0.2.121) -When `design/part-checks.json` gives a part's `dims` (pitch, span, body size between pads or body corners; the aiflow-sourcing skill), `altium library` puts each on the imported footprint with `altium_add_dimensions`: a real Altium dimension anchored to the pads or the assembly outline's corners, its direction and position worked out from the footprint's KiCad file, text scaled to the footprint. Altium answers MATCH or MISMATCH for each. A mismatch stops the step (the library is built; fix the footprint or acknowledge the dimension with `"ack"`). The dimensioned footprint is pictured (`altium/footprints/<footprint>.png`) and recorded in `altium/footprint-dims.json`, which the design review shows under "Footprints checked against datasheets".+When `design/part-checks.json` gives a part's `dims` (pitch, span, body size between pads or body corners; the aiflow-sourcing skill), `altium library` puts each on the imported footprint with `altium_add_dimensions`: a real Altium dimension anchored to the pads or the assembly outline's corners, its direction and position worked out from the footprint's KiCad file, text scaled to the footprint. Altium answers MATCH or MISMATCH for each. A mismatch stops the step (the library is built; fix the footprint or acknowledge the dimension with `"ack"`). The dimensioned footprint is pictured (`altium/footprints/<footprint>.png`) and recorded in `altium/footprint-dims.json`, which the design review shows under "Footprints checked against datasheets". With altium-bridge 0.2.122 a rerun (`altium library --again`) replaces a footprint's dimensions (`replace: true`) and the reply's `format.applied` and each dimension's `style` (read back from Altium) are kept in the record; with 0.2.121 a footprint is dimensioned once, since the bridge would add copies. 
docs/release-0.2.138.mdadded+10
@@ -0,0 +1,10 @@+# adom-aiflow 0.2.138++## Altium: readable dimension pictures, and reruns redo them (altium-bridge 0.2.122)++0.2.137's dimensioned footprints kept Altium's default arrows, large on a small part. With altium-lane's format keys (all mm), the dimension text, its stroke, the lines, the arrows and the extension offset now start from altium-lane's measured 0603 values (text 0.3, arrows 0.15 by 0.25, lines 0.05) and grow with the footprint, the text at most 1 mm.++- altium-bridge 0.2.122 answers which format keys it read (`format.applied`) and did not know (`format.ignored`), and each dimension's `style` as read back from Altium after the library reopened; the record (altium/footprint-dims.json) keeps both.+- `replace: true` (0.2.122) takes a footprint's earlier dimensions off first, so `altium library --again` redoes them instead of skipping the footprint. With 0.2.121 a footprint is still dimensioned only once.++Tested live on the test desktop (Altium Designer 26, altium-bridge 0.2.122): an 0603 dimensioned with small arrows and readable text, every format value applied and none ignored, and a rerun left three dimensions, not six.
package.json+1−1
@@ -1,7 +1,7 @@ {   "slug": "adom-aiflow",   "type": "app",-  "version": "0.2.137",+  "version": "0.2.138",   "title": "AI Flow",   "description": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. One Rust binary with a crate per step (placement helpers, a grid router with Kelvin taps, pours with keepouts, KiCad's DRC gate, live landing through the KiCad Bridge, copper measurement, current and thermal analysis) and a finish line that refuses an unfinished board. Every command answers with hints for the AI; every turn, its thinking time and every rework loop go into run.jsonl, so Claude, Codex and any other engine are compared on the same flow. KiCad, Fusion 360 and Altium Designer today (the same steps and gates through each tool's bridge); Adom's own web apps next.",   "summary": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. The AI thinks its way from placement through routing, pours, current and thermal analysis to a delivered video; the binary does the fast, deterministic parts of every step, hands back hints, and keeps a ledger of every turn, every return to an earlier step, and the clock from the prompt to done.",
page.json+1−1
@@ -1,7 +1,7 @@ {   "slug": "adom-aiflow",   "type": "app",-  "version": "0.2.137",+  "version": "0.2.138",   "title": "AI Flow",   "description": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. One Rust binary with a crate per step (placement helpers, a grid router with Kelvin taps, pours with keepouts, KiCad's DRC gate, live landing through the KiCad Bridge, copper measurement, current and thermal analysis) and a finish line that refuses an unfinished board. Every command answers with hints for the AI; every turn, its thinking time and every rework loop go into run.jsonl, so Claude, Codex and any other engine are compared on the same flow. KiCad, Fusion 360 and Altium Designer today (the same steps and gates through each tool's bridge); Adom's own web apps next.",   "summary": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. The AI thinks its way from placement through routing, pours, current and thermal analysis to a delivered video; the binary does the fast, deterministic parts of every step, hands back hints, and keeps a ledger of every turn, every return to an earlier step, and the clock from the prompt to done.",
tests/altium-dims.py+7−2
@@ -43,11 +43,16 @@ def main():     # every dimension line runs outside the pads and the body, and two the same way go on opposite sides     assert all(abs(d['at']) > (2.45 if d['dir'] == 'H' else 2.7) for d in vd) and vd[0]['at'] * vd[2]['at'] < 0, vd     f = ns['dim_format'](pads, box)-    assert 0.25 <= f['textHeightMm'] <= 1.0 and f['units'] == 'mm'+    assert f['units'] == 'mm' and 'textHeight' not in f and all(isinstance(v, float) for k, v in f.items() if k != 'units')+    # an 0603 (1.65 mm across) gets altium-lane's measured values; a larger part grows them, the text at most 1 mm+    o603 = ns['dim_format']({'1': (-0.825, 0.0), '2': (0.825, 0.0)}, (-0.8, -0.4125, 0.8, 0.4125))+    assert o603 == {'textHeightMm': 0.3, 'textLineWidthMm': 0.04, 'lineWidthMm': 0.05, 'arrowSizeMm': 0.15, 'arrowLengthMm': 0.25, 'extensionOffsetMm': 0.1, 'units': 'mm'}, o603+    assert f['arrowSizeMm'] > 0.15 and f['textHeightMm'] <= 1.0      # all match: rows, no stop, the picture kept     facts = {'mpn': 'X', 'source': 'ds p.1', 'dims': dims[:4]}-    rec = ns['dimension_part']('C:/L/P.PcbLib', 'SOIC8', facts, SOIC)+    rec = ns['dimension_part']('C:/L/P.PcbLib', 'SOIC8', facts, SOIC, replace=True)+    assert calls[0][1]['replace'] is True     assert rec['stop'] == [] and len(rec['rows']) == 4 and all(r['check'] == 'MATCH' for r in rec['rows'])     assert rec['image'] and Path(rec['image']).name == 'SOIC8.png' and Path(rec['image']).is_file()     assert [c[0] for c in calls] == ['altium_add_dimensions', 'altium_show_footprint']
tools/altium-dims.py+20−7
@@ -15,6 +15,7 @@ step (a wrong footprint is a wrong board) unless it carries "ack": "<why>". """  DIMS_FROM = (0, 2, 121)+REPLACE_FROM = (0, 2, 122) CORNERS = ('TL', 'TR', 'BR', 'BL')  @@ -82,23 +83,31 @@ def verb_dims(dims, pads, box):   def dim_format(pads, box):-    """Text and arrows scaled to the footprint: a 0603 and a QFN-48 both stay readable."""+    """Text, lines and arrows scaled to the footprint (altium-bridge 0.2.122's format keys, mm): altium-lane's measured+    0603 values (a 1.65 mm footprint) grown with the part, so a 0603 and a QFN-48 both read well in the picture."""     xs = [p[0] for p in pads.values()] + ([box[0], box[2]] if box else [])     ys = [p[1] for p in pads.values()] + ([box[1], box[3]] if box else [])     size = max((max(xs) - min(xs)) if xs else 1.0, (max(ys) - min(ys)) if ys else 1.0, 0.5)-    h = round(min(1.0, max(0.25, 0.18 * size)), 3)-    return {'textHeightMm': h, 'textHeight': h, 'lineWidthMm': round(h / 8, 3), 'arrowSizeMm': round(h * 0.8, 3), 'arrowLengthMm': round(h * 0.8, 3), 'extensionOffsetMm': round(h / 2, 3), 'units': 'mm'}+    k = min(6.0, max(1.0, size / 1.65))+    base = {'textHeightMm': 0.3, 'textLineWidthMm': 0.04, 'lineWidthMm': 0.05, 'arrowSizeMm': 0.15, 'arrowLengthMm': 0.25, 'extensionOffsetMm': 0.1}+    f = {key: round(v * k, 3) for key, v in base.items()}+    f['textHeightMm'] = min(f['textHeightMm'], 1.0)+    f['units'] = 'mm'+    return f  -def dimension_part(pcb_lib, footprint, facts, fp_text):-    """Check one imported footprint against its datasheet dims in Altium and keep its picture. Returns the record-    {footprint, mpn, source, rows, stop, acked, image}."""+def dimension_part(pcb_lib, footprint, facts, fp_text, replace=False):+    """Check one imported footprint against its datasheet dims in Altium and keep its picture. `replace` (altium-bridge+    0.2.122) takes off the footprint's earlier dimensions first, so a rerun redoes them. Returns the record+    {footprint, mpn, source, rows, stop, acked, image, format}."""     pads, box = kicad_geometry(fp_text)     dims = [d for d in facts.get('dims') or [] if isinstance(d, dict) and d.get('mm') is not None]     vd, problems = verb_dims(dims, pads, box)     rec = {'footprint': footprint, 'mpn': facts.get('mpn'), 'source': facts.get('source'), 'rows': [], 'stop': ['%s: %s' % (facts.get('mpn'), p) for p in problems], 'acked': [], 'image': None}     if not vd: return rec-    r = ab('altium_add_dimensions', {'libraryPath': win(pcb_lib), 'footprint': footprint, 'dimensions': vd, 'format': dim_format(pads, box)}, timeout=900)+    args = {'libraryPath': win(pcb_lib), 'footprint': footprint, 'dimensions': vd, 'format': dim_format(pads, box)}+    if replace: args['replace'] = True+    r = ab('altium_add_dimensions', args, timeout=900)     if not r.get('success'):         rec['stop'].append('%s: altium_add_dimensions failed: %s' % (facts.get('mpn'), str(r.get('error') or r.get('errorCode'))[:200]))         return rec@@ -107,10 +116,14 @@ def dimension_part(pcb_lib, footprint, facts, fp_text):     for d, g in zip(asked, got):         what = d.get('what') or '%s to %s' % (d.get('a'), d.get('b'))         row = {'what': what, 'a': str(d.get('a')), 'b': str(d.get('b')), 'datasheetMm': d['mm'], 'footprintMm': g.get('valueMm', g.get('lengthMm')), 'check': g.get('check'), 'ack': d.get('ack')}+        if g.get('style'): row['style'] = g['style']         rec['rows'].append(row)         if g.get('check') != 'MATCH':             line = '%s: %s (%s to %s) is %s mm on footprint %s, %s mm in the datasheet' % (facts.get('mpn'), what, row['a'], row['b'], row['footprintMm'], footprint, d['mm'])             (rec['acked'] if d.get('ack') else rec['stop']).append(line + (' (acknowledged: %s)' % d['ack'] if d.get('ack') else ''))+    # 0.2.122 says which format keys it read and which it did not know+    fmt = r.get('format') if isinstance(r.get('format'), dict) else {}+    rec['format'] = {'applied': fmt.get('applied'), 'ignored': fmt.get('ignored')} if fmt else None     shot = ab('altium_show_footprint', {'libraryPath': win(pcb_lib), 'footprintName': footprint}, timeout=300).get('shot') or {}     if isinstance(shot, dict) and shot.get('image'):         import base64
tools/altium-project.py+4−2
@@ -157,6 +157,8 @@ def cmd_library(a):     # #43: the datasheet's dimensions (design/part-checks.json `dims`), checked in Altium on each imported footprint     pc_facts = part_check_facts() if version_tuple(ver) >= DIMS_FROM else {}     dim_recs, dim_skipped = [], []+    # altium-bridge 0.2.122: replace:true takes a footprint's earlier dimensions off first, so a rerun redoes them+    can_replace = version_tuple(ver) >= REPLACE_FROM     prev_parts = json.loads(json.dumps(st.get('parts') or {}))     for key, w in work.items():         if w['origin'] == 'project-lib': from_lib.append(w['mpn'])@@ -202,11 +204,11 @@ def cmd_library(a):         # a footprint dimensioned by an earlier run keeps those dimensions through a re-import, and the bridge adds to         # what is there: dimension it once, so a rerun does not stack copies         prev_dims = (prev_parts.get(key) or {}).get('dims')-        if facts and prev_dims and prev_dims.get('rows'):+        if facts and prev_dims and prev_dims.get('rows') and not can_replace:             st['parts'][key]['dims'] = prev_dims             dim_skipped.append(key)         elif facts:-            rec = dimension_part(pcb_lib, key, facts, Path(fp_path).read_text(errors='ignore'))+            rec = dimension_part(pcb_lib, key, facts, Path(fp_path).read_text(errors='ignore'), replace=can_replace)             dim_recs.append(rec)             st['parts'][key]['dims'] = {'rows': rec['rows'], 'image': rec['image'], 'stop': rec['stop']}         added.append(key)