circuit-json-to-kicad 0.0.18 → 0.0.20

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 +117 -72
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1349,7 +1349,7 @@ var AddNetsStage = class extends ConverterStage {
1349
1349
  };
1350
1350
 
1351
1351
  // lib/pcb/stages/AddFootprintsStage.ts
1352
- import { Footprint, FpText } from "kicadts";
1352
+ import { Footprint } from "kicadts";
1353
1353
  import { applyToPoint as applyToPoint5 } from "transformation-matrix";
1354
1354
 
1355
1355
  // lib/pcb/stages/utils/CreateSmdPadFromCircuitJson.ts
@@ -1475,6 +1475,95 @@ function createThruHolePadFromCircuitJson({
1475
1475
  });
1476
1476
  }
1477
1477
 
1478
+ // lib/pcb/stages/utils/CreateNpthPadFromCircuitJson.ts
1479
+ import { FootprintPad as FootprintPad3, PadDrill as PadDrill2 } from "kicadts";
1480
+ function createNpthPadFromCircuitJson({
1481
+ pcbHole,
1482
+ componentCenter
1483
+ }) {
1484
+ if (!("x" in pcbHole && "y" in pcbHole)) {
1485
+ return null;
1486
+ }
1487
+ const relativeX = pcbHole.x - componentCenter.x;
1488
+ const relativeY = -(pcbHole.y - componentCenter.y);
1489
+ let padShape = "circle";
1490
+ let padSize;
1491
+ let drill;
1492
+ if (pcbHole.hole_shape === "circle") {
1493
+ padShape = "circle";
1494
+ const diameter = pcbHole.hole_diameter;
1495
+ padSize = [diameter, diameter];
1496
+ drill = new PadDrill2({
1497
+ diameter
1498
+ });
1499
+ } else if (pcbHole.hole_shape === "oval") {
1500
+ padShape = "oval";
1501
+ const width = pcbHole.hole_width;
1502
+ const height = pcbHole.hole_height;
1503
+ padSize = [width, height];
1504
+ drill = new PadDrill2({
1505
+ oval: true,
1506
+ diameter: width,
1507
+ width: height
1508
+ });
1509
+ } else {
1510
+ padShape = "circle";
1511
+ const diameter = pcbHole.hole_diameter || 1;
1512
+ padSize = [diameter, diameter];
1513
+ drill = new PadDrill2({ diameter });
1514
+ }
1515
+ return new FootprintPad3({
1516
+ number: "",
1517
+ // Non-plated holes have no pad number
1518
+ padType: "np_thru_hole",
1519
+ shape: padShape,
1520
+ at: [relativeX, relativeY, 0],
1521
+ size: padSize,
1522
+ drill,
1523
+ layers: ["*.Cu", "*.Mask"],
1524
+ removeUnusedLayers: false,
1525
+ uuid: crypto.randomUUID()
1526
+ });
1527
+ }
1528
+
1529
+ // lib/pcb/stages/utils/CreateFpTextFromCircuitJson.ts
1530
+ import { FpText, TextEffects as TextEffects4, TextEffectsFont as TextEffectsFont4 } from "kicadts";
1531
+ function createFpTextFromCircuitJson({
1532
+ textElement,
1533
+ componentCenter
1534
+ }) {
1535
+ if (!textElement.text || !textElement.anchor_position) {
1536
+ return null;
1537
+ }
1538
+ const relativePosition = {
1539
+ x: textElement.anchor_position.x - componentCenter.x,
1540
+ y: -(textElement.anchor_position.y - componentCenter.y)
1541
+ };
1542
+ const layerMap = {
1543
+ top: "F.SilkS",
1544
+ bottom: "B.SilkS"
1545
+ };
1546
+ const kicadLayer = layerMap[textElement.layer] || textElement.layer || "F.SilkS";
1547
+ const fontSize = (textElement.font_size || 1) / 1.5;
1548
+ const font = new TextEffectsFont4();
1549
+ font.size = { width: fontSize, height: fontSize };
1550
+ const textEffects = new TextEffects4({
1551
+ font
1552
+ });
1553
+ const rotation = textElement.ccw_rotation || 0;
1554
+ return new FpText({
1555
+ type: "user",
1556
+ text: textElement.text,
1557
+ position: {
1558
+ x: relativePosition.x,
1559
+ y: relativePosition.y,
1560
+ angle: rotation
1561
+ },
1562
+ layer: kicadLayer,
1563
+ effects: textEffects
1564
+ });
1565
+ }
1566
+
1478
1567
  // lib/pcb/stages/AddFootprintsStage.ts
