Skip to content
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
3 changes: 3 additions & 0 deletions lib/ConvertContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ export interface ConvertContext {

netGeoms: Map<ConnectivityMapKey, Array<Polygon | Box>>

copperLayerPolygons: Polygon[]
boardCutPolygons: Polygon[]

origin: { x: number; y: number }
}
15 changes: 2 additions & 13 deletions lib/element-handlers/addPcbBoard/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Polygon, point } from "@flatten-js/core"
import type { PcbBoard } from "circuit-json"
import { ShapePath } from "lbrnts"
import type { ConvertContext } from "../../ConvertContext"
import { polygonToShapePathData } from "../../polygon-to-shape-path"

export const addPcbBoard = (board: PcbBoard, ctx: ConvertContext) => {
const { origin, project, throughBoardCutSetting } = ctx
const { origin, boardCutPolygons } = ctx

let polygon: Polygon | null = null

Expand Down Expand Up @@ -37,14 +35,5 @@ export const addPcbBoard = (board: PcbBoard, ctx: ConvertContext) => {

if (!polygon) return

const { verts, prims } = polygonToShapePathData(polygon)

project.children.push(
new ShapePath({
cutIndex: throughBoardCutSetting.index,
verts,
prims,
isClosed: true,
}),
)
boardCutPolygons.push(polygon)
}
56 changes: 44 additions & 12 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const convertCircuitJsonToLbrn = (
throughBoardCutSetting,
connMap,
netGeoms: new Map(),
copperLayerPolygons: [],
boardCutPolygons: [],
origin,
}

Expand Down Expand Up @@ -111,7 +113,8 @@ export const convertCircuitJsonToLbrn = (
// }
// }

// Create a union of all the net geoms, and add to project
// Phase 1: Construct flattenjs polygons for each cutting layer
// Create a union of all the net geoms and collect polygons for the copper layer
for (const net of Object.keys(connMap.netMap)) {
const netGeoms = ctx.netGeoms.get(net)!

Expand All @@ -137,18 +140,47 @@ export const convertCircuitJsonToLbrn = (
// }

for (const island of union.splitToIslands()) {
// Convert the polygon to verts and prims
const { verts, prims } = polygonToShapePathData(island)

project.children.push(
new ShapePath({
cutIndex: copperCutSetting.index,
verts,
prims,
isClosed: false,
}),
)
ctx.copperLayerPolygons.push(island)
}
}
// Phase 2: Construct a single cut path for each cutting layer

if (ctx.copperLayerPolygons.length > 0) {
const [firstCopper, ...restCopper] = ctx.copperLayerPolygons
let copperUnion: Polygon = firstCopper!
for (const poly of restCopper) {
copperUnion = BooleanOperations.unify(copperUnion, poly)
}

const { verts, prims } = polygonToShapePathData(copperUnion)

project.children.push(
new ShapePath({
cutIndex: copperCutSetting.index,
verts,
prims,
isClosed: false,
}),
)
}

if (ctx.boardCutPolygons.length > 0) {
const [firstBoard, ...restBoards] = ctx.boardCutPolygons
let boardUnion: Polygon = firstBoard!
for (const poly of restBoards) {
boardUnion = BooleanOperations.unify(boardUnion, poly)
}

const { verts, prims } = polygonToShapePathData(boardUnion)

project.children.push(
new ShapePath({
cutIndex: throughBoardCutSetting.index,
verts,
prims,
isClosed: true,
}),
)
}
return project
}
2 changes: 1 addition & 1 deletion tests/examples/__snapshots__/lga-interconnect.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.