@modular-circuit/transpiler 0.2.11 → 0.3.0
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.d.mts +6 -10
- package/dist/index.d.ts +6 -10
- package/dist/index.js +91 -141
- package/dist/index.mjs +30 -77
- package/package.json +6 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VECTOR2, At, Color, ConnectionGraph, NL_NetList, BOX2 } from '@modular-circuit/electronics-model';
|
|
2
2
|
import { SCHEMATIC, PIN_DISPLAY_OPT, LIB_SYMBOL, Drawing, PIN_DEFINITION, SCH_LABEL, SCH_SYMBOL, SCH_LINE, PIN_INSTANCE, SCH_SHEET, SCH_SHEET_PIN, Effects, Justify, SCH_FIELD, Fill, Stroke, Project, IR_Graph, DesignBlockContent, ModuleResolver, ModuleCircuit } from '@modular-circuit/ir';
|
|
3
3
|
import { CG_SCHEMATIC, CONNECTION_GRAPH_BUILDER_CTX } from '@modular-circuit/perc';
|
|
4
|
+
import { NetlistTranspiler } from '@modular-circuit/genai';
|
|
4
5
|
|
|
5
6
|
declare function get_sch_default_drawing_sheet(): string;
|
|
6
7
|
|
|
@@ -43,6 +44,10 @@ declare class SCHEMATIC_PRINTER {
|
|
|
43
44
|
interface ConvertGraphToKiCadInput extends Omit<CONNECTION_GRAPH_BUILDER_CTX, 'dependencies'> {
|
|
44
45
|
project: Project;
|
|
45
46
|
schematics: Record<string, IR_Graph>;
|
|
47
|
+
/**
|
|
48
|
+
* If provided and there is ResolvedAbstractBlock in the schematics, the netlist in ResolvedAbstractBlock will be converted to kicad_sch
|
|
49
|
+
*/
|
|
50
|
+
netlist_transpiler?: NetlistTranspiler;
|
|
46
51
|
}
|
|
47
52
|
interface ConnectionGraphMap {
|
|
48
53
|
connection_graph: ConnectionGraph;
|
|
@@ -372,12 +377,6 @@ declare class KiCadProjectArchive {
|
|
|
372
377
|
toZip(): Promise<Blob>;
|
|
373
378
|
}
|
|
374
379
|
|
|
375
|
-
declare function collect_sub_sheets(dependencies: Record<string, string>, module_resolver: ModuleResolver): Promise<{
|
|
376
|
-
sheets: Record<string, string>;
|
|
377
|
-
module_main_sheet: Record<string, string>;
|
|
378
|
-
modules: Record<string, ModuleCircuit>;
|
|
379
|
-
}>;
|
|
380
|
-
|
|
381
380
|
declare function filterNullOrUndefined(originalMethod: unknown, _context: ClassMethodDecoratorContext): (this: unknown, ...args: unknown[]) => any;
|
|
382
381
|
|
|
383
382
|
declare const tab = "\t";
|
|
@@ -401,9 +400,6 @@ declare function collect_sub_sheets_by_id(module_ids: string[], module_resolver:
|
|
|
401
400
|
design_blocks: DesignBlockContent[];
|
|
402
401
|
}>;
|
|
403
402
|
|
|
404
|
-
declare const fmt_to_valid_filename: (name: string) => string;
|
|
405
|
-
declare const fmt_module_place_holder_sch_name: (mod_name: string) => string;
|
|
406
|
-
|
|
407
403
|
declare const gen_empty_sch: (name: string) => Promise<string>;
|
|
408
404
|
|
|
409
405
|
declare const gen_lib_gnd: (value: string) => LIB_SYMBOL;
|
|
@@ -414,4 +410,4 @@ declare const gen_sch_gnd: (value: string, pwr_number: number, port_id: string,
|
|
|
414
410
|
|
|
415
411
|
declare const gen_sch_vcc: (value: string, pwr_number: number, port_id: string, position: VECTOR2) => SCH_SYMBOL;
|
|
416
412
|
|
|
417
|
-
export { BLOCK_PIN_GAP, BLOCK_PIN_TB_MARGIN, type BlockLabelPadding, type BlockSize, type BoxGeometry, type ConnectionGraphMap, type ConvertGraphToKiCadContext, type ConvertGraphToKiCadInput, FONT_SIZE, GRID_SIZE, GraphConverter, KICAD_SCH_FRAME, KiCadProjectArchive, type LabelPadding, Layout, NetListConverter, type NetlistProject, type NetlistToKicadContext, SCHEMATIC_PRINTER, StringFormatter, WIRE_PADDING,
|
|
413
|
+
export { BLOCK_PIN_GAP, BLOCK_PIN_TB_MARGIN, type BlockLabelPadding, type BlockSize, type BoxGeometry, type ConnectionGraphMap, type ConvertGraphToKiCadContext, type ConvertGraphToKiCadInput, FONT_SIZE, GRID_SIZE, GraphConverter, KICAD_SCH_FRAME, KiCadProjectArchive, type LabelPadding, Layout, NetListConverter, type NetlistProject, type NetlistToKicadContext, SCHEMATIC_PRINTER, StringFormatter, WIRE_PADDING, collect_sub_sheets_by_id, convert_graph_to_design_block, convert_graph_to_kicad_project, convert_graph_to_sheets, filterNullOrUndefined, gen_empty_sch, gen_lib_gnd, gen_lib_vcc, gen_sch_gnd, gen_sch_vcc, get_power_pos, get_sch_default_drawing_sheet, tab };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { VECTOR2, At, Color, ConnectionGraph, NL_NetList, BOX2 } from '@modular-circuit/electronics-model';
|
|
2
2
|
import { SCHEMATIC, PIN_DISPLAY_OPT, LIB_SYMBOL, Drawing, PIN_DEFINITION, SCH_LABEL, SCH_SYMBOL, SCH_LINE, PIN_INSTANCE, SCH_SHEET, SCH_SHEET_PIN, Effects, Justify, SCH_FIELD, Fill, Stroke, Project, IR_Graph, DesignBlockContent, ModuleResolver, ModuleCircuit } from '@modular-circuit/ir';
|
|
3
3
|
import { CG_SCHEMATIC, CONNECTION_GRAPH_BUILDER_CTX } from '@modular-circuit/perc';
|
|
4
|
+
import { NetlistTranspiler } from '@modular-circuit/genai';
|
|
4
5
|
|
|
5
6
|
declare function get_sch_default_drawing_sheet(): string;
|
|
6
7
|
|
|
@@ -43,6 +44,10 @@ declare class SCHEMATIC_PRINTER {
|
|
|
43
44
|
interface ConvertGraphToKiCadInput extends Omit<CONNECTION_GRAPH_BUILDER_CTX, 'dependencies'> {
|
|
44
45
|
project: Project;
|
|
45
46
|
schematics: Record<string, IR_Graph>;
|
|
47
|
+
/**
|
|
48
|
+
* If provided and there is ResolvedAbstractBlock in the schematics, the netlist in ResolvedAbstractBlock will be converted to kicad_sch
|
|
49
|
+
*/
|
|
50
|
+
netlist_transpiler?: NetlistTranspiler;
|
|
46
51
|
}
|
|
47
52
|
interface ConnectionGraphMap {
|
|
48
53
|
connection_graph: ConnectionGraph;
|
|
@@ -372,12 +377,6 @@ declare class KiCadProjectArchive {
|
|
|
372
377
|
toZip(): Promise<Blob>;
|
|
373
378
|
}
|
|
374
379
|
|
|
375
|
-
declare function collect_sub_sheets(dependencies: Record<string, string>, module_resolver: ModuleResolver): Promise<{
|
|
376
|
-
sheets: Record<string, string>;
|
|
377
|
-
module_main_sheet: Record<string, string>;
|
|
378
|
-
modules: Record<string, ModuleCircuit>;
|
|
379
|
-
}>;
|
|
380
|
-
|
|
381
380
|
declare function filterNullOrUndefined(originalMethod: unknown, _context: ClassMethodDecoratorContext): (this: unknown, ...args: unknown[]) => any;
|
|
382
381
|
|
|
383
382
|
declare const tab = "\t";
|
|
@@ -401,9 +400,6 @@ declare function collect_sub_sheets_by_id(module_ids: string[], module_resolver:
|
|
|
401
400
|
design_blocks: DesignBlockContent[];
|
|
402
401
|
}>;
|
|
403
402
|
|
|
404
|
-
declare const fmt_to_valid_filename: (name: string) => string;
|
|
405
|
-
declare const fmt_module_place_holder_sch_name: (mod_name: string) => string;
|
|
406
|
-
|
|
407
403
|
declare const gen_empty_sch: (name: string) => Promise<string>;
|
|
408
404
|
|
|
409
405
|
declare const gen_lib_gnd: (value: string) => LIB_SYMBOL;
|
|
@@ -414,4 +410,4 @@ declare const gen_sch_gnd: (value: string, pwr_number: number, port_id: string,
|
|
|
414
410
|
|
|
415
411
|
declare const gen_sch_vcc: (value: string, pwr_number: number, port_id: string, position: VECTOR2) => SCH_SYMBOL;
|
|
416
412
|
|
|
417
|
-
export { BLOCK_PIN_GAP, BLOCK_PIN_TB_MARGIN, type BlockLabelPadding, type BlockSize, type BoxGeometry, type ConnectionGraphMap, type ConvertGraphToKiCadContext, type ConvertGraphToKiCadInput, FONT_SIZE, GRID_SIZE, GraphConverter, KICAD_SCH_FRAME, KiCadProjectArchive, type LabelPadding, Layout, NetListConverter, type NetlistProject, type NetlistToKicadContext, SCHEMATIC_PRINTER, StringFormatter, WIRE_PADDING,
|
|
413
|
+
export { BLOCK_PIN_GAP, BLOCK_PIN_TB_MARGIN, type BlockLabelPadding, type BlockSize, type BoxGeometry, type ConnectionGraphMap, type ConvertGraphToKiCadContext, type ConvertGraphToKiCadInput, FONT_SIZE, GRID_SIZE, GraphConverter, KICAD_SCH_FRAME, KiCadProjectArchive, type LabelPadding, Layout, NetListConverter, type NetlistProject, type NetlistToKicadContext, SCHEMATIC_PRINTER, StringFormatter, WIRE_PADDING, collect_sub_sheets_by_id, convert_graph_to_design_block, convert_graph_to_kicad_project, convert_graph_to_sheets, filterNullOrUndefined, gen_empty_sch, gen_lib_gnd, gen_lib_vcc, gen_sch_gnd, gen_sch_vcc, get_power_pos, get_sch_default_drawing_sheet, tab };
|
package/dist/index.js
CHANGED
|
@@ -86,14 +86,11 @@ __export(index_exports, {
|
|
|
86
86
|
SCHEMATIC_PRINTER: () => SCHEMATIC_PRINTER,
|
|
87
87
|
StringFormatter: () => StringFormatter,
|
|
88
88
|
WIRE_PADDING: () => WIRE_PADDING,
|
|
89
|
-
collect_sub_sheets: () => collect_sub_sheets,
|
|
90
89
|
collect_sub_sheets_by_id: () => collect_sub_sheets_by_id,
|
|
91
90
|
convert_graph_to_design_block: () => convert_graph_to_design_block,
|
|
92
91
|
convert_graph_to_kicad_project: () => convert_graph_to_kicad_project,
|
|
93
92
|
convert_graph_to_sheets: () => convert_graph_to_sheets,
|
|
94
93
|
filterNullOrUndefined: () => filterNullOrUndefined,
|
|
95
|
-
fmt_module_place_holder_sch_name: () => fmt_module_place_holder_sch_name,
|
|
96
|
-
fmt_to_valid_filename: () => fmt_to_valid_filename,
|
|
97
94
|
gen_empty_sch: () => gen_empty_sch,
|
|
98
95
|
gen_lib_gnd: () => gen_lib_gnd,
|
|
99
96
|
gen_lib_vcc: () => gen_lib_vcc,
|
|
@@ -119,52 +116,7 @@ function get_sch_default_drawing_sheet() {
|
|
|
119
116
|
// src/converter/kicad_sexpr/eeschema/printer.ts
|
|
120
117
|
var import_electronics_model = require("@modular-circuit/electronics-model");
|
|
121
118
|
var import_ir = require("@modular-circuit/ir");
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
// src/utils/collect_sub_sheets.ts
|
|
125
|
-
var import_utils = require("@modular-circuit/utils");
|
|
126
|
-
async function collect_sub_sheets(dependencies, module_resolver) {
|
|
127
|
-
const sheets = {};
|
|
128
|
-
const module_main_sheet = {};
|
|
129
|
-
const modules = {};
|
|
130
|
-
for (const [k, v] of Object.entries(dependencies)) {
|
|
131
|
-
try {
|
|
132
|
-
const zip_archive_url = await module_resolver.get_module_archive({
|
|
133
|
-
...(0, import_utils.parse_module_name)(k),
|
|
134
|
-
version: v
|
|
135
|
-
});
|
|
136
|
-
const module2 = await module_resolver.get_module_circuit({
|
|
137
|
-
...(0, import_utils.parse_module_name)(k),
|
|
138
|
-
version: v
|
|
139
|
-
});
|
|
140
|
-
if (!zip_archive_url || !module2) {
|
|
141
|
-
console.error(`Module ${k}/${v} not found`);
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
if (!module2.main) {
|
|
145
|
-
console.error(`Missing main entry in module ${k}/${v}`);
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
module_main_sheet[k] = module2.main;
|
|
149
|
-
modules[k] = module2;
|
|
150
|
-
const zip_archive = await fetch(zip_archive_url).then((res) => res.arrayBuffer());
|
|
151
|
-
const files = await (0, import_utils.unzipFile)(zip_archive);
|
|
152
|
-
for (const [name, content] of Object.entries(files)) {
|
|
153
|
-
if (name.endsWith(import_utils.KiCadSchematicFileExtension)) {
|
|
154
|
-
const fileName = (0, import_utils.remove_filename_path_prefix)(name);
|
|
155
|
-
if (fileName in sheets) {
|
|
156
|
-
console.error(`Duplicate sheet name: ${fileName}`);
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
sheets[fileName] = content;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} catch (e) {
|
|
163
|
-
console.error(`Failed to download zip for module : ${e}`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return { sheets, module_main_sheet, modules };
|
|
167
|
-
}
|
|
119
|
+
var import_utils3 = require("@modular-circuit/utils");
|
|
168
120
|
|
|
169
121
|
// src/utils/filter_null_undefined.ts
|
|
170
122
|
function filterNullOrUndefined(originalMethod, _context) {
|
|
@@ -207,7 +159,7 @@ var StringFormatter = class {
|
|
|
207
159
|
};
|
|
208
160
|
|
|
209
161
|
// src/utils/collect_sub_sheets_by_id.ts
|
|
210
|
-
var
|
|
162
|
+
var import_utils = require("@modular-circuit/utils");
|
|
211
163
|
async function collect_sub_sheets_by_id(module_ids, module_resolver) {
|
|
212
164
|
const sheets = {};
|
|
213
165
|
const module_main_sheet = {};
|
|
@@ -229,7 +181,7 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
|
|
|
229
181
|
console.error(`Missing main entry in module${module_circuit.author}/${module_circuit.name}`);
|
|
230
182
|
continue;
|
|
231
183
|
}
|
|
232
|
-
const k = (0,
|
|
184
|
+
const k = (0, import_utils.fmt_module_name)(module_circuit);
|
|
233
185
|
module_main_sheet[k] = module_circuit.main;
|
|
234
186
|
modules[k] = module_circuit;
|
|
235
187
|
const design_block = {
|
|
@@ -240,18 +192,18 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
|
|
|
240
192
|
};
|
|
241
193
|
console.log(`Fetching ZIP archive for module ${id} from ${zip_archive_url.toString()}`);
|
|
242
194
|
const zip_archive = await fetch(zip_archive_url).then((res) => res.arrayBuffer());
|
|
243
|
-
const files = await (0,
|
|
195
|
+
const files = await (0, import_utils.unzipFile)(zip_archive);
|
|
244
196
|
for (const [name, content] of Object.entries(files)) {
|
|
245
|
-
if (name.endsWith(
|
|
246
|
-
const filename = (0,
|
|
197
|
+
if (name.endsWith(import_utils.KiCadSchematicFileExtension)) {
|
|
198
|
+
const filename = (0, import_utils.remove_filename_path_prefix)(name);
|
|
247
199
|
if (filename in sheets) {
|
|
248
200
|
console.error(`Duplicate sheet name: ${filename}`);
|
|
249
201
|
continue;
|
|
250
202
|
}
|
|
251
203
|
sheets[filename] = content;
|
|
252
204
|
design_block.schematics.push({ filename, content });
|
|
253
|
-
} else if (name.endsWith(
|
|
254
|
-
const filename = (0,
|
|
205
|
+
} else if (name.endsWith(import_utils.KiCadPcbFileExtension)) {
|
|
206
|
+
const filename = (0, import_utils.remove_filename_path_prefix)(name);
|
|
255
207
|
design_block.pcb = { pcb: { filename, content } };
|
|
256
208
|
}
|
|
257
209
|
}
|
|
@@ -263,20 +215,14 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
|
|
|
263
215
|
return { sheets, module_main_sheet, modules, design_blocks };
|
|
264
216
|
}
|
|
265
217
|
|
|
266
|
-
// src/utils/fmt_to_valid_filename.ts
|
|
267
|
-
var fmt_to_valid_filename = (name) => {
|
|
268
|
-
return name.replace(/[\\/:*?"<>|]/g, "_").trim();
|
|
269
|
-
};
|
|
270
|
-
var fmt_module_place_holder_sch_name = (mod_name) => `placeholder_${fmt_to_valid_filename(mod_name)}.kicad_sch`;
|
|
271
|
-
|
|
272
218
|
// src/utils/gen_empty_sch.ts
|
|
273
|
-
var
|
|
219
|
+
var import_utils2 = require("@modular-circuit/utils");
|
|
274
220
|
var gen_empty_sch = async (name) => {
|
|
275
221
|
const printer = new SCHEMATIC_PRINTER();
|
|
276
222
|
const schematics = {};
|
|
277
223
|
const filename = `${name}`;
|
|
278
224
|
schematics[filename] = {
|
|
279
|
-
uuid: (0,
|
|
225
|
+
uuid: (0, import_utils2.gen_uuid)(),
|
|
280
226
|
filename,
|
|
281
227
|
sheet_symbols: [],
|
|
282
228
|
powers: [],
|
|
@@ -329,11 +275,11 @@ var SCHEMATIC_PRINTER = class {
|
|
|
329
275
|
})();
|
|
330
276
|
return `
|
|
331
277
|
(kicad_sch
|
|
332
|
-
(version ${
|
|
333
|
-
(generator "${
|
|
334
|
-
(generator_version "${
|
|
335
|
-
(uuid "${(0,
|
|
336
|
-
(paper "${
|
|
278
|
+
(version ${import_utils3.SCH_VERSION})
|
|
279
|
+
(generator "${import_utils3.GENERATOR_NAME}")
|
|
280
|
+
(generator_version "${import_utils3.GENERATOR_VERSION}")
|
|
281
|
+
(uuid "${(0, import_utils3.gen_uuid)()}")
|
|
282
|
+
(paper "${import_utils3.PAPER}")
|
|
337
283
|
${lib_symbols}
|
|
338
284
|
${wires}
|
|
339
285
|
${labels}
|
|
@@ -1811,13 +1757,13 @@ var GraphConverter = class {
|
|
|
1811
1757
|
};
|
|
1812
1758
|
|
|
1813
1759
|
// src/converter/netlist_to_kicad/layout.ts
|
|
1814
|
-
var
|
|
1760
|
+
var import_utils5 = require("@modular-circuit/utils");
|
|
1815
1761
|
var import_elk_bundled = __toESM(require("elkjs/lib/elk.bundled.js"));
|
|
1816
1762
|
var MIL_TO_MM = 0.0254;
|
|
1817
1763
|
var GRID_SIZE = 50 * MIL_TO_MM;
|
|
1818
1764
|
var FONT_SIZE = GRID_SIZE;
|
|
1819
1765
|
var POWER_START_Y = 30 * GRID_SIZE;
|
|
1820
|
-
var POWER_START_X = (
|
|
1766
|
+
var POWER_START_X = (import_utils5.PAPER_SIZE.A4.height - 30) * GRID_SIZE;
|
|
1821
1767
|
var POWER_Y_STEP = 16 * GRID_SIZE;
|
|
1822
1768
|
var BLOCK_V_SPACE = 8 * GRID_SIZE;
|
|
1823
1769
|
var BLOCK_H_SPACE = 14 * GRID_SIZE - BLOCK_V_SPACE;
|
|
@@ -1855,8 +1801,8 @@ var Layout = class {
|
|
|
1855
1801
|
"org.eclipse.elk.aspectRatio": "1.414",
|
|
1856
1802
|
"elk.spacing.nodeNode": `${BLOCK_V_SPACE}`,
|
|
1857
1803
|
"elk.padding": `[top=${PADDING_TOP},left=${PADDING},bottom=${PADDING},right=${PADDING}]`,
|
|
1858
|
-
"elk.childAreaWidth": `${
|
|
1859
|
-
"elk.childAreaHeight": `${
|
|
1804
|
+
"elk.childAreaWidth": `${import_utils5.PAPER_SIZE.A4.height}`,
|
|
1805
|
+
"elk.childAreaHeight": `${import_utils5.PAPER_SIZE.A4.width}`
|
|
1860
1806
|
},
|
|
1861
1807
|
children: [],
|
|
1862
1808
|
edges: []
|
|
@@ -1915,10 +1861,10 @@ var Layout = class {
|
|
|
1915
1861
|
// src/converter/netlist_to_kicad/netlist_converter.ts
|
|
1916
1862
|
var import_electronics_model8 = require("@modular-circuit/electronics-model");
|
|
1917
1863
|
var import_ir4 = require("@modular-circuit/ir");
|
|
1918
|
-
var
|
|
1864
|
+
var import_utils14 = require("@modular-circuit/utils");
|
|
1919
1865
|
|
|
1920
1866
|
// src/kicad/label/net_label.ts
|
|
1921
|
-
var
|
|
1867
|
+
var import_utils6 = require("@modular-circuit/utils");
|
|
1922
1868
|
var gen_net_label = (name, at, justify) => ({
|
|
1923
1869
|
label_type: "label",
|
|
1924
1870
|
text: name,
|
|
@@ -1926,23 +1872,23 @@ var gen_net_label = (name, at, justify) => ({
|
|
|
1926
1872
|
fields_autoplaced: true,
|
|
1927
1873
|
at: { position: at, rotation: 0 },
|
|
1928
1874
|
effects: {
|
|
1929
|
-
font: { size:
|
|
1875
|
+
font: { size: import_utils6.DEFAULT_FONT_SIZE },
|
|
1930
1876
|
justify
|
|
1931
1877
|
},
|
|
1932
|
-
uuid: (0,
|
|
1878
|
+
uuid: (0, import_utils6.gen_uuid)()
|
|
1933
1879
|
});
|
|
1934
1880
|
|
|
1935
1881
|
// src/kicad/label/sheet_pin.ts
|
|
1936
|
-
var
|
|
1882
|
+
var import_utils7 = require("@modular-circuit/utils");
|
|
1937
1883
|
var gen_base_hierarchical_label = (text, at, justify, rotation, shape) => ({
|
|
1938
1884
|
shape,
|
|
1939
1885
|
effects: {
|
|
1940
|
-
font: { size:
|
|
1886
|
+
font: { size: import_utils7.DEFAULT_FONT_SIZE },
|
|
1941
1887
|
justify
|
|
1942
1888
|
},
|
|
1943
1889
|
text,
|
|
1944
1890
|
at: { position: at, rotation },
|
|
1945
|
-
uuid: (0,
|
|
1891
|
+
uuid: (0, import_utils7.gen_uuid)()
|
|
1946
1892
|
});
|
|
1947
1893
|
var gen_sheet_pin = (text, at, justify, rotation, shape) => ({
|
|
1948
1894
|
label_type: "hierarchical_label",
|
|
@@ -1951,7 +1897,7 @@ var gen_sheet_pin = (text, at, justify, rotation, shape) => ({
|
|
|
1951
1897
|
var gen_hierarchical_label = gen_sheet_pin;
|
|
1952
1898
|
|
|
1953
1899
|
// src/kicad/sheet/sheet.ts
|
|
1954
|
-
var
|
|
1900
|
+
var import_utils8 = require("@modular-circuit/utils");
|
|
1955
1901
|
var TEXT_MARGIN = 0.7116;
|
|
1956
1902
|
var gen_sch_sheet = (rect, pins, fields) => ({
|
|
1957
1903
|
// NOTE no rotation in the sheet
|
|
@@ -1964,7 +1910,7 @@ var gen_sch_sheet = (rect, pins, fields) => ({
|
|
|
1964
1910
|
text: fields.Sheetname,
|
|
1965
1911
|
at: { position: { x: rect.pos.x, y: rect.pos.y - TEXT_MARGIN }, rotation: 0 },
|
|
1966
1912
|
effects: {
|
|
1967
|
-
font: { size:
|
|
1913
|
+
font: { size: import_utils8.DEFAULT_FONT_SIZE },
|
|
1968
1914
|
justify: {
|
|
1969
1915
|
vertical: "bottom",
|
|
1970
1916
|
horizontal: "left"
|
|
@@ -1976,7 +1922,7 @@ var gen_sch_sheet = (rect, pins, fields) => ({
|
|
|
1976
1922
|
text: fields.Sheetfile,
|
|
1977
1923
|
at: { position: { x: rect.pos.x, y: rect.pos.y + rect.size.y + TEXT_MARGIN }, rotation: 0 },
|
|
1978
1924
|
effects: {
|
|
1979
|
-
font: { size:
|
|
1925
|
+
font: { size: import_utils8.DEFAULT_FONT_SIZE },
|
|
1980
1926
|
justify: {
|
|
1981
1927
|
vertical: "top",
|
|
1982
1928
|
horizontal: "left"
|
|
@@ -1992,13 +1938,13 @@ var gen_sch_sheet = (rect, pins, fields) => ({
|
|
|
1992
1938
|
fill: {
|
|
1993
1939
|
color: { r: 0, g: 0, b: 0, a: 0 }
|
|
1994
1940
|
},
|
|
1995
|
-
uuid: (0,
|
|
1941
|
+
uuid: (0, import_utils8.gen_uuid)()
|
|
1996
1942
|
});
|
|
1997
1943
|
|
|
1998
1944
|
// src/kicad/symbols/lib_symbol/gnd.ts
|
|
1999
1945
|
var import_electronics_model5 = require("@modular-circuit/electronics-model");
|
|
2000
1946
|
var import_ir2 = require("@modular-circuit/ir");
|
|
2001
|
-
var
|
|
1947
|
+
var import_utils9 = require("@modular-circuit/utils");
|
|
2002
1948
|
var gen_lib_gnd = (value) => ({
|
|
2003
1949
|
name: `power:${value}`,
|
|
2004
1950
|
pin_numbers: {
|
|
@@ -2018,7 +1964,7 @@ var gen_lib_gnd = (value) => ({
|
|
|
2018
1964
|
text: "#PWR",
|
|
2019
1965
|
at: { position: { x: 0, y: -6.35 }, rotation: 0 },
|
|
2020
1966
|
effects: {
|
|
2021
|
-
font: { size:
|
|
1967
|
+
font: { size: import_utils9.DEFAULT_FONT_SIZE },
|
|
2022
1968
|
hide: true
|
|
2023
1969
|
}
|
|
2024
1970
|
},
|
|
@@ -2027,7 +1973,7 @@ var gen_lib_gnd = (value) => ({
|
|
|
2027
1973
|
text: `${value}`,
|
|
2028
1974
|
at: { position: { x: 0, y: -3.81 }, rotation: 0 },
|
|
2029
1975
|
effects: {
|
|
2030
|
-
font: { size:
|
|
1976
|
+
font: { size: import_utils9.DEFAULT_FONT_SIZE }
|
|
2031
1977
|
}
|
|
2032
1978
|
},
|
|
2033
1979
|
{
|
|
@@ -2035,7 +1981,7 @@ var gen_lib_gnd = (value) => ({
|
|
|
2035
1981
|
text: "",
|
|
2036
1982
|
at: { position: { x: 0, y: 0 }, rotation: 0 },
|
|
2037
1983
|
effects: {
|
|
2038
|
-
font: { size:
|
|
1984
|
+
font: { size: import_utils9.DEFAULT_FONT_SIZE },
|
|
2039
1985
|
hide: true
|
|
2040
1986
|
}
|
|
2041
1987
|
},
|
|
@@ -2044,7 +1990,7 @@ var gen_lib_gnd = (value) => ({
|
|
|
2044
1990
|
text: "",
|
|
2045
1991
|
at: { position: { x: 0, y: 0 }, rotation: 0 },
|
|
2046
1992
|
effects: {
|
|
2047
|
-
font: { size:
|
|
1993
|
+
font: { size: import_utils9.DEFAULT_FONT_SIZE },
|
|
2048
1994
|
hide: true
|
|
2049
1995
|
}
|
|
2050
1996
|
},
|
|
@@ -2053,7 +1999,7 @@ var gen_lib_gnd = (value) => ({
|
|
|
2053
1999
|
text: 'Power symbol creates a global label with name \\"GND\\" , ground',
|
|
2054
2000
|
at: { position: { x: 0, y: 0 }, rotation: 0 },
|
|
2055
2001
|
effects: {
|
|
2056
|
-
font: { size:
|
|
2002
|
+
font: { size: import_utils9.DEFAULT_FONT_SIZE },
|
|
2057
2003
|
hide: true
|
|
2058
2004
|
}
|
|
2059
2005
|
},
|
|
@@ -2062,7 +2008,7 @@ var gen_lib_gnd = (value) => ({
|
|
|
2062
2008
|
text: "global power",
|
|
2063
2009
|
at: { position: { x: 0, y: 0 }, rotation: 0 },
|
|
2064
2010
|
effects: {
|
|
2065
|
-
font: { size:
|
|
2011
|
+
font: { size: import_utils9.DEFAULT_FONT_SIZE },
|
|
2066
2012
|
hide: true
|
|
2067
2013
|
}
|
|
2068
2014
|
}
|
|
@@ -2103,13 +2049,13 @@ var gen_lib_gnd = (value) => ({
|
|
|
2103
2049
|
name: {
|
|
2104
2050
|
text: "~",
|
|
2105
2051
|
effects: {
|
|
2106
|
-
font: { size:
|
|
2052
|
+
font: { size: import_utils9.DEFAULT_FONT_SIZE }
|
|
2107
2053
|
}
|
|
2108
2054
|
},
|
|
2109
2055
|
number: {
|
|
2110
2056
|
text: "1",
|
|
2111
2057
|
effects: {
|
|
2112
|
-
font: { size:
|
|
2058
|
+
font: { size: import_utils9.DEFAULT_FONT_SIZE }
|
|
2113
2059
|
}
|
|
2114
2060
|
}
|
|
2115
2061
|
}
|
|
@@ -2121,7 +2067,7 @@ var gen_lib_gnd = (value) => ({
|
|
|
2121
2067
|
// src/kicad/symbols/lib_symbol/vcc.ts
|
|
2122
2068
|
var import_electronics_model6 = require("@modular-circuit/electronics-model");
|
|
2123
2069
|
var import_ir3 = require("@modular-circuit/ir");
|
|
2124
|
-
var
|
|
2070
|
+
var import_utils10 = require("@modular-circuit/utils");
|
|
2125
2071
|
var gen_lib_vcc = (value) => ({
|
|
2126
2072
|
name: `power:${value}`,
|
|
2127
2073
|
power: true,
|
|
@@ -2142,7 +2088,7 @@ var gen_lib_vcc = (value) => ({
|
|
|
2142
2088
|
text: "#PWR",
|
|
2143
2089
|
at: { position: { x: 0, y: -3.81 }, rotation: 0 },
|
|
2144
2090
|
effects: {
|
|
2145
|
-
font: { size:
|
|
2091
|
+
font: { size: import_utils10.DEFAULT_FONT_SIZE },
|
|
2146
2092
|
hide: true
|
|
2147
2093
|
}
|
|
2148
2094
|
},
|
|
@@ -2151,7 +2097,7 @@ var gen_lib_vcc = (value) => ({
|
|
|
2151
2097
|
text: `${value}`,
|
|
2152
2098
|
at: { position: { x: 0, y: 3.556 }, rotation: 0 },
|
|
2153
2099
|
effects: {
|
|
2154
|
-
font: { size:
|
|
2100
|
+
font: { size: import_utils10.DEFAULT_FONT_SIZE }
|
|
2155
2101
|
}
|
|
2156
2102
|
},
|
|
2157
2103
|
{
|
|
@@ -2159,7 +2105,7 @@ var gen_lib_vcc = (value) => ({
|
|
|
2159
2105
|
text: "",
|
|
2160
2106
|
at: { position: { x: 0, y: 0 }, rotation: 0 },
|
|
2161
2107
|
effects: {
|
|
2162
|
-
font: { size:
|
|
2108
|
+
font: { size: import_utils10.DEFAULT_FONT_SIZE },
|
|
2163
2109
|
hide: true
|
|
2164
2110
|
}
|
|
2165
2111
|
},
|
|
@@ -2168,7 +2114,7 @@ var gen_lib_vcc = (value) => ({
|
|
|
2168
2114
|
text: "",
|
|
2169
2115
|
at: { position: { x: 0, y: 0 }, rotation: 0 },
|
|
2170
2116
|
effects: {
|
|
2171
|
-
font: { size:
|
|
2117
|
+
font: { size: import_utils10.DEFAULT_FONT_SIZE },
|
|
2172
2118
|
hide: true
|
|
2173
2119
|
}
|
|
2174
2120
|
},
|
|
@@ -2177,7 +2123,7 @@ var gen_lib_vcc = (value) => ({
|
|
|
2177
2123
|
text: `Power symbol creates a global label with name \\"${value}\\"`,
|
|
2178
2124
|
at: { position: { x: 0, y: 0 }, rotation: 0 },
|
|
2179
2125
|
effects: {
|
|
2180
|
-
font: { size:
|
|
2126
|
+
font: { size: import_utils10.DEFAULT_FONT_SIZE },
|
|
2181
2127
|
hide: true
|
|
2182
2128
|
}
|
|
2183
2129
|
},
|
|
@@ -2186,7 +2132,7 @@ var gen_lib_vcc = (value) => ({
|
|
|
2186
2132
|
text: "global power",
|
|
2187
2133
|
at: { position: { x: 0, y: 0 }, rotation: 0 },
|
|
2188
2134
|
effects: {
|
|
2189
|
-
font: { size:
|
|
2135
|
+
font: { size: import_utils10.DEFAULT_FONT_SIZE },
|
|
2190
2136
|
hide: true
|
|
2191
2137
|
}
|
|
2192
2138
|
}
|
|
@@ -2224,13 +2170,13 @@ var gen_lib_vcc = (value) => ({
|
|
|
2224
2170
|
name: {
|
|
2225
2171
|
text: "~",
|
|
2226
2172
|
effects: {
|
|
2227
|
-
font: { size:
|
|
2173
|
+
font: { size: import_utils10.DEFAULT_FONT_SIZE }
|
|
2228
2174
|
}
|
|
2229
2175
|
},
|
|
2230
2176
|
number: {
|
|
2231
2177
|
text: "1",
|
|
2232
2178
|
effects: {
|
|
2233
|
-
font: { size:
|
|
2179
|
+
font: { size: import_utils10.DEFAULT_FONT_SIZE }
|
|
2234
2180
|
}
|
|
2235
2181
|
}
|
|
2236
2182
|
}
|
|
@@ -2240,7 +2186,7 @@ var gen_lib_vcc = (value) => ({
|
|
|
2240
2186
|
});
|
|
2241
2187
|
|
|
2242
2188
|
// src/kicad/symbols/sch_symbol/gnd.ts
|
|
2243
|
-
var
|
|
2189
|
+
var import_utils11 = require("@modular-circuit/utils");
|
|
2244
2190
|
|
|
2245
2191
|
// src/kicad/symbols/symbol_utils.ts
|
|
2246
2192
|
var gen_pwr_ref = (pwr_num) => `#PWR${pwr_num}`;
|
|
@@ -2255,14 +2201,14 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
|
|
|
2255
2201
|
on_board: true,
|
|
2256
2202
|
dnp: false,
|
|
2257
2203
|
fields_autoplaced: true,
|
|
2258
|
-
uuid: (0,
|
|
2204
|
+
uuid: (0, import_utils11.gen_uuid)(),
|
|
2259
2205
|
properties: [
|
|
2260
2206
|
{
|
|
2261
2207
|
name: "Reference",
|
|
2262
2208
|
text: gen_pwr_ref(pwr_number),
|
|
2263
2209
|
at: { position: { x: position.x, y: position.y + 6.35 }, rotation: 0 },
|
|
2264
2210
|
effects: {
|
|
2265
|
-
font: { size:
|
|
2211
|
+
font: { size: import_utils11.DEFAULT_FONT_SIZE },
|
|
2266
2212
|
hide: true
|
|
2267
2213
|
}
|
|
2268
2214
|
},
|
|
@@ -2271,7 +2217,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
|
|
|
2271
2217
|
text: `${value}`,
|
|
2272
2218
|
at: { position: { x: position.x, y: position.y + 5.08 }, rotation: 0 },
|
|
2273
2219
|
effects: {
|
|
2274
|
-
font: { size:
|
|
2220
|
+
font: { size: import_utils11.DEFAULT_FONT_SIZE }
|
|
2275
2221
|
}
|
|
2276
2222
|
},
|
|
2277
2223
|
{
|
|
@@ -2279,7 +2225,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
|
|
|
2279
2225
|
text: "",
|
|
2280
2226
|
at: { position, rotation: 0 },
|
|
2281
2227
|
effects: {
|
|
2282
|
-
font: { size:
|
|
2228
|
+
font: { size: import_utils11.DEFAULT_FONT_SIZE },
|
|
2283
2229
|
hide: true
|
|
2284
2230
|
}
|
|
2285
2231
|
},
|
|
@@ -2288,7 +2234,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
|
|
|
2288
2234
|
text: "",
|
|
2289
2235
|
at: { position, rotation: 0 },
|
|
2290
2236
|
effects: {
|
|
2291
|
-
font: { size:
|
|
2237
|
+
font: { size: import_utils11.DEFAULT_FONT_SIZE },
|
|
2292
2238
|
hide: true
|
|
2293
2239
|
}
|
|
2294
2240
|
},
|
|
@@ -2297,7 +2243,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
|
|
|
2297
2243
|
text: `Power symbol creates a global label with name \\"${value}\\" , ground`,
|
|
2298
2244
|
at: { position, rotation: 0 },
|
|
2299
2245
|
effects: {
|
|
2300
|
-
font: { size:
|
|
2246
|
+
font: { size: import_utils11.DEFAULT_FONT_SIZE },
|
|
2301
2247
|
hide: true
|
|
2302
2248
|
}
|
|
2303
2249
|
}
|
|
@@ -2311,7 +2257,7 @@ var gen_sch_gnd = (value, pwr_number, port_id, position) => ({
|
|
|
2311
2257
|
});
|
|
2312
2258
|
|
|
2313
2259
|
// src/kicad/symbols/sch_symbol/vcc.ts
|
|
2314
|
-
var
|
|
2260
|
+
var import_utils12 = require("@modular-circuit/utils");
|
|
2315
2261
|
var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
|
|
2316
2262
|
lib_id: `power:${value}`,
|
|
2317
2263
|
at: { position, rotation: 0 },
|
|
@@ -2321,14 +2267,14 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
|
|
|
2321
2267
|
on_board: true,
|
|
2322
2268
|
dnp: false,
|
|
2323
2269
|
fields_autoplaced: true,
|
|
2324
|
-
uuid: (0,
|
|
2270
|
+
uuid: (0, import_utils12.gen_uuid)(),
|
|
2325
2271
|
properties: [
|
|
2326
2272
|
{
|
|
2327
2273
|
name: "Reference",
|
|
2328
2274
|
text: gen_pwr_ref(pwr_number),
|
|
2329
2275
|
at: { position: { x: position.x, y: position.y + 3.81 }, rotation: 0 },
|
|
2330
2276
|
effects: {
|
|
2331
|
-
font: { size:
|
|
2277
|
+
font: { size: import_utils12.DEFAULT_FONT_SIZE },
|
|
2332
2278
|
hide: true
|
|
2333
2279
|
}
|
|
2334
2280
|
},
|
|
@@ -2337,7 +2283,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
|
|
|
2337
2283
|
text: `${value}`,
|
|
2338
2284
|
at: { position: { x: position.x, y: position.y - 5.08 }, rotation: 0 },
|
|
2339
2285
|
effects: {
|
|
2340
|
-
font: { size:
|
|
2286
|
+
font: { size: import_utils12.DEFAULT_FONT_SIZE }
|
|
2341
2287
|
}
|
|
2342
2288
|
},
|
|
2343
2289
|
{
|
|
@@ -2345,7 +2291,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
|
|
|
2345
2291
|
text: "",
|
|
2346
2292
|
at: { position, rotation: 0 },
|
|
2347
2293
|
effects: {
|
|
2348
|
-
font: { size:
|
|
2294
|
+
font: { size: import_utils12.DEFAULT_FONT_SIZE },
|
|
2349
2295
|
hide: true
|
|
2350
2296
|
}
|
|
2351
2297
|
},
|
|
@@ -2354,7 +2300,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
|
|
|
2354
2300
|
text: "",
|
|
2355
2301
|
at: { position, rotation: 0 },
|
|
2356
2302
|
effects: {
|
|
2357
|
-
font: { size:
|
|
2303
|
+
font: { size: import_utils12.DEFAULT_FONT_SIZE },
|
|
2358
2304
|
hide: true
|
|
2359
2305
|
}
|
|
2360
2306
|
},
|
|
@@ -2363,7 +2309,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
|
|
|
2363
2309
|
text: `Power symbol creates a global label with name \\"${value}\\"`,
|
|
2364
2310
|
at: { position, rotation: 0 },
|
|
2365
2311
|
effects: {
|
|
2366
|
-
font: { size:
|
|
2312
|
+
font: { size: import_utils12.DEFAULT_FONT_SIZE },
|
|
2367
2313
|
hide: true
|
|
2368
2314
|
}
|
|
2369
2315
|
}
|
|
@@ -2378,7 +2324,7 @@ var gen_sch_vcc = (value, pwr_number, port_id, position) => ({
|
|
|
2378
2324
|
|
|
2379
2325
|
// src/kicad/wire/gen_wire.ts
|
|
2380
2326
|
var import_electronics_model7 = require("@modular-circuit/electronics-model");
|
|
2381
|
-
var
|
|
2327
|
+
var import_utils13 = require("@modular-circuit/utils");
|
|
2382
2328
|
var gen_wire = (start, end) => ({
|
|
2383
2329
|
stroke: {
|
|
2384
2330
|
type: "default",
|
|
@@ -2386,7 +2332,7 @@ var gen_wire = (start, end) => ({
|
|
|
2386
2332
|
},
|
|
2387
2333
|
start,
|
|
2388
2334
|
end,
|
|
2389
|
-
uuid: (0,
|
|
2335
|
+
uuid: (0, import_utils13.gen_uuid)(),
|
|
2390
2336
|
type: import_electronics_model7.GS_SCH_ITEM_TYPE.LINE
|
|
2391
2337
|
});
|
|
2392
2338
|
|
|
@@ -2434,15 +2380,15 @@ var NetListConverter = class {
|
|
|
2434
2380
|
const powers = /* @__PURE__ */ new Set();
|
|
2435
2381
|
this.wires = [];
|
|
2436
2382
|
const sch = {
|
|
2437
|
-
version:
|
|
2438
|
-
generator:
|
|
2439
|
-
generator_version:
|
|
2383
|
+
version: import_utils14.SCH_VERSION,
|
|
2384
|
+
generator: import_utils14.GENERATOR_NAME,
|
|
2385
|
+
generator_version: import_utils14.GENERATOR_VERSION,
|
|
2440
2386
|
paper: {
|
|
2441
2387
|
size: "A4"
|
|
2442
2388
|
},
|
|
2443
2389
|
title_block: {
|
|
2444
2390
|
title: name.replace(`.${import_ir4.MODULAR_CIRCUIT_SCH_EXT}`, ""),
|
|
2445
|
-
date: (0,
|
|
2391
|
+
date: (0, import_utils14.replaceAll)((/* @__PURE__ */ new Date()).toISOString().slice(0, 10), "-", "/"),
|
|
2446
2392
|
rev: "1.0",
|
|
2447
2393
|
comment: {
|
|
2448
2394
|
1: "https://www.eda.cn",
|
|
@@ -2605,19 +2551,26 @@ var NetListConverter = class {
|
|
|
2605
2551
|
// src/builder/graph_to_kicad/convert_graph_to_sheets.ts
|
|
2606
2552
|
var import_ir5 = require("@modular-circuit/ir");
|
|
2607
2553
|
var import_perc = require("@modular-circuit/perc");
|
|
2608
|
-
var
|
|
2554
|
+
var import_utils15 = require("@modular-circuit/utils");
|
|
2609
2555
|
async function do_convert_graph_to_kicad_project(ctx) {
|
|
2610
2556
|
const module_ids = [];
|
|
2557
|
+
const generated_sheets = {};
|
|
2611
2558
|
for (const sch of Object.values(ctx.schematics)) {
|
|
2612
2559
|
for (const mod of sch.blocks ?? []) {
|
|
2613
|
-
if (!(0, import_ir5.block_is_abstract)(mod)
|
|
2614
|
-
module_ids.push(mod.type);
|
|
2560
|
+
if (!(0, import_ir5.block_is_abstract)(mod)) {
|
|
2561
|
+
if ((0, import_ir5.block_is_associated_with_concrete_module)(mod.type)) module_ids.push(mod.type);
|
|
2562
|
+
} else {
|
|
2563
|
+
if (ctx.netlist_transpiler && (0, import_ir5.block_is_resolved_abstract)(mod)) {
|
|
2564
|
+
const sheet_file_name = (0, import_utils15.fmt_abstract_sch_name)(mod);
|
|
2565
|
+
const netlist2 = mod.netlist;
|
|
2566
|
+
generated_sheets[sheet_file_name] = await ctx.netlist_transpiler.convert_netlist_to_kicad(netlist2);
|
|
2567
|
+
}
|
|
2615
2568
|
}
|
|
2616
2569
|
}
|
|
2617
2570
|
}
|
|
2618
2571
|
const { sheets } = {
|
|
2619
|
-
...await
|
|
2620
|
-
...
|
|
2572
|
+
...await collect_sub_sheets_by_id(module_ids, ctx.module_resolver),
|
|
2573
|
+
...{ sheets: generated_sheets }
|
|
2621
2574
|
};
|
|
2622
2575
|
const netlist = new GraphConverter({
|
|
2623
2576
|
...ctx
|
|
@@ -2626,7 +2579,7 @@ async function do_convert_graph_to_kicad_project(ctx) {
|
|
|
2626
2579
|
for (const sheet of sch.sheet_symbols) {
|
|
2627
2580
|
const original_st_fn = sheet.sheet_file_name;
|
|
2628
2581
|
if (!(original_st_fn in sheets)) {
|
|
2629
|
-
const placeholder_fn = fmt_module_place_holder_sch_name(sheet.sheet_name);
|
|
2582
|
+
const placeholder_fn = (0, import_utils15.fmt_module_place_holder_sch_name)(sheet.sheet_name);
|
|
2630
2583
|
sheet.sheet_file_name = placeholder_fn;
|
|
2631
2584
|
sheets[placeholder_fn] = await gen_empty_sch(placeholder_fn);
|
|
2632
2585
|
}
|
|
@@ -2641,7 +2594,7 @@ async function do_convert_graph_to_kicad_project(ctx) {
|
|
|
2641
2594
|
if (k in sheets) {
|
|
2642
2595
|
console.error(`Duplicated sheet file name found ${k}`);
|
|
2643
2596
|
}
|
|
2644
|
-
sheets[k.replace(import_ir5.MODULAR_CIRCUIT_SCH_EXT,
|
|
2597
|
+
sheets[k.replace(import_ir5.MODULAR_CIRCUIT_SCH_EXT, import_utils15.KiCadSchematicFileExtension)] = sexpr_printer.schematic(v);
|
|
2645
2598
|
}
|
|
2646
2599
|
return sheets;
|
|
2647
2600
|
}
|
|
@@ -2656,7 +2609,7 @@ async function convert_graph_to_sheets(ctx) {
|
|
|
2656
2609
|
}
|
|
2657
2610
|
|
|
2658
2611
|
// src/kicad/project/kicad_project_archive.ts
|
|
2659
|
-
var
|
|
2612
|
+
var import_utils18 = require("@modular-circuit/utils");
|
|
2660
2613
|
var import_jszip = __toESM(require("jszip"));
|
|
2661
2614
|
|
|
2662
2615
|
// src/kicad/project/kicad_prl.ts
|
|
@@ -2745,7 +2698,7 @@ var kicad_prl = (prj_name) => ({
|
|
|
2745
2698
|
});
|
|
2746
2699
|
|
|
2747
2700
|
// src/kicad/project/kicad_pro.ts
|
|
2748
|
-
var
|
|
2701
|
+
var import_utils17 = require("@modular-circuit/utils");
|
|
2749
2702
|
var kicad_pro = (project_name) => ({
|
|
2750
2703
|
board: {
|
|
2751
2704
|
"3dviewports": [],
|
|
@@ -2955,7 +2908,7 @@ var kicad_pro = (project_name) => ({
|
|
|
2955
2908
|
version: 1
|
|
2956
2909
|
},
|
|
2957
2910
|
net_format_name: "",
|
|
2958
|
-
page_layout_descr_file: `${project_name}.${
|
|
2911
|
+
page_layout_descr_file: `${project_name}.${import_utils17.DrawingSheetFileExtension}`,
|
|
2959
2912
|
plot_directory: "",
|
|
2960
2913
|
spice_current_sheet_as_root: false,
|
|
2961
2914
|
spice_external_command: 'spice "%I"',
|
|
@@ -2993,16 +2946,16 @@ var KiCadProjectArchive = class {
|
|
|
2993
2946
|
return kicad_pro(this.project_name);
|
|
2994
2947
|
}
|
|
2995
2948
|
get main_sch_name() {
|
|
2996
|
-
return this.get_project_directive_file_name(
|
|
2949
|
+
return this.get_project_directive_file_name(import_utils18.KiCadSchematicFileExtension);
|
|
2997
2950
|
}
|
|
2998
2951
|
get_project_directive_file_name(ext) {
|
|
2999
2952
|
return `${this.project_name}.${ext}`;
|
|
3000
2953
|
}
|
|
3001
2954
|
async toZip() {
|
|
3002
2955
|
const zip = new import_jszip.default();
|
|
3003
|
-
zip.file(this.get_project_directive_file_name(
|
|
3004
|
-
zip.file(this.get_project_directive_file_name(
|
|
3005
|
-
zip.file(this.get_project_directive_file_name(
|
|
2956
|
+
zip.file(this.get_project_directive_file_name(import_utils18.ProjectLocalSettingsFileExtension), JSON.stringify(this.kicad_prl));
|
|
2957
|
+
zip.file(this.get_project_directive_file_name(import_utils18.ProjectFileExtension), JSON.stringify(this.kicad_pro));
|
|
2958
|
+
zip.file(this.get_project_directive_file_name(import_utils18.DrawingSheetFileExtension), this.sch_frame);
|
|
3006
2959
|
for (const schematic of this.designBlock.schematics) {
|
|
3007
2960
|
zip.file(schematic.filename, schematic.content);
|
|
3008
2961
|
}
|
|
@@ -3050,9 +3003,9 @@ var KiCadProjectArchive = class {
|
|
|
3050
3003
|
};
|
|
3051
3004
|
|
|
3052
3005
|
// src/builder/graph_to_kicad/convert_graph_to_design_block.ts
|
|
3053
|
-
var
|
|
3006
|
+
var import_utils19 = require("@modular-circuit/utils");
|
|
3054
3007
|
async function convert_graph_to_design_block(ctx) {
|
|
3055
|
-
const root = ctx.project.main.replace(
|
|
3008
|
+
const root = ctx.project.main.replace(import_utils19.ModularCircuitFileExtension, import_utils19.KiCadSchematicFileExtension);
|
|
3056
3009
|
const sheets = await convert_graph_to_sheets(ctx);
|
|
3057
3010
|
if (!(root in sheets)) {
|
|
3058
3011
|
throw new Error(`Cannot find root sch file ${root}`);
|
|
@@ -3091,14 +3044,11 @@ async function convert_graph_to_kicad_project(ctx) {
|
|
|
3091
3044
|
SCHEMATIC_PRINTER,
|
|
3092
3045
|
StringFormatter,
|
|
3093
3046
|
WIRE_PADDING,
|
|
3094
|
-
collect_sub_sheets,
|
|
3095
3047
|
collect_sub_sheets_by_id,
|
|
3096
3048
|
convert_graph_to_design_block,
|
|
3097
3049
|
convert_graph_to_kicad_project,
|
|
3098
3050
|
convert_graph_to_sheets,
|
|
3099
3051
|
filterNullOrUndefined,
|
|
3100
|
-
fmt_module_place_holder_sch_name,
|
|
3101
|
-
fmt_to_valid_filename,
|
|
3102
3052
|
gen_empty_sch,
|
|
3103
3053
|
gen_lib_gnd,
|
|
3104
3054
|
gen_lib_vcc,
|
package/dist/index.mjs
CHANGED
|
@@ -64,56 +64,6 @@ import {
|
|
|
64
64
|
} from "@modular-circuit/ir";
|
|
65
65
|
import { GENERATOR_NAME, GENERATOR_VERSION, PAPER, SCH_VERSION, gen_uuid as gen_uuid2 } from "@modular-circuit/utils";
|
|
66
66
|
|
|
67
|
-
// src/utils/collect_sub_sheets.ts
|
|
68
|
-
import {
|
|
69
|
-
KiCadSchematicFileExtension,
|
|
70
|
-
parse_module_name,
|
|
71
|
-
remove_filename_path_prefix,
|
|
72
|
-
unzipFile
|
|
73
|
-
} from "@modular-circuit/utils";
|
|
74
|
-
async function collect_sub_sheets(dependencies, module_resolver) {
|
|
75
|
-
const sheets = {};
|
|
76
|
-
const module_main_sheet = {};
|
|
77
|
-
const modules = {};
|
|
78
|
-
for (const [k, v] of Object.entries(dependencies)) {
|
|
79
|
-
try {
|
|
80
|
-
const zip_archive_url = await module_resolver.get_module_archive({
|
|
81
|
-
...parse_module_name(k),
|
|
82
|
-
version: v
|
|
83
|
-
});
|
|
84
|
-
const module = await module_resolver.get_module_circuit({
|
|
85
|
-
...parse_module_name(k),
|
|
86
|
-
version: v
|
|
87
|
-
});
|
|
88
|
-
if (!zip_archive_url || !module) {
|
|
89
|
-
console.error(`Module ${k}/${v} not found`);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (!module.main) {
|
|
93
|
-
console.error(`Missing main entry in module ${k}/${v}`);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
module_main_sheet[k] = module.main;
|
|
97
|
-
modules[k] = module;
|
|
98
|
-
const zip_archive = await fetch(zip_archive_url).then((res) => res.arrayBuffer());
|
|
99
|
-
const files = await unzipFile(zip_archive);
|
|
100
|
-
for (const [name, content] of Object.entries(files)) {
|
|
101
|
-
if (name.endsWith(KiCadSchematicFileExtension)) {
|
|
102
|
-
const fileName = remove_filename_path_prefix(name);
|
|
103
|
-
if (fileName in sheets) {
|
|
104
|
-
console.error(`Duplicate sheet name: ${fileName}`);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
sheets[fileName] = content;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
} catch (e) {
|
|
111
|
-
console.error(`Failed to download zip for module : ${e}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return { sheets, module_main_sheet, modules };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
67
|
// src/utils/filter_null_undefined.ts
|
|
118
68
|
function filterNullOrUndefined(originalMethod, _context) {
|
|
119
69
|
function replacementMethod(...args) {
|
|
@@ -157,10 +107,10 @@ var StringFormatter = class {
|
|
|
157
107
|
// src/utils/collect_sub_sheets_by_id.ts
|
|
158
108
|
import {
|
|
159
109
|
KiCadPcbFileExtension,
|
|
160
|
-
KiCadSchematicFileExtension
|
|
110
|
+
KiCadSchematicFileExtension,
|
|
161
111
|
fmt_module_name,
|
|
162
|
-
remove_filename_path_prefix
|
|
163
|
-
unzipFile
|
|
112
|
+
remove_filename_path_prefix,
|
|
113
|
+
unzipFile
|
|
164
114
|
} from "@modular-circuit/utils";
|
|
165
115
|
async function collect_sub_sheets_by_id(module_ids, module_resolver) {
|
|
166
116
|
const sheets = {};
|
|
@@ -194,10 +144,10 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
|
|
|
194
144
|
};
|
|
195
145
|
console.log(`Fetching ZIP archive for module ${id} from ${zip_archive_url.toString()}`);
|
|
196
146
|
const zip_archive = await fetch(zip_archive_url).then((res) => res.arrayBuffer());
|
|
197
|
-
const files = await
|
|
147
|
+
const files = await unzipFile(zip_archive);
|
|
198
148
|
for (const [name, content] of Object.entries(files)) {
|
|
199
|
-
if (name.endsWith(
|
|
200
|
-
const filename =
|
|
149
|
+
if (name.endsWith(KiCadSchematicFileExtension)) {
|
|
150
|
+
const filename = remove_filename_path_prefix(name);
|
|
201
151
|
if (filename in sheets) {
|
|
202
152
|
console.error(`Duplicate sheet name: ${filename}`);
|
|
203
153
|
continue;
|
|
@@ -205,7 +155,7 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
|
|
|
205
155
|
sheets[filename] = content;
|
|
206
156
|
design_block.schematics.push({ filename, content });
|
|
207
157
|
} else if (name.endsWith(KiCadPcbFileExtension)) {
|
|
208
|
-
const filename =
|
|
158
|
+
const filename = remove_filename_path_prefix(name);
|
|
209
159
|
design_block.pcb = { pcb: { filename, content } };
|
|
210
160
|
}
|
|
211
161
|
}
|
|
@@ -217,12 +167,6 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
|
|
|
217
167
|
return { sheets, module_main_sheet, modules, design_blocks };
|
|
218
168
|
}
|
|
219
169
|
|
|
220
|
-
// src/utils/fmt_to_valid_filename.ts
|
|
221
|
-
var fmt_to_valid_filename = (name) => {
|
|
222
|
-
return name.replace(/[\\/:*?"<>|]/g, "_").trim();
|
|
223
|
-
};
|
|
224
|
-
var fmt_module_place_holder_sch_name = (mod_name) => `placeholder_${fmt_to_valid_filename(mod_name)}.kicad_sch`;
|
|
225
|
-
|
|
226
170
|
// src/utils/gen_empty_sch.ts
|
|
227
171
|
import { gen_uuid } from "@modular-circuit/utils";
|
|
228
172
|
var gen_empty_sch = async (name) => {
|
|
@@ -2574,22 +2518,34 @@ var NetListConverter = class {
|
|
|
2574
2518
|
import {
|
|
2575
2519
|
MODULAR_CIRCUIT_SCH_EXT as MODULAR_CIRCUIT_SCH_EXT2,
|
|
2576
2520
|
block_is_abstract,
|
|
2577
|
-
block_is_associated_with_concrete_module
|
|
2521
|
+
block_is_associated_with_concrete_module,
|
|
2522
|
+
block_is_resolved_abstract
|
|
2578
2523
|
} from "@modular-circuit/ir";
|
|
2579
2524
|
import { build_connection_graph } from "@modular-circuit/perc";
|
|
2580
|
-
import {
|
|
2525
|
+
import {
|
|
2526
|
+
fmt_abstract_sch_name,
|
|
2527
|
+
fmt_module_place_holder_sch_name,
|
|
2528
|
+
KiCadSchematicFileExtension as KiCadSchematicFileExtension2
|
|
2529
|
+
} from "@modular-circuit/utils";
|
|
2581
2530
|
async function do_convert_graph_to_kicad_project(ctx) {
|
|
2582
2531
|
const module_ids = [];
|
|
2532
|
+
const generated_sheets = {};
|
|
2583
2533
|
for (const sch of Object.values(ctx.schematics)) {
|
|
2584
2534
|
for (const mod of sch.blocks ?? []) {
|
|
2585
|
-
if (!block_is_abstract(mod)
|
|
2586
|
-
module_ids.push(mod.type);
|
|
2535
|
+
if (!block_is_abstract(mod)) {
|
|
2536
|
+
if (block_is_associated_with_concrete_module(mod.type)) module_ids.push(mod.type);
|
|
2537
|
+
} else {
|
|
2538
|
+
if (ctx.netlist_transpiler && block_is_resolved_abstract(mod)) {
|
|
2539
|
+
const sheet_file_name = fmt_abstract_sch_name(mod);
|
|
2540
|
+
const netlist2 = mod.netlist;
|
|
2541
|
+
generated_sheets[sheet_file_name] = await ctx.netlist_transpiler.convert_netlist_to_kicad(netlist2);
|
|
2542
|
+
}
|
|
2587
2543
|
}
|
|
2588
2544
|
}
|
|
2589
2545
|
}
|
|
2590
2546
|
const { sheets } = {
|
|
2591
|
-
...await
|
|
2592
|
-
...
|
|
2547
|
+
...await collect_sub_sheets_by_id(module_ids, ctx.module_resolver),
|
|
2548
|
+
...{ sheets: generated_sheets }
|
|
2593
2549
|
};
|
|
2594
2550
|
const netlist = new GraphConverter({
|
|
2595
2551
|
...ctx
|
|
@@ -2613,7 +2569,7 @@ async function do_convert_graph_to_kicad_project(ctx) {
|
|
|
2613
2569
|
if (k in sheets) {
|
|
2614
2570
|
console.error(`Duplicated sheet file name found ${k}`);
|
|
2615
2571
|
}
|
|
2616
|
-
sheets[k.replace(MODULAR_CIRCUIT_SCH_EXT2,
|
|
2572
|
+
sheets[k.replace(MODULAR_CIRCUIT_SCH_EXT2, KiCadSchematicFileExtension2)] = sexpr_printer.schematic(v);
|
|
2617
2573
|
}
|
|
2618
2574
|
return sheets;
|
|
2619
2575
|
}
|
|
@@ -2630,7 +2586,7 @@ async function convert_graph_to_sheets(ctx) {
|
|
|
2630
2586
|
// src/kicad/project/kicad_project_archive.ts
|
|
2631
2587
|
import {
|
|
2632
2588
|
DrawingSheetFileExtension as DrawingSheetFileExtension2,
|
|
2633
|
-
KiCadSchematicFileExtension as
|
|
2589
|
+
KiCadSchematicFileExtension as KiCadSchematicFileExtension3,
|
|
2634
2590
|
ProjectFileExtension,
|
|
2635
2591
|
ProjectLocalSettingsFileExtension
|
|
2636
2592
|
} from "@modular-circuit/utils";
|
|
@@ -2970,7 +2926,7 @@ var KiCadProjectArchive = class {
|
|
|
2970
2926
|
return kicad_pro(this.project_name);
|
|
2971
2927
|
}
|
|
2972
2928
|
get main_sch_name() {
|
|
2973
|
-
return this.get_project_directive_file_name(
|
|
2929
|
+
return this.get_project_directive_file_name(KiCadSchematicFileExtension3);
|
|
2974
2930
|
}
|
|
2975
2931
|
get_project_directive_file_name(ext) {
|
|
2976
2932
|
return `${this.project_name}.${ext}`;
|
|
@@ -3027,9 +2983,9 @@ var KiCadProjectArchive = class {
|
|
|
3027
2983
|
};
|
|
3028
2984
|
|
|
3029
2985
|
// src/builder/graph_to_kicad/convert_graph_to_design_block.ts
|
|
3030
|
-
import { KiCadSchematicFileExtension as
|
|
2986
|
+
import { KiCadSchematicFileExtension as KiCadSchematicFileExtension4, ModularCircuitFileExtension } from "@modular-circuit/utils";
|
|
3031
2987
|
async function convert_graph_to_design_block(ctx) {
|
|
3032
|
-
const root = ctx.project.main.replace(ModularCircuitFileExtension,
|
|
2988
|
+
const root = ctx.project.main.replace(ModularCircuitFileExtension, KiCadSchematicFileExtension4);
|
|
3033
2989
|
const sheets = await convert_graph_to_sheets(ctx);
|
|
3034
2990
|
if (!(root in sheets)) {
|
|
3035
2991
|
throw new Error(`Cannot find root sch file ${root}`);
|
|
@@ -3067,14 +3023,11 @@ export {
|
|
|
3067
3023
|
SCHEMATIC_PRINTER,
|
|
3068
3024
|
StringFormatter,
|
|
3069
3025
|
WIRE_PADDING,
|
|
3070
|
-
collect_sub_sheets,
|
|
3071
3026
|
collect_sub_sheets_by_id,
|
|
3072
3027
|
convert_graph_to_design_block,
|
|
3073
3028
|
convert_graph_to_kicad_project,
|
|
3074
3029
|
convert_graph_to_sheets,
|
|
3075
3030
|
filterNullOrUndefined,
|
|
3076
|
-
fmt_module_place_holder_sch_name,
|
|
3077
|
-
fmt_to_valid_filename,
|
|
3078
3031
|
gen_empty_sch,
|
|
3079
3032
|
gen_lib_gnd,
|
|
3080
3033
|
gen_lib_vcc,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modular-circuit/transpiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Intermediate representation of the modular circuit",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -29,10 +29,11 @@
|
|
|
29
29
|
"elkjs": "^0.11.0",
|
|
30
30
|
"js-base64": "^3.7.7",
|
|
31
31
|
"jszip": "^3.10.1",
|
|
32
|
-
"@modular-circuit/electronics-model": "0.
|
|
33
|
-
"@modular-circuit/
|
|
34
|
-
"@modular-circuit/
|
|
35
|
-
"@modular-circuit/
|
|
32
|
+
"@modular-circuit/electronics-model": "0.3.0",
|
|
33
|
+
"@modular-circuit/perc": "0.3.0",
|
|
34
|
+
"@modular-circuit/ir": "0.3.0",
|
|
35
|
+
"@modular-circuit/genai": "0.3.0",
|
|
36
|
+
"@modular-circuit/utils": "0.3.0"
|
|
36
37
|
},
|
|
37
38
|
"scripts": {
|
|
38
39
|
"clean": "rimraf dist",
|