@modular-circuit/transpiler 0.0.90 → 0.0.92

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.
@@ -75,7 +75,7 @@ var __read = (this && this.__read) || function (o, n) {
75
75
  import { MODULAR_CIRCUIT_SCH_EXT } from '@modular-circuit/ir';
76
76
  import { GraphConverter, SCHEMATIC_PRINTER, } from '../../converter';
77
77
  import { NetListConverter } from '../../converter/netlist_to_kicad';
78
- import { KiCadProjectAchieve, KiCadSchematicFileExtension } from '../../kicad/project';
78
+ import { KiCadProjectArchive, KiCadSchematicFileExtension } from '../../kicad/project';
79
79
  import { collect_sub_sheets } from '../../utils/collect_sub_sheets';
80
80
  export function do_convert_graph_to_kicad_project(ctx) {
81
81
  return __awaiter(this, void 0, void 0, function () {
@@ -105,7 +105,7 @@ export function do_convert_graph_to_kicad_project(ctx) {
105
105
  }
106
106
  finally { if (e_1) throw e_1.error; }
107
107
  }
108
- kicad_project = new KiCadProjectAchieve(ctx.project.name, __assign({}, sheets));
108
+ kicad_project = new KiCadProjectArchive(ctx.project.name, __assign({}, sheets));
109
109
  return [2 /*return*/, kicad_project.toZip()];
110
110
  }
111
111
  });
@@ -1,10 +1,6 @@
1
1
  import type { BOX2 } from '@modular-circuit/electronics-model';
2
2
  export declare const GRID_SIZE: number;
3
3
  export declare const FONT_SIZE: number;
4
- export declare function get_power_pos(pwr_number: number): {
5
- x: number;
6
- y: number;
7
- };
8
4
  export declare const BLOCK_PIN_GAP: number;
9
5
  export declare const BLOCK_PIN_TB_MARGIN: number;
10
6
  export declare const WIRE_PADDING: number;
@@ -21,10 +17,24 @@ export interface BoxGeometry {
21
17
  box: BOX2;
22
18
  bounding_box: BOX2;
23
19
  }
20
+ export declare function get_power_pos(pwr_number: number): {
21
+ x: number;
22
+ y: number;
23
+ };
24
24
  export declare class Layout {
25
- private width;
26
- private height;
27
- private max_height;
28
- get_block_geometry(factor: BlockLabelPadding): BoxGeometry;
25
+ private PAGE_MAX_WIDTH;
26
+ private blocks;
27
+ private assignments;
28
+ add_block(factor: BlockLabelPadding): void;
29
+ /**
30
+ * PHASE 1: Create provisional columns using greedy online assignment.
31
+ */
32
+ private initial_column_assign;
33
+ /**
34
+ * PHASE 2: Rebalance columns globally.
35
+ * Produce near-equal column heights for professional appearance.
36
+ */
37
+ private rebalance_columns;
38
+ finalize(): BoxGeometry[];
29
39
  }
30
40
  //# 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,MAAM,oCAAoC,CAAA;AAI9D,eAAO,MAAM,SAAS,QAAiB,CAAA;AACvC,eAAO,MAAM,SAAS,QAAY,CAAA;AAKlC,eAAO,MAAM,aAAa,QAAgB,CAAA;AAC1C,eAAO,MAAM,mBAAmB,QAAgB,CAAA;AAMhD,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;AAcD,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM;;;EAE/C;AACD,qBAAa,MAAM;IACjB,OAAO,CAAC,cAAc,CAAkC;IAExD,OAAO,CAAC,MAAM,CAAyB;IAGvC,OAAO,CAAC,WAAW,CAAe;IAE3B,SAAS,CAAC,MAAM,EAAE,iBAAiB;IAsB1C;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAwD7B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IA8ClB,QAAQ,IAAI,WAAW,EAAE;CA8CjC"}
@@ -1,66 +1,205 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
1
12
  import { PAPER_SIZE } from '../../utils/constraints';
2
13
  var MIL_TO_MM = 0.0254;
3
14
  export var GRID_SIZE = 50 * MIL_TO_MM;
4
15
  export var FONT_SIZE = GRID_SIZE;
16
+ var BLOCK_START_Y = 5 * GRID_SIZE;
17
+ var BLOCK_START_X = 5 * GRID_SIZE;
18
+ export var BLOCK_PIN_GAP = 4 * GRID_SIZE;
19
+ export var BLOCK_PIN_TB_MARGIN = 2 * GRID_SIZE;
20
+ var BLOCK_MARGIN_TOP = 6 * GRID_SIZE;
21
+ var BLOCK_MARGIN_LEFT = 4 * GRID_SIZE;
22
+ var INTERNAL_LABEL_MARGIN = 3 * FONT_SIZE;
23
+ var MIN_BLOCK_WIDTH = 8 * GRID_SIZE;
24
+ export var WIRE_PADDING = GRID_SIZE;
5
25
  var POWER_START_Y = 30 * GRID_SIZE;
