master
John Lauer Add native thermal-pour expansion experiment, finite-difference comparison and recording scripts 33c4ac5 1mo ago
"""Native-refilled expansion candidates; original video-10 board remains untouched."""
import sys,json,xml.etree.ElementTree as ET
from pathlib import Path
P=Path(__file__).resolve().parent
sys.path.insert(0,str(P.parent/'thermal'))
from crr import call,execute
BOUNDS={'VAC1':(0,18.7,23,26.4),'VBUS':(0,7.7,23,18.7),'VAC2':(0,0,23,7.7),'VBAT':(40.8,0,50.4,26.4)}
def build(name,bounds):
 out=P/name;out.mkdir(exist_ok=False)
 t=ET.parse(P.parent/'thermal/recording-02/bq25792-astra-thermal-routed.brd');b=t.find('drawing/board')
 for s in b.findall('signals/signal'):
  for p in s.findall('polygonpour'):
   for e in p.findall('polygonfilldetails'):p.remove(e)
   if s.get('name') not in bounds or p.get('layer')!='16':continue
   x,y,z,w=bounds[s.get('name')];o=p.find('polygonoutlineobjects')
   for v in list(o):o.remove(v)
   for xx,yy in [(x,y),(z,y),(z,w),(x,w)]:ET.SubElement(o,'vertex',{'x':str(xx),'y':str(yy)})
   p.set('orphans','no')
 f=out/(name+'.brd');t.write(f,encoding='utf-8',xml_declaration=True)
 (out/'bounds.json').write_text(json.dumps(bounds,indent=2))
 r=call('send_files',{'filePaths':[str(f)],'dest':'C:/Users/john/AppData/Local/Temp/adom-thermal-expansion','reason':'Validate expanded heatsinking on a separate copy of the Fusion demo board'});assert r.get('success'),r
 r=call('fusion_open_board',{'filePath':r['destinationPaths'][0]});assert r.get('success'),r
 r=execute(name,"app.executeTextCommand('Electron.run RATSNEST;')\ns=handle(app,{'expectDocument':target.name},'routing_state')\nresult=handle(app,{'expectDocument':target.name,'boardId':s['boardId'],'expectedRevision':s['revision']},'routing_drc')")
 (out/'native-drc.json').write_text(json.dumps(r,indent=2));print(name,r['drc'],flush=True)
 host='C:/Users/john/AppData/Local/Temp/adom-thermal-expansion/'+name+'-filled.brd'
 r=execute(name,"root,b,m=snapshot(app,{'expectDocument':target.name})\np=Path("+repr(host)+")\nET.ElementTree(root).write(p,encoding='utf-8',xml_declaration=True)\nresult={'path':p.as_posix()}")
 r=call('pull_file',{'filePaths':[host],'saveTo':str(out)});assert r.get('success'),r
 
 # Current AB mesh pull lands on the local Windows host. Normalize into this container.
 import shutil
 filled=out/(name+'-filled.brd')
 if not filled.exists():
  src=Path('/mnt/c')/str(out).lstrip('/')/filled.name
  assert src.exists(),r
  shutil.copy2(src,filled)
 return out
if __name__=='__main__':build('expansion-01',BOUNDS)