@modular-circuit/transpiler 0.2.10 → 0.2.12

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 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;
@@ -401,9 +406,6 @@ declare function collect_sub_sheets_by_id(module_ids: string[], module_resolver:
401
406
  design_blocks: DesignBlockContent[];
402
407
  }>;
403
408
 
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
409
  declare const gen_empty_sch: (name: string) => Promise<string>;
408
410
 
409
411
  declare const gen_lib_gnd: (value: string) => LIB_SYMBOL;
@@ -414,4 +416,4 @@ declare const gen_sch_gnd: (value: string, pwr_number: number, port_id: string,
414
416
 
415
417
  declare const gen_sch_vcc: (value: string, pwr_number: number, port_id: string, position: VECTOR2) => SCH_SYMBOL;
416
418
 
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, collect_sub_sheets, collect_sub_sheets_by_id, convert_graph_to_design_block, convert_graph_to_kicad_project, convert_graph_to_sheets, filterNullOrUndefined, fmt_module_place_holder_sch_name, fmt_to_valid_filename, gen_empty_sch, gen_lib_gnd, gen_lib_vcc, gen_sch_gnd, gen_sch_vcc, get_power_pos, get_sch_default_drawing_sheet, tab };
419
+ 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, 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;
@@ -401,9 +406,6 @@ declare function collect_sub_sheets_by_id(module_ids: string[], module_resolver:
401
406
  design_blocks: DesignBlockContent[];
402
407
  }>;
403
408
 
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
409
  declare const gen_empty_sch: (name: string) => Promise<string>;
408
410
 
409
411
  declare const gen_lib_gnd: (value: string) => LIB_SYMBOL;
