circuit-json-to-kicad 0.0.19 → 0.0.21

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.
Files changed (2) hide show
  1. package/dist/index.js +118 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1350,20 +1350,27 @@ var AddNetsStage = class extends ConverterStage {
1350
1350
 
1351
1351
  // lib/pcb/stages/AddFootprintsStage.ts
1352
1352
  import { Footprint } from "kicadts";
1353
- import { applyToPoint as applyToPoint5 } from "transformation-matrix";
1353
+ import { applyToPoint as applyToPoint9 } from "transformation-matrix";
1354
1354
 
1355
1355
  // lib/pcb/stages/utils/CreateSmdPadFromCircuitJson.ts
1356
1356
  import { FootprintPad } from "kicadts";
1357
+ import { applyToPoint as applyToPoint5, rotate, identity } from "transformation-matrix";
1357
1358
  function createSmdPadFromCircuitJson({
1358
1359
  pcbPad,
1359
1360
  componentCenter,
1360
- padNumber
1361
+ padNumber,
1362
+ componentRotation = 0
1361
1363
  }) {
1362
1364
  if (!("x" in pcbPad && "y" in pcbPad)) {
1363
1365
  throw new Error("no support for polygon pads (or any pads w/o X/Y) yet");
1364
1366
  }
1365
1367
  const relativeX = pcbPad.x - componentCenter.x;
1366
1368
  const relativeY = -(pcbPad.y - componentCenter.y);
1369
+ const rotationMatrix = componentRotation !== 0 ? rotate(componentRotation * Math.PI / 180) : identity();
1370
+ const rotatedPos = applyToPoint5(rotationMatrix, {
1371
+ x: relativeX,
1372
+ y: relativeY
1373
+ });
1367
1374
  const layerMap = {
1368
1375
  top: "F.Cu",
1369
1376
  bottom: "B.Cu"
@@ -1381,7 +1388,7 @@ function createSmdPadFromCircuitJson({
1381
1388
  number: String(padNumber),
1382
1389
  padType: "smd",
1383
1390
  shape: padShape,
1384
- at: [relativeX, relativeY, 0],
1391
+ at: [rotatedPos.x, rotatedPos.y, 0],
1385
1392
  size: padSize,
1386
1393
  layers: [
1387
1394
  `${padLayer}`,
@@ -1394,16 +1401,23 @@ function createSmdPadFromCircuitJson({
1394
1401
 
1395
1402
  // lib/pcb/stages/utils/CreateThruHolePadFromCircuitJson.ts
1396
1403
  import { FootprintPad as FootprintPad2, PadDrill } from "kicadts";
1404
+ import { applyToPoint as applyToPoint6, rotate as rotate2, identity as identity2 } from "transformation-matrix";
1397
1405
  function createThruHolePadFromCircuitJson({
1398
1406
  platedHole,
1399
1407
  componentCenter,
1400
- padNumber
1408
+ padNumber,
1409
+ componentRotation = 0
1401
1410
  }) {
1402
1411
  if (!("x" in platedHole && "y" in platedHole)) {
1403
1412
  return null;
1404
1413
  }
1405
1414
  const relativeX = platedHole.x - componentCenter.x;
1406
1415
  const relativeY = -(platedHole.y - componentCenter.y);
1416
+ const rotationMatrix = componentRotation !== 0 ? rotate2(componentRotation * Math.PI / 180) : identity2();
1417
+ const rotatedPos = applyToPoint6(rotationMatrix, {
1418
+ x: relativeX,
1419
+ y: relativeY
1420
+ });
1407
1421
  let padShape = "circle";
1408
1422
  let padSize;
1409
1423
  let drill;
@@ -1466,7 +1480,65 @@ function createThruHolePadFromCircuitJson({
1466
1480
  number: String(padNumber),
1467
1481
  padType: "thru_hole",
1468
1482
  shape: padShape,
1469
- at: [relativeX, relativeY, rotation],
1483
+ at: [rotatedPos.x, rotatedPos.y, rotation],
1484
+ size: padSize,
1485
+ drill,
1486
+ layers: ["*.Cu", "*.Mask"],
1487
+ removeUnusedLayers: false,
1488
+ uuid: crypto.randomUUID()
1489
+ });
1490
+ }
1491
+
1492
+ // lib/pcb/stages/utils/CreateNpthPadFromCircuitJson.ts
1493
+ import { FootprintPad as FootprintPad3, PadDrill as PadDrill2 } from "kicadts";
1494
+ import { applyToPoint as applyToPoint7, rotate as rotate3, identity as identity3 } from "transformation-matrix";
1495
+ function createNpthPadFromCircuitJson({
1496
+ pcbHole,
1497
+ componentCenter,
1498
+ componentRotation = 0
1499
+ }) {
1500
+ if (!("x" in pcbHole && "y" in pcbHole)) {
1501
+ return null;
1502
+ }
1503
+ const relativeX = pcbHole.x - componentCenter.x;
1504
+ const relativeY = -(pcbHole.y - componentCenter.y);
1505
+ const rotationMatrix = componentRotation !== 0 ? rotate3(componentRotation * Math.PI / 180) : identity3();
1506
+ const rotatedPos = applyToPoint7(rotationMatrix, {
1507
+ x: relativeX,
1508
+ y: relativeY
1509
+ });
1510
+ let padShape = "circle";
1511
+ let padSize;
1512
+ let drill;
1513
+ if (pcbHole.hole_shape === "circle") {
1514
+ padShape = "circle";
1515
+ const diameter = pcbHole.hole_diameter;
1516
+ padSize = [diameter, diameter];
1517
+ drill = new PadDrill2({
1518
+ diameter
1519
+ });
1520
+ } else if (pcbHole.hole_shape === "oval") {
1521
+ padShape = "oval";
1522
+ const width = pcbHole.hole_width;
1523
+ const height = pcbHole.hole_height;
1524
+ padSize = [width, height];
1525
+ drill = new PadDrill2({
1526
+ oval: true,
1527
+ diameter: width,
1528
+ width: height
1529
+ });
1530
+ } else {
1531
+ padShape = "circle";
1532
+ const diameter = pcbHole.hole_diameter || 1;
1533
+ padSize = [diameter, diameter];
1534
+ drill = new PadDrill2({ diameter });
1535
+ }
1536
+ return new FootprintPad3({
1537
+ number: "",
1538
+ // Non-plated holes have no pad number
1539
+ padType: "np_thru_hole",
1540
+ shape: padShape,
1541
+ at: [rotatedPos.x, rotatedPos.y, 0],
1470
1542
  size: padSize,
1471
1543
  drill,
1472
1544
  layers: ["*.Cu", "*.Mask"],
@@ -1477,16 +1549,25 @@ function createThruHolePadFromCircuitJson({
1477
1549
 
1478
1550
  // lib/pcb/stages/utils/CreateFpTextFromCircuitJson.ts
1479
1551
  import { FpText, TextEffects as TextEffects4, TextEffectsFont as TextEffectsFont4 } from "kicadts";
1552
+ import { applyToPoint as applyToPoint8, rotate as rotate4, identity as identity4 } from "transformation-matrix";
1480
1553
  function createFpTextFromCircuitJson({
1481
1554
  textElement,
1482
- componentCenter
1555
+ componentCenter,
1556
+ componentRotation = 0
1483
1557
  }) {
1484
1558
  if (!textElement.text || !textElement.anchor_position) {
1485
1559
  return null;
1486
1560
  }
1561
+ const relativeX = textElement.anchor_position.x - componentCenter.x;
1562
+ const relativeY = -(textElement.anchor_position.y - componentCenter.y);
1563
+ const rotationMatrix = componentRotation !== 0 ? rotate4(componentRotation * Math.PI / 180) : identity4();
1564
+ const rotatedPos = applyToPoint8(rotationMatrix, {
1565
+ x: relativeX,
1566
+ y: relativeY
1567
+ });
1487
1568
  const relativePosition = {
1488
- x: textElement.anchor_position.x - componentCenter.x,
1489
- y: -(textElement.anchor_position.y - componentCenter.y)
1569
+ x: rotatedPos.x,
1570
+ y: rotatedPos.y
1490
1571
  };
1491
1572
  const layerMap = {
1492
1573
  top: "F.SilkS",
@@ -1536,8 +1617,7 @@ var AddFootprintsStage = class extends ConverterStage {
1536
1617
  const component = this.pcbComponents[this.componentsProcessed];
1537
1618
  const sourceComponent = component.source_component_id ? this.ctx.db.source_component.get(component.source_component_id) : null;
1538
1619
  const footprintName = sourceComponent?.ftype || "Unknown";
1539
- const componentName = sourceComponent?.name || `Component_${this.componentsProcessed}`;
1540
- const transformedPos = applyToPoint5(c2kMatPcb, {
1620
+ const transformedPos = applyToPoint9(c2kMatPcb, {
1541
1621
  x: component.center.x,
1542
1622
  y: component.center.y
1543
1623
  });
@@ -1554,7 +1634,8 @@ var AddFootprintsStage = class extends ConverterStage {
1554
1634
  for (const textElement of pcbSilkscreenTexts) {
1555
1635
  const fpText = createFpTextFromCircuitJson({
1556
1636
  textElement,
1557
- componentCenter: component.center
1637
+ componentCenter: component.center,
1638
+ componentRotation: component.rotation || 0
1558
1639
  });
1559
1640
  if (fpText) {
1560
1641
  fpTexts.push(fpText);
@@ -1570,7 +1651,8 @@ var AddFootprintsStage = class extends ConverterStage {
1570
1651
  const pad = createSmdPadFromCircuitJson({
1571
1652
  pcbPad,
1572
1653
  componentCenter: component.center,
1573
- padNumber
1654
+ padNumber,
1655
+ componentRotation: component.rotation || 0
1574
1656
  });
1575
1657
  fpPads.push(pad);
1576
1658
  padNumber++;
@@ -1582,13 +1664,27 @@ var AddFootprintsStage = class extends ConverterStage {
1582
1664
  const pad = createThruHolePadFromCircuitJson({
1583
1665
  platedHole,
1584
1666
  componentCenter: component.center,
1585
- padNumber
1667
+ padNumber,
1668
+ componentRotation: component.rotation || 0
1586
1669
  });
1587
1670
  if (pad) {
1588
1671
  fpPads.push(pad);
1589
1672
  padNumber++;
1590
1673
  }
1591
1674
  }
1675
+ const pcbHoles = this.ctx.db.pcb_hole?.list().filter(
1676
+ (hole) => hole.subcircuit_id === component.subcircuit_id
1677
+ ) || [];
1678
+ for (const pcbHole of pcbHoles) {
1679
+ const pad = createNpthPadFromCircuitJson({
1680
+ pcbHole,
1681
+ componentCenter: component.center,
1682
+ componentRotation: component.rotation || 0
1683
+ });
1684
+ if (pad) {
1685
+ fpPads.push(pad);
1686
+ }
1687
+ }
1592
1688
  footprint.fpPads = fpPads;
1593
1689
  const footprints = kicadPcb.footprints;
1594
1690
  footprints.push(footprint);
@@ -1602,7 +1698,7 @@ var AddFootprintsStage = class extends ConverterStage {
1602
1698
 
1603
1699
  // lib/pcb/stages/AddTracesStage.ts
1604
1700
  import { Segment, SegmentNet } from "kicadts";
1605
- import { applyToPoint as applyToPoint6 } from "transformation-matrix";
1701
+ import { applyToPoint as applyToPoint10 } from "transformation-matrix";
1606
1702
  var AddTracesStage = class extends ConverterStage {
1607
1703
  tracesProcessed = 0;
1608
1704
  pcbTraces = [];
@@ -1630,11 +1726,11 @@ var AddTracesStage = class extends ConverterStage {
1630
1726
  for (let i = 0; i < trace.route.length - 1; i++) {
1631
1727
  const startPoint = trace.route[i];
1632
1728
  const endPoint = trace.route[i + 1];
1633
- const transformedStart = applyToPoint6(c2kMatPcb, {
1729
+ const transformedStart = applyToPoint10(c2kMatPcb, {
1634
1730
  x: startPoint.x,
1635
1731
  y: startPoint.y
1636
1732
  });
1637
- const transformedEnd = applyToPoint6(c2kMatPcb, {
1733
+ const transformedEnd = applyToPoint10(c2kMatPcb, {
1638
1734
  x: endPoint.x,
1639
1735
  y: endPoint.y
1640
1736
  });
@@ -1668,7 +1764,7 @@ var AddTracesStage = class extends ConverterStage {
1668
1764
 
1669
1765
  // lib/pcb/stages/AddViasStage.ts
1670
1766
  import { Via, ViaNet } from "kicadts";
1671
- import { applyToPoint as applyToPoint7 } from "transformation-matrix";
1767
+ import { applyToPoint as applyToPoint11 } from "transformation-matrix";
1672
1768
  var AddViasStage = class extends ConverterStage {
1673
1769
  viasProcessed = 0;
1674
1770
  pcbVias = [];
@@ -1689,7 +1785,7 @@ var AddViasStage = class extends ConverterStage {
1689
1785
  return;
1690
1786
  }
1691
1787
  const via = this.pcbVias[this.viasProcessed];
1692
- const transformedPos = applyToPoint7(c2kMatPcb, {
1788
+ const transformedPos = applyToPoint11(c2kMatPcb, {
1693
1789
  x: via.x,
1694
1790
  y: via.y
1695
1791
  });
@@ -1716,7 +1812,7 @@ var AddViasStage = class extends ConverterStage {
1716
1812
 
1717
1813
  // lib/pcb/stages/AddGraphicsStage.ts
1718
1814
  import { GrLine } from "kicadts";
1719
- import { applyToPoint as applyToPoint8 } from "transformation-matrix";
1815
+ import { applyToPoint as applyToPoint12 } from "transformation-matrix";
1720
1816
  var AddGraphicsStage = class extends ConverterStage {
1721
1817
  _step() {
1722
1818
  const { kicadPcb, c2kMatPcb } = this.ctx;
@@ -1733,11 +1829,11 @@ var AddGraphicsStage = class extends ConverterStage {
1733
1829
  const startPoint = path.route[i];
1734
1830
  const endPoint = path.route[i + 1];
1735
1831
  if (!startPoint || !endPoint) continue;
1736
- const transformedStart = applyToPoint8(c2kMatPcb, {
1832
+ const transformedStart = applyToPoint12(c2kMatPcb, {
1737
1833
  x: startPoint.x,
1738
1834
  y: startPoint.y
1739
1835
  });
1740
- const transformedEnd = applyToPoint8(c2kMatPcb, {
1836
+ const transformedEnd = applyToPoint12(c2kMatPcb, {
1741
1837
  x: endPoint.x,
1742
1838
  y: endPoint.y
1743
1839
  });
@@ -1778,7 +1874,7 @@ var AddGraphicsStage = class extends ConverterStage {
1778
1874
  ];
1779
1875
  }
1780
1876
  const transformedCorners = corners.map(
1781
- (corner) => applyToPoint8(c2kMatPcb, corner)
1877
+ (corner) => applyToPoint12(c2kMatPcb, corner)
1782
1878
  );
1783
1879
  for (let i = 0; i < transformedCorners.length; i++) {
1784
1880
  const start = transformedCorners[i];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-json-to-kicad",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.19",
4
+ "version": "0.0.21",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"