kicad-to-circuit-json 0.0.152 → 0.0.154
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 +174 -75
- package/package.json +1 -1
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 {
|
|
@@ -2240,10 +2333,13 @@ function mapKicadJustifyToAnchorAlignment(justify) {
|
|
|
2240
2333
|
}
|
|
2241
2334
|
|
|
2242
2335
|
// lib/stages/pcb/CollectFootprintsStage/process-text.ts
|
|
2243
|
-
function convertKiCadAngleToCircuitJsonCcwRotation(rotationDegrees) {
|
|
2336
|
+
function convertKiCadAngleToCircuitJsonCcwRotation(rotationDegrees, unlocked = false) {
|
|
2244
2337
|
if (!rotationDegrees) return 0;
|
|
2245
|
-
const circuitJsonRotation = rotationDegrees % 360;
|
|
2246
|
-
|
|
2338
|
+
const circuitJsonRotation = (rotationDegrees % 360 + 360) % 360;
|
|
2339
|
+
if (!unlocked && circuitJsonRotation > 90 && circuitJsonRotation <= 270) {
|
|
2340
|
+
return (circuitJsonRotation + 180) % 360;
|
|
2341
|
+
}
|
|
2342
|
+
return circuitJsonRotation;
|
|
2247
2343
|
}
|
|
2248
2344
|
function isKicadTextHidden(text) {
|
|
2249
2345
|
return text.hidden === true || text._sxHide?.value === true;
|
|
@@ -2315,6 +2411,7 @@ function processFootprintText(params) {
|
|
|
2315
2411
|
if (!isPcbTextRenderLayer(renderLayer)) continue;
|
|
2316
2412
|
const textElement = {
|
|
2317
2413
|
text: text.text,
|
|
2414
|
+
unlocked: text.unlocked,
|
|
2318
2415
|
at: getKiCadTextAnchor(text),
|
|
2319
2416
|
// Use _sxPosition for position
|
|
2320
2417
|
layer: text.layer,
|
|
@@ -2345,6 +2442,7 @@ function processFootprintProperties(params) {
|
|
|
2345
2442
|
if (!isPcbTextRenderLayer(renderLayer) || isPropertyHidden) continue;
|
|
2346
2443
|
const textElement = {
|
|
2347
2444
|
text: property.value,
|
|
2445
|
+
unlocked: property.unlocked,
|
|
2348
2446
|
at: getKiCadTextAnchor(property),
|
|
2349
2447
|
layer: property.layer,
|
|
2350
2448
|
effects: property._sxEffects || property.effects,
|
|
@@ -2391,7 +2489,7 @@ function createGraphicText(params) {
|
|
|
2391
2489
|
);
|
|
2392
2490
|
const kicadFontSize = textElement._sxEffects?._sxFont?._sxSize?._height || textElement.effects?.font?.size?.y || 1;
|
|
2393
2491
|
const fontSize = kicadFontSize * KICAD_TEXT_HEIGHT_TO_CIRCUIT_JSON_FONT_SIZE;
|
|
2394
|
-
const ccwRotation = isReferenceText ? 0 : convertKiCadAngleToCircuitJsonCcwRotation(at?.angle);
|
|
2492
|
+
const ccwRotation = isReferenceText ? 0 : convertKiCadAngleToCircuitJsonCcwRotation(at?.angle, textElement.unlocked);
|
|
2395
2493
|
const justify = textElement._sxEffects?._sxJustify || textElement.effects?.justify;
|
|
2396
2494
|
const anchorAlignment = mapKicadJustifyToAnchorAlignment(justify);
|
|
2397
2495
|
if (renderLayer.endsWith("_silkscreen")) {
|
|
@@ -2417,7 +2515,8 @@ function createGraphicText(params) {
|
|
|
2417
2515
|
text: processedText,
|
|
2418
2516
|
anchor_position: pos,
|
|
2419
2517
|
anchor_alignment: anchorAlignment,
|
|
2420
|
-
layer
|
|
2518
|
+
layer,
|
|
2519
|
+
ccw_rotation: ccwRotation || void 0
|
|
2421
2520
|
});
|
|
2422
2521
|
return;
|
|
2423
2522
|
}
|