hrithik18k/metal-touch-panel

A PCB autorouting wrapper that corrects footprint-trace obstacle dimensions, solves routes with a preloaded trace-graph solver, and reports completed traces or routing errors.

Version
1.0.0
License
unset
Stars
0

coil-aware-router.ts

import { AutoroutingPipelineSolver9_PreloadedTraceGraph } from '@tscircuit/capacity-autorouter'
// Local integration workaround: core currently represents footprint trace copper
// as 0.1 mm obstacles regardless of width and omits the rounded end caps.
export async function coilAwareRouter(input: any) {
  const corrected = structuredClone(input)
  for (const o of corrected.obstacles) {
    if(o.connectedTo?.some((id:string)=>/^pcb_trace_[0-3]$/.test(id))) {
      if(o.width===0.1){o.width=0.2;o.height+=0.2}
      else if(o.height===0.1){o.height=0.2;o.width+=0.2}
    }
  }
  const solver = new AutoroutingPipelineSolver9_PreloadedTraceGraph(corrected)
  const handlers: Record<string,Function[]>={}
  return {
    on(event:string,fn:Function){(handlers[event]??=[]).push(fn)},
    start(){
      try {
        solver.solve()
        if(solver.failed)throw new Error(solver.error??'Routing failed')
        for(const f of handlers.complete??[])f({traces:solver.getOutputSimpleRouteJson().traces??[]})
      } catch(error){for(const f of handlers.error??[])f({error})}
    },
    stop(){},
    getOutputSimpleRouteJson(){return solver.getOutputSimpleRouteJson()}
  }
}