circuit-json-to-lbrn 0.0.20 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +784 -345
  3. package/lib/ConvertContext.ts +6 -2
  4. package/lib/element-handlers/addPcbCutout/addCirclePcbCutout.ts +10 -2
  5. package/lib/element-handlers/addPcbCutout/addPolygonPcbCutout.ts +10 -6
  6. package/lib/element-handlers/addPcbCutout/addRectPcbCutout.ts +12 -12
  7. package/lib/element-handlers/addPcbHole/addCirclePcbHole.ts +10 -2
  8. package/lib/element-handlers/addPcbHole/addOvalPcbHole.ts +8 -8
  9. package/lib/element-handlers/addPcbHole/addPillPcbHole.ts +8 -8
  10. package/lib/element-handlers/addPcbHole/addRectPcbHole.ts +10 -10
  11. package/lib/element-handlers/addPcbHole/addRotatedPillPcbHole.ts +8 -8
  12. package/lib/element-handlers/addPcbTrace/index.ts +145 -61
  13. package/lib/element-handlers/addPcbVia/index.ts +49 -15
  14. package/lib/element-handlers/addPlatedHole/addCirclePlatedHole.ts +49 -15
  15. package/lib/element-handlers/addPlatedHole/addCircularHoleWithRectPad.ts +38 -18
  16. package/lib/element-handlers/addPlatedHole/addHoleWithPolygonPad.ts +41 -16
  17. package/lib/element-handlers/addPlatedHole/addOvalPlatedHole.ts +39 -18
  18. package/lib/element-handlers/addPlatedHole/addPillHoleWithRectPad.ts +38 -23
  19. package/lib/element-handlers/addPlatedHole/addPillPlatedHole.ts +39 -18
  20. package/lib/element-handlers/addPlatedHole/addRotatedPillHoleWithRectPad.ts +43 -28
  21. package/lib/element-handlers/addSmtPad/addCircleSmtPad.ts +31 -4
  22. package/lib/element-handlers/addSmtPad/addPillSmtPad.ts +33 -4
  23. package/lib/element-handlers/addSmtPad/addPolygonSmtPad.ts +25 -3
  24. package/lib/element-handlers/addSmtPad/addRectSmtPad.ts +20 -3
  25. package/lib/element-handlers/addSmtPad/addRotatedPillSmtPad.ts +31 -12
  26. package/lib/element-handlers/addSmtPad/addRotatedRectSmtPad.ts +31 -12
  27. package/lib/helpers/circleShape.ts +13 -6
  28. package/lib/helpers/ovalShape.ts +17 -8
  29. package/lib/helpers/pathPointUtils.ts +11 -5
  30. package/lib/helpers/pillShape.ts +24 -11
  31. package/lib/helpers/polygonShape.ts +11 -5
  32. package/lib/helpers/roundedRectShape.ts +19 -9
  33. package/lib/index.ts +92 -41
  34. package/package.json +1 -1
  35. package/tests/assets/keyboard-default60.json +92565 -0
  36. package/tests/examples/__snapshots__/board-outline-soldermask-preset.snap.svg +1 -1
  37. package/tests/examples/__snapshots__/board-outline.snap.svg +1 -1
  38. package/tests/examples/__snapshots__/lga-interconnect.snap.svg +1 -1
  39. package/tests/examples/__snapshots__/single-trace.snap.svg +1 -1
  40. package/tests/examples/addPcbCutout/__snapshots__/pcb-cutout-circle.snap.svg +1 -1
  41. package/tests/examples/addPcbCutout/__snapshots__/pcb-cutout-path.snap.svg +1 -1
  42. package/tests/examples/addPcbCutout/__snapshots__/pcb-cutout-polygon.snap.svg +1 -1
  43. package/tests/examples/addPcbCutout/__snapshots__/pcb-cutout-rect.snap.svg +1 -1
  44. package/tests/examples/addPcbHole/__snapshots__/pcb-hole-circle.snap.svg +1 -1
  45. package/tests/examples/addPcbHole/__snapshots__/pcb-hole-oval.snap.svg +1 -1
  46. package/tests/examples/addPcbHole/__snapshots__/pcb-hole-pill.snap.svg +1 -1
  47. package/tests/examples/addPcbHole/__snapshots__/pcb-hole-rect.snap.svg +1 -1
  48. package/tests/examples/addPcbHole/__snapshots__/pcb-hole-rotated-pill.snap.svg +2 -2
  49. package/tests/examples/addPcbHole/__snapshots__/pcb-hole-with-soldermask.snap.svg +1 -1
  50. package/tests/examples/addPcbVia/__snapshots__/pcb-via-basic.snap.svg +1 -1
  51. package/tests/examples/addPcbVia/__snapshots__/pcb-via-with-net.snap.svg +1 -1
  52. package/tests/examples/addPcbVia/__snapshots__/pcb-via-with-soldermask.snap.svg +1 -1
  53. package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-circle.snap.svg +1 -1
  54. package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-circular-hole-with-rect-pad.snap.svg +1 -1
  55. package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-oval.snap.svg +1 -1
  56. package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-pill-with-rect-pad.snap.svg +1 -1
  57. package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-pill.snap.svg +1 -1
  58. package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-polygon.snap.svg +1 -1
  59. package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-rotated-pill-with-rect-pad.snap.svg +1 -1
  60. package/tests/examples/addSmtPad/__snapshots__/circleSmtPad.snap.svg +1 -1
  61. package/tests/examples/addSmtPad/__snapshots__/pillSmtPad.snap.svg +1 -1
  62. package/tests/examples/addSmtPad/__snapshots__/polygonSmtPad.snap.svg +1 -1
  63. package/tests/examples/addSmtPad/__snapshots__/rotatedPillSmtPad.snap.svg +1 -1
  64. package/tests/examples/addSmtPad/__snapshots__/rotatedRectSmtPad.snap.svg +1 -1
  65. package/tests/examples/keyboard-defaul60/__snapshots__/keyboard-both-layer-includeSoldermask.snap.svg +8 -0
  66. package/tests/examples/keyboard-defaul60/__snapshots__/keyboard-both-layers.snap.svg +8 -0
  67. package/tests/examples/keyboard-defaul60/__snapshots__/keyboard-bottom-layer.snap.svg +8 -0
  68. package/tests/examples/keyboard-defaul60/__snapshots__/keyboard-top-layer.snap.svg +8 -0
  69. package/tests/examples/keyboard-defaul60/keyboard-both-layer-includeSoldermask.test.ts +27 -0
  70. package/tests/examples/keyboard-defaul60/keyboard-both-layers.test.ts +26 -0
  71. package/tests/examples/keyboard-defaul60/keyboard-bottom-layer.test.ts +26 -0
  72. package/tests/examples/keyboard-defaul60/keyboard-top-layer.test.ts +26 -0
  73. package/tests/examples/lga-interconnect.test.ts +3 -2
  74. package/tests/examples/soldermask/__snapshots__/copper-and-soldermask.snap.svg +1 -1
  75. package/tests/examples/soldermask/__snapshots__/copper-only.snap.svg +1 -1
  76. package/tests/examples/soldermask/__snapshots__/soldermask-only.snap.svg +1 -1
  77. package/tests/examples/soldermask/copper-and-soldermask.test.ts +18 -10
  78. package/tests/examples/soldermask/soldermask-only.test.ts +3 -3
  79. package/tests/examples/soldermask-margin/__snapshots__/negative-soldermask-margin.snap.svg +1 -1
  80. package/tests/examples/soldermask-margin/__snapshots__/positive-soldermask-margin.snap.svg +1 -1
  81. package/tsconfig.json +2 -1
