43 行
1.9 KiB
Python
43 行
1.9 KiB
Python
import json, sys, math
|
|
import matplotlib; matplotlib.use('Agg')
|
|
import matplotlib.pyplot as plt
|
|
from matplotlib.patches import Rectangle, Circle
|
|
M=39.3701
|
|
g=json.load(open('_pcb2_route_geom.json',encoding='utf-8'))
|
|
r=json.load(open('_pcb2_sig_routes.json',encoding='utf-8'))
|
|
out=sys.argv[1]; box=[float(v) for v in sys.argv[2:6]] if len(sys.argv)>5 else None
|
|
hl=set(sys.argv[6].split(',')) if len(sys.argv)>6 else set()
|
|
col={1:'#d33',2:'#26f',15:'#8a2',16:'#a80'}
|
|
fig,ax=plt.subplots(figsize=(16,10))
|
|
for p in g['pads']:
|
|
ref,num,net,lay,x,y=p[0],p[1],p[2],p[3],p[4]/M,p[5]/M
|
|
sh=p[7] if len(p)>7 else None
|
|
c='#888' if lay==12 else col.get(lay,'#888')
|
|
if net in hl: c='#f0f'
|
|
w=h=0.6
|
|
if sh and len(sh)>=3 and isinstance(sh[1],(int,float)): w,h=sh[1]/M,sh[2]/M
|
|
rot=p[6] if len(p)>6 and isinstance(p[6],(int,float)) else 0
|
|
if rot%180==90: w,h=h,w
|
|
ax.add_patch(Rectangle((x-w/2,y-h/2),w,h,fc=c,ec='none',alpha=0.6))
|
|
if box and box[0]<=x<=box[2] and box[1]<=y<=box[3] and (box[2]-box[0])<60:
|
|
ax.text(x,y,'%s.%s\n%s'%(ref,num,net),fontsize=4,ha='center',va='center')
|
|
for v in g['vias']:
|
|
net,x,y,d=v[0],v[1]/M,v[2]/M,v[3]/M
|
|
ax.add_patch(Circle((x,y),d/2,fc='#0a0' if net=='GND' else '#000',ec='none',alpha=0.7))
|
|
for l in g['lines']:
|
|
_,net,lay,x0,y0,x1,y1,w=l
|
|
ax.plot([x0/M,x1/M],[y0/M,y1/M],color=col.get(lay,'#888'),lw=w/M*6,alpha=0.5,solid_capstyle='round')
|
|
for k,path in r.items():
|
|
net=k.split(chr(0))[0]
|
|
for a,b in zip(path,path[1:]):
|
|
if a[2]==b[2]:
|
|
ax.plot([a[0],b[0]],[a[1],b[1]],color=('#f0f' if net in hl else col.get(a[2],'#888')),lw=a[3]*6,alpha=0.9,solid_capstyle='round')
|
|
else:
|
|
ax.add_patch(Circle((a[0],a[1]),0.305,fc='#000',ec='none'))
|
|
ax.set_aspect('equal')
|
|
if box: ax.set_xlim(box[0],box[2]); ax.set_ylim(box[1],box[3])
|
|
else: ax.set_xlim(0,220); ax.set_ylim(0,135)
|
|
ax.grid(True,lw=0.2)
|
|
plt.tight_layout(); plt.savefig(out,dpi=150)
|
|
print('saved',out)
|