Skip to content

Commit 093df3c

Browse files
author
techmannih
committed
feat: implement dynamic text resolution for SilkscreenText components in footprints and add a corresponding test
1 parent e1ba8b0 commit 093df3c

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

lib/components/primitive-components/SilkscreenText.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class SilkscreenText extends PrimitiveComponent<
126126
bottom: props.knockoutPaddingBottom ?? uniformPadding,
127127
}
128128
: undefined
129-
129+
let text = this._resolveText()
130130
for (const layer of targetLayers) {
131131
const pcb_silkscreen_text = db.pcb_silkscreen_text.insert({
132132
anchor_alignment: props.anchorAlignment,
@@ -137,7 +137,7 @@ export class SilkscreenText extends PrimitiveComponent<
137137
font: props.font ?? "tscircuit2024",
138138
font_size: fontSize,
139139
layer: maybeFlipLayer(layer) as "top" | "bottom",
140-
text: normalizeTextForCircuitJson(props.text ?? ""),
140+
text: normalizeTextForCircuitJson(text),
141141
ccw_rotation: rotation,
142142
pcb_component_id: container.pcb_component_id!,
143143
subcircuit_id: subcircuit?.subcircuit_id ?? undefined,
@@ -167,7 +167,7 @@ export class SilkscreenText extends PrimitiveComponent<
167167
this.getInheritedProperty("pcbStyle")?.silkscreenFontSize ??
168168
this._footprinterFontSize ??
169169
1
170-
const text = props.text ?? ""
170+
const text = this._resolveText()
171171
const textWidth = text.length * fontSize
172172
const textHeight = fontSize
173173
return { width: textWidth * fontSize, height: textHeight * fontSize }
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { test, expect } from "bun:test"
2+
import { getTestFixture } from "tests/fixtures/get-test-fixture"
3+
4+
test("footprint text resolution", async () => {
5+
const { circuit } = getTestFixture()
6+
7+
circuit.add(
8+
<board width="10mm" height="10mm">
9+
<chip
10+
name="U1"
11+
footprint={
12+
<footprint>
13+
<silkscreentext text="{NAME}" pcbX={0} pcbY={4} />
14+
15+
<platedhole
16+
portHints={["4"]}
17+
pcbX="3.2499299999998357mm"
18+
pcbY="-2.249932000000058mm"
19+
outerDiameter="1.9999959999999999mm"
20+
holeDiameter="1.3000228mm"
21+
shape="circle"
22+
/>
23+
<platedhole
24+
portHints={["2"]}
25+
pcbX="3.2499299999998357mm"
26+
pcbY="2.249932000000058mm"
27+
outerDiameter="1.9999959999999999mm"
28+
holeDiameter="1.3000228mm"
29+
shape="circle"
30+
/>
31+
<platedhole
32+
portHints={["1"]}
33+
pcbX="-3.2499299999999494mm"
34+
pcbY="2.249932000000058mm"
35+
outerDiameter="1.9999959999999999mm"
36+
holeDiameter="1.3000228mm"
37+
shape="circle"
38+
/>
39+
<platedhole
40+
portHints={["3"]}
41+
pcbX="-3.2499299999999494mm"
42+
pcbY="-2.249932000000058mm"
43+
outerDiameter="1.9999959999999999mm"
44+
holeDiameter="1.3000228mm"
45+
shape="circle"
46+
/>
47+
<silkscreenpath
48+
route={[
49+
{ x: -2.2743160000001126, y: -2.999994000000015 },
50+
{ x: 2.274315999999999, y: -2.999994000000015 },
51+
]}
52+
/>
53+
<silkscreenpath
54+
route={[
55+
{ x: -2.999994000000129, y: 1.0999978000000965 },
56+
{ x: -2.999994000000129, y: -0.999998000000005 },
57+
]}
58+
/>
59+
<silkscreenpath
60+
route={[
61+
{ x: 3.0999937999998792, y: 1.0279888000000028 },
62+
{ x: 3.0999937999998792, y: -1.0999977999999828 },
63+
]}
64+
/>
65+
<silkscreenpath
66+
route={[
67+
{ x: -1.99999600000001, y: 2.999994000000015 },
68+
{ x: 2.274315999999999, y: 2.999994000000015 },
69+
]}
70+
/>
71+
</footprint>
72+
}
73+
schPortArrangement={{
74+
leftSide: {
75+
direction: "top-to-bottom",
76+
pins: [1, 3],
77+
},
78+
rightSide: {
79+
direction: "bottom-to-top",
80+
pins: [4, 2],
81+
},
82+
}}
83+
/>
84+
</board>,
85+
)
86+
87+
await circuit.renderUntilSettled()
88+
const circuitJson = circuit.getCircuitJson()
89+
90+
const silkscreenText = circuitJson.find(
91+
(e) => e.type === "pcb_silkscreen_text",
92+
)
93+
94+
expect(silkscreenText).toBeDefined()
95+
expect((silkscreenText as any).text).toBe("U1")
96+
// add pcbbbb snapshot test
97+
expect(circuitJson).toMatchPcbSnapshot(import.meta.path)
98+
})

0 commit comments

Comments
 (0)