circuit-json-to-kicad 0.0.16 → 0.0.17
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 +144 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1349,8 +1349,133 @@ var AddNetsStage = class extends ConverterStage {
|
|
|
1349
1349
|
};
|
|
1350
1350
|
|
|
1351
1351
|
// lib/pcb/stages/AddFootprintsStage.ts
|
|
1352
|
-
import { Footprint, FpText
|
|
1352
|
+
import { Footprint, FpText } from "kicadts";
|
|
1353
1353
|
import { applyToPoint as applyToPoint5 } from "transformation-matrix";
|
|
1354
|
+
|
|
1355
|
+
// lib/pcb/stages/utils/CreateSmdPadFromCircuitJson.ts
|
|
1356
|
+
import { FootprintPad } from "kicadts";
|
|
1357
|
+
function createSmdPadFromCircuitJson({
|
|
1358
|
+
pcbPad,
|
|
1359
|
+
componentCenter,
|
|
1360
|
+
padNumber
|
|
1361
|
+
}) {
|
|
1362
|
+
if (!("x" in pcbPad && "y" in pcbPad)) {
|
|
1363
|
+
throw new Error("no support for polygon pads (or any pads w/o X/Y) yet");
|
|
1364
|
+
}
|
|
1365
|
+
const relativeX = pcbPad.x - componentCenter.x;
|
|
1366
|
+
const relativeY = pcbPad.y - componentCenter.y;
|
|
1367
|
+
const layerMap = {
|
|
1368
|
+
top: "F.Cu",
|
|
1369
|
+
bottom: "B.Cu"
|
|
1370
|
+
};
|
|
1371
|
+
const padLayer = layerMap[pcbPad.layer] || "F.Cu";
|
|
1372
|
+
const padShape = pcbPad.shape === "circle" ? "circle" : "rect";
|
|
1373
|
+
const padSize = pcbPad.shape === "circle" ? [
|
|
1374
|
+
"radius" in pcbPad ? pcbPad.radius * 2 : 0.5,
|
|
1375
|
+
"radius" in pcbPad ? pcbPad.radius * 2 : 0.5
|
|
1376
|
+
] : [
|
|
1377
|
+
"width" in pcbPad ? pcbPad.width : 0.5,
|
|
1378
|
+
"height" in pcbPad ? pcbPad.height : 0.5
|
|
1379
|
+
];
|
|
1380
|
+
return new FootprintPad({
|
|
1381
|
+
number: String(padNumber),
|
|
1382
|
+
padType: "smd",
|
|
1383
|
+
shape: padShape,
|
|
1384
|
+
at: [relativeX, relativeY, 0],
|
|
1385
|
+
size: padSize,
|
|
1386
|
+
layers: [
|
|
1387
|
+
`${padLayer}`,
|
|
1388
|
+
`${padLayer === "F.Cu" ? "F" : "B"}.Paste`,
|
|
1389
|
+
`${padLayer === "F.Cu" ? "F" : "B"}.Mask`
|
|
1390
|
+
],
|
|
1391
|
+
uuid: crypto.randomUUID()
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
// lib/pcb/stages/utils/CreateThruHolePadFromCircuitJson.ts
|
|
1396
|
+
import { FootprintPad as FootprintPad2, PadDrill } from "kicadts";
|
|
1397
|
+
function createThruHolePadFromCircuitJson({
|
|
1398
|
+
platedHole,
|
|
1399
|
+
componentCenter,
|
|
1400
|
+
padNumber
|
|
1401
|
+
}) {
|
|
1402
|
+
if (!("x" in platedHole && "y" in platedHole)) {
|
|
1403
|
+
return null;
|
|
1404
|
+
}
|
|
1405
|
+
const relativeX = platedHole.x - componentCenter.x;
|
|
1406
|
+
const relativeY = platedHole.y - componentCenter.y;
|
|
1407
|
+
let padShape = "circle";
|
|
1408
|
+
let padSize;
|
|
1409
|
+
let drill;
|
|
1410
|
+
let rotation = 0;
|
|
1411
|
+
if (platedHole.shape === "circle") {
|
|
1412
|
+
padShape = "circle";
|
|
1413
|
+
padSize = [platedHole.outer_diameter, platedHole.outer_diameter];
|
|
1414
|
+
drill = new PadDrill({
|
|
1415
|
+
diameter: platedHole.hole_diameter
|
|
1416
|
+
});
|
|
1417
|
+
} else if (platedHole.shape === "pill" || platedHole.shape === "oval") {
|
|
1418
|
+
padShape = "oval";
|
|
1419
|
+
padSize = [
|
|
1420
|
+
platedHole.outer_width,
|
|
1421
|
+
platedHole.outer_height
|
|
1422
|
+
];
|
|
1423
|
+
drill = new PadDrill({
|
|
1424
|
+
oval: true,
|
|
1425
|
+
diameter: platedHole.hole_width,
|
|
1426
|
+
width: platedHole.hole_height
|
|
1427
|
+
});
|
|
1428
|
+
} else if (platedHole.shape === "pill_hole_with_rect_pad") {
|
|
1429
|
+
padShape = "rect";
|
|
1430
|
+
padSize = [
|
|
1431
|
+
platedHole.rect_pad_width,
|
|
1432
|
+
platedHole.rect_pad_height
|
|
1433
|
+
];
|
|
1434
|
+
drill = new PadDrill({
|
|
1435
|
+
oval: true,
|
|
1436
|
+
diameter: platedHole.hole_width,
|
|
1437
|
+
width: platedHole.hole_height
|
|
1438
|
+
});
|
|
1439
|
+
} else if (platedHole.shape === "circular_hole_with_rect_pad") {
|
|
1440
|
+
padShape = "rect";
|
|
1441
|
+
padSize = [
|
|
1442
|
+
platedHole.rect_pad_width,
|
|
1443
|
+
platedHole.rect_pad_height
|
|
1444
|
+
];
|
|
1445
|
+
drill = new PadDrill({
|
|
1446
|
+
diameter: platedHole.hole_diameter
|
|
1447
|
+
});
|
|
1448
|
+
} else if (platedHole.shape === "rotated_pill_hole_with_rect_pad") {
|
|
1449
|
+
padShape = "rect";
|
|
1450
|
+
padSize = [
|
|
1451
|
+
platedHole.rect_pad_width,
|
|
1452
|
+
platedHole.rect_pad_height
|
|
1453
|
+
];
|
|
1454
|
+
drill = new PadDrill({
|
|
1455
|
+
oval: true,
|
|
1456
|
+
diameter: platedHole.hole_width,
|
|
1457
|
+
width: platedHole.hole_height
|
|
1458
|
+
});
|
|
1459
|
+
rotation = platedHole.rect_ccw_rotation || 0;
|
|
1460
|
+
} else {
|
|
1461
|
+
padShape = "circle";
|
|
1462
|
+
padSize = [1.6, 1.6];
|
|
1463
|
+
drill = new PadDrill({ diameter: 0.8 });
|
|
1464
|
+
}
|
|
1465
|
+
return new FootprintPad2({
|
|
1466
|
+
number: String(padNumber),
|
|
1467
|
+
padType: "thru_hole",
|
|
1468
|
+
shape: padShape,
|
|
1469
|
+
at: [relativeX, relativeY, rotation],
|
|
1470
|
+
size: padSize,
|
|
1471
|
+
drill,
|
|
1472
|
+
layers: ["*.Cu", "*.Mask"],
|
|
1473
|
+
removeUnusedLayers: false,
|
|
1474
|
+
uuid: crypto.randomUUID()
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
// lib/pcb/stages/AddFootprintsStage.ts
|
|
1354
1479
|
var AddFootprintsStage = class extends ConverterStage {
|
|
1355
1480
|
componentsProcessed = 0;
|
|
1356
1481
|
pcbComponents = [];
|
|
@@ -1408,40 +1533,28 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
1408
1533
|
const fpPads = footprint.fpPads;
|
|
1409
1534
|
let padNumber = 1;
|
|
1410
1535
|
for (const pcbPad of pcbPads) {
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
const relativeY = pcbPad.y - component.center.y;
|
|
1416
|
-
const layerMap = {
|
|
1417
|
-
top: "F.Cu",
|
|
1418
|
-
bottom: "B.Cu"
|
|
1419
|
-
};
|
|
1420
|
-
const padLayer = layerMap[pcbPad.layer] || "F.Cu";
|
|
1421
|
-
const padShape = pcbPad.shape === "circle" ? "circle" : "rect";
|
|
1422
|
-
const padSize = pcbPad.shape === "circle" ? [
|
|
1423
|
-
"radius" in pcbPad ? pcbPad.radius * 2 : 0.5,
|
|
1424
|
-
"radius" in pcbPad ? pcbPad.radius * 2 : 0.5
|
|
1425
|
-
] : [
|
|
1426
|
-
"width" in pcbPad ? pcbPad.width : 0.5,
|
|
1427
|
-
"height" in pcbPad ? pcbPad.height : 0.5
|
|
1428
|
-
];
|
|
1429
|
-
const pad = new FootprintPad({
|
|
1430
|
-
number: String(padNumber),
|
|
1431
|
-
padType: "smd",
|
|
1432
|
-
shape: padShape,
|
|
1433
|
-
at: [relativeX, relativeY, 0],
|
|
1434
|
-
size: padSize,
|
|
1435
|
-
layers: [
|
|
1436
|
-
`${padLayer}`,
|
|
1437
|
-
`${padLayer === "F.Cu" ? "F" : "B"}.Paste`,
|
|
1438
|
-
`${padLayer === "F.Cu" ? "F" : "B"}.Mask`
|
|
1439
|
-
],
|
|
1440
|
-
uuid: crypto.randomUUID()
|
|
1536
|
+
const pad = createSmdPadFromCircuitJson({
|
|
1537
|
+
pcbPad,
|
|
1538
|
+
componentCenter: component.center,
|
|
1539
|
+
padNumber
|
|
1441
1540
|
});
|
|
1442
1541
|
fpPads.push(pad);
|
|
1443
1542
|
padNumber++;
|
|
1444
1543
|
}
|
|
1544
|
+
const pcbPlatedHoles = this.ctx.db.pcb_plated_hole?.list().filter(
|
|
1545
|
+
(hole) => hole.pcb_component_id === component.pcb_component_id
|
|
1546
|
+
) || [];
|
|
1547
|
+
for (const platedHole of pcbPlatedHoles) {
|
|
1548
|
+
const pad = createThruHolePadFromCircuitJson({
|
|
1549
|
+
platedHole,
|
|
1550
|
+
componentCenter: component.center,
|
|
1551
|
+
padNumber
|
|
1552
|
+
});
|
|
1553
|
+
if (pad) {
|
|
1554
|
+
fpPads.push(pad);
|
|
1555
|
+
padNumber++;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1445
1558
|
footprint.fpPads = fpPads;
|
|
1446
1559
|
const footprints = kicadPcb.footprints;
|
|
1447
1560
|
footprints.push(footprint);
|