1479
1568
  var AddFootprintsStage = class extends ConverterStage {
1480
1569
  componentsProcessed = 0;
@@ -1509,23 +1598,19 @@ var AddFootprintsStage = class extends ConverterStage {
1509
1598
  at: [transformedPos.x, transformedPos.y, component.rotation || 0],
1510
1599
  uuid: crypto.randomUUID()
1511
1600
  });
1512
- const refText = new FpText({
1513
- type: "reference",
1514
- text: componentName,
1515
- position: [0, -1.5, 0],
1516
- layer: "F.SilkS",
1517
- uuid: crypto.randomUUID()
1518
- });
1519
- const valueText = new FpText({
1520
- type: "value",
1521
- text: footprintName,
1522
- position: [0, 1.5, 0],
1523
- layer: "F.Fab",
1524
- uuid: crypto.randomUUID()
1525
- });
1526
1601
  const fpTexts = footprint.fpTexts;
1527
- fpTexts.push(refText);
1528
- fpTexts.push(valueText);
1602
+ const pcbSilkscreenTexts = this.ctx.db.pcb_silkscreen_text?.list().filter(
1603
+ (text) => text.pcb_component_id === component.pcb_component_id
1604
+ ) || [];
1605
+ for (const textElement of pcbSilkscreenTexts) {
1606
+ const fpText = createFpTextFromCircuitJson({
1607
+ textElement,
1608
+ componentCenter: component.center
1609
+ });
1610
+ if (fpText) {
1611
+ fpTexts.push(fpText);
1612
+ }
1613
+ }
1529
1614
  footprint.fpTexts = fpTexts;
1530
1615
  const pcbPads = this.ctx.db.pcb_smtpad?.list().filter(
1531
1616
  (pad) => pad.pcb_component_id === component.pcb_component_id
@@ -1555,6 +1640,18 @@ var AddFootprintsStage = class extends ConverterStage {
1555
1640
  padNumber++;
1556
1641
  }
1557
1642
  }
1643
+ const pcbHoles = this.ctx.db.pcb_hole?.list().filter(
1644
+ (hole) => hole.subcircuit_id === component.subcircuit_id
1645
+ ) || [];
1646
+ for (const pcbHole of pcbHoles) {
1647
+ const pad = createNpthPadFromCircuitJson({
1648
+ pcbHole,
1649
+ componentCenter: component.center
1650
+ });
1651
+ if (pad) {
1652
+ fpPads.push(pad);
1653
+ }
1654
+ }
1558
1655
  footprint.fpPads = fpPads;
1559
1656
  const footprints = kicadPcb.footprints;
1560
1657
  footprints.push(footprint);
