circuitscript 0.0.38 → 0.1.2

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 (66) hide show
  1. package/dist/cjs/BaseVisitor.js +69 -46
  2. package/dist/cjs/SymbolValidatorVisitor.js +1 -1
  3. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  4. package/dist/cjs/antlr/CircuitScriptParser.js +580 -613
  5. package/dist/cjs/builtinMethods.js +32 -10
  6. package/dist/cjs/draw_symbols.js +375 -233
  7. package/dist/cjs/execute.js +142 -131
  8. package/dist/cjs/export.js +2 -4
  9. package/dist/cjs/geometry.js +52 -19
  10. package/dist/cjs/globals.js +14 -9
  11. package/dist/cjs/helpers.js +16 -3
  12. package/dist/cjs/layout.js +143 -151
  13. package/dist/cjs/logger.js +8 -1
  14. package/dist/cjs/objects/ClassComponent.js +22 -22
  15. package/dist/cjs/objects/ExecutionScope.js +10 -4
  16. package/dist/cjs/objects/Frame.js +4 -1
  17. package/dist/cjs/objects/ParamDefinition.js +120 -4
  18. package/dist/cjs/objects/PinDefinition.js +1 -4
  19. package/dist/cjs/objects/types.js +41 -0
  20. package/dist/cjs/render.js +41 -110
  21. package/dist/cjs/sizing.js +33 -7
  22. package/dist/cjs/utils.js +92 -2
  23. package/dist/cjs/visitor.js +279 -284
  24. package/dist/esm/BaseVisitor.mjs +70 -47
  25. package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
  26. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  27. package/dist/esm/antlr/CircuitScriptParser.mjs +580 -613
  28. package/dist/esm/builtinMethods.mjs +29 -10
  29. package/dist/esm/draw_symbols.mjs +381 -238
  30. package/dist/esm/execute.mjs +144 -133
  31. package/dist/esm/export.mjs +2 -4
  32. package/dist/esm/geometry.mjs +52 -19
  33. package/dist/esm/globals.mjs +13 -8
  34. package/dist/esm/helpers.mjs +17 -4
  35. package/dist/esm/layout.mjs +144 -153
  36. package/dist/esm/logger.mjs +8 -1
  37. package/dist/esm/objects/ClassComponent.mjs +21 -26
  38. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  39. package/dist/esm/objects/Frame.mjs +4 -1
  40. package/dist/esm/objects/ParamDefinition.mjs +119 -3
  41. package/dist/esm/objects/PinDefinition.mjs +0 -2
  42. package/dist/esm/objects/types.mjs +42 -0
  43. package/dist/esm/render.mjs +44 -113
  44. package/dist/esm/sizing.mjs +34 -8
  45. package/dist/esm/utils.mjs +86 -1
  46. package/dist/esm/visitor.mjs +281 -286
  47. package/dist/types/BaseVisitor.d.ts +3 -2
  48. package/dist/types/antlr/CircuitScriptParser.d.ts +5 -3
  49. package/dist/types/draw_symbols.d.ts +81 -49
  50. package/dist/types/execute.d.ts +16 -11
  51. package/dist/types/geometry.d.ts +31 -19
  52. package/dist/types/globals.d.ts +15 -10
  53. package/dist/types/helpers.d.ts +2 -1
  54. package/dist/types/layout.d.ts +22 -21
  55. package/dist/types/logger.d.ts +1 -1
  56. package/dist/types/objects/ClassComponent.d.ts +19 -16
  57. package/dist/types/objects/ExecutionScope.d.ts +2 -1
  58. package/dist/types/objects/Frame.d.ts +5 -3
  59. package/dist/types/objects/ParamDefinition.d.ts +31 -2
  60. package/dist/types/objects/PinDefinition.d.ts +0 -2
  61. package/dist/types/objects/types.d.ts +7 -2
  62. package/dist/types/render.d.ts +2 -1
  63. package/dist/types/utils.d.ts +9 -1
  64. package/dist/types/visitor.d.ts +5 -5
  65. package/libs/lib.cst +102 -32
  66. package/package.json +7 -3
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExtractDrawingRects = exports.CalculatePinPositions = exports.RenderJunction = exports.RenderFrameType = exports.RenderFrame = exports.RenderText = exports.RenderComponent = exports.RenderWire = exports.RenderObject = exports.getBounds = exports.LayoutEngine = void 0;
3
+ exports.ExtractDrawingRects = exports.CalculatePinPositions = exports.RenderJunction = exports.RenderFrameType = exports.RenderFrame = exports.RenderText = exports.RenderComponent = exports.RenderWire = exports.RenderObject = exports.getBounds = exports.applyComponentParamsToSymbol = exports.LayoutEngine = void 0;
4
4
  const graphlib_1 = require("@dagrejs/graphlib");
5
5
  const draw_symbols_js_1 = require("./draw_symbols.js");
6
6
  const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
7
7
  const globals_js_1 = require("./globals.js");
8
- const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
9
8
  const geometry_js_1 = require("./geometry.js");