6
26
  var POWER_START_X = (PAPER_SIZE.A4.height - 30) * GRID_SIZE;
7
27
  var POWER_Y_STEP = 16 * GRID_SIZE;
8
28
  export function get_power_pos(pwr_number) {
9
29
  return { x: POWER_START_X, y: POWER_START_Y + POWER_Y_STEP * pwr_number };
10
30
  }
11
- var BLOCK_START_Y = 36 * GRID_SIZE;
12
- var BLOCK_START_X = BLOCK_START_Y;
13
- export var BLOCK_PIN_GAP = 4 * GRID_SIZE;
14
- export var BLOCK_PIN_TB_MARGIN = 2 * GRID_SIZE;
15
- var BLOCK_MARGIN_TOP = 8 * GRID_SIZE;
16
- var MIN_BLOCK_WIDTH = 8 * GRID_SIZE;
17
- var BLOCK_MARGIN_LEFT = 16 * GRID_SIZE;
18
- var BLOCK_MARGIN_RIGHT = BLOCK_MARGIN_LEFT;
19
- var INTERNAL_LABEL_MARGIN = 8 * FONT_SIZE;
20
- export var WIRE_PADDING = GRID_SIZE;
21
31
  var Layout = /** @class */ (function () {
22
32
  function Layout() {
23
- this.width = BLOCK_START_X;
24
- this.height = BLOCK_START_Y;
25
- this.max_height = 0;
33
+ this.PAGE_MAX_WIDTH = PAPER_SIZE.A4.width * GRID_SIZE;
34
+ this.blocks = [];
35
+ // Provisional placement: column index for each block
36
+ this.assignments = [];
26
37
  }
27
- Layout.prototype.get_block_geometry = function (factor) {
38
+ Layout.prototype.add_block = function (factor) {
28
39
  var block_height = Math.floor(factor.total_pin_num / 2) * BLOCK_PIN_GAP + 2 * BLOCK_PIN_TB_MARGIN;
29
40
  var block_width = Math.max(MIN_BLOCK_WIDTH, factor.internal.l_side + factor.internal.r_side + INTERNAL_LABEL_MARGIN);
30
- var block_bounding_width = Math.max(block_width, factor.internal.l_side +
31
- factor.internal.r_side +
32
- factor.outer.l_side +
33
- factor.outer.r_side +
34
- // | txt | | txt |
35
- 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
- },
41
+ var bounding_width = Math.max(block_width, factor.internal.l_side + factor.internal.r_side + factor.outer.l_side + factor.outer.r_side + WIRE_PADDING * 2);
42
+ var measurement = {
43
+ block_width: block_width,
44
+ bounding_width: bounding_width,
45
+ height: block_height,
45
46
  };
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
- },
55
- };
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;
47
+ this.blocks.push(measurement);
48
+ };
49
+ /**
50
+ * PHASE 1: Create provisional columns using greedy online assignment.
51
+ */
52
+ Layout.prototype.initial_column_assign = function () {
53
+ var cols = [];
54
+ for (var i = 0; i < this.blocks.length; i++) {
55
+ var b = this.blocks[i];
56
+ if (cols.length === 0) {
57
+ cols.push({ height: 0, width: b.bounding_width });
58
+ this.assignments.push(0);
59
+ cols[0].height += b.height + BLOCK_MARGIN_TOP;
60
+ cols[0].width = Math.max(cols[0].width, b.bounding_width);
61
+ continue;
62
+ }
63
+ // find shortest column
64
+ var bestIdx = 0;
65
+ for (var c = 1; c < cols.length; c++) {
66
+ if (cols[c].height < cols[bestIdx].height)
67
+ bestIdx = c;
68
+ }
69
+ var best = cols[bestIdx];
70
+ var newColWidth = Math.max(best.width, b.bounding_width);
71
+ // Check if expanding this column fits page width
72
+ var currentTotalWidth = cols.reduce(function (s, c) { return s + c.width; }, 0) + BLOCK_MARGIN_LEFT * (cols.length - 1);
73
+ var totalIfExpand = currentTotalWidth - best.width + newColWidth;
74
+ if (totalIfExpand <= this.PAGE_MAX_WIDTH - BLOCK_START_X) {
75
+ // expand best column
76
+ best.width = newColWidth;
77
+ this.assignments.push(bestIdx);
78
+ best.height += b.height + BLOCK_MARGIN_TOP;
79
+ }
80
+ else {
81
+ // try new column
82
+ var widthIfNew = currentTotalWidth + BLOCK_MARGIN_LEFT + b.bounding_width;
83
+ if (widthIfNew <= this.PAGE_MAX_WIDTH - BLOCK_START_X) {
84
+ cols.push({
85
+ height: b.height + BLOCK_MARGIN_TOP,
86
+ width: b.bounding_width,
87
+ });
88
+ this.assignments.push(cols.length - 1);
89
+ }
90
+ else {
91
+ // fallback: place in best column even if slightly overflowing
92
+ best.width = newColWidth;
93
+ this.assignments.push(bestIdx);
94
+ best.height += b.height + BLOCK_MARGIN_TOP;
95
+ }
96
+ }
97
+ }
98
+ return cols;
99
+ };
100
+ /**
101
+ * PHASE 2: Rebalance columns globally.
102
+ * Produce near-equal column heights for professional appearance.
103
+ */
104
+ Layout.prototype.rebalance_columns = function (initialCols) {
105
+ var _this = this;
106
+ var colCount = initialCols.length;
107
+ var itemsPerColumn = Array.from({ length: colCount }, function () { return []; });
108
+ for (var i = 0; i < this.blocks.length; i++) {
109
+ itemsPerColumn[this.assignments[i]].push(i);
110
+ }
111
+ // Compute heights per column
112
+ var heights = itemsPerColumn.map(function (colIndices) {
113
+ return colIndices.reduce(function (sum, idx) { return sum + _this.blocks[idx].height + BLOCK_MARGIN_TOP; }, 0);
114
+ });
115
+ // Simple redistribution: move from tallest to shortest until balanced
116
+ var changed = true;
117
+ while (changed) {
118
+ changed = false;
119
+ // Find tallest & shortest
120
+ var maxIdx = 0;
121
+ var minIdx = 0;
122
+ for (var i = 1; i < colCount; i++) {
123
+ if (heights[i] > heights[maxIdx])
124
+ maxIdx = i;
125
+ if (heights[i] < heights[minIdx])
126
+ minIdx = i;
127
+ }
128
+ if (heights[maxIdx] - heights[minIdx] < BLOCK_MARGIN_TOP * 2)
129
+ break; // good enough
130
+ // Move one block (the last one) from max column to min column
131
+ var from = itemsPerColumn[maxIdx];
132
+ if (from.length <= 1)
133
+ break;
134
+ var idxToMove = from.pop();
135
+ var b = this.blocks[idxToMove];
136
+ heights[maxIdx] -= b.height + BLOCK_MARGIN_TOP;
137
+ itemsPerColumn[minIdx].push(idxToMove);
138
+ heights[minIdx] += b.height + BLOCK_MARGIN_TOP;
139
+ this.assignments[idxToMove] = minIdx;
140
+ changed = true;
141
+ }
142
+ return itemsPerColumn;
143
+ };
144
+ Layout.prototype.finalize = function () {
145
+ var e_1, _a, e_2, _b;
146
+ var initialCols = this.initial_column_assign();
147
+ var itemsPerColumn = this.rebalance_columns(initialCols);
148
+ var colCount = itemsPerColumn.length;
149
+ // Recompute column widths after rebalancing
150
+ var finalColWidths = new Array(colCount).fill(0);
151
+ for (var c = 0; c < colCount; c++) {
152
+ try {
153
+ for (var _c = (e_1 = void 0, __values(itemsPerColumn[c])), _d = _c.next(); !_d.done; _d = _c.next()) {
154
+ var idx = _d.value;
155
+ finalColWidths[c] = Math.max(finalColWidths[c], this.blocks[idx].bounding_width);
156
+ }
157
+ }
158
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
159
+ finally {
160
+ try {
161
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
162
+ }
163
+ finally { if (e_1) throw e_1.error; }
164
+ }
165
+ }
166
+ // Compute X positions
167
+ var colX = [];
168
+ var x = BLOCK_START_X;
169
+ for (var c = 0; c < colCount; c++) {
170
+ colX[c] = x;
171
+ x += finalColWidths[c] + BLOCK_MARGIN_LEFT;
172
+ }
173
+ // Produce final coordinates
174
+ var result = new Array(this.blocks.length);
175
+ var colY = new Array(colCount).fill(BLOCK_START_Y);
176
+ for (var c = 0; c < colCount; c++) {
177
+ try {
178
+ for (var _e = (e_2 = void 0, __values(itemsPerColumn[c])), _f = _e.next(); !_f.done; _f = _e.next()) {
179
+ var idx = _f.value;
180
+ var b = this.blocks[idx];
181
+ result[idx] = {
182
+ box: {
183
+ pos: { x: colX[c], y: colY[c] },
184
+ size: { x: b.block_width, y: b.height },
185
+ },
186
+ bounding_box: {
187
+ pos: { x: colX[c], y: colY[c] },
188
+ size: { x: finalColWidths[c], y: b.height },
189
+ },
190
+ };
191
+ colY[c] += b.height + BLOCK_MARGIN_TOP;
192
+ }
193
+ }
194
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
195
+ finally {
196
+ try {
197
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
198
+ }
199
+ finally { if (e_2) throw e_2.error; }
200
+ }
62
201
  }
63
- return { box: box, bounding_box: bounding_box };
202
+ return result;
64
203
  };
65
204
  return Layout;
66
205
  }());
