Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented silkscreen path #22

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading