From 3ef2dd48fe995cadce53016350b3d59861afbdf5 Mon Sep 17 00:00:00 2001 From: seveibar Date: Mon, 30 Sep 2024 20:27:40 -0700 Subject: [PATCH] add errors when there's a missing footprint --- lib/components/primitive-components/Port.ts | 4 ++ lib/components/primitive-components/Trace.ts | 22 +++++++ tests/examples/example4-kicad.test.tsx | 51 +++++++++++++++ .../repros/repro2-capacitor-pin-bug.test.tsx | 64 +++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 tests/examples/example4-kicad.test.tsx create mode 100644 tests/repros/repro2-capacitor-pin-bug.test.tsx diff --git a/lib/components/primitive-components/Port.ts b/lib/components/primitive-components/Port.ts index f2e1997..6e39daa 100644 --- a/lib/components/primitive-components/Port.ts +++ b/lib/components/primitive-components/Port.ts @@ -249,4 +249,8 @@ export class Port extends PrimitiveComponent { y: newCenter.y, }) } + + _hasMatchedPcbPrimitive() { + return this.matchedComponents.some((c) => c.isPcbPrimitive) + } } diff --git a/lib/components/primitive-components/Trace.ts b/lib/components/primitive-components/Trace.ts index c37eded..9d0ecec 100644 --- a/lib/components/primitive-components/Trace.ts +++ b/lib/components/primitive-components/Trace.ts @@ -41,6 +41,7 @@ import { } from "lib/utils/selector-matching" import { tryNow } from "lib/utils/try-now" import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map" +import type { Renderable } from "../base-components/Renderable" type PcbRouteObjective = | RouteHintPoint @@ -270,6 +271,27 @@ export class Trace extends PrimitiveComponent { if (!allPortsFound) return + const portsWithoutMatchedPcbPrimitive: Port[] = [] + for (const port of ports) { + if (!port._hasMatchedPcbPrimitive()) { + portsWithoutMatchedPcbPrimitive.push(port) + } + } + + if (portsWithoutMatchedPcbPrimitive.length > 0) { + db.pcb_trace_error.insert({ + error_type: "pcb_trace_error", + source_trace_id: this.source_trace_id!, + message: `Some ports did not have a matching PCB primitive (e.g. a pad or plated hole), this can happen if a footprint is missing. As a result, ${this} wasn't routed. Missing ports: ${portsWithoutMatchedPcbPrimitive.map((p) => p.getString()).join(", ")}`, + pcb_trace_id: this.pcb_trace_id!, + pcb_component_ids: [], + pcb_port_ids: portsWithoutMatchedPcbPrimitive + .map((p) => p.pcb_port_id!) + .filter(Boolean), + }) + return + } + const nets = this._findConnectedNets().netsWithSelectors if (ports.length === 0 && nets.length === 2) { diff --git a/tests/examples/example4-kicad.test.tsx b/tests/examples/example4-kicad.test.tsx new file mode 100644 index 0000000..3af19f8 --- /dev/null +++ b/tests/examples/example4-kicad.test.tsx @@ -0,0 +1,51 @@ +import { it, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +it("example 4: kicad theme demo", async () => { + const { project, logSoup } = getTestFixture() + + project.add( + + + + + + + , + ) + + project.render() +}) diff --git a/tests/repros/repro2-capacitor-pin-bug.test.tsx b/tests/repros/repro2-capacitor-pin-bug.test.tsx new file mode 100644 index 0000000..5a425bc --- /dev/null +++ b/tests/repros/repro2-capacitor-pin-bug.test.tsx @@ -0,0 +1,64 @@ +import { expect, test } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +test("capacitor connection not working", async () => { + const { circuit } = getTestFixture() + + const BlinkingLedWith555Timer = () => ( + + + + + + + + + + + + + + + + + + + ) + + circuit.add() + + circuit.render() + + const errors = circuit.db.pcb_trace_error.list() + + expect(errors.map((e) => e.message).join("\n\n")).toContain( + "Some ports did not have a matching PCB primitive", + ) +})