Skip to content

Commit 43fc7e7

Browse files
authored
Add support for plated hole shape circular_hole_with_rect_pad (#111)
* Add support for plated hole shape `circular_hole_with_rect_pad` * method name update
1 parent ad32eb7 commit 43fc7e7

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

lib/dsn-pcb/circuit-json-to-dsn-json/process-plated-holes.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
import {
99
createCircularPadstack,
1010
createOvalPadstack,
11+
createCircularHoleRectangularPadstack,
1112
} from "lib/utils/create-padstack"
1213
import { getFootprintName } from "lib/utils/get-footprint-name"
1314
import { getPadstackName } from "lib/utils/get-padstack-name"
@@ -115,6 +116,31 @@ export function processPlatedHoles(
115116
processedPadstacks.add(padstackName)
116117
}
117118
}
119+
// Handle circular hole with rectangular pad shape
120+
else if (hole.shape === "circular_hole_with_rect_pad") {
121+
const padstackName = getPadstackName({
122+
shape: "rect",
123+
width: hole.rect_pad_width * 1000,
124+
height: hole.rect_pad_height * 1000,
125+
layer: "all",
126+
})
127+
128+
if (!processedPadstacks.has(padstackName)) {
129+
const padOuterWidthInUm = Math.round(hole.rect_pad_width * 1000)
130+
const padOuterHeightInUm = Math.round(hole.rect_pad_height * 1000)
131+
const holeDiameterInUm = Math.round(hole.hole_diameter * 1000)
132+
133+
pcb.library.padstacks.push(
134+
createCircularHoleRectangularPadstack(
135+
padstackName,
136+
padOuterWidthInUm,
137+
padOuterHeightInUm,
138+
holeDiameterInUm,
139+
),
140+
)
141+
processedPadstacks.add(padstackName)
142+
}
143+
}
118144
}
119145

120146
// Find existing image and add plated hole pins
@@ -184,6 +210,31 @@ export function processPlatedHoles(
184210
x: (Number(hole.x.toFixed(3)) - pcbComponent.center.x) * 1000,
185211
y: (Number(hole.y.toFixed(3)) - pcbComponent.center.y) * 1000,
186212
}
213+
// Only return pin if it doesn't already exist in the image
214+
return !existingImage.pins.some(
215+
(existingPin) =>
216+
existingPin.x === pin.x &&
217+
existingPin.y === pin.y &&
218+
existingPin.padstack_name === pin.padstack_name,
219+
)
220+
? pin
221+
: undefined
222+
} else if (hole.shape === "circular_hole_with_rect_pad") {
223+
const pin = {
224+
padstack_name: getPadstackName({
225+
shape: "rect",
226+
width: hole.rect_pad_width * 1000,
227+
height: hole.rect_pad_height * 1000,
228+
layer: "all",
229+
}),
230+
pin_number:
231+
sourcePort?.port_hints?.find(
232+
(hint) => !Number.isNaN(Number(hint)),
233+
) || 1,
234+
x: (Number(hole.x.toFixed(3)) - pcbComponent.center.x) * 1000,
235+
y: (Number(hole.y.toFixed(3)) - pcbComponent.center.y) * 1000,
236+
}
237+
187238
// Only return pin if it doesn't already exist in the image
188239
return !existingImage.pins.some(
189240
(existingPin) =>

lib/utils/create-padstack.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,50 @@ export function createRectangularPadstack(
102102
attach: "off",
103103
}
104104
}
105+
106+
export function createCircularHoleRectangularPadstack(
107+
name: string,
108+
outerWidth: number,
109+
outerHeight: number,
110+
holeDiameter: number,
111+
): Padstack {
112+
const halfWidth = outerWidth / 2
113+
const halfHeight = outerHeight / 2
114+
115+
// Define the rectangle polygon once so we can reuse for both layers
116+
const rectPolygon = [
117+
-halfWidth,
118+
halfHeight, // Top-left
119+
halfWidth,
120+
halfHeight, // Top-right
121+
halfWidth,
122+
-halfHeight, // Bottom-right
123+
-halfWidth,
124+
-halfHeight, // Bottom-left
125+
-halfWidth,
126+
halfHeight, // Close the polygon
127+
]
128+
129+
return {
130+
name,
131+
shapes: [
132+
{
133+
shapeType: "polygon",
134+
layer: "F.Cu",
135+
width: 0,
136+
coordinates: rectPolygon,
137+
},
138+
{
139+
shapeType: "polygon",
140+
layer: "B.Cu",
141+
width: 0,
142+
coordinates: rectPolygon,
143+
},
144+
],
145+
hole: {
146+
shape: "circle",
147+
diameter: holeDiameter,
148+
},
149+
attach: "off",
150+
}
151+
}

0 commit comments

Comments
 (0)