@modular-circuit/transpiler 0.0.95 → 0.0.97

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,10 +21,15 @@ 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
- private width;
26
- private height;
27
- private max_height;
28
- get_block_geometry(factor: BlockLabelPadding): BoxGeometry;
29
+ private block_geo;
30
+ private elk;
31
+ add_block(id: string, factor: BlockLabelPadding): void;
32
+ finalize(): Promise<Record<string, BOX2>>;
33
+ private calc_block_size;
29
34
  }
30
35
  //# 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;IAE7B,OAAO,CAAC,MAAM,CAAgB;IAE9B,OAAO,CAAC,UAAU,CAAI;IAEf,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW;CAoDlE"}
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;AASlC,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM;;;EAE/C;AAED,eAAO,MAAM,aAAa,QAAgB,CAAA;AAE1C,eAAO,MAAM,mBAAmB,QAAgB,CAAA;AAKhD,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,SAAS,CAAgC;IAEjD,OAAO,CAAC,GAAG,CAAY;IAEhB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;IAIzC,QAAQ;IA8CrB,OAAO,CAAC,eAAe;CAiCxB"}
@@ -1,3 +1,67 @@
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
+ };
48
+ var __read = (this && this.__read) || function (o, n) {
49
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
50
+ if (!m) return o;
51
+ var i = m.call(o), r, ar = [], e;
52
+ try {
53
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
54
+ }
55
+ catch (error) { e = { error: error }; }
56
+ finally {
57
+ try {
58
+ if (r && !r.done && (m = i["return"])) m.call(i);
59
+ }
60
+ finally { if (e) throw e.error; }
61
+ }
62
+ return ar;
63
+ };
64
+ import ELK, {} from 'elkjs/lib/elk.bundled.js';
1
65
  import { PAPER_SIZE } from '../../utils/constraints';
2
66
  var MIL_TO_MM = 0.0254;
3
67
  export var GRID_SIZE = 50 * MIL_TO_MM;
@@ -5,26 +69,97 @@ export var FONT_SIZE = GRID_SIZE;
5
69
  var POWER_START_Y = 30 * GRID_SIZE;
6
70
  var POWER_START_X = (PAPER_SIZE.A4.height - 30) * GRID_SIZE;
7
71
  var POWER_Y_STEP = 16 * GRID_SIZE;
72
+ var BLOCK_MARGIN_LEFT = 16 * GRID_SIZE;
73
+ var BLOCK_MARGIN_RIGHT = BLOCK_MARGIN_LEFT;
8
74
  export function get_power_pos(pwr_number) {
9
75
  return { x: POWER_START_X, y: POWER_START_Y + POWER_Y_STEP * pwr_number };
10
76
  }
11
- var BLOCK_START_Y = 36 * GRID_SIZE;
12
- var BLOCK_START_X = BLOCK_START_Y;
13
77
  export var BLOCK_PIN_GAP = 4 * GRID_SIZE;
14
78
  export var BLOCK_PIN_TB_MARGIN = 2 * GRID_SIZE;
15
- var BLOCK_MARGIN_TOP = 8 * GRID_SIZE;
16
79
  var MIN_BLOCK_WIDTH = 8 * GRID_SIZE;
17
- var BLOCK_MARGIN_LEFT = 16 * GRID_SIZE;
18
- var BLOCK_MARGIN_RIGHT = BLOCK_MARGIN_LEFT;
19
80
  var INTERNAL_LABEL_MARGIN = 8 * FONT_SIZE;
20
81
  export var WIRE_PADDING = GRID_SIZE;
