circuit-json-to-kicad 0.0.16 → 0.0.18

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 +199 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1349,8 +1349,133 @@ var AddNetsStage = class extends ConverterStage {
1349
1349
  };
1350
1350
 
1351
1351
  // lib/pcb/stages/AddFootprintsStage.ts
1352
- import { Footprint, FpText, FootprintPad } from "kicadts";
1352
+ import { Footprint, FpText } from "kicadts";
1353
1353
  import { applyToPoint as applyToPoint5 } from "transformation-matrix";
1354
+
1355
+ // lib/pcb/stages/utils/CreateSmdPadFromCircuitJson.ts
1356
+ import { FootprintPad } from "kicadts";
1357
+ function createSmdPadFromCircuitJson({
1358
+ pcbPad,
1359
+ componentCenter,
1360
+ padNumber
1361
+ }) {
1362
+ if (!("x" in pcbPad && "y" in pcbPad)) {
1363
+ throw new Error("no support for polygon pads (or any pads w/o X/Y) yet");
1364
+ }
1365
+ const relativeX = pcbPad.x - componentCenter.x;
1366
+ const relativeY = -(pcbPad.y - componentCenter.y);
1367
+ const layerMap = {
1368
+ top: "F.Cu",
1369
+ bottom: "B.Cu"
1370
+ };
1371
+ const padLayer = layerMap[pcbPad.layer] || "F.Cu";
1372
+ const padShape = pcbPad.shape === "circle" ? "circle" : "rect";
1373
+ const padSize = pcbPad.shape === "circle" ? [
1374
+ "radius" in pcbPad ? pcbPad.radius * 2 : 0.5,
1375
+ "radius" in pcbPad ? pcbPad.radius * 2 : 0.5
1376
+ ] : [
1377
+ "width" in pcbPad ? pcbPad.width : 0.5,
1378
+ "height" in pcbPad ? pcbPad.height : 0.5
1379
+ ];
1380
+ return new FootprintPad({
1381
+ number: String(padNumber),
1382
+ padType: "smd",
1383
+ shape: padShape,
1384
+ at: [relativeX, relativeY, 0],
1385
+ size: padSize,
1386
+ layers: [
1387
+ `${padLayer}`,
1388
+ `${padLayer === "F.Cu" ? "F" : "B"}.Paste`,
1389
+ `${padLayer === "F.Cu" ? "F" : "B"}.Mask`
1390
+ ],
1391
+ uuid: crypto.randomUUID()
1392
+ });
1393
+ }
1394
+
1395
+ // lib/pcb/stages/utils/CreateThruHolePadFromCircuitJson.ts
1396
+ import { FootprintPad as FootprintPad2, PadDrill } from "kicadts";
1397
+ function createThruHolePadFromCircuitJson({
1398
+ platedHole,
1399
+ componentCenter,
1400
+ padNumber
1401
+ }) {
1402
+ if (!("x" in platedHole && "y" in platedHole)) {
1403
+ return null;
1404
+ }
1405
+ const relativeX = platedHole.x - componentCenter.x;
1406
+ const relativeY = -(platedHole.y - componentCenter.y);
1407
+ let padShape = "circle";
1408
+ let padSize;
1409
+ let drill;
1410
+ let rotation = 0;
1411
+ if (platedHole.shape === "circle") {
1412
+ padShape = "circle";
1413
+ padSize = [platedHole.outer_diameter, platedHole.outer_diameter];
1414
+ drill = new PadDrill({
1415
+ diameter: platedHole.hole_diameter
1416
+ });
1417
+ } else if (platedHole.shape === "pill" || platedHole.shape === "oval") {
1418
+ padShape = "oval";
1419
+ padSize = [
1420
+ platedHole.outer_width,
1421
+ platedHole.outer_height
1422
+ ];
1423
+ drill = new PadDrill({
1424
+ oval: true,
1425
+ diameter: platedHole.hole_width,
1426
+ width: platedHole.hole_height
1427
+ });
1428
+ } else if (platedHole.shape === "pill_hole_with_rect_pad") {
1429
+ padShape = "rect";
1430
+ padSize = [
1431
+ platedHole.rect_pad_width,
1432
+ platedHole.rect_pad_height
1433
+ ];
1434
+ drill = new PadDrill({
1435
+ oval: true,
1436
+ diameter: platedHole.hole_width,
1437
+ width: platedHole.hole_height
1438
+ });
1439
+ } else if (platedHole.shape === "circular_hole_with_rect_pad") {
1440
+ padShape = "rect";
1441
+ padSize = [
1442
+ platedHole.rect_pad_width,
1443
+ platedHole.rect_pad_height
1444
+ ];
1445
+ drill = new PadDrill({
1446
+ diameter: platedHole.hole_diameter
1447
+ });
1448
+ } else if (platedHole.shape === "rotated_pill_hole_with_rect_pad") {
1449
+ padShape = "rect";
1450
+ padSize = [
1451
+ platedHole.rect_pad_width,
1452
+ platedHole.rect_pad_height
1453
+ ];
1454
+ drill = new PadDrill({
1455
+ oval: true,
1456
+ diameter: platedHole.hole_width,
1457
+ width: platedHole.hole_height
1458
+ });
1459
+ rotation = platedHole.rect_ccw_rotation || 0;
1460
+ } else {
1461
+ padShape = "circle";
1462
+ padSize = [1.6, 1.6];
1463
+ drill = new PadDrill({ diameter: 0.8 });
1464
+ }
1465
+ return new FootprintPad2({
1466
+ number: String(padNumber),
1467
+ padType: "thru_hole",
1468
+ shape: padShape,
1469
+ at: [relativeX, relativeY, rotation],
1470
+ size: padSize,
1471
+ drill,
1472
+ layers: ["*.Cu", "*.Mask"],
1473
+ removeUnusedLayers: false,
1474
+ uuid: crypto.randomUUID()
1475
+ });
1476
+ }
1477
+
1478
+ // lib/pcb/stages/AddFootprintsStage.ts
1354
1479
  var AddFootprintsStage = class extends ConverterStage {
1355
1480
  componentsProcessed = 0;
1356
1481
  pcbComponents = [];
@@ -1408,40 +1533,28 @@ var AddFootprintsStage = class extends ConverterStage {
1408
1533
  const fpPads = footprint.fpPads;
1409
1534
  let padNumber = 1;
1410
1535
  for (const pcbPad of pcbPads) {
1411
- if (!("x" in pcbPad && "y" in pcbPad)) {
1412
- throw new Error("no support for polygon pads (or any pads w/o X/Y) yet");
1413
- }
1414
- const relativeX = pcbPad.x - component.center.x;
1415
- const relativeY = pcbPad.y - component.center.y;
1416
- const layerMap = {
1417
- top: "F.Cu",
1418
- bottom: "B.Cu"
1419
- };
1420
- const padLayer = layerMap[pcbPad.layer] || "F.Cu";
1421
- const padShape = pcbPad.shape === "circle" ? "circle" : "rect";
1422
- const padSize = pcbPad.shape === "circle" ? [
1423
- "radius" in pcbPad ? pcbPad.radius * 2 : 0.5,
1424
- "radius" in pcbPad ? pcbPad.radius * 2 : 0.5
1425
- ] : [
1426
- "width" in pcbPad ? pcbPad.width : 0.5,
1427
- "height" in pcbPad ? pcbPad.height : 0.5
1428
- ];
1429
- const pad = new FootprintPad({
1430
- number: String(padNumber),
1431
- padType: "smd",
1432
- shape: padShape,
1433
- at: [relativeX, relativeY, 0],
1434
- size: padSize,
1435
- layers: [
1436
- `${padLayer}`,
1437
- `${padLayer === "F.Cu" ? "F" : "B"}.Paste`,
1438
- `${padLayer === "F.Cu" ? "F" : "B"}.Mask`
1439
- ],
1440
- uuid: crypto.randomUUID()
1536
+ const pad = createSmdPadFromCircuitJson({
1537
+ pcbPad,
1538
+ componentCenter: component.center,
1539
+ padNumber
1441
1540
  });
1442
1541
  fpPads.push(pad);
1443
1542
  padNumber++;
1444
1543
  }
1544
+ const pcbPlatedHoles = this.ctx.db.pcb_plated_hole?.list().filter(
1545
+ (hole) => hole.pcb_component_id === component.pcb_component_id
1546
+ ) || [];
1547
+ for (const platedHole of pcbPlatedHoles) {
1548
+ const pad = createThruHolePadFromCircuitJson({
1549
+ platedHole,
1550
+ componentCenter: component.center,
1551
+ padNumber
1552
+ });
1553
+ if (pad) {
1554
+ fpPads.push(pad);
1555
+ padNumber++;
1556
+ }
1557
+ }
1445
1558
  footprint.fpPads = fpPads;
1446
1559
  const footprints = kicadPcb.footprints;
1447
1560
  footprints.push(footprint);
@@ -1569,7 +1682,47 @@ var AddViasStage = class extends ConverterStage {
1569
1682
 
1570
1683
  // lib/pcb/stages/AddGraphicsStage.ts
1571
1684
  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";
1572
1689
  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
1573
1726
  var AddGraphicsStage = class extends ConverterStage {
1574
1727
  _step() {
1575
1728
  const { kicadPcb, c2kMatPcb } = this.ctx;
@@ -1586,11 +1739,11 @@ var AddGraphicsStage = class extends ConverterStage {
1586
1739
  const startPoint = path.route[i];
1587
1740
  const endPoint = path.route[i + 1];
1588
1741
  if (!startPoint || !endPoint) continue;
1589
- const transformedStart = applyToPoint8(c2kMatPcb, {
1742
+ const transformedStart = applyToPoint9(c2kMatPcb, {
1590
1743
  x: startPoint.x,
1591
1744
  y: startPoint.y
1592
1745
  });
1593
- const transformedEnd = applyToPoint8(c2kMatPcb, {
1746
+ const transformedEnd = applyToPoint9(c2kMatPcb, {
1594
1747
  x: endPoint.x,
1595
1748
  y: endPoint.y
1596
1749
  });
@@ -1610,6 +1763,18 @@ var AddGraphicsStage = class extends ConverterStage {
1610
1763
  kicadPcb.graphicLines = graphicLines;
1611
1764
  }
1612
1765
  }
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
+ }
1613
1778
  const pcbBoards = this.ctx.db.pcb_board?.list() || [];
1614
1779
  if (pcbBoards.length > 0) {
1615
1780
  const board = pcbBoards[0];
@@ -1631,7 +1796,7 @@ var AddGraphicsStage = class extends ConverterStage {
1631
1796
  ];
1632
1797
  }
1633
1798
  const transformedCorners = corners.map(
1634
- (corner) => applyToPoint8(c2kMatPcb, corner)
1799
+ (corner) => applyToPoint9(c2kMatPcb, corner)
1635
1800
  );
1636
1801
  for (let i = 0; i < transformedCorners.length; i++) {
1637
1802
  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.16",
4
+ "version": "0.0.18",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"