Skip to content

Commit

Permalink
Merge pull request #5 from anas-sarkez/main
Browse files Browse the repository at this point in the history
Fixed multilayer SVG gerber layers issue
  • Loading branch information
AnasSarkiz authored Sep 3, 2024
2 parents d8d6124 + 434388a commit 4fc4c70
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@ dist
# Finder (MacOS) folder config
.DS_Store

.vscode
.vscode
# yalc
.yalc
yalc.lock
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@tscircuit/soup": "^0.0.60",
"@types/bun": "^1.1.8",
"@types/node": "^22.5.2",
"bun-match-svg": "^0.0.2",
"bun-match-svg": "^0.0.3",
"gerber-to-svg": "^4.2.8",
"pcb-stackup": "^4.2.8",
"tsup": "^8.2.4"
Expand Down
7 changes: 7 additions & 0 deletions tests/__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.
7 changes: 7 additions & 0 deletions tests/__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.
7 changes: 0 additions & 7 deletions tests/__snapshots__/simple1.snap.svg

This file was deleted.

7 changes: 7 additions & 0 deletions tests/__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.
7 changes: 7 additions & 0 deletions tests/__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.
7 changes: 0 additions & 7 deletions tests/__snapshots__/simple2.snap.svg

This file was deleted.

20 changes: 14 additions & 6 deletions tests/fixtures/preload.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import "bun-match-svg"
import { expect } from "bun:test"
import pcbStackup from "pcb-stackup"
import pcbStackup, { type Stackup } from "pcb-stackup"
import { Readable } from "stream"

async function toMatchGerberSnapshot(
this: any,
gerberOutput: Record<string, string>,
Expand All @@ -17,11 +16,20 @@ async function toMatchGerberSnapshot(

try {
const stackup = await pcbStackup(layers)
const svgArray: string[] = []
const svgNames: string[] = []

// We'll use the top layer SVG for comparison, but you could choose bottom or both
const svg = stackup.top.svg

return expect(svg).toMatchSvgSnapshot(testPathOriginal, svgName)
for (const item of Object.keys(stackup!) as Array<keyof Stackup>) {
const layer = stackup[item] as { svg: string };
if (layer.svg) {
svgArray.push(layer.svg)
svgNames.push(`${svgName}-${item}`)
}
}
return expect(svgArray).toMatchMultipleSvgSnapshots(
testPathOriginal,
svgNames,
)
} catch (error) {
throw new Error(`Failed to generate PCB stackup: ${error}`)
}
Expand Down
1 change: 0 additions & 1 deletion tests/generate-board-outline-gerber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from "src/stringify-gerber"
import { maybeOutputGerber } from "tests/fixtures/maybe-output-gerber"
import gerberToSvg from "gerber-to-svg"

// If you're trying to test this, I would recommend opening up Kicad's Gerber
// Viewer and loading in the files from the generated directory "gerber-output"
// that's produced if OUTPUT_GERBER=1 when you do `npx ava ./tests/gerber/generate-gerber-with-trace.test.ts`
Expand Down
19 changes: 12 additions & 7 deletions tests/generate-gerber-with-basic-elements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
stringifyGerberCommands,
} from "src/stringify-gerber"
import { maybeOutputGerber } from "tests/fixtures/maybe-output-gerber"

// If you're trying to test this, I would recommend opening up Kicad's Gerber
// Viewer and loading in the files from the generated directory "gerber-output"
// that's produced if OUTPUT_GERBER=1 when you do `npx ava ./tests/gerber/generate-gerber-with-trace.test.ts`
Expand Down Expand Up @@ -70,16 +69,22 @@ test("Generate simple gerber with basic elements", async () => {
outer_diameter: 2,
},
])
const fu_cp = stringifyGerberCommands(gerber_cmds.F_Cu)
const edgecut_gerber = stringifyGerberCommands(gerber_cmds.Edge_Cuts)
// console.log("Gerber")
// console.log("----------------------------------------------")
// console.log(fu_cp)
// console.log(stringifyGerberCommands(gerber_cmds.B_Mask))
// console.log(edgecut_gerber)

// TODO parse gerber to check for correctness
const gerbers = stringifyGerberCommandLayers(gerber_cmds)

await maybeOutputGerber(gerbers)
const gerberOutput = stringifyGerberCommandLayers(gerber_cmds)

await maybeOutputGerber(gerberOutput)

expect(gerberOutput).toMatchGerberSnapshot(import.meta.path, "simple2")

// gerberToSvg(gerberOutput.Edge_Cuts, {}, (err, svg) => {
// expect(svg).toMatchSvgSnapshot(import.meta.path, "gerber-edge-cuts")
// })

expect(gerbers).toMatchGerberSnapshot(import.meta.path, "simple2")
// render(
})

0 comments on commit 4fc4c70

Please sign in to comment.