circuit-json-to-kicad 0.0.26 → 0.0.28
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 +44 -9
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1418,12 +1418,39 @@ import {
|
|
|
1418
1418
|
scale as scale2,
|
|
1419
1419
|
rotate
|
|
1420
1420
|
} from "transformation-matrix";
|
|
1421
|
+
|
|
1422
|
+
// lib/pcb/stages/utils/generateDeterministicUuid.ts
|
|
1423
|
+
function simpleHash(str) {
|
|
1424
|
+
let hash = 0;
|
|
1425
|
+
for (let i = 0; i < str.length; i++) {
|
|
1426
|
+
const char = str.charCodeAt(i);
|
|
1427
|
+
hash = (hash << 5) - hash + char;
|
|
1428
|
+
hash = hash & hash;
|
|
1429
|
+
}
|
|
1430
|
+
let result = "";
|
|
1431
|
+
for (let i = 0; i < 4; i++) {
|
|
1432
|
+
let h = hash;
|
|
1433
|
+
for (let j = 0; j < str.length; j++) {
|
|
1434
|
+
h = (h << 5) - h + str.charCodeAt(j) + i * 31;
|
|
1435
|
+
h = h & h;
|
|
1436
|
+
}
|
|
1437
|
+
result += Math.abs(h).toString(16).padStart(8, "0");
|
|
1438
|
+
}
|
|
1439
|
+
return result;
|
|
1440
|
+
}
|
|
1441
|
+
function generateDeterministicUuid(data) {
|
|
1442
|
+
const hash = simpleHash(data);
|
|
1443
|
+
return `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
// lib/pcb/stages/utils/CreateSmdPadFromCircuitJson.ts
|
|
1421
1447
|
function createSmdPadFromCircuitJson({
|
|
1422
1448
|
pcbPad,
|
|
1423
1449
|
componentCenter,
|
|
1424
1450
|
padNumber,
|
|
1425
1451
|
componentRotation = 0,
|
|
1426
|
-
netInfo
|
|
1452
|
+
netInfo,
|
|
1453
|
+
componentId
|
|
1427
1454
|
}) {
|
|
1428
1455
|
let padX;
|
|
1429
1456
|
let padY;
|
|
@@ -1490,6 +1517,7 @@ function createSmdPadFromCircuitJson({
|
|
|
1490
1517
|
"height" in pcbPad ? pcbPad.height : 0.5
|
|
1491
1518
|
];
|
|
1492
1519
|
}
|
|
1520
|
+
const padData = `pad:${componentId}:${padNumber}:${rotatedPos.x},${rotatedPos.y}`;
|
|
1493
1521
|
const pad = new FootprintPad({
|
|
1494
1522
|
number: String(padNumber),
|
|
1495
1523
|
padType: "smd",
|
|
@@ -1501,7 +1529,7 @@ function createSmdPadFromCircuitJson({
|
|
|
1501
1529
|
`${padLayer === "F.Cu" ? "F" : "B"}.Paste`,
|
|
1502
1530
|
`${padLayer === "F.Cu" ? "F" : "B"}.Mask`
|
|
1503
1531
|
],
|
|
1504
|
-
uuid:
|
|
1532
|
+
uuid: generateDeterministicUuid(padData)
|
|
1505
1533
|
});
|
|
1506
1534
|
if (padOptions) {
|
|
1507
1535
|
pad.options = padOptions;
|
|
@@ -1523,7 +1551,8 @@ function createThruHolePadFromCircuitJson({
|
|
|
1523
1551
|
componentCenter,
|
|
1524
1552
|
padNumber,
|
|
1525
1553
|
componentRotation = 0,
|
|
1526
|
-
netInfo
|
|
1554
|
+
netInfo,
|
|
1555
|
+
componentId
|
|
1527
1556
|
}) {
|
|
1528
1557
|
if (!("x" in platedHole && "y" in platedHole)) {
|
|
1529
1558
|
return null;
|
|
@@ -1613,6 +1642,7 @@ function createThruHolePadFromCircuitJson({
|
|
|
1613
1642
|
padSize = [1.6, 1.6];
|
|
1614
1643
|
drill = new PadDrill({ diameter: 0.8, offset: drillOffset });
|
|
1615
1644
|
}
|
|
1645
|
+
const padData = `thruhole:${componentId}:${padNumber}:${rotatedPos.x},${rotatedPos.y}`;
|
|
1616
1646
|
const pad = new FootprintPad2({
|
|
1617
1647
|
number: String(padNumber),
|
|
1618
1648
|
padType: "thru_hole",
|
|
@@ -1622,7 +1652,7 @@ function createThruHolePadFromCircuitJson({
|
|
|
1622
1652
|
drill,
|
|
1623
1653
|
layers: ["*.Cu", "*.Mask"],
|
|
1624
1654
|
removeUnusedLayers: false,
|
|
1625
|
-
uuid:
|
|
1655
|
+
uuid: generateDeterministicUuid(padData)
|
|
1626
1656
|
});
|
|
1627
1657
|
if (netInfo) {
|
|
1628
1658
|
pad.net = new PadNet2(netInfo.id, netInfo.name);
|
|
@@ -1774,11 +1804,12 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
1774
1804
|
x: component.center.x,
|
|
1775
1805
|
y: component.center.y
|
|
1776
1806
|
});
|
|
1807
|
+
const footprintData = `footprint:${component.pcb_component_id}:${transformedPos.x},${transformedPos.y}`;
|
|
1777
1808
|
const footprint = new Footprint({
|
|
1778
1809
|
libraryLink: `tscircuit:${footprintName}`,
|
|
1779
1810
|
layer: "F.Cu",
|
|
1780
1811
|
at: [transformedPos.x, transformedPos.y, component.rotation || 0],
|
|
1781
|
-
uuid:
|
|
1812
|
+
uuid: generateDeterministicUuid(footprintData)
|
|
1782
1813
|
});
|
|
1783
1814
|
const fpTexts = footprint.fpTexts;
|
|
1784
1815
|
const pcbSilkscreenTexts = this.ctx.db.pcb_silkscreen_text?.list().filter(
|
|
@@ -1807,7 +1838,8 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
1807
1838
|
componentCenter: component.center,
|
|
1808
1839
|
padNumber,
|
|
1809
1840
|
componentRotation: component.rotation || 0,
|
|
1810
|
-
netInfo
|
|
1841
|
+
netInfo,
|
|
1842
|
+
componentId: component.pcb_component_id
|
|
1811
1843
|
});
|
|
1812
1844
|
fpPads.push(pad);
|
|
1813
1845
|
padNumber++;
|
|
@@ -1822,7 +1854,8 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
1822
1854
|
componentCenter: component.center,
|
|
1823
1855
|
padNumber,
|
|
1824
1856
|
componentRotation: component.rotation || 0,
|
|
1825
|
-
netInfo
|
|
1857
|
+
netInfo,
|
|
1858
|
+
componentId: component.pcb_component_id
|
|
1826
1859
|
});
|
|
1827
1860
|
if (pad) {
|
|
1828
1861
|
fpPads.push(pad);
|
|
@@ -1926,13 +1959,14 @@ var AddTracesStage = class extends ConverterStage {
|
|
|
1926
1959
|
bottom: "B.Cu"
|
|
1927
1960
|
};
|
|
1928
1961
|
const kicadLayer = layerMap[startPoint.layer] || startPoint.layer || "F.Cu";
|
|
1962
|
+
const segmentData = `segment:${transformedStart.x},${transformedStart.y}:${transformedEnd.x},${transformedEnd.y}:${kicadLayer}:${netInfo?.id ?? 0}`;
|
|
1929
1963
|
const segment = new Segment({
|
|
1930
1964
|
start: { x: transformedStart.x, y: transformedStart.y },
|
|
1931
1965
|
end: { x: transformedEnd.x, y: transformedEnd.y },
|
|
1932
1966
|
layer: kicadLayer,
|
|
1933
1967
|
width: trace.width || 0.25,
|
|
1934
1968
|
net: new SegmentNet(netInfo?.id ?? 0),
|
|
1935
|
-
uuid:
|
|
1969
|
+
uuid: generateDeterministicUuid(segmentData)
|
|
1936
1970
|
});
|
|
1937
1971
|
const segments = kicadPcb.segments;
|
|
1938
1972
|
segments.push(segment);
|
|
@@ -2012,13 +2046,14 @@ var AddViasStage = class extends ConverterStage {
|
|
|
2012
2046
|
netInfo = pcbNetMap.get(connectivityKey);
|
|
2013
2047
|
}
|
|
2014
2048
|
}
|
|
2049
|
+
const viaData = `via:${transformedPos.x},${transformedPos.y}:${via.outer_diameter || 0.8}:${via.hole_diameter || 0.4}:${netInfo?.id ?? 0}`;
|
|
2015
2050
|
const kicadVia = new Via({
|
|
2016
2051
|
at: [transformedPos.x, transformedPos.y],
|
|
2017
2052
|
size: via.outer_diameter || 0.8,
|
|
2018
2053
|
drill: via.hole_diameter || 0.4,
|
|
2019
2054
|
layers: ["F.Cu", "B.Cu"],
|
|
2020
2055
|
net: new ViaNet(netInfo?.id ?? 0),
|
|
2021
|
-
uuid:
|
|
2056
|
+
uuid: generateDeterministicUuid(viaData)
|
|
2022
2057
|
});
|
|
2023
2058
|
const vias = kicadPcb.vias;
|
|
2024
2059
|
vias.push(kicadVia);
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "circuit-json-to-kicad",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.28",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsup-node lib/index.ts --format esm --dts",
|
|
11
|
+
"build:site": "bun build ./site/index.html --outdir site-build",
|
|
11
12
|
"download-demos": "git clone --depth 1 --filter=blob:none --sparse https://gitlab.com/kicad/code/kicad.git kicad-demos && cd kicad-demos && git sparse-checkout set demos",
|
|
12
13
|
"typecheck": "bunx tsc --noEmit",
|
|
13
14
|
"format": "biome format --write .",
|