circuit-json-to-kicad 0.0.21 → 0.0.22

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 +84 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1812,7 +1812,76 @@ var AddViasStage = class extends ConverterStage {
1812
1812
 
1813
1813
  // lib/pcb/stages/AddGraphicsStage.ts
1814
1814
  import { GrLine } from "kicadts";
1815
+ import { applyToPoint as applyToPoint13 } from "transformation-matrix";
1816
+
1817
+ // lib/pcb/stages/utils/CreateGrTextFromCircuitJson.ts
1818
+ import {
1819
+ GrText,
1820
+ TextEffects as TextEffects5,
1821
+ TextEffectsFont as TextEffectsFont5,
1822
+ TextEffectsJustify as TextEffectsJustify3,
1823
+ At
1824
+ } from "kicadts";
1815
1825
  import { applyToPoint as applyToPoint12 } from "transformation-matrix";
1826
+ function createGrTextFromCircuitJson({
1827
+ textElement,
1828
+ c2kMatPcb
1829
+ }) {
1830
+ if (!textElement.text || !textElement.anchor_position) {
1831
+ return null;
1832
+ }
1833
+ const transformedPos = applyToPoint12(c2kMatPcb, {
1834
+ x: textElement.anchor_position.x,
1835
+ y: textElement.anchor_position.y
1836
+ });
1837
+ const layerMap = {
1838
+ top: "F.SilkS",
1839
+ bottom: "B.SilkS"
1840
+ };
1841
+ const kicadLayer = layerMap[textElement.layer] || textElement.layer || "F.SilkS";
1842
+ const fontSize = (textElement.font_size || 1) / 1.5;
1843
+ const font = new TextEffectsFont5();
1844
+ font.size = { width: fontSize, height: fontSize };
1845
+ const justify = new TextEffectsJustify3();
1846
+ const anchorAlignment = textElement.anchor_alignment || "center";
1847
+ switch (anchorAlignment) {
1848
+ case "top_left":
1849
+ justify.horizontal = "left";
1850
+ justify.vertical = "top";
1851
+ break;
1852
+ case "top_right":
1853
+ justify.horizontal = "right";
1854
+ justify.vertical = "top";
1855
+ break;
1856
+ case "bottom_left":
1857
+ justify.horizontal = "left";
1858
+ justify.vertical = "bottom";
1859
+ break;
1860
+ case "bottom_right":
1861
+ justify.horizontal = "right";
1862
+ justify.vertical = "bottom";
1863
+ break;
1864
+ case "center":
1865
+ break;
1866
+ }
1867
+ const textEffects = new TextEffects5({
1868
+ font
1869
+ });
1870
+ if (anchorAlignment !== "center") {
1871
+ textEffects.justify = justify;
1872
+ }
1873
+ const rotation = textElement.ccw_rotation || 0;
1874
+ const position = new At([transformedPos.x, transformedPos.y, rotation]);
1875
+ const grText = new GrText({
1876
+ text: textElement.text,
1877
+ layer: kicadLayer,
1878
+ effects: textEffects
1879
+ });
1880
+ grText.position = position;
1881
+ return grText;
1882
+ }
1883
+
1884
+ // lib/pcb/stages/AddGraphicsStage.ts
1816
1885
  var AddGraphicsStage = class extends ConverterStage {
1817
1886
  _step() {
1818
1887
  const { kicadPcb, c2kMatPcb } = this.ctx;
@@ -1829,11 +1898,11 @@ var AddGraphicsStage = class extends ConverterStage {
1829
1898
  const startPoint = path.route[i];
1830
1899
  const endPoint = path.route[i + 1];
1831
1900
  if (!startPoint || !endPoint) continue;
1832
- const transformedStart = applyToPoint12(c2kMatPcb, {
1901
+ const transformedStart = applyToPoint13(c2kMatPcb, {
1833
1902
  x: startPoint.x,
1834
1903
  y: startPoint.y
1835
1904
  });
1836
- const transformedEnd = applyToPoint12(c2kMatPcb, {
1905
+ const transformedEnd = applyToPoint13(c2kMatPcb, {
1837
1906
  x: endPoint.x,
1838
1907
  y: endPoint.y
1839
1908
  });
@@ -1853,6 +1922,18 @@ var AddGraphicsStage = class extends ConverterStage {
1853
1922
  kicadPcb.graphicLines = graphicLines;
1854
1923
  }
1855
1924
  }
1925
+ const standaloneSilkscreenTexts = this.ctx.db.pcb_silkscreen_text?.list().filter((text) => !text.pcb_component_id) || [];
1926
+ for (const textElement of standaloneSilkscreenTexts) {
1927
+ const grText = createGrTextFromCircuitJson({
1928
+ textElement,
1929
+ c2kMatPcb
1930
+ });
1931
+ if (grText) {
1932
+ const graphicTexts = kicadPcb.graphicTexts;
1933
+ graphicTexts.push(grText);
1934
+ kicadPcb.graphicTexts = graphicTexts;
1935
+ }
1936
+ }
1856
1937
  const pcbBoards = this.ctx.db.pcb_board?.list() || [];
1857
1938
  if (pcbBoards.length > 0) {
1858
1939
  const board = pcbBoards[0];
@@ -1874,7 +1955,7 @@ var AddGraphicsStage = class extends ConverterStage {
1874
1955
  ];
1875
1956
  }
1876
1957
  const transformedCorners = corners.map(
1877
- (corner) => applyToPoint12(c2kMatPcb, corner)
1958
+ (corner) => applyToPoint13(c2kMatPcb, corner)
1878
1959
  );
1879
1960
  for (let i = 0; i < transformedCorners.length; i++) {
1880
1961
  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.21",
4
+ "version": "0.0.22",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"