From c30464216f5ac56546872d9a7185739393f2924d Mon Sep 17 00:00:00 2001 From: seveibar Date: Mon, 14 Oct 2024 21:21:40 -0700 Subject: [PATCH] trace layer fix for explicitly defined smtpads --- .../base-components/PrimitiveComponent.ts | 2 +- .../chip-layer-trace-bug-pcb.snap.svg | 13 ++++ .../chip-layer-trace-bug.test.tsx | 69 +++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tests/components/normal-components/__snapshots__/chip-layer-trace-bug-pcb.snap.svg create mode 100644 tests/components/normal-components/chip-layer-trace-bug.test.tsx diff --git a/lib/components/base-components/PrimitiveComponent.ts b/lib/components/base-components/PrimitiveComponent.ts index 5dee3f9..55bf000 100644 --- a/lib/components/base-components/PrimitiveComponent.ts +++ b/lib/components/base-components/PrimitiveComponent.ts @@ -479,7 +479,7 @@ export abstract class PrimitiveComponent< getAvailablePcbLayers(): string[] { if (this.isPcbPrimitive) { const { maybeFlipLayer } = this._getPcbPrimitiveFlippedHelpers() - if ("layer" in this._parsedProps) { + if ("layer" in this._parsedProps || this.componentName === "SmtPad") { const layer = maybeFlipLayer(this._parsedProps.layer ?? "top") return [layer] } diff --git a/tests/components/normal-components/__snapshots__/chip-layer-trace-bug-pcb.snap.svg b/tests/components/normal-components/__snapshots__/chip-layer-trace-bug-pcb.snap.svg new file mode 100644 index 0000000..7d9dd42 --- /dev/null +++ b/tests/components/normal-components/__snapshots__/chip-layer-trace-bug-pcb.snap.svg @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/tests/components/normal-components/chip-layer-trace-bug.test.tsx b/tests/components/normal-components/chip-layer-trace-bug.test.tsx new file mode 100644 index 0000000..f09265d --- /dev/null +++ b/tests/components/normal-components/chip-layer-trace-bug.test.tsx @@ -0,0 +1,69 @@ +import { test, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +const FlippedChip = ({ + name, + ...props +}: { name: string; [key: string]: any }) => ( + + + +) + +test("chip with flipped layer should have traces on correct layer", async () => { + const { circuit } = getTestFixture() + + circuit.add( + + + + + + } + pcbX={0} + pcbY={0} + /> + + + , + ) + + circuit.render() + + const traces = circuit.db.pcb_trace.list() + + const routeLayers = traces[0].route.flatMap((point) => { + if ("layer" in point) { + return [point.layer] + } + return [point.to_layer, point.from_layer] + }) + + expect(circuit).toMatchPcbSnapshot(import.meta.path) + + expect(routeLayers).toContain("bottom") + expect(routeLayers).toContain("top") +})