@@ -2,7 +2,6 @@ import { type SCHEMATIC } from '@modular-circuit/ir';
2
2
  import type { NetlistToKicadContext } from './context';
3
3
  export declare class NetListConverter {
4
4
  private ctx;
5
- private block_calc;
6
5
  private sheet_pwr_count;
7
6
  private net_name;
8
7
  private wires;
@@ -18,7 +17,6 @@ export declare class NetListConverter {
18
17
  * @returns
19
18
  */
20
19
  private convert_sch;
21
- private convert_hierarchical_label;
22
20
  private convert_pwr_symbol;
23
21
  private get_sheet_symbol_lb_padding;
24
22
  private convert_sheet_symbol;
@@ -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;AAatD,qBAAa,gBAAgB;IAOR,OAAO,CAAC,GAAG;IAN9B,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;IAWvB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IAqFnB,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,2BAA2B;IA+CnC,OAAO,CAAC,oBAAoB;IAsC5B,OAAO,CAAC,iBAAiB;IAgCzB,OAAO,CAAC,iBAAiB;CAQ1B"}
@@ -32,7 +32,7 @@ import { gen_hierarchical_label, gen_net_label, gen_sheet_pin } from '../../kica
32
32
  import { gen_sch_sheet } from '../../kicad/sheet';
33
33
  import { gen_lib_gnd, gen_lib_vcc, gen_sch_gnd, gen_sch_vcc } from '../../kicad/symbols';
34
34
  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';
35
+ import { BLOCK_PIN_GAP, BLOCK_PIN_TB_MARGIN, FONT_SIZE, Layout, WIRE_PADDING, get_power_pos, } from './layout';
36
36
  import { gen_wire } from '../../kicad/wire/gen_wire';
37
37
  var NetListConverter = /** @class */ (function () {
38
38
  function NetListConverter(ctx) {
@@ -80,7 +80,6 @@ var NetListConverter = /** @class */ (function () {
80
80
  for (var _b = __values(Object.entries(this.ctx.netlist.schematics)), _c = _b.next(); !_c.done; _c = _b.next()) {
81
81
  var _d = __read(_c.value, 2), k = _d[0], v = _d[1];
82
82
  this.sheet_pwr_count = 0;
83
- this.block_calc = new Layout();
84
83
  all_sch[k] = this.convert_sch(k, v);
85
84
  }
86
85
  }
@@ -101,8 +100,8 @@ var NetListConverter = /** @class */ (function () {
101
100
  * @returns
102
101
  */
103
102
  NetListConverter.prototype.convert_sch = function (name, schematic) {
104
- var e_4, _a, e_5, _b, e_6, _c;
105
- var _d, _e;
103
+ var e_4, _a, e_5, _b;
104
+ var _c, _d;
106
105
  var powers = new Set();
107
106
  this.wires = [];
108
107
  var sch = {
@@ -131,15 +130,15 @@ var NetListConverter = /** @class */ (function () {
131
130
  sheets: [],
132
131
  };
133
132
  try {
134
- for (var _f = __values(schematic.powers), _g = _f.next(); !_g.done; _g = _f.next()) {
135
- var it_2 = _g.value;
133
+ for (var _e = __values(schematic.powers), _f = _e.next(); !_f.done; _f = _e.next()) {
134
+ var it_2 = _f.value;
136
135
  if (!powers.has(it_2.value)) {
137
136
  switch (it_2.shape) {
138
137
  case PowerShape.VCC:
139
- (_d = sch.lib_symbols) === null || _d === void 0 ? void 0 : _d.symbols.push(gen_lib_vcc(it_2.value));
138
+ (_c = sch.lib_symbols) === null || _c === void 0 ? void 0 : _c.symbols.push(gen_lib_vcc(it_2.value));
140
139
  break;
141
140
  case PowerShape.GND:
142
- (_e = sch.lib_symbols) === null || _e === void 0 ? void 0 : _e.symbols.push(gen_lib_gnd(it_2.value));
141
+ (_d = sch.lib_symbols) === null || _d === void 0 ? void 0 : _d.symbols.push(gen_lib_gnd(it_2.value));
143
142
  break;
144
143
  }
145
144
  powers.add(it_2.value);
@@ -150,7 +149,7 @@ var NetListConverter = /** @class */ (function () {
150
149
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
151
150
  finally {
152
151
  try {
153
- if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
152
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
154
153
  }
155
154
  finally { if (e_4) throw e_4.error; }
156
155
  }
@@ -158,12 +157,12 @@ var NetListConverter = /** @class */ (function () {
158
157
  var ordered_sheets = schematic.sheet_symbols.sort(function (a, b) {
159
158
  return b.pins.length - a.pins.length;
160
159
  });
160
+ var layout = new Layout();
161
161
  try {
162
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
163
  var it_3 = ordered_sheets_1_1.value;
164
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);
165
+ layout.add_block(sheet_padding);
167
166
  }
168
167
  }
169
168
  catch (e_5_1) { e_5 = { error: e_5_1 }; }
@@ -173,31 +172,28 @@ var NetListConverter = /** @class */ (function () {
173
172
  }
174
173
  finally { if (e_5) throw e_5.error; }
175
174
  }
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; }
175
+ var result = layout.finalize();
176
+ for (var i = 0; i < ordered_sheets.length; i++) {
177
+ var sheet_sym = ordered_sheets[i];
178
+ var rect = result[i].box;
179
+ this.convert_sheet_symbol(sheet_sym, rect, sch, sheet_names_count);
188
180
  }
181
+ // for (const it of schematic.hiera_labels) {
182
+ // this.convert_hierarchical_label(it, sch)
183
+ // }
189
184
  sch.wires = this.wires;
190
185
  return sch;
191
186
  };
192
- NetListConverter.prototype.convert_hierarchical_label = function (pin, sch) {
193
- 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));
200
- };
187
+ // private convert_hierarchical_label(pin: NL_HierarchicalLabel, sch: SCHEMATIC) {
188
+ // const layout = new Layout()
189
+ // layout.add_block({
190
+ // internal: { l_side: 0, r_side: 0 },
191
+ // outer: { l_side: 0, r_side: 0 },
192
+ // total_pin_num: 1,
193
+ // })
194
+ // const pos = layout.finalize()[0].box.pos
195
+ // sch.labels?.push(gen_hierarchical_label(pin.name, pos, { horizontal: 'left', vertical: 'bottom' }, 0, pin.shape))
196
+ // }
201
197
  NetListConverter.prototype.convert_pwr_symbol = function (pwr, at, sch) {
202
198
  // NOTE : The power uuid is used as the uuid of its pin ,cause all power symbols have only one pin
203
199
  var pin_id = pwr.uuid;
@@ -1,3 +1,3 @@
1
1
  export * from './wildcards_and_files_ext';
2
- export * from './kicad_project_achieve';
2
+ export * from './kicad_project_archive';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,2 @@
1
1
  export * from './wildcards_and_files_ext';
2
- export * from './kicad_project_achieve';
2
+ export * from './kicad_project_archive';
@@ -1,5 +1,5 @@
1
1
  export declare const KICAD_SCH_FRAME: string;
2
- export declare class KiCadProjectAchieve {
2
+ export declare class KiCadProjectArchive {
3
3
  project_name: string;
4
4
  sheets: Record<string, string>;
5
5
  kicad_sym?: string;
@@ -234,4 +234,4 @@ export declare class KiCadProjectAchieve {
234
234
  get_project_directive_file_name(ext: string): string;
235
235
  toZip(): Promise<Blob>;
236
236
  }
237
- //# sourceMappingURL=kicad_project_achieve.d.ts.map
237
+ //# sourceMappingURL=kicad_project_archive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kicad_project_achieve.d.ts","sourceRoot":"","sources":["../../../src/kicad/project/kicad_project_achieve.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,eAAe,QAAkC,CAAA;AAE9D,qBAAa,mBAAmB;IAmBrB,YAAY,EAAE,MAAM;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAnBhC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,aAAa,CAAC,EAAE,MAAM,CAAA;IAC7B,IAAW,SAAS,WAEnB;IAED,IAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEnB;IAED,IAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEnB;gBAGQ,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAGhC,+BAA+B,CAAC,GAAG,EAAE,MAAM;IAI3C,KAAK;CAQb"}
1
+ {"version":3,"file":"kicad_project_archive.d.ts","sourceRoot":"","sources":["../../../src/kicad/project/kicad_project_archive.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,eAAe,QAAkC,CAAA;AAE9D,qBAAa,mBAAmB;IAmBrB,YAAY,EAAE,MAAM;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAnBhC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,aAAa,CAAC,EAAE,MAAM,CAAA;IAC7B,IAAW,SAAS,WAEnB;IAED,IAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEnB;IAED,IAAW,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAEnB;gBAGQ,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAGhC,+BAA+B,CAAC,GAAG,EAAE,MAAM;IAI3C,KAAK;CAQb"}
@@ -15,39 +15,39 @@ import { kicad_prl } from './kicad_prl';
15
15
  import { kicad_pro } from './kicad_pro';
16
16
  import { DrawingSheetFileExtension, ProjectFileExtension, ProjectLocalSettingsFileExtension, } from './wildcards_and_files_ext';
17
17
  export var KICAD_SCH_FRAME = get_sch_default_drawing_sheet();
18
- var KiCadProjectAchieve = /** @class */ (function () {
19
- function KiCadProjectAchieve(project_name, sheets) {
18
+ var KiCadProjectArchive = /** @class */ (function () {
19
+ function KiCadProjectArchive(project_name, sheets) {
20
20
  this.project_name = project_name;
21
21
  this.sheets = sheets;
22
22
  }
23
- Object.defineProperty(KiCadProjectAchieve.prototype, "sch_frame", {
23
+ Object.defineProperty(KiCadProjectArchive.prototype, "sch_frame", {
24
24
  get: function () {
25
25
  return KICAD_SCH_FRAME;
26
26
  },
27
27
  enumerable: false,
28
28
  configurable: true
29
29
  });
30
- Object.defineProperty(KiCadProjectAchieve.prototype, "kicad_prl", {
30
+ Object.defineProperty(KiCadProjectArchive.prototype, "kicad_prl", {
31
31
  get: function () {
32
32
  return kicad_prl(this.project_name);
33
33
  },
34
34
  enumerable: false,
35
35
  configurable: true
36
36
  });
37
- Object.defineProperty(KiCadProjectAchieve.prototype, "kicad_pro", {
37
+ Object.defineProperty(KiCadProjectArchive.prototype, "kicad_pro", {
38
38
  get: function () {
39
39
  return kicad_pro(this.project_name);
40
40
  },
41
41
  enumerable: false,
42
42
  configurable: true
43
43
  });
44
- KiCadProjectAchieve.prototype.get_project_directive_file_name = function (ext) {
44
+ KiCadProjectArchive.prototype.get_project_directive_file_name = function (ext) {
45
45
  return "".concat(this.project_name, ".").concat(ext);
46
46
  };
47
- KiCadProjectAchieve.prototype.toZip = function () {
47
+ KiCadProjectArchive.prototype.toZip = function () {
48
48
  var _a;
49
49
  return zipFiles(__assign((_a = {}, _a[this.get_project_directive_file_name(ProjectLocalSettingsFileExtension)] = JSON.stringify(this.kicad_prl), _a[this.get_project_directive_file_name(ProjectFileExtension)] = JSON.stringify(this.kicad_pro), _a[this.get_project_directive_file_name(DrawingSheetFileExtension)] = this.sch_frame, _a), this.sheets));
50
50
  };
51
- return KiCadProjectAchieve;
51
+ return KiCadProjectArchive;
52
52
  }());
53
- export { KiCadProjectAchieve };
53
+ export { KiCadProjectArchive };
@@ -1 +1 @@
1
- {"root":["../src/index.ts","../src/builder/index.ts","../src/builder/graph_to_kicad/do_convert_graph_to_kicad_project.ts","../src/builder/graph_to_kicad/index.ts","../src/converter/index.ts","../src/converter/graph_to_netlist/context.ts","../src/converter/graph_to_netlist/graph_converter.ts","../src/converter/graph_to_netlist/index.ts","../src/converter/kicad_sexpr/index.ts","../src/converter/kicad_sexpr/eeschema/index.ts","../src/converter/kicad_sexpr/eeschema/printer.ts","../src/converter/kicad_sexpr/eeschema/drawing_sheet/index.ts","../src/converter/kicad_sexpr/eeschema/drawing_sheet/sch_default_drawing_sheet.ts","../src/converter/kicad_sexpr/pcb/index.ts","../src/converter/link_to_netlist/context.ts","../src/converter/link_to_netlist/converter.ts","../src/converter/link_to_netlist/index.ts","../src/converter/link_to_netlist/links/converter_base.ts","../src/converter/link_to_netlist/links/converters.ts","../src/converter/link_to_netlist/links/index.ts","../src/converter/netlist_to_kicad/context.ts","../src/converter/netlist_to_kicad/index.ts","../src/converter/netlist_to_kicad/layout.ts","../src/converter/netlist_to_kicad/netlist_converter.ts","../src/converter/netlist_to_kicad/place_blocks.ts","../src/kicad/index.ts","../src/kicad/constraints/index.ts","../src/kicad/label/index.ts","../src/kicad/label/net_label.ts","../src/kicad/label/sheet_pin.ts","../src/kicad/project/index.ts","../src/kicad/project/kicad_prl.ts","../src/kicad/project/kicad_pro.ts","../src/kicad/project/kicad_project_achieve.ts","../src/kicad/project/wildcards_and_files_ext.ts","../src/kicad/sheet/index.ts","../src/kicad/sheet/sheet.ts","../src/kicad/symbols/index.ts","../src/kicad/symbols/symbol_utils.ts","../src/kicad/symbols/lib_symbol/gnd.ts","../src/kicad/symbols/lib_symbol/index.ts","../src/kicad/symbols/lib_symbol/vcc.ts","../src/kicad/symbols/sch_symbol/gnd.ts","../src/kicad/symbols/sch_symbol/index.ts","../src/kicad/symbols/sch_symbol/vcc.ts","../src/kicad/wire/gen_wire.ts","../src/utils/collect_sub_sheets.ts","../src/utils/collect_sub_sheets_by_id.ts","../src/utils/constraints.ts","../src/utils/filter_null_undefined.ts","../src/utils/index.ts","../src/utils/string_formatter.ts"],"version":"5.8.3"}
1
+ {"root":["../src/index.ts","../src/builder/index.ts","../src/builder/graph_to_kicad/do_convert_graph_to_kicad_project.ts","../src/builder/graph_to_kicad/index.ts","../src/converter/index.ts","../src/converter/graph_to_netlist/context.ts","../src/converter/graph_to_netlist/graph_converter.ts","../src/converter/graph_to_netlist/index.ts","../src/converter/kicad_sexpr/index.ts","../src/converter/kicad_sexpr/eeschema/index.ts","../src/converter/kicad_sexpr/eeschema/printer.ts","../src/converter/kicad_sexpr/eeschema/drawing_sheet/index.ts","../src/converter/kicad_sexpr/eeschema/drawing_sheet/sch_default_drawing_sheet.ts","../src/converter/kicad_sexpr/pcb/index.ts","../src/converter/link_to_netlist/context.ts","../src/converter/link_to_netlist/converter.ts","../src/converter/link_to_netlist/index.ts","../src/converter/link_to_netlist/links/converter_base.ts","../src/converter/link_to_netlist/links/converters.ts","../src/converter/link_to_netlist/links/index.ts","../src/converter/netlist_to_kicad/context.ts","../src/converter/netlist_to_kicad/index.ts","../src/converter/netlist_to_kicad/layout.ts","../src/converter/netlist_to_kicad/netlist_converter.ts","../src/converter/netlist_to_kicad/place_blocks.ts","../src/kicad/index.ts","../src/kicad/constraints/index.ts","../src/kicad/label/index.ts","../src/kicad/label/net_label.ts","../src/kicad/label/sheet_pin.ts","../src/kicad/project/index.ts","../src/kicad/project/kicad_prl.ts","../src/kicad/project/kicad_pro.ts","../src/kicad/project/kicad_project_archive.ts","../src/kicad/project/wildcards_and_files_ext.ts","../src/kicad/sheet/index.ts","../src/kicad/sheet/sheet.ts","../src/kicad/symbols/index.ts","../src/kicad/symbols/symbol_utils.ts","../src/kicad/symbols/lib_symbol/gnd.ts","../src/kicad/symbols/lib_symbol/index.ts","../src/kicad/symbols/lib_symbol/vcc.ts","../src/kicad/symbols/sch_symbol/gnd.ts","../src/kicad/symbols/sch_symbol/index.ts","../src/kicad/symbols/sch_symbol/vcc.ts","../src/kicad/wire/gen_wire.ts","../src/utils/collect_sub_sheets.ts","../src/utils/collect_sub_sheets_by_id.ts","../src/utils/constraints.ts","../src/utils/filter_null_undefined.ts","../src/utils/index.ts","../src/utils/string_formatter.ts"],"version":"5.8.3"}
@@ -75,7 +75,7 @@ var __read = (this && this.__read) || function (o, n) {
75
75
  import { KICAD_SHC_FILE_EXT, parse_module_name, remove_filename_path_prefix, unzipFile } from '@modular-circuit/utils';
76
76
  export function collect_sub_sheets(dependencies, module_resolver) {
77
77
  return __awaiter(this, void 0, void 0, function () {
78
- var sheets, module_main_sheet, modules, _a, _b, _c, k, v, zip_achieve_url, module_1, zip_achieve, files, _d, _e, _f, name, content, fileName, e_1_1;
78
+ var sheets, module_main_sheet, modules, _a, _b, _c, k, v, zip_archive_url, module_1, zip_archive, files, _d, _e, _f, name, content, fileName, e_1_1;
79
79
  var e_1, _g, e_2, _h;
80
80
  return __generator(this, function (_j) {
81
81
  switch (_j.label) {
@@ -91,13 +91,13 @@ export function collect_sub_sheets(dependencies, module_resolver) {
91
91
  case 2:
92
92
  if (!!_b.done) return [3 /*break*/, 8];
93
93
  _c = __read(_b.value, 2), k = _c[0], v = _c[1];
94
- return [4 /*yield*/, module_resolver.get_module_achieve(__assign(__assign({}, parse_module_name(k)), { version: v }))];
94
+ return [4 /*yield*/, module_resolver.get_module_archive(__assign(__assign({}, parse_module_name(k)), { version: v }))];
95
95
  case 3:
96
- zip_achieve_url = _j.sent();
96
+ zip_archive_url = _j.sent();
97
97
  return [4 /*yield*/, module_resolver.get_module_circuit(__assign(__assign({}, parse_module_name(k)), { version: v }))];
98
98
  case 4:
99
99
  module_1 = _j.sent();
100
- if (!zip_achieve_url || !module_1) {
100
+ if (!zip_archive_url || !module_1) {
101
101
  console.error("Module ".concat(k, "/").concat(v, " not found"));
102
102
  return [3 /*break*/, 7];
103
103
  }
@@ -107,10 +107,10 @@ export function collect_sub_sheets(dependencies, module_resolver) {
107
107
  }
108
108
  module_main_sheet[k] = module_1.main;
109
109
  modules[k] = module_1;
110
- return [4 /*yield*/, fetch(zip_achieve_url).then(function (res) { return res.arrayBuffer(); })];
110
+ return [4 /*yield*/, fetch(zip_archive_url).then(function (res) { return res.arrayBuffer(); })];
111
111
  case 5:
112
- zip_achieve = _j.sent();
113
- return [4 /*yield*/, unzipFile(zip_achieve)];
112
+ zip_archive = _j.sent();
113
+ return [4 /*yield*/, unzipFile(zip_archive)];
114
114
  case 6:
115
115
  files = _j.sent();
116
116
  try {
@@ -64,7 +64,7 @@ var __read = (this && this.__read) || function (o, n) {
64
64
  import { fmt_module_name, KICAD_SHC_FILE_EXT, parse_module_name, remove_filename_path_prefix, unzipFile, } from '@modular-circuit/utils';
65
65
  export function collect_sub_sheets_by_id(module_ids, module_resolver) {
66
66
  return __awaiter(this, void 0, void 0, function () {
67
- var sheets, module_main_sheet, modules, module_ids_1, module_ids_1_1, id, zip_achieve_url, module_circuit, k, zip_achieve, files, _a, _b, _c, name, content, fileName, e_1_1;
67
+ var sheets, module_main_sheet, modules, module_ids_1, module_ids_1_1, id, zip_archive_url, module_circuit, k, zip_archive, files, _a, _b, _c, name, content, fileName, e_1_1;
68
68
  var e_1, _d, e_2, _e;
69
69
  return __generator(this, function (_f) {
70
70
  switch (_f.label) {
@@ -80,9 +80,9 @@ export function collect_sub_sheets_by_id(module_ids, module_resolver) {
80
80
  case 2:
81
81
  if (!!module_ids_1_1.done) return [3 /*break*/, 8];
82
82
  id = module_ids_1_1.value;
83
- return [4 /*yield*/, module_resolver.get_module_achieve_by_id(id)];
83
+ return [4 /*yield*/, module_resolver.get_module_archive_by_id(id)];
84
84
  case 3:
85
- zip_achieve_url = _f.sent();
85
+ zip_archive_url = _f.sent();
86
86
  return [4 /*yield*/, module_resolver.get_module_circuit_by_id(id)];
87
87
  case 4:
88
88
  module_circuit = _f.sent();
@@ -90,7 +90,7 @@ export function collect_sub_sheets_by_id(module_ids, module_resolver) {
90
90
  console.error("Module ".concat(id, " not found"));
91
91
  return [3 /*break*/, 7];
92
92
  }
93
- if (!zip_achieve_url || !module_circuit) {
93
+ if (!zip_archive_url || !module_circuit) {
94
94
  console.error("Module ".concat(module_circuit.author, "/").concat(module_circuit.name, " not found"));
95
95
  return [3 /*break*/, 7];
96
96
  }
@@ -101,10 +101,10 @@ export function collect_sub_sheets_by_id(module_ids, module_resolver) {
101
101
  k = fmt_module_name(module_circuit);
102
102
  module_main_sheet[k] = module_circuit.main;
103
103
  modules[k] = module_circuit;
104
- return [4 /*yield*/, fetch(zip_achieve_url).then(function (res) { return res.arrayBuffer(); })];
104
+ return [4 /*yield*/, fetch(zip_archive_url).then(function (res) { return res.arrayBuffer(); })];
105
105
  case 5:
106
- zip_achieve = _f.sent();
107
- return [4 /*yield*/, unzipFile(zip_achieve)];
106
+ zip_archive = _f.sent();
107
+ return [4 /*yield*/, unzipFile(zip_archive)];
108
108
  case 6:
109
109
  files = _f.sent();
110
110
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-circuit/transpiler",
3
- "version": "0.0.90",
3
+ "version": "0.0.92",
4
4
  "description": "Intermediate representation of the modular circuit",
5
5
  "main": "./build/index.js",
6
6
  "files": [
@@ -28,8 +28,8 @@
28
28
  "jszip": "^3.10.1",
29
29
  "@modular-circuit/electronics-model": "0.0.54",
30
30
  "@modular-circuit/perc": "0.0.61",
31
- "@modular-circuit/utils": "0.0.40",
32
- "@modular-circuit/ir": "0.0.62"
31
+ "@modular-circuit/ir": "0.0.63",
32
+ "@modular-circuit/utils": "0.0.41"
33
33
  },
34
34
  "scripts": {
35
35
  "clean": "rimraf build",