@modular-circuit/transpiler 0.0.94 → 0.0.96

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.
@@ -87,7 +87,9 @@ export function do_convert_graph_to_kicad_project(ctx) {
87
87
  case 1:
88
88
  sheets = (_e.sent()).sheets;
89
89
  netlist = new GraphConverter(__assign({}, ctx)).convert_to_netlist();
90
- converted_sheets = new NetListConverter(__assign(__assign({}, ctx), { netlist: netlist })).convert_to_kicad();
90
+ return [4 /*yield*/, new NetListConverter(__assign(__assign({}, ctx), { netlist: netlist })).convert_to_kicad()];
91
+ case 2:
92
+ converted_sheets = _e.sent();
91
93
  sexpr_printer = new SCHEMATIC_PRINTER();
92
94
  try {
93
95
  for (_a = __values(Object.entries(converted_sheets)), _b = _a.next(); !_b.done; _b = _a.next()) {
@@ -1,4 +1,4 @@
1
- import type { BOX2 } from '@modular-circuit/electronics-model';
1
+ import type { BOX2, VECTOR2 } from '@modular-circuit/electronics-model';
2
2
  export declare const GRID_SIZE: number;
3
3
  export declare const FONT_SIZE: number;
4
4
  export declare function get_power_pos(pwr_number: number): {
@@ -21,14 +21,18 @@ export interface BoxGeometry {
21
21
  box: BOX2;
22
22
  bounding_box: BOX2;
23
23
  }
24
+ export interface BlockSize {
25
+ size: VECTOR2;
26
+ bounding_size: VECTOR2;
27
+ }
24
28
  export declare class Layout {
25
29
  private width;
26
30
  private height;
27
31
  private max_height;
28
- private current_row_index;
29
- private current_row_items;
30
- private flush_row;
31
- get_block_geometry(factor: BlockLabelPadding): BoxGeometry;
32
- finalize(): void;
32
+ private block_geo;
33
+ private elk;
34
+ add_block(id: string, factor: BlockLabelPadding): void;
35
+ finalize(): Promise<Record<string, BOX2>>;
36
+ private calc_block_size;
33
37
  }
34
38
  //# sourceMappingURL=layout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/converter/netlist_to_kicad/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAA;AAI9D,eAAO,MAAM,SAAS,QAAiB,CAAA;AAEvC,eAAO,MAAM,SAAS,QAAY,CAAA;AAQlC,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM;;;EAE/C;AAKD,eAAO,MAAM,aAAa,QAAgB,CAAA;AAE1C,eAAO,MAAM,mBAAmB,QAAgB,CAAA;AAQhD,eAAO,MAAM,YAAY,QAAY,CAAA;AAErC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,YAAY,CAAA;IACtB,KAAK,EAAE,YAAY,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,IAAI,CAAA;IACT,YAAY,EAAE,IAAI,CAAA;CACnB;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,MAAM,CAAgB;IAE9B,OAAO,CAAC,UAAU,CAAI;IAEtB,OAAO,CAAC,iBAAiB,CAAI;IAC7B,OAAO,CAAC,iBAAiB,CAA0C;IAEnE,OAAO,CAAC,SAAS;IAwBV,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW;IA4C1D,QAAQ;CAGhB"}
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/converter/netlist_to_kicad/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAA;AAMvE,eAAO,MAAM,SAAS,QAAiB,CAAA;AAEvC,eAAO,MAAM,SAAS,QAAY,CAAA;AAQlC,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM;;;EAE/C;AAKD,eAAO,MAAM,aAAa,QAAgB,CAAA;AAE1C,eAAO,MAAM,mBAAmB,QAAgB,CAAA;AAQhD,eAAO,MAAM,YAAY,QAAY,CAAA;AAErC,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,YAAY,CAAA;IACtB,KAAK,EAAE,YAAY,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,IAAI,CAAA;IACT,YAAY,EAAE,IAAI,CAAA;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,OAAO,CAAA;IACb,aAAa,EAAE,OAAO,CAAA;CACvB;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,KAAK,CAAgB;IAE7B,OAAO,CAAC,MAAM,CAAgB;IAE9B,OAAO,CAAC,UAAU,CAAI;IAEtB,OAAO,CAAC,SAAS,CAAkC;IAEnD,OAAO,CAAC,GAAG,CAAY;IAEhB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;IAIzC,QAAQ;IAwDrB,OAAO,CAAC,eAAe;CAoDxB"}
@@ -1,3 +1,50 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __values = (this && this.__values) || function(o) {
38
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
+ if (m) return m.call(o);
40
+ if (o && typeof o.length === "number") return {
41
+ next: function () {
42
+ if (o && i >= o.length) o = void 0;
43
+ return { value: o && o[i++], done: !o };
44
+ }
45
+ };
46
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
+ };
1
48
  var __read = (this && this.__read) || function (o, n) {
2
49
  var m = typeof Symbol === "function" && o[Symbol.iterator];
3
50
  if (!m) return o;
@@ -14,26 +61,7 @@ var __read = (this && this.__read) || function (o, n) {
14
61
  }
15
62
  return ar;
16
63
  };
17
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
- if (ar || !(i in from)) {
20
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
- ar[i] = from[i];
22
- }
23
- }
24
- return to.concat(ar || Array.prototype.slice.call(from));
25
- };
26
- var __values = (this && this.__values) || function(o) {
27
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
28
- if (m) return m.call(o);
29
- if (o && typeof o.length === "number") return {
30
- next: function () {
31
- if (o && i >= o.length) o = void 0;
32
- return { value: o && o[i++], done: !o };
33
- }
34
- };
35
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
36
- };
64
+ import ELK, {} from 'elkjs/lib/elk.bundled.js';
37
65
  import { PAPER_SIZE } from '../../utils/constraints';
38
66
  var MIL_TO_MM = 0.0254;
39
67
  export var GRID_SIZE = 50 * MIL_TO_MM;
@@ -44,7 +72,7 @@ var POWER_Y_STEP = 16 * GRID_SIZE;
44
72
  export function get_power_pos(pwr_number) {
45
73
  return { x: POWER_START_X, y: POWER_START_Y + POWER_Y_STEP * pwr_number };
46
74
  }
47
- var BLOCK_START_Y = GRID_SIZE;
75
+ var BLOCK_START_Y = 36 * GRID_SIZE;
48
76
  var BLOCK_START_X = BLOCK_START_Y;
49
77
  export var BLOCK_PIN_GAP = 4 * GRID_SIZE;
50
78
  export var BLOCK_PIN_TB_MARGIN = 2 * GRID_SIZE;
@@ -59,70 +87,130 @@ var Layout = /** @class */ (function () {
59
87
  this.width = BLOCK_START_X;
60
88
  this.height = BLOCK_START_Y;
61
89
  this.max_height = 0;
62
- this.current_row_index = 0;
63
- this.current_row_items = [];
90
+ this.block_geo = {};
91
+ this.elk = new ELK();
64
92
  }
65
- Layout.prototype.flush_row = function () {
66
- var e_1, _a;
67
- if (this.current_row_items.length === 0)
68
- return;
69
- // If this row is odd: apply right-to-left packing
70
- var rtl = this.current_row_index % 2 === 1;
71
- if (rtl) {
72
- // right-most limit
73
- var cursor = POWER_START_X - BLOCK_MARGIN_RIGHT;
74
- try {
75
- for (var _b = __values(__spreadArray([], __read(this.current_row_items), false).reverse()), _c = _b.next(); !_c.done; _c = _b.next()) {
76
- var item = _c.value;
77
- var w = item.bounding_box.size.x;
78
- cursor -= w;
79
- item.box.pos.x = cursor;
80
- item.bounding_box.pos.x = cursor;
81
- cursor -= BLOCK_MARGIN_LEFT;
82
- }
83
- }
84
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
85
- finally {
86
- try {
87
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
93
+ Layout.prototype.add_block = function (id, factor) {
94
+ this.block_geo[id] = this.calc_block_size(factor);
95
+ };
96
+ Layout.prototype.finalize = function () {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var bbox, graph, _a, _b, _c, id, geo, bounding_size, res, _d, _e, child, geo, pos, block_offset, final_pos;
99
+ var e_1, _f, e_2, _g;
100
+ var _h, _j;
101
+ return __generator(this, function (_k) {
102
+ switch (_k.label) {
103
+ case 0:
104
+ bbox = {};
105
+ graph = {
106
+ id: 'root',
107
+ layoutOptions: {
108
+ 'elk.algorithm': 'box',
109
+ 'elk.contentAlignment': 'H_LEFT | V_TOP',
110
+ 'elk.fixedGraphSize': 'true',
111
+ 'elk.spacing.nodeNode': "".concat(GRID_SIZE),
112
+ 'elk.padding': "[top=".concat(GRID_SIZE, ",left=").concat(GRID_SIZE, ",bottom=").concat(GRID_SIZE, ",right=").concat(GRID_SIZE, "]"),
113
+ 'elk.childAreaWidth': "".concat(PAPER_SIZE.A4.width * MIL_TO_MM - GRID_SIZE * 2),
114
+ 'elk.childAreaHeight': "".concat(PAPER_SIZE.A4.height * MIL_TO_MM - GRID_SIZE * 2),
115
+ },
116
+ children: [],
117
+ edges: [],
118
+ };
119
+ try {
120
+ for (_a = __values(Object.entries(this.block_geo)), _b = _a.next(); !_b.done; _b = _a.next()) {
121
+ _c = __read(_b.value, 2), id = _c[0], geo = _c[1];
122
+ bounding_size = geo.bounding_box.size;
123
+ graph.children.push({
124
+ id: id,
125
+ width: bounding_size.x,
126
+ height: bounding_size.y,
127
+ });
128
+ }
129
+ }
130
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
131
+ finally {
132
+ try {
133
+ if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
134
+ }
135
+ finally { if (e_1) throw e_1.error; }
136
+ }
137
+ return [4 /*yield*/, this.elk.layout(graph)];
138
+ case 1:
139
+ res = _k.sent();
140
+ if (res.children) {
141
+ try {
142
+ for (_d = __values(res.children), _e = _d.next(); !_e.done; _e = _d.next()) {
143
+ child = _e.value;
144
+ geo = this.block_geo[child.id];
145
+ pos = {
146
+ x: (_h = child.x) !== null && _h !== void 0 ? _h : 0,
147
+ y: (_j = child.y) !== null && _j !== void 0 ? _j : 0,
148
+ };
149
+ block_offset = {
150
+ x: geo.bounding_box.pos.x - geo.box.pos.x,
151
+ y: geo.bounding_box.pos.y - geo.box.pos.y,
152
+ };
153
+ final_pos = {
154
+ x: pos.x - block_offset.x,
155
+ y: pos.y - block_offset.y,
156
+ };
157
+ bbox[child.id] = {
158
+ pos: final_pos,
159
+ size: geo.box.size,
160
+ };
161
+ }
162
+ }
163
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
164
+ finally {
165
+ try {
166
+ if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
167
+ }
168
+ finally { if (e_2) throw e_2.error; }
169
+ }
170
+ }
171
+ return [2 /*return*/, bbox];
88
172
  }
89
- finally { if (e_1) throw e_1.error; }
90
- }
91
- }
92
- // row finished → move to next
93
- this.current_row_items = [];
94
- this.current_row_index++;
173
+ });
174
+ });
95
175
  };
96
- Layout.prototype.get_block_geometry = function (factor) {
176
+ Layout.prototype.calc_block_size = function (factor) {
97
177
  var block_height = Math.floor(factor.total_pin_num / 2) * BLOCK_PIN_GAP + 2 * BLOCK_PIN_TB_MARGIN;
98
178
  var block_width = Math.max(MIN_BLOCK_WIDTH, factor.internal.l_side + factor.internal.r_side + INTERNAL_LABEL_MARGIN);
99
- var block_bounding_width = Math.max(block_width, factor.internal.l_side + factor.internal.r_side + factor.outer.l_side + factor.outer.r_side + WIRE_PADDING * 4);
179
+ var block_bounding_width = Math.max(block_width, factor.internal.l_side +
180
+ factor.internal.r_side +
181
+ factor.outer.l_side +
182
+ factor.outer.r_side +
183
+ // | txt | | txt |
184
+ WIRE_PADDING * 4);
100
185
  var box = {
101
- pos: { x: this.width, y: this.height },
102
- size: { x: block_width, y: block_height },
186
+ pos: {
187
+ x: this.width,
188
+ y: this.height,
189
+ },
190
+ size: {
191
+ x: block_width,
192
+ y: block_height,
193
+ },
103
194
  };
104
195
  var bounding_box = {
105
- pos: { x: this.width, y: this.height },
106
- size: { x: block_bounding_width, y: block_height },
196
+ pos: {
197
+ x: this.width,
198
+ y: this.height,
199
+ },
200
+ size: {
201
+ x: block_bounding_width,
202
+ y: block_height,
203
+ },
107
204
  };
108
- this.current_row_items.push({ box: box, bounding_box: bounding_box });
109
205
  this.max_height = Math.max(this.max_height, block_height);
110
- // compute next X
111
206
  this.width += block_bounding_width + BLOCK_MARGIN_LEFT;
112
- // Row break?
113
207
  if (this.width + BLOCK_MARGIN_RIGHT + MIN_BLOCK_WIDTH + BLOCK_MARGIN_LEFT > POWER_START_X) {
114
- this.flush_row();
115
- // reset for next row
116
208
  this.width = BLOCK_START_X;
117
209
  this.height += this.max_height + BLOCK_MARGIN_TOP;
118
210
  this.max_height = 0;
119
211
  }
120
212
  return { box: box, bounding_box: bounding_box };
121
213
  };
122
- // When all blocks processed, call this
123
- Layout.prototype.finalize = function () {
124
- this.flush_row();
125
- };
126
214
  return Layout;
127
215
  }());
128
216
  export { Layout };
@@ -9,7 +9,7 @@ export declare class NetListConverter {
9
9
  constructor(ctx: NetlistToKicadContext);
10
10
  pin_is_connected(id: string): boolean;
11
11
  get_pin_net_name(id: string): string;
12
- convert_to_kicad(): Record<string, SCHEMATIC>;
12
+ convert_to_kicad(): Promise<Record<string, SCHEMATIC>>;
13
13
  /**
14
14
  * Convert a schematic to a kicad schematic
15
15
  * @param name The name of the graph ,also the file name of the converted schematic
@@ -1 +1 @@
1
- {"version":3,"file":"netlist_converter.d.ts","sourceRoot":"","sources":["../../../src/converter/netlist_to_kicad/netlist_converter.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,SAAS,EAGf,MAAM,qBAAqB,CAAA;AAM5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AAatD,qBAAa,gBAAgB;IASR,OAAO,CAAC,GAAG;IAR9B,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO,CAAC,eAAe,CAAI;IAE3B,OAAO,CAAC,QAAQ,CAA6B;IAE7C,OAAO,CAAC,KAAK,CAAiB;gBAEH,GAAG,EAAE,qBAAqB;IAQrD,gBAAgB,CAAC,EAAE,EAAE,MAAM;IAI3B,gBAAgB,CAAC,EAAE,EAAE,MAAM;IAIpB,gBAAgB;IAYvB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IAgEnB,OAAO,CAAC,0BAA0B;IAYlC,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,2BAA2B;IA+CnC,OAAO,CAAC,oBAAoB;IAsC5B,OAAO,CAAC,iBAAiB;IAgCzB,OAAO,CAAC,iBAAiB;CAQ1B"}
1
+ {"version":3,"file":"netlist_converter.d.ts","sourceRoot":"","sources":["../../../src/converter/netlist_to_kicad/netlist_converter.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,SAAS,EAGf,MAAM,qBAAqB,CAAA;AAM5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AAmBtD,qBAAa,gBAAgB;IASR,OAAO,CAAC,GAAG;IAR9B,OAAO,CAAC,UAAU,CAAS;IAE3B,OAAO,CAAC,eAAe,CAAI;IAE3B,OAAO,CAAC,QAAQ,CAA6B;IAE7C,OAAO,CAAC,KAAK,CAAiB;gBAEH,GAAG,EAAE,qBAAqB;IAQrD,gBAAgB,CAAC,EAAE,EAAE,MAAM;IAI3B,gBAAgB,CAAC,EAAE,EAAE,MAAM;IAId,gBAAgB;IAY7B;;;;;;OAMG;YACW,WAAW;IAwEzB,OAAO,CAAC,0BAA0B;IAMlC,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,2BAA2B;IA+CnC,OAAO,CAAC,oBAAoB;IAsC5B,OAAO,CAAC,iBAAiB;IAgCzB,OAAO,CAAC,iBAAiB;CAQ1B"}
@@ -1,3 +1,39 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
1
37
  var __values = (this && this.__values) || function(o) {
2
38
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
39
  if (m) return m.call(o);
@@ -34,6 +70,11 @@ import { gen_lib_gnd, gen_lib_vcc, gen_sch_gnd, gen_sch_vcc } from '../../kicad/
34
70
  import { GENERATOR_NAME, GENERATOR_VERSION, SCH_VERSION } from '../../utils/constraints';
35
71
  import { BLOCK_PIN_GAP, BLOCK_PIN_TB_MARGIN, FONT_SIZE, Layout, WIRE_PADDING, get_power_pos, } from './layout';
36
72
  import { gen_wire } from '../../kicad/wire/gen_wire';
73
+ var H_LABEL_FACTOR = {
74
+ internal: { l_side: 0, r_side: 0 },
75
+ outer: { l_side: 0, r_side: 0 },
76
+ total_pin_num: 1,
77
+ };
37
78
  var NetListConverter = /** @class */ (function () {
38
79
  function NetListConverter(ctx) {
39
80
  var e_1, _a, e_2, _b;
@@ -74,24 +115,47 @@ var NetListConverter = /** @class */ (function () {
74
115
  return this.net_name[id];
75
116
  };
76
117
  NetListConverter.prototype.convert_to_kicad = function () {
77
- var e_3, _a;
78
- var all_sch = {};
79
- try {
80
- for (var _b = __values(Object.entries(this.ctx.netlist.schematics)), _c = _b.next(); !_c.done; _c = _b.next()) {
81
- var _d = __read(_c.value, 2), k = _d[0], v = _d[1];
82
- this.sheet_pwr_count = 0;
83
- this.block_calc = new Layout();
84
- all_sch[k] = this.convert_sch(k, v);
85
- }
86
- }
87
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
88
- finally {
89
- try {
90
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
91
- }
92
- finally { if (e_3) throw e_3.error; }
93
- }
94
- return all_sch;
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ var all_sch, _a, _b, _c, k, v, _d, _e, e_3_1;
120
+ var e_3, _f;
121
+ return __generator(this, function (_g) {
122
+ switch (_g.label) {
123
+ case 0:
124
+ all_sch = {};
125
+ _g.label = 1;
126
+ case 1:
127
+ _g.trys.push([1, 6, 7, 8]);
128
+ _a = __values(Object.entries(this.ctx.netlist.schematics)), _b = _a.next();
129
+ _g.label = 2;
130
+ case 2:
131
+ if (!!_b.done) return [3 /*break*/, 5];
132
+ _c = __read(_b.value, 2), k = _c[0], v = _c[1];
133
+ this.sheet_pwr_count = 0;
134
+ this.block_calc = new Layout();
135
+ _d = all_sch;
136
+ _e = k;
137
+ return [4 /*yield*/, this.convert_sch(k, v)];
138
+ case 3:
139
+ _d[_e] = _g.sent();
140
+ _g.label = 4;
141
+ case 4:
142
+ _b = _a.next();
143
+ return [3 /*break*/, 2];
144
+ case 5: return [3 /*break*/, 8];
145
+ case 6:
146
+ e_3_1 = _g.sent();
147
+ e_3 = { error: e_3_1 };
148
+ return [3 /*break*/, 8];
149
+ case 7:
150
+ try {
151
+ if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
152
+ }
153
+ finally { if (e_3) throw e_3.error; }
154
+ return [7 /*endfinally*/];
155
+ case 8: return [2 /*return*/, all_sch];
156
+ }
157
+ });
158
+ });
95
159
  };
96
160
  /**
97
161
  * Convert a schematic to a kicad schematic
@@ -101,103 +165,133 @@ var NetListConverter = /** @class */ (function () {
101
165
  * @returns
102
166
  */
103
167
  NetListConverter.prototype.convert_sch = function (name, schematic) {
104
- var e_4, _a, e_5, _b, e_6, _c;
105
- var _d, _e;
106
- var powers = new Set();
107
- this.wires = [];
108
- var sch = {
109
- version: SCH_VERSION,
110
- generator: GENERATOR_NAME,
111
- generator_version: GENERATOR_VERSION,
112
- paper: {
113
- size: 'A4',
114
- },
115
- title_block: {
116
- title: name.replace(".".concat(MODULAR_CIRCUIT_SCH_EXT), ''),
117
- date: replaceAll(new Date().toISOString().slice(0, 10), '-', '/'),
118
- rev: '1.0',
119
- comment: {
120
- 1: 'https://www.eda.cn',
121
- 2: this.ctx.project.author,
122
- 3: this.ctx.project.name,
123
- },
124
- },
125
- lib_symbols: {
126
- symbols: [],
127
- },
128
- uuid: schematic.uuid,
129
- symbols: [],
130
- labels: [],
131
- sheets: [],
132
- };
133
- try {
134
- for (var _f = __values(schematic.powers), _g = _f.next(); !_g.done; _g = _f.next()) {
135
- var it_2 = _g.value;
136
- if (!powers.has(it_2.value)) {
137
- switch (it_2.shape) {
138
- case PowerShape.VCC:
139
- (_d = sch.lib_symbols) === null || _d === void 0 ? void 0 : _d.symbols.push(gen_lib_vcc(it_2.value));
140
- break;
141
- case PowerShape.GND:
142
- (_e = sch.lib_symbols) === null || _e === void 0 ? void 0 : _e.symbols.push(gen_lib_gnd(it_2.value));
143
- break;
144
- }
145
- powers.add(it_2.value);
146
- this.convert_pwr_symbol(it_2, get_power_pos(this.sheet_pwr_count++), sch);
168
+ return __awaiter(this, void 0, void 0, function () {
169
+ var powers, sch, _a, _b, it_2, sheet_names_count, ordered_sheets, ordered_sheets_1, ordered_sheets_1_1, it_3, sheet_padding, _c, _d, it_4, res, ordered_sheets_2, ordered_sheets_2_1, it_5, _e, _f, it_6;
170
+ var e_4, _g, e_5, _h, e_6, _j, e_7, _k, e_8, _l;
171
+ var _m, _o;
172
+ return __generator(this, function (_p) {
173
+ switch (_p.label) {
174
+ case 0:
175
+ powers = new Set();
176
+ this.wires = [];
177
+ sch = {
178
+ version: SCH_VERSION,
179
+ generator: GENERATOR_NAME,
180
+ generator_version: GENERATOR_VERSION,
181
+ paper: {
182
+ size: 'A4',
183
+ },
184
+ title_block: {
185
+ title: name.replace(".".concat(MODULAR_CIRCUIT_SCH_EXT), ''),
186
+ date: replaceAll(new Date().toISOString().slice(0, 10), '-', '/'),
187
+ rev: '1.0',
188
+ comment: {
189
+ 1: 'https://www.eda.cn',
190
+ 2: this.ctx.project.author,
191
+ 3: this.ctx.project.name,
192
+ },
193
+ },
194
+ lib_symbols: {
195
+ symbols: [],
196
+ },
197
+ uuid: schematic.uuid,
198
+ symbols: [],
199
+ labels: [],
200
+ sheets: [],
201
+ };
202
+ try {
203
+ for (_a = __values(schematic.powers), _b = _a.next(); !_b.done; _b = _a.next()) {
204
+ it_2 = _b.value;
205
+ if (!powers.has(it_2.value)) {
206
+ switch (it_2.shape) {
207
+ case PowerShape.VCC:
208
+ (_m = sch.lib_symbols) === null || _m === void 0 ? void 0 : _m.symbols.push(gen_lib_vcc(it_2.value));
209
+ break;
210
+ case PowerShape.GND:
211
+ (_o = sch.lib_symbols) === null || _o === void 0 ? void 0 : _o.symbols.push(gen_lib_gnd(it_2.value));
212
+ break;
213
+ }
214
+ powers.add(it_2.value);
215
+ this.convert_pwr_symbol(it_2, get_power_pos(this.sheet_pwr_count++), sch);
216
+ }
217
+ }
218
+ }
219
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
220
+ finally {
221
+ try {
222
+ if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
223
+ }
224
+ finally { if (e_4) throw e_4.error; }
225
+ }
226
+ sheet_names_count = new Map();
227
+ ordered_sheets = schematic.sheet_symbols.sort(function (a, b) {
228
+ return b.pins.length - a.pins.length;
229
+ });
230
+ try {
231
+ for (ordered_sheets_1 = __values(ordered_sheets), ordered_sheets_1_1 = ordered_sheets_1.next(); !ordered_sheets_1_1.done; ordered_sheets_1_1 = ordered_sheets_1.next()) {
232
+ it_3 = ordered_sheets_1_1.value;
233
+ sheet_padding = this.get_sheet_symbol_lb_padding(it_3);
234
+ this.block_calc.add_block(it_3.uuid, sheet_padding);
235
+ }
236
+ }
237
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
238
+ finally {
239
+ try {
240
+ if (ordered_sheets_1_1 && !ordered_sheets_1_1.done && (_h = ordered_sheets_1.return)) _h.call(ordered_sheets_1);
241
+ }
242
+ finally { if (e_5) throw e_5.error; }
243
+ }
244
+ try {
245
+ for (_c = __values(schematic.hiera_labels), _d = _c.next(); !_d.done; _d = _c.next()) {
246
+ it_4 = _d.value;
247
+ this.block_calc.add_block(it_4.uuid, H_LABEL_FACTOR);
248
+ }
249
+ }
250
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
251
+ finally {
252
+ try {
253
+ if (_d && !_d.done && (_j = _c.return)) _j.call(_c);
254
+ }
255
+ finally { if (e_6) throw e_6.error; }
256
+ }
257
+ return [4 /*yield*/, this.block_calc.finalize()];
258
+ case 1:
259
+ res = _p.sent();
260
+ try {
261
+ for (ordered_sheets_2 = __values(ordered_sheets), ordered_sheets_2_1 = ordered_sheets_2.next(); !ordered_sheets_2_1.done; ordered_sheets_2_1 = ordered_sheets_2.next()) {
262
+ it_5 = ordered_sheets_2_1.value;
263
+ this.convert_sheet_symbol(it_5, res[it_5.uuid], sch, sheet_names_count);
264
+ }
265
+ }
266
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
267
+ finally {
268
+ try {
269
+ if (ordered_sheets_2_1 && !ordered_sheets_2_1.done && (_k = ordered_sheets_2.return)) _k.call(ordered_sheets_2);
270
+ }
271
+ finally { if (e_7) throw e_7.error; }
272
+ }
273
+ try {
274
+ for (_e = __values(schematic.hiera_labels), _f = _e.next(); !_f.done; _f = _e.next()) {
275
+ it_6 = _f.value;
276
+ this.convert_hierarchical_label(it_6, res[it_6.uuid], sch);
277
+ }
278
+ }
279
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
280
+ finally {
281
+ try {
282
+ if (_f && !_f.done && (_l = _e.return)) _l.call(_e);
283
+ }
284
+ finally { if (e_8) throw e_8.error; }
285
+ }
286
+ sch.wires = this.wires;
287
+ return [2 /*return*/, sch];
147
288
  }
148
- }
149
- }
150
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
151
- finally {
152
- try {
153
- if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
154
- }
155
- finally { if (e_4) throw e_4.error; }
156
- }
157
- var sheet_names_count = new Map();
158
- var ordered_sheets = schematic.sheet_symbols.sort(function (a, b) {
159
- return b.pins.length - a.pins.length;
289
+ });
160
290
  });
161
- try {
162
- for (var ordered_sheets_1 = __values(ordered_sheets), ordered_sheets_1_1 = ordered_sheets_1.next(); !ordered_sheets_1_1.done; ordered_sheets_1_1 = ordered_sheets_1.next()) {
163
- var it_3 = ordered_sheets_1_1.value;
164
- var sheet_padding = this.get_sheet_symbol_lb_padding(it_3);
165
- var block_geo = this.block_calc.get_block_geometry(sheet_padding);
166
- this.convert_sheet_symbol(it_3, block_geo.box, sch, sheet_names_count);
167
- }
168
- }
169
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
170
- finally {
171
- try {
172
- if (ordered_sheets_1_1 && !ordered_sheets_1_1.done && (_b = ordered_sheets_1.return)) _b.call(ordered_sheets_1);
173
- }
174
- finally { if (e_5) throw e_5.error; }
175
- }
176
- try {
177
- for (var _h = __values(schematic.hiera_labels), _j = _h.next(); !_j.done; _j = _h.next()) {
178
- var it_4 = _j.value;
179
- this.convert_hierarchical_label(it_4, sch);
180
- }
181
- }
182
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
183
- finally {
184
- try {
185
- if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
186
- }
187
- finally { if (e_6) throw e_6.error; }
188
- }
189
- this.block_calc.finalize();
190
- sch.wires = this.wires;
191
- return sch;
192
291
  };
193
- NetListConverter.prototype.convert_hierarchical_label = function (pin, sch) {
292
+ NetListConverter.prototype.convert_hierarchical_label = function (pin, bbox, sch) {
194
293
  var _a;
195
- var pin_pos = this.block_calc.get_block_geometry({
196
- internal: { l_side: 0, r_side: 0 },
197
- outer: { l_side: 0, r_side: 0 },
198
- total_pin_num: 1,
199
- }).box.pos;
200
- (_a = sch.labels) === null || _a === void 0 ? void 0 : _a.push(gen_hierarchical_label(pin.name, pin_pos, { horizontal: 'left', vertical: 'bottom' }, 0, pin.shape));
294
+ (_a = sch.labels) === null || _a === void 0 ? void 0 : _a.push(gen_hierarchical_label(pin.name, bbox.pos, { horizontal: 'left', vertical: 'bottom' }, 0, pin.shape));
201
295
  };
202
296
  NetListConverter.prototype.convert_pwr_symbol = function (pwr, at, sch) {
203
297
  // NOTE : The power uuid is used as the uuid of its pin ,cause all power symbols have only one pin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-circuit/transpiler",
3
- "version": "0.0.94",
3
+ "version": "0.0.96",
4
4
  "description": "Intermediate representation of the modular circuit",
5
5
  "main": "./build/index.js",
6
6
  "files": [
@@ -24,12 +24,13 @@
24
24
  "typescript": "^5.4.5"
25
25
  },
26
26
  "dependencies": {
27
+ "elkjs": "^0.11.0",
27
28
  "js-base64": "^3.7.7",
28
29
  "jszip": "^3.10.1",
29
30
  "@modular-circuit/electronics-model": "0.0.54",
30
31
  "@modular-circuit/ir": "0.0.63",
31
- "@modular-circuit/utils": "0.0.41",
32
- "@modular-circuit/perc": "0.0.61"
32
+ "@modular-circuit/perc": "0.0.61",
33
+ "@modular-circuit/utils": "0.0.41"
33
34
  },
34
35
  "scripts": {
35
36
  "clean": "rimraf build",