21
82
  var Layout = /** @class */ (function () {
22
83
  function Layout() {
23
- this.width = BLOCK_START_X;
24
- this.height = BLOCK_START_Y;
25
- this.max_height = 0;
84
+ this.block_geo = {};
85
+ this.elk = new ELK();
26
86
  }
27
- Layout.prototype.get_block_geometry = function (factor) {
87
+ Layout.prototype.add_block = function (id, factor) {
88
+ this.block_geo[id] = this.calc_block_size(factor);
89
+ };
90
+ Layout.prototype.finalize = function () {
91
+ return __awaiter(this, void 0, void 0, function () {
92
+ var bbox, graph, _a, _b, _c, id, geo, bounding_size, res, _d, _e, child, geo, pos;
93
+ var e_1, _f, e_2, _g;
94
+ var _h, _j;
95
+ return __generator(this, function (_k) {
96
+ switch (_k.label) {
97
+ case 0:
98
+ bbox = {};
99
+ graph = {
100
+ id: 'root',
101
+ layoutOptions: {
102
+ 'elk.algorithm': 'box',
103
+ 'elk.contentAlignment': 'H_CENTER | V_CENTER',
104
+ 'elk.fixedGraphSize': 'true',
105
+ 'elk.spacing.nodeNode': "".concat(BLOCK_MARGIN_RIGHT + BLOCK_MARGIN_LEFT),
106
+ 'elk.padding': "[top=".concat(GRID_SIZE, ",left=").concat(GRID_SIZE, ",bottom=").concat(GRID_SIZE, ",right=").concat(GRID_SIZE, "]"),
107
+ 'elk.childAreaWidth': "".concat(PAPER_SIZE.A4.width * MIL_TO_MM - GRID_SIZE * 2),
108
+ 'elk.childAreaHeight': "".concat(PAPER_SIZE.A4.height * MIL_TO_MM - GRID_SIZE * 2),
109
+ },
110
+ children: [],
111
+ edges: [],
112
+ };
113
+ try {
114
+ for (_a = __values(Object.entries(this.block_geo)), _b = _a.next(); !_b.done; _b = _a.next()) {
115
+ _c = __read(_b.value, 2), id = _c[0], geo = _c[1];
116
+ bounding_size = geo.bounding_size;
117
+ graph.children.push({
118
+ id: id,
119
+ width: bounding_size.x,
120
+ height: bounding_size.y,
121
+ });
122
+ }
123
+ }
124
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
125
+ finally {
126
+ try {
127
+ if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
128
+ }
129
+ finally { if (e_1) throw e_1.error; }
130
+ }
131
+ return [4 /*yield*/, this.elk.layout(graph)];
132
+ case 1:
133
+ res = _k.sent();
134
+ if (res.children) {
135
+ try {
136
+ for (_d = __values(res.children), _e = _d.next(); !_e.done; _e = _d.next()) {
137
+ child = _e.value;
138
+ geo = this.block_geo[child.id];
139
+ pos = {
140
+ x: (_h = child.x) !== null && _h !== void 0 ? _h : 0,
141
+ y: (_j = child.y) !== null && _j !== void 0 ? _j : 0,
142
+ };
143
+ bbox[child.id] = {
144
+ pos: pos,
145
+ size: geo.size,
146
+ };
147
+ }
148
+ }
149
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
150
+ finally {
151
+ try {
152
+ if (_e && !_e.done && (_g = _d.return)) _g.call(_d);
153
+ }
154
+ finally { if (e_2) throw e_2.error; }
155
+ }
156
+ }
157
+ return [2 /*return*/, bbox];
158
+ }
159
+ });
160
+ });
161
+ };
162
+ Layout.prototype.calc_block_size = function (factor) {
28
163
  var block_height = Math.floor(factor.total_pin_num / 2) * BLOCK_PIN_GAP + 2 * BLOCK_PIN_TB_MARGIN;
29
164
  var block_width = Math.max(MIN_BLOCK_WIDTH, factor.internal.l_side + factor.internal.r_side + INTERNAL_LABEL_MARGIN);
30
165
  var block_bounding_width = Math.max(block_width, factor.internal.l_side +
@@ -33,34 +168,18 @@ var Layout = /** @class */ (function () {
33
168
  factor.outer.r_side +
34
169
  // | txt | | txt |
35
170
  WIRE_PADDING * 4);
36
- var box = {
37
- pos: {
38
- x: this.width,
39
- y: this.height,
40
- },
41
- size: {
42
- x: block_width,
43
- y: block_height,
44
- },
171
+ var size = {
172
+ x: block_width,
173
+ y: block_height,
45
174
  };
46
- var bounding_box = {
47
- pos: {
48
- x: this.width,
49
- y: this.height,
50
- },
51
- size: {
52
- x: block_bounding_width,
53
- y: block_height,
54
- },
175
+ var bounding_size = {
176
+ x: block_bounding_width,
177
+ y: block_height,
178
+ };
179
+ return {
180
+ size: size,
181
+ bounding_size: bounding_size,
55
182
  };
56
- this.max_height = Math.max(this.max_height, block_height);
57
- this.width += block_bounding_width + BLOCK_MARGIN_LEFT;
58
- if (this.width + BLOCK_MARGIN_RIGHT + MIN_BLOCK_WIDTH + BLOCK_MARGIN_LEFT > POWER_START_X) {
59
- this.width = BLOCK_START_X;
60
- this.height += this.max_height + BLOCK_MARGIN_TOP;
61
- this.max_height = 0;
62
- }
63
- return { box: box, bounding_box: bounding_box };
64
183
  };
65
184
  return Layout;
66
185
  }());
@@ -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;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
+ {"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);
@@ -32,8 +68,13 @@ import { gen_hierarchical_label, gen_net_label, gen_sheet_pin } from '../../kica
32
68
  import { gen_sch_sheet } from '../../kicad/sheet';
33
69
  import { gen_lib_gnd, gen_lib_vcc, gen_sch_gnd, gen_sch_vcc } from '../../kicad/symbols';
34
70
  import { GENERATOR_NAME, GENERATOR_VERSION, SCH_VERSION } from '../../utils/constraints';
35
- import { BLOCK_PIN_GAP, BLOCK_PIN_TB_MARGIN, FONT_SIZE, Layout, WIRE_PADDING, get_power_pos } from './layout';
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,102 +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
- sch.wires = this.wires;
190
- return sch;
191
291
  };
192
- NetListConverter.prototype.convert_hierarchical_label = function (pin, sch) {
292
+ NetListConverter.prototype.convert_hierarchical_label = function (pin, bbox, sch) {
193
293
  var _a;
194
- var pin_pos = this.block_calc.get_block_geometry({
195
- internal: { l_side: 0, r_side: 0 },
196
- outer: { l_side: 0, r_side: 0 },
197
- total_pin_num: 1,
198
- }).box.pos;
199
- (_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));
200
295
  };
201
296
  NetListConverter.prototype.convert_pwr_symbol = function (pwr, at, sch) {
202
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.95",
3
+ "version": "0.0.97",
4
4
  "description": "Intermediate representation of the modular circuit",
5
5
  "main": "./build/index.js",
6
6
  "files": [
@@ -24,6 +24,7 @@
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",