Skip to content

Commit be23404

Browse files
committed
fix pushbutton externally connected pins
1 parent 8d76557 commit be23404

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

lib/components/normal-components/PushButton.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "lib/utils/constants"
88
import { NormalComponent } from "../base-components/NormalComponent/NormalComponent"
99
import { Port } from "../primitive-components/Port"
10+
import { Trace } from "../primitive-components/Trace/Trace"
1011
import { symbols } from "schematic-symbols"
1112

1213
export class PushButton extends NormalComponent<
@@ -27,6 +28,23 @@ export class PushButton extends NormalComponent<
2728
return []
2829
}
2930

31+
doInitialCreateTracesFromProps() {
32+
const { _parsedProps: props } = this
33+
34+
if (props.externallyConnectedPins) {
35+
for (const [pin1, pin2] of props.externallyConnectedPins) {
36+
this.add(
37+
new Trace({
38+
from: `${this.getSubcircuitSelector()} > port.${pin1}`,
39+
to: `${this.getSubcircuitSelector()} > port.${pin2}`,
40+
}),
41+
)
42+
}
43+
}
44+
45+
this._createTracesFromConnectionsProp()
46+
}
47+
3048
override initPorts() {
3149
super.initPorts({
3250
pinCount: 2,
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { test, expect } from "bun:test"
2+
import { getTestFixture } from "tests/fixtures/get-test-fixture"
3+
4+
test("<pushbutton /> creates traces for externally connected pins", () => {
5+
const { circuit } = getTestFixture()
6+
7+
circuit.add(
8+
<board width="20mm" height="20mm" routingDisabled>
9+
<pushbutton
10+
name="SW1"
11+
footprint="pushbutton"
12+
externallyConnectedPins={[["pin1", "pin2"]]}
13+
/>
14+
</board>,
15+
)
16+
17+
circuit.render()
18+
19+
const sourceTraces = circuit
20+
.getCircuitJson()
21+
.filter((elm) => elm.type === "source_trace")
22+
23+
expect(sourceTraces).toHaveLength(1)
24+
const sourcePortsById = new Map(
25+
circuit.db.source_port
26+
.list()
27+
.map((sourcePort) => [sourcePort.source_port_id, sourcePort]),
28+
)
29+
expect(
30+
sourceTraces[0].connected_source_port_ids.map(
31+
(sourcePortId) => sourcePortsById.get(sourcePortId)?.name,
32+
),
33+
).toEqual(["pin1", "pin2"])
34+
expect(circuit).toMatchPcbSnapshot(import.meta.path)
35+
})

0 commit comments

Comments
 (0)