@@ -414,4 +416,4 @@ declare const gen_sch_gnd: (value: string, pwr_number: number, port_id: string,
414
416
 
415
417
  declare const gen_sch_vcc: (value: string, pwr_number: number, port_id: string, position: VECTOR2) => SCH_SYMBOL;
416
418
 
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, collect_sub_sheets, collect_sub_sheets_by_id, convert_graph_to_design_block, convert_graph_to_kicad_project, convert_graph_to_sheets, filterNullOrUndefined, fmt_module_place_holder_sch_name, fmt_to_valid_filename, gen_empty_sch, gen_lib_gnd, gen_lib_vcc, gen_sch_gnd, gen_sch_vcc, get_power_pos, get_sch_default_drawing_sheet, tab };
419
+ 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, 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
@@ -92,8 +92,6 @@ __export(index_exports, {
92
92
  convert_graph_to_kicad_project: () => convert_graph_to_kicad_project,
93
93
  convert_graph_to_sheets: () => convert_graph_to_sheets,
94
94
  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
95
  gen_empty_sch: () => gen_empty_sch,
98
96
  gen_lib_gnd: () => gen_lib_gnd,
99
97
  gen_lib_vcc: () => gen_lib_vcc,
@@ -263,12 +261,6 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
263
261
  return { sheets, module_main_sheet, modules, design_blocks };
264
262
  }
265
263
 
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
264
  // src/utils/gen_empty_sch.ts
273
265
  var import_utils3 = require("@modular-circuit/utils");
274
266
  var gen_empty_sch = async (name) => {
@@ -2608,16 +2600,24 @@ var import_perc = require("@modular-circuit/perc");
2608
2600
  var import_utils16 = require("@modular-circuit/utils");
2609
2601
  async function do_convert_graph_to_kicad_project(ctx) {
2610
2602
  const module_ids = [];
2603
+ const generated_sheets = {};
2611
2604
  for (const sch of Object.values(ctx.schematics)) {
2612
2605
  for (const mod of sch.blocks ?? []) {
2613
- if (!(0, import_ir5.block_is_abstract)(mod) && (0, import_ir5.block_is_associated_with_concrete_module)(mod.type)) {
2614
- module_ids.push(mod.type);
2606
+ if (!(0, import_ir5.block_is_abstract)(mod)) {
2607
+ if ((0, import_ir5.block_is_associated_with_concrete_module)(mod.type)) module_ids.push(mod.type);
2608
+ } else {
2609
+ if (ctx.netlist_transpiler && (0, import_ir5.block_is_resolved_abstract)(mod)) {
2610
+ const sheet_file_name = (0, import_utils16.fmt_abstract_sch_name)(mod);
2611
+ const netlist2 = mod.netlist;
2612
+ generated_sheets[sheet_file_name] = await ctx.netlist_transpiler.convert_netlist_to_kicad(netlist2);
2613
+ }
2615
2614
  }
2616
2615
  }
2617
2616
  }
2618
2617
  const { sheets } = {
2619
2618
  ...await collect_sub_sheets(ctx.project.dependencies, ctx.module_resolver),
2620
- ...await collect_sub_sheets_by_id(module_ids, ctx.module_resolver)
2619
+ ...await collect_sub_sheets_by_id(module_ids, ctx.module_resolver),
2620
+ ...{ sheets: generated_sheets }
2621
2621
  };
2622
2622
  const netlist = new GraphConverter({
2623
2623
  ...ctx
@@ -2626,7 +2626,7 @@ async function do_convert_graph_to_kicad_project(ctx) {
2626
2626
  for (const sheet of sch.sheet_symbols) {
2627
2627
  const original_st_fn = sheet.sheet_file_name;
2628
2628
  if (!(original_st_fn in sheets)) {
2629
- const placeholder_fn = fmt_module_place_holder_sch_name(sheet.sheet_name);
2629
+ const placeholder_fn = (0, import_utils16.fmt_module_place_holder_sch_name)(sheet.sheet_name);
2630
2630
  sheet.sheet_file_name = placeholder_fn;
2631
2631
  sheets[placeholder_fn] = await gen_empty_sch(placeholder_fn);
2632
2632
  }
@@ -3097,8 +3097,6 @@ async function convert_graph_to_kicad_project(ctx) {
3097
3097
  convert_graph_to_kicad_project,
3098
3098
  convert_graph_to_sheets,
3099
3099
  filterNullOrUndefined,
3100
- fmt_module_place_holder_sch_name,
3101
- fmt_to_valid_filename,
3102
3100
  gen_empty_sch,
3103
3101
  gen_lib_gnd,
3104
3102
  gen_lib_vcc,
package/dist/index.mjs CHANGED
@@ -217,12 +217,6 @@ async function collect_sub_sheets_by_id(module_ids, module_resolver) {
217
217
  return { sheets, module_main_sheet, modules, design_blocks };
218
218
  }
219
219
 
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
220
  // src/utils/gen_empty_sch.ts
227
221
  import { gen_uuid } from "@modular-circuit/utils";
228
222
  var gen_empty_sch = async (name) => {
@@ -2574,22 +2568,35 @@ var NetListConverter = class {
2574
2568
  import {
2575
2569
  MODULAR_CIRCUIT_SCH_EXT as MODULAR_CIRCUIT_SCH_EXT2,
2576
2570
  block_is_abstract,
2577
- block_is_associated_with_concrete_module
2571
+ block_is_associated_with_concrete_module,
2572
+ block_is_resolved_abstract
2578
2573
  } from "@modular-circuit/ir";
2579
2574
  import { build_connection_graph } from "@modular-circuit/perc";
2580
- import { KiCadSchematicFileExtension as KiCadSchematicFileExtension3 } from "@modular-circuit/utils";
2575
+ import {
2576
+ fmt_abstract_sch_name,
2577
+ fmt_module_place_holder_sch_name,
2578
+ KiCadSchematicFileExtension as KiCadSchematicFileExtension3
2579
+ } from "@modular-circuit/utils";
2581
2580
  async function do_convert_graph_to_kicad_project(ctx) {
2582
2581
  const module_ids = [];
2582
+ const generated_sheets = {};
2583
2583
  for (const sch of Object.values(ctx.schematics)) {
2584
2584
  for (const mod of sch.blocks ?? []) {
2585
- if (!block_is_abstract(mod) && block_is_associated_with_concrete_module(mod.type)) {
2586
- module_ids.push(mod.type);
2585
+ if (!block_is_abstract(mod)) {
2586
+ if (block_is_associated_with_concrete_module(mod.type)) module_ids.push(mod.type);
2587
+ } else {
2588
+ if (ctx.netlist_transpiler && block_is_resolved_abstract(mod)) {
2589
+ const sheet_file_name = fmt_abstract_sch_name(mod);
2590
+ const netlist2 = mod.netlist;
2591
+ generated_sheets[sheet_file_name] = await ctx.netlist_transpiler.convert_netlist_to_kicad(netlist2);
2592
+ }
2587
2593
  }
2588
2594
  }
2589
2595
  }
2590
2596
  const { sheets } = {
2591
2597
  ...await collect_sub_sheets(ctx.project.dependencies, ctx.module_resolver),
2592
- ...await collect_sub_sheets_by_id(module_ids, ctx.module_resolver)
2598
+ ...await collect_sub_sheets_by_id(module_ids, ctx.module_resolver),
2599
+ ...{ sheets: generated_sheets }
2593
2600
  };
2594
2601
  const netlist = new GraphConverter({
2595
2602
  ...ctx
@@ -3073,8 +3080,6 @@ export {
3073
3080
  convert_graph_to_kicad_project,
3074
3081
  convert_graph_to_sheets,
3075
3082
  filterNullOrUndefined,
3076
- fmt_module_place_holder_sch_name,
3077
- fmt_to_valid_filename,
3078
3083
  gen_empty_sch,
3079
3084
  gen_lib_gnd,
3080
3085
  gen_lib_vcc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-circuit/transpiler",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
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/ir": "0.2.10",
33
- "@modular-circuit/electronics-model": "0.2.12",
34
- "@modular-circuit/perc": "0.2.18",
35
- "@modular-circuit/utils": "0.2.10"
32
+ "@modular-circuit/electronics-model": "0.2.14",
33
+ "@modular-circuit/ir": "0.2.12",
34
+ "@modular-circuit/utils": "0.2.12",
35
+ "@modular-circuit/genai": "0.1.10",
36
+ "@modular-circuit/perc": "0.2.20"
36
37
  },
37
38
  "scripts": {
38
39
  "clean": "rimraf dist",