Skip to content

Commit

Permalink
implemented silkscreen path
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiboSoftwareDev committed Oct 17, 2024
1 parent a85a05e commit 59fda24
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
PcbVia,
PcbHole,
PcbSolderPaste,
PcbSilkscreenPath,
} from "circuit-json"
import stableStringify from "fast-json-stable-stringify"
import type { AnyGerberCommand } from "../any_gerber_command"
Expand Down Expand Up @@ -103,6 +104,18 @@ export const getApertureConfigFromPcbSmtpad = (
throw new Error(`Unsupported shape ${(elm as any).shape}`)
}

export const getApertureConfigFromPcbSilkscreenPath = (
elm: PcbSilkscreenPath,
): ApertureTemplateConfig => {
if ("stroke_width" in elm) {
return {
standard_template_code: "C",
diameter: elm.stroke_width,
}
}
throw new Error(`Provide stroke_width for: ${elm as any}`)
}

export const getApertureConfigFromPcbSolderPaste = (
elm: PcbSolderPaste,
): ApertureTemplateConfig => {
Expand Down Expand Up @@ -204,7 +217,8 @@ function getAllApertureTemplateConfigsForLayer(
else console.warn("NOT IMPLEMENTED: drawing gerber for non circle holes")
} else if (elm.type === "pcb_via") {
addConfigIfNew(getApertureConfigFromPcbVia(elm))
}
} else if (elm.type === "pcb_silkscreen_path")
addConfigIfNew(getApertureConfigFromPcbSilkscreenPath(elm))
}

return configs
Expand Down
38 changes: 36 additions & 2 deletions src/gerber/convert-soup-to-gerber-commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
defineAperturesForLayer,
getApertureConfigFromCirclePcbHole,
getApertureConfigFromCirclePcbPlatedHole,
getApertureConfigFromPcbSilkscreenPath,
getApertureConfigFromPcbSmtpad,
getApertureConfigFromPcbSolderPaste,
getApertureConfigFromPcbVia,
Expand All @@ -27,7 +28,10 @@ export const convertSoupToGerberCommands = (
layer: "top",
layer_type: "copper",
}),
F_SilkScreen: [],
F_SilkScreen: getCommandHeaders({
layer: "top",
layer_type: "silkscreen",
}),
F_Mask: getCommandHeaders({
layer: "top",
layer_type: "soldermask",
Expand All @@ -40,7 +44,10 @@ export const convertSoupToGerberCommands = (
layer: "bottom",
layer_type: "copper",
}),
B_SilkScreen: [],
B_SilkScreen: getCommandHeaders({
layer: "bottom",
layer_type: "silkscreen",
}),
B_Mask: getCommandHeaders({
layer: "bottom",
layer_type: "soldermask",
Expand All @@ -61,6 +68,8 @@ export const convertSoupToGerberCommands = (
"B_Mask",
"F_Paste",
"B_Paste",
"F_SilkScreen",
"B_SilkScreen",
] as const) {
const glayer = glayers[glayer_name]
// defineCommonMacros(glayer)
Expand Down Expand Up @@ -113,6 +122,31 @@ export const convertSoupToGerberCommands = (
}
}
}
} else if (element.type === "pcb_silkscreen_path") {
if (element.layer === layer) {
const glayer = glayers[getGerberLayerName(layer, "silkscreen")]
const apertureConfig = getApertureConfigFromPcbSilkscreenPath(element)
const gerber = gerberBuilder().add("select_aperture", {
aperture_number: findApertureNumber(glayer, apertureConfig),
})
// Move to the first point
if (element.route.length > 0) {
gerber.add("move_operation", {
x: element.route[0].x,
y: mfy(element.route[0].y),
})
}

// Plot lines to subsequent points
for (let i = 1; i < element.route.length; i++) {
gerber.add("plot_operation", {
x: element.route[i].x,
y: mfy(element.route[i].y),
})
}

glayer.push(...gerber.build())
}
} else if (element.type === "pcb_smtpad") {
if (element.layer === layer) {
for (const glayer of [
Expand Down
Loading

0 comments on commit 59fda24

Please sign in to comment.