Skip to content

Commit

Permalink
Merge pull request #165 from tscircuit/trace-layer-fix
Browse files Browse the repository at this point in the history
trace layer fix for explicitly defined smtpads
  • Loading branch information
seveibar authored Oct 15, 2024
2 parents fbcb343 + c304642 commit c6d35ce
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/components/base-components/PrimitiveComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions tests/components/normal-components/chip-layer-trace-bug.test.tsx
Original file line number Diff line number Diff line change
@@ -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 }) => (
<group>
<chip {...props} name={name} layer="bottom" />
</group>
)

test("chip with flipped layer should have traces on correct layer", async () => {
const { circuit } = getTestFixture()

circuit.add(
<board width="20mm" height="20mm">
<FlippedChip
name="U1"
footprint={
<footprint>
<smtpad
shape="rect"
width="1mm"
height="1mm"
pcbX={-2}
pcbY={0}
portHints={["1"]}
/>
<smtpad
shape="rect"
width="1mm"
height="1mm"
pcbX={2}
pcbY={0}
portHints={["2"]}
/>
</footprint>
}
pcbX={0}
pcbY={0}
/>
<resistor
name="R1"
resistance="10k"
footprint="0402"
pcbX={-5}
pcbY={0}
/>
<trace from=".R1 > .pin2" to=".U1 > .1" />
</board>,
)

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")
})

0 comments on commit c6d35ce

Please sign in to comment.