circuit-json-to-lbrn 0.0.7 → 0.0.9
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.
- package/dist/index.js +697 -10
- package/lib/element-handlers/addPlatedHole/addCirclePlatedHole.ts +30 -72
- package/lib/element-handlers/addPlatedHole/addCircularHoleWithRectPad.ts +44 -3
- package/lib/element-handlers/addPlatedHole/addHoleWithPolygonPad.ts +55 -4
- package/lib/element-handlers/addPlatedHole/addOvalPlatedHole.ts +49 -4
- package/lib/element-handlers/addPlatedHole/addPillHoleWithRectPad.ts +52 -4
- package/lib/element-handlers/addPlatedHole/addPillPlatedHole.ts +52 -0
- package/lib/element-handlers/addPlatedHole/addRotatedPillHoleWithRectPad.ts +57 -4
- package/lib/element-handlers/addPlatedHole/index.ts +4 -1
- package/lib/element-handlers/addSmtPad/addCircleSmtPad.ts +26 -0
- package/lib/element-handlers/addSmtPad/addPillSmtPad.ts +25 -0
- package/lib/element-handlers/addSmtPad/addPolygonSmtPad.ts +25 -0
- package/lib/element-handlers/addSmtPad/addRotatedPillSmtPad.ts +32 -0
- package/lib/element-handlers/addSmtPad/addRotatedRectSmtPad.ts +36 -0
- package/lib/element-handlers/addSmtPad/index.ts +25 -7
- package/lib/helpers/circleShape.ts +42 -0
- package/lib/helpers/ovalShape.ts +51 -0
- package/lib/helpers/pathPointUtils.ts +45 -0
- package/lib/helpers/pillShape.ts +99 -0
- package/lib/helpers/polygonShape.ts +38 -0
- package/lib/helpers/roundedRectShape.ts +121 -0
- package/lib/index.ts +3 -3
- package/package.json +2 -2
- package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-circle.snap.svg +8 -0
- package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-circular-hole-with-rect-pad.snap.svg +8 -0
- package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-oval.snap.svg +8 -0
- package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-pill-with-rect-pad.snap.svg +8 -0
- package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-pill.snap.svg +8 -0
- package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-polygon.snap.svg +8 -0
- package/tests/examples/addPlatedHole/__snapshots__/pcb-plated-hole-rotated-pill-with-rect-pad.snap.svg +8 -0
- package/tests/examples/addPlatedHole/pcb-plated-hole-circle.test.ts +62 -0
- package/tests/examples/addPlatedHole/pcb-plated-hole-circular-hole-with-rect-pad.test.ts +54 -0
- package/tests/examples/addPlatedHole/pcb-plated-hole-oval.test.ts +101 -0
- package/tests/examples/addPlatedHole/pcb-plated-hole-pill-with-rect-pad.test.ts +54 -0
- package/tests/examples/addPlatedHole/pcb-plated-hole-pill.test.ts +101 -0
- package/tests/examples/addPlatedHole/pcb-plated-hole-polygon.test.ts +59 -0
- package/tests/examples/addPlatedHole/pcb-plated-hole-rotated-pill-with-rect-pad.test.ts +56 -0
- package/tests/examples/addSmtPad/__snapshots__/circleSmtPad.snap.svg +8 -0
- package/tests/examples/addSmtPad/__snapshots__/pillSmtPad.snap.svg +8 -0
- package/tests/examples/addSmtPad/__snapshots__/polygonSmtPad.snap.svg +8 -0
- package/tests/examples/addSmtPad/__snapshots__/rotatedPillSmtPad.snap.svg +8 -0
- package/tests/examples/addSmtPad/__snapshots__/rotatedRectSmtPad.snap.svg +8 -0
- package/tests/examples/addSmtPad/circleSmtPad.test.ts +45 -0
- package/tests/examples/addSmtPad/pillSmtPad.test.ts +47 -0
- package/tests/examples/addSmtPad/polygonSmtPad.test.ts +51 -0
- package/tests/examples/addSmtPad/rotatedPillSmtPad.test.ts +48 -0
- package/tests/examples/addSmtPad/rotatedRectSmtPad.test.ts +59 -0
package/dist/index.js
CHANGED
|
@@ -1,10 +1,576 @@
|
|
|
1
1
|
// lib/index.ts
|
|
2
|
-
import { LightBurnProject, CutSetting, ShapePath as
|
|
2
|
+
import { LightBurnProject, CutSetting, ShapePath as ShapePath15 } from "lbrnts";
|
|
3
3
|
import { cju as cju2 } from "@tscircuit/circuit-json-util";
|
|
4
4
|
|
|
5
5
|
// lib/element-handlers/addPlatedHole/addCirclePlatedHole.ts
|
|
6
6
|
import { ShapePath } from "lbrnts";
|
|
7
7
|
|
|
8
|
+
// lib/helpers/circleShape.ts
|
|
9
|
+
var createCirclePath = (centerX, centerY, radius, segments = 64) => {
|
|
10
|
+
const verts = [];
|
|
11
|
+
const prims = [];
|
|
12
|
+
for (let i = 0; i < segments; i++) {
|
|
13
|
+
const angle = i / segments * Math.PI * 2;
|
|
14
|
+
const x = centerX + radius * Math.cos(angle);
|
|
15
|
+
const y = centerY + radius * Math.sin(angle);
|
|
16
|
+
verts.push({ x, y });
|
|
17
|
+
prims.push({ type: 0 });
|
|
18
|
+
}
|
|
19
|
+
if (verts.length > 0) {
|
|
20
|
+
const firstVert = verts[0];
|
|
21
|
+
if (firstVert) {
|
|
22
|
+
verts.push({ ...firstVert });
|
|
23
|
+
prims.push({ type: 0 });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { verts, prims };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// lib/element-handlers/addPlatedHole/addCirclePlatedHole.ts
|
|
30
|
+
var addCirclePlatedHole = (platedHole, ctx) => {
|
|
31
|
+
const { project, copperCutSetting, throughBoardCutSetting, origin } = ctx;
|
|
32
|
+
const centerX = platedHole.x + origin.x;
|
|
33
|
+
const centerY = platedHole.y + origin.y;
|
|
34
|
+
if (platedHole.outer_diameter > 0) {
|
|
35
|
+
const outerRadius = platedHole.outer_diameter / 2;
|
|
36
|
+
const outer = createCirclePath(centerX, centerY, outerRadius);
|
|
37
|
+
project.children.push(
|
|
38
|
+
new ShapePath({
|
|
39
|
+
cutIndex: copperCutSetting.index,
|
|
40
|
+
verts: outer.verts,
|
|
41
|
+
prims: outer.prims,
|
|
42
|
+
isClosed: true
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (platedHole.hole_diameter > 0) {
|
|
47
|
+
const innerRadius = platedHole.hole_diameter / 2;
|
|
48
|
+
const inner = createCirclePath(centerX, centerY, innerRadius);
|
|
49
|
+
project.children.push(
|
|
50
|
+
new ShapePath({
|
|
51
|
+
cutIndex: throughBoardCutSetting.index,
|
|
52
|
+
verts: inner.verts,
|
|
53
|
+
prims: inner.prims,
|
|
54
|
+
isClosed: true
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// lib/element-handlers/addPlatedHole/addOvalPlatedHole.ts
|
|
61
|
+
import { ShapePath as ShapePath2 } from "lbrnts";
|
|
62
|
+
|
|
63
|
+
// lib/helpers/ovalShape.ts
|
|
64
|
+
var createOvalPath = (centerX, centerY, width, height, rotation = 0, segments = 64) => {
|
|
65
|
+
const verts = [];
|
|
66
|
+
const prims = [];
|
|
67
|
+
const radiusX = width / 2;
|
|
68
|
+
const radiusY = height / 2;
|
|
69
|
+
const cosTheta = Math.cos(rotation);
|
|
70
|
+
const sinTheta = Math.sin(rotation);
|
|
71
|
+
for (let i = 0; i < segments; i++) {
|
|
72
|
+
const angle = i / segments * Math.PI * 2;
|
|
73
|
+
const localX = radiusX * Math.cos(angle);
|
|
74
|
+
const localY = radiusY * Math.sin(angle);
|
|
75
|
+
const rotatedX = centerX + localX * cosTheta - localY * sinTheta;
|
|
76
|
+
const rotatedY = centerY + localX * sinTheta + localY * cosTheta;
|
|
77
|
+
verts.push({ x: rotatedX, y: rotatedY });
|
|
78
|
+
prims.push({ type: 0 });
|
|
79
|
+
}
|
|
80
|
+
if (verts.length > 0) {
|
|
81
|
+
const firstVert = verts[0];
|
|
82
|
+
if (firstVert) {
|
|
83
|
+
verts.push({ ...firstVert });
|
|
84
|
+
prims.push({ type: 0 });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { verts, prims };
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// lib/element-handlers/addPlatedHole/addOvalPlatedHole.ts
|
|
91
|
+
var addOvalPlatedHole = (platedHole, ctx) => {
|
|
92
|
+
const { project, copperCutSetting, throughBoardCutSetting, origin } = ctx;
|
|
93
|
+
if (platedHole.outer_width <= 0 || platedHole.outer_height <= 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const centerX = platedHole.x + origin.x;
|
|
97
|
+
const centerY = platedHole.y + origin.y;
|
|
98
|
+
const rotation = (platedHole.ccw_rotation ?? 0) * (Math.PI / 180);
|
|
99
|
+
if (platedHole.outer_width > 0 && platedHole.outer_height > 0) {
|
|
100
|
+
const outer = createOvalPath(
|
|
101
|
+
centerX,
|
|
102
|
+
centerY,
|
|
103
|
+
platedHole.outer_width,
|
|
104
|
+
platedHole.outer_height,
|
|
105
|
+
rotation
|
|
106
|
+
);
|
|
107
|
+
project.children.push(
|
|
108
|
+
new ShapePath2({
|
|
109
|
+
cutIndex: copperCutSetting.index,
|
|
110
|
+
verts: outer.verts,
|
|
111
|
+
prims: outer.prims,
|
|
112
|
+
isClosed: true
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (platedHole.hole_width > 0 && platedHole.hole_height > 0) {
|
|
117
|
+
const inner = createOvalPath(
|
|
118
|
+
centerX,
|
|
119
|
+
centerY,
|
|
120
|
+
platedHole.hole_width,
|
|
121
|
+
platedHole.hole_height,
|
|
122
|
+
rotation
|
|
123
|
+
);
|
|
124
|
+
project.children.push(
|
|
125
|
+
new ShapePath2({
|
|
126
|
+
cutIndex: throughBoardCutSetting.index,
|
|
127
|
+
verts: inner.verts,
|
|
128
|
+
prims: inner.prims,
|
|
129
|
+
isClosed: true
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// lib/element-handlers/addPlatedHole/addCircularHoleWithRectPad.ts
|
|
136
|
+
import { ShapePath as ShapePath3 } from "lbrnts";
|
|
137
|
+
|
|
138
|
+
// lib/helpers/roundedRectShape.ts
|
|
139
|
+
var createRoundedRectPath = (centerX, centerY, width, height, borderRadius = 0, segments = 4, rotation = 0) => {
|
|
140
|
+
const verts = [];
|
|
141
|
+
const prims = [];
|
|
142
|
+
const halfWidth = width / 2;
|
|
143
|
+
const halfHeight = height / 2;
|
|
144
|
+
const rotatePoint = (x, y) => {
|
|
145
|
+
const cos = Math.cos(rotation);
|
|
146
|
+
const sin = Math.sin(rotation);
|
|
147
|
+
return {
|
|
148
|
+
x: x * cos - y * sin,
|
|
149
|
+
y: x * sin + y * cos
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const addPoint = (x, y) => {
|
|
153
|
+
const rotated = rotation ? rotatePoint(x, y) : { x, y };
|
|
154
|
+
verts.push({ x: centerX + rotated.x, y: centerY + rotated.y });
|
|
155
|
+
prims.push({ type: 0 });
|
|
156
|
+
};
|
|
157
|
+
addPoint(-halfWidth + borderRadius, -halfHeight);
|
|
158
|
+
addPoint(halfWidth - borderRadius, -halfHeight);
|
|
159
|
+
if (borderRadius > 0) {
|
|
160
|
+
for (let i = 0; i <= segments; i++) {
|
|
161
|
+
const angle = Math.PI * 1.5 + i * Math.PI * 0.5 / segments;
|
|
162
|
+
addPoint(
|
|
163
|
+
halfWidth - borderRadius + Math.cos(angle) * borderRadius,
|
|
164
|
+
-halfHeight + borderRadius + Math.sin(angle) * borderRadius
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
addPoint(halfWidth, -halfHeight);
|
|
169
|
+
}
|
|
170
|
+
addPoint(halfWidth, -halfHeight + borderRadius);
|
|
171
|
+
addPoint(halfWidth, halfHeight - borderRadius);
|
|
172
|
+
if (borderRadius > 0) {
|
|
173
|
+
for (let i = 0; i <= segments; i++) {
|
|
174
|
+
const angle = i * Math.PI * 0.5 / segments;
|
|
175
|
+
addPoint(
|
|
176
|
+
halfWidth - borderRadius + Math.cos(angle) * borderRadius,
|
|
177
|
+
halfHeight - borderRadius + Math.sin(angle) * borderRadius
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
addPoint(halfWidth, halfHeight);
|
|
182
|
+
}
|
|
183
|
+
addPoint(halfWidth - borderRadius, halfHeight);
|
|
184
|
+
addPoint(-halfWidth + borderRadius, halfHeight);
|
|
185
|
+
if (borderRadius > 0) {
|
|
186
|
+
for (let i = 0; i <= segments; i++) {
|
|
187
|
+
const angle = Math.PI * 0.5 + i * Math.PI * 0.5 / segments;
|
|
188
|
+
addPoint(
|
|
189
|
+
-halfWidth + borderRadius + Math.cos(angle) * borderRadius,
|
|
190
|
+
halfHeight - borderRadius + Math.sin(angle) * borderRadius
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
addPoint(-halfWidth, halfHeight);
|
|
195
|
+
}
|
|
196
|
+
addPoint(-halfWidth, halfHeight - borderRadius);
|
|
197
|
+
addPoint(-halfWidth, -halfHeight + borderRadius);
|
|
198
|
+
if (borderRadius > 0) {
|
|
199
|
+
for (let i = 0; i <= segments; i++) {
|
|
200
|
+
const angle = Math.PI + i * Math.PI * 0.5 / segments;
|
|
201
|
+
addPoint(
|
|
202
|
+
-halfWidth + borderRadius + Math.cos(angle) * borderRadius,
|
|
203
|
+
-halfHeight + borderRadius + Math.sin(angle) * borderRadius
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
addPoint(-halfWidth, -halfHeight);
|
|
208
|
+
}
|
|
209
|
+
if (verts.length > 0) {
|
|
210
|
+
const firstVert = verts[0];
|
|
211
|
+
if (firstVert) {
|
|
212
|
+
verts.push({ ...firstVert });
|
|
213
|
+
prims.push({ type: 0 });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return { verts, prims };
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// lib/element-handlers/addPlatedHole/addCircularHoleWithRectPad.ts
|
|
220
|
+
var addCircularHoleWithRectPad = (platedHole, ctx) => {
|
|
221
|
+
const { project, copperCutSetting, throughBoardCutSetting, origin } = ctx;
|
|
222
|
+
const centerX = platedHole.x + origin.x;
|
|
223
|
+
const centerY = platedHole.y + origin.y;
|
|
224
|
+
const holeRadius = platedHole.hole_diameter / 2;
|
|
225
|
+
const padWidth = platedHole.rect_pad_width;
|
|
226
|
+
const padHeight = platedHole.rect_pad_height;
|
|
227
|
+
const borderRadius = platedHole.rect_border_radius ?? 0;
|
|
228
|
+
const padPath = createRoundedRectPath(
|
|
229
|
+
centerX,
|
|
230
|
+
centerY,
|
|
231
|
+
padWidth,
|
|
232
|
+
padHeight,
|
|
233
|
+
borderRadius
|
|
234
|
+
);
|
|
235
|
+
project.children.push(
|
|
236
|
+
new ShapePath3({
|
|
237
|
+
cutIndex: copperCutSetting.index,
|
|
238
|
+
verts: padPath.verts,
|
|
239
|
+
prims: padPath.prims,
|
|
240
|
+
isClosed: true
|
|
241
|
+
})
|
|
242
|
+
);
|
|
243
|
+
if (holeRadius > 0) {
|
|
244
|
+
const holeCenterX = centerX + platedHole.hole_offset_x;
|
|
245
|
+
const holeCenterY = centerY + platedHole.hole_offset_y;
|
|
246
|
+
const holePath = createCirclePath(holeCenterX, holeCenterY, holeRadius, 32);
|
|
247
|
+
project.children.push(
|
|
248
|
+
new ShapePath3({
|
|
249
|
+
cutIndex: throughBoardCutSetting.index,
|
|
250
|
+
verts: holePath.verts,
|
|
251
|
+
prims: holePath.prims,
|
|
252
|
+
isClosed: true
|
|
253
|
+
})
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// lib/element-handlers/addPlatedHole/addPillHoleWithRectPad.ts
|
|
259
|
+
import { ShapePath as ShapePath4 } from "lbrnts";
|
|
260
|
+
|
|
261
|
+
// lib/helpers/pathPointUtils.ts
|
|
262
|
+
var createPointAdder = (verts, prims, options = {}) => {
|
|
263
|
+
const { rotation = 0, rotationCenter, translation } = options;
|
|
264
|
+
const cos = Math.cos(rotation);
|
|
265
|
+
const sin = Math.sin(rotation);
|
|
266
|
+
const effectiveCenter = rotationCenter ?? translation ?? { x: 0, y: 0 };
|
|
267
|
+
return (x, y) => {
|
|
268
|
+
let px = x;
|
|
269
|
+
let py = y;
|
|
270
|
+
if (rotation) {
|
|
271
|
+
const cx = effectiveCenter.x;
|
|
272
|
+
const cy = effectiveCenter.y;
|
|
273
|
+
const dx = px - cx;
|
|
274
|
+
const dy = py - cy;
|
|
275
|
+
px = cx + dx * cos - dy * sin;
|
|
276
|
+
py = cy + dx * sin + dy * cos;
|
|
277
|
+
}
|
|
278
|
+
const tx = translation?.x ?? 0;
|
|
279
|
+
const ty = translation?.y ?? 0;
|
|
280
|
+
verts.push({ x: px + tx, y: py + ty });
|
|
281
|
+
prims.push({ type: 0 });
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// lib/helpers/pillShape.ts
|
|
286
|
+
var createPillPath = (centerX, centerY, width, height, rotation = 0, segments = 32) => {
|
|
287
|
+
const verts = [];
|
|
288
|
+
const prims = [];
|
|
289
|
+
const halfWidth = width / 2;
|
|
290
|
+
const halfHeight = height / 2;
|
|
291
|
+
const radius = Math.min(halfWidth, halfHeight);
|
|
292
|
+
const isVertical = height > width;
|
|
293
|
+
const addPoint = createPointAdder(verts, prims, {
|
|
294
|
+
rotation,
|
|
295
|
+
rotationCenter: { x: centerX, y: centerY }
|
|
296
|
+
});
|
|
297
|
+
if (isVertical) {
|
|
298
|
+
const capOffset = halfHeight - radius;
|
|
299
|
+
for (let i = 0; i <= segments; i++) {
|
|
300
|
+
const angle = Math.PI + i / segments * Math.PI;
|
|
301
|
+
const x = centerX + radius * Math.cos(angle);
|
|
302
|
+
const y = centerY - capOffset + radius * Math.sin(angle);
|
|
303
|
+
addPoint(x, y);
|
|
304
|
+
}
|
|
305
|
+
addPoint(centerX + radius, centerY + capOffset);
|
|
306
|
+
for (let i = 0; i <= segments; i++) {
|
|
307
|
+
const angle = i / segments * Math.PI;
|
|
308
|
+
const x = centerX + radius * Math.cos(angle);
|
|
309
|
+
const y = centerY + capOffset + radius * Math.sin(angle);
|
|
310
|
+
addPoint(x, y);
|
|
311
|
+
}
|
|
312
|
+
addPoint(centerX - radius, centerY - capOffset);
|
|
313
|
+
} else {
|
|
314
|
+
const capOffset = halfWidth - radius;
|
|
315
|
+
for (let i = 0; i <= segments; i++) {
|
|
316
|
+
const angle = -Math.PI / 2 + i / segments * Math.PI;
|
|
317
|
+
const x = centerX + capOffset + radius * Math.cos(angle);
|
|
318
|
+
const y = centerY + radius * Math.sin(angle);
|
|
319
|
+
addPoint(x, y);
|
|
320
|
+
}
|
|
321
|
+
addPoint(centerX - capOffset, centerY + radius);
|
|
322
|
+
for (let i = 0; i <= segments; i++) {
|
|
323
|
+
const angle = Math.PI / 2 + i / segments * Math.PI;
|
|
324
|
+
const x = centerX - capOffset + radius * Math.cos(angle);
|
|
325
|
+
const y = centerY + radius * Math.sin(angle);
|
|
326
|
+
addPoint(x, y);
|
|
327
|
+
}
|
|
328
|
+
addPoint(centerX + capOffset, centerY - radius);
|
|
329
|
+
}
|
|
330
|
+
if (verts.length > 0) {
|
|
331
|
+
const firstVert = verts[0];
|
|
332
|
+
if (firstVert) {
|
|
333
|
+
verts.push({ ...firstVert });
|
|
334
|
+
prims.push({ type: 0 });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return { verts, prims };
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// lib/element-handlers/addPlatedHole/addPillHoleWithRectPad.ts
|
|
341
|
+
var addPillHoleWithRectPad = (platedHole, ctx) => {
|
|
342
|
+
const { project, copperCutSetting, throughBoardCutSetting, origin } = ctx;
|
|
343
|
+
const centerX = platedHole.x + origin.x;
|
|
344
|
+
const centerY = platedHole.y + origin.y;
|
|
345
|
+
const padWidth = platedHole.rect_pad_width;
|
|
346
|
+
const padHeight = platedHole.rect_pad_height;
|
|
347
|
+
const borderRadius = platedHole.rect_border_radius ?? 0;
|
|
348
|
+
if (padWidth > 0 && padHeight > 0) {
|
|
349
|
+
const padPath = createRoundedRectPath(
|
|
350
|
+
centerX,
|
|
351
|
+
centerY,
|
|
352
|
+
padWidth,
|
|
353
|
+
padHeight,
|
|
354
|
+
borderRadius
|
|
355
|
+
);
|
|
356
|
+
project.children.push(
|
|
357
|
+
new ShapePath4({
|
|
358
|
+
cutIndex: copperCutSetting.index,
|
|
359
|
+
verts: padPath.verts,
|
|
360
|
+
prims: padPath.prims,
|
|
361
|
+
isClosed: true
|
|
362
|
+
})
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
const holeWidth = platedHole.hole_width;
|
|
366
|
+
const holeHeight = platedHole.hole_height;
|
|
367
|
+
if (holeWidth > 0 && holeHeight > 0) {
|
|
368
|
+
const holeCenterX = centerX + platedHole.hole_offset_x;
|
|
369
|
+
const holeCenterY = centerY + platedHole.hole_offset_y;
|
|
370
|
+
const holePath = createPillPath(
|
|
371
|
+
holeCenterX,
|
|
372
|
+
holeCenterY,
|
|
373
|
+
holeWidth,
|
|
374
|
+
holeHeight
|
|
375
|
+
);
|
|
376
|
+
project.children.push(
|
|
377
|
+
new ShapePath4({
|
|
378
|
+
cutIndex: throughBoardCutSetting.index,
|
|
379
|
+
verts: holePath.verts,
|
|
380
|
+
prims: holePath.prims,
|
|
381
|
+
isClosed: true
|
|
382
|
+
})
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
// lib/element-handlers/addPlatedHole/addRotatedPillHoleWithRectPad.ts
|
|
388
|
+
import { ShapePath as ShapePath5 } from "lbrnts";
|
|
389
|
+
var addRotatedPillHoleWithRectPad = (platedHole, ctx) => {
|
|
390
|
+
const { project, copperCutSetting, throughBoardCutSetting, origin } = ctx;
|
|
391
|
+
const centerX = platedHole.x + origin.x;
|
|
392
|
+
const centerY = platedHole.y + origin.y;
|
|
393
|
+
const padWidth = platedHole.rect_pad_width;
|
|
394
|
+
const padHeight = platedHole.rect_pad_height;
|
|
395
|
+
const borderRadius = platedHole.rect_border_radius ?? 0;
|
|
396
|
+
const padRotation = (platedHole.rect_ccw_rotation ?? 0) * (Math.PI / 180);
|
|
397
|
+
if (padWidth > 0 && padHeight > 0) {
|
|
398
|
+
const padPath = createRoundedRectPath(
|
|
399
|
+
centerX,
|
|
400
|
+
centerY,
|
|
401
|
+
padWidth,
|
|
402
|
+
padHeight,
|
|
403
|
+
borderRadius,
|
|
404
|
+
4,
|
|
405
|
+
padRotation
|
|
406
|
+
);
|
|
407
|
+
project.children.push(
|
|
408
|
+
new ShapePath5({
|
|
409
|
+
cutIndex: copperCutSetting.index,
|
|
410
|
+
verts: padPath.verts,
|
|
411
|
+
prims: padPath.prims,
|
|
412
|
+
isClosed: true
|
|
413
|
+
})
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
const holeWidth = platedHole.hole_width;
|
|
417
|
+
const holeHeight = platedHole.hole_height;
|
|
418
|
+
const holeRotation = (platedHole.hole_ccw_rotation ?? 0) * (Math.PI / 180);
|
|
419
|
+
if (holeWidth > 0 && holeHeight > 0) {
|
|
420
|
+
const holeCenterX = centerX + platedHole.hole_offset_x;
|
|
421
|
+
const holeCenterY = centerY + platedHole.hole_offset_y;
|
|
422
|
+
const holePath = createPillPath(
|
|
423
|
+
holeCenterX,
|
|
424
|
+
holeCenterY,
|
|
425
|
+
holeWidth,
|
|
426
|
+
holeHeight,
|
|
427
|
+
holeRotation
|
|
428
|
+
);
|
|
429
|
+
project.children.push(
|
|
430
|
+
new ShapePath5({
|
|
431
|
+
cutIndex: throughBoardCutSetting.index,
|
|
432
|
+
verts: holePath.verts,
|
|
433
|
+
prims: holePath.prims,
|
|
434
|
+
isClosed: true
|
|
435
|
+
})
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// lib/element-handlers/addPlatedHole/addHoleWithPolygonPad.ts
|
|
441
|
+
import { ShapePath as ShapePath6 } from "lbrnts";
|
|
442
|
+
|
|
443
|
+
// lib/helpers/polygonShape.ts
|
|
444
|
+
var createPolygonPathFromOutline = (outline, offsetX, offsetY) => {
|
|
445
|
+
const verts = [];
|
|
446
|
+
for (const point2 of outline) {
|
|
447
|
+
const x = (point2.x ?? 0) + offsetX;
|
|
448
|
+
const y = (point2.y ?? 0) + offsetY;
|
|
449
|
+
verts.push({ x, y });
|
|
450
|
+
}
|
|
451
|
+
if (verts.length === 0) {
|
|
452
|
+
return { verts, prims: [] };
|
|
453
|
+
}
|
|
454
|
+
const first = verts[0];
|
|
455
|
+
verts.push({ x: first.x, y: first.y });
|
|
456
|
+
const prims = new Array(verts.length).fill({ type: 0 });
|
|
457
|
+
return { verts, prims };
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
// lib/element-handlers/addPlatedHole/addHoleWithPolygonPad.ts
|
|
461
|
+
var addHoleWithPolygonPad = (platedHole, ctx) => {
|
|
462
|
+
const { project, copperCutSetting, throughBoardCutSetting, origin } = ctx;
|
|
463
|
+
if (platedHole.pad_outline.length >= 3) {
|
|
464
|
+
const pad = createPolygonPathFromOutline(
|
|
465
|
+
platedHole.pad_outline,
|
|
466
|
+
platedHole.x + origin.x,
|
|
467
|
+
platedHole.y + origin.y
|
|
468
|
+
);
|
|
469
|
+
project.children.push(
|
|
470
|
+
new ShapePath6({
|
|
471
|
+
cutIndex: copperCutSetting.index,
|
|
472
|
+
verts: pad.verts,
|
|
473
|
+
prims: pad.prims,
|
|
474
|
+
isClosed: true
|
|
475
|
+
})
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
if (platedHole.hole_shape === "circle" && platedHole.hole_diameter) {
|
|
479
|
+
const centerX = platedHole.x + platedHole.hole_offset_x + origin.x;
|
|
480
|
+
const centerY = platedHole.y + platedHole.hole_offset_y + origin.y;
|
|
481
|
+
const radius = platedHole.hole_diameter / 2;
|
|
482
|
+
const hole = createCirclePath(centerX, centerY, radius, 64);
|
|
483
|
+
project.children.push(
|
|
484
|
+
new ShapePath6({
|
|
485
|
+
cutIndex: throughBoardCutSetting.index,
|
|
486
|
+
verts: hole.verts,
|
|
487
|
+
prims: hole.prims,
|
|
488
|
+
isClosed: true
|
|
489
|
+
})
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
if (platedHole.hole_shape === "pill" && platedHole.hole_diameter) {
|
|
493
|
+
const centerX = platedHole.x + platedHole.hole_offset_x + origin.x;
|
|
494
|
+
const centerY = platedHole.y + platedHole.hole_offset_y + origin.y;
|
|
495
|
+
const radius = platedHole.hole_diameter / 2;
|
|
496
|
+
const hole = createCirclePath(centerX, centerY, radius, 64);
|
|
497
|
+
project.children.push(
|
|
498
|
+
new ShapePath6({
|
|
499
|
+
cutIndex: throughBoardCutSetting.index,
|
|
500
|
+
verts: hole.verts,
|
|
501
|
+
prims: hole.prims,
|
|
502
|
+
isClosed: true
|
|
503
|
+
})
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// lib/element-handlers/addPlatedHole/addPillPlatedHole.ts
|
|
509
|
+
import { ShapePath as ShapePath7 } from "lbrnts";
|
|
510
|
+
var addPcbPlatedHolePill = (platedHole, ctx) => {
|
|
511
|
+
const { project, copperCutSetting, throughBoardCutSetting, origin } = ctx;
|
|
512
|
+
const centerX = platedHole.x + origin.x;
|
|
513
|
+
const centerY = platedHole.y + origin.y;
|
|
514
|
+
const rotation = (platedHole.ccw_rotation || 0) * (Math.PI / 180);
|
|
515
|
+
if (platedHole.outer_width > 0 && platedHole.outer_height > 0) {
|
|
516
|
+
const outer = createPillPath(
|
|
517
|
+
centerX,
|
|
518
|
+
centerY,
|
|
519
|
+
platedHole.outer_width,
|
|
520
|
+
platedHole.outer_height,
|
|
521
|
+
rotation
|
|
522
|
+
);
|
|
523
|
+
project.children.push(
|
|
524
|
+
new ShapePath7({
|
|
525
|
+
cutIndex: copperCutSetting.index,
|
|
526
|
+
verts: outer.verts,
|
|
527
|
+
prims: outer.prims,
|
|
528
|
+
isClosed: true
|
|
529
|
+
})
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
if (platedHole.hole_width > 0 && platedHole.hole_height > 0) {
|
|
533
|
+
const inner = createPillPath(
|
|
534
|
+
centerX,
|
|
535
|
+
centerY,
|
|
536
|
+
platedHole.hole_width,
|
|
537
|
+
platedHole.hole_height,
|
|
538
|
+
rotation
|
|
539
|
+
);
|
|
540
|
+
project.children.push(
|
|
541
|
+
new ShapePath7({
|
|
542
|
+
cutIndex: throughBoardCutSetting.index,
|
|
543
|
+
verts: inner.verts,
|
|
544
|
+
prims: inner.prims,
|
|
545
|
+
isClosed: true
|
|
546
|
+
})
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
// lib/element-handlers/addPlatedHole/index.ts
|
|
552
|
+
var addPlatedHole = (platedHole, ctx) => {
|
|
553
|
+
switch (platedHole.shape) {
|
|
554
|
+
case "circle":
|
|
555
|
+
return addCirclePlatedHole(platedHole, ctx);
|
|
556
|
+
case "oval":
|
|
557
|
+
return addOvalPlatedHole(platedHole, ctx);
|
|
558
|
+
case "pill":
|
|
559
|
+
return addPcbPlatedHolePill(platedHole, ctx);
|
|
560
|
+
case "circular_hole_with_rect_pad":
|
|
561
|
+
return addCircularHoleWithRectPad(platedHole, ctx);
|
|
562
|
+
case "pill_hole_with_rect_pad":
|
|
563
|
+
return addPillHoleWithRectPad(platedHole, ctx);
|
|
564
|
+
case "rotated_pill_hole_with_rect_pad":
|
|
565
|
+
return addRotatedPillHoleWithRectPad(platedHole, ctx);
|
|
566
|
+
case "hole_with_polygon_pad":
|
|
567
|
+
return addHoleWithPolygonPad(platedHole, ctx);
|
|
568
|
+
default:
|
|
569
|
+
const _exhaustive = platedHole;
|
|
570
|
+
console.warn(`Unknown plated hole shape: ${platedHole.shape}`);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
|
|
8
574
|
// lib/element-handlers/addSmtPad/addRectSmtPad.ts
|
|
9
575
|
import { Box } from "@flatten-js/core";
|
|
10
576
|
import "lbrnts";
|
|
@@ -25,16 +591,134 @@ var addRectSmtPad = (smtPad, ctx) => {
|
|
|
25
591
|
);
|
|
26
592
|
};
|
|
27
593
|
|
|
594
|
+
// lib/element-handlers/addSmtPad/addCircleSmtPad.ts
|
|
595
|
+
import { ShapePath as ShapePath9 } from "lbrnts";
|
|
596
|
+
var addCircleSmtPad = (smtPad, ctx) => {
|
|
597
|
+
const { project, copperCutSetting, origin } = ctx;
|
|
598
|
+
const centerX = smtPad.x + origin.x;
|
|
599
|
+
const centerY = smtPad.y + origin.y;
|
|
600
|
+
if (smtPad.radius > 0) {
|
|
601
|
+
const outerRadius = smtPad.radius;
|
|
602
|
+
const outer = createCirclePath(centerX, centerY, outerRadius);
|
|
603
|
+
project.children.push(
|
|
604
|
+
new ShapePath9({
|
|
605
|
+
cutIndex: copperCutSetting.index,
|
|
606
|
+
verts: outer.verts,
|
|
607
|
+
prims: outer.prims,
|
|
608
|
+
isClosed: true
|
|
609
|
+
})
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
// lib/element-handlers/addSmtPad/addPillSmtPad.ts
|
|
615
|
+
import { ShapePath as ShapePath10 } from "lbrnts";
|
|
616
|
+
var addPillSmtPad = (smtPad, ctx) => {
|
|
617
|
+
const { project, copperCutSetting, origin } = ctx;
|
|
618
|
+
const centerX = smtPad.x + origin.x;
|
|
619
|
+
const centerY = smtPad.y + origin.y;
|
|
620
|
+
if (smtPad.width > 0 && smtPad.height > 0) {
|
|
621
|
+
const outer = createPillPath(centerX, centerY, smtPad.width, smtPad.height);
|
|
622
|
+
project.children.push(
|
|
623
|
+
new ShapePath10({
|
|
624
|
+
cutIndex: copperCutSetting.index,
|
|
625
|
+
verts: outer.verts,
|
|
626
|
+
prims: outer.prims,
|
|
627
|
+
isClosed: true
|
|
628
|
+
})
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
// lib/element-handlers/addSmtPad/addRotatedPillSmtPad.ts
|
|
634
|
+
import { ShapePath as ShapePath11 } from "lbrnts";
|
|
635
|
+
var addRotatedPillSmtPad = (smtPad, ctx) => {
|
|
636
|
+
const { project, copperCutSetting, origin } = ctx;
|
|
637
|
+
const centerX = smtPad.x + origin.x;
|
|
638
|
+
const centerY = smtPad.y + origin.y;
|
|
639
|
+
const borderRadius = smtPad.radius ?? 0;
|
|
640
|
+
if (smtPad.width > 0 && smtPad.height > 0) {
|
|
641
|
+
const outer = createPillPath(
|
|
642
|
+
centerX,
|
|
643
|
+
centerY,
|
|
644
|
+
smtPad.width,
|
|
645
|
+
smtPad.height,
|
|
646
|
+
(smtPad.ccw_rotation ?? 0) * (Math.PI / 180)
|
|
647
|
+
);
|
|
648
|
+
project.children.push(
|
|
649
|
+
new ShapePath11({
|
|
650
|
+
cutIndex: copperCutSetting.index,
|
|
651
|
+
verts: outer.verts,
|
|
652
|
+
prims: outer.prims,
|
|
653
|
+
isClosed: true
|
|
654
|
+
})
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
// lib/element-handlers/addSmtPad/addPolygonSmtPad.ts
|
|
660
|
+
import { ShapePath as ShapePath12 } from "lbrnts";
|
|
661
|
+
var addPolygonSmtPad = (smtPad, ctx) => {
|
|
662
|
+
const { project, copperCutSetting, origin } = ctx;
|
|
663
|
+
if (smtPad.points.length >= 3) {
|
|
664
|
+
const pad = createPolygonPathFromOutline(smtPad.points, origin.x, origin.y);
|
|
665
|
+
project.children.push(
|
|
666
|
+
new ShapePath12({
|
|
667
|
+
cutIndex: copperCutSetting.index,
|
|
668
|
+
verts: pad.verts,
|
|
669
|
+
prims: pad.prims,
|
|
670
|
+
isClosed: true
|
|
671
|
+
})
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
// lib/element-handlers/addSmtPad/addRotatedRectSmtPad.ts
|
|
677
|
+
import { ShapePath as ShapePath13 } from "lbrnts";
|
|
678
|
+
var addRotatedRectSmtPad = (smtPad, ctx) => {
|
|
679
|
+
const { project, copperCutSetting, origin } = ctx;
|
|
680
|
+
const centerX = smtPad.x + origin.x;
|
|
681
|
+
const centerY = smtPad.y + origin.y;
|
|
682
|
+
const rotation = smtPad.ccw_rotation ?? 0;
|
|
683
|
+
const borderRadius = smtPad.rect_border_radius ?? 0;
|
|
684
|
+
if (smtPad.width > 0 && smtPad.height > 0) {
|
|
685
|
+
const outer = createRoundedRectPath(
|
|
686
|
+
centerX,
|
|
687
|
+
centerY,
|
|
688
|
+
smtPad.width,
|
|
689
|
+
smtPad.height,
|
|
690
|
+
borderRadius,
|
|
691
|
+
4,
|
|
692
|
+
rotation
|
|
693
|
+
);
|
|
694
|
+
project.children.push(
|
|
695
|
+
new ShapePath13({
|
|
696
|
+
cutIndex: copperCutSetting.index,
|
|
697
|
+
verts: outer.verts,
|
|
698
|
+
prims: outer.prims,
|
|
699
|
+
isClosed: true
|
|
700
|
+
})
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
|
|
28
705
|
// lib/element-handlers/addSmtPad/index.ts
|
|
29
706
|
var addSmtPad = (smtPad, ctx) => {
|
|
30
707
|
switch (smtPad.shape) {
|
|
31
|
-
case "rect":
|
|
32
|
-
addRectSmtPad(smtPad, ctx);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
708
|
+
case "rect":
|
|
709
|
+
return addRectSmtPad(smtPad, ctx);
|
|
710
|
+
case "circle":
|
|
711
|
+
return addCircleSmtPad(smtPad, ctx);
|
|
712
|
+
case "pill":
|
|
713
|
+
return addPillSmtPad(smtPad, ctx);
|
|
714
|
+
case "rotated_pill":
|
|
715
|
+
return addRotatedPillSmtPad(smtPad, ctx);
|
|
716
|
+
case "polygon":
|
|
717
|
+
return addPolygonSmtPad(smtPad, ctx);
|
|
718
|
+
case "rotated_rect":
|
|
719
|
+
return addRotatedRectSmtPad(smtPad, ctx);
|
|
720
|
+
default:
|
|
36
721
|
throw new Error(`Unknown smt pad shape: ${smtPad.shape}`);
|
|
37
|
-
}
|
|
38
722
|
}
|
|
39
723
|
};
|
|
40
724
|
|
|
@@ -119,7 +803,7 @@ var addPcbTrace = (trace, ctx) => {
|
|
|
119
803
|
|
|
120
804
|
// lib/element-handlers/addPcbBoard/index.ts
|
|
121
805
|
import { Polygon, point } from "@flatten-js/core";
|
|
122
|
-
import { ShapePath as
|
|
806
|
+
import { ShapePath as ShapePath14 } from "lbrnts";
|
|
123
807
|
|
|
124
808
|
// lib/polygon-to-shape-path.ts
|
|
125
809
|
function polygonToShapePathData(polygon) {
|
|
@@ -175,7 +859,7 @@ var addPcbBoard = (board, ctx) => {
|
|
|
175
859
|
if (!polygon) return;
|
|
176
860
|
const { verts, prims } = polygonToShapePathData(polygon);
|
|
177
861
|
project.children.push(
|
|
178
|
-
new
|
|
862
|
+
new ShapePath14({
|
|
179
863
|
cutIndex: throughBoardCutSetting.index,
|
|
180
864
|
verts,
|
|
181
865
|
prims,
|
|
@@ -286,6 +970,9 @@ var convertCircuitJsonToLbrn = (circuitJson, options = {}) => {
|
|
|
286
970
|
for (const smtpad of db.pcb_smtpad.list()) {
|
|
287
971
|
addSmtPad(smtpad, ctx);
|
|
288
972
|
}
|
|
973
|
+
for (const platedHole of db.pcb_plated_hole.list()) {
|
|
974
|
+
addPlatedHole(platedHole, ctx);
|
|
975
|
+
}
|
|
289
976
|
for (const trace of db.pcb_trace.list()) {
|
|
290
977
|
addPcbTrace(trace, ctx);
|
|
291
978
|
}
|
|
@@ -311,7 +998,7 @@ var convertCircuitJsonToLbrn = (circuitJson, options = {}) => {
|
|
|
311
998
|
for (const island of union.splitToIslands()) {
|
|
312
999
|
const { verts, prims } = polygonToShapePathData(island);
|
|
313
1000
|
project.children.push(
|
|
314
|
-
new
|
|
1001
|
+
new ShapePath15({
|
|
315
1002
|
cutIndex: copperCutSetting.index,
|
|
316
1003
|
verts,
|
|
317
1004
|
prims,
|