Skip to content

Commit

Permalink
implemented pcb_solder_paste (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiboSoftwareDev authored Oct 6, 2024
1 parent 458adbf commit 6ce180e
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 47 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@tscircuit/core": "^0.0.98",
"@tscircuit/core": "^0.0.102",
"@types/bun": "^1.1.8",
"@types/node": "^22.5.2",
"@types/react": "^18.3.11",
Expand All @@ -26,7 +26,7 @@
"typescript": "^5.0.0"
},
"dependencies": {
"circuit-json": "^0.0.82",
"circuit-json": "^0.0.83",
"fast-json-stable-stringify": "^2.1.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
PCBSMTPad,
PcbVia,
PcbHole,
PcbSolderPaste,
} from "circuit-json"
import stableStringify from "fast-json-stable-stringify"
import type { AnyGerberCommand } from "../any_gerber_command"
Expand Down Expand Up @@ -101,6 +102,26 @@ export const getApertureConfigFromPcbSmtpad = (
}
throw new Error(`Unsupported shape ${(elm as any).shape}`)
}

export const getApertureConfigFromPcbSolderPaste = (
elm: PcbSolderPaste,
): ApertureTemplateConfig => {
if (elm.shape === "rect") {
return {
standard_template_code: "R",
x_size: elm.width,
y_size: elm.height,
}
}
if (elm.shape === "circle") {
return {
standard_template_code: "C",
diameter: elm.radius * 2,
}
}
throw new Error(`Unsupported shape ${(elm as any).shape}`)
}

export const getApertureConfigFromCirclePcbPlatedHole = (
elm: PCBPlatedHole,
): ApertureTemplateConfig => {
Expand Down Expand Up @@ -163,6 +184,10 @@ function getAllApertureTemplateConfigsForLayer(
if (elm.layer === layer) {
addConfigIfNew(getApertureConfigFromPcbSmtpad(elm))
}
} else if (elm.type === "pcb_solder_paste") {
if (elm.layer === layer) {
addConfigIfNew(getApertureConfigFromPcbSolderPaste(elm))
}
} else if (elm.type === "pcb_plated_hole") {
if (elm.layers.includes(layer)) {
if (elm.shape === "circle") {
Expand Down
36 changes: 33 additions & 3 deletions src/gerber/convert-soup-to-gerber-commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getApertureConfigFromCirclePcbHole,
getApertureConfigFromCirclePcbPlatedHole,
getApertureConfigFromPcbSmtpad,
getApertureConfigFromPcbSolderPaste,
getApertureConfigFromPcbVia,
} from "./defineAperturesForLayer"
import { findApertureNumber } from "./findApertureNumber"
Expand All @@ -31,7 +32,10 @@ export const convertSoupToGerberCommands = (
layer: "top",
layer_type: "soldermask",
}),
F_Paste: [],
F_Paste: getCommandHeaders({
layer: "top",
layer_type: "paste",
}),
B_Cu: getCommandHeaders({
layer: "bottom",
layer_type: "copper",
Expand All @@ -41,13 +45,23 @@ export const convertSoupToGerberCommands = (
layer: "bottom",
layer_type: "soldermask",
}),
B_Paste: [],
B_Paste: getCommandHeaders({
layer: "bottom",
layer_type: "paste",
}),
Edge_Cuts: getCommandHeaders({
layer: "edgecut",
}),
}

for (const glayer_name of ["F_Cu", "B_Cu", "F_Mask", "B_Mask"] as const) {
for (const glayer_name of [
"F_Cu",
"B_Cu",
"F_Mask",
"B_Mask",
"F_Paste",
"B_Paste",
] as const) {
const glayer = glayers[glayer_name]
// defineCommonMacros(glayer)
defineAperturesForLayer({
Expand Down Expand Up @@ -118,6 +132,22 @@ export const convertSoupToGerberCommands = (
)
}
}
} else if (element.type === "pcb_solder_paste") {
if (element.layer === layer) {
for (const glayer of [glayers[getGerberLayerName(layer, "paste")]]) {
glayer.push(
...gerberBuilder()
.add("select_aperture", {
aperture_number: findApertureNumber(
glayer,
getApertureConfigFromPcbSolderPaste(element),
),
})
.add("flash_operation", { x: element.x, y: mfy(element.y) })
.build(),
)
}
}
} else if (element.type === "pcb_plated_hole") {
if (element.layers.includes(layer as any)) {
for (const glayer of [
Expand Down
14 changes: 7 additions & 7 deletions tests/gerber/__snapshots__/simple1-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__/simple1-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.
Loading

0 comments on commit 6ce180e

Please sign in to comment.