Skip to content

Create Solder Paste Layers/Gerber Files #29

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
19 changes: 18 additions & 1 deletion docs/CIRCUIT_JSON_PCB_OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,24 @@ export interface PcbPlatedHoleOval {
pcb_plated_hole_id: string
}

export type PcbPlatedHole = PcbPlatedHoleCircle | PcbPlatedHoleOval
export interface PcbHoleCircularWithRectPad {
type: "pcb_plated_hole"
shape: "circular_hole_with_rect_pad"
hole_shape: "circle"
pad_shape: "rect"
hole_diameter: number
rect_pad_width: number
rect_pad_height: number
x: Distance
y: Distance
layers: LayerRef[]
port_hints?: string[]
pcb_component_id?: string
pcb_port_id?: string
pcb_plated_hole_id: string
}

export type PcbPlatedHole = PcbPlatedHoleCircle | PcbPlatedHoleOval | PcbHoleCircularWithRectPad

export interface PcbFabricationNoteText {
type: "pcb_fabrication_note_text"
Expand Down
7 changes: 7 additions & 0 deletions tests/gerber/__snapshots__/paste-layer-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.
7 changes: 7 additions & 0 deletions tests/gerber/__snapshots__/paste-layer-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.
83 changes: 83 additions & 0 deletions tests/gerber/generate-gerber-with-paste.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { test, expect } from "bun:test"
import { convertSoupToGerberCommands } from "src/gerber/convert-soup-to-gerber-commands"
import {
convertSoupToExcellonDrillCommands,
stringifyExcellonDrill,
} from "src/excellon-drill"
import { stringifyGerberCommandLayers } from "src/gerber/stringify-gerber"
import { maybeOutputGerber } from "tests/fixtures/maybe-output-gerber"
import { Circuit } from "@tscircuit/core"

test("Generate gerber with paste layers", async () => {
const circuit = new Circuit()
circuit.add(
<board width={10} height={10}>
{/* Top layer pads */}
<smtpad
shape="rect"
width={1}
height={1.5}
layer="top"
pcbX={-2}
pcbY={2}
/>
<smtpad
shape="circle"
radius={0.75}
layer="top"
pcbX={2}
pcbY={2}
/>

{/* Bottom layer pads */}
<smtpad
shape="rect"
width={1.5}
height={1}
layer="bottom"
pcbX={-2}
pcbY={-2}
/>
<smtpad
shape="circle"
radius={0.5}
layer="bottom"
pcbX={2}
pcbY={-2}
/>
</board>,
)

const circuitJson = circuit.getCircuitJson()

// Generate commands
const gerber_cmds = convertSoupToGerberCommands(circuitJson)
const excellon_drill_cmds_plated = convertSoupToExcellonDrillCommands({
circuitJson: circuitJson,
is_plated: true, // Paste usually goes with plated holes
})
const excellon_drill_cmds_unplated = convertSoupToExcellonDrillCommands({
circuitJson: circuitJson,
is_plated: false,
})

// Stringify outputs
const gerberOutput = stringifyGerberCommandLayers(gerber_cmds)
const excellonDrillOutputPlated = stringifyExcellonDrill(
excellon_drill_cmds_plated,
)
const excellonDrillOutputUnplated = stringifyExcellonDrill(
excellon_drill_cmds_unplated,
)

// Optionally write files for debugging
await maybeOutputGerber(gerberOutput, excellonDrillOutputPlated)

// Assert against snapshot
// This will generate SVGs for each layer, including F_Paste and B_Paste
expect({
...gerberOutput,
"drill_plated.drl": excellonDrillOutputPlated,
"drill_unplated.drl": excellonDrillOutputUnplated,
}).toMatchGerberSnapshot(import.meta.path, "paste-layer")
})
Loading