seveibar/am3352-dev-board

A 324-ball TI AM3352 ARM processor with DDR3, LCD, USB, Ethernet, storage, serial, analog, clock, reset, power, and JTAG interfaces, paired with configurable JST-GH board connectors and constrained PCB routing.

Version
1.0.2
License
unset
Stars
0

scripts/clean-moved-copper.py

import json,runpy,math
from pathlib import Path
from shapely.geometry import Point,LineString
ctx=runpy.run_path('scripts/audit-copper.py');c=ctx['c'];padshape=ctx['padshape'];find=ctx['find'];ports=ctx['ports']
data=json.loads(Path('design/routed-copper.json').read_text());old=json.loads(Path('../../work/before-power-placement.json').read_text());op={p['source_port_id']:p for p in old if p['type']=='pcb_port'}
moved=[]
for p in ports.values():
 q=op.get(p['source_port_id'])
 if q and math.dist((q['x'],q['y']),(p['x'],p['y']))>.002:moved.append((q['x'],q['y']))
pads=[(padshape(p), find(ports[p['pcb_port_id']]['source_port_id']) if p.get('pcb_port_id') in ports else 'NC', [p['layer']] if p['type']=='pcb_smtpad' else ctx['layers']) for p in c if p['type'] in ['pcb_smtpad','pcb_plated_hole','pcb_hole']]
names={p['source_net_id']:p['name'] for p in c if p['type']=='source_net'};removed=0
for sid,routes in data['nets'].items():
 keep=[]
 for r in routes:
  bad=names.get(sid) in ['SW1','SW2','SW3'];via=next((p for p in r if p['route_type']=='via'),None)
  if not via and any(math.dist((p['x'],p['y']),q)<.002 for p in [r[0],r[-1]] for q in moved):bad=True
  if via:
   g=Point(via['x'],via['y']).buffer(.2);ls=ctx['layers']
  else:
   if len(r)<2:continue
   g=LineString([(p['x'],p['y']) for p in r]).buffer(r[0]['width']/2);ls=[r[0]['layer']]
  for pg,pn,pl in pads:
   if not set(ls).intersection(pl):continue
   if pn!=find(sid) and g.distance(pg)<.099:bad=True;break
   if via and pn==find(sid) and g.centroid.intersects(pg):
    if not(names.get(sid)=='GND' and abs(via['x']+23)<2 and abs(via['y']+3)<2):bad=True;break
  if bad:removed+=1
  else:keep.append(r)
 data['nets'][sid]=keep
Path('design/routed-copper.json').write_text(json.dumps(data,separators=(',',':'))+'\n');print('Removed',removed,'obsolete/colliding route records;',len(moved),'moved ports')