circuitscript 0.1.0 → 0.1.3

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.
Files changed (61) hide show
  1. package/dist/cjs/BaseVisitor.js +13 -8
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  3. package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
  4. package/dist/cjs/builtinMethods.js +27 -8
  5. package/dist/cjs/draw_symbols.js +320 -197
  6. package/dist/cjs/execute.js +114 -116
  7. package/dist/cjs/export.js +2 -4
  8. package/dist/cjs/geometry.js +52 -19
  9. package/dist/cjs/globals.js +17 -12
  10. package/dist/cjs/helpers.js +16 -3
  11. package/dist/cjs/layout.js +473 -354
  12. package/dist/cjs/logger.js +8 -1
  13. package/dist/cjs/objects/ClassComponent.js +22 -22
  14. package/dist/cjs/objects/ExecutionScope.js +10 -4
  15. package/dist/cjs/objects/Frame.js +11 -2
  16. package/dist/cjs/objects/ParamDefinition.js +123 -4
  17. package/dist/cjs/objects/PinDefinition.js +1 -4
  18. package/dist/cjs/render.js +76 -138
  19. package/dist/cjs/sizing.js +33 -7
  20. package/dist/cjs/utils.js +86 -2
  21. package/dist/cjs/visitor.js +224 -255
  22. package/dist/esm/BaseVisitor.mjs +15 -10
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
  25. package/dist/esm/builtinMethods.mjs +24 -8
  26. package/dist/esm/draw_symbols.mjs +322 -200
  27. package/dist/esm/execute.mjs +116 -118
  28. package/dist/esm/export.mjs +2 -4
  29. package/dist/esm/geometry.mjs +52 -19
  30. package/dist/esm/globals.mjs +17 -12
  31. package/dist/esm/helpers.mjs +17 -4
  32. package/dist/esm/layout.mjs +479 -360
  33. package/dist/esm/logger.mjs +8 -1
  34. package/dist/esm/objects/ClassComponent.mjs +21 -26
  35. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  36. package/dist/esm/objects/Frame.mjs +10 -1
  37. package/dist/esm/objects/ParamDefinition.mjs +122 -3
  38. package/dist/esm/objects/PinDefinition.mjs +0 -2
  39. package/dist/esm/render.mjs +79 -141
  40. package/dist/esm/sizing.mjs +34 -8
  41. package/dist/esm/utils.mjs +80 -1
  42. package/dist/esm/visitor.mjs +226 -257
  43. package/dist/types/BaseVisitor.d.ts +1 -1
  44. package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
  45. package/dist/types/draw_symbols.d.ts +72 -45
  46. package/dist/types/execute.d.ts +15 -10
  47. package/dist/types/geometry.d.ts +31 -19
  48. package/dist/types/globals.d.ts +15 -11
  49. package/dist/types/helpers.d.ts +2 -1
  50. package/dist/types/layout.d.ts +35 -54
  51. package/dist/types/logger.d.ts +1 -1
  52. package/dist/types/objects/ClassComponent.d.ts +19 -16
  53. package/dist/types/objects/ExecutionScope.d.ts +3 -2
  54. package/dist/types/objects/Frame.d.ts +9 -2
  55. package/dist/types/objects/ParamDefinition.d.ts +32 -2
  56. package/dist/types/objects/PinDefinition.d.ts +0 -2
  57. package/dist/types/render.d.ts +2 -1
  58. package/dist/types/utils.d.ts +14 -1
  59. package/dist/types/visitor.d.ts +4 -5
  60. package/libs/lib.cst +25 -8
  61. package/package.json +7 -3
@@ -11,9 +11,9 @@ const Frame_js_1 = require("./objects/Frame.js");
11
11
  const utils_js_1 = require("./utils.js");
12
12
  const types_js_1 = require("./objects/types.js");
13
13
  const helpers_js_1 = require("./helpers.js");
