Skip to content

Commit 8238c67

Browse files
committed
fix footprint pcbx/pcby
1 parent 13a6a61 commit 8238c67

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

cli/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ program
6565
const betterEasy = EasyEdaJsonSchema.parse(easyEdaJson)
6666
await fs.writeFile(options.output, JSON.stringify(betterEasy, null, 2))
6767
console.log(`Saved better EasyEDA JSON: ${options.output}`)
68-
} else if (options.output.endsWith(".ts")) {
68+
} else if (
69+
options.output.endsWith(".tsx") ||
70+
options.output.endsWith(".ts")
71+
) {
6972
const tsComp = convertRawEasyToTs(easyEdaJson)
7073
await fs.writeFile(options.output, tsComp)
7174
console.log(`Saved TypeScript component: ${options.output}`)

lib/generate-footprint-tsx.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,37 @@ export const generateFootprintTsx = (easyEdaJson: EasyEdaJson): string => {
77
(shape): shape is z.infer<typeof PadSchema> => shape.type === "PAD"
88
)
99

10+
// Calculate the center point of all pads
11+
const minX = Math.min(...pads.map((pad) => pad.center.x))
12+
const maxX = Math.max(...pads.map((pad) => pad.center.x))
13+
const minY = Math.min(...pads.map((pad) => pad.center.y))
14+
const maxY = Math.max(...pads.map((pad) => pad.center.y))
15+
16+
const centerX = (minX + maxX) / 2
17+
const centerY = (minY + maxY) / 2
18+
1019
const footprintElements = pads.map((pad) => {
1120
const { center, width, height, holeRadius, number } = pad
1221
const isPlatedHole = holeRadius !== undefined && holeRadius > 0
1322

23+
// Normalize the position by subtracting the center point
24+
const normalizedX = center.x - centerX
25+
const normalizedY = center.y - centerY
26+
1427
if (isPlatedHole) {
1528
return `
1629
<platedhole
17-
x="${center.x}mm"
18-
y="${center.y}mm"
30+
pcbX="${normalizedX.toFixed(2)}mm"
31+
pcbY="${normalizedY.toFixed(2)}mm"
1932
hole_diameter="${holeRadius * 2}mm"
2033
outer_diameter="${width}mm"
2134
port_hints={["${number}"]}
2235
/>`
2336
} else {
2437
return `
2538
<smtpad
26-
x="${center.x}mm"
27-
y="${center.y}mm"
39+
pcbX="${normalizedX.toFixed(2)}mm"
40+
pcbY="${normalizedY.toFixed(2)}mm"
2841
width="${width}mm"
2942
height="${height}mm"
3043
shape="rect"

0 commit comments

Comments
 (0)