10
9
  const logger_js_1 = require("./logger.js");
11
10
  const Frame_js_1 = require("./objects/Frame.js");
12
11
  const utils_js_1 = require("./utils.js");
13
12
  const types_js_1 = require("./objects/types.js");
14
13
  const helpers_js_1 = require("./helpers.js");
14
+ const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
15
15
  class LayoutEngine {
16
16
  constructor(options = { showBaseFrame: false }) {
17
17
  this.placeSubgraphVersion = 2;
@@ -116,8 +116,8 @@ class LayoutEngine {
116
116
  const allLines = wires.map(wire => {
117
117
  return wire.points.map(pt => {
118
118
  return {
119
- x: wire.x + pt.x,
120
- y: wire.y + pt.y,
119
+ x: wire.x.add(pt.x),
120
+ y: wire.y.add(pt.y),
121
121
  };
122
122
  });
123
123
  });
@@ -128,7 +128,7 @@ class LayoutEngine {
128
128
  intersectPoints,
129
129
  });
130
130
  intersectPoints.forEach(([x, y]) => {
131
- junctions.push(new RenderJunction(x, y));
131
+ junctions.push(new RenderJunction((0, ParamDefinition_js_1.numeric)(x), (0, ParamDefinition_js_1.numeric)(y)));
132
132
  });
133
133
  }
134
134
  return {
@@ -138,15 +138,15 @@ class LayoutEngine {
138
138
  }
139
139
  placeFrames(graph, subgraphInfo, frameObjects) {
140
140
  const baseFrame = frameObjects[0];
141
- baseFrame.padding = 0;
142
- baseFrame.borderWidth = 0;
141
+ baseFrame.padding = (0, ParamDefinition_js_1.numeric)(0);
142
+ baseFrame.borderWidth = (0, ParamDefinition_js_1.numeric)(0);
143
143
  if (this.showBaseFrame) {
144
- baseFrame.borderWidth = 5;
144
+ baseFrame.borderWidth = (0, ParamDefinition_js_1.numeric)(5);
145
145
  baseFrame.width = 11692 - 400 * 2;
146
146
  baseFrame.height = 8267 - 400 * 2;
147
147
  }
148
- baseFrame.x = 0;
149
- baseFrame.y = 0;
148
+ baseFrame.x = (0, ParamDefinition_js_1.numeric)(0);
149
+ baseFrame.y = (0, ParamDefinition_js_1.numeric)(0);
150
150
  let textObjects = [];
151
151
  let elementFrames = [];
152
152
  baseFrame.bounds = {
@@ -192,18 +192,18 @@ class LayoutEngine {
192
192
  const innerItems = frame.innerItems;
193
193
  innerItems.forEach(innerFrame => {
194
194
  if (innerFrame.frame.frameType === globals_js_1.FrameType.Sheet) {
195
- innerFrame.x = 0;
196
- innerFrame.y = 0;
195
+ innerFrame.x = (0, ParamDefinition_js_1.numeric)(0);
196
+ innerFrame.y = (0, ParamDefinition_js_1.numeric)(0);
197
197
  }
198
198
  else {
199
- innerFrame.x += frame.x;
200
- innerFrame.y += frame.y;
199
+ innerFrame.x = innerFrame.x.add(frame.x);
200
+ innerFrame.y = innerFrame.y.add(frame.y);
201
201
  }
202
202
  if (innerFrame.type === RenderFrameType.Elements) {
203
203
  this.print(level, "".padStart(level * 4), 'element frame', innerFrame.x, innerFrame.y);
204
204
  innerFrame.innerItems.forEach(item2 => {
205
- item2.x += innerFrame.x - innerFrame.translateX;
206
- item2.y += innerFrame.y - innerFrame.translateY;
205
+ item2.x = item2.x.add(innerFrame.x).sub(innerFrame.translateX);
206
+ item2.y = item2.y.add(innerFrame.y).sub(innerFrame.translateY);
207
207
  });
208
208
  }
209
209
  else {
@@ -215,8 +215,8 @@ class LayoutEngine {
215
215
  placeAndSizeFrame(frame, level = 0) {
216
216
  const innerFrames = frame.innerItems;
217
217
  const gridSize = globals_js_1.defaultGridSizeUnits;
218
- let accumX = 0;
219
- let accumY = 0;
218
+ let accumX = (0, ParamDefinition_js_1.numeric)(0);
219
+ let accumY = (0, ParamDefinition_js_1.numeric)(0);
220
220
  const boundPoints = [];
221
221
  const frameSizes = innerFrames.map(innerFrame => {
222
222
  if (innerFrame.type === RenderFrameType.Elements) {
@@ -244,7 +244,7 @@ class LayoutEngine {
244
244
  return accum;
245
245
  }
246
246
  return accum + width +
247
- ((index + 1 < frameSizes.length) ? frame.gap : 0);
247
+ ((index + 1 < frameSizes.length) ? frame.gap.toNumber() : 0);
248
248
  }, 0);
249
249
  }
250
250
  else {
@@ -268,47 +268,55 @@ class LayoutEngine {
268
268
  innerFrames.forEach(innerFrame => {
269
269
  const { width: frameWidth, height: frameHeight } = (0, utils_js_1.getBoundsSize)(innerFrame.bounds);
270
270
  if (innerFrame.containsTitle) {
271
- innerFrame.x = offsetX + accumX + (0, utils_js_1.toNearestGrid)(widthForTitle / 2 - frameWidth / 2, gridSize);
272
- innerFrame.y = offsetY + accumY;
273
- accumY += (frameHeight + frame.gap);
271
+ innerFrame.x = offsetX.add(accumX).add((0, utils_js_1.toNearestGrid)(widthForTitle / 2 - frameWidth / 2, gridSize));
272
+ innerFrame.y = offsetY.add(accumY);
273
+ accumY = accumY.add(frameHeight).add(frame.gap);
274
274
  }
275
275
  else {
276
276
  if (frame.direction === Frame_js_1.FramePlotDirection.Column) {
277
- innerFrame.x = offsetX + accumX + (0, utils_js_1.toNearestGrid)(maxWidth / 2 - frameWidth / 2, gridSize);
278
- innerFrame.y = offsetY + accumY;
279
- accumY += (frameHeight + frame.gap);
277
+ innerFrame.x = offsetX.add(accumX).add((0, utils_js_1.toNearestGrid)(maxWidth / 2 - frameWidth / 2, gridSize));
278
+ innerFrame.y = offsetY.add(accumY);
279
+ accumY = accumY.add(frameHeight).add(frame.gap);
280
280
  }
281
281
  else if (frame.direction === Frame_js_1.FramePlotDirection.Row) {
282
- innerFrame.x = offsetX + centeredOffsetX + accumX;
283
- innerFrame.y = offsetY + accumY;
284
- accumX += (frameWidth + frame.gap);
282
+ innerFrame.x = offsetX.add(centeredOffsetX).add(accumX);
283
+ innerFrame.y = offsetY.add(accumY);
284
+ accumX = accumX.add(frameWidth).add(frame.gap);
285
285
  }
286
286
  }
287
- boundPoints.push([innerFrame.x, innerFrame.y], [innerFrame.x + frameWidth, innerFrame.y + frameHeight]);
287
+ boundPoints.push([innerFrame.x, innerFrame.y], [innerFrame.x.add(frameWidth), innerFrame.y.add(frameHeight)]);
288
+ });
289
+ const tmpBoundPoints = boundPoints.map(item => {
290
+ return [
291
+ item[0].toNumber(),
292
+ item[1].toNumber(),
293
+ ];
288
294
  });
289
- const contentsBounds = (0, utils_js_1.resizeBounds)(getBoundsFromPoints(boundPoints), frame.padding);
295
+ const contentsBounds = (0, utils_js_1.resizeBounds)(getBoundsFromPoints(tmpBoundPoints), frame.padding.toNumber());
290
296
  if (frame.frame.parameters.has(Frame_js_1.FrameParamKeys.SheetType)) {
291
297
  const frameComponent = frame.frame.parameters.get(Frame_js_1.FrameParamKeys.SheetType);
292
- const rects = ExtractDrawingRects(frameComponent.displayProp);
293
- let frameWidth = 0;
294
- let frameHeight = 0;
298
+ const frameDrawing = frameComponent.displayProp;
299
+ frameDrawing.variables = (0, utils_js_1.combineMaps)(frameComponent.parameters, frame.frame.parameters);
300
+ const rects = ExtractDrawingRects(frameDrawing);
301
+ let frameWidth = (0, ParamDefinition_js_1.numeric)(0);
302
+ let frameHeight = (0, ParamDefinition_js_1.numeric)(0);
295
303
  if (rects[1]) {
296
304
  frameWidth = (0, helpers_js_1.milsToMM)(rects[1].width);
297
305
  frameHeight = (0, helpers_js_1.milsToMM)(rects[1].height);
298
306
  }
299
307
  const contentsWidth = contentsBounds.xmax - contentsBounds.xmin;
300
308
  const contentsHeight = contentsBounds.ymax - contentsBounds.ymin;
301
- const frameOffsetX = (0, utils_js_1.toNearestGrid)((frameWidth - contentsWidth) / 2, gridSize);
302
- const frameOffsetY = (0, utils_js_1.toNearestGrid)((frameHeight - contentsHeight) / 2, gridSize);
309
+ const frameOffsetX = (0, utils_js_1.toNearestGrid)((frameWidth.toNumber() - contentsWidth) / 2, gridSize);
310
+ const frameOffsetY = (0, utils_js_1.toNearestGrid)((frameHeight.toNumber() - contentsHeight) / 2, gridSize);
303
311
  innerFrames.forEach(innerFrame => {
304
- innerFrame.x += frameOffsetX;
305
- innerFrame.y += frameOffsetY;
312
+ innerFrame.x = innerFrame.x.add(frameOffsetX);
313
+ innerFrame.y = innerFrame.y.add(frameOffsetY);
306
314
  });
307
315
  frame.bounds = {
308
316
  xmin: 0,
309
317
  ymin: 0,
310
- xmax: frameWidth,
311
- ymax: frameHeight
318
+ xmax: frameWidth.toNumber(),
319
+ ymax: frameHeight.toNumber(),
312
320
  };
313
321
  }
314
322
  else {
@@ -375,13 +383,14 @@ class LayoutEngine {
375
383
  }, []);
376
384
  if (frame.type === RenderFrameType.Container) {
377
385
  const frameObject = frame.frame;
378
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Title)) {
386
+ const isSheetFrame = frameObject.frameType === globals_js_1.FrameType.Sheet;
387
+ if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Title) && !isSheetFrame) {
379
388
  const title = frameObject.parameters.get(Frame_js_1.FrameParamKeys.Title);
380
389
  const tmpFrame = new RenderFrame(new Frame_js_1.Frame(-2), RenderFrameType.Elements);
381
390
  tmpFrame.containsTitle = true;
382
391
  tmpFrame.subgraphId = title.replace(/\s/g, "_");
383
392
  const textObject = new RenderText(title);
384
- textObject.fontSize = globals_js_1.defaultFrameTitleTextSize;
393
+ textObject.fontSize = (0, ParamDefinition_js_1.numeric)(globals_js_1.defaultFrameTitleTextSize);
385
394
  textObject.fontWeight = 'bold';
386
395
  textObject.symbol.refreshDrawing();
387
396
  tmpFrame.innerItems.push(textObject);
@@ -392,8 +401,8 @@ class LayoutEngine {
392
401
  xmax: tmpBox.start[0] + tmpBox.width,
393
402
  ymax: tmpBox.start[1] + tmpBox.height
394
403
  };
395
- textObject.x = 0;
396
- textObject.y = 0;
404
+ textObject.x = (0, ParamDefinition_js_1.numeric)(0);
405
+ textObject.y = (0, ParamDefinition_js_1.numeric)(0);
397
406
  frame.innerItems.splice(0, 0, tmpFrame);
398
407
  this.printLevel(level, frame, 'added text', tmpFrame);
399
408
  textObjects.push(textObject);
@@ -426,46 +435,43 @@ class LayoutEngine {
426
435
  const tmpInstanceName = component.instanceName;
427
436
  if (!graph.hasNode(tmpInstanceName)) {
428
437
  this.print('create instance', tmpInstanceName);
429
- let { displayProp = null, widthProp = null, typeProp = null } = component;
438
+ const { displayProp = null, widthProp = null, heightProp = null } = component;
430
439
  let tmpSymbol;
431
- if (displayProp === null &&
432
- component.parameters.get(globals_js_1.ParamKeys.net_name) === globals_js_1.GlobalNames.gnd) {
433
- displayProp = 'gnd';
434
- }
435
- if (displayProp !== null) {
436
- if (displayProp instanceof draw_symbols_js_1.SymbolDrawing) {
437
- tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(displayProp);
438
- tmpSymbol.drawing.logger = this.logger;
439
- }
440
- else if (typeof displayProp === "string") {
441
- tmpSymbol = (0, draw_symbols_js_1.SymbolFactory)(displayProp);
442
- }
440
+ if (displayProp instanceof draw_symbols_js_1.SymbolDrawing) {
441
+ tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(displayProp);
442
+ tmpSymbol.drawing.logger = this.logger;
443
443
  }
444
444
  else {
445
445
  const symbolPinDefinitions = generateLayoutPinDefinition(component);
446
- if (component.typeProp === 'module') {
447
- tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions);
446
+ if (component.typeProp === globals_js_1.ComponentTypes.module) {
447
+ tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions, component.pinsMaxPositions);
448
448
  }
449
449
  else {
450
- tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions);
450
+ tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
451
451
  }
452
452
  }
453
- applyComponentParamsToSymbol(typeProp, component, tmpSymbol);
453
+ applyComponentParamsToSymbol(component, tmpSymbol);
454
454
  let didSetAngle = false;
455
- if (component.parameters.has('angle')) {
455
+ if (component.parameters.has(globals_js_1.ParamKeys.angle)) {
456
456
  didSetAngle = true;
457
- tmpSymbol.angle = component.parameters.get('angle');
457
+ const value = component.parameters.get(globals_js_1.ParamKeys.angle).toNumber();
458
+ tmpSymbol.angle = value;
458
459
  }
459
- if (component.parameters.has('flipX')) {
460
+ if (component.parameters.has(globals_js_1.ParamKeys.flipX)) {
460
461
  tmpSymbol.flipX =
461
- component.parameters.get('flipX');
462
+ component.parameters.get(globals_js_1.ParamKeys.flipX);
462
463
  }
463
- if (component.parameters.has('flipY')) {
464
+ if (component.parameters.has(globals_js_1.ParamKeys.flipY)) {
464
465
  tmpSymbol.flipY =
465
- component.parameters.get('flipY');
466
+ component.parameters.get(globals_js_1.ParamKeys.flipY);
466
467
  }
467
- if (tmpSymbol instanceof draw_symbols_js_1.SymbolCustom && widthProp) {
468
- tmpSymbol.bodyWidth = (0, helpers_js_1.milsToMM)(widthProp);
468
+ if (tmpSymbol instanceof draw_symbols_js_1.SymbolCustom) {
469
+ if (widthProp) {
470
+ tmpSymbol.bodyWidth = (0, helpers_js_1.milsToMM)(widthProp);
471
+ }
472
+ if (heightProp) {
473
+ tmpSymbol.bodyHeight = (0, helpers_js_1.milsToMM)(heightProp);
474
+ }
469
475
  }
470
476
  if (!didSetAngle && component.parameters.has('_addDirection')) {
471
477
  tmpSymbol.refreshDrawing(false);
@@ -487,7 +493,7 @@ class LayoutEngine {
487
493
  }
488
494
  else if (action === ExecutionScope_js_1.SequenceAction.Wire) {
489
495
  const [, wireId, wireSegments] = sequence[i];
490
- const wire = new RenderWire(0, 0, wireSegments);
496
+ const wire = new RenderWire((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), wireSegments);
491
497
  wire.id = wireId;
492
498
  let useNetName = null;
493
499
  if (previousNode !== null) {
@@ -651,7 +657,7 @@ class LayoutEngine {
651
657
  }
652
658
  if (subgraphEdges.length === 0) {
653
659
  const [, node1] = graph.node(firstNodeId);
654
- this.placeNodeAtPosition(0, 0, node1, 1);
660
+ this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, 1);
655
661
  return;
656
662
  }
657
663
  let fixedNode;
@@ -664,7 +670,7 @@ class LayoutEngine {
664
670
  const [, node2] = graph.node(nodeId2);
665
671
  if (nodeId1 === firstNodeId && !firstNodePlaced) {
666
672
  this.print('first node placed at origin');
667
- this.placeNodeAtPosition(0, 0, node1, pin1);
673
+ this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, pin1);
668
674
  firstNodePlaced = true;
669
675
  node1.isFloating = false;
670
676
  originNodes.push(node1);
@@ -687,7 +693,7 @@ class LayoutEngine {
687
693
  originNodes.push(node1);
688
694
  originNodeGroups.set(node1.toString(), [node1]);
689
695
  this.print('creating new origin node at', node1);
690
- this.placeNodeAtPosition(0, 0, node1, pin1);
696
+ this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, pin1);
691
697
  node1.isFloating = false;
692
698
  fixedNode = node1;
693
699
  fixedNodePin = pin1;
@@ -704,7 +710,7 @@ class LayoutEngine {
704
710
  else {
705
711
  const [x1, y1] = getNodePositionAtPin(node1, pin1);
706
712
  const [x2, y2] = getNodePositionAtPin(node2, pin2);
707
- if (x1 !== x2 && y1 !== y2) {
713
+ if (!x1.eq(x2) && !y1.eq(y2)) {
708
714
  if (node1 instanceof RenderWire &&
709
715
  node2 instanceof RenderComponent) {
710
716
  const refdes = node2.component.assignedRefDes;
@@ -781,8 +787,8 @@ class LayoutEngine {
781
787
  this.print('merging origin node groups, fixed:', keepOriginNode, ', other:', otherOriginNode);
782
788
  const [x, y] = getNodePositionAtPin(fixedNode, fixedNodePin);
783
789
  const [otherNodeOriginX, otherNodeOriginY] = getNodePositionAtPin(mergedNode, mergedNodePin);
784
- const offsetX = x - otherNodeOriginX;
785
- const offsetY = y - otherNodeOriginY;
790
+ const offsetX = x.sub(otherNodeOriginX);
791
+ const offsetY = y.sub(otherNodeOriginY);
786
792
  this.print('offset of other origin:', offsetX, offsetY);
787
793
  const otherItemsLinkedToOriginNode = originNodeGroups.get(otherOriginNode);
788
794
  this.print('nodes in other origin:', otherItemsLinkedToOriginNode);
@@ -804,7 +810,7 @@ class LayoutEngine {
804
810
  const [, node2] = graph.node(nodeId2);
805
811
  if (nodeId1 === firstNodeId && !firstNodePlaced) {
806
812
  this.print('first node placed at origin');
807
- this.placeNodeAtPosition(0, 0, node1, pin1);
813
+ this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, pin1);
808
814
  firstNodePlaced = true;
809
815
  node1.isFloating = false;
810
816
  }
@@ -850,14 +856,14 @@ class LayoutEngine {
850
856
  });
851
857
  }
852
858
  translateNodeBy(offsetX, offsetY, item) {
853
- item.x += offsetX;
854
- item.y += offsetY;
859
+ item.x = item.x.add(offsetX);
860
+ item.y = item.y.add(offsetY);
855
861
  }
856
862
  placeNodeAtPosition(fromX, fromY, item, pin, depth = 0) {
857
863
  if (item instanceof RenderComponent) {
858
864
  const pinPosition = item.symbol.pinPosition(pin);
859
- item.x = fromX - pinPosition.x;
860
- item.y = fromY - pinPosition.y;
865
+ item.x = fromX.sub(pinPosition.x);
866
+ item.y = fromY.sub(pinPosition.y);
861
867
  }
862
868
  else if (item instanceof RenderWire) {
863
869
  if (pin === 0) {
@@ -866,8 +872,8 @@ class LayoutEngine {
866
872
  }
867
873
  else {
868
874
  const wireEnd = item.getWireEnd();
869
- item.x = fromX - wireEnd.x;
870
- item.y = fromY - wireEnd.y;
875
+ item.x = fromX.sub(wireEnd.x);
876
+ item.y = fromY.sub(wireEnd.y);
871
877
  }
872
878
  }
873
879
  this.print(this.padLevel(depth), 'place', item, 'pin', pin, 'at', item.x, item.y);
@@ -907,12 +913,12 @@ class LayoutEngine {
907
913
  }
908
914
  exports.LayoutEngine = LayoutEngine;
909
915
  function getNodePositionAtPin(item, pin) {
910
- let x = 0;
911
- let y = 0;
916
+ let x = (0, ParamDefinition_js_1.numeric)(0);
917
+ let y = (0, ParamDefinition_js_1.numeric)(0);
912
918
  if (item instanceof RenderComponent) {
913
919
  const pinPosition = item.symbol.pinPosition(pin);
914
- x = item.x + pinPosition.x;
915
- y = item.y + pinPosition.y;
920
+ x = item.x.add(pinPosition.x);
921
+ y = item.y.add(pinPosition.y);
916
922
  }
917
923
  else if (item instanceof RenderWire) {
918
924
  if (pin === 0) {
@@ -921,8 +927,8 @@ function getNodePositionAtPin(item, pin) {
921
927
  }
922
928
  else {
923
929
  const wireEnd = item.getWireEnd();
924
- x = item.x + wireEnd.x;
925
- y = item.y + wireEnd.y;
930
+ x = item.x.add(wireEnd.x);
931
+ y = item.y.add(wireEnd.y);
926
932
  }
927
933
  }
928
934
  return [
@@ -955,7 +961,7 @@ function generateLayoutPinDefinition(component) {
955
961
  const pinPosition = Math.floor(i / 2);
956
962
  const pin = pins.get(existingPinIds[i]);
957
963
  symbolPinDefinitions.push({
958
- side: (i % 2 === 0) ? "left" : "right",
964
+ side: (i % 2 === 0) ? globals_js_1.SymbolPinSide.Left : globals_js_1.SymbolPinSide.Right,
959
965
  pinId: existingPinIds[i],
960
966
  text: pin.name,
961
967
  position: pinPosition,
@@ -974,24 +980,24 @@ function generateLayoutPinDefinition(component) {
974
980
  useItems = [...items];
975
981
  }
976
982
  useItems.forEach(pinId => {
977
- if (existingPinIds.indexOf(pinId) !== -1) {
978
- const pin = pins.get(pinId);
979
- symbolPinDefinitions.push({
980
- side: key,
981
- pinId: pinId,
982
- text: pin.name,
983
- position: pin.position,
984
- pinType: pin.pinType,
985
- });
986
- addedPins.push(pinId);
983
+ if (pinId instanceof ParamDefinition_js_1.NumericValue) {
984
+ const pinIdValue = pinId.toNumber();
985
+ if (existingPinIds.indexOf(pinIdValue) !== -1) {
986
+ const pin = pins.get(pinIdValue);
987
+ symbolPinDefinitions.push({
988
+ side: key,
989
+ pinId: pinIdValue,
990
+ text: pin.name,
991
+ position: pin.position,
992
+ pinType: pin.pinType,
993
+ });
994
+ addedPins.push(pinIdValue);
995
+ }
987
996
  }
988
997
  });
989
998
  }
990
- const unplacedPins = [];
991
- existingPinIds.forEach(item => {
992
- if (addedPins.indexOf(item) === -1) {
993
- unplacedPins.push(item);
994
- }
999
+ const unplacedPins = existingPinIds.filter(pinId => {
1000
+ return addedPins.indexOf(pinId) === -1;
995
1001
  });
996
1002
  if (unplacedPins.length > 0) {
997
1003
  throw "'arrange' property is defined, but not all pins are specified: " + unplacedPins.join(",");
@@ -999,29 +1005,14 @@ function generateLayoutPinDefinition(component) {
999
1005
  }
1000
1006
  return symbolPinDefinitions;
1001
1007
  }
1002
- function applyComponentParamsToSymbol(typeProp, component, symbol) {
1003
- if (typeProp === 'net') {
1004
- symbol.setLabelValue("net_name", component.parameters.get(globals_js_1.ParamKeys.net_name));
1005
- }
1006
- if (component.assignedRefDes !== null) {
1007
- symbol.setLabelValue("refdes", component.assignedRefDes);
1008
- }
1009
- for (const [key, value] of component.parameters) {
1010
- if (key !== 'refdes' && key !== 'net_name') {
1011
- let useValue;
1012
- if (typeof value == 'object' && (value instanceof ParamDefinition_js_1.NumericValue)) {
1013
- useValue = value.toDisplayString();
1014
- }
1015
- else if (typeof value === 'number') {
1016
- useValue = value.toString();
1017
- }
1018
- else if (typeof value === 'string') {
1019
- useValue = value;
1020
- }
1021
- symbol.setLabelValue(key, useValue);
1022
- }
1008
+ function applyComponentParamsToSymbol(component, symbol) {
1009
+ const newMap = new Map(component.parameters);
1010
+ if (!newMap.has('refdes')) {
1011
+ newMap.set('refdes', component.assignedRefDes ?? "?");
1023
1012
  }
1013
+ symbol.drawing.variables = newMap;
1024
1014
  }
1015
+ exports.applyComponentParamsToSymbol = applyComponentParamsToSymbol;
1025
1016
  function calculateSymbolAngle(symbol, pin, direction) {
1026
1017
  let directionVector = 0;
1027
1018
  switch (direction) {
@@ -1048,21 +1039,21 @@ function getBounds(components, wires, junctions, frames) {
1048
1039
  const bbox = item.symbol.drawing.getBoundingBox();
1049
1040
  const [x1, y1] = bbox.start;
1050
1041
  const [x2, y2] = bbox.end;
1051
- points.push([x1 + item.x, y1 + item.y]);
1052
- points.push([x2 + item.x, y2 + item.y]);
1042
+ points.push([x1 + item.x.toNumber(), y1 + item.y.toNumber()]);
1043
+ points.push([x2 + item.x.toNumber(), y2 + item.y.toNumber()]);
1053
1044
  });
1054
1045
  wires.forEach(wire => {
1055
1046
  wire.points.forEach(point => {
1056
- points.push([wire.x + point.x, wire.y + point.y]);
1047
+ points.push([wire.x.add(point.x).toNumber(), wire.y.add(point.y).toNumber()]);
1057
1048
  });
1058
1049
  });
1059
1050
  junctions.forEach(item => {
1060
- points.push([item.x, item.y]);
1051
+ points.push([item.x.toNumber(), item.y.toNumber()]);
1061
1052
  });
1062
1053
  frames.forEach(item => {
1063
1054
  const { width, height } = (0, utils_js_1.getBoundsSize)(item.bounds);
1064
- points.push([item.x, item.y]);
1065
- points.push([item.x + width, item.y + height]);
1055
+ points.push([item.x.toNumber(), item.y.toNumber()]);
1056
+ points.push([item.x.toNumber() + width, item.y.toNumber() + height]);
1066
1057
  });
1067
1058
  return getBoundsFromPoints(points);
1068
1059
  }
@@ -1080,8 +1071,8 @@ function getBoundsFromPoints(points) {
1080
1071
  }
1081
1072
  class RenderObject {
1082
1073
  constructor() {
1083
- this.x = -1;
1084
- this.y = -1;
1074
+ this.x = (0, ParamDefinition_js_1.numeric)(-1);
1075
+ this.y = (0, ParamDefinition_js_1.numeric)(-1);
1085
1076
  this.isFloating = true;
1086
1077
  this.floatingRelativeTo = [];
1087
1078
  }
@@ -1124,7 +1115,7 @@ class RenderWire extends RenderObject {
1124
1115
  tmpX += useValue;
1125
1116
  }
1126
1117
  else if (direction === globals_js_1.WireAutoDirection.Auto || direction === globals_js_1.WireAutoDirection.Auto_) {
1127
- const { valueXY = [0, 0] } = segment;
1118
+ const { valueXY = [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)] } = segment;
1128
1119
  const tmpPoints = this.getAutoPoints(valueXY, direction);
1129
1120
  tmpPoints.forEach(point => {
1130
1121
  if (point[0] !== 0 || point[1] !== 0) {
@@ -1142,8 +1133,8 @@ class RenderWire extends RenderObject {
1142
1133
  this.points = points;
1143
1134
  }
1144
1135
  getAutoPoints(value, direction) {
1145
- const valueX = (0, utils_js_1.roundValue)(value[0]);
1146
- const valueY = (0, utils_js_1.roundValue)(value[1]);
1136
+ const valueX = (0, utils_js_1.roundValue)(value[0]).toNumber();
1137
+ const valueY = (0, utils_js_1.roundValue)(value[1]).toNumber();
1147
1138
  const inQuadrant = geometry_js_1.Geometry.getQuadrant(valueX, valueY);
1148
1139
  const [dx, dy] = [valueX, valueY];
1149
1140
  if (direction === globals_js_1.WireAutoDirection.Auto) {
@@ -1199,16 +1190,16 @@ class RenderWire extends RenderObject {
1199
1190
  useValue = value;
1200
1191
  }
1201
1192
  if (direction === types_js_1.Direction.Down) {
1202
- tmpY += useValue;
1193
+ tmpY = tmpY.add(useValue);
1203
1194
  }
1204
1195
  else if (direction === types_js_1.Direction.Up) {
1205
- tmpY -= useValue;
1196
+ tmpY = tmpY.sub(useValue);
1206
1197
  }
1207
1198
  else if (direction === types_js_1.Direction.Left) {
1208
- tmpX -= useValue;
1199
+ tmpX = tmpX.sub(useValue);
1209
1200
  }
1210
1201
  else if (direction === types_js_1.Direction.Right) {
1211
- tmpX += useValue;
1202
+ tmpX = tmpX.add(useValue);
1212
1203
  }
1213
1204
  });
1214
1205
  let useValue = null;
@@ -1216,22 +1207,22 @@ class RenderWire extends RenderObject {
1216
1207
  const lastSegment = this.segments[this.segments.length - 1];
1217
1208
  switch (lastSegment.direction) {
1218
1209
  case types_js_1.Direction.Left:
1219
- useValue = tmpX - untilX;
1210
+ useValue = tmpX.sub(untilX);
1220
1211
  break;
1221
1212
  case types_js_1.Direction.Right:
1222
- useValue = untilX - tmpX;
1213
+ useValue = untilX.sub(tmpX);
1223
1214
  break;
1224
1215
  case types_js_1.Direction.Up:
1225
- useValue = untilY - tmpY;
1216
+ useValue = untilY.sub(tmpY);
1226
1217
  break;
1227
1218
  case types_js_1.Direction.Down:
1228
- useValue = tmpY - untilY;
1219
+ useValue = tmpY.sub(untilY);
1229
1220
  break;
1230
1221
  case globals_js_1.WireAutoDirection.Auto:
1231
1222
  case globals_js_1.WireAutoDirection.Auto_:
1232
1223
  valueXY = [
1233
- untilX - tmpX,
1234
- untilY - tmpY,
1224
+ untilX.sub(tmpX),
1225
+ untilY.sub(tmpY),
1235
1226
  ];
1236
1227
  useValue = 0;
1237
1228
  break;
@@ -1282,7 +1273,7 @@ class RenderText extends RenderObject {
1282
1273
  }
1283
1274
  constructor(text) {
1284
1275
  super();
1285
- this._fontSize = 12;
1276
+ this._fontSize = (0, ParamDefinition_js_1.numeric)(12);
1286
1277
  this._fontWeight = 'regular';
1287
1278
  this.symbol = new draw_symbols_js_1.SymbolText(text);
1288
1279
  }
@@ -1297,11 +1288,10 @@ class RenderFrame extends RenderObject {
1297
1288
  this.translateY = 0;
1298
1289
  this.padding = (0, helpers_js_1.milsToMM)(100);
1299
1290
  this.gap = (0, helpers_js_1.milsToMM)(100);
1291
+ this.borderWidth = (0, ParamDefinition_js_1.numeric)(5);
1300
1292
  this.direction = Frame_js_1.FramePlotDirection.Column;
1301
- this.borderWidth = 5;
1302
1293
  this.width = null;
1303
1294
  this.height = null;
1304
- this.size = null;
1305
1295
  this.subgraphId = "";
1306
1296
  this.containsTitle = false;
1307
1297
  this.frame = frame;
@@ -1315,7 +1305,8 @@ class RenderFrame extends RenderObject {
1315
1305
  else if (this.type === RenderFrameType.Elements) {
1316
1306
  name = 'elements_' + this.subgraphId;
1317
1307
  }
1318
- return name + ": " + this.x + "," + this.y + " bounds:" + (0, utils_js_1.printBounds)(this.bounds);
1308
+ return name + ": " + this.x + "," + this.y
1309
+ + " bounds:" + (this.bounds && (0, utils_js_1.printBounds)(this.bounds));
1319
1310
  }
1320
1311
  }
1321
1312
  exports.RenderFrame = RenderFrame;
@@ -1340,8 +1331,9 @@ function CalculatePinPositions(component) {
1340
1331
  }
1341
1332
  else {
1342
1333
  const symbolPinDefinitions = generateLayoutPinDefinition(component);
1343
- tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions);
1334
+ tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
1344
1335
  }
1336
+ applyComponentParamsToSymbol(component, tmpSymbol);
1345
1337
  tmpSymbol.refreshDrawing();
1346
1338
  const pins = component.pins;
1347
1339
  pins.forEach((value, key) => {
@@ -7,7 +7,14 @@ class Logger {
7
7
  this.add((new Date()).toISOString());
8
8
  this.add('starting logger...');
9
9
  }
10
- add(message) {
10
+ add(...args) {
11
+ let message = "";
12
+ if (args.length === 1) {
13
+ message = args[0].toString();
14
+ }
15
+ else {
16
+ message = args.join(" ");
17
+ }
11
18
  this.logs.push((new Date()).toISOString() + " | " + message);
12
19
  }
13
20
  dump() {