Skip to content

Commit

Permalink
fixed gerber units and now works with jlcpcb and pcbway
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiboSoftwareDev committed Sep 29, 2024
1 parent fb3587d commit 74d99a8
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ dist
.yalc
yalc.lock

gerber-output
gerber-output
gerber-output.zip
Binary file modified bun.lockb
Binary file not shown.
10 changes: 3 additions & 7 deletions src/excellon-drill/convert-soup-to-excellon-drill-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import type { AnySoupElement } from "@tscircuit/soup"
import type { AnyExcellonDrillCommand } from "./any-excellon-drill-command-map"
import { excellonDrill } from "./excellon-drill-builder"

export const inchToMm = (mm: number) => {
return mm * 25.4
}

export const convertSoupToExcellonDrillCommands = ({
soup,
is_plated,
Expand Down Expand Up @@ -62,7 +58,7 @@ export const convertSoupToExcellonDrillCommands = ({
})
builder.add("define_tool", {
tool_number: tool_counter,
diameter: inchToMm(element.hole_diameter),
diameter: element.hole_diameter,
})
diameterToToolNumber[element.hole_diameter] = tool_counter
tool_counter++
Expand Down Expand Up @@ -92,8 +88,8 @@ export const convertSoupToExcellonDrillCommands = ({
if (!("hole_diameter" in element)) continue
if (diameterToToolNumber[element.hole_diameter] === i) {
builder.add("drill_at", {
x: inchToMm(element.x),
y: inchToMm(element.y) * (flip_y_axis ? -1 : 1),
x: element.x,
y: element.y * (flip_y_axis ? -1 : 1),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gerber/commands/set_unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const set_unit = defineGerberCommand({
schema: z
.object({
command_code: z.literal("MO").default("MO"),
unit: z.enum(["mm", "in"]),
unit: z.enum(["MM", "in"]),
})
.describe("Mode: Sets the unit to mm or inch. 4.2.1"),
stringify({ unit }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const getCommandHeaders = (opts: {
)
.add("format_specification", {})
.add("set_unit", {
unit: "mm",
unit: "MM",
})
.add("comment", {
comment: "Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)",
Expand Down
216 changes: 216 additions & 0 deletions tests/excellon-drill/__snapshots__/excellon-drill-builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,219 @@ exports[`test that we can recreate an example drill file: excellon-drill-builder
},
]
`;

exports[`test that we can recreate an example drill file: excellon-drill-builder 1`] = `
[
{
"command_code": "M48",
},
{
"command_code": "header_comment",
"text": "DRILL file {tscircuit} date 2024-04-09T20:34:41-0700",
},
{
"command_code": "header_comment",
"text": "FORMAT={-:-/ absolute / inch / decimal}",
},
{
"attribute_name": "TF.CreationDate",
"attribute_value": "2024-04-09T20:34:41-07:00",
"command_code": "header_attribute",
},
{
"attribute_name": "TF.GenerationSoftware",
"attribute_value": "Kicad,Pcbnew,8.0.1",
"command_code": "header_attribute",
},
{
"attribute_name": "TF.FileFunction",
"attribute_value": "Plated,1,2,PTH",
"command_code": "header_attribute",
},
{
"command_code": "FMAT",
"format": 2,
},
{
"command_code": "header_comment",
"text": "TA.AperFunction,Plated,PTH,ComponentDrill",
},
{
"command_code": "define_tool",
"diameter": 0.0394,
"tool_number": 1,
},
{
"command_code": "header_comment",
"text": "End of header",
},
{
"command_code": "G90",
},
{
"command_code": "G05",
},
{
"command_code": "define_tool",
"diameter": 0.0394,
"tool_number": 1,
},
{
"command_code": "drill_at",
"x": 4.9197,
"y": -2.9724,
},
{
"command_code": "drill_at",
"x": 5.0197,
"y": -2.9724,
},
{
"command_code": "M30",
},
]
`;

exports[`test that we can recreate an example drill file: excellon-drill-builder 1`] = `
[
{
"command_code": "M48",
},
{
"command_code": "header_comment",
"text": "DRILL file {tscircuit} date 2024-04-09T20:34:41-0700",
},
{
"command_code": "header_comment",
"text": "FORMAT={-:-/ absolute / inch / decimal}",
},
{
"attribute_name": "TF.CreationDate",
"attribute_value": "2024-04-09T20:34:41-07:00",
"command_code": "header_attribute",
},
{
"attribute_name": "TF.GenerationSoftware",
"attribute_value": "Kicad,Pcbnew,8.0.1",
"command_code": "header_attribute",
},
{
"attribute_name": "TF.FileFunction",
"attribute_value": "Plated,1,2,PTH",
"command_code": "header_attribute",
},
{
"command_code": "FMAT",
"format": 2,
},
{
"command_code": "header_comment",
"text": "TA.AperFunction,Plated,PTH,ComponentDrill",
},
{
"command_code": "define_tool",
"diameter": 0.0394,
"tool_number": 1,
},
{
"command_code": "header_comment",
"text": "End of header",
},
{
"command_code": "G90",
},
{
"command_code": "G05",
},
{
"command_code": "define_tool",
"diameter": 0.0394,
"tool_number": 1,
},
{
"command_code": "drill_at",
"x": 4.9197,
"y": -2.9724,
},
{
"command_code": "drill_at",
"x": 5.0197,
"y": -2.9724,
},
{
"command_code": "M30",
},
]
`;

exports[`test that we can recreate an example drill file: excellon-drill-builder 1`] = `
[
{
"command_code": "M48",
},
{
"command_code": "header_comment",
"text": "DRILL file {tscircuit} date 2024-04-09T20:34:41-0700",
},
{
"command_code": "header_comment",
"text": "FORMAT={-:-/ absolute / inch / decimal}",
},
{
"attribute_name": "TF.CreationDate",
"attribute_value": "2024-04-09T20:34:41-07:00",
"command_code": "header_attribute",
},
{
"attribute_name": "TF.GenerationSoftware",
"attribute_value": "Kicad,Pcbnew,8.0.1",
"command_code": "header_attribute",
},
{
"attribute_name": "TF.FileFunction",
"attribute_value": "Plated,1,2,PTH",
"command_code": "header_attribute",
},
{
"command_code": "FMAT",
"format": 2,
},
{
"command_code": "header_comment",
"text": "TA.AperFunction,Plated,PTH,ComponentDrill",
},
{
"command_code": "define_tool",
"diameter": 0.0394,
"tool_number": 1,
},
{
"command_code": "header_comment",
"text": "End of header",
},
{
"command_code": "G90",
},
{
"command_code": "G05",
},
{
"command_code": "define_tool",
"diameter": 0.0394,
"tool_number": 1,
},
{
"command_code": "drill_at",
"x": 4.9197,
"y": -2.9724,
},
{
"command_code": "drill_at",
"x": 5.0197,
"y": -2.9724,
},
{
"command_code": "M30",
},
]
`;
4 changes: 2 additions & 2 deletions tests/excellon-drill/convert-soup-to-excellon-drill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ test("generate excellon drill text from axial resistor", async () => {
const excellon_drill_file_content =
stringifyExcellonDrill(excellon_drill_cmds)

expect(excellon_drill_file_content.includes("X-254.0000Y254.0000")).toBeTrue()
expect(excellon_drill_file_content.includes("T11C25.400000")).toBeTrue()
expect(excellon_drill_file_content.includes("X-10.0000Y10.0000")).toBeTrue()
expect(excellon_drill_file_content.includes("T10C2.500000")).toBeTrue()
expect(excellon_drill_file_content.includes("G90")).toBeTrue()
expect(excellon_drill_file_content.includes("G05")).toBeTrue()
})
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.
Loading

0 comments on commit 74d99a8

Please sign in to comment.