Skip to content

Commit

Permalink
pcb_via now appears in the copper layer (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiboSoftwareDev authored Oct 2, 2024
1 parent 7c4ea98 commit 6c62504
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import type { PCBHole, LayerRef, PCBPlatedHole, PCBSMTPad } from "circuit-json"
import type {
PCBHole,
LayerRef,
PCBPlatedHole,
PCBSMTPad,
PcbVia,
PcbHole,
} from "circuit-json"
import stableStringify from "fast-json-stable-stringify"
import type { AnyGerberCommand } from "../any_gerber_command"
import type { ApertureTemplateConfig } from "../commands/define_aperture_template"
Expand Down Expand Up @@ -109,7 +116,7 @@ export const getApertureConfigFromCirclePcbPlatedHole = (
}

export const getApertureConfigFromCirclePcbHole = (
elm: PCBHole,
elm: PcbHole,
): ApertureTemplateConfig => {
if (!("hole_diameter" in elm)) {
throw new Error(
Expand All @@ -122,6 +129,20 @@ export const getApertureConfigFromCirclePcbHole = (
}
}

export const getApertureConfigFromPcbVia = (
elm: PcbVia,
): ApertureTemplateConfig => {
if (!("outer_diameter" in elm)) {
throw new Error(
"outer_diameter not specified in getApertureConfigFromPcbVia",
)
}
return {
standard_template_code: "C",
diameter: elm.outer_diameter,
}
}

function getAllApertureTemplateConfigsForLayer(
soup: AnyCircuitElement[],
layer: "top" | "bottom",
Expand Down Expand Up @@ -156,6 +177,8 @@ function getAllApertureTemplateConfigsForLayer(
if (elm.hole_shape === "circle")
addConfigIfNew(getApertureConfigFromCirclePcbHole(elm))
else console.warn("NOT IMPLEMENTED: drawing gerber for non circle holes")
} else if (elm.type === "pcb_via") {
addConfigIfNew(getApertureConfigFromPcbVia(elm))
}
}

Expand Down
17 changes: 17 additions & 0 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,
getApertureConfigFromPcbVia,
} from "./defineAperturesForLayer"
import { findApertureNumber } from "./findApertureNumber"
import { getCommandHeaders } from "./getCommandHeaders"
Expand Down Expand Up @@ -166,6 +167,22 @@ export const convertSoupToGerberCommands = (
)
}
}
} else if (element.type === "pcb_via") {
if (element.layers.includes(layer as any)) {
for (const glayer of [glayers[getGerberLayerName(layer, "copper")]]) {
glayer.push(
...gerberBuilder()
.add("select_aperture", {
aperture_number: findApertureNumber(
glayer,
getApertureConfigFromPcbVia(element),
),
})
.add("flash_operation", { x: element.x, y: mfy(element.y) })
.build(),
)
}
}
} else if (element.type === "pcb_board" && layer === "edgecut") {
const glayer = glayers.Edge_Cuts
const { width, height, center, outline } = element
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.
14 changes: 7 additions & 7 deletions tests/gerber/__snapshots__/simple2-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__/simple2-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.

0 comments on commit 6c62504

Please sign in to comment.