Skip to content

Commit

Permalink
fix footprint pcbx/pcby
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Jul 5, 2024
1 parent 13a6a61 commit 8238c67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ program
const betterEasy = EasyEdaJsonSchema.parse(easyEdaJson)
await fs.writeFile(options.output, JSON.stringify(betterEasy, null, 2))
console.log(`Saved better EasyEDA JSON: ${options.output}`)
} else if (options.output.endsWith(".ts")) {
} else if (
options.output.endsWith(".tsx") ||
options.output.endsWith(".ts")
) {
const tsComp = convertRawEasyToTs(easyEdaJson)
await fs.writeFile(options.output, tsComp)
console.log(`Saved TypeScript component: ${options.output}`)
Expand Down
21 changes: 17 additions & 4 deletions lib/generate-footprint-tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,37 @@ export const generateFootprintTsx = (easyEdaJson: EasyEdaJson): string => {
(shape): shape is z.infer<typeof PadSchema> => shape.type === "PAD"
)

// Calculate the center point of all pads
const minX = Math.min(...pads.map((pad) => pad.center.x))
const maxX = Math.max(...pads.map((pad) => pad.center.x))
const minY = Math.min(...pads.map((pad) => pad.center.y))
const maxY = Math.max(...pads.map((pad) => pad.center.y))

const centerX = (minX + maxX) / 2
const centerY = (minY + maxY) / 2

const footprintElements = pads.map((pad) => {
const { center, width, height, holeRadius, number } = pad
const isPlatedHole = holeRadius !== undefined && holeRadius > 0

// Normalize the position by subtracting the center point
const normalizedX = center.x - centerX
const normalizedY = center.y - centerY

if (isPlatedHole) {
return `
<platedhole
x="${center.x}mm"
y="${center.y}mm"
pcbX="${normalizedX.toFixed(2)}mm"
pcbY="${normalizedY.toFixed(2)}mm"
hole_diameter="${holeRadius * 2}mm"
outer_diameter="${width}mm"
port_hints={["${number}"]}
/>`
} else {
return `
<smtpad
x="${center.x}mm"
y="${center.y}mm"
pcbX="${normalizedX.toFixed(2)}mm"
pcbY="${normalizedY.toFixed(2)}mm"
width="${width}mm"
height="${height}mm"
shape="rect"
Expand Down

0 comments on commit 8238c67

Please sign in to comment.