circuit-json-to-kicad 0.0.20 → 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 +58 -25
  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,7 @@ 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],
1470
1484
  size: padSize,
1471
1485
  drill,
1472
1486
  layers: ["*.Cu", "*.Mask"],
@@ -1477,15 +1491,22 @@ function createThruHolePadFromCircuitJson({
1477
1491
 
1478
1492
  // lib/pcb/stages/utils/CreateNpthPadFromCircuitJson.ts
1479
1493
  import { FootprintPad as FootprintPad3, PadDrill as PadDrill2 } from "kicadts";
1494
+ import { applyToPoint as applyToPoint7, rotate as rotate3, identity as identity3 } from "transformation-matrix";
1480
1495
  function createNpthPadFromCircuitJson({
1481
1496
  pcbHole,
1482
- componentCenter
1497
+ componentCenter,
1498
+ componentRotation = 0
1483
1499
  }) {
1484
1500
  if (!("x" in pcbHole && "y" in pcbHole)) {
1485
1501
  return null;
1486
1502
  }
1487
1503
  const relativeX = pcbHole.x - componentCenter.x;
1488
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
+ });
1489
1510
  let padShape = "circle";
1490
1511
  let padSize;
1491
1512
  let drill;
@@ -1517,7 +1538,7 @@ function createNpthPadFromCircuitJson({
1517
1538
  // Non-plated holes have no pad number
1518
1539
  padType: "np_thru_hole",
1519
1540
  shape: padShape,
1520
- at: [relativeX, relativeY, 0],
1541
+ at: [rotatedPos.x, rotatedPos.y, 0],
1521
1542
  size: padSize,
1522
1543
  drill,
1523
1544
  layers: ["*.Cu", "*.Mask"],
@@ -1528,16 +1549,25 @@ function createNpthPadFromCircuitJson({
1528
1549
 
1529
1550
  // lib/pcb/stages/utils/CreateFpTextFromCircuitJson.ts
1530
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";
1531
1553
  function createFpTextFromCircuitJson({
1532
1554
  textElement,
1533
- componentCenter
1555
+ componentCenter,
1556
+ componentRotation = 0
1534
1557
  }) {
1535
1558
  if (!textElement.text || !textElement.anchor_position) {
1536
1559
  return null;
1537
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
+ });
1538
1568
  const relativePosition = {
1539
- x: textElement.anchor_position.x - componentCenter.x,
1540
- y: -(textElement.anchor_position.y - componentCenter.y)
1569
+ x: rotatedPos.x,
1570
+ y: rotatedPos.y
1541
1571
  };
1542
1572
  const layerMap = {
1543
1573
  top: "F.SilkS",
@@ -1587,8 +1617,7 @@ var AddFootprintsStage = class extends ConverterStage {
1587
1617
  const component = this.pcbComponents[this.componentsProcessed];
1588
1618
  const sourceComponent = component.source_component_id ? this.ctx.db.source_component.get(component.source_component_id) : null;
1589
1619
  const footprintName = sourceComponent?.ftype || "Unknown";
1590
- const componentName = sourceComponent?.name || `Component_${this.componentsProcessed}`;
1591
- const transformedPos = applyToPoint5(c2kMatPcb, {
1620
+ const transformedPos = applyToPoint9(c2kMatPcb, {
1592
1621
  x: component.center.x,
1593
1622
  y: component.center.y
1594
1623
  });
@@ -1605,7 +1634,8 @@ var AddFootprintsStage = class extends ConverterStage {
1605
1634
  for (const textElement of pcbSilkscreenTexts) {
1606
1635
  const fpText = createFpTextFromCircuitJson({
1607
1636
  textElement,
1608
- componentCenter: component.center
1637
+ componentCenter: component.center,
1638
+ componentRotation: component.rotation || 0
1609
1639
  });
1610
1640
  if (fpText) {
1611
1641
  fpTexts.push(fpText);
@@ -1621,7 +1651,8 @@ var AddFootprintsStage = class extends ConverterStage {
1621
1651
  const pad = createSmdPadFromCircuitJson({
1622
1652
  pcbPad,
1623
1653
  componentCenter: component.center,
1624
- padNumber
1654
+ padNumber,
1655
+ componentRotation: component.rotation || 0
1625
1656
  });
1626
1657
  fpPads.push(pad);
1627
1658
  padNumber++;
@@ -1633,7 +1664,8 @@ var AddFootprintsStage = class extends ConverterStage {
1633
1664
  const pad = createThruHolePadFromCircuitJson({
1634
1665
  platedHole,
1635
1666
  componentCenter: component.center,
1636
- padNumber
1667
+ padNumber,
1668
+ componentRotation: component.rotation || 0
1637
1669
  });
1638
1670
  if (pad) {
1639
1671
  fpPads.push(pad);
@@ -1646,7 +1678,8 @@ var AddFootprintsStage = class extends ConverterStage {
1646
1678
  for (const pcbHole of pcbHoles) {
1647
1679
  const pad = createNpthPadFromCircuitJson({
1648
1680
  pcbHole,
1649
- componentCenter: component.center
1681
+ componentCenter: component.center,
1682
+ componentRotation: component.rotation || 0
1650
1683
  });
1651
1684
  if (pad) {
1652
1685
  fpPads.push(pad);
@@ -1665,7 +1698,7 @@ var AddFootprintsStage = class extends ConverterStage {
1665
1698
 
1666
1699
  // lib/pcb/stages/AddTracesStage.ts
1667
1700
  import { Segment, SegmentNet } from "kicadts";
1668
- import { applyToPoint as applyToPoint6 } from "transformation-matrix";
1701
+ import { applyToPoint as applyToPoint10 } from "transformation-matrix";
1669
1702
  var AddTracesStage = class extends ConverterStage {
1670
1703
  tracesProcessed = 0;
1671
1704
  pcbTraces = [];
@@ -1693,11 +1726,11 @@ var AddTracesStage = class extends ConverterStage {
1693
1726
  for (let i = 0; i < trace.route.length - 1; i++) {
1694
1727
  const startPoint = trace.route[i];
1695
1728
  const endPoint = trace.route[i + 1];
1696
- const transformedStart = applyToPoint6(c2kMatPcb, {
1729
+ const transformedStart = applyToPoint10(c2kMatPcb, {
1697
1730
  x: startPoint.x,
1698
1731
  y: startPoint.y
1699
1732
  });
1700
- const transformedEnd = applyToPoint6(c2kMatPcb, {
1733
+ const transformedEnd = applyToPoint10(c2kMatPcb, {
1701
1734
  x: endPoint.x,
1702
1735
  y: endPoint.y
1703
1736
  });
@@ -1731,7 +1764,7 @@ var AddTracesStage = class extends ConverterStage {
1731
1764
 
1732
1765
  // lib/pcb/stages/AddViasStage.ts
1733
1766
  import { Via, ViaNet } from "kicadts";
1734
- import { applyToPoint as applyToPoint7 } from "transformation-matrix";
1767
+ import { applyToPoint as applyToPoint11 } from "transformation-matrix";
1735
1768
  var AddViasStage = class extends ConverterStage {
1736
1769
  viasProcessed = 0;
1737
1770
  pcbVias = [];
@@ -1752,7 +1785,7 @@ var AddViasStage = class extends ConverterStage {
1752
1785
  return;
1753
1786
  }
1754
1787
  const via = this.pcbVias[this.viasProcessed];
1755
- const transformedPos = applyToPoint7(c2kMatPcb, {
1788
+ const transformedPos = applyToPoint11(c2kMatPcb, {
1756
1789
  x: via.x,
1757
1790
  y: via.y
1758
1791
  });
@@ -1779,7 +1812,7 @@ var AddViasStage = class extends ConverterStage {
1779
1812
 
1780
1813
  // lib/pcb/stages/AddGraphicsStage.ts
1781
1814
  import { GrLine } from "kicadts";
1782
- import { applyToPoint as applyToPoint8 } from "transformation-matrix";
1815
+ import { applyToPoint as applyToPoint12 } from "transformation-matrix";
1783
1816
  var AddGraphicsStage = class extends ConverterStage {
1784
1817
  _step() {
1785
1818
  const { kicadPcb, c2kMatPcb } = this.ctx;
@@ -1796,11 +1829,11 @@ var AddGraphicsStage = class extends ConverterStage {
1796
1829
  const startPoint = path.route[i];
1797
1830
  const endPoint = path.route[i + 1];
1798
1831
  if (!startPoint || !endPoint) continue;
1799
- const transformedStart = applyToPoint8(c2kMatPcb, {
1832
+ const transformedStart = applyToPoint12(c2kMatPcb, {
1800
1833
  x: startPoint.x,
1801
1834
  y: startPoint.y
1802
1835
  });
1803
- const transformedEnd = applyToPoint8(c2kMatPcb, {
1836
+ const transformedEnd = applyToPoint12(c2kMatPcb, {
1804
1837
  x: endPoint.x,
1805
1838
  y: endPoint.y
1806
1839
  });
@@ -1841,7 +1874,7 @@ var AddGraphicsStage = class extends ConverterStage {
1841
1874
  ];
1842
1875
  }
1843
1876
  const transformedCorners = corners.map(
1844
- (corner) => applyToPoint8(c2kMatPcb, corner)
1877
+ (corner) => applyToPoint12(c2kMatPcb, corner)
1845
1878
  );
1846
1879
  for (let i = 0; i < transformedCorners.length; i++) {
1847
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.20",
4
+ "version": "0.0.21",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"