main
John Lauer Screen stock TO-220 sink against board 18 without new PCB drills 2cb7065
"""Plot the current-board stock-sink envelope screen, never an exact assembly drawing."""
import json
from pathlib import Path
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle,Circle,FancyBboxPatch
P=Path(__file__).resolve().parents[1]
a=json.loads((P/'mechanical/cooling-680-body-audit.json').read_text());s=json.loads((P/'mechanical/cooling-680-screen.json').read_text());assert a['boardSha256']==s['boardSha256']
plt.style.use('dark_background');fig,ax=plt.subplots(figsize=(11,10));fig.patch.set_facecolor('#101723');ax.set_facecolor('#101723')
ax.add_patch(FancyBboxPatch((98,30),64,72,boxstyle='round,pad=0,rounding_size=2',facecolor='#123a32',edgecolor='#8fa99c',lw=2))
for r in a['rows']:
 b=r.get('boundsMm')
 if b and b[5]>=0:ax.add_patch(Rectangle((b[0],b[1]),b[3]-b[0],b[4]-b[1],facecolor='#70828d',edgecolor='#a6b0b8',alpha=.55,lw=.4))
x0,y0,x1,y1=s['sinkXY'];ax.add_patch(Rectangle((x0,y0),x1-x0,y1-y0,facecolor='#60d5cb',edgecolor='#60d5cb',alpha=.16,lw=2));ax.add_patch(Rectangle((x0,y0),x1-x0,y1-y0,fill=False,edgecolor='#60d5cb',lw=2))
for p in s['probeChecks']:
 ax.add_patch(Circle((p['x'],p['y']),2,fill=False,edgecolor='#f7ca78',lw=1.2));ax.text(p['x']+2.4,p['y']+.8,p['ref'],fontsize=8,color='#f7ca78')
hx,hy=s['existingQ1HoleXY'];ax.add_patch(Circle((hx,hy),1.75,fill=False,edgecolor='#ffffff',lw=1.8));ax.annotate('Existing Q1 hole\nNo new PCB drill proposed',xy=(hx,hy),xytext=(101,55),fontsize=10,arrowprops={'arrowstyle':'->','color':'white'},color='white')
ax.text(139,77,'Stock 680-125220\n45.974 mm square\nNominal base Z = 5.09 mm',ha='center',va='center',fontsize=11,color='#a9f2e8',bbox={'facecolor':'#101723','alpha':.85,'edgecolor':'none'})
ax.set(xlim=(93,171),ylim=(107,25),xlabel='Board X (mm)',ylabel='Board Y (mm)');ax.set_aspect('equal');ax.spines[['top','right']].set_visible(False)
fig.suptitle('Stock heatsink candidate · board 18',fontsize=20,y=.97)
fig.text(.5,.924,'91 fitted models: no bounding-box intersection  •  Probe approach circles: clear',ha='center',fontsize=11,color='#b8cecd')
fig.text(.5,.044,'ENVELOPE SCREEN ONLY — not accepted for fabrication\nFasteners, support cradle, exact contact, mating plugs and installed airflow remain unresolved.',ha='center',fontsize=11,color='#f7ca78')
fig.subplots_adjust(top=.9,bottom=.12,left=.08,right=.94)
fig.savefig(P/'mechanical/cooling-680-screen.png',dpi=160,facecolor=fig.get_facecolor())