Skip to content
Merged
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
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 39 additions & 15 deletions lib/components/workspace-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React, {
} from "react"
import conductivityPadsTemplateRaw from "../../assets/connectivity-test-pads.json?raw"
import fiducialsTemplateRaw from "../../assets/fiducials.json?raw"
import { configureTopSoldermaskRemovalLayer } from "../helpers/configure-top-soldermask-removal-layer"

export type FiducialConductivityOption =
| "none"
Expand Down Expand Up @@ -143,6 +144,8 @@ const defaultLbrnOptions: ConvertCircuitJsonToLbrnOptions = {
includeSoldermask: true,
includeSilkscreen: true,
includeCopperCutFill: true,
includeSoldermaskAblation: true,
soldermaskAblationClearance: 0.5,
includeOxidationCleaningLayer: true,
includeSoldermaskCure: true,
mirrorBottomLayer: true,
Expand Down Expand Up @@ -258,20 +261,29 @@ export function WorkspaceProvider({ children }: { children: ReactNode }) {
const setLbrnOptions = (
options: Partial<ConvertCircuitJsonToLbrnOptions>,
) => {
setLbrnOptionsState((prev) => ({
...prev,
...options,
includeCopper: true,
includeSoldermask: true,
includeSilkscreen: true,
includeCopperCutFill: true,
includeOxidationCleaningLayer:
options.includeOxidationCleaningLayer ??
prev.includeOxidationCleaningLayer ??
true,
includeSoldermaskCure: true,
includeLayers: options.includeLayers ?? prev.includeLayers,
}))
setLbrnOptionsState((prev) => {
const copperCutFillMargin =
options.copperCutFillMargin ??
prev.copperCutFillMargin ??
defaultLbrnOptions.copperCutFillMargin

return {
...prev,
...options,
includeCopper: true,
includeSoldermask: true,
includeSilkscreen: true,
includeCopperCutFill: true,
includeSoldermaskAblation: true,
soldermaskAblationClearance: copperCutFillMargin,
includeOxidationCleaningLayer:
options.includeOxidationCleaningLayer ??
prev.includeOxidationCleaningLayer ??
true,
includeSoldermaskCure: true,
includeLayers: options.includeLayers ?? prev.includeLayers,
}
})
}

const resetSavedLbrnOptions = () => {
Expand All @@ -280,6 +292,8 @@ export function WorkspaceProvider({ children }: { children: ReactNode }) {
laserSpotSize: defaultLbrnOptions.laserSpotSize,
traceMargin: defaultLbrnOptions.traceMargin,
copperCutFillMargin: defaultLbrnOptions.copperCutFillMargin,
soldermaskAblationClearance:
defaultLbrnOptions.soldermaskAblationClearance,
globalCopperSoldermaskMarginAdjustment:
defaultLbrnOptions.globalCopperSoldermaskMarginAdjustment,
solderMaskMarginPercent: defaultLbrnOptions.solderMaskMarginPercent,
Expand Down Expand Up @@ -460,9 +474,19 @@ export function WorkspaceProvider({ children }: { children: ReactNode }) {
setError(null)

try {
const finalOptions = { ...lbrnOptions, ...options }
const copperCutFillMargin =
options?.copperCutFillMargin ??
lbrnOptions.copperCutFillMargin ??
defaultLbrnOptions.copperCutFillMargin
const finalOptions = {
...lbrnOptions,
...options,
includeSoldermaskAblation: true,
soldermaskAblationClearance: copperCutFillMargin,
}

const project = await convertCircuitJsonToLbrn(circuitJson, finalOptions)
configureTopSoldermaskRemovalLayer(project)
const xml = project.getString()

setLbrnFileContent({
Expand Down
20 changes: 20 additions & 0 deletions lib/helpers/configure-top-soldermask-removal-layer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CutSetting, type LightBurnProject } from "lbrnts"

export const TOP_SOLDERMASK_REMOVAL_LAYER_INDEX = 16
export const TOP_SOLDERMASK_REMOVAL_LAYER_NAME = "Top Soldermask Removal"

export const configureTopSoldermaskRemovalLayer = (
project: LightBurnProject,
): CutSetting | undefined => {
const cutSetting = project.children.find(
(child): child is CutSetting =>
child instanceof CutSetting &&
child.index === TOP_SOLDERMASK_REMOVAL_LAYER_INDEX,
)

if (cutSetting) {
cutSetting.name = TOP_SOLDERMASK_REMOVAL_LAYER_NAME
}

return cutSetting
}
45 changes: 45 additions & 0 deletions tests/top-soldermask-removal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect, test } from "bun:test"
import type { CircuitJson } from "circuit-json"
import { convertCircuitJsonToLbrn } from "circuit-json-to-lbrn"
import circuitJson from "./examples/example01/1206x4_3216metric.json" with {
type: "json",
}
import {
configureTopSoldermaskRemovalLayer,
TOP_SOLDERMASK_REMOVAL_LAYER_INDEX,
TOP_SOLDERMASK_REMOVAL_LAYER_NAME,
} from "../lib/helpers/configure-top-soldermask-removal-layer"

type ProjectNode = {
children?: ProjectNode[]
cutIndex?: number
}

const flattenProject = (nodes: ProjectNode[]): ProjectNode[] =>
nodes.flatMap((node) => [node, ...flattenProject(node.children ?? [])])

test("creates top soldermask removal from cut fill without interior lines", async () => {
const project = await convertCircuitJsonToLbrn(circuitJson as CircuitJson, {
includeLayers: ["top"],
includeCopper: true,
includeCopperCutFill: true,
includeSoldermaskAblation: true,
copperCutFillMargin: 0.5,
soldermaskAblationClearance: 0.5,
origin: { x: 0, y: 0 },
})

const removalSetting = configureTopSoldermaskRemovalLayer(project)
const projectNodes = flattenProject(project.children as ProjectNode[])
const copperCutFillShapes = projectNodes.filter((node) => node.cutIndex === 6)
const removalShapes = projectNodes.filter(
(node) => node.cutIndex === TOP_SOLDERMASK_REMOVAL_LAYER_INDEX,
)

expect(removalSetting?.name).toBe(TOP_SOLDERMASK_REMOVAL_LAYER_NAME)
expect(removalShapes).toHaveLength(1)
expect(copperCutFillShapes.length).toBeGreaterThan(removalShapes.length)
expect(project.getString()).toContain(
`<name Value="${TOP_SOLDERMASK_REMOVAL_LAYER_NAME}"/>`,
)
})
Loading