Skip to content

Commit

Permalink
horz pill working
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Oct 25, 2024
1 parent a584732 commit dfd125c
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 34 deletions.
31 changes: 25 additions & 6 deletions src/gerber/commands/define_aperture_template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,38 @@ const standard_aperture_template_config = z.discriminatedUnion(
[circle_template, rectangle_template, obround_template, polygon_template],
)

const pill_template = z.object({
macro_name: z.literal("PILL"),
const horz_pill_template = z.object({
macro_name: z.literal("HORZPILL"),
x_size: z.number(),
y_size: z.number(),
circle_diameter: z.number(),
circle_center_offset: z.number(),
})

const vert_pill_template = z.object({
macro_name: z.literal("VERTPILL"),
x_size: z.number(),
y_size: z.number(),
circle_diameter: z.number(),
circle_center_offset: z.number(),
})

const roundrect_template = z.object({
macro_name: z.literal("ROUNDRECT"),
corner_radius: z.number(),
corner_1_x: z.number(),
corner_1_y: z.number(),
corner_2_x: z.number(),
corner_2_y: z.number(),
corner_3_x: z.number(),
corner_3_y: z.number(),
corner_4_x: z.number(),
corner_4_y: z.number(),
})

const macro_aperture_template_config = z.discriminatedUnion("macro_name", [
pill_template,
horz_pill_template,
vert_pill_template,
roundrect_template,
])

Expand All @@ -68,9 +88,8 @@ export const define_aperture_template = defineGerberCommand({
const { aperture_number, macro_name } = props
let commandString = `%ADD${aperture_number}${macro_name},`

if (macro_name === "PILL") {
// For PILL macro, we need width (x_size) and height (y_size)
commandString += `${props.x_size.toFixed(6)}X${props.y_size.toFixed(6)}`
if (macro_name === "HORZPILL" || macro_name === "VERTPILL") {
commandString += `${props.x_size.toFixed(6)}X${props.y_size.toFixed(6)}X${props.circle_diameter.toFixed(6)}X${props.circle_center_offset.toFixed(6)}`
} else if (macro_name === "ROUNDRECT") {
// Handle ROUNDRECT if needed
throw new Error("ROUNDRECT macro not implemented yet")
Expand Down
37 changes: 27 additions & 10 deletions src/gerber/convert-soup-to-gerber-commands/define-common-macros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,34 @@ export const defineCommonMacros = (glayer: Array<AnyGerberCommand>) => {
...gerberBuilder()
.add("comment", { comment: "APERTURE MACROS START" })
.add("define_macro_aperture_template", {
macro_name: "PILL",
macro_name: "HORZPILL",
template_code: `
0 Pill shape (rounded rectangle with semicircle ends)*
0 $1 = width*
0 $2 = height*
0 Center rectangle*
21,1,$1,0,0,$2-$1,0*
0 Left circle*
1,1,$1,0,-($2-$1)/2,0*
0 Right circle*
1,1,$1,0,($2-$1)/2,0*%
0 Horizontal pill (stadium) shape macro*
0 Parameters:*
0 $1 = Total width*
0 $2 = Total height*
0 $3 = Circle diameter (equal to height)*
0 $4 = Circle center offset ((width-diameter)/2)*
0 21 = Center Line(Exposure, Width, Height, Center X, Center Y, Rotation)*
0 1 = Circle(Exposure, Diameter, Center X, Center Y, Rotation)*
21,1,$1,$2,0.0,0.0,0.0*
1,1,$3,0.0-$4,0.0*
1,1,$3,$4,0.0*%
`.trim(),
})
.add("define_macro_aperture_template", {
macro_name: "VERTPILL",
template_code: `
0 Vertical pill (stadium) shape macro*
0 Parameters:*
0 $1 = Total width*
0 $2 = Total height*
0 $3 = Circle diameter (equal to width)*
0 $4 = Circle center offset ((height-diameter)/2)*
0 21 = Center Line(Exposure, Width, Height, Center X, Center Y, Rotation)*
21,1,$1,$2,0.0,0.0,0.0*
1,1,$3,0.0,0.0-$4*
1,1,$3,0.0,$4*%
`.trim(),
})
.add("define_macro_aperture_template", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,22 @@ export const getApertureConfigFromPcbPlatedHole = (
"Invalid pill shape in getApertureConfigFromPcbPlatedHole: missing dimensions",
)
}

if (elm.outer_width > elm.outer_height) {
return {
macro_name: "HORZPILL",
x_size: elm.outer_width,
y_size: elm.outer_height,
circle_diameter: Math.min(elm.outer_width, elm.outer_height),
circle_center_offset: elm.outer_width / 2,
}
}
return {
macro_name: "PILL",
macro_name: "VERTPILL",
x_size: elm.outer_width,
y_size: elm.outer_height,
circle_diameter: Math.min(elm.outer_width, elm.outer_height),
circle_center_offset: elm.outer_height / 2,
}
}
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ export const findApertureNumber = (
const trace_width = search_params.trace_width
aperture = glayer.find(
(command): command is DefineAperatureTemplateCommand =>
"standard_template_code" in command &&
command.command_code === "ADD" &&
command.standard_template_code === "C" &&
command.diameter === trace_width,
)
} else if ("standard_template_code" in search_params || "macro_name" in search_params) {
} else if (
"standard_template_code" in search_params ||
"macro_name" in search_params
) {
aperture = glayer.find(
(command): command is DefineAperatureTemplateCommand =>
command.command_code === "ADD" &&
Expand Down
14 changes: 7 additions & 7 deletions tests/gerber/__snapshots__/pill-shape-bottom.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions tests/gerber/__snapshots__/pill-shape-top.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions tests/gerber/generate-gerber-with-pill-shape.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ test("Generate gerber with pill shape", async () => {
<platedhole
shape="pill"
outerWidth={5}
outerHeight={2.5}
outerHeight={1.5}
innerWidth={4}
innerHeight={2}
innerHeight={1}
pcbX={2}
pcbY={2}
/>
<platedhole
shape="pill"
outerWidth={2}
outerHeight={5}
innerWidth={1.5}
innerHeight={4}
pcbX={-2}
pcbY={-2}
/>
</board>,
)

Expand Down

0 comments on commit dfd125c

Please sign in to comment.