@@ -1682,47 +1779,7 @@ var AddViasStage = class extends ConverterStage {
1682
1779
 
1683
1780
  // lib/pcb/stages/AddGraphicsStage.ts
1684
1781
  import { GrLine } from "kicadts";
1685
- import { applyToPoint as applyToPoint9 } from "transformation-matrix";
1686
-
1687
- // lib/pcb/stages/utils/CreateGrTextFromCircuitJson.ts
1688
- import { GrText, TextEffects as TextEffects4, TextEffectsFont as TextEffectsFont4 } from "kicadts";
1689
1782
  import { applyToPoint as applyToPoint8 } from "transformation-matrix";
1690
- function createGrTextFromCircuitJson({
1691
- textElement,
1692
- transformationMatrix
1693
- }) {
1694
- if (!textElement.text || !textElement.anchor_position) {
1695
- return null;
1696
- }
1697
- const transformedPosition = applyToPoint8(transformationMatrix, {
1698
- x: textElement.anchor_position.x,
1699
- y: textElement.anchor_position.y
1700
- });
1701
- const layerMap = {
1702
- top: "F.SilkS",
1703
- bottom: "B.SilkS"
1704
- };
1705
- const kicadLayer = layerMap[textElement.layer] || textElement.layer || "F.SilkS";
1706
- const fontSize = (textElement.font_size || 1) / 2;
1707
- const font = new TextEffectsFont4();
1708
- font.size = { width: fontSize, height: fontSize };
1709
- const textEffects = new TextEffects4({
1710
- font
1711
- });
1712
- const rotation = textElement.ccw_rotation || 0;
1713
- return new GrText({
1714
- text: textElement.text,
1715
- position: {
1716
- x: transformedPosition.x,
1717
- y: transformedPosition.y,
1718
- angle: rotation
1719
- },
1720
- layer: kicadLayer,
1721
- effects: textEffects
1722
- });
1723
- }
1724
-
1725
- // lib/pcb/stages/AddGraphicsStage.ts
1726
1783
  var AddGraphicsStage = class extends ConverterStage {
1727
1784
  _step() {
1728
1785
  const { kicadPcb, c2kMatPcb } = this.ctx;
@@ -1739,11 +1796,11 @@ var AddGraphicsStage = class extends ConverterStage {
1739
1796
  const startPoint = path.route[i];
1740
1797
  const endPoint = path.route[i + 1];
1741
1798
  if (!startPoint || !endPoint) continue;
1742
- const transformedStart = applyToPoint9(c2kMatPcb, {
1799
+ const transformedStart = applyToPoint8(c2kMatPcb, {
1743
1800
  x: startPoint.x,
1744
1801
  y: startPoint.y
1745
1802
  });
1746
- const transformedEnd = applyToPoint9(c2kMatPcb, {
1803
+ const transformedEnd = applyToPoint8(c2kMatPcb, {
1747
1804
  x: endPoint.x,
1748
1805
  y: endPoint.y
1749
1806
  });
@@ -1763,18 +1820,6 @@ var AddGraphicsStage = class extends ConverterStage {
1763
1820
  kicadPcb.graphicLines = graphicLines;
1764
1821
  }
1765
1822
  }
1766
- const pcbSilkscreenTexts = this.ctx.db.pcb_silkscreen_text?.list() || [];
1767
- for (const textElement of pcbSilkscreenTexts) {
1768
- const grText = createGrTextFromCircuitJson({
1769
- textElement,
1770
- transformationMatrix: c2kMatPcb
1771
- });
1772
- if (grText) {
1773
- const graphicTexts = kicadPcb.graphicTexts || [];
1774
- graphicTexts.push(grText);
1775
- kicadPcb.graphicTexts = graphicTexts;
1776
- }
1777
- }
1778
1823
  const pcbBoards = this.ctx.db.pcb_board?.list() || [];
1779
1824
  if (pcbBoards.length > 0) {
1780
1825
  const board = pcbBoards[0];
@@ -1796,7 +1841,7 @@ var AddGraphicsStage = class extends ConverterStage {
1796
1841
  ];
1797
1842
  }
1798
1843
  const transformedCorners = corners.map(
1799
- (corner) => applyToPoint9(c2kMatPcb, corner)
1844
+ (corner) => applyToPoint8(c2kMatPcb, corner)
1800
1845
  );
1801
1846
  for (let i = 0; i < transformedCorners.length; i++) {
1802
1847
  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.18",
4
+ "version": "0.0.20",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"