Skip to content

Commit

Permalink
Merge pull request #4 from ShiboSoftwareDev/main
Browse files Browse the repository at this point in the history
integrated board outline
  • Loading branch information
seveibar authored Sep 2, 2024
2 parents 89edddf + 86a0919 commit d8d6124
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 42 deletions.
Binary file modified bun.lockb
Binary file not shown.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"module": "src/index.ts",
"type": "module",
"devDependencies": {
"@tscircuit/soup": "^0.0.58",
"@types/bun": "latest",
"@tscircuit/soup": "^0.0.60",
"@types/bun": "^1.1.8",
"@types/node": "^22.5.2",
"bun-match-svg": "^0.0.2",
"gerber-to-svg": "^4.2.8",
"tsup": "^8.2.4",
"bun-match-svg": "^0.0.1",
"pcb-stackup": "^4.2.8"
"pcb-stackup": "^4.2.8",
"tsup": "^8.2.4"
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/any_gerber_command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GerberCommandDef } from "./define-gerber-command"
import { z } from "zod"
import type { z } from "zod"

import { add_attribute_on_aperture } from "./commands/add_attribute_on_aperture"
import { add_attribute_on_file } from "./commands/add_attribute_on_file"
Expand Down
4 changes: 2 additions & 2 deletions src/convert-soup-to-gerber-commands/GerberLayerName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnyGerberCommand } from "../any_gerber_command"
import { GerberJobJson } from "./gerber-job-json"
import type { AnyGerberCommand } from "../any_gerber_command"
import type { GerberJobJson } from "./gerber-job-json"

