← Commit history
Merge PR #650: 0.2.136: Altium layer count from the bridge, silkscreen check (altium-layers-silk-0.2.136 -> main) merge
Showing changes introduced by the merge (against its first parent).
9 files changed
+149−21
Cargo.lock+11−11@@ -4,7 +4,7 @@ version = 4 [[package]] name = "adom-aiflow"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-analyze", "aiflow-board",@@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "aiflow-analyze"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-board", "aiflow-sys",@@ -39,7 +39,7 @@ dependencies = [ [[package]] name = "aiflow-board"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-sys", "roxmltree",@@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "aiflow-bridge"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-board", "aiflow-sys",@@ -59,7 +59,7 @@ dependencies = [ [[package]] name = "aiflow-copper"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-board", "aiflow-grid",@@ -70,7 +70,7 @@ dependencies = [ [[package]] name = "aiflow-grid"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-board", "serde",@@ -79,7 +79,7 @@ dependencies = [ [[package]] name = "aiflow-place"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-board", "aiflow-sys",@@ -89,7 +89,7 @@ dependencies = [ [[package]] name = "aiflow-pours"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-board", "aiflow-copper",@@ -100,7 +100,7 @@ dependencies = [ [[package]] name = "aiflow-router"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-board", "aiflow-grid",@@ -111,7 +111,7 @@ dependencies = [ [[package]] name = "aiflow-run"-version = "0.2.135"+version = "0.2.136" dependencies = [ "aiflow-sys", "serde",@@ -120,7 +120,7 @@ dependencies = [ [[package]] name = "aiflow-sys"-version = "0.2.135"+version = "0.2.136" dependencies = [ "serde_json", ]
Cargo.toml+1−1@@ -15,7 +15,7 @@ members = [ ] [workspace.package]-version = "0.2.135"+version = "0.2.136" edition = "2021" license = "MIT" repository = "https://wiki.adom.inc/adom/adom-aiflow"
docs/altium-lane.md+6@@ -178,3 +178,9 @@ adom-aiflow altium simulate --sources sim/altium-sources.json [--loads sim/altiu altium-bridge before 0.2.119 filled a PcbLib its footprint and layer-map verbs touched with all 1024 mechanical layers (1048 layer records instead of about 56), and Altium could hang attaching a STEP to such a library. `altium library` checks a library it reuses: the saved file names its layers and footprints, so a library whose mechanical layers reach 1000 or more is copied footprint by footprint into a fresh one (`altium_xcopy_footprint`), checked, and swapped in at the same path, with the old file kept as `<name>.bloated.PcbLib`. The library's folder is closed (saved) in Altium before the copy and before the swap, so Altium's in-memory copy cannot write the old library back. The repair needs altium-bridge 0.2.120; on an older bridge a bloated library is named and left alone, and a bridge before 0.2.119 is warned about, since it adds the layers again. +From altium-bridge 0.2.120 the layer count comes from the bridge (`altium_layer_map {action: "get"}` answers `libraryLayers.bloated` from the saved file), for the library and for the board; the export step names a board that carries the 1024 layers (it works, only larger; there is no repair for a board, but building it again on 0.2.120 or newer is clean).++## Silkscreen against exposed copper (altium-bridge 0.2.121)++After the library step imports footprints, `altium_check_silkscreen` measures each one's silkscreen against its exposed copper: the pad plus its solder mask opening (the pad's own, else Altium's default 4 mil). Footprints closer than spec `silkPadClearance` (default 0.15 mm, JLCPCB's figure) are named in the step's result with the clearance and the pad, as a note: the fab clips silkscreen out of a pad opening, so such a line prints shorter rather than on the pad. Trim it with `altium_edit_footprint` where the outline matters. A KiCad 0603 resistor footprint reads about 0.06 mm with the 4 mil opening.+
docs/release-0.2.136.mdadded+13@@ -0,0 +1,13 @@+# adom-aiflow 0.2.136++## Altium: the bridge counts the layers (altium-bridge 0.2.120, public)++The library step's check for a library with all 1024 mechanical layers (0.2.132, altium-bridge#44) now asks the bridge: `altium_layer_map get` reads the saved file and says `bloated`. A clean library is no longer copied to the container to be read; a bloated one still is, for its footprint names, and the fresh copy is checked by the bridge too before it is swapped in. An older bridge keeps 0.2.132's own file count.++The export step also names a board that carries the 1024 layers (placed on typed layers with altium-bridge 0.2.113 to 0.2.118): it works, only larger and slower to open; there is no repair for a board, and one built again on 0.2.120 or newer is clean.++## Altium: silkscreen against exposed copper (altium-bridge 0.2.121, #43)++After `altium library` imports footprints, it measures each one's silkscreen against its exposed copper (the pad plus its mask opening) with `altium_check_silkscreen`, in one call. Footprints closer than spec `silkPadClearance` (default 0.15 mm, JLCPCB's figure) are named in the step's result with the clearance, the pad and the mask opening used. It is a note, not a stop: the fab clips silkscreen out of a pad's opening, so such a line prints shorter rather than on the pad. Needs altium-bridge 0.2.121 (insiders today); older bridges skip it.++Tested live on the test desktop (Altium Designer 26, altium-bridge 0.2.121): a new library's 0603 resistor read 0.062 mm against Altium's 0.102 mm default mask opening and was named; the same library reused was judged clean by the bridge's count without being copied.
package.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow", "type": "app",- "version": "0.2.135",+ "version": "0.2.136", "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.135",+ "version": "0.2.136", "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-libfix.py+30@@ -28,6 +28,15 @@ def harness(files, fail_copy=None, swap_ok=True): src = args['filePaths'][0].replace('\\', '/') if src in files: (Path(args['saveTo']) / src.split('/')[-1]).write_bytes(files[src]) return {'success': True}+ if verb == 'altium_layer_map':+ src = args['libraryPath'].replace('\\', '/')+ if src not in files: return {'success': False, 'error': 'file not found'}+ recs = len(re.findall(rb'LAYER_V8_\d+NAME=', files[src])); mech = [int(x) for x in re.findall(rb'MECHANICAL(\d+)', files[src])]+ return {'success': True, 'libraryLayers': {'bloated': max(mech or [0]) >= 1000, 'layerRecords': recs, 'mechanicalLayers': max(mech or [0])}}+ if verb == 'altium_check_silkscreen':+ return {'success': True, 'maskExpansion': {'mm': 0.1016}, 'footprints': [+ {'footprint': f, 'result': 'FAIL' if f == 'R0603' else 'PASS', 'closest': {'clearanceMm': 0.062 if f == 'R0603' else 0.3, 'pad': '1', 'overlaps': False}, 'under': [{}] * (4 if f == 'R0603' else 0)}+ for f in args['footprints']]} if verb == 'altium_xcopy_footprint': if args['from'] == fail_copy: return {'success': False, 'error': 'no such footprint'} return {'success': True, 'data': {'ok': True}}@@ -94,6 +103,27 @@ def main(): ns, _, _ = harness({lib_path: bloated, fresh: lib(56, 32, ['R0603', 'SOT-23'])}, swap_ok=False) try: ns['repair_pcblib'](lib_path); raise AssertionError('should stop') except Stop as e: assert 'could not swap' in str(e)+ # altium-bridge 0.2.120+: the bridge counts the layers; a clean library is not even pulled+ ns, calls, _ = harness({lib_path: clean})+ out = ns['repair_pcblib'](lib_path, ver='0.2.120')+ assert out['by'] == 'altium_layer_map' and out['bloated'] is False and [c[0] for c in calls] == ['altium_layer_map'], (out, calls)+ # a bloated one is pulled for its footprint names, and the fresh copy is checked by the bridge too+ ns, calls, _ = harness({lib_path: bloated, fresh: lib(56, 32, ['R0603', 'SOT-23'])})+ out = ns['repair_pcblib'](lib_path, ver='0.2.120')+ assert out['repaired'] and [c[0] for c in calls].count('altium_layer_map') == 2, calls+ # a board: a note only when the bridge says bloated, and only from 0.2.120+ board = 'C:/Box/Proj.PcbDoc'+ ns, _, _ = harness({board: bloated})+ assert 'altium-bridge#44' in ns['board_note'](board, '0.2.121') and ns['board_note'](board, '0.2.118') is None+ ns, _, _ = harness({board: clean})+ assert ns['board_note'](board, '0.2.121') is None+ # altium-bridge 0.2.121: the silkscreen check names the footprints under the minimum, a note with the mask opening+ ns, calls, _ = harness({})+ rows = ns['silk_check'](lib_path, ['R0603', 'SOT-23'], 0.15)+ assert [x['result'] for x in rows] == ['FAIL', 'PASS'] and calls[0][1]['footprints'] == ['R0603', 'SOT-23']+ lines = ns['silk_lines'](rows, 0.15)+ assert len(lines) == 1 and 'R0603 0.062 mm at pad 1' in lines[0] and '0.102 mm mask opening' in lines[0] and '1 of 2 footprint(s)' in lines[0], lines+ assert ns['silk_lines']([{'footprint': 'R0603', 'result': 'PASS'}], 0.15) == [] print('OK')
tools/altium-libfix.py+73−4@@ -7,7 +7,14 @@ footprints (`PATTERN=<name>`). A library whose mechanical layers reach MECHANICA footprint into a fresh library with `altium_xcopy_footprint` (which carries only the layers each footprint's graphics use), checked, and swapped in at the same path; the old file is kept beside it as <name>.bloated.PcbLib. A bridge before 0.2.119 is named before the library step writes anything, since every footprint it writes adds-the layers again.+the layers again. From altium-bridge 0.2.120 the layer count comes from the bridge (`altium_layer_map get`, which reads+the saved file and says `bloated`), for a library and for the board; the file is read only for a library's footprint+names when it needs the repair.++altium-bridge 0.2.121 (#43): `altium_check_silkscreen` measures each footprint's silkscreen against its exposed copper+(the pad plus its mask opening). The library step checks the footprints a run imports and names the ones closer than+the minimum (spec `silkPadClearance`, else 0.15 mm, JLCPCB's figure), as a note: the fab clips silkscreen out of a+pad's opening, so such a line prints shorter rather than on the pad. """ FIXED_IN = (0, 2, 119)@@ -15,6 +22,9 @@ FIXED_IN = (0, 2, 119) REPAIR_FROM = (0, 2, 120) BLOAT_MECH = 1000 FACTORY_STRAY = 'PCBComponent_1'+LAYER_VERB_FROM = (0, 2, 120)+SILK_CHECK_FROM = (0, 2, 121)+SILK_PAD_MIN_MM = 0.15 def layer_census(blob):@@ -64,14 +74,39 @@ def pull_lib(path, into): return local.read_bytes() if local.is_file() else None -def repair_pcblib(pcb_lib, repair=True):+def bridge_layers(path):+ """altium_layer_map get's count for a saved .PcbLib or .PcbDoc (altium-bridge 0.2.120+): {bloated, layerRecords,+ mechanicalLayers, ...}, or None when it cannot read the file."""+ r = ab('altium_layer_map', {'action': 'get', 'libraryPath': win(path)}, timeout=180)+ ll = r.get('libraryLayers')+ return ll if r.get('success') and isinstance(ll, dict) and 'bloated' in ll else None+++def board_note(board, ver):+ """A note for a board that carries the 1024 mechanical layers (bridge 0.2.113 to 0.2.118 placing on typed layers):+ it still works, only larger; there is no repair for a board. None when it is clean or cannot be read."""+ if not board or not version_tuple(ver) or version_tuple(ver) < LAYER_VERB_FROM: return None+ ll = bridge_layers(board)+ if not ll or not ll.get('bloated'): return None+ return ('%s carries %s layer records (mechanical layers up to %s) from an altium-bridge before 0.2.119 (altium-bridge#44): it works, '+ 'only larger and slower to open; a board built again with altium-bridge 0.2.120 or newer (`altium board`) is clean'+ % (board, ll.get('layerRecords'), ll.get('mechanicalLayers')))+++def repair_pcblib(pcb_lib, repair=True, ver=None): """Check the project PcbLib at `pcb_lib` (a desktop path) and, when `repair` (altium-bridge 0.2.120+), repair it when it carries the 1024 layers. Returns None when there is no library to read, else what was found and done.""" work = STATE / 'libcheck'+ by_bridge = version_tuple(ver) >= LAYER_VERB_FROM if ver else False+ if by_bridge:+ ll = bridge_layers(pcb_lib)+ if ll is None: return None+ if not ll.get('bloated'):+ return {'bloated': False, 'records': ll.get('layerRecords'), 'highestMechanical': ll.get('mechanicalLayers'), 'by': 'altium_layer_map'} blob = pull_lib(pcb_lib, work) if blob is None: return None recs, high, fps = layer_census(blob)- if high < BLOAT_MECH:+ if high < BLOAT_MECH and not by_bridge: return {'bloated': False, 'records': recs, 'highestMechanical': high} if not repair: say('WARNING: %s carries %d layer records, mechanical layers up to %d (altium-bridge#44); AI Flow repairs it from altium-bridge 0.2.120'@@ -97,7 +132,8 @@ def repair_pcblib(pcb_lib, repair=True): if fb is None: err('repairing %s: the fresh library %s could not be read back' % (pcb_lib, fresh), ['The library is untouched.']) frecs, fhigh, ffps = layer_census(fb) missing = sorted(set(names) - set(ffps))- if fhigh >= BLOAT_MECH or missing:+ still = (bridge_layers(fresh) or {}).get('bloated') if by_bridge else False+ if fhigh >= BLOAT_MECH or missing or still: err('repairing %s: the fresh library is not right (%d layer records, mechanical up to %d%s)' % (pcb_lib, frecs, fhigh, ('; missing ' + ', '.join(missing)) if missing else ''), ['The library is untouched; %s is the attempt. Update altium-bridge to 0.2.119 or newer.' % fresh]) close_folder(pcb_lib)@@ -107,3 +143,36 @@ def repair_pcblib(pcb_lib, repair=True): ['The fresh library is %s. Close the library in Altium, then run `altium library` again.' % fresh]) return {'bloated': True, 'repaired': True, 'records': recs, 'highestMechanical': high, 'footprints': len(names), 'after': {'records': frecs, 'highestMechanical': fhigh}, 'kept': kept}+++def silk_check(pcb_lib, footprints, min_mm):+ """altium_check_silkscreen on `footprints` of the library (altium-bridge 0.2.121+): one row per footprint+ {footprint, result PASS|FAIL, clearanceMm, pad, overlaps, under, maskMm}, or a row with result "unchecked"."""+ if not footprints: return []+ r = ab('altium_check_silkscreen', {'libraryPath': win(pcb_lib), 'footprints': list(footprints), 'minMm': min_mm}, timeout=900)+ if not r.get('success'):+ why = str(r.get('error') or r.get('errorCode') or '?')[:160]+ return [{'footprint': f, 'result': 'unchecked', 'why': why} for f in footprints]+ mask = (r.get('maskExpansion') or {}).get('mm')+ rows = []+ for f in r.get('footprints') or []:+ c = f.get('closest') or {}+ rows.append({'footprint': f.get('footprint'), 'result': f.get('result'), 'clearanceMm': c.get('clearanceMm'), 'pad': c.get('pad'),+ 'overlaps': bool(c.get('overlaps')), 'under': len(f.get('under') or []), 'maskMm': mask})+ return rows+++def silk_lines(rows, min_mm):+ """The library step's note on the silkscreen check: the footprints under the minimum, closest first."""+ bad = sorted([x for x in rows if x.get('result') == 'FAIL'], key=lambda x: x.get('clearanceMm') if x.get('clearanceMm') is not None else -1)+ un = [x for x in rows if x.get('result') == 'unchecked']+ out = []+ if bad:+ mask = next((x['maskMm'] for x in bad if x.get('maskMm') is not None), None)+ out.append('silkscreen closer than %.2f mm to exposed copper (pad plus %s mask opening) on %d of %d footprint(s): %s. The fab clips silkscreen '+ 'out of a pad opening, so these lines print shorter; trim them (altium_edit_footprint graphics) where the outline matters, or set spec silkPadClearance to the fab\'s own figure'+ % (min_mm, ('%.3f mm' % mask) if mask is not None else 'its', len(bad), len(rows),+ ', '.join('%s %s mm at pad %s%s' % (x['footprint'], x.get('clearanceMm'), x.get('pad'), ' (on the copper)' if x.get('overlaps') else '') for x in bad[:12])))+ if un: out.append('silkscreen not checked on %s: %s' % (', '.join(x['footprint'] for x in un[:12]), un[0].get('why')))+ return out+
tools/altium-project.py+13−3@@ -131,7 +131,7 @@ def cmd_library(a): if old_note: say('WARNING: ' + old_note) fix = None if st.get('pcbLib'):- fix = repair_pcblib(pcb_lib, repair=can_repair(ver))+ fix = repair_pcblib(pcb_lib, repair=can_repair(ver), ver=ver) if fix: st['pcbLibCheck'] = fix; save_state(st) # the `parts` step's choice per MPN: the wiki page it matched, or the board's project library rows = parts_rows(run_data())@@ -196,6 +196,14 @@ def cmd_library(a): say('part %s: footprint%s%s%s, refs %s%s' % (key, ', symbol' if spec_sym else '', ', 3D' if step else '', (', SPICE model' if st['parts'][key].get('sim', {}).get('attached') else ', no SPICE model (%s)' % st['parts'][key]['sim'].get('why')) if st['parts'][key].get('sim') else '', ' '.join(r for r in w['refs'] if r) or '-', ' (from the project library)' if w['origin'] == 'project-lib' else '')) save_state(st) st['schLib'], st['pcbLib'] = sch_lib, pcb_lib+ # altium-bridge 0.2.121 (#43): silkscreen against exposed copper on the footprints this run imported (a note, not a stop)+ silk_notes = []+ if added and version_tuple(ver) >= SILK_CHECK_FROM:+ smin = run_spec().get('silkPadClearance') or SILK_PAD_MIN_MM+ rows = silk_check(pcb_lib, added, smin)+ for row in rows:+ if row.get('footprint') in st['parts']: st['parts'][row['footprint']]['silk'] = row+ silk_notes = silk_lines(rows, smin) save_state(st) prove('library', {'name': name, 'parts': len(st['parts']), 'tool': 'altium', 'projectLibParts': from_lib, 'spiceModels': sum(1 for p in st['parts'].values() if (p.get('sim') or {}).get('attached'))}) if fix and fix.get('repaired'):@@ -203,7 +211,7 @@ def cmd_library(a): % (pcb_lib, fix['records'], fix['highestMechanical'], fix['after']['records'], fix['after']['highestMechanical'], fix['footprints'], fix['kept'])) ok('library %s: %d part(s) (%d added, %d kept%s): %s and %s' % (name, len(st['parts']), len(added), len(kept), '; %d from the board\'s project library: %s' % (len(from_lib), ', '.join(from_lib)) if from_lib else '', pcb_lib, sch_lib),- spice_summary(st['parts']) + ['No distributor number yet: ' + '; '.join('%s %s' % (m, ' '.join(v)) for m, v in unverified.items()) + '. Run `altium library` again when the services are back, or add the numbers to the part\'s wiki page (a project-library part: "mouser"/"digikey"/"lcsc" in its provenance.json entry).' if unverified else '',+ silk_notes + spice_summary(st['parts']) + ['No distributor number yet: ' + '; '.join('%s %s' % (m, ' '.join(v)) for m, v in unverified.items()) + '. Run `altium library` again when the services are back, or add the numbers to the part\'s wiki page (a project-library part: "mouser"/"digikey"/"lcsc" in its provenance.json entry).' if unverified else '', 'Next: adom-aiflow altium reference --kicad <reference .kicad_pcb> --spec <spec.json> (if there is a reference board), then adom-aiflow altium schematic --netlist <netlist.json> --name <Design> (the schematic, then the board in the same project).']) @@ -715,7 +723,9 @@ def cmd_export(a): out, zp.name, len(copper_files), ' as the stack has' if stack_n else ', stack not read', hits, len(refs_in(cpl)), len(table(bom)[1])), ['No LCSC number on: ' + ', '.join(missing_numbers) + '. That is fine: for a JLCPCB build, buy these anywhere (DigiKey, Mouser, ...) and send them as consigned parts, or add an LCSC number to the part to have JLCPCB source it (usually cheaper and faster).' if missing_numbers else '', 'Test points and board-only pads are bare copper, out of the BOM and the pick and place: ' + ', '.join(tps) if tps else '',- 'Machine contacts and pins are fitted after assembly: DNP in the BOM, out of the pick and place: ' + ', '.join(dnp) if dnp else ''])+ 'Machine contacts and pins are fitted after assembly: DNP in the BOM, out of the pick and place: ' + ', '.join(dnp) if dnp else '',+ # altium-bridge#44: a board placed with 0.2.113 to 0.2.118 on typed layers carries 1024 mechanical layers+ board_note(pcb, ab('altium_status', {}, timeout=120).get('bridgeVersion')) or '']) # ---------------------------------------------------------------- reset / view3d