@modular-circuit/transpiler 0.0.85 → 0.0.87
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/build/builder/graph_to_kicad/do_convert_graph_to_kicad_project.js +1 -3
- package/build/converter/netlist_to_kicad/netlist_converter.d.ts +1 -1
- package/build/converter/netlist_to_kicad/netlist_converter.d.ts.map +1 -1
- package/build/converter/netlist_to_kicad/netlist_converter.js +104 -197
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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()) {
|
|
@@ -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():
|
|
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;
|
|
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;AAYtD,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;IA8CnC,OAAO,CAAC,oBAAoB;IAqC5B,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,10 +31,9 @@ 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 {
|
|
71
|
-
import { BLOCK_PIN_GAP, FONT_SIZE,
|
|
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
|
-
import { place_blocks } from './place_blocks';
|
|
74
37
|
var NetListConverter = /** @class */ (function () {
|
|
75
38
|
function NetListConverter(ctx) {
|
|
76
39
|
var e_1, _a, e_2, _b;
|
|
@@ -111,48 +74,24 @@ var NetListConverter = /** @class */ (function () {
|
|
|
111
74
|
return this.net_name[id];
|
|
112
75
|
};
|
|
113
76
|
NetListConverter.prototype.convert_to_kicad = function () {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
_d = all_sch;
|
|
133
|
-
_e = k;
|
|
134
|
-
return [4 /*yield*/, this.convert_sch(k, v)];
|
|
135
|
-
case 3:
|
|
136
|
-
_d[_e] = _g.sent();
|
|
137
|
-
_g.label = 4;
|
|
138
|
-
case 4:
|
|
139
|
-
_b = _a.next();
|
|
140
|
-
return [3 /*break*/, 2];
|
|
141
|
-
case 5: return [3 /*break*/, 8];
|
|
142
|
-
case 6:
|
|
143
|
-
e_3_1 = _g.sent();
|
|
144
|
-
e_3 = { error: e_3_1 };
|
|
145
|
-
return [3 /*break*/, 8];
|
|
146
|
-
case 7:
|
|
147
|
-
try {
|
|
148
|
-
if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
|
|
149
|
-
}
|
|
150
|
-
finally { if (e_3) throw e_3.error; }
|
|
151
|
-
return [7 /*endfinally*/];
|
|
152
|
-
case 8: return [2 /*return*/, all_sch];
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
});
|
|
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;
|
|
156
95
|
};
|
|
157
96
|
/**
|
|
158
97
|
* Convert a schematic to a kicad schematic
|
|
@@ -162,128 +101,96 @@ var NetListConverter = /** @class */ (function () {
|
|
|
162
101
|
* @returns
|
|
163
102
|
*/
|
|
164
103
|
NetListConverter.prototype.convert_sch = function (name, schematic) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
(_k = sch.lib_symbols) === null || _k === void 0 ? void 0 : _k.symbols.push(gen_lib_gnd(it_2.value));
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
powers.add(it_2.value);
|
|
209
|
-
this.convert_pwr_symbol(it_2, get_power_pos(this.sheet_pwr_count++), sch);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
214
|
-
finally {
|
|
215
|
-
try {
|
|
216
|
-
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
217
|
-
}
|
|
218
|
-
finally { if (e_4) throw e_4.error; }
|
|
219
|
-
}
|
|
220
|
-
sheet_names_count = new Map();
|
|
221
|
-
ordered_sheets = schematic.sheet_symbols.sort(function (a, b) {
|
|
222
|
-
return b.pins.length - a.pins.length;
|
|
223
|
-
});
|
|
224
|
-
sheet_bounding_boxes = {};
|
|
225
|
-
sheet_size = {};
|
|
226
|
-
try {
|
|
227
|
-
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()) {
|
|
228
|
-
it_3 = ordered_sheets_1_1.value;
|
|
229
|
-
sheet_padding = this.get_sheet_symbol_lb_padding(it_3);
|
|
230
|
-
block_geo = this.block_calc.get_block_geometry(sheet_padding);
|
|
231
|
-
sheet_bounding_boxes[it_3.uuid] = {
|
|
232
|
-
x: block_geo.box.size.x / GRID_SIZE,
|
|
233
|
-
y: block_geo.box.size.y / GRID_SIZE,
|
|
234
|
-
};
|
|
235
|
-
sheet_size[it_3.uuid] = block_geo.box.size;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
239
|
-
finally {
|
|
240
|
-
try {
|
|
241
|
-
if (ordered_sheets_1_1 && !ordered_sheets_1_1.done && (_f = ordered_sheets_1.return)) _f.call(ordered_sheets_1);
|
|
242
|
-
}
|
|
243
|
-
finally { if (e_5) throw e_5.error; }
|
|
244
|
-
}
|
|
245
|
-
sheet_pos = place_blocks(sheet_bounding_boxes, 1, DEFAULT_PAPER_SIZE.width / GRID_SIZE);
|
|
246
|
-
try {
|
|
247
|
-
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()) {
|
|
248
|
-
it_4 = ordered_sheets_2_1.value;
|
|
249
|
-
scaled_pos = sheet_pos[it_4.uuid];
|
|
250
|
-
this.convert_sheet_symbol(it_4, {
|
|
251
|
-
pos: {
|
|
252
|
-
x: scaled_pos.x * GRID_SIZE,
|
|
253
|
-
y: scaled_pos.y * GRID_SIZE,
|
|
254
|
-
},
|
|
255
|
-
size: sheet_size[it_4.uuid],
|
|
256
|
-
}, sch, sheet_names_count);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
260
|
-
finally {
|
|
261
|
-
try {
|
|
262
|
-
if (ordered_sheets_2_1 && !ordered_sheets_2_1.done && (_g = ordered_sheets_2.return)) _g.call(ordered_sheets_2);
|
|
263
|
-
}
|
|
264
|
-
finally { if (e_6) throw e_6.error; }
|
|
265
|
-
}
|
|
266
|
-
try {
|
|
267
|
-
for (_c = __values(schematic.hiera_labels), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
268
|
-
it_5 = _d.value;
|
|
269
|
-
this.convert_hierarchical_label(it_5, sch);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
273
|
-
finally {
|
|
274
|
-
try {
|
|
275
|
-
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;
|
|
276
144
|
}
|
|
277
|
-
|
|
145
|
+
powers.add(it_2.value);
|
|
146
|
+
this.convert_pwr_symbol(it_2, get_power_pos(this.sheet_pwr_count++), sch);
|
|
278
147
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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;
|
|
282
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;
|
|
283
191
|
};
|
|
284
192
|
NetListConverter.prototype.convert_hierarchical_label = function (pin, sch) {
|
|
285
193
|
var _a;
|
|
286
|
-
// FIXME: layout them in the Yoga layout
|
|
287
194
|
var pin_pos = this.block_calc.get_block_geometry({
|
|
288
195
|
internal: { l_side: 0, r_side: 0 },
|
|
289
196
|
outer: { l_side: 0, r_side: 0 },
|