14
+ const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
14
15
  class LayoutEngine {
15
16
  constructor(options = { showBaseFrame: false }) {
16
- this.placeSubgraphVersion = 2;
17
17
  this.layoutWarnings = [];
18
18
  this.showBaseFrame = false;
19
19
  this.logger = new logger_js_1.Logger();
@@ -115,8 +115,8 @@ class LayoutEngine {
115
115
  const allLines = wires.map(wire => {
116
116
  return wire.points.map(pt => {
117
117
  return {
118
- x: wire.x + pt.x,
119
- y: wire.y + pt.y,
118
+ x: wire.x.add(pt.x),
119
+ y: wire.y.add(pt.y),
120
120
  };
121
121
  });
122
122
  });
@@ -127,7 +127,7 @@ class LayoutEngine {
127
127
  intersectPoints,
128
128
  });
129
129
  intersectPoints.forEach(([x, y]) => {
130
- junctions.push(new RenderJunction(x, y));
130
+ junctions.push(new RenderJunction((0, ParamDefinition_js_1.numeric)(x), (0, ParamDefinition_js_1.numeric)(y)));
131
131
  });
132
132
  }
133
133
  return {
@@ -137,21 +137,21 @@ class LayoutEngine {
137
137
  }
138
138
  placeFrames(graph, subgraphInfo, frameObjects) {
139
139
  const baseFrame = frameObjects[0];
140
- baseFrame.padding = 0;
141
- baseFrame.borderWidth = 0;
140
+ baseFrame.padding = (0, ParamDefinition_js_1.numeric)(0);
141
+ baseFrame.borderWidth = (0, ParamDefinition_js_1.numeric)(0);
142
142
  if (this.showBaseFrame) {
143
- baseFrame.borderWidth = 5;
144
- baseFrame.width = 11692 - 400 * 2;
145
- baseFrame.height = 8267 - 400 * 2;
143
+ baseFrame.borderWidth = (0, ParamDefinition_js_1.numeric)(5);
144
+ baseFrame.width = (0, ParamDefinition_js_1.numeric)(11692 - 400 * 2);
145
+ baseFrame.height = (0, ParamDefinition_js_1.numeric)(8267 - 400 * 2);
146
146
  }
147
- baseFrame.x = 0;
148
- baseFrame.y = 0;
149
- let textObjects = [];
150
- let elementFrames = [];
147
+ baseFrame.x = (0, ParamDefinition_js_1.numeric)(0);
148
+ baseFrame.y = (0, ParamDefinition_js_1.numeric)(0);
151
149
  baseFrame.bounds = {
152
150
  xmin: 0, ymin: 0,
153
151
  xmax: 0, ymax: 0,
154
152
  };
153
+ let textObjects = [];
154
+ let elementFrames = [];
155
155
  if (subgraphInfo.length > 0) {
156
156
  const result = this.prepareFrames(graph, subgraphInfo, baseFrame);
157
157
  textObjects = result.textObjects;
@@ -176,10 +176,10 @@ class LayoutEngine {
176
176
  const innerItems = frame.innerItems;
177
177
  const frames = [];
178
178
  innerItems.forEach(item => {
179
- if (item.type === RenderFrameType.Elements) {
179
+ if (item.renderType === RenderFrameType.Elements) {
180
180
  frames.push(item);
181
181
  }
182
- else if (item.type === RenderFrameType.Container) {
182
+ else if (item.renderType === RenderFrameType.Container) {
183
183
  const innerFrames = this.collectElementFrames(item, level + 1);
184
184
  frames.push(...innerFrames);
185
185
  }
@@ -191,18 +191,20 @@ class LayoutEngine {
191
191
  const innerItems = frame.innerItems;
192
192
  innerItems.forEach(innerFrame => {
193
193
  if (innerFrame.frame.frameType === globals_js_1.FrameType.Sheet) {
194
- innerFrame.x = 0;
195
- innerFrame.y = 0;
194
+ innerFrame.x = (0, ParamDefinition_js_1.numeric)(0);
195
+ innerFrame.y = (0, ParamDefinition_js_1.numeric)(0);
196
196
  }
197
197
  else {
198
- innerFrame.x += frame.x;
199
- innerFrame.y += frame.y;
198
+ innerFrame.x = innerFrame.x.add(frame.x);
199
+ innerFrame.y = innerFrame.y.add(frame.y);
200
200
  }
201
- if (innerFrame.type === RenderFrameType.Elements) {
201
+ if (innerFrame.renderType === RenderFrameType.Elements) {
202
202
  this.print(level, "".padStart(level * 4), 'element frame', innerFrame.x, innerFrame.y);
203
- innerFrame.innerItems.forEach(item2 => {
204
- item2.x += innerFrame.x - innerFrame.translateX;
205
- item2.y += innerFrame.y - innerFrame.translateY;
203
+ const diffX = innerFrame.x.sub(innerFrame.translateX);
204
+ const diffY = innerFrame.y.sub(innerFrame.translateY);
205
+ innerFrame.innerItems.forEach(item => {
206
+ item.x = item.x.add(diffX);
207
+ item.y = item.y.add(diffY);
206
208
  });
207
209
  }
208
210
  else {
@@ -214,11 +216,10 @@ class LayoutEngine {
214
216
  placeAndSizeFrame(frame, level = 0) {
215
217
  const innerFrames = frame.innerItems;
216
218
  const gridSize = globals_js_1.defaultGridSizeUnits;
217
- let accumX = 0;
218
- let accumY = 0;
219
+ const frameDirection = frame.direction;
219
220
  const boundPoints = [];
220
221
  const frameSizes = innerFrames.map(innerFrame => {
221
- if (innerFrame.type === RenderFrameType.Elements) {
222
+ if (innerFrame.renderType === RenderFrameType.Elements) {
222
223
  innerFrame.bounds = (0, utils_js_1.resizeToNearestGrid)(innerFrame.bounds, gridSize);
223
224
  innerFrame.translateX = innerFrame.bounds.xmin;
224
225
  innerFrame.translateY = innerFrame.bounds.ymin;
@@ -232,10 +233,14 @@ class LayoutEngine {
232
233
  const { width } = (0, utils_js_1.getBoundsSize)(item);
233
234
  return width;
234
235
  }));
236
+ const maxHeight = Math.max(...frameSizes.map(item => {
237
+ const { height } = (0, utils_js_1.getBoundsSize)(item);
238
+ return height;
239
+ }));
235
240
  let accumRowWidth = 0;
236
- let titleFrameWidth = null;
241
+ let titleFrameWidth = 0;
237
242
  const inRowShouldCenterInnerFrames = true;
238
- if (frame.direction === Frame_js_1.FramePlotDirection.Row) {
243
+ if (frameDirection === Frame_js_1.FramePlotDirection.Row) {
239
244
  accumRowWidth = frameSizes.reduce((accum, item, index) => {
240
245
  const { width } = (0, utils_js_1.getBoundsSize)(item);
241
246
  if (frame.innerItems[index].containsTitle) {
@@ -243,85 +248,252 @@ class LayoutEngine {
243
248
  return accum;
244
249
  }
245
250
  return accum + width +
246
- ((index + 1 < frameSizes.length) ? frame.gap : 0);
251
+ ((index + 1 < frameSizes.length) ? frame.gap.toNumber() : 0);
247
252
  }, 0);
248
253
  }
249
254
  else {
250
255
  accumRowWidth = maxWidth;
251
256
  }
257
+ let frameWidth = (0, ParamDefinition_js_1.numeric)(0);
258
+ let frameHeight = (0, ParamDefinition_js_1.numeric)(0);
259
+ let frameXMin = (0, ParamDefinition_js_1.numeric)(0);
260
+ let frameYMin = (0, ParamDefinition_js_1.numeric)(0);
261
+ const frameParams = frame.frame.parameters;
262
+ const avoidAreas = [];
263
+ if (frameParams.has(Frame_js_1.FrameParamKeys.SheetType)) {
264
+ const frameComponent = frameParams.get(Frame_js_1.FrameParamKeys.SheetType);
265
+ const frameDrawing = frameComponent.displayProp;
266
+ frameDrawing.variables = (0, utils_js_1.combineMaps)(frameComponent.parameters, frameParams);
267
+ const rects = ExtractDrawingRects(frameDrawing);
268
+ const drawableRect = rects.find(rect => rect.className === 'plot-area');
269
+ let frameMinX = (0, ParamDefinition_js_1.numeric)(0);
270
+ let frameMinY = (0, ParamDefinition_js_1.numeric)(0);
271
+ if (drawableRect) {
272
+ frameMinX = (0, helpers_js_1.milsToMM)(drawableRect.x);
273
+ frameMinY = (0, helpers_js_1.milsToMM)(drawableRect.y);
274
+ frameWidth = (0, helpers_js_1.milsToMM)(drawableRect.width);
275
+ frameHeight = (0, helpers_js_1.milsToMM)(drawableRect.height);
276
+ }
277
+ const infoAreaRect = rects.filter(rect => rect.className === 'keepout-area');
278
+ infoAreaRect.forEach(area => {
279
+ const x1 = area.x;
280
+ const y1 = area.y;
281
+ const x2 = area.x.add(area.width);
282
+ const y2 = area.y.add(area.height);
283
+ avoidAreas.push([
284
+ (0, helpers_js_1.milsToMM)(x1).sub(frameMinX).toNumber(),
285
+ (0, helpers_js_1.milsToMM)(y1).sub(frameMinY).toNumber(),
286
+ (0, helpers_js_1.milsToMM)(x2).sub(frameMinX).toNumber(),
287
+ (0, helpers_js_1.milsToMM)(y2).sub(frameMinY).toNumber(),
288
+ ]);
289
+ });
290
+ }
291
+ else {
292
+ if (frame.width !== null) {
293
+ frameWidth = frame.width;
294
+ }
295
+ if (frame.height !== null) {
296
+ frameHeight = frame.height;
297
+ }
298
+ }
252
299
  const offsetX = frame.padding;
253
300
  const offsetY = frame.padding;
254
301
  let centeredOffsetX = 0;
255
302
  let widthForTitle;
256
- if (titleFrameWidth > accumRowWidth) {
303
+ if (frameWidth.toNumber() !== 0) {
304
+ widthForTitle = frameWidth.toNumber();
305
+ }
306
+ else if (titleFrameWidth > accumRowWidth) {
257
307
  widthForTitle = titleFrameWidth;
258
308
  }
259
309
  else {
260
310
  widthForTitle = accumRowWidth;
261
311
  }
262
- if (frame.direction === Frame_js_1.FramePlotDirection.Row &&
312
+ if (frameDirection === Frame_js_1.FramePlotDirection.Row &&
263
313
  inRowShouldCenterInnerFrames &&
264
314
  titleFrameWidth !== null && titleFrameWidth > accumRowWidth) {
265
- centeredOffsetX = (0, utils_js_1.toNearestGrid)(titleFrameWidth / 2 - accumRowWidth / 2, gridSize);
315
+ centeredOffsetX =
316
+ (0, utils_js_1.toNearestGrid)(titleFrameWidth / 2 - accumRowWidth / 2, gridSize);
266
317
  }
267
- innerFrames.forEach(innerFrame => {
268
- const { width: frameWidth, height: frameHeight } = (0, utils_js_1.getBoundsSize)(innerFrame.bounds);
318
+ let title_align = geometry_js_1.HorizontalAlign.Middle;
319
+ if (frameParams.has(Frame_js_1.FrameParamKeys.TitleAlign)) {
320
+ title_align = frameParams.get(Frame_js_1.FrameParamKeys.TitleAlign);
321
+ }
322
+ let accumX = (0, ParamDefinition_js_1.numeric)(0);
323
+ let accumY = (0, ParamDefinition_js_1.numeric)(0);
324
+ innerFrames.forEach((innerFrame, index) => {
325
+ const { width: innerFrameWidth, height: innerFrameHeight } = (0, utils_js_1.getBoundsSize)(innerFrame.bounds);
326
+ let arrangeLineAttempts = 0;
327
+ const maxAttempts = 10;
328
+ let innerFrameX = (0, ParamDefinition_js_1.numeric)(0);
329
+ let innerFrameY = (0, ParamDefinition_js_1.numeric)(0);
269
330
  if (innerFrame.containsTitle) {
270
- innerFrame.x = offsetX + accumX + (0, utils_js_1.toNearestGrid)(widthForTitle / 2 - frameWidth / 2, gridSize);
271
- innerFrame.y = offsetY + accumY;
272
- accumY += (frameHeight + frame.gap);
331
+ innerFrame.x = offsetX.add(accumX);
332
+ innerFrame.y = offsetY.add(accumY);
333
+ accumY = accumY.add(innerFrameHeight).add(frame.gap);
273
334
  }
274
335
  else {
275
- if (frame.direction === Frame_js_1.FramePlotDirection.Column) {
276
- innerFrame.x = offsetX + accumX + (0, utils_js_1.toNearestGrid)(maxWidth / 2 - frameWidth / 2, gridSize);
277
- innerFrame.y = offsetY + accumY;
278
- accumY += (frameHeight + frame.gap);
336
+ if (frameDirection === Frame_js_1.FramePlotDirection.Column) {
337
+ innerFrameX = offsetX.add(accumX);
338
+ innerFrameY = offsetY.add(accumY);
339
+ while (arrangeLineAttempts < maxAttempts) {
340
+ const innerFrameY2 = innerFrameY.toNumber() + innerFrameHeight;
341
+ const doesExceedFrameHeight = (frameHeight.toNumber() > 0
342
+ && innerFrameY2 > frameHeight.toNumber());
343
+ const { xmax } = getBoundsFromPoints(boundPoints);
344
+ const tmpX1 = innerFrameX.toNumber();
345
+ const tmpY1 = innerFrameY.toNumber();
346
+ const tmpX2 = tmpX1 + innerFrameWidth;
347
+ const tmpY2 = tmpY1 + innerFrameHeight;
348
+ const frameArea = [tmpX1, tmpY1, tmpX2, tmpY2];
349
+ const overlaps = avoidAreas.filter(area => (0, utils_js_1.areasOverlap)(frameArea, area));
350
+ const doesOverlapAreasToAvoid = overlaps.length > 0;
351
+ if (doesExceedFrameHeight || doesOverlapAreasToAvoid) {
352
+ innerFrameY = offsetY;
353
+ const nextX = (0, ParamDefinition_js_1.numeric)(xmax).sub(offsetX).add(frame.gap);
354
+ innerFrameX = offsetX.add(nextX);
355
+ accumY = (0, ParamDefinition_js_1.numeric)(0);
356
+ accumX = nextX;
357
+ }
358
+ arrangeLineAttempts++;
359
+ if (arrangeLineAttempts > maxAttempts) {
360
+ throw "Failed to place inner frame";
361
+ }
362
+ }
363
+ innerFrame.x = innerFrameX;
364
+ innerFrame.y = innerFrameY;
365
+ accumY = accumY.add(innerFrameHeight).add(frame.gap);
279
366
  }
280
- else if (frame.direction === Frame_js_1.FramePlotDirection.Row) {
281
- innerFrame.x = offsetX + centeredOffsetX + accumX;
282
- innerFrame.y = offsetY + accumY;
283
- accumX += (frameWidth + frame.gap);
367
+ else if (frameDirection === Frame_js_1.FramePlotDirection.Row) {
368
+ innerFrameX = offsetX.add(centeredOffsetX).add(accumX);
369
+ innerFrameY = offsetY.add(accumY);
370
+ while (arrangeLineAttempts < maxAttempts) {
371
+ const innerFrameX2 = innerFrameX.toNumber() + innerFrameWidth;
372
+ const doesExceedFrameWidth = (frameWidth.toNumber() > 0
373
+ && innerFrameX2 > frameWidth.toNumber());
374
+ const tmpX1 = innerFrameX.toNumber();
375
+ const tmpY1 = innerFrameY.toNumber();
376
+ const tmpX2 = tmpX1 + innerFrameWidth;
377
+ const tmpY2 = tmpY1 + innerFrameHeight;
378
+ const frameArea = [tmpX1, tmpY1, tmpX2, tmpY2];
379
+ const overlaps = avoidAreas.filter(area => (0, utils_js_1.areasOverlap)(frameArea, area));
380
+ const doesOverlapAreasToAvoid = overlaps.length > 0;
381
+ if (doesExceedFrameWidth || doesOverlapAreasToAvoid) {
382
+ innerFrameX = offsetX.add(centeredOffsetX);
383
+ const { ymax } = getBoundsFromPoints(boundPoints);
384
+ const nextY = (0, ParamDefinition_js_1.numeric)(ymax).sub(offsetY).add(frame.gap);
385
+ innerFrameY = offsetY.add(nextY);
386
+ accumX = (0, ParamDefinition_js_1.numeric)(0);
387
+ accumY = nextY;
388
+ }
389
+ else {
390
+ break;
391
+ }
392
+ arrangeLineAttempts++;
393
+ if (arrangeLineAttempts > maxAttempts) {
394
+ throw "Failed to place inner frame";
395
+ }
396
+ }
397
+ innerFrame.x = innerFrameX;
398
+ innerFrame.y = innerFrameY;
399
+ accumX = accumX.add(innerFrameWidth).add(frame.gap);
284
400
  }
285
401
  }
286
- boundPoints.push([innerFrame.x, innerFrame.y], [innerFrame.x + frameWidth, innerFrame.y + frameHeight]);
402
+ boundPoints.push([
403
+ innerFrame.x.toNumber(),
404
+ innerFrame.y.toNumber()
405
+ ], [
406
+ innerFrame.x.add(innerFrameWidth).toNumber(),
407
+ innerFrame.y.add(innerFrameHeight).toNumber()
408
+ ]);
287
409
  });
288
- const contentsBounds = (0, utils_js_1.resizeBounds)(getBoundsFromPoints(boundPoints), frame.padding);
289
- if (frame.frame.parameters.has(Frame_js_1.FrameParamKeys.SheetType)) {
290
- const frameComponent = frame.frame.parameters.get(Frame_js_1.FrameParamKeys.SheetType);
291
- const frameDrawing = frameComponent.displayProp;
292
- frameDrawing.variables = (0, utils_js_1.combineMaps)(frameComponent.parameters, frame.frame.parameters);
293
- const rects = ExtractDrawingRects(frameDrawing);
294
- let frameWidth = 0;
295
- let frameHeight = 0;
296
- if (rects[1]) {
297
- frameWidth = (0, helpers_js_1.milsToMM)(rects[1].width);
298
- frameHeight = (0, helpers_js_1.milsToMM)(rects[1].height);
299
- }
300
- const contentsWidth = contentsBounds.xmax - contentsBounds.xmin;
301
- const contentsHeight = contentsBounds.ymax - contentsBounds.ymin;
302
- const frameOffsetX = (0, utils_js_1.toNearestGrid)((frameWidth - contentsWidth) / 2, gridSize);
303
- const frameOffsetY = (0, utils_js_1.toNearestGrid)((frameHeight - contentsHeight) / 2, gridSize);
304
- innerFrames.forEach(innerFrame => {
305
- innerFrame.x += frameOffsetX;
306
- innerFrame.y += frameOffsetY;
307
- });
308
- frame.bounds = {
309
- xmin: 0,
310
- ymin: 0,
311
- xmax: frameWidth,
312
- ymax: frameHeight
313
- };
410
+ const contentsBounds = (0, utils_js_1.resizeBounds)(getBoundsFromPoints(boundPoints), frame.padding.toNumber());
411
+ const contentsWidth = contentsBounds.xmax - contentsBounds.xmin;
412
+ const contentsHeight = contentsBounds.ymax - contentsBounds.ymin;
413
+ let hAlign = geometry_js_1.HorizontalAlign.Middle;
414
+ let vAlign = geometry_js_1.VerticalAlign.Middle;
415
+ if (frameParams.has(Frame_js_1.FrameParamKeys.HorizontalAlign)) {
416
+ hAlign =
417
+ frameParams.get(Frame_js_1.FrameParamKeys.HorizontalAlign);
418
+ }
419
+ if (frameParams.has(Frame_js_1.FrameParamKeys.VerticalAlign)) {
420
+ vAlign =
421
+ frameParams.get(Frame_js_1.FrameParamKeys.VerticalAlign);
422
+ }
423
+ if (frameParams.has(Frame_js_1.FrameParamKeys.SheetType)) {
424
+ frameXMin = (0, ParamDefinition_js_1.numeric)(0);
425
+ frameYMin = (0, ParamDefinition_js_1.numeric)(0);
314
426
  }
315
427
  else {
316
- frame.bounds = contentsBounds;
428
+ frameXMin = (0, ParamDefinition_js_1.numeric)(contentsBounds.xmin);
429
+ frameYMin = (0, ParamDefinition_js_1.numeric)(contentsBounds.ymin);
430
+ }
431
+ if (frameWidth.toNumber() === 0) {
432
+ frameWidth = (0, ParamDefinition_js_1.numeric)(contentsWidth);
433
+ }
434
+ if (frameHeight.toNumber() === 0) {
435
+ frameHeight = (0, ParamDefinition_js_1.numeric)(contentsHeight);
436
+ }
437
+ const titleFrame = innerFrames.find(frame => {
438
+ return frame.containsTitle;
439
+ });
440
+ if (titleFrame) {
441
+ const { width: innerFrameWidth } = (0, utils_js_1.getBoundsSize)(titleFrame.bounds);
442
+ let titleOffset = 0;
443
+ switch (title_align) {
444
+ case geometry_js_1.HorizontalAlign.Left:
445
+ titleOffset = 0;
446
+ break;
447
+ case geometry_js_1.HorizontalAlign.Middle:
448
+ titleOffset = (0, utils_js_1.toNearestGrid)(widthForTitle / 2 - innerFrameWidth / 2, gridSize);
449
+ break;
450
+ case geometry_js_1.HorizontalAlign.Right:
451
+ titleOffset = frameWidth.toNumber() - innerFrameWidth;
452
+ break;
453
+ }
454
+ titleFrame.x = titleFrame.x.add(titleOffset);
455
+ }
456
+ let frameOffsetX = 0;
457
+ let frameOffsetY = 0;
458
+ switch (hAlign) {
459
+ case geometry_js_1.HorizontalAlign.Left:
460
+ frameOffsetX = 0;
461
+ break;
462
+ case geometry_js_1.HorizontalAlign.Middle:
463
+ frameOffsetX = (0, utils_js_1.toNearestGrid)((frameWidth.toNumber() - contentsWidth) / 2, gridSize);
464
+ break;
465
+ case geometry_js_1.HorizontalAlign.Right:
466
+ frameOffsetX = (0, utils_js_1.toNearestGrid)(frameWidth.toNumber() - contentsWidth, gridSize);
467
+ break;
468
+ }
469
+ switch (vAlign) {
470
+ case geometry_js_1.VerticalAlign.Top:
471
+ frameOffsetY = 0;
472
+ break;
473
+ case geometry_js_1.VerticalAlign.Middle:
474
+ frameOffsetY = (0, utils_js_1.toNearestGrid)((frameHeight.toNumber() - contentsHeight) / 2, gridSize);
475
+ break;
476
+ case geometry_js_1.VerticalAlign.Bottom:
477
+ frameOffsetY = (0, utils_js_1.toNearestGrid)(frameHeight.toNumber() - contentsHeight, gridSize);
478
+ break;
317
479
  }
480
+ innerFrames.forEach(innerFrame => {
481
+ innerFrame.x = innerFrame.x.add(frameOffsetX);
482
+ innerFrame.y = innerFrame.y.add(frameOffsetY);
483
+ });
484
+ frame.bounds = {
485
+ xmin: frameXMin.toNumber(),
486
+ ymin: frameYMin.toNumber(),
487
+ xmax: frameXMin.toNumber() + frameWidth.toNumber(),
488
+ ymax: frameYMin.toNumber() + frameHeight.toNumber(),
489
+ };
318
490
  }
319
491
  dumpFrame(frame, level = 0) {
320
492
  this.print(level, "".padStart(level * 4), 'frame, items:', frame.innerItems.length);
321
493
  frame.innerItems.forEach(item => {
322
494
  item = item;
323
- if (item.type === RenderFrameType.Elements) {
324
- this.print(level, "".padStart(level * 4), 'element frame, items:', item.innerItems.map(item => {
495
+ if (item.renderType === RenderFrameType.Elements) {
496
+ this.print(level, "".padStart(level * 4), '- element frame, items:', item.innerItems.map(item => {
325
497
  if (item instanceof RenderComponent) {
326
498
  return item.component.instanceName;
327
499
  }
@@ -332,7 +504,7 @@ class LayoutEngine {
332
504
  }));
333
505
  }
334
506
  else {
335
- this.print(level, "".padStart(level * 4), 'container');
507
+ this.print(level, "".padStart(level * 4), '- container');
336
508
  this.dumpFrame(item, level + 1);
337
509
  }
338
510
  });
@@ -349,21 +521,21 @@ class LayoutEngine {
349
521
  accum.push(item);
350
522
  }
351
523
  else if (item instanceof RenderComponent) {
352
- const instanceName = item.component.instanceName;
524
+ const { instanceName } = item.component;
353
525
  if (ignoreItems.indexOf(instanceName) === -1) {
354
- const subgraph = subgraphInfo.find(item => {
355
- return item.components.indexOf(instanceName) !== -1;
526
+ const withinSubgraph = subgraphInfo.find(subgraphInfo => {
527
+ return subgraphInfo.components.indexOf(instanceName) !== -1;
356
528
  });
357
- if (subgraph !== undefined) {
358
- const tmpFrame = new RenderFrame(new Frame_js_1.Frame(-2), RenderFrameType.Elements);
529
+ if (withinSubgraph !== undefined) {
530
+ const tmpFrame = new RenderFrame(new Frame_js_1.Frame(Frame_js_1.FixedFrameIds.FrameIdNotUsed), RenderFrameType.Elements);
359
531
  tmpFrame.subgraphId = instanceName;
360
532
  tmpFrame.innerItems =
361
- subgraph.components.map(instanceName => {
533
+ withinSubgraph.components.map(instanceName => {
362
534
  const [, component,] = graph.node(instanceName);
363
535
  return component;
364
536
  });
365
- tmpFrame.bounds = subgraph.bounds;
366
- ignoreItems.push(...subgraph.components);
537
+ tmpFrame.bounds = withinSubgraph.bounds;
538
+ ignoreItems.push(...withinSubgraph.components);
367
539
  accum.push(tmpFrame);
368
540
  elementFrames.push(tmpFrame);
369
541
  }
@@ -374,16 +546,23 @@ class LayoutEngine {
374
546
  }
375
547
  return accum;
376
548
  }, []);
377
- if (frame.type === RenderFrameType.Container) {
549
+ this.checkAddFrameTitle(frame, elementFrames, textObjects, level);
550
+ return {
551
+ elementFrames,
552
+ textObjects,
553
+ };
554
+ }
555
+ checkAddFrameTitle(frame, elementFrames, textObjects, level) {
556
+ if (frame.renderType === RenderFrameType.Container) {
378
557
  const frameObject = frame.frame;
379
558
  const isSheetFrame = frameObject.frameType === globals_js_1.FrameType.Sheet;
380
559
  if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Title) && !isSheetFrame) {
381
560
  const title = frameObject.parameters.get(Frame_js_1.FrameParamKeys.Title);
382
- const tmpFrame = new RenderFrame(new Frame_js_1.Frame(-2), RenderFrameType.Elements);
561
+ const tmpFrame = new RenderFrame(new Frame_js_1.Frame(Frame_js_1.FixedFrameIds.FrameIdNotUsed), RenderFrameType.Elements);
383
562
  tmpFrame.containsTitle = true;
384
563
  tmpFrame.subgraphId = title.replace(/\s/g, "_");
385
564
  const textObject = new RenderText(title);
386
- textObject.fontSize = globals_js_1.defaultFrameTitleTextSize;
565
+ textObject.fontSize = (0, ParamDefinition_js_1.numeric)(globals_js_1.defaultFrameTitleTextSize);
387
566
  textObject.fontWeight = 'bold';
388
567
  textObject.symbol.refreshDrawing();
389
568
  tmpFrame.innerItems.push(textObject);
@@ -394,18 +573,14 @@ class LayoutEngine {
394
573
  xmax: tmpBox.start[0] + tmpBox.width,
395
574
  ymax: tmpBox.start[1] + tmpBox.height
396
575
  };
397
- textObject.x = 0;
398
- textObject.y = 0;
576
+ textObject.x = (0, ParamDefinition_js_1.numeric)(0);
577
+ textObject.y = (0, ParamDefinition_js_1.numeric)(0);
399
578
  frame.innerItems.splice(0, 0, tmpFrame);
400
579
  this.printLevel(level, frame, 'added text', tmpFrame);
401
580
  textObjects.push(textObject);
402
581
  elementFrames.splice(0, 0, tmpFrame);
403
582
  }
404
583
  }
405
- return {
406
- elementFrames,
407
- textObjects,
408
- };
409
584
  }
410
585
  generateLayoutGraph(sequence, nets) {
411
586
  let previousNode = null;
@@ -415,161 +590,155 @@ class LayoutEngine {
415
590
  compound: true,
416
591
  });
417
592
  this.print('sequence length:', sequence.length);
418
- const baseRenderFrame = new RenderFrame(new Frame_js_1.Frame(-1));
419
- const frameStack = [baseRenderFrame];
420
- const containerFrames = [baseRenderFrame];
421
- for (let i = 0; i < sequence.length; i++) {
422
- const action = sequence[i][0];
593
+ const baseFrame = new RenderFrame(new Frame_js_1.Frame(Frame_js_1.FixedFrameIds.BaseFrame));
594
+ const frameStack = [baseFrame];
595
+ const containerFrames = [baseFrame];
596
+ sequence.forEach((sequenceStep, index) => {
597
+ const action = sequenceStep[0];
423
598
  let tmpComponent;
424
- if (action === ExecutionScope_js_1.SequenceAction.At || action === ExecutionScope_js_1.SequenceAction.To) {
425
- this.print(...sequence[i]);
426
- const component = sequence[i][1];
427
- const pin = sequence[i][2];
428
- const tmpInstanceName = component.instanceName;
429
- if (!graph.hasNode(tmpInstanceName)) {
430
- this.print('create instance', tmpInstanceName);
431
- let { displayProp = null, widthProp = null, typeProp = null } = component;
432
- let tmpSymbol;
433
- if (displayProp === null &&
434
- component.parameters.get(globals_js_1.ParamKeys.net_name) === globals_js_1.GlobalNames.gnd) {
435
- displayProp = 'gnd';
436
- }
437
- if (displayProp !== null) {
599
+ switch (action) {
600
+ case ExecutionScope_js_1.SequenceAction.To:
601
+ case ExecutionScope_js_1.SequenceAction.At: {
602
+ this.print(...sequenceStep);
603
+ const [, component, pin] = sequenceStep;
604
+ const tmpInstanceName = component.instanceName;
605
+ if (!graph.hasNode(tmpInstanceName)) {
606
+ this.print('create instance', tmpInstanceName);
607
+ const { displayProp = null, widthProp = null, heightProp = null } = component;
608
+ let tmpSymbol;
438
609
  if (displayProp instanceof draw_symbols_js_1.SymbolDrawing) {
439
610
  tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(displayProp);
440
611
  tmpSymbol.drawing.logger = this.logger;
441
612
  }
442
- else if (typeof displayProp === "string") {
443
- tmpSymbol = (0, draw_symbols_js_1.SymbolFactory)(displayProp);
613
+ else {
614
+ const symbolPinDefinitions = generateLayoutPinDefinition(component);
615
+ if (component.typeProp === globals_js_1.ComponentTypes.module) {
616
+ tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions, component.pinsMaxPositions);
617
+ }
618
+ else {
619
+ tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
620
+ }
444
621
  }
445
- }
446
- else {
447
- const symbolPinDefinitions = generateLayoutPinDefinition(component);
448
- if (component.typeProp === 'module') {
449
- tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions);
622
+ applyComponentParamsToSymbol(component, tmpSymbol);
623
+ if (component.parameters.has(globals_js_1.ParamKeys.angle)) {
624
+ const value = component.parameters.get(globals_js_1.ParamKeys.angle).toNumber();
625
+ tmpSymbol.angle = value;
450
626
  }
451
- else {
452
- tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions);
627
+ if (component.parameters.has(globals_js_1.ParamKeys.flipX)) {
628
+ tmpSymbol.flipX =
629
+ component.parameters.get(globals_js_1.ParamKeys.flipX);
453
630
  }
631
+ if (component.parameters.has(globals_js_1.ParamKeys.flipY)) {
632
+ tmpSymbol.flipY =
633
+ component.parameters.get(globals_js_1.ParamKeys.flipY);
634
+ }
635
+ if (tmpSymbol instanceof draw_symbols_js_1.SymbolCustom) {
636
+ if (widthProp) {
637
+ tmpSymbol.bodyWidth = (0, helpers_js_1.milsToMM)(widthProp);
638
+ }
639
+ if (heightProp) {
640
+ tmpSymbol.bodyHeight = (0, helpers_js_1.milsToMM)(heightProp);
641
+ }
642
+ }
643
+ tmpSymbol.refreshDrawing();
644
+ const { width: useWidth, height: useHeight } = tmpSymbol.size();
645
+ tmpComponent = new RenderComponent(component, useWidth, useHeight);
646
+ tmpComponent.symbol = tmpSymbol;
647
+ graph.setNode(tmpInstanceName, [RenderItemType.Component, tmpComponent, index]);
648
+ const currentFrame = frameStack[frameStack.length - 1];
649
+ currentFrame && currentFrame.innerItems.push(tmpComponent);
454
650
  }
455
- applyComponentParamsToSymbol(component, tmpSymbol);
456
- let didSetAngle = false;
457
- if (component.parameters.has('angle')) {
458
- didSetAngle = true;
459
- tmpSymbol.angle = component.parameters.get('angle');
460
- }
461
- if (component.parameters.has('flipX')) {
462
- tmpSymbol.flipX =
463
- component.parameters.get('flipX');
464
- }
465
- if (component.parameters.has('flipY')) {
466
- tmpSymbol.flipY =
467
- component.parameters.get('flipY');
468
- }
469
- if (tmpSymbol instanceof draw_symbols_js_1.SymbolCustom && widthProp) {
470
- tmpSymbol.bodyWidth = (0, helpers_js_1.milsToMM)(widthProp);
471
- }
472
- if (!didSetAngle && component.parameters.has('_addDirection')) {
473
- tmpSymbol.refreshDrawing(false);
474
- tmpSymbol.angle = calculateSymbolAngle(tmpSymbol, component.parameters.get('_addPin'), component.parameters.get('_addDirection'));
651
+ if (action === ExecutionScope_js_1.SequenceAction.To && previousNode && previousPin) {
652
+ this.setGraphEdge(graph, previousNode, tmpInstanceName, makeEdgeValue(previousNode, previousPin, tmpInstanceName, pin, index));
475
653
  }
476
- tmpSymbol.refreshDrawing();
477
- const { width: useWidth, height: useHeight } = tmpSymbol.size();
478
- tmpComponent = new RenderComponent(component, useWidth, useHeight);
479
- tmpComponent.symbol = tmpSymbol;
480
- graph.setNode(tmpInstanceName, [RenderItemType.Component, tmpComponent, i]);
481
- const currentFrame = frameStack[frameStack.length - 1];
482
- currentFrame && currentFrame.innerItems.push(tmpComponent);
654
+ previousNode = tmpInstanceName;
655
+ previousPin = pin;
656
+ break;
483
657
  }
484
- if (action === ExecutionScope_js_1.SequenceAction.To) {
485
- this.setGraphEdge(graph, previousNode, tmpInstanceName, makeEdgeValue(previousNode, previousPin, tmpInstanceName, pin, i));
486
- }
487
- previousNode = tmpInstanceName;
488
- previousPin = pin;
489
- }
490
- else if (action === ExecutionScope_js_1.SequenceAction.Wire) {
491
- const [, wireId, wireSegments] = sequence[i];
492
- const wire = new RenderWire(0, 0, wireSegments);
493
- wire.id = wireId;
494
- let useNetName = null;
495
- if (previousNode !== null) {
496
- const [prevNodeType, prevNodeItem] = graph.node(previousNode);
497
- if (prevNodeType === RenderItemType.Component) {
498
- const matchingItem = nets.find(([comp, pin]) => {
499
- return comp.instanceName === previousNode && pin === previousPin;
500
- });
501
- useNetName = matchingItem !== undefined ? matchingItem[2].name : null;
502
- }
503
- else if (prevNodeType === RenderItemType.Wire) {
504
- useNetName = prevNodeItem.netName;
658
+ case ExecutionScope_js_1.SequenceAction.Wire: {
659
+ const [, wireId, wireSegments] = sequenceStep;
660
+ const wire = new RenderWire((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), wireSegments);
661
+ wire.id = wireId;
662
+ let useNetName = null;
663
+ if (previousNode !== null) {
664
+ const [prevNodeType, prevNodeItem] = graph.node(previousNode);
665
+ if (prevNodeType === RenderItemType.Component) {
666
+ const matchingItem = nets.find(([comp, pin]) => {
667
+ return comp.instanceName === previousNode && pin === previousPin;
668
+ });
669
+ useNetName = matchingItem !== undefined ? matchingItem[2].name : null;
670
+ }
671
+ else if (prevNodeType === RenderItemType.Wire) {
672
+ useNetName = prevNodeItem.netName;
673
+ }
505
674
  }
675
+ wire.netName = useNetName;
676
+ const wireName = getWireName(wire.id);
677
+ graph.setNode(wireName, [RenderItemType.Wire, wire, index]);
678
+ this.setGraphEdge(graph, previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, index));
679
+ previousNode = wireName;
680
+ previousPin = 1;
681
+ const wireSegmentsInfo = wireSegments.map(item => {
682
+ const tmp = {
683
+ direction: item.direction,
684
+ value: item.value,
685
+ };
686
+ if (item.valueXY) {
687
+ tmp.valueXY = item.valueXY;
688
+ }
689
+ if (item.until) {
690
+ tmp.until = [item.until[0].toString(), item.until[1]];
691
+ }
692
+ return tmp;
693
+ });
694
+ this.print(ExecutionScope_js_1.SequenceAction.Wire, wireId, JSON.stringify(wireSegmentsInfo));
695
+ break;
506
696
  }
507
- wire.netName = useNetName;
508
- const wireName = getWireName(wire.id);
509
- graph.setNode(wireName, [RenderItemType.Wire, wire, i]);
510
- this.setGraphEdge(graph, previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, i));
511
- previousNode = wireName;
512
- previousPin = 1;
513
- const wireSegmentsInfo = wireSegments.map(item => {
514
- const tmp = {
515
- direction: item.direction,
516
- value: item.value,
517
- };
518
- if (item.valueXY) {
519
- tmp.valueXY = item.valueXY;
697
+ case ExecutionScope_js_1.SequenceAction.WireJump: {
698
+ this.print(...sequenceStep);
699
+ const wireId = sequenceStep[1];
700
+ const wireName = getWireName(wireId);
701
+ let wirePin = 1;
702
+ if (sequenceStep.length === 3) {
703
+ wirePin = sequenceStep[2];
520
704
  }
521
- if (item.until) {
522
- tmp.until = [item.until[0].toString(), item.until[1]];
523
- }
524
- return tmp;
525
- });
526
- this.print(ExecutionScope_js_1.SequenceAction.Wire, wireId, JSON.stringify(wireSegmentsInfo));
527
- }
528
- else if (action === ExecutionScope_js_1.SequenceAction.WireJump) {
529
- this.print(...sequence[i]);
530
- const wireId = sequence[i][1];
531
- const wireName = getWireName(wireId);
532
- let wirePin = 1;
533
- if (sequence[i].length === 3) {
534
- wirePin = sequence[i][2];
705
+ previousNode = wireName;
706
+ previousPin = wirePin;
707
+ break;
535
708
  }
536
- previousNode = wireName;
537
- previousPin = wirePin;
538
- }
539
- else if (action === ExecutionScope_js_1.SequenceAction.Frame) {
540
- const [, frameObject, frameAction] = sequence[i];
541
- if (frameAction === ExecutionScope_js_1.FrameAction.Enter) {
542
- const prevFrame = frameStack[frameStack.length - 1];
543
- const newFrame = new RenderFrame(frameObject);
544
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Direction)) {
545
- newFrame.direction =
546
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Direction);
547
- }
548
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Padding)) {
549
- newFrame.padding =
550
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Padding);
551
- }
552
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Border)) {
553
- newFrame.borderWidth =
554
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Border);
555
- }
556
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Width)) {
557
- newFrame.width =
558
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Width);
709
+ case ExecutionScope_js_1.SequenceAction.Frame: {
710
+ const [, frameObject, frameAction] = sequenceStep;
711
+ if (frameAction === ExecutionScope_js_1.FrameAction.Enter) {
712
+ const prevFrame = frameStack[frameStack.length - 1];
713
+ const newFrame = new RenderFrame(frameObject);
714
+ if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Direction)) {
715
+ newFrame.direction =
716
+ frameObject.parameters.get(Frame_js_1.FrameParamKeys.Direction);
717
+ }
718
+ if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Padding)) {
719
+ newFrame.padding = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Padding));
720
+ }
721
+ if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Border)) {
722
+ newFrame.borderWidth =
723
+ frameObject.parameters.get(Frame_js_1.FrameParamKeys.Border);
724
+ }
725
+ if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Width)) {
726
+ newFrame.width = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Width));
727
+ }
728
+ if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Height)) {
729
+ newFrame.height = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Height));
730
+ }
731
+ containerFrames.push(newFrame);
732
+ frameStack.push(newFrame);
733
+ prevFrame && prevFrame.innerItems.push(newFrame);
559
734
  }
560
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Height)) {
561
- newFrame.height =
562
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Height);
735
+ else if (frameAction === ExecutionScope_js_1.FrameAction.Exit) {
736
+ frameStack.pop();
563
737
  }
564
- containerFrames.push(newFrame);
565
- frameStack.push(newFrame);
566
- prevFrame && prevFrame.innerItems.push(newFrame);
567
- }
568
- else if (frameAction === ExecutionScope_js_1.FrameAction.Exit) {
569
- frameStack.pop();
738
+ break;
570
739
  }
571
740
  }
572
- }
741
+ });
573
742
  return {
574
743
  graph,
575
744
  containerFrames,
@@ -584,10 +753,10 @@ class LayoutEngine {
584
753
  this.print('===== placing subgraphs =====');
585
754
  this.print('number of subgraphs: ', subGraphs.length);
586
755
  const subgraphInfo = [];
587
- subGraphs.forEach(innerGraph => {
756
+ subGraphs.forEach(subGraph => {
588
757
  let smallestNodeIdLevel = Number.POSITIVE_INFINITY;
589
- let smallestNodeId = null;
590
- innerGraph.forEach(nodeId => {
758
+ let smallestNodeId = "";
759
+ subGraph.forEach(nodeId => {
591
760
  const [, , sequenceId] = graph.node(nodeId);
592
761
  if (sequenceId < smallestNodeIdLevel) {
593
762
  smallestNodeIdLevel = sequenceId;
@@ -630,12 +799,7 @@ class LayoutEngine {
630
799
  }
631
800
  return accum;
632
801
  }, []);
633
- if (this.placeSubgraphVersion === 1) {
634
- this.placeSubgraph(graph, firstNodeId, subgraphEdges);
635
- }
636
- else if (this.placeSubgraphVersion === 2) {
637
- this.placeSubgraphV2(graph, firstNodeId, subgraphEdges);
638
- }
802
+ this.placeSubgraphV2(graph, firstNodeId, subgraphEdges);
639
803
  }
640
804
  placeSubgraphV2(graph, firstNodeId, subgraphEdges) {
641
805
  let firstNodePlaced = false;
@@ -653,7 +817,7 @@ class LayoutEngine {
653
817
  }
654
818
  if (subgraphEdges.length === 0) {
655
819
  const [, node1] = graph.node(firstNodeId);
656
- this.placeNodeAtPosition(0, 0, node1, 1);
820
+ this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, 1);
657
821
  return;
658
822
  }
659
823
  let fixedNode;
@@ -666,7 +830,7 @@ class LayoutEngine {
666
830
  const [, node2] = graph.node(nodeId2);
667
831
  if (nodeId1 === firstNodeId && !firstNodePlaced) {
668
832
  this.print('first node placed at origin');
669
- this.placeNodeAtPosition(0, 0, node1, pin1);
833
+ this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, pin1);
670
834
  firstNodePlaced = true;
671
835
  node1.isFloating = false;
672
836
  originNodes.push(node1);
@@ -689,7 +853,7 @@ class LayoutEngine {
689
853
  originNodes.push(node1);
690
854
  originNodeGroups.set(node1.toString(), [node1]);
691
855
  this.print('creating new origin node at', node1);
692
- this.placeNodeAtPosition(0, 0, node1, pin1);
856
+ this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, pin1);
693
857
  node1.isFloating = false;
694
858
  fixedNode = node1;
695
859
  fixedNodePin = pin1;
@@ -706,7 +870,7 @@ class LayoutEngine {
706
870
  else {
707
871
  const [x1, y1] = getNodePositionAtPin(node1, pin1);
708
872
  const [x2, y2] = getNodePositionAtPin(node2, pin2);
709
- if (x1 !== x2 && y1 !== y2) {
873
+ if (!x1.eq(x2) && !y1.eq(y2)) {
710
874
  if (node1 instanceof RenderWire &&
711
875
  node2 instanceof RenderComponent) {
712
876
  const refdes = node2.component.assignedRefDes;
@@ -783,8 +947,8 @@ class LayoutEngine {
783
947
  this.print('merging origin node groups, fixed:', keepOriginNode, ', other:', otherOriginNode);
784
948
  const [x, y] = getNodePositionAtPin(fixedNode, fixedNodePin);
785
949
  const [otherNodeOriginX, otherNodeOriginY] = getNodePositionAtPin(mergedNode, mergedNodePin);
786
- const offsetX = x - otherNodeOriginX;
787
- const offsetY = y - otherNodeOriginY;
950
+ const offsetX = x.sub(otherNodeOriginX);
951
+ const offsetY = y.sub(otherNodeOriginY);
788
952
  this.print('offset of other origin:', offsetX, offsetY);
789
953
  const otherItemsLinkedToOriginNode = originNodeGroups.get(otherOriginNode);
790
954
  this.print('nodes in other origin:', otherItemsLinkedToOriginNode);
@@ -798,68 +962,15 @@ class LayoutEngine {
798
962
  this.print('removed other origin');
799
963
  this.print('merge completed');
800
964
  }
801
- placeSubgraph(graph, firstNodeId, subgraphEdges) {
802
- let firstNodePlaced = false;
803
- subgraphEdges.forEach(edge => {
804
- const [nodeId1, pin1, nodeId2, pin2] = graph.edge(edge);
805
- const [, node1] = graph.node(nodeId1);
806
- const [, node2] = graph.node(nodeId2);
807
- if (nodeId1 === firstNodeId && !firstNodePlaced) {
808
- this.print('first node placed at origin');
809
- this.placeNodeAtPosition(0, 0, node1, pin1);
810
- firstNodePlaced = true;
811
- node1.isFloating = false;
812
- }
813
- let fixedNode;
814
- let fixedNodePin;
815
- let floatingNode;
816
- let floatingNodePin;
817
- this.print('edge:', '[', node1, pin1, node1.isFloating, ']', '[', node2, pin2, node2.isFloating, ']');
818
- if (!node1.isFloating && node2.isFloating) {
819
- fixedNode = node1;
820
- fixedNodePin = pin1;
821
- floatingNode = node2;
822
- floatingNodePin = pin2;
823
- }
824
- else if (node1.isFloating && !node2.isFloating) {
825
- fixedNode = node2;
826
- fixedNodePin = pin2;
827
- floatingNode = node1;
828
- floatingNodePin = pin1;
829
- }
830
- else if (node1.isFloating && node2.isFloating) {
831
- this.print('both nodes are floating', node1, 'pin', pin1, 'and', node2, 'pin', pin2);
832
- node1.floatingRelativeTo.push([pin1, nodeId2, pin2]);
833
- node2.floatingRelativeTo.push([pin2, nodeId1, pin1]);
834
- }
835
- if (fixedNode && floatingNode) {
836
- this.print('place floating node', floatingNode, 'pin', floatingNodePin, 'to', fixedNode, 'pin', fixedNodePin);
837
- const [x, y] = getNodePositionAtPin(fixedNode, fixedNodePin);
838
- this.placeNodeAtPosition(x, y, floatingNode, floatingNodePin);
839
- floatingNode.isFloating = false;
840
- this.placeFloatingItems(graph, floatingNode);
841
- }
842
- [node1, node2].forEach(item => {
843
- if (item instanceof RenderWire) {
844
- if (item.isEndAutoLength()) {
845
- const [instance, pin] = item.getEndAuto();
846
- const [, targetNode] = graph.node(instance.instanceName);
847
- const [untilX, untilY] = getNodePositionAtPin(targetNode, pin);
848
- item.setEndAuto(untilX, untilY);
849
- }
850
- }
851
- });
852
- });
853
- }
854
965
  translateNodeBy(offsetX, offsetY, item) {
855
- item.x += offsetX;
856
- item.y += offsetY;
966
+ item.x = item.x.add(offsetX);
967
+ item.y = item.y.add(offsetY);
857
968
  }
858
969
  placeNodeAtPosition(fromX, fromY, item, pin, depth = 0) {
859
970
  if (item instanceof RenderComponent) {
860
971
  const pinPosition = item.symbol.pinPosition(pin);
861
- item.x = fromX - pinPosition.x;
862
- item.y = fromY - pinPosition.y;
972
+ item.x = fromX.sub(pinPosition.x);
973
+ item.y = fromY.sub(pinPosition.y);
863
974
  }
864
975
  else if (item instanceof RenderWire) {
865
976
  if (pin === 0) {
@@ -868,8 +979,8 @@ class LayoutEngine {
868
979
  }
869
980
  else {
870
981
  const wireEnd = item.getWireEnd();
871
- item.x = fromX - wireEnd.x;
872
- item.y = fromY - wireEnd.y;
982
+ item.x = fromX.sub(wireEnd.x);
983
+ item.y = fromY.sub(wireEnd.y);
873
984
  }
874
985
  }
875
986
  this.print(this.padLevel(depth), 'place', item, 'pin', pin, 'at', item.x, item.y);
@@ -909,12 +1020,12 @@ class LayoutEngine {
909
1020
  }
910
1021
  exports.LayoutEngine = LayoutEngine;
911
1022
  function getNodePositionAtPin(item, pin) {
912
- let x = 0;
913
- let y = 0;
1023
+ let x = (0, ParamDefinition_js_1.numeric)(0);
1024
+ let y = (0, ParamDefinition_js_1.numeric)(0);
914
1025
  if (item instanceof RenderComponent) {
915
1026
  const pinPosition = item.symbol.pinPosition(pin);
916
- x = item.x + pinPosition.x;
917
- y = item.y + pinPosition.y;
1027
+ x = item.x.add(pinPosition.x);
1028
+ y = item.y.add(pinPosition.y);
918
1029
  }
919
1030
  else if (item instanceof RenderWire) {
920
1031
  if (pin === 0) {
@@ -923,8 +1034,8 @@ function getNodePositionAtPin(item, pin) {
923
1034
  }
924
1035
  else {
925
1036
  const wireEnd = item.getWireEnd();
926
- x = item.x + wireEnd.x;
927
- y = item.y + wireEnd.y;
1037
+ x = item.x.add(wireEnd.x);
1038
+ y = item.y.add(wireEnd.y);
928
1039
  }
929
1040
  }
930
1041
  return [
@@ -957,7 +1068,7 @@ function generateLayoutPinDefinition(component) {
957
1068
  const pinPosition = Math.floor(i / 2);
958
1069
  const pin = pins.get(existingPinIds[i]);
959
1070
  symbolPinDefinitions.push({
960
- side: (i % 2 === 0) ? "left" : "right",
1071
+ side: (i % 2 === 0) ? globals_js_1.SymbolPinSide.Left : globals_js_1.SymbolPinSide.Right,
961
1072
  pinId: existingPinIds[i],
962
1073
  text: pin.name,
963
1074
  position: pinPosition,
@@ -976,24 +1087,24 @@ function generateLayoutPinDefinition(component) {
976
1087
  useItems = [...items];
977
1088
  }
978
1089
  useItems.forEach(pinId => {
979
- if (existingPinIds.indexOf(pinId) !== -1) {
980
- const pin = pins.get(pinId);
981
- symbolPinDefinitions.push({
982
- side: key,
983
- pinId: pinId,
984
- text: pin.name,
985
- position: pin.position,
986
- pinType: pin.pinType,
987
- });
988
- addedPins.push(pinId);
1090
+ if (pinId instanceof ParamDefinition_js_1.NumericValue) {
1091
+ const pinIdValue = pinId.toNumber();
1092
+ if (existingPinIds.indexOf(pinIdValue) !== -1) {
1093
+ const pin = pins.get(pinIdValue);
1094
+ symbolPinDefinitions.push({
1095
+ side: key,
1096
+ pinId: pinIdValue,
1097
+ text: pin.name,
1098
+ position: pin.position,
1099
+ pinType: pin.pinType,
1100
+ });
1101
+ addedPins.push(pinIdValue);
1102
+ }
989
1103
  }
990
1104
  });
991
1105
  }
992
- const unplacedPins = [];
993
- existingPinIds.forEach(item => {
994
- if (addedPins.indexOf(item) === -1) {
995
- unplacedPins.push(item);
996
- }
1106
+ const unplacedPins = existingPinIds.filter(pinId => {
1107
+ return addedPins.indexOf(pinId) === -1;
997
1108
  });
998
1109
  if (unplacedPins.length > 0) {
999
1110
  throw "'arrange' property is defined, but not all pins are specified: " + unplacedPins.join(",");
@@ -1035,21 +1146,21 @@ function getBounds(components, wires, junctions, frames) {
1035
1146
  const bbox = item.symbol.drawing.getBoundingBox();
1036
1147
  const [x1, y1] = bbox.start;
1037
1148
  const [x2, y2] = bbox.end;
1038
- points.push([x1 + item.x, y1 + item.y]);
1039
- points.push([x2 + item.x, y2 + item.y]);
1149
+ points.push([x1 + item.x.toNumber(), y1 + item.y.toNumber()]);
1150
+ points.push([x2 + item.x.toNumber(), y2 + item.y.toNumber()]);
1040
1151
  });
1041
1152
  wires.forEach(wire => {
1042
1153
  wire.points.forEach(point => {
1043
- points.push([wire.x + point.x, wire.y + point.y]);
1154
+ points.push([wire.x.add(point.x).toNumber(), wire.y.add(point.y).toNumber()]);
1044
1155
  });
1045
1156
  });
1046
1157
  junctions.forEach(item => {
1047
- points.push([item.x, item.y]);
1158
+ points.push([item.x.toNumber(), item.y.toNumber()]);
1048
1159
  });
1049
1160
  frames.forEach(item => {
1050
1161
  const { width, height } = (0, utils_js_1.getBoundsSize)(item.bounds);
1051
- points.push([item.x, item.y]);
1052
- points.push([item.x + width, item.y + height]);
1162
+ points.push([item.x.toNumber(), item.y.toNumber()]);
1163
+ points.push([item.x.toNumber() + width, item.y.toNumber() + height]);
1053
1164
  });
1054
1165
  return getBoundsFromPoints(points);
1055
1166
  }
@@ -1067,8 +1178,8 @@ function getBoundsFromPoints(points) {
1067
1178
  }
1068
1179
  class RenderObject {
1069
1180
  constructor() {
1070
- this.x = -1;
1071
- this.y = -1;
1181
+ this.x = (0, ParamDefinition_js_1.numeric)(-1);
1182
+ this.y = (0, ParamDefinition_js_1.numeric)(-1);
1072
1183
  this.isFloating = true;
1073
1184
  this.floatingRelativeTo = [];
1074
1185
  }
@@ -1111,7 +1222,7 @@ class RenderWire extends RenderObject {
1111
1222
  tmpX += useValue;
1112
1223
  }
1113
1224
  else if (direction === globals_js_1.WireAutoDirection.Auto || direction === globals_js_1.WireAutoDirection.Auto_) {
1114
- const { valueXY = [0, 0] } = segment;
1225
+ const { valueXY = [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)] } = segment;
1115
1226
  const tmpPoints = this.getAutoPoints(valueXY, direction);
1116
1227
  tmpPoints.forEach(point => {
1117
1228
  if (point[0] !== 0 || point[1] !== 0) {
@@ -1129,8 +1240,8 @@ class RenderWire extends RenderObject {
1129
1240
  this.points = points;
1130
1241
  }
1131
1242
  getAutoPoints(value, direction) {
1132
- const valueX = (0, utils_js_1.roundValue)(value[0]);
1133
- const valueY = (0, utils_js_1.roundValue)(value[1]);
1243
+ const valueX = (0, utils_js_1.roundValue)(value[0]).toNumber();
1244
+ const valueY = (0, utils_js_1.roundValue)(value[1]).toNumber();
1134
1245
  const inQuadrant = geometry_js_1.Geometry.getQuadrant(valueX, valueY);
1135
1246
  const [dx, dy] = [valueX, valueY];
1136
1247
  if (direction === globals_js_1.WireAutoDirection.Auto) {
@@ -1186,16 +1297,16 @@ class RenderWire extends RenderObject {
1186
1297
  useValue = value;
1187
1298
  }
1188
1299
  if (direction === types_js_1.Direction.Down) {
1189
- tmpY += useValue;
1300
+ tmpY = tmpY.add(useValue);
1190
1301
  }
1191
1302
  else if (direction === types_js_1.Direction.Up) {
1192
- tmpY -= useValue;
1303
+ tmpY = tmpY.sub(useValue);
1193
1304
  }
1194
1305
  else if (direction === types_js_1.Direction.Left) {
1195
- tmpX -= useValue;
1306
+ tmpX = tmpX.sub(useValue);
1196
1307
  }
1197
1308
  else if (direction === types_js_1.Direction.Right) {
1198
- tmpX += useValue;
1309
+ tmpX = tmpX.add(useValue);
1199
1310
  }
1200
1311
  });
1201
1312
  let useValue = null;
@@ -1203,22 +1314,22 @@ class RenderWire extends RenderObject {
1203
1314
  const lastSegment = this.segments[this.segments.length - 1];
1204
1315
  switch (lastSegment.direction) {
1205
1316
  case types_js_1.Direction.Left:
1206
- useValue = tmpX - untilX;
1317
+ useValue = tmpX.sub(untilX);
1207
1318
  break;
1208
1319
  case types_js_1.Direction.Right:
1209
- useValue = untilX - tmpX;
1320
+ useValue = untilX.sub(tmpX);
1210
1321
  break;
1211
1322
  case types_js_1.Direction.Up:
1212
- useValue = untilY - tmpY;
1323
+ useValue = untilY.sub(tmpY);
1213
1324
  break;
1214
1325
  case types_js_1.Direction.Down:
1215
- useValue = tmpY - untilY;
1326
+ useValue = tmpY.sub(untilY);
1216
1327
  break;
1217
1328
  case globals_js_1.WireAutoDirection.Auto:
1218
1329
  case globals_js_1.WireAutoDirection.Auto_:
1219
1330
  valueXY = [
1220
- untilX - tmpX,
1221
- untilY - tmpY,
1331
+ untilX.sub(tmpX),
1332
+ untilY.sub(tmpY),
1222
1333
  ];
1223
1334
  useValue = 0;
1224
1335
  break;
@@ -1269,7 +1380,7 @@ class RenderText extends RenderObject {
1269
1380
  }
1270
1381
  constructor(text) {
1271
1382
  super();
1272
- this._fontSize = 12;
1383
+ this._fontSize = (0, ParamDefinition_js_1.numeric)(12);
1273
1384
  this._fontWeight = 'regular';
1274
1385
  this.symbol = new draw_symbols_js_1.SymbolText(text);
1275
1386
  }
@@ -1284,25 +1395,25 @@ class RenderFrame extends RenderObject {
1284
1395
  this.translateY = 0;
1285
1396
  this.padding = (0, helpers_js_1.milsToMM)(100);
1286
1397
  this.gap = (0, helpers_js_1.milsToMM)(100);
1398
+ this.borderWidth = (0, ParamDefinition_js_1.numeric)(5);
1287
1399
  this.direction = Frame_js_1.FramePlotDirection.Column;
1288
- this.borderWidth = 5;
1289
1400
  this.width = null;
1290
1401
  this.height = null;
1291
- this.size = null;
1292
1402
  this.subgraphId = "";
1293
1403
  this.containsTitle = false;
1294
1404
  this.frame = frame;
1295
- this.type = type;
1405
+ this.renderType = type;
1296
1406
  }
1297
1407
  toString() {
1298
1408
  let name = "";
1299
- if (this.type === RenderFrameType.Container) {
1409
+ if (this.renderType === RenderFrameType.Container) {
1300
1410
  name = 'container_' + this.frame.frameId;
1301
1411
  }
1302
- else if (this.type === RenderFrameType.Elements) {
1412
+ else if (this.renderType === RenderFrameType.Elements) {
1303
1413
  name = 'elements_' + this.subgraphId;
1304
1414
  }
1305
- return name + ": " + this.x + "," + this.y + " bounds:" + (0, utils_js_1.printBounds)(this.bounds);
1415
+ return name + ": " + this.x + "," + this.y
1416
+ + " bounds:" + (this.bounds && (0, utils_js_1.printBounds)(this.bounds));
1306
1417
  }
1307
1418
  }
1308
1419
  exports.RenderFrame = RenderFrame;
@@ -1327,7 +1438,7 @@ function CalculatePinPositions(component) {
1327
1438
  }
1328
1439
  else {
1329
1440
  const symbolPinDefinitions = generateLayoutPinDefinition(component);
1330
- tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions);
1441
+ tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
1331
1442
  }
1332
1443
  applyComponentParamsToSymbol(component, tmpSymbol);
1333
1444
  tmpSymbol.refreshDrawing();
@@ -1342,9 +1453,17 @@ function ExtractDrawingRects(drawing) {
1342
1453
  return drawing.getCommands().filter(item => {
1343
1454
  return (item[0] === draw_symbols_js_1.PlaceHolderCommands.rect);
1344
1455
  }).map(item => {
1456
+ const map = item[2];
1457
+ let className = undefined;
1458
+ if (map.has('class')) {
1459
+ className = map.get('class');
1460
+ }
1345
1461
  return {
1462
+ x: item[1][0],
1463
+ y: item[1][1],
1346
1464
  width: item[1][2],
1347
1465
  height: item[1][3],
1466
+ className
1348
1467
  };
1349
1468
  });
1350
1469
  }