From 6c62504beecee16750c5431ccd87e641db64275e Mon Sep 17 00:00:00 2001 From: Shibo Date: Wed, 2 Oct 2024 19:28:39 +0200 Subject: [PATCH] pcb_via now appears in the copper layer (#14) --- .../defineAperturesForLayer.ts | 27 +++++++++++++++++-- .../convert-soup-to-gerber-commands/index.ts | 17 ++++++++++++ .../__snapshots__/simple1-bottom.snap.svg | 14 +++++----- .../gerber/__snapshots__/simple1-top.snap.svg | 14 +++++----- .../__snapshots__/simple2-bottom.snap.svg | 14 +++++----- .../gerber/__snapshots__/simple2-top.snap.svg | 14 +++++----- 6 files changed, 70 insertions(+), 30 deletions(-) diff --git a/src/gerber/convert-soup-to-gerber-commands/defineAperturesForLayer.ts b/src/gerber/convert-soup-to-gerber-commands/defineAperturesForLayer.ts index f0b179d..02f96c3 100644 --- a/src/gerber/convert-soup-to-gerber-commands/defineAperturesForLayer.ts +++ b/src/gerber/convert-soup-to-gerber-commands/defineAperturesForLayer.ts @@ -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" @@ -109,7 +116,7 @@ export const getApertureConfigFromCirclePcbPlatedHole = ( } export const getApertureConfigFromCirclePcbHole = ( - elm: PCBHole, + elm: PcbHole, ): ApertureTemplateConfig => { if (!("hole_diameter" in elm)) { throw new Error( @@ -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", @@ -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)) } } diff --git a/src/gerber/convert-soup-to-gerber-commands/index.ts b/src/gerber/convert-soup-to-gerber-commands/index.ts index 8add5fa..1df3c90 100644 --- a/src/gerber/convert-soup-to-gerber-commands/index.ts +++ b/src/gerber/convert-soup-to-gerber-commands/index.ts @@ -7,6 +7,7 @@ import { getApertureConfigFromCirclePcbHole, getApertureConfigFromCirclePcbPlatedHole, getApertureConfigFromPcbSmtpad, + getApertureConfigFromPcbVia, } from "./defineAperturesForLayer" import { findApertureNumber } from "./findApertureNumber" import { getCommandHeaders } from "./getCommandHeaders" @@ -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 diff --git a/tests/gerber/__snapshots__/simple1-bottom.snap.svg b/tests/gerber/__snapshots__/simple1-bottom.snap.svg index d85b0bf..991aad4 100644 --- a/tests/gerber/__snapshots__/simple1-bottom.snap.svg +++ b/tests/gerber/__snapshots__/simple1-bottom.snap.svg @@ -1,7 +1,7 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/tests/gerber/__snapshots__/simple1-top.snap.svg b/tests/gerber/__snapshots__/simple1-top.snap.svg index d8c8ab2..f5e2ab7 100644 --- a/tests/gerber/__snapshots__/simple1-top.snap.svg +++ b/tests/gerber/__snapshots__/simple1-top.snap.svg @@ -1,7 +1,7 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/tests/gerber/__snapshots__/simple2-bottom.snap.svg b/tests/gerber/__snapshots__/simple2-bottom.snap.svg index f4d8fca..2d2ce57 100644 --- a/tests/gerber/__snapshots__/simple2-bottom.snap.svg +++ b/tests/gerber/__snapshots__/simple2-bottom.snap.svg @@ -1,7 +1,7 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/tests/gerber/__snapshots__/simple2-top.snap.svg b/tests/gerber/__snapshots__/simple2-top.snap.svg index 5dfbe2e..637325b 100644 --- a/tests/gerber/__snapshots__/simple2-top.snap.svg +++ b/tests/gerber/__snapshots__/simple2-top.snap.svg @@ -1,7 +1,7 @@ - \ No newline at end of file + \ No newline at end of file