master
John Lauer Preserve BQ independent routing, narration and native copper-retention evidence a4b7711 1mo ago
import sys,json,time,concurrent.futures
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]));from call import call
from live_panel import LivePanel
ROOT=Path(__file__).resolve().parent;TAKE=ROOT/(sys.argv[1] if len(sys.argv)>1 else 'strip-take-02');TAKE.mkdir(exist_ok=False);log=[];doc='bq25792-original-tour'
def invoke(v,a,transport=False):
 t=time.time();r=call(v,a,script_transport=transport);log.append({'verb':v,'args':a,'start':t,'end':time.time(),'result':r});(TAKE/'calls.json').write_text(json.dumps(log,indent=2));assert r.get('success'),r;return r
s=invoke('fusion_routing_state',{'expectDocument':doc},True);assert s['segmentCount']==587 and s['viaCount']==88
w=invoke('desktop_list_windows',{})['windows'];main=next(x for x in w if x['image']=='Fusion360.exe' and x['owner']==0);palette=next(x for x in w if x['image']=='Fusion360.exe' and x['title']=='ADOM')
panel=LivePanel(invoke,doc,TAKE/'panel-events.jsonl',palette['hwnd']);panel.update(status='Remove reference routing from this copy',detail='Original source preserved / isolated demo document',connection='587 routed segments / 88 vias / 38 pours',plan='Native EAGLE RIPUP; then a clean copy without old pours',checks='Astra planner used only pads, netlist and design rules',percent=0)
records=[]
try:
 for name,hwnd in [('board',main['hwnd']),('panel',palette['hwnd'])]:
  r=invoke('desktop_record_window_start',{'hwnd':hwnd,'fps':30,'audio':False,'maxDurationMs':90000,'reason':'Record removing Adonis routing from an isolated demo copy'});records.append((name,r));(TAKE/(name+'-start.json')).write_text(json.dumps(r,indent=2))
 time.sleep(2)
 source=(ROOT.parents[2]/'rust/bridge/src/routing_script.py').read_text();script='exec('+repr(source)+')\nargs='+repr({'expectDocument':doc,'boardId':s['boardId'],'expectedRevision':s['revision']})+'\n_,b,m=snapshot(app,args)\nassert m["revision"]==args["expectedRevision"]\napp.executeTextCommand("Electron.run RIPUP ;")\napp.executeTextCommand("Electron.ImmediateRepaint /full")\n_,b,m=snapshot(app,args)\nresult={"success":True,**state(b,m)}'
 script=script.replace('Electron.run RIPUP ;','Electron.run DISPLAY 1 2 15 16 17 18 20 21; RIPUP ;')
 with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
  pending=pool.submit(invoke,'fusion_run_modeling_script',{'expectDocument':doc,'script':script})
  for _ in range(40):
   if pending.done():break
   time.sleep(1)
   shot=call('desktop_screenshot_window',{'hwnd':main['hwnd']})
   popup=next((x for x in shot.get('screenshots',[]) if x.get('title')=='Fusion'),None)
   if popup:
    found=call('desktop_find_control',{'hwnd':popup['hwnd'],'name':'Yes','role':'button'})
    if found.get('best',{}).get('invokable'):
     invoke('desktop_ui_click',{'hwnd':popup['hwnd'],'name':'Yes','role':'button','reason':'Confirm user-requested removal of all traces from the isolated demo copy'});break
  r=pending.result()
 result=r['result'];(TAKE/'stripped.json').write_text(json.dumps(result,indent=2));assert result['segmentCount']==0 and result['viaCount']==0
 panel.update(status='Native traces removed',connection='0 routed segments / 0 routing vias',plan='Next: open the isolated input with all old pours removed',checks=f"{result['pourCount']} original pour outlines remain here.\nThe clean planning input contains zero pours.",percent=100);time.sleep(3)
finally:
 paths=[]
 for name,r in records:
  stop=invoke('desktop_record_window_stop',{'recordingId':r['recordingId']});(TAKE/(name+'-stop.json')).write_text(json.dumps(stop,indent=2));paths.append(stop['path'])
 if paths:invoke('pull_file',{'filePaths':paths,'saveTo':str(TAKE)})