@@ -12,15 +12,25 @@ export interface RoundedRectPath {
12
12
  prims: Prim[]
13
13
  }
14
14
 
15
- export const createRoundedRectPath = (
16
- centerX: number,
17
- centerY: number,
18
- width: number,
19
- height: number,
20
- borderRadius: number = 0,
21
- segments: number = 4,
22
- rotation: number = 0,
23
- ): RoundedRectPath => {
15
+ export interface CreateRoundedRectPathParams {
16
+ centerX: number
17
+ centerY: number
18
+ width: number
19
+ height: number
20
+ borderRadius?: number
21
+ segments?: number
22
+ rotation?: number
23
+ }
24
+
25
+ export const createRoundedRectPath = ({
26
+ centerX,
27
+ centerY,
28
+ width,
29
+ height,
30
+ borderRadius = 0,
31
+ segments = 4,
32
+ rotation = 0,
33
+ }: CreateRoundedRectPathParams): RoundedRectPath => {
24
34
  const verts: Point[] = []
25
35
  const prims: Prim[] = []
26
36
  const halfWidth = width / 2
package/lib/index.ts CHANGED
@@ -27,6 +27,7 @@ export const convertCircuitJsonToLbrn = (
27
27
  includeCopper?: boolean
28
28
  includeSoldermask?: boolean
29
29
  soldermaskMargin?: number
30
+ includeLayers?: Array<"top" | "bottom">
30
31
  } = {},
31
32
  ): LightBurnProject => {
32
33
  const db = cju(circuitJson)
@@ -35,16 +36,27 @@ export const convertCircuitJsonToLbrn = (
35
36
  formatVersion: "1",
36
37
  })
37
38
 
38
- const copperCutSetting = new CutSetting({
39
+ // Default to all layers if not specified
40
+ const includeLayers = options.includeLayers ?? ["top", "bottom"]
41
+
42
+ const topCopperCutSetting = new CutSetting({
39
43
  index: 0,
40
- name: "Cut Copper",
44
+ name: "Cut Top Copper",
41
45
  numPasses: 12,
42
46
  speed: 100,
43
47
  })
44
- project.children.push(copperCutSetting)
48
+ project.children.push(topCopperCutSetting)
45
49
 
46
- const throughBoardCutSetting = new CutSetting({
50
+ const bottomCopperCutSetting = new CutSetting({
47
51
  index: 1,
52
+ name: "Cut Bottom Copper",
53
+ numPasses: 12,
54
+ speed: 100,
55
+ })
56
+ project.children.push(bottomCopperCutSetting)
57
+
58
+ const throughBoardCutSetting = new CutSetting({
59
+ index: 2,
48
60
  name: "Cut Through Board",
49
61
  numPasses: 3,
50
62
  speed: 50,
@@ -52,14 +64,14 @@ export const convertCircuitJsonToLbrn = (
52
64
  project.children.push(throughBoardCutSetting)
53
65
 
54
66
  const soldermaskCutSetting = new CutSetting({
55
- type: "Scan", // Use Scan mode to fill the pad shapes for Kapton tape cutting
56
- index: 2,
67
+ type: "Scan", // Use Scan mode to fill pad shapes for Kapton tape cutting
68
+ index: 3,
57
69
  name: "Cut Soldermask",
58
70
  numPasses: 1,
59
71
  speed: 150,
60
72
  scanOpt: "individual", // Scan each shape individually
61
73
  interval: 0.18, // Distance between cross-hatch lines
62
- angle: 45, // Angle of the cross-hatch lines
74
+ angle: 45, // Angle of cross-hatch lines
63
75
  crossHatch: true,
64
76
  })
65
77
  project.children.push(soldermaskCutSetting)
@@ -76,19 +88,23 @@ export const convertCircuitJsonToLbrn = (
76
88
  const ctx: ConvertContext = {
77
89
  db,
78
90
  project,
79
- copperCutSetting,
91
+ topCopperCutSetting,
92
+ bottomCopperCutSetting,
80
93
  throughBoardCutSetting,
81
94
  soldermaskCutSetting,
82
95
  connMap,
83
- netGeoms: new Map(),
96
+ topNetGeoms: new Map(),
97
+ bottomNetGeoms: new Map(),
84
98
  origin,
85
99
  includeCopper: options.includeCopper ?? true,
86
100
  includeSoldermask: options.includeSoldermask ?? false,
87
101
  soldermaskMargin: options.soldermaskMargin ?? 0,
102
+ includeLayers,
88
103
  }
89
104
 
90
105
  for (const net of Object.keys(connMap.netMap)) {
91
- ctx.netGeoms.set(net, [])
106
+ ctx.topNetGeoms.set(net, [])
107
+ ctx.bottomNetGeoms.set(net, [])
92
108
  }
93
109
 
94
110
  for (const smtpad of db.pcb_smtpad.list()) {
@@ -149,42 +165,77 @@ export const convertCircuitJsonToLbrn = (
149
165
  // Create a union of all the net geoms, and add to project
150
166
  // Only do this when including copper
151
167
  if (ctx.includeCopper) {
152
- for (const net of Object.keys(connMap.netMap)) {
153
- const netGeoms = ctx.netGeoms.get(net)!
168
+ // Process top layer
169
+ if (includeLayers.includes("top")) {
170
+ for (const net of Object.keys(connMap.netMap)) {
171
+ const netGeoms = ctx.topNetGeoms.get(net)!
154
172
 
155
- if (netGeoms.length === 0) {
156
- continue
157
- }
173
+ if (netGeoms.length === 0) {
174
+ continue
175
+ }
158
176
 
159
- let union = netGeoms[0]!
160
- if (union instanceof Box) {
161
- union = new Polygon(union)
162
- }
163
- for (const geom of netGeoms.slice(1)) {
164
- if (geom instanceof Polygon) {
165
- union = BooleanOperations.unify(union, geom)
166
- } else if (geom instanceof Box) {
167
- union = BooleanOperations.unify(union, new Polygon(geom))
177
+ let union = netGeoms[0]!
178
+ if (union instanceof Box) {
179
+ union = new Polygon(union)
180
+ }
181
+ for (const geom of netGeoms.slice(1)) {
182
+ if (geom instanceof Polygon) {
183
+ union = BooleanOperations.unify(union, geom)
184
+ } else if (geom instanceof Box) {
185
+ union = BooleanOperations.unify(union, new Polygon(geom))
186
+ }
187
+ }
188
+
189
+ for (const island of union.splitToIslands()) {
190
+ // Convert the polygon to verts and prims
191
+ const { verts, prims } = polygonToShapePathData(island)
192
+
193
+ project.children.push(
194
+ new ShapePath({
195
+ cutIndex: topCopperCutSetting.index,
196
+ verts,
197
+ prims,
198
+ isClosed: false,
199
+ }),
200
+ )
168
201
  }
169
202
  }
203
+ }
204
+
205
+ // Process bottom layer
206
+ if (includeLayers.includes("bottom")) {
207
+ for (const net of Object.keys(connMap.netMap)) {
208
+ const netGeoms = ctx.bottomNetGeoms.get(net)!
170
209
 
171
- // DEBUGGING ONLY!!!
172
- // if (netGeoms.length > 1) {
173
- // writeDebugSvg(net, union)
174
- // }
175
-
176
- for (const island of union.splitToIslands()) {
177
- // Convert the polygon to verts and prims
178
- const { verts, prims } = polygonToShapePathData(island)
179
-
180
- project.children.push(
181
- new ShapePath({
182
- cutIndex: copperCutSetting.index,
183
- verts,
184
- prims,
185
- isClosed: false,
186
- }),
187
- )
210
+ if (netGeoms.length === 0) {
211
+ continue
212
+ }
213
+
214
+ let union = netGeoms[0]!
215
+ if (union instanceof Box) {
216
+ union = new Polygon(union)
217
+ }
218
+ for (const geom of netGeoms.slice(1)) {
219
+ if (geom instanceof Polygon) {
220
+ union = BooleanOperations.unify(union, geom)
221
+ } else if (geom instanceof Box) {
222
+ union = BooleanOperations.unify(union, new Polygon(geom))
223
+ }
224
+ }
225
+
226
+ for (const island of union.splitToIslands()) {
227
+ // Convert the polygon to verts and prims
228
+ const { verts, prims } = polygonToShapePathData(island)
229
+
230
+ project.children.push(
231
+ new ShapePath({
232
+ cutIndex: bottomCopperCutSetting.index,
233
+ verts,
234
+ prims,
235
+ isClosed: false,
236
+ }),
237
+ )
238
+ }
188
239
  }
189
240
  }
190
241
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-json-to-lbrn",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.20",
4
+ "version": "0.0.22",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "bun run site/index.html",