@modular-circuit/transpiler 0.0.86 → 0.0.88

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,9 +87,7 @@ 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
- return [4 /*yield*/, new NetListConverter(__assign(__assign({}, ctx), { netlist: netlist })).convert_to_kicad()];
91
- case 2:
92
- converted_sheets = _e.sent();
90
+ converted_sheets = new NetListConverter(__assign(__assign({}, ctx), { netlist: netlist })).convert_to_kicad();
93
91
  sexpr_printer = new SCHEMATIC_PRINTER();
94
92
  try {
95
93
  for (_a = __values(Object.entries(converted_sheets)), _b = _a.next(); !_b.done; _b = _a.next()) {
@@ -10,7 +10,7 @@ export function get_power_pos(pwr_number) {
10
10
  }
11
11
  var BLOCK_START_Y = 36 * GRID_SIZE;
12
12
  var BLOCK_START_X = BLOCK_START_Y;
13
- export var BLOCK_PIN_GAP = 3 * GRID_SIZE;
13
+ export var BLOCK_PIN_GAP = 4 * GRID_SIZE;
14
14
  var BLOCK_MARGIN_TOP = 8 * GRID_SIZE;
15
15
  var MIN_BLOCK_WIDTH = 8 * GRID_SIZE;
16
16
  var BLOCK_MARGIN_LEFT = 16 * GRID_SIZE;
@@ -24,7 +24,7 @@ var Layout = /** @class */ (function () {
24
24
  this.max_height = 0;
25
25
  }
26
26
  Layout.prototype.get_block_geometry = function (factor) {
27
- var block_height = (BLOCK_PIN_GAP * factor.total_pin_num) / 2 + BLOCK_PIN_GAP * 2;
27
+ var block_height = Math.ceil(factor.total_pin_num / 2) * BLOCK_PIN_GAP;
28
28
  var block_width = Math.max(MIN_BLOCK_WIDTH, factor.internal.l_side + factor.internal.r_side + INTERNAL_LABEL_MARGIN);
29
29
  var block_bounding_width = Math.max(block_width, factor.internal.l_side +
30
30
  factor.internal.r_side +
@@ -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(): Promise<Record<string, SCHEMATIC>>;
12
+ convert_to_kicad(): 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;IAId,gBAAgB;IAa7B;;;;;;OAMG;YACW,WAAW;IAsEzB,OAAO,CAAC,0BAA0B;IAYlC,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,2BAA2B;IA8CnC,OAAO,CAAC,oBAAoB;IAqC5B,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;AAKtD,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;IA+DnB,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,39 +1,3 @@
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
1
  var __values = (this && this.__values) || function(o) {
38
2
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
3
  if (m) return m.call(o);
@@ -67,8 +31,8 @@ import { replaceAll } from '@modular-circuit/utils';
67
31
  import { gen_hierarchical_label, gen_net_label, gen_sheet_pin } from '../../kicad/label';
68
32
  import { gen_sch_sheet } from '../../kicad/sheet';
69
33
  import { gen_lib_gnd, gen_lib_vcc, gen_sch_gnd, gen_sch_vcc } from '../../kicad/symbols';
70
- import { DEFAULT_PAPER_SIZE, GENERATOR_NAME, GENERATOR_VERSION, SCH_VERSION } from '../../utils/constraints';
71
- import { BLOCK_PIN_GAP, FONT_SIZE, GRID_SIZE, Layout, WIRE_PADDING, get_power_pos, } from './layout';
34
+ import { GENERATOR_NAME, GENERATOR_VERSION, SCH_VERSION } from '../../utils/constraints';
35
+ import { BLOCK_PIN_GAP, FONT_SIZE, Layout, WIRE_PADDING, get_power_pos } from './layout';
72
36
  import { gen_wire } from '../../kicad/wire/gen_wire';
73
37
  var NetListConverter = /** @class */ (function () {
74
38
  function NetListConverter(ctx) {
@@ -110,48 +74,24 @@ var NetListConverter = /** @class */ (function () {
110
74
  return this.net_name[id];
111
75
  };
112
76
  NetListConverter.prototype.convert_to_kicad = function () {
113
- return __awaiter(this, void 0, void 0, function () {
114
- var all_sch, _a, _b, _c, k, v, _d, _e, e_3_1;
115
- var e_3, _f;
116
- return __generator(this, function (_g) {
117
- switch (_g.label) {
118
- case 0:
119
- all_sch = {};
120
- _g.label = 1;
121
- case 1:
122
- _g.trys.push([1, 6, 7, 8]);
123
- _a = __values(Object.entries(this.ctx.netlist.schematics)), _b = _a.next();
124
- _g.label = 2;
125
- case 2:
126
- if (!!_b.done) return [3 /*break*/, 5];
127
- _c = __read(_b.value, 2), k = _c[0], v = _c[1];
128
- this.sheet_pwr_count = 0;
129
- this.block_calc = new Layout();
130
- this.wires = [];
131
- _d = all_sch;
132
- _e = k;
133
- return [4 /*yield*/, this.convert_sch(k, v)];
134
- case 3:
135
- _d[_e] = _g.sent();
136
- _g.label = 4;
137
- case 4:
138
- _b = _a.next();
139
- return [3 /*break*/, 2];
140
- case 5: return [3 /*break*/, 8];
141
- case 6:
142
- e_3_1 = _g.sent();
143
- e_3 = { error: e_3_1 };
144
- return [3 /*break*/, 8];
145
- case 7:
146
- try {
147
- if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
148
- }
149
- finally { if (e_3) throw e_3.error; }
150
- return [7 /*endfinally*/];
151
- case 8: return [2 /*return*/, all_sch];
152
- }
153
- });
154
- });
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;
155
95
  };
156
96
  /**
157
97
  * Convert a schematic to a kicad schematic
@@ -161,111 +101,93 @@ var NetListConverter = /** @class */ (function () {
161
101
  * @returns
162
102
  */
163
103
  NetListConverter.prototype.convert_sch = function (name, schematic) {
164
- return __awaiter(this, void 0, void 0, function () {
165
- var powers, sch, _a, _b, it_2, sheet_names_count, ordered_sheets, sheet_box, ordered_sheets_1, ordered_sheets_1_1, it_3, sheet_padding, block_geo, ordered_sheets_2, ordered_sheets_2_1, it_4, _c, _d, it_5;
166
- var e_4, _e, e_5, _f, e_6, _g, e_7, _h;
167
- var _j, _k;
168
- return __generator(this, function (_l) {
169
- powers = new Set();
170
- sch = {
171
- version: SCH_VERSION,
172
- generator: GENERATOR_NAME,
173
- generator_version: GENERATOR_VERSION,
174
- paper: {
175
- size: 'A4',
176
- },
177
- title_block: {
178
- title: name.replace(".".concat(MODULAR_CIRCUIT_SCH_EXT), ''),
179
- date: replaceAll(new Date().toISOString().slice(0, 10), '-', '/'),
180
- rev: '1.0',
181
- comment: {
182
- 1: 'https://www.eda.cn',
183
- 2: this.ctx.project.author,
184
- 3: this.ctx.project.name,
185
- },
186
- },
187
- lib_symbols: {
188
- symbols: [],
189
- },
190
- uuid: schematic.uuid,
191
- symbols: [],
192
- labels: [],
193
- sheets: [],
194
- };
195
- try {
196
- for (_a = __values(schematic.powers), _b = _a.next(); !_b.done; _b = _a.next()) {
197
- it_2 = _b.value;
198
- if (!powers.has(it_2.value)) {
199
- switch (it_2.shape) {
200
- case PowerShape.VCC:
201
- (_j = sch.lib_symbols) === null || _j === void 0 ? void 0 : _j.symbols.push(gen_lib_vcc(it_2.value));
202
- break;
203
- case PowerShape.GND:
204
- (_k = sch.lib_symbols) === null || _k === void 0 ? void 0 : _k.symbols.push(gen_lib_gnd(it_2.value));
205
- break;
206
- }
207
- powers.add(it_2.value);
208
- this.convert_pwr_symbol(it_2, get_power_pos(this.sheet_pwr_count++), sch);
209
- }
210
- }
211
- }
212
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
213
- finally {
214
- try {
215
- if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
216
- }
217
- finally { if (e_4) throw e_4.error; }
218
- }
219
- sheet_names_count = new Map();
220
- ordered_sheets = schematic.sheet_symbols.sort(function (a, b) {
221
- return b.pins.length - a.pins.length;
222
- });
223
- sheet_box = {};
224
- try {
225
- 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()) {
226
- it_3 = ordered_sheets_1_1.value;
227
- sheet_padding = this.get_sheet_symbol_lb_padding(it_3);
228
- block_geo = this.block_calc.get_block_geometry(sheet_padding);
229
- sheet_box[it_3.uuid] = block_geo.box;
230
- }
231
- }
232
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
233
- finally {
234
- try {
235
- if (ordered_sheets_1_1 && !ordered_sheets_1_1.done && (_f = ordered_sheets_1.return)) _f.call(ordered_sheets_1);
236
- }
237
- finally { if (e_5) throw e_5.error; }
238
- }
239
- try {
240
- 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()) {
241
- it_4 = ordered_sheets_2_1.value;
242
- this.convert_sheet_symbol(it_4, sheet_box[it_4.uuid], sch, sheet_names_count);
243
- }
244
- }
245
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
246
- finally {
247
- try {
248
- if (ordered_sheets_2_1 && !ordered_sheets_2_1.done && (_g = ordered_sheets_2.return)) _g.call(ordered_sheets_2);
249
- }
250
- finally { if (e_6) throw e_6.error; }
251
- }
252
- try {
253
- for (_c = __values(schematic.hiera_labels), _d = _c.next(); !_d.done; _d = _c.next()) {
254
- it_5 = _d.value;
255
- this.convert_hierarchical_label(it_5, sch);
256
- }
257
- }
258
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
259
- finally {
260
- try {
261
- if (_d && !_d.done && (_h = _c.return)) _h.call(_c);
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;
262
144
  }
263
- finally { if (e_7) throw e_7.error; }
145
+ powers.add(it_2.value);
146
+ this.convert_pwr_symbol(it_2, get_power_pos(this.sheet_pwr_count++), sch);
264
147
  }
265
- sch.wires = this.wires;
266
- return [2 /*return*/, sch];
267
- });
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;
268
160
  });
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
+ sch.wires = this.wires;
190
+ return sch;
269
191
  };
270
192
  NetListConverter.prototype.convert_hierarchical_label = function (pin, sch) {
271
193
  var _a;
@@ -298,8 +220,9 @@ var NetListConverter = /** @class */ (function () {
298
220
  total_pin_num: sheet_sym.pins.length,
299
221
  };
300
222
  var port_count = sheet_sym.pins.length;
223
+ var h_count = Math.ceil(port_count / 2);
301
224
  for (var i = 0; i < port_count; i++) {
302
- var is_left = i < port_count / 2;
225
+ var is_left = i < h_count;
303
226
  var cur_pin = sheet_sym.pins[i];
304
227
  if (is_left) {
305
228
  factor.internal.l_side = Math.max(factor.internal.l_side, cur_pin.name.length);
@@ -332,10 +255,11 @@ var NetListConverter = /** @class */ (function () {
332
255
  NetListConverter.prototype.convert_sheet_symbol = function (sheet_sym, rect, sch, sheet_names_count) {
333
256
  var port_count = sheet_sym.pins.length;
334
257
  var pins = [];
258
+ var h_count = Math.ceil(port_count / 2);
335
259
  for (var i = 0; i < port_count; i++) {
336
- var is_left = i < port_count / 2;
260
+ var is_left = i < h_count;
337
261
  var x = is_left ? rect.pos.x : rect.pos.x + rect.size.x;
338
- var y = rect.pos.y + BLOCK_PIN_GAP * ((i < port_count / 2 ? i : i - port_count / 2) + 1);
262
+ var y = rect.pos.y + BLOCK_PIN_GAP * Math.abs(i - h_count);
339
263
  var justify = is_left ? 'left' : 'right';
340
264
  var rotation = is_left ? 180 : 0;
341
265
  pins.push(this.convert_sheet_pin(sheet_sym.pins[i], { x: x, y: y }, sch, justify, rotation, is_left));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-circuit/transpiler",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "description": "Intermediate representation of the modular circuit",
5
5
  "main": "./build/index.js",
6
6
  "files": [
@@ -26,10 +26,10 @@
26
26
  "dependencies": {
27
27
  "js-base64": "^3.7.7",
28
28
  "jszip": "^3.10.1",
29
- "@modular-circuit/ir": "0.0.61",
30
- "@modular-circuit/perc": "0.0.61",
31
29
  "@modular-circuit/electronics-model": "0.0.54",
32
- "@modular-circuit/utils": "0.0.40"
30
+ "@modular-circuit/utils": "0.0.40",
31
+ "@modular-circuit/ir": "0.0.61",
32
+ "@modular-circuit/perc": "0.0.61"
33
33
  },
34
34
  "scripts": {
35
35
  "clean": "rimraf build",