ShiboSoftwareDev/linux-gameboy-advance
Restores PCB assembly metadata by assigning part numbers and 3D CAD models, removing test-point bodies, and validating top-side SMT solder-paste features without altering copper or pads.
- Version
- 1.0.17
- License
- unset
- Stars
- 0
scripts/route-drc.mjs
import fs from "node:fs"
import { runAllRoutingChecks } from "@tscircuit/checks"
const circuit = JSON.parse(fs.readFileSync("dist/index/circuit.json", "utf8"))
const cache = JSON.parse(fs.readFileSync("carrier-route-cache.json", "utf8"))
const routeFile = process.argv[2]
const traces = routeFile
? JSON.parse(fs.readFileSync(routeFile, "utf8"))
: cache.traces
if(process.argv.includes("--raised-fpc")){
const source=circuit.find((e)=>e.type==="source_component"&&e.name==="J_LCD")
const component=circuit.find((e)=>e.type==="pcb_component"&&e.source_component_id===source.source_component_id)
for(const element of circuit){
if(element.pcb_component_id===component.pcb_component_id&&typeof element.y==="number")element.y+=5
}
component.center.y+=5
}
const carrierIds = new Set(cache.traces.map((trace) => trace.pcb_trace_id))
const routeById = new Map(traces.map((trace) => [trace.pcb_trace_id, trace.route]))
const existingKeyByTrace = new Map(
circuit
.filter((element) => element.type === "pcb_via" && carrierIds.has(element.pcb_trace_id))
.map((via) => [via.pcb_trace_id, via.subcircuit_connectivity_map_key]),
)
for (const trace of circuit.filter(
(element) => element.type === "pcb_trace" && routeById.has(element.pcb_trace_id),
)) trace.route = structuredClone(routeById.get(trace.pcb_trace_id))
const withoutOldCarrierVias = circuit.filter(
(element) =>
element.type !== "pcb_copper_pour" &&
!(element.type === "pcb_via" && carrierIds.has(element.pcb_trace_id)),
)
let viaIndex = 0
for (const trace of circuit.filter(
(element) => element.type === "pcb_trace" && carrierIds.has(element.pcb_trace_id),
)) {
for (const point of trace.route.filter((point) => point.route_type === "via")) {
withoutOldCarrierVias.push({
type: "pcb_via",
pcb_via_id: `route_test_via_${viaIndex++}`,
pcb_trace_id: trace.pcb_trace_id,
x: point.x,
y: point.y,
hole_diameter: point.via_hole_diameter,
outer_diameter: point.via_diameter,
layers: ["top", "inner1", "inner2", "bottom"],
from_layer: point.from_layer,
to_layer: point.to_layer,
subcircuit_id: trace.subcircuit_id,
subcircuit_connectivity_map_key: existingKeyByTrace.get(trace.pcb_trace_id),
})
}
}
const errors = (await runAllRoutingChecks(withoutOldCarrierVias)).filter(
(element) => element.type.endsWith("_error"),
)
const counts = {}
for (const error of errors) counts[error.type] = (counts[error.type] ?? 0) + 1
console.log(JSON.stringify({ counts, total: errors.length }, null, 2))
for (const error of errors) console.log(`${error.type}: ${error.message}`,
error.type === "pcb_trace_error" ? JSON.stringify(error) : "")