@modular-circuit/transpiler 0.1.10 → 0.1.13

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.
package/dist/index.mjs CHANGED
@@ -65,7 +65,7 @@ import {
65
65
  import { gen_uuid } from "@modular-circuit/utils";
66
66
 
67
67
  // src/utils/collect_sub_sheets.ts
68
- import { KICAD_SHC_FILE_EXT, parse_module_name, remove_filename_path_prefix, unzipFile } from "@modular-circuit/utils";
68
+ import { KiCadSchematicFileExtension, parse_module_name, remove_filename_path_prefix, unzipFile } from "@modular-circuit/utils";
69
69
  async function collect_sub_sheets(dependencies, module_resolver) {
70
70
  const sheets = {};
71
71
  const module_main_sheet = {};
@@ -93,7 +93,7 @@ async function collect_sub_sheets(dependencies, module_resolver) {
93
93
  const zip_archive = await fetch(zip_archive_url).then((res) => res.arrayBuffer());
94
94
  const files = await unzipFile(zip_archive);
95
95
  for (const [name, content] of Object.entries(files)) {
96
- if (name.endsWith(KICAD_SHC_FILE_EXT)) {
96
+ if (name.endsWith(KiCadSchematicFileExtension)) {
97
97
  const fileName = remove_filename_path_prefix(name);
98
98
  if (fileName in sheets) {
99
99
  console.error(`Duplicate sheet name: ${fileName}`);
@@ -169,9 +169,9 @@ var StringFormatter = class {
169
169
 
170
170
  // src/utils/collect_sub_sheets_by_id.ts
171
171
  import {
172
- KICAD_PCB_FILE_EXT,
173
- KICAD_SHC_FILE_EXT as KICAD_SHC_FILE_EXT2,
174
172
  fmt_module_name,
173
+ KiCadPcbFileExtension,
174
+ KiCadSchematicFileExtension as KiCadSchematicFileExtension2,
175
175
  remove_filename_path_prefix as remove_filename_path_prefix2,
176
176
  unzipFile as unzipFile2
177
177
  } from "@modular-circuit/utils";
@@ -209,7 +209,7 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
209
209
  const zip_archive = await fetch(zip_archive_url).then((res) => res.arrayBuffer());
210
210
  const files = await unzipFile2(zip_archive);
211
211
  for (const [name, content] of Object.entries(files)) {
212
- if (name.endsWith(KICAD_SHC_FILE_EXT2)) {
212
+ if (name.endsWith(KiCadSchematicFileExtension2)) {
213
213
  const filename = remove_filename_path_prefix2(name);
214
214
  if (filename in sheets) {
215
215
  console.error(`Duplicate sheet name: ${filename}`);
@@ -217,7 +217,7 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
217
217
  }
218
218
  sheets[filename] = content;
219
219
  design_block.schematics.push({ filename, content });
220
- } else if (name.endsWith(KICAD_PCB_FILE_EXT)) {
220
+ } else if (name.endsWith(KiCadPcbFileExtension)) {
221
221
  const filename = remove_filename_path_prefix2(name);
222
222
  design_block.pcb = { pcb: { filename, content } };
223
223
  }
@@ -1745,15 +1745,7 @@ import {
1745
1745
  import { replaceAll } from "@modular-circuit/utils";
1746
1746
 
1747
1747
  // src/kicad/label/net_label.ts
1748
- import { gen_uuid as gen_uuid2 } from "@modular-circuit/utils";
1749
-
1750
- // src/kicad/constraints/index.ts
1751
- var DEFAULT_FONT_SIZE = {
1752
- x: 1.27,
1753
- y: 1.27
1754
- };
1755
-
1756
- // src/kicad/label/net_label.ts
1748
+ import { DEFAULT_FONT_SIZE, gen_uuid as gen_uuid2 } from "@modular-circuit/utils";
1757
1749
  var gen_net_label = (name, at, justify) => ({
1758
1750
  label_type: "label",
1759
1751
  text: name,
@@ -1768,11 +1760,11 @@ var gen_net_label = (name, at, justify) => ({
1768
1760
  });
1769
1761
 
1770
1762
  // src/kicad/label/sheet_pin.ts
1771
- import { gen_uuid as gen_uuid3 } from "@modular-circuit/utils";
1763
+ import { DEFAULT_FONT_SIZE as DEFAULT_FONT_SIZE2, gen_uuid as gen_uuid3 } from "@modular-circuit/utils";
1772
1764
  var gen_base_hierarchical_label = (text, at, justify, rotation, shape) => ({
1773
1765
  shape,
1774
1766
  effects: {
1775
- font: { size: DEFAULT_FONT_SIZE },
1767
+ font: { size: DEFAULT_FONT_SIZE2 },
1776
1768
  justify
1777
1769
  },
1778
1770
  text,
@@ -1786,7 +1778,7 @@ var gen_sheet_pin = (text, at, justify, rotation, shape) => ({
1786
1778
  var gen_hierarchical_label = gen_sheet_pin;
1787
1779
 
1788
1780
  // src/kicad/sheet/sheet.ts
1789
- import { gen_uuid as gen_uuid4 } from "@modular-circuit/utils";
1781
+ import { DEFAULT_FONT_SIZE as DEFAULT_FONT_SIZE3, gen_uuid as gen_uuid4 } from "@modular-circuit/utils";
1790
1782
  var TEXT_MARGIN = 0.7116;
1791
1783
  var gen_sch_sheet = (rect, pins, fields) => ({
1792
1784
  // NOTE no rotation in the sheet
@@ -1799,7 +1791,7 @@ var gen_sch_sheet = (rect, pins, fields) => ({
1799
1791
  text: fields.Sheetname,
1800
1792
  at: { position: { x: rect.pos.x, y: rect.pos.y - TEXT_MARGIN }, rotation: 0 },
1801
1793
  effects: {
1802
- font: { size: DEFAULT_FONT_SIZE },
1794
+ font: { size: DEFAULT_FONT_SIZE3 },
1803
1795
  justify: {
1804
1796
  vertical: "bottom",
1805
1797
  horizontal: "left"
@@ -1811,7 +1803,7 @@ var gen_sch_sheet = (rect, pins, fields) => ({
1811
1803
  text: fields.Sheetfile,
1812
1804
  at: { position: { x: rect.pos.x, y: rect.pos.y + rect.size.y + TEXT_MARGIN }, rotation: 0 },
1813
1805
  effects: {
1814
- font: { size: DEFAULT_FONT_SIZE },
1806
+ font: { size: DEFAULT_FONT_SIZE3 },
1815
1807
  justify: {
1816
1808
  vertical: "top",
1817
1809
  horizontal: "left"
@@ -1833,6 +1825,7 @@ var gen_sch_sheet = (rect, pins, fields) => ({
1833
1825
  // src/kicad/symbols/lib_symbol/gnd.ts
1834
1826
  import { ELECTRICAL_PINTYPE, GRAPHIC_PINSHAPE } from "@modular-circuit/electronics-model";
1835
1827
  import { SHAPE_T as SHAPE_T2 } from "@modular-circuit/ir";
1828
+ import { DEFAULT_FONT_SIZE as DEFAULT_FONT_SIZE4 } from "@modular-circuit/utils";
1836
1829
  var gen_lib_gnd = (value) => ({
1837
1830
  name: `power:${value}`,
1838
1831
  pin_numbers: {
@@ -1852,7 +1845,7 @@ var gen_lib_gnd = (value) => ({
1852
1845
  text: "#PWR",
1853
1846
  at: { position: { x: 0, y: -6.35 }, rotation: 0 },
1854
1847
  effects: {
1855
- font: { size: DEFAULT_FONT_SIZE },
1848
+ font: { size: DEFAULT_FONT_SIZE4 },
1856
1849
  hide: true
1857
1850
  }
1858
1851
  },
@@ -1861,7 +1854,7 @@ var gen_lib_gnd = (value) => ({
1861
1854
  text: `${value}`,
1862
1855
  at: { position: { x: 0, y: -3.81 }, rotation: 0 },
1863
1856
  effects: {
1864
- font: { size: DEFAULT_FONT_SIZE }
1857
+ font: { size: DEFAULT_FONT_SIZE4 }
1865
1858
  }
1866
1859
  },
1867
1860
  {
@@ -1869,7 +1862,7 @@ var gen_lib_gnd = (value) => ({
1869
1862
  text: "",
1870
1863
  at: { position: { x: 0, y: 0 }, rotation: 0 },
1871
1864
  effects: {
1872
- font: { size: DEFAULT_FONT_SIZE },
1865
+ font: { size: DEFAULT_FONT_SIZE4 },
1873
1866
  hide: true
1874
1867
  }
1875
1868
  },
@@ -1878,7 +1871,7 @@ var gen_lib_gnd = (value) => ({
1878
1871
  text: "",
1879
1872
  at: { position: { x: 0, y: 0 }, rotation: 0 },
1880
1873
  effects: {
1881
- font: { size: DEFAULT_FONT_SIZE },
1874
+ font: { size: DEFAULT_FONT_SIZE4 },
1882
1875
  hide: true
1883
1876
  }
1884
1877
  },
@@ -1887,7 +1880,7 @@ var gen_lib_gnd = (value) => ({
1887
1880
  text: 'Power symbol creates a global label with name \\"GND\\" , ground',
1888
1881
  at: { position: { x: 0, y: 0 }, rotation: 0 },
1889
1882
  effects: {
1890
- font: { size: DEFAULT_FONT_SIZE },
1883
+ font: { size: DEFAULT_FONT_SIZE4 },
1891
1884
  hide: true
1892
1885
  }
1893
1886
  },
@@ -1896,7 +1889,7 @@ var gen_lib_gnd = (value) => ({
1896
1889
  text: "global power",
1897
1890
  at: { position: { x: 0, y: 0 }, rotation: 0 },
1898
1891
  effects: {
1899
- font: { size: DEFAULT_FONT_SIZE },
1892
+ font: { size: DEFAULT_FONT_SIZE4 },
1900
1893
  hide: true
1901
1894
  }
1902
1895
  }
@@ -1937,13 +1930,13 @@ var gen_lib_gnd = (value) => ({
1937
1930
  name: {
1938
1931
  text: "~",
1939
1932
  effects: {
1940
- font: { size: DEFAULT_FONT_SIZE }
1933
+ font: { size: DEFAULT_FONT_SIZE4 }
1941
1934
  }
1942
1935
  },
1943
1936
  number: {
1944
1937
  text: "1",
1945
1938
  effects: {
1946
- font: { size: DEFAULT_FONT_SIZE }
1939
+ font: { size: DEFAULT_FONT_SIZE4 }
1947
1940
  }
1948
1941
  }
1949
1942
  }
@@ -1955,6 +1948,7 @@ var gen_lib_gnd = (value) => ({
1955
1948
  // src/kicad/symbols/lib_symbol/vcc.ts
1956
1949
  import { ELECTRICAL_PINTYPE as ELECTRICAL_PINTYPE2, GRAPHIC_PINSHAPE as GRAPHIC_PINSHAPE2 } from "@modular-circuit/electronics-model";
1957
1950
  import { SHAPE_T as SHAPE_T3 } from "@modular-circuit/ir";
1951
+ import { DEFAULT_FONT_SIZE as DEFAULT_FONT_SIZE5 } from "@modular-circuit/utils";
1958
1952
  var gen_lib_vcc = (value) => ({
1959
1953
  name: `power:${value}`,
1960
1954
  power: true,
@@ -1975,7 +1969,7 @@ var gen_lib_vcc = (value) => ({
1975
1969
  text: "#PWR",
1976
1970
  at: { position: { x: 0, y: -3.81 }, rotation: 0 },
1977
1971
  effects: {
1978
- font: { size: DEFAULT_FONT_SIZE },
1972
+ font: { size: DEFAULT_FONT_SIZE5 },
1979
1973
  hide: true
1980
1974
  }
1981
1975
  },
@@ -1984,7 +1978,7 @@ var gen_lib_vcc = (value) => ({
1984
1978
  text: `${value}`,
1985
1979
  at: { position: { x: 0, y: 3.556 }, rotation: 0 },
1986
1980
  effects: {
1987
- font: { size: DEFAULT_FONT_SIZE }
1981
+ font: { size: DEFAULT_FONT_SIZE5 }
1988
1982
  }
1989
1983
  },
1990
1984
  {
@@ -1992,7 +1986,7 @@ var gen_lib_vcc = (value) => ({
1992
1986
  text: "",
1993
1987
  at: { position: { x: 0, y: 0 }, rotation: 0 },
1994
1988
  effects: {
1995
- font: { size: DEFAULT_FONT_SIZE },
1989
+ font: { size: DEFAULT_FONT_SIZE5 },
1996
1990
  hide: true
1997
1991
  }
1998
1992
  },
@@ -2001,7 +1995,7 @@ var gen_lib_vcc = (value) => ({
2001
1995
  text: "",
2002
1996
  at: { position: { x: 0, y: 0 }, rotation: 0 },
2003
1997
  effects: {
2004
- font: { size: DEFAULT_FONT_SIZE },
1998
+ font: { size: DEFAULT_FONT_SIZE5 },
2005
1999
  hide: true
2006
2000
  }
2007
2001
  },
@@ -2010,7 +2004,7 @@ var gen_lib_vcc = (value) => ({
2010
2004
  text: `Power symbol creates a global label with name \\"${value}\\"`,
2011
2005
  at: { position: { x: 0, y: 0 }, rotation: 0 },
2012
2006
  effects: {
2013
- font: { size: DEFAULT_FONT_SIZE },
2007
+ font: { size: DEFAULT_FONT_SIZE5 },
2014
2008
  hide: true
2015
2009
  }
2016
2010
  },
@@ -2019,7 +2013,7 @@ var gen_lib_vcc = (value) => ({
2019
2013
  text: "global power",
2020
2014
  at: { position: { x: 0, y: 0 }, rotation: 0 },
2021
2015
  effects: {
2022
- font: { size: DEFAULT_FONT_SIZE },
2016
+ font: { size: DEFAULT_FONT_SIZE5 },
2023
2017
  hide: true
2024
2018
  }
2025
2019
  }
@@ -2057,13 +2051,13 @@ var gen_lib_vcc = (value) => ({
2057
2051
  name: {
2058
2052
  text: "~",
2059
2053
  effects: {
2060
- font: { size: DEFAULT_FONT_SIZE }
2054
+ font: { size: DEFAULT_FONT_SIZE5 }
2061
2055
  }
2062
2056
  },
2063
2057
  number: {
2064
2058
  text: "1",
2065
2059
  effects: {
2066
- font: { size: DEFAULT_FONT_SIZE }
2060
+ font: { size: DEFAULT_FONT_SIZE5 }
2067
2061
  }
2068
2062
  }
2069
2063
  }
@@ -2073,7 +2067,7 @@ var gen_lib_vcc = (value) => ({
2073
2067
  });
2074
2068
 
2075
2069
  // src/kicad/symbols/sch_symbol/gnd.ts
2076
- import { gen_uuid as gen_uuid5 } from "@modular-circuit/utils";
2070
+ import { DEFAULT_FONT_SIZE as DEFAULT_FONT_SIZE6, gen_uuid as gen_uuid5 } from "@modular-circuit/utils";
2077
2071
 
2078
2072
  // src/kicad/symbols/symbol_utils.ts
2079
2073
  var gen_pwr_ref = (pwr_num) => `#PWR${pwr_num}`;
@@ -2095,7 +2089,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
2095
2089
  text: gen_pwr_ref(pwr_number),
2096
2090
  at: { position: { x: position.x, y: position.y + 6.35 }, rotation: 0 },
2097
2091
  effects: {
2098
- font: { size: DEFAULT_FONT_SIZE },
2092
+ font: { size: DEFAULT_FONT_SIZE6 },
2099
2093
  hide: true
2100
2094
  }
2101
2095
  },
@@ -2104,7 +2098,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
2104
2098
  text: `${value}`,
2105
2099
  at: { position: { x: position.x, y: position.y + 5.08 }, rotation: 0 },
2106
2100
  effects: {
2107
- font: { size: DEFAULT_FONT_SIZE }
2101
+ font: { size: DEFAULT_FONT_SIZE6 }
2108
2102
  }
2109
2103
  },
2110
2104
  {
@@ -2112,7 +2106,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
2112
2106
  text: "",
2113
2107
  at: { position, rotation: 0 },
2114
2108
  effects: {
2115
- font: { size: DEFAULT_FONT_SIZE },
2109
+ font: { size: DEFAULT_FONT_SIZE6 },
2116
2110
  hide: true
2117
2111
  }
2118
2112
  },
@@ -2121,7 +2115,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
2121
2115
  text: "",
2122
2116
  at: { position, rotation: 0 },
2123
2117
  effects: {
2124
- font: { size: DEFAULT_FONT_SIZE },
2118
+ font: { size: DEFAULT_FONT_SIZE6 },
2125
2119
  hide: true
2126
2120
  }
2127
2121
  },
@@ -2130,7 +2124,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
2130
2124
  text: `Power symbol creates a global label with name \\"${value}\\" , ground`,
2131
2125
  at: { position, rotation: 0 },
2132
2126
  effects: {
2133
- font: { size: DEFAULT_FONT_SIZE },
2127
+ font: { size: DEFAULT_FONT_SIZE6 },
2134
2128
  hide: true
2135
2129
  }
2136
2130
  }
@@ -2144,7 +2138,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
2144
2138
  });
2145
2139
 
2146
2140
  // src/kicad/symbols/sch_symbol/vcc.ts
2147
- import { gen_uuid as gen_uuid6 } from "@modular-circuit/utils";
2141
+ import { DEFAULT_FONT_SIZE as DEFAULT_FONT_SIZE7, gen_uuid as gen_uuid6 } from "@modular-circuit/utils";
2148
2142
  var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
2149
2143
  lib_id: `power:${value}`,
2150
2144
  at: { position, rotation: 0 },
@@ -2161,7 +2155,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
2161
2155
  text: gen_pwr_ref(pwr_number),
2162
2156
  at: { position: { x: position.x, y: position.y + 3.81 }, rotation: 0 },
2163
2157
  effects: {
2164
- font: { size: DEFAULT_FONT_SIZE },
2158
+ font: { size: DEFAULT_FONT_SIZE7 },
2165
2159
  hide: true
2166
2160
  }
2167
2161
  },
@@ -2170,7 +2164,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
2170
2164
  text: `${value}`,
2171
2165
  at: { position: { x: position.x, y: position.y - 5.08 }, rotation: 0 },
2172
2166
  effects: {
2173
- font: { size: DEFAULT_FONT_SIZE }
2167
+ font: { size: DEFAULT_FONT_SIZE7 }
2174
2168
  }
2175
2169
  },
2176
2170
  {
@@ -2178,7 +2172,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
2178
2172
  text: "",
2179
2173
  at: { position, rotation: 0 },
2180
2174
  effects: {
2181
- font: { size: DEFAULT_FONT_SIZE },
2175
+ font: { size: DEFAULT_FONT_SIZE7 },
2182
2176
  hide: true
2183
2177
  }
2184
2178
  },
@@ -2187,7 +2181,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
2187
2181
  text: "",
2188
2182
  at: { position, rotation: 0 },
2189
2183
  effects: {
2190
- font: { size: DEFAULT_FONT_SIZE },
2184
+ font: { size: DEFAULT_FONT_SIZE7 },
2191
2185
  hide: true
2192
2186
  }
2193
2187
  },
@@ -2196,7 +2190,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
2196
2190
  text: `Power symbol creates a global label with name \\"${value}\\"`,
2197
2191
  at: { position, rotation: 0 },
2198
2192
  effects: {
2199
- font: { size: DEFAULT_FONT_SIZE },
2193
+ font: { size: DEFAULT_FONT_SIZE7 },
2200
2194
  hide: true
2201
2195
  }
2202
2196
  }
@@ -2437,72 +2431,35 @@ var NetListConverter = class {
2437
2431
 
2438
2432
  // src/builder/graph_to_kicad/convert_graph_to_sheets.ts
2439
2433
  import { MODULAR_CIRCUIT_SCH_EXT as MODULAR_CIRCUIT_SCH_EXT2 } from "@modular-circuit/ir";
2440
-
2441
- // src/kicad/project/wildcards_and_files_ext.ts
2442
- var KiCadSymbolLibFileExtension = "kicad_sym";
2443
- var SchematicSymbolFileExtension = "sym";
2444
- var LegacySymbolLibFileExtension = "lib";
2445
- var LegacySymbolDocumentFileExtension = "dcm";
2446
- var VrmlFileExtension = "wrl";
2447
- var ProjectFileExtension = "kicad_pro";
2448
- var LegacyProjectFileExtension = "pro";
2449
- var ProjectLocalSettingsFileExtension = "kicad_prl";
2450
- var LegacySchematicFileExtension = "sch";
2451
- var CadstarSchematicFileExtension = "csa";
2452
- var CadstarPartsLibraryFileExtension = "lib";
2453
- var KiCadSchematicFileExtension = "kicad_sch";
2454
- var SpiceFileExtension = "cir";
2455
- var CadstarNetlistFileExtension = "frp";
2456
- var OrCadPcb2NetlistFileExtension = "net";
2457
- var NetlistFileExtension = "net";
2458
- var AllegroNetlistFileExtension = "txt";
2459
- var FootprintAssignmentFileExtension = "cmp";
2460
- var GerberFileExtension = "gbr";
2461
- var GerberJobFileExtension = "gbrjob";
2462
- var HtmlFileExtension = "html";
2463
- var EquFileExtension = "equ";
2464
- var HotkeyFileExtension = "hotkeys";
2465
- var DatabaseLibraryFileExtension = "kicad_dbl";
2466
- var HTTPLibraryFileExtension = "kicad_httplib";
2467
- var ArchiveFileExtension = "zip";
2468
- var LegacyPcbFileExtension = "brd";
2469
- var EaglePcbFileExtension = "brd";
2470
- var CadstarPcbFileExtension = "cpa";
2471
- var KiCadPcbFileExtension = "kicad_pcb";
2472
- var DrawingSheetFileExtension = "kicad_wks";
2473
- var DesignRulesFileExtension = "kicad_dru";
2474
- var PdfFileExtension = "pdf";
2475
- var MacrosFileExtension = "mcr";
2476
- var DrillFileExtension = "drl";
2477
- var SVGFileExtension = "svg";
2478
- var ReportFileExtension = "rpt";
2479
- var FootprintPlaceFileExtension = "pos";
2480
- var KiCadFootprintLibPathExtension = "pretty";
2481
- var LegacyFootprintLibPathExtension = "mod";
2482
- var AltiumFootprintLibPathExtension = "PcbLib";
2483
- var CadstarFootprintLibPathExtension = "cpa";
2484
- var EagleFootprintLibPathExtension = "lbr";
2485
- var GedaPcbFootprintLibFileExtension = "fp";
2486
- var KiCadFootprintFileExtension = "kicad_mod";
2487
- var SpecctraDsnFileExtension = "dsn";
2488
- var SpecctraSessionFileExtension = "ses";
2489
- var IpcD356FileExtension = "d356";
2490
- var Ipc2581FileExtension = "xml";
2491
- var WorkbookFileExtension = "wbk";
2492
- var PngFileExtension = "png";
2493
- var JpegFileExtension = "jpg";
2494
- var TextFileExtension = "txt";
2495
- var MarkdownFileExtension = "md";
2496
- var CsvFileExtension = "csv";
2497
- var XmlFileExtension = "xml";
2498
- var JsonFileExtension = "json";
2499
- var StepFileExtension = "step";
2500
- var StepFileAbrvExtension = "stp";
2501
- var GltfBinaryFileExtension = "glb";
2502
- var GerberFileExtensionsRegex = /(gbr|gko|pho|(g[tb][alops])|(gm?\\d\\d*)|(gp[tb]))/;
2503
-
2504
- // src/kicad/project/kicad_project_archive.ts
2505
- import { zipFiles } from "@modular-circuit/utils";
2434
+ import { build_connection_graph } from "@modular-circuit/perc";
2435
+ import { KiCadSchematicFileExtension as KiCadSchematicFileExtension3 } from "@modular-circuit/utils";
2436
+ async function do_convert_graph_to_kicad_project(ctx) {
2437
+ const { sheets } = await collect_sub_sheets(ctx.project.dependencies, ctx.module_resolver);
2438
+ const netlist = new GraphConverter({
2439
+ ...ctx
2440
+ }).convert_to_netlist();
2441
+ const converted_sheets = await new NetListConverter({
2442
+ ...ctx,
2443
+ netlist
2444
+ }).convert_to_kicad();
2445
+ const sexpr_printer = new SCHEMATIC_PRINTER();
2446
+ for (const [k, v] of Object.entries(converted_sheets)) {
2447
+ if (k in sheets) {
2448
+ console.error(`Duplicated sheet file name found ${k}`);
2449
+ }
2450
+ sheets[k.replace(MODULAR_CIRCUIT_SCH_EXT2, KiCadSchematicFileExtension3)] = sexpr_printer.schematic(v);
2451
+ }
2452
+ return sheets;
2453
+ }
2454
+ async function convert_graph_to_sheets(ctx) {
2455
+ return do_convert_graph_to_kicad_project({
2456
+ ...ctx,
2457
+ ...await build_connection_graph({
2458
+ ...ctx,
2459
+ dependencies: ctx.project.dependencies
2460
+ })
2461
+ });
2462
+ }
2506
2463
 
2507
2464
  // src/kicad/project/kicad_prl.ts
2508
2465
  var kicad_prl = (prj_name) => ({
@@ -2590,6 +2547,7 @@ var kicad_prl = (prj_name) => ({
2590
2547
  });
2591
2548
 
2592
2549
  // src/kicad/project/kicad_pro.ts
2550
+ import { DrawingSheetFileExtension } from "@modular-circuit/utils";
2593
2551
  var kicad_pro = (project_name) => ({
2594
2552
  board: {
2595
2553
  "3dviewports": [],
@@ -2815,15 +2773,23 @@ var kicad_pro = (project_name) => ({
2815
2773
  });
2816
2774
 
2817
2775
  // src/kicad/project/kicad_project_archive.ts
2776
+ import {
2777
+ DrawingSheetFileExtension as DrawingSheetFileExtension2,
2778
+ KiCadSchematicFileExtension as KiCadSchematicFileExtension4,
2779
+ ProjectFileExtension,
2780
+ ProjectLocalSettingsFileExtension
2781
+ } from "@modular-circuit/utils";
2782
+ import JSZip from "jszip";
2818
2783
  var KICAD_SCH_FRAME = get_sch_default_drawing_sheet();
2819
2784
  var KiCadProjectArchive = class {
2820
- constructor(project_name, sheets) {
2821
- this.project_name = project_name;
2822
- this.sheets = sheets;
2823
- if (!(this.main_sch_name in this.sheets)) {
2824
- throw new Error(
2825
- `Expecting a main schematic file named ${this.main_sch_name} in the sheets : ${Object.keys(this.sheets)}`
2826
- );
2785
+ constructor(designBlock) {
2786
+ this.designBlock = designBlock;
2787
+ if (!this.designBlock.root) {
2788
+ throw new Error("No root sch file found");
2789
+ }
2790
+ this.project_name = this.designBlock.root.split(".")[0];
2791
+ if (!this.project_name) {
2792
+ throw new Error(`Cannot get project name from ${this.designBlock.root}`);
2827
2793
  }
2828
2794
  }
2829
2795
  get sch_frame() {
@@ -2836,68 +2802,87 @@ var KiCadProjectArchive = class {
2836
2802
  return kicad_pro(this.project_name);
2837
2803
  }
2838
2804
  get main_sch_name() {
2839
- return this.get_project_directive_file_name(KiCadSchematicFileExtension);
2805
+ return this.get_project_directive_file_name(KiCadSchematicFileExtension4);
2840
2806
  }
2841
2807
  get_project_directive_file_name(ext) {
2842
2808
  return `${this.project_name}.${ext}`;
2843
2809
  }
2844
- toZip() {
2845
- return zipFiles({
2846
- [this.get_project_directive_file_name(ProjectLocalSettingsFileExtension)]: JSON.stringify(this.kicad_prl),
2847
- [this.get_project_directive_file_name(ProjectFileExtension)]: JSON.stringify(this.kicad_pro),
2848
- [this.get_project_directive_file_name(DrawingSheetFileExtension)]: this.sch_frame,
2849
- ...this.sheets
2850
- });
2851
- }
2852
- };
2853
-
2854
- // src/builder/graph_to_kicad/convert_graph_to_sheets.ts
2855
- import { build_connection_graph } from "@modular-circuit/perc";
2856
- async function do_convert_graph_to_kicad_project(ctx) {
2857
- const { sheets } = await collect_sub_sheets(ctx.project.dependencies, ctx.module_resolver);
2858
- const netlist = new GraphConverter({
2859
- ...ctx
2860
- }).convert_to_netlist();
2861
- const converted_sheets = await new NetListConverter({
2862
- ...ctx,
2863
- netlist
2864
- }).convert_to_kicad();
2865
- const sexpr_printer = new SCHEMATIC_PRINTER();
2866
- for (const [k, v] of Object.entries(converted_sheets)) {
2867
- if (k in sheets) {
2868
- console.error(`Duplicated sheet file name found ${k}`);
2810
+ async toZip() {
2811
+ const zip = new JSZip();
2812
+ zip.file(
2813
+ this.get_project_directive_file_name(ProjectLocalSettingsFileExtension),
2814
+ JSON.stringify(this.kicad_prl)
2815
+ );
2816
+ zip.file(
2817
+ this.get_project_directive_file_name(ProjectFileExtension),
2818
+ JSON.stringify(this.kicad_pro)
2819
+ );
2820
+ zip.file(
2821
+ this.get_project_directive_file_name(DrawingSheetFileExtension2),
2822
+ this.sch_frame
2823
+ );
2824
+ for (const schematic of this.designBlock.schematics) {
2825
+ zip.file(schematic.filename, schematic.content);
2826
+ }
2827
+ const fpLibTableContent = `(fp_lib_table
2828
+ (version 7)
2829
+ (lib (name "kicad_api_lib")(type "KiCad")(uri "\${KIPRJMOD}/kicad_api_libs/kicad_api_lib.pretty")(options "Added by KiCad IPC API")(descr ""))
2830
+ )`;
2831
+ zip.file("fp-lib-table", fpLibTableContent);
2832
+ let symLibTableContent = "(sym_lib_table\n (version 7)\n";
2833
+ const existing_components = /* @__PURE__ */ new Set();
2834
+ if (this.designBlock.components) {
2835
+ for (const component of this.designBlock.components) {
2836
+ const symFilename = component.symbol.filename;
2837
+ const componentName = symFilename.replace(".kicad_sym", "");
2838
+ if (existing_components.has(componentName)) {
2839
+ continue;
2840
+ }
2841
+ existing_components.add(componentName);
2842
+ symLibTableContent += ` (lib (name "${componentName}")(type "KiCad")(uri "\${KIPRJMOD}/kicad_api_libs/${symFilename}")(options "Added by KiCad IPC API")(descr ""))
2843
+ `;
2844
+ zip.file(`kicad_api_libs/${symFilename}`, component.symbol.content);
2845
+ if (component.footprints) {
2846
+ for (const fp of component.footprints) {
2847
+ const fpFilename = fp.footprint.filename;
2848
+ zip.file(
2849
+ `kicad_api_libs/kicad_api_lib.pretty/${fpFilename}`,
2850
+ fp.footprint.content
2851
+ );
2852
+ if (fp.models) {
2853
+ for (const model of fp.models) {
2854
+ zip.file(
2855
+ `kicad_api_libs/3d_models/${model.filename}`,
2856
+ model.content
2857
+ );
2858
+ }
2859
+ }
2860
+ }
2861
+ }
2862
+ }
2869
2863
  }
2870
- sheets[k.replace(MODULAR_CIRCUIT_SCH_EXT2, KiCadSchematicFileExtension)] = sexpr_printer.schematic(v);
2864
+ symLibTableContent += ")";
2865
+ zip.file("sym-lib-table", symLibTableContent);
2866
+ if (this.designBlock.pcb?.pcb) {
2867
+ if (this.designBlock.pcb.pcb.content) {
2868
+ zip.file(this.designBlock.pcb.pcb.filename, this.designBlock.pcb.pcb.content);
2869
+ }
2870
+ }
2871
+ const blob = await zip.generateAsync({ type: "blob" });
2872
+ return blob;
2871
2873
  }
2872
- return sheets;
2873
- }
2874
- async function convert_graph_to_sheets(ctx) {
2875
- return do_convert_graph_to_kicad_project({
2876
- ...ctx,
2877
- ...await build_connection_graph({
2878
- ...ctx,
2879
- dependencies: ctx.project.dependencies
2880
- })
2881
- });
2882
- }
2883
-
2884
- // src/builder/graph_to_kicad/convert_graph_to_kicad_project.ts
2885
- async function convert_graph_to_kicad_project(ctx) {
2886
- const sheets = await convert_graph_to_sheets(ctx);
2887
- const kicad_project = new KiCadProjectArchive(ctx.project.name, {
2888
- ...sheets
2889
- });
2890
- return kicad_project.toZip();
2891
- }
2874
+ };
2892
2875
 
2893
2876
  // src/builder/graph_to_kicad/convert_graph_to_design_block.ts
2877
+ import { KiCadSchematicFileExtension as KiCadSchematicFileExtension5, ModularCircuitFileExtension } from "@modular-circuit/utils";
2894
2878
  async function convert_graph_to_design_block(ctx) {
2879
+ const root = ctx.project.main.replace(ModularCircuitFileExtension, KiCadSchematicFileExtension5);
2895
2880
  const sheets = await convert_graph_to_sheets(ctx);
2896
- const kicad_project = new KiCadProjectArchive(ctx.project.name, {
2897
- ...sheets
2898
- });
2881
+ if (!(root in sheets)) {
2882
+ throw new Error(`Cannot find root sch file ${root}`);
2883
+ }
2899
2884
  const design_block = {
2900
- root: kicad_project.main_sch_name,
2885
+ root,
2901
2886
  pcb: null,
2902
2887
  components: [],
2903
2888
  schematics: Object.entries(sheets).map(([filename, content]) => {
@@ -2909,86 +2894,32 @@ async function convert_graph_to_design_block(ctx) {
2909
2894
  };
2910
2895
  return design_block;
2911
2896
  }
2897
+
2898
+ // src/builder/graph_to_kicad/convert_graph_to_kicad_project.ts
2899
+ async function convert_graph_to_kicad_project(ctx) {
2900
+ const design_block = await convert_graph_to_design_block(ctx);
2901
+ const kicad_project = new KiCadProjectArchive(design_block);
2902
+ return kicad_project.toZip();
2903
+ }
2912
2904
  export {
2913
- AllegroNetlistFileExtension,
2914
- AltiumFootprintLibPathExtension,
2915
- ArchiveFileExtension,
2916
2905
  BLOCK_PIN_GAP,
2917
2906
  BLOCK_PIN_TB_MARGIN,
2918
- CadstarFootprintLibPathExtension,
2919
- CadstarNetlistFileExtension,
2920
- CadstarPartsLibraryFileExtension,
2921
- CadstarPcbFileExtension,
2922
- CadstarSchematicFileExtension,
2923
- CsvFileExtension,
2924
2907
  DEFAULT_PAPER_SIZE,
2925
- DatabaseLibraryFileExtension,
2926
- DesignRulesFileExtension,
2927
- DrawingSheetFileExtension,
2928
- DrillFileExtension,
2929
- EagleFootprintLibPathExtension,
2930
- EaglePcbFileExtension,
2931
- EquFileExtension,
2932
2908
  FONT_SIZE,
2933
- FootprintAssignmentFileExtension,
2934
- FootprintPlaceFileExtension,
2935
2909
  GENERATOR_NAME,
2936
2910
  GENERATOR_VERSION,
2937
2911
  GRID_SIZE,
2938
- GedaPcbFootprintLibFileExtension,
2939
- GerberFileExtension,
2940
- GerberFileExtensionsRegex,
2941
- GerberJobFileExtension,
2942
- GltfBinaryFileExtension,
2943
2912
  GraphConverter,
2944
- HTTPLibraryFileExtension,
2945
- HotkeyFileExtension,
2946
- HtmlFileExtension,
2947
- Ipc2581FileExtension,
2948
- IpcD356FileExtension,
2949
- JpegFileExtension,
2950
- JsonFileExtension,
2951
2913
  KICAD_SCH_FRAME,
2952
- KiCadFootprintFileExtension,
2953
- KiCadFootprintLibPathExtension,
2954
- KiCadPcbFileExtension,
2955
2914
  KiCadProjectArchive,
2956
- KiCadSchematicFileExtension,
2957
- KiCadSymbolLibFileExtension,
2958
2915
  Layout,
2959
- LegacyFootprintLibPathExtension,
2960
- LegacyPcbFileExtension,
2961
- LegacyProjectFileExtension,
2962
- LegacySchematicFileExtension,
2963
- LegacySymbolDocumentFileExtension,
2964
- LegacySymbolLibFileExtension,
2965
- MacrosFileExtension,
2966
- MarkdownFileExtension,
2967
2916
  NetListConverter,
2968
- NetlistFileExtension,
2969
- OrCadPcb2NetlistFileExtension,
2970
2917
  PAPER,
2971
2918
  PAPER_SIZE,
2972
- PdfFileExtension,
2973
- PngFileExtension,
2974
- ProjectFileExtension,
2975
- ProjectLocalSettingsFileExtension,
2976
- ReportFileExtension,
2977
2919
  SCHEMATIC_PRINTER,
2978
2920
  SCH_VERSION,
2979
- SVGFileExtension,
2980
- SchematicSymbolFileExtension,
2981
- SpecctraDsnFileExtension,
2982
- SpecctraSessionFileExtension,
2983
- SpiceFileExtension,
2984
- StepFileAbrvExtension,
2985
- StepFileExtension,
2986
2921
  StringFormatter,
2987
- TextFileExtension,
2988
- VrmlFileExtension,
2989
2922
  WIRE_PADDING,
2990
- WorkbookFileExtension,
2991
- XmlFileExtension,
2992
2923
  collect_sub_sheets,
2993
2924
  collect_sub_sheets_by_id,
2994
2925
  convert_graph_to_design_block,