kicad-to-circuit-json 0.0.151 → 0.0.153
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.d.ts +7 -0
- package/dist/index.js +190 -86
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -314,6 +314,13 @@ declare class CollectZonesStage extends ConverterStage {
|
|
|
314
314
|
private createZonePolygonRecordsFromShape;
|
|
315
315
|
private getPolygonLayers;
|
|
316
316
|
private getZoneLayers;
|
|
317
|
+
private isZoneOnCopper;
|
|
318
|
+
/**
|
|
319
|
+
* The copper layers that the KiCad layers of a zone or of its fill name.
|
|
320
|
+
* "*.Cu" is every copper layer of the board and the legacy "F&B.Cu" is
|
|
321
|
+
* both outer layers; a technical layer such as F.Mask is none.
|
|
322
|
+
*/
|
|
323
|
+
private getCopperLayerRefs;
|
|
317
324
|
private getZoneLayerLabel;
|
|
318
325
|
private extractPointsFromPts;
|
|
319
326
|
}
|
package/dist/index.js
CHANGED
|
@@ -1292,6 +1292,12 @@ function getNextPcbPlatedHoleId(ctx) {
|
|
|
1292
1292
|
);
|
|
1293
1293
|
return getNextUnusedId(usedIds, "pcb_plated_hole");
|
|
1294
1294
|
}
|
|
1295
|
+
function getNextPcbSolderPasteId(ctx) {
|
|
1296
|
+
const usedIds = new Set(
|
|
1297
|
+
ctx.db.pcb_solder_paste.list().map((paste) => paste.pcb_solder_paste_id)
|
|
1298
|
+
);
|
|
1299
|
+
return getNextUnusedId(usedIds, "pcb_solder_paste");
|
|
1300
|
+
}
|
|
1295
1301
|
|
|
1296
1302
|
// lib/stages/pcb/CollectFootprintsStage/pad-rotation.ts
|
|
1297
1303
|
function normalizeRotationDegrees(rotationDegrees) {
|
|
@@ -1437,6 +1443,38 @@ function getChamferedPadPoints({
|
|
|
1437
1443
|
return points;
|
|
1438
1444
|
}
|
|
1439
1445
|
|
|
1446
|
+
// lib/stages/pcb/CollectFootprintsStage/get-pad-shape.ts
|
|
1447
|
+
function getPadShape({
|
|
1448
|
+
shape,
|
|
1449
|
+
width,
|
|
1450
|
+
height,
|
|
1451
|
+
ccwRotationDegrees,
|
|
1452
|
+
radius = Math.min(width, height) / 2
|
|
1453
|
+
}) {
|
|
1454
|
+
const rotation = normalizeRotationDegrees(ccwRotationDegrees);
|
|
1455
|
+
const turns = getRightAngleTurns(rotation);
|
|
1456
|
+
if (turns !== null && turns % 2 !== 0) {
|
|
1457
|
+
;
|
|
1458
|
+
[width, height] = [height, width];
|
|
1459
|
+
}
|
|
1460
|
+
if (shape === "pill") {
|
|
1461
|
+
if (turns === null) {
|
|
1462
|
+
return {
|
|
1463
|
+
shape: "rotated_pill",
|
|
1464
|
+
width,
|
|
1465
|
+
height,
|
|
1466
|
+
radius,
|
|
1467
|
+
ccw_rotation: rotation
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
return { shape: "pill", width, height, radius };
|
|
1471
|
+
}
|
|
1472
|
+
if (turns === null) {
|
|
1473
|
+
return { shape: "rotated_rect", width, height, ccw_rotation: rotation };
|
|
1474
|
+
}
|
|
1475
|
+
return { shape: "rect", width, height };
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1440
1478
|
// lib/stages/pcb/CollectFootprintsStage/get-supported-pad-type.ts
|
|
1441
1479
|
function getSupportedPadType(pad) {
|
|
1442
1480
|
switch (pad.padType) {
|
|
@@ -1541,6 +1579,86 @@ function createPcbPort({
|
|
|
1541
1579
|
return insertedPort.pcb_port_id;
|
|
1542
1580
|
}
|
|
1543
1581
|
|
|
1582
|
+
// lib/stages/pcb/CollectFootprintsStage/process-solder-paste.ts
|
|
1583
|
+
function processSolderPaste({
|
|
1584
|
+
ctx,
|
|
1585
|
+
footprint,
|
|
1586
|
+
pad,
|
|
1587
|
+
componentId,
|
|
1588
|
+
position,
|
|
1589
|
+
hasCopper,
|
|
1590
|
+
pcbSmtPadId
|
|
1591
|
+
}) {
|
|
1592
|
+
const layers = extractKicadLayerNames(pad.layers);
|
|
1593
|
+
const pasteLayers = ["F.Paste", "B.Paste"].filter(
|
|
1594
|
+
(layer) => layers.includes(layer) || layers.includes("*.Paste")
|
|
1595
|
+
);
|
|
1596
|
+
if (pasteLayers.length === 0) return;
|
|
1597
|
+
if (!["circle", "rect", "oval", "roundrect"].includes(pad.shape)) return;
|
|
1598
|
+
if (pad.shape === "roundrect" && pad.chamferRatio && pad.chamferCorners?.length)
|
|
1599
|
+
return;
|
|
1600
|
+
const size = pad.size;
|
|
1601
|
+
if (!size) return;
|
|
1602
|
+
let margin = 0;
|
|
1603
|
+
let ratio = 0;
|
|
1604
|
+
if (hasCopper) {
|
|
1605
|
+
margin = pad.solderPasteMargin ?? footprint.solderPasteMargin?.value ?? 0;
|
|
1606
|
+
ratio = pad.solderPasteMarginRatio ?? footprint.solderPasteMarginRatio?.value ?? footprint.solderPasteRatio?.value ?? 0;
|
|
1607
|
+
}
|
|
1608
|
+
const marginX = margin + size.width * ratio;
|
|
1609
|
+
const marginY = margin + size.height * ratio;
|
|
1610
|
+
const width = Math.max(0, size.width + 2 * marginX);
|
|
1611
|
+
const height = Math.max(0, size.height + 2 * marginY);
|
|
1612
|
+
if (width === 0 || height === 0) return;
|
|
1613
|
+
let radius;
|
|
1614
|
+
if (pad.shape === "oval") {
|
|
1615
|
+
radius = Math.min(width, height) / 2;
|
|
1616
|
+
} else if (pad.shape === "roundrect") {
|
|
1617
|
+
radius = Math.max(
|
|
1618
|
+
0,
|
|
1619
|
+
Math.min(
|
|
1620
|
+
Math.min(size.width, size.height) * (pad.roundrectRatio ?? 0) + Math.min(marginX, marginY),
|
|
1621
|
+
width / 2,
|
|
1622
|
+
height / 2
|
|
1623
|
+
)
|
|
1624
|
+
);
|
|
1625
|
+
}
|
|
1626
|
+
for (const pasteLayer of pasteLayers) {
|
|
1627
|
+
const base = {
|
|
1628
|
+
type: "pcb_solder_paste",
|
|
1629
|
+
pcb_solder_paste_id: getNextPcbSolderPasteId(ctx),
|
|
1630
|
+
pcb_component_id: componentId,
|
|
1631
|
+
pcb_smtpad_id: pcbSmtPadId,
|
|
1632
|
+
x: position.x,
|
|
1633
|
+
y: position.y,
|
|
1634
|
+
layer: mapKicadLayerToVisibleLayer(pasteLayer)
|
|
1635
|
+
};
|
|
1636
|
+
let aperture;
|
|
1637
|
+
if (pad.shape === "circle") {
|
|
1638
|
+
const turns = getRightAngleTurns(normalizeRotationDegrees(pad.at?.angle));
|
|
1639
|
+
let diameter = width;
|
|
1640
|
+
if (turns !== null && turns % 2 !== 0) diameter = height;
|
|
1641
|
+
aperture = {
|
|
1642
|
+
...base,
|
|
1643
|
+
shape: "circle",
|
|
1644
|
+
radius: diameter / 2
|
|
1645
|
+
};
|
|
1646
|
+
} else {
|
|
1647
|
+
aperture = {
|
|
1648
|
+
...base,
|
|
1649
|
+
...getPadShape({
|
|
1650
|
+
shape: radius === void 0 ? "rect" : "pill",
|
|
1651
|
+
width,
|
|
1652
|
+
height,
|
|
1653
|
+
radius,
|
|
1654
|
+
ccwRotationDegrees: pad.at?.angle
|
|
1655
|
+
})
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
ctx.db.pcb_solder_paste.insert(aperture);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1544
1662
|
// lib/stages/pcb/CollectFootprintsStage/process-pads.ts
|
|
1545
1663
|
function processPads(params) {
|
|
1546
1664
|
const {
|
|
@@ -1617,11 +1735,10 @@ function processPad({
|
|
|
1617
1735
|
});
|
|
1618
1736
|
if (!pcbPortId) sourcePortId = void 0;
|
|
1619
1737
|
}
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
createSmdPad({
|
|
1738
|
+
const isSurfacePad = padType === "smd" || padType === "connect";
|
|
1739
|
+
let pcbSmtPadId;
|
|
1740
|
+
if (isSurfacePad && copperLayers.length > 0) {
|
|
1741
|
+
pcbSmtPadId = createSmdPad({
|
|
1625
1742
|
ctx,
|
|
1626
1743
|
pad,
|
|
1627
1744
|
componentId,
|
|
@@ -1633,7 +1750,18 @@ function processPad({
|
|
|
1633
1750
|
padKicadPos,
|
|
1634
1751
|
customPrimitiveKicadRotationDegrees
|
|
1635
1752
|
});
|
|
1636
|
-
}
|
|
1753
|
+
}
|
|
1754
|
+
processSolderPaste({
|
|
1755
|
+
ctx,
|
|
1756
|
+
footprint,
|
|
1757
|
+
pad,
|
|
1758
|
+
componentId,
|
|
1759
|
+
position: globalPos,
|
|
1760
|
+
hasCopper: copperLayers.length > 0,
|
|
1761
|
+
pcbSmtPadId
|
|
1762
|
+
});
|
|
1763
|
+
if (isSurfacePad) return;
|
|
1764
|
+
if (padType === "np_thru_hole") {
|
|
1637
1765
|
createNpthHole({
|
|
1638
1766
|
ctx,
|
|
1639
1767
|
componentId,
|
|
@@ -1699,9 +1827,9 @@ function createSmdPad({
|
|
|
1699
1827
|
port_hints: [pad.number.toString()],
|
|
1700
1828
|
points
|
|
1701
1829
|
};
|
|
1702
|
-
ctx.db.pcb_smtpad.insert(smtpad);
|
|
1830
|
+
const insertedPad = ctx.db.pcb_smtpad.insert(smtpad);
|
|
1703
1831
|
if (ctx.stats) ctx.stats.pads = (ctx.stats.pads || 0) + 1;
|
|
1704
|
-
return;
|
|
1832
|
+
return insertedPad.pcb_smtpad_id;
|
|
1705
1833
|
}
|
|
1706
1834
|
if (shape === "custom") {
|
|
1707
1835
|
const primitives = pad.primitives?.graphics ?? [];
|
|
@@ -1887,7 +2015,7 @@ function createSmdPad({
|
|
|
1887
2015
|
}
|
|
1888
2016
|
return;
|
|
1889
2017
|
}
|
|
1890
|
-
|
|
2018
|
+
let pcbSmtPadId;
|
|
1891
2019
|
if (shape === "circle") {
|
|
1892
2020
|
const smtpad = {
|
|
1893
2021
|
type: "pcb_smtpad",
|
|
@@ -1903,44 +2031,27 @@ function createSmdPad({
|
|
|
1903
2031
|
shape: "circle",
|
|
1904
2032
|
radius: Math.max(size.x, size.y) / 2
|
|
1905
2033
|
};
|
|
1906
|
-
ctx.db.pcb_smtpad.insert(smtpad);
|
|
2034
|
+
pcbSmtPadId = ctx.db.pcb_smtpad.insert(smtpad).pcb_smtpad_id;
|
|
1907
2035
|
} else if (shape === "oval") {
|
|
1908
|
-
const
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
pcb_component_id: componentId,
|
|
1915
|
-
x: pos.x,
|
|
1916
|
-
y: pos.y,
|
|
1917
|
-
width: size.x,
|
|
1918
|
-
height: size.y,
|
|
1919
|
-
radius,
|
|
1920
|
-
layer,
|
|
1921
|
-
pcb_port_id: pcbPortId,
|
|
1922
|
-
port_hints: [pad.number.toString()],
|
|
1923
|
-
shape: "rotated_pill",
|
|
1924
|
-
ccw_rotation: normalizedCcwRotation
|
|
1925
|
-
};
|
|
1926
|
-
ctx.db.pcb_smtpad.insert(rotatedSmtPad);
|
|
1927
|
-
return;
|
|
1928
|
-
}
|
|
1929
|
-
const shouldSwapDimensions = rightAngleTurns !== null && Math.abs(rightAngleTurns) % 2 === 1;
|
|
2036
|
+
const geometry = getPadShape({
|
|
2037
|
+
shape: "pill",
|
|
2038
|
+
width: size.x,
|
|
2039
|
+
height: size.y,
|
|
2040
|
+
ccwRotationDegrees: pad.at?.angle
|
|
2041
|
+
});
|
|
1930
2042
|
const smtpad = {
|
|
1931
2043
|
type: "pcb_smtpad",
|
|
2044
|
+
pcb_smtpad_id: getNextPcbSmtPadId(ctx),
|
|
1932
2045
|
pcb_component_id: componentId,
|
|
2046
|
+
pcb_port_id: pcbPortId,
|
|
2047
|
+
port_hints: [pad.number.toString()],
|
|
1933
2048
|
x: pos.x,
|
|
1934
2049
|
y: pos.y,
|
|
1935
|
-
width: shouldSwapDimensions ? size.y : size.x,
|
|
1936
|
-
height: shouldSwapDimensions ? size.x : size.y,
|
|
1937
|
-
radius,
|
|
1938
2050
|
layer,
|
|
1939
|
-
|
|
1940
|
-
port_hints: [pad.number.toString()],
|
|
1941
|
-
shape: "pill"
|
|
2051
|
+
...geometry
|
|
1942
2052
|
};
|
|
1943
|
-
ctx.db.pcb_smtpad.insert(smtpad);
|
|
2053
|
+
pcbSmtPadId = ctx.db.pcb_smtpad.insert(smtpad).pcb_smtpad_id;
|
|
2054
|
+
if (geometry.shape === "rotated_pill") return pcbSmtPadId;
|
|
1944
2055
|
} else {
|
|
1945
2056
|
let rectangleSize = size;
|
|
1946
2057
|
if (shape === "trapezoid") {
|
|
@@ -1951,7 +2062,8 @@ function createSmdPad({
|
|
|
1951
2062
|
x: size.x + Math.abs(deltaY),
|
|
1952
2063
|
y: size.y + Math.abs(deltaX)
|
|
1953
2064
|
};
|
|
1954
|
-
|
|
2065
|
+
ctx.warnings ??= [];
|
|
2066
|
+
ctx.warnings.push(
|
|
1955
2067
|
`Trapezoid pad ${pad.number} on ${componentId} has nonzero rect_delta; using its conservative rotated rectangle envelope`
|
|
1956
2068
|
);
|
|
1957
2069
|
}
|
|
@@ -1962,48 +2074,29 @@ function createSmdPad({
|
|
|
1962
2074
|
const minDimension = Math.min(size.x, size.y);
|
|
1963
2075
|
cornerRadius = minDimension * roundrectRatio;
|
|
1964
2076
|
}
|
|
1965
|
-
const normalizedCcwRotation = normalizeRotationDegrees(ccwRotationDegrees);
|
|
1966
|
-
const rightAngleTurns = getRightAngleTurns(normalizedCcwRotation);
|
|
1967
|
-
if (rightAngleTurns === null && normalizedCcwRotation !== 0) {
|
|
1968
|
-
const rotatedsmtpad = {
|
|
1969
|
-
type: "pcb_smtpad",
|
|
1970
|
-
pcb_component_id: componentId,
|
|
1971
|
-
x: pos.x,
|
|
1972
|
-
y: pos.y,
|
|
1973
|
-
width: rectangleSize.x,
|
|
1974
|
-
height: rectangleSize.y,
|
|
1975
|
-
layer,
|
|
1976
|
-
pcb_port_id: pcbPortId,
|
|
1977
|
-
port_hints: [pad.number?.toString()],
|
|
1978
|
-
shape: "rotated_rect",
|
|
1979
|
-
ccw_rotation: normalizedCcwRotation,
|
|
1980
|
-
corner_radius: cornerRadius
|
|
1981
|
-
};
|
|
1982
|
-
ctx.db.pcb_smtpad.insert(rotatedsmtpad);
|
|
1983
|
-
if (ctx.stats) {
|
|
1984
|
-
ctx.stats.pads = (ctx.stats.pads || 0) + 1;
|
|
1985
|
-
}
|
|
1986
|
-
return;
|
|
1987
|
-
}
|
|
1988
|
-
const shouldSwapDimensions = rightAngleTurns !== null && Math.abs(rightAngleTurns) % 2 === 1;
|
|
1989
2077
|
const smtpad = {
|
|
1990
2078
|
type: "pcb_smtpad",
|
|
2079
|
+
pcb_smtpad_id: getNextPcbSmtPadId(ctx),
|
|
1991
2080
|
pcb_component_id: componentId,
|
|
2081
|
+
pcb_port_id: pcbPortId,
|
|
2082
|
+
port_hints: [pad.number?.toString()],
|
|
1992
2083
|
x: pos.x,
|
|
1993
2084
|
y: pos.y,
|
|
1994
|
-
width: shouldSwapDimensions ? rectangleSize.y : rectangleSize.x,
|
|
1995
|
-
height: shouldSwapDimensions ? rectangleSize.x : rectangleSize.y,
|
|
1996
2085
|
layer,
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2086
|
+
...getPadShape({
|
|
2087
|
+
shape: "rect",
|
|
2088
|
+
width: rectangleSize.x,
|
|
2089
|
+
height: rectangleSize.y,
|
|
2090
|
+
ccwRotationDegrees: pad.at?.angle
|
|
2091
|
+
}),
|
|
2000
2092
|
corner_radius: cornerRadius
|
|
2001
2093
|
};
|
|
2002
|
-
ctx.db.pcb_smtpad.insert(smtpad);
|
|
2094
|
+
pcbSmtPadId = ctx.db.pcb_smtpad.insert(smtpad).pcb_smtpad_id;
|
|
2003
2095
|
}
|
|
2004
2096
|
if (ctx.stats) {
|
|
2005
2097
|
ctx.stats.pads = (ctx.stats.pads || 0) + 1;
|
|
2006
2098
|
}
|
|
2099
|
+
return pcbSmtPadId;
|
|
2007
2100
|
}
|
|
2008
2101
|
function createPlatedHole(params) {
|
|
2009
2102
|
const {
|
|
@@ -5239,11 +5332,10 @@ var CollectZonesStage = class extends ConverterStage {
|
|
|
5239
5332
|
if (!this.ctx.k2cMatPcb || !this.ctx.netNumToName) return;
|
|
5240
5333
|
const polygonRecords = this.getZonePolygonRecords(zone);
|
|
5241
5334
|
if (polygonRecords.length === 0) {
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
}
|
|
5335
|
+
const reason = this.isZoneOnCopper(zone) ? "has no valid polygon points" : "is not on a copper layer and was not imported as a copper pour";
|
|
5336
|
+
this.ctx.warnings?.push(
|
|
5337
|
+
`Zone on layer ${this.getZoneLayerLabel(zone)} ${reason}`
|
|
5338
|
+
);
|
|
5247
5339
|
return;
|
|
5248
5340
|
}
|
|
5249
5341
|
const netKey = getKicadNetKey(zone);
|
|
@@ -5294,21 +5386,33 @@ var CollectZonesStage = class extends ConverterStage {
|
|
|
5294
5386
|
}
|
|
5295
5387
|
getPolygonLayers(zone, polygon) {
|
|
5296
5388
|
if (polygon.layer) {
|
|
5297
|
-
return
|
|
5389
|
+
return this.getCopperLayerRefs(polygon.layer);
|
|
5298
5390
|
}
|
|
5299
5391
|
return this.getZoneLayers(zone);
|
|
5300
5392
|
}
|
|
5301
5393
|
getZoneLayers(zone) {
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5394
|
+
return this.getCopperLayerRefs(zone.layer ?? zone.layers);
|
|
5395
|
+
}
|
|
5396
|
+
isZoneOnCopper(zone) {
|
|
5397
|
+
const layerSources = [
|
|
5398
|
+
zone.layer,
|
|
5399
|
+
zone.layers,
|
|
5400
|
+
...zone.filledPolygons.map((filledPolygon) => filledPolygon.layer)
|
|
5401
|
+
];
|
|
5402
|
+
return layerSources.some(
|
|
5403
|
+
(layerSource) => this.getCopperLayerRefs(layerSource).length > 0
|
|
5404
|
+
);
|
|
5405
|
+
}
|
|
5406
|
+
/**
|
|
5407
|
+
* The copper layers that the KiCad layers of a zone or of its fill name.
|
|
5408
|
+
* "*.Cu" is every copper layer of the board and the legacy "F&B.Cu" is
|
|
5409
|
+
* both outer layers; a technical layer such as F.Mask is none.
|
|
5410
|
+
*/
|
|
5411
|
+
getCopperLayerRefs(layer) {
|
|
5412
|
+
const layerNames = extractKicadLayerNames(layer).flatMap(
|
|
5413
|
+
(layerName) => layerName === "F&B.Cu" ? ["F.Cu", "B.Cu"] : [layerName]
|
|
5414
|
+
);
|
|
5415
|
+
return getLayerRefsFromLayers(layerNames, this.ctx.kicadPcb);
|
|
5312
5416
|
}
|
|
5313
5417
|
getZoneLayerLabel(zone) {
|
|
5314
5418
|
return [...zone.layer?.names ?? [], ...zone.layers?.names ?? []].join(" ") || "unknown";
|