from build123d import *
import importlib.machinery,importlib.util,math,json,pathlib
base=pathlib.Path('/root/work/current-ui'); prev=pathlib.Path('/root/work/carrier-parent')
loader=importlib.machinery.SourceFileLoader('bezel',str(base/'bezel-candidate.build123d')); spec=importlib.util.spec_from_loader('bezel',loader); mod=importlib.util.module_from_spec(spec); loader.exec_module(mod)
shape=mod.result
th=math.degrees(math.atan2(83,35)); bezel=Pos(0,-57.5,61.5+0.68468)*Rot(th,0,0)*Pos(-25,0,1.63)*shape
scene=json.loads((prev/'parent-scene-snapshot.json').read_text())['models']
names=['front panel v1','roof panel v2','left frame v1','right frame v1','front strip v1','left panel v1','right panel v1']
def placed(s,m):
 if not m['zIsUp']: s=s.rotate(Axis.X,90)
 for ax,k in [(Axis.Z,'z'),(Axis.Y,'y'),(Axis.X,'x')]:
  if m['rotation'][k]:s=s.rotate(ax,math.degrees(m['rotation'][k]))
 p=m['position']; return s.translate((1000*p['x'],1000*p['y'],1000*p['z']))
rows=[]
for name in names:
 m=next(v for v in scene if v['name']==name); fn=m['key'].split('/')[-1]+'.step'; s=placed(import_step(prev/fn),m); c=bezel.intersect(s); v=0 if c is None else c.volume
 rows.append({'model':name,'distance_mm':bezel.distance_to(s),'overlap_mm3':v})
report={'scope':'bezel vs listed prior scene shell only; excludes new controls, clips, other components, tolerance and adhesive fit','outer_mm':[42,30,2], 'opening_mm':[30,22], 'area_mm2':600,'bezel_installed_panel_datum_mm':[-25,0,1.63], 'scene_z_offset_mm':0.68468,'overlap_check':rows}
(base/'bezel-check.json').write_text(json.dumps(report,indent=2)); export_step(shape,str(base/'bezel-candidate.step')); print(json.dumps(report,indent=2))
