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

scripts/associate-coil-copper.mjs

import fs from 'node:fs';
const file='dist/index/circuit.json';
const a=JSON.parse(fs.readFileSync(file,'utf8'));
if(a.some(e=>e.type.endsWith("_error")))throw Error("Refusing export normalization: recorded circuit errors");
const coils=a.filter(e=>e.type==='pcb_trace'&&e.pcb_component_id&&e.route.length>40);
if(coils.length!==4)throw Error('Expected four preserved sensing spirals');
for(const coil of coils){
 const pc=a.find(e=>e.type==='pcb_component'&&e.pcb_component_id===coil.pcb_component_id);
 const sc=a.find(e=>e.type==='source_component'&&e.source_component_id===pc.source_component_id);
 if(!/^L[1-4]$/.test(sc.name))throw Error('Unexpected copper owner');
 const port=a.find(e=>e.type==='source_port'&&e.source_component_id===sc.source_component_id&&e.pin_number===1);
 if(!port)throw Error('No inductor pin 1');
 const trace=a.find(e=>e.type==='source_trace'&&e.connected_source_port_ids?.includes(port.source_port_id));
 if(!trace)throw Error('No source trace for inductor');
 // Metadata only, AFTER routing. Feeding this back into auto-routing can replace
 // intentional winding geometry. Preserve original copper coordinates byte-for-byte.
 coil.source_trace_id=trace.source_trace_id;
}
fs.writeFileSync('dist/metal-touch-panel.circuit.json',JSON.stringify(a,null,2));
console.log('Associated four footprint copper paths with their source nets; no geometry changed.');