export type LayerToGerberCommandsMap = {
F_Cu: AnyGerberCommand[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyGerberCommand } from "../any_gerber_command"
import type { AnyGerberCommand } from "../any_gerber_command"
import { gerberBuilder } from "../gerber-builder"

export const defineCommonMacros = (glayer: Array<AnyGerberCommand>) => {
Expand Down
6 changes: 3 additions & 3 deletions src/convert-soup-to-gerber-commands/findApertureNumber.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
import type {
ApertureTemplateConfig,
DefineAperatureTemplateCommand,
} from "../commands/define_aperture_template"
import { AnyGerberCommand } from "../any_gerber_command"
import type { AnyGerberCommand } from "../any_gerber_command"

export const findApertureNumber = (
glayer: AnyGerberCommand[],
Expand All @@ -26,7 +26,7 @@ export const findApertureNumber = (
(command): command is DefineAperatureTemplateCommand =>
command.command_code === "ADD" &&
Object.keys(search_params).every(
(param_name) => command[param_name] === search_params[param_name]
(param_name) => command[param_name as keyof typeof search_params] === search_params[param_name as keyof typeof search_params]
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/convert-soup-to-gerber-commands/getCommandHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getCommandHeaders = (opts: {
unit: "mm",
})
.add("comment", {
comment: `Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)`,
comment: "Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)",
})
.add("comment", {
comment: `Created by tscircuit (builder) date ${new Date().toISOString()}`,
Expand Down
2 changes: 1 addition & 1 deletion src/convert-soup-to-gerber-commands/getGerberLayerName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export const getGerberLayerName = (
layer_type: "copper" | "silkscreen" | "soldermask" | "paste"
): GerberLayerName => {
if (layer_ref === "edgecut") return "Edge_Cuts"
return `${layerRefToGerberPrefix[layer_ref]}${layerTypeToGerberSuffix[layer_type]}` as any
return `${layerRefToGerberPrefix[layer_ref as keyof typeof layerRefToGerberPrefix]}${layerTypeToGerberSuffix[layer_type]}`
}
26 changes: 16 additions & 10 deletions src/convert-soup-to-gerber-commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const convertSoupToGerberCommands = (
}

// Edgecuts has a single aperature
glayers["Edge_Cuts"].push(
glayers.Edge_Cuts.push(
...gerberBuilder()
.add("define_aperture_template", {
aperture_number: 10,
Expand Down Expand Up @@ -143,12 +143,17 @@ export const convertSoupToGerberCommands = (
}
} else if (element.type === "pcb_board" && layer === "edgecut") {
const glayer = glayers.Edge_Cuts
const { width, height, center } = element
glayer.push(
...gerberBuilder()
.add("select_aperture", {
aperture_number: 10,
})
const { width, height, center, outline } = element
const gerberBuild = gerberBuilder().add("select_aperture", {
aperture_number: 10,
})
if (outline && outline.length > 2) {
gerberBuild.add("move_operation", outline[0])
for (let i = 1; i < outline.length; i++) {
gerberBuild.add("plot_operation", outline[i])
}
} else {
gerberBuild
.add("move_operation", {
x: center.x - width / 2,
y: mfy(center.y - height / 2),
Expand Down Expand Up @@ -181,14 +186,15 @@ export const convertSoupToGerberCommands = (
x: center.x - width / 2,
y: mfy(center.y - height / 2),
})
.build(),
)
}

glayer.push(...gerberBuild.build())
}
}
}

for (const key of Object.keys(glayers)) {
glayers[key].push(...gerberBuilder().add("end_of_file", {}).build())
glayers[key as keyof LayerToGerberCommandsMap].push(...gerberBuilder().add("end_of_file", {}).build())
}

return glayers
Expand Down
2 changes: 1 addition & 1 deletion src/define-gerber-command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyZodObject, z, ZodObject, ZodUnion } from "zod"
import type { AnyZodObject, z, ZodObject, ZodUnion } from "zod"

export interface GerberCommandDef<
K extends string,
Expand Down
4 changes: 2 additions & 2 deletions src/gerber-builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnyGerberCommand } from "./any_gerber_command"
import { z } from "zod"
import type { AnyGerberCommand } from "./any_gerber_command"
import type { z } from "zod"
import { gerber_command_map } from "./any_gerber_command"

export const gerberBuilder = () => new GerberBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/stringify-gerber/stringify-gerber-command-layers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnyGerberCommand } from "../any_gerber_command"
import { GerberLayerName } from "../convert-soup-to-gerber-commands/GerberLayerName"
import type { AnyGerberCommand } from "../any_gerber_command"
import type { GerberLayerName } from "../convert-soup-to-gerber-commands/GerberLayerName"
import { stringifyGerberCommand } from "./stringify-gerber-command"

export const stringifyGerberCommandLayers = (
Expand Down
3 changes: 2 additions & 1 deletion src/stringify-gerber/stringify-gerber-command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AnyGerberCommand, gerber_command_map } from "../any_gerber_command"
import type { AnyGerberCommand } from "../any_gerber_command"
import { gerber_command_map } from "../any_gerber_command"

export const stringifyGerberCommand = (command: AnyGerberCommand): string => {
const command_def = Object.values(gerber_command_map).find(
Expand Down
2 changes: 1 addition & 1 deletion src/stringify-gerber/stringify-gerber-commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyGerberCommand } from "../any_gerber_command"
import type { AnyGerberCommand } from "../any_gerber_command"
import { stringifyGerberCommand } from "./stringify-gerber-command"

export const stringifyGerberCommands = (
Expand Down
14 changes: 7 additions & 7 deletions tests/__snapshots__/simple1.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/fixtures/maybe-output-gerber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const maybeOutputGerber = async (gerber_map: Record<string, string>) => {
// @ts-ignore
if (process.env.OUTPUT_GERBER) {
// @ts-ignore
const fs = await import("fs")
const fs = await import("node:fs")
fs.mkdirSync("./gerber-output", { recursive: true })
for (const filename of Object.keys(gerber_map)) {
const fp = `./gerber-output/${filename}.gbr`
Expand Down
46 changes: 43 additions & 3 deletions tests/generate-board-outline-gerber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,49 @@ test("Generate simple gerber with a single trace", async () => {
const gerber_cmds = convertSoupToGerberCommands([
{
type: "pcb_board",
width: 20,
height: 20,
center: { x: 10, y: -10 },
width: 100,
height: 100,
center: { x: 0, y: 0 },
outline: [
{ x: -22.5, y: 24.5 },
{ x: 22.5, y: 24.5 },
{ x: 22.5, y: 16.5 },
{ x: 20.5, y: 16.5 },
{ x: 20.5, y: 12.5 },
{ x: 22.5, y: 12.5 },
{ x: 22.5, y: 2.5 },
{ x: 18, y: -1.5 },
{ x: 18, y: -18 },
{ x: -18, y: -18 },
{ x: -18, y: -1.5 },
{ x: -22.5, y: 2.5 },
{ x: -22.5, y: 12.5 },
{ x: -20.5, y: 12.5 },
{ x: -20.5, y: 16.5 },
{ x: -22.5, y: 16.5 },
{ x: -22.5, y: 24.5 },
],
},
{
type: "pcb_trace",
source_trace_id: "source_trace_1",
pcb_trace_id: "pcb_trace_1",
route: [
{
x: -10,
y: 0,
width: 0.1,
route_type: "wire",
layer: "top",
},
{
x: 10,
y: 0,
width: 0.1,
route_type: "wire",
layer: "top",
},
],
},
])
const edgecut_gerber = stringifyGerberCommands(gerber_cmds.Edge_Cuts)
Expand Down

0 comments on commit d8d6124

Please sign in to comment.