circuitscript 0.0.28 → 0.0.31

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 (60) hide show
  1. package/dist/cjs/BaseVisitor.js +6 -1
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +204 -200
  3. package/dist/cjs/antlr/CircuitScriptParser.js +1066 -1173
  4. package/dist/cjs/draw_symbols.js +383 -103
  5. package/dist/cjs/execute.js +39 -14
  6. package/dist/cjs/geometry.js +79 -18
  7. package/dist/cjs/globals.js +41 -7
  8. package/dist/cjs/helpers.js +40 -2
  9. package/dist/cjs/layout.js +72 -39
  10. package/dist/cjs/main.js +10 -4
  11. package/dist/cjs/objects/ClassComponent.js +2 -0
  12. package/dist/cjs/objects/ExecutionScope.js +1 -1
  13. package/dist/cjs/objects/Net.js +3 -2
  14. package/dist/cjs/objects/PinTypes.js +7 -1
  15. package/dist/cjs/objects/types.js +11 -1
  16. package/dist/cjs/regenerate-tests.js +84 -14
  17. package/dist/cjs/render.js +22 -15
  18. package/dist/cjs/sizing.js +4 -6
  19. package/dist/cjs/utils.js +29 -5
  20. package/dist/cjs/visitor.js +176 -10
  21. package/dist/esm/BaseVisitor.mjs +6 -1
  22. package/dist/esm/antlr/CircuitScriptLexer.mjs +204 -200
  23. package/dist/esm/antlr/CircuitScriptParser.mjs +1061 -1171
  24. package/dist/esm/antlr/CircuitScriptVisitor.mjs +3 -0
  25. package/dist/esm/draw_symbols.mjs +378 -102
  26. package/dist/esm/execute.mjs +40 -15
  27. package/dist/esm/geometry.mjs +79 -17
  28. package/dist/esm/globals.mjs +40 -6
  29. package/dist/esm/helpers.mjs +38 -1
  30. package/dist/esm/layout.mjs +75 -42
  31. package/dist/esm/main.mjs +11 -5
  32. package/dist/esm/objects/ClassComponent.mjs +6 -0
  33. package/dist/esm/objects/ExecutionScope.mjs +1 -1
  34. package/dist/esm/objects/Net.mjs +3 -2
  35. package/dist/esm/objects/PinTypes.mjs +6 -0
  36. package/dist/esm/objects/types.mjs +14 -0
  37. package/dist/esm/regenerate-tests.mjs +85 -15
  38. package/dist/esm/render.mjs +23 -16
  39. package/dist/esm/sizing.mjs +3 -4
  40. package/dist/esm/utils.mjs +26 -4
  41. package/dist/esm/visitor.mjs +179 -13
  42. package/dist/types/antlr/CircuitScriptLexer.d.ts +42 -41
  43. package/dist/types/antlr/CircuitScriptParser.d.ts +144 -133
  44. package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -0
  45. package/dist/types/draw_symbols.d.ts +24 -6
  46. package/dist/types/execute.d.ts +5 -4
  47. package/dist/types/geometry.d.ts +5 -3
  48. package/dist/types/globals.d.ts +38 -6
  49. package/dist/types/helpers.d.ts +12 -0
  50. package/dist/types/layout.d.ts +2 -1
  51. package/dist/types/objects/ClassComponent.d.ts +8 -0
  52. package/dist/types/objects/PinTypes.d.ts +1 -0
  53. package/dist/types/objects/Wire.d.ts +4 -2
  54. package/dist/types/objects/types.d.ts +8 -0
  55. package/dist/types/sizing.d.ts +0 -4
  56. package/dist/types/utils.d.ts +3 -0
  57. package/dist/types/visitor.d.ts +8 -1
  58. package/fonts/Arial.ttf +0 -0
  59. package/libs/lib.cst +78 -55
  60. package/package.json +1 -1
@@ -195,20 +195,20 @@ class ExecutionContext {
195
195
  return component;
196
196
  }
197
197
  printPoint(extra = '') {
198
- let netName = globals_js_1.NoNetText;
198
+ let netString = globals_js_1.NoNetText;
199
199
  if (this.scope.currentComponent === null || this.scope.currentPin === null) {
200
200
  this.log((extra !== '' ? (extra + ' ') : '') + 'point is null');
201
201
  return;
202
202
  }
203
203
  if (this.scope.hasNet(this.scope.currentComponent, this.scope.currentPin)) {
204
- netName = this.scope
204
+ netString = this.scope
205
205
  .getNet(this.scope.currentComponent, this.scope.currentPin)
206
206
  .toString();
207
207
  }
208
208
  this.log((extra !== '' ? (extra + ' ') : '') + 'point: ' +
209
209
  this.scope.currentComponent.instanceName +
210
210
  ' ' +
211
- this.scope.currentPin + ' ' + netName);
211
+ this.scope.currentPin + ' ' + netString);
212
212
  }
213
213
  addComponentExisting(component, pin) {
214
214
  const startPin = pin;
@@ -462,34 +462,34 @@ class ExecutionContext {
462
462
  for (let i = 0; i < reversed.length; i++) {
463
463
  const context = reversed[i];
464
464
  if (context.hasFunction(idName)) {
465
- return {
465
+ return new types_js_1.DeclaredReference({
466
466
  found: true,
467
467
  value: context.getFunction(idName),
468
468
  type: globals_js_1.ReferenceTypes.function,
469
469
  name: idName,
470
- };
470
+ });
471
471
  }
472
472
  else if (context.scope.variables.has(idName)) {
473
- return {
473
+ return new types_js_1.DeclaredReference({
474
474
  found: true,
475
475
  value: context.scope.variables.get(idName),
476
476
  type: globals_js_1.ReferenceTypes.variable,
477
477
  name: idName,
478
- };
478
+ });
479
479
  }
480
480
  else if (context.scope.instances.has(idName)) {
481
- return {
481
+ return new types_js_1.DeclaredReference({
482
482
  found: true,
483
483
  value: context.scope.instances.get(idName),
484
484
  type: globals_js_1.ReferenceTypes.instance,
485
485
  name: idName,
486
- };
486
+ });
487
487
  }
488
488
  }
489
- return {
489
+ return new types_js_1.DeclaredReference({
490
490
  found: false,
491
491
  name: idName,
492
- };
492
+ });
493
493
  }
494
494
  callFunction(functionName, functionParams, executionStack, netNamespace) {
495
495
  let __runFunc = null;
@@ -516,6 +516,7 @@ class ExecutionContext {
516
516
  }
517
517
  if (__runFunc !== null) {
518
518
  this.log(`call function '${functionName}'`);
519
+ this.log(`net namespace: ${netNamespace}`);
519
520
  const functionResult = __runFunc(functionParams, { netNamespace });
520
521
  this.log(`done call function '${functionName}'`);
521
522
  return functionResult;
@@ -648,6 +649,10 @@ class ExecutionContext {
648
649
  this.scope.setActive(ExecutionScope_js_1.ActiveObject.Wire, wireId);
649
650
  this.scope.sequence.push([ExecutionScope_js_1.SequenceAction.Wire, wireId, tmp]);
650
651
  this.scope.currentComponent.pinWires.set(this.scope.currentPin, tmp);
652
+ if (!this.scope.currentComponent.didSetWireOrientationAngle) {
653
+ this.applyComponentAngleFromWire(this.scope.currentComponent, this.scope.currentPin, true);
654
+ this.scope.currentComponent.didSetWireOrientationAngle = true;
655
+ }
651
656
  }
652
657
  addPoint(pointId, userDefined = true) {
653
658
  if (this.scope.instances.has(pointId)) {
@@ -698,18 +703,37 @@ class ExecutionContext {
698
703
  this.scope.currentComponent.styles[key] = styles[key];
699
704
  }
700
705
  }
701
- applyComponentAngleFromWire(component, pin) {
706
+ applyComponentAngleFromWire(component, pin, opposite = false) {
702
707
  if (this.componentAngleFollowsWire
703
708
  && component.followWireOrientationProp
704
709
  && component.useWireOrientationAngle
710
+ && !component.didSetWireOrientationAngle
705
711
  && this.scope.currentWireId !== -1) {
706
712
  const currentWire = this.scope.wires[this.scope.currentWireId];
707
- const lastSegment = currentWire.path[currentWire.path.length - 1];
713
+ let useSegment = currentWire.path[currentWire.path.length - 1];
714
+ if (opposite) {
715
+ useSegment = currentWire.path[0];
716
+ }
708
717
  const pinPositions = (0, layout_js_1.CalculatePinPositions)(component);
709
718
  if (pinPositions.has(pin)) {
710
719
  const connectedPinPos = pinPositions.get(pin);
711
720
  let targetAngle = null;
712
- switch (lastSegment.direction) {
721
+ let useDirection = useSegment.direction;
722
+ if (opposite) {
723
+ if (useDirection === types_js_1.Direction.Down) {
724
+ useDirection = types_js_1.Direction.Up;
725
+ }
726
+ else if (useDirection === types_js_1.Direction.Up) {
727
+ useDirection = types_js_1.Direction.Down;
728
+ }
729
+ else if (useDirection === types_js_1.Direction.Right) {
730
+ useDirection = types_js_1.Direction.Left;
731
+ }
732
+ else if (useDirection === types_js_1.Direction.Left) {
733
+ useDirection = types_js_1.Direction.Right;
734
+ }
735
+ }
736
+ switch (useDirection) {
713
737
  case types_js_1.Direction.Down:
714
738
  targetAngle = 90;
715
739
  break;
@@ -748,6 +772,7 @@ class ExecutionContext {
748
772
  component.setParam('angle', 270);
749
773
  }
750
774
  component.wireOrientationAngle = useAngle;
775
+ component.didSetWireOrientationAngle = true;
751
776
  }
752
777
  }
753
778
  }
@@ -3,11 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.VerticalAlign = exports.HorizontalAlign = exports.Geometry = exports.GeometryProp = exports.Label = exports.Textbox = void 0;
6
+ exports.VerticalAlign = exports.HorizontalAlign = exports.Geometry = exports.GeometryProp = exports.Textbox = void 0;
7
7
  const core_1 = __importDefault(require("@flatten-js/core"));
8
8
  const sizing_js_1 = require("./sizing.js");
9
9
  const globals_js_1 = require("./globals.js");
10
10
  const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
11
+ const PinTypes_js_1 = require("./objects/PinTypes.js");
12
+ const utils_js_1 = require("./utils.js");
11
13
  class Textbox extends core_1.default.Polygon {
12
14
  get box() {
13
15
  return this.polygon.box;
@@ -41,34 +43,91 @@ class Textbox extends core_1.default.Polygon {
41
43
  else {
42
44
  throw 'Invalid string passed into textbox';
43
45
  }
44
- const { fontSize = 10, anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', } = style ?? {};
45
- const { width, height, box } = (0, sizing_js_1.measureTextSize2)(useText, globals_js_1.defaultFont, fontSize, fontWeight, anchor, vanchor);
46
- const polygonCoords = [
47
- [box.x, box.y],
48
- [box.x2, box.y],
49
- [box.x2, box.y2],
50
- [box.x, box.y2],
51
- [box.x, box.y],
52
- ];
46
+ const { fontSize = 10, anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', portType = null, } = style ?? {};
47
+ const { width, height, box } = (0, sizing_js_1.measureTextSize2)(useText, globals_js_1.defaultFont, fontSize * globals_js_1.fontDisplayScale, fontWeight, anchor, vanchor);
48
+ let polygonCoords = [];
49
+ let anchorOffsetX = 0;
50
+ let anchorOffsetY = 0;
51
+ if (portType === null) {
52
+ polygonCoords = [
53
+ [box.x, box.y],
54
+ [box.x2, box.y],
55
+ [box.x2, box.y2],
56
+ [box.x, box.y2],
57
+ [box.x, box.y],
58
+ ];
59
+ }
60
+ else if (PinTypes_js_1.AllPinTypes.indexOf(portType) !== -1) {
61
+ const paddingHorizontal = globals_js_1.PortPaddingHorizontal;
62
+ const paddingVert = globals_js_1.PortPaddingVertical;
63
+ if (portType === PinTypes_js_1.PinTypes.Input) {
64
+ polygonCoords = [
65
+ [box.x - paddingHorizontal - globals_js_1.PortArrowSize, box.y - paddingVert],
66
+ [box.x2 + paddingHorizontal, box.y - paddingVert],
67
+ [box.x2 + paddingHorizontal, box.y2 + paddingVert],
68
+ [box.x - paddingHorizontal - globals_js_1.PortArrowSize, box.y2 + paddingVert],
69
+ [box.x - paddingHorizontal - globals_js_1.PortArrowSize, box.y - paddingVert],
70
+ ];
71
+ anchorOffsetX += (globals_js_1.PortArrowSize + paddingHorizontal);
72
+ }
73
+ else if (portType === PinTypes_js_1.PinTypes.Output) {
74
+ polygonCoords = [
75
+ [box.x - paddingHorizontal, box.y - paddingVert],
76
+ [box.x2 + paddingHorizontal + globals_js_1.PortArrowSize, box.y - paddingVert],
77
+ [box.x2 + paddingHorizontal + globals_js_1.PortArrowSize, box.y2 + paddingVert],
78
+ [box.x - paddingHorizontal, box.y2 + paddingVert],
79
+ [box.x - paddingHorizontal, box.y - paddingVert],
80
+ ];
81
+ anchorOffsetX += paddingHorizontal;
82
+ }
83
+ else if (portType === PinTypes_js_1.PinTypes.IO) {
84
+ polygonCoords = [
85
+ [box.x - paddingHorizontal - globals_js_1.PortArrowSize, box.y - paddingVert],
86
+ [box.x2 + paddingHorizontal + globals_js_1.PortArrowSize, box.y - paddingVert],
87
+ [box.x2 + paddingHorizontal + globals_js_1.PortArrowSize, box.y2 + paddingVert],
88
+ [box.x - paddingHorizontal - globals_js_1.PortArrowSize, box.y2 + paddingVert],
89
+ [box.x - paddingHorizontal - globals_js_1.PortArrowSize, box.y - paddingVert],
90
+ ];
91
+ anchorOffsetX += paddingHorizontal + globals_js_1.PortArrowSize;
92
+ }
93
+ else if (portType === PinTypes_js_1.PinTypes.Any) {
94
+ polygonCoords = [
95
+ [box.x - paddingHorizontal, box.y - paddingVert],
96
+ [box.x2 + paddingHorizontal, box.y - paddingVert],
97
+ [box.x2 + paddingHorizontal, box.y2 + paddingVert],
98
+ [box.x - paddingHorizontal, box.y2 + paddingVert],
99
+ [box.x - paddingHorizontal, box.y - paddingVert],
100
+ ];
101
+ anchorOffsetX += paddingHorizontal;
102
+ }
103
+ anchorOffsetY += paddingVert / 2;
104
+ }
53
105
  const polygon = new core_1.default.Polygon(polygonCoords);
54
- return new Textbox(id, useText, [x, y], polygon, style, box, label);
106
+ return new Textbox(id, useText, [x + anchorOffsetX, y + anchorOffsetY], polygon, style, box, label);
55
107
  }
56
108
  rotate(angle, origin) {
57
109
  const feature = super.rotate(angle, origin);
58
- return new Textbox(this.id, this.text, this.anchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
110
+ const newAnchorPoint = this.transformAnchorPoint(segment => segment.rotate(angle, origin));
111
+ return new Textbox(this.id, this.text, newAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
59
112
  }
60
113
  transform(matrix) {
61
114
  const feature = super.transform(matrix);
62
- return new Textbox(this.id, this.text, this.anchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
115
+ const newAnchorPoint = this.transformAnchorPoint(segment => segment.transform(matrix));
116
+ return new Textbox(this.id, this.text, newAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
117
+ }
118
+ transformAnchorPoint(callback) {
119
+ const anchorPointSegment = new core_1.default.Segment(new core_1.default.Point(0, 0), new core_1.default.Point(this.anchorPoint));
120
+ const newSegment = callback(anchorPointSegment);
121
+ const lastPoint = newSegment.vertices[newSegment.vertices.length - 1];
122
+ return [
123
+ lastPoint.x, lastPoint.y
124
+ ];
63
125
  }
64
126
  getLabelPosition() {
65
127
  return this.anchorPoint;
66
128
  }
67
129
  }
68
130
  exports.Textbox = Textbox;
69
- class Label extends Textbox {
70
- }
71
- exports.Label = Label;
72
131
  class GeometryProp {
73
132
  constructor(name, value) {
74
133
  this.name = name;
@@ -151,7 +210,7 @@ class Geometry {
151
210
  && feature.text.trim().length === 0) {
152
211
  return;
153
212
  }
154
- if (feature instanceof Textbox && !feature.label) {
213
+ if (feature instanceof Textbox) {
155
214
  const [x, y] = feature.anchorPoint;
156
215
  box = {
157
216
  xmin: box.xmin + x,
@@ -247,7 +306,9 @@ class Geometry {
247
306
  const existingSegments = [];
248
307
  wirePoints.forEach(points => {
249
308
  const tmpPoints = points.map(pt => {
250
- return new core_1.default.Point(pt.x, pt.y);
309
+ const roundedX = (0, utils_js_1.roundValue)(pt.x);
310
+ const roundedY = (0, utils_js_1.roundValue)(pt.y);
311
+ return new core_1.default.Point(roundedX, roundedY);
251
312
  });
252
313
  for (let i = 0; i < tmpPoints.length - 1; i++) {
253
314
  const pt1 = tmpPoints[i];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.wireColor = exports.junctionColor = exports.junctionSize = exports.bodyColor = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.portHeight = exports.portWidth = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = void 0;
3
+ exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = void 0;
4
4
  var GlobalNames;
5
5
  (function (GlobalNames) {
6
6
  GlobalNames["__root"] = "__root";
@@ -26,15 +26,49 @@ var SymbolPinSide;
26
26
  SymbolPinSide["Left"] = "left";
27
27
  SymbolPinSide["Right"] = "right";
28
28
  })(SymbolPinSide || (exports.SymbolPinSide = SymbolPinSide = {}));
29
+ var LengthUnit;
30
+ (function (LengthUnit) {
31
+ LengthUnit["mm"] = "mm";
32
+ LengthUnit["mils"] = "mils";
33
+ LengthUnit["px"] = "px";
34
+ })(LengthUnit || (exports.LengthUnit = LengthUnit = {}));
35
+ var WireAutoDirection;
36
+ (function (WireAutoDirection) {
37
+ WireAutoDirection["Auto"] = "auto";
38
+ WireAutoDirection["Auto_"] = "auto_";
39
+ })(WireAutoDirection || (exports.WireAutoDirection = WireAutoDirection = {}));
40
+ exports.MilsToMM = 0.0254;
41
+ exports.MMToPx = 3.779276;
42
+ exports.PxToMM = 0.2645833;
29
43
  exports.portWidth = 20;
30
44
  exports.portHeight = 2;
31
- exports.defaultFont = 'Open Sans-Regular, Arial';
32
- exports.defaultFontBold = 'Open Sans-Bold, Arial-Bold, Arial';
45
+ exports.defaultGridSizeUnits = exports.MilsToMM * 100;
46
+ exports.defaultZoomScale = 2.5;
47
+ exports.fontDisplayScale = 0.032;
48
+ exports.defaultSymbolLineWidth = exports.MilsToMM * 6;
49
+ exports.defaultWireLineWidth = exports.MilsToMM * 6;
50
+ exports.defaultPinNameTextSize = 40;
51
+ exports.defaultPinIdTextSize = 30;
52
+ exports.CustomSymbolPinTextSize = exports.defaultPinNameTextSize;
53
+ exports.CustomSymbolPinIdSize = exports.defaultPinIdTextSize;
54
+ exports.CustomSymbolRefDesSize = 50;
55
+ exports.CustomSymbolParamTextSize = 40;
56
+ exports.defaultFrameTitleTextSize = 60;
57
+ exports.displayUnits = LengthUnit.mils;
58
+ exports.defaultFont = 'Arial';
59
+ exports.defaultFontBold = 'Arial';
33
60
  exports.defaultFontSize = 10;
34
- exports.bodyColor = '#FFFEAF';
35
- exports.junctionSize = 5;
36
- exports.junctionColor = 'rgb(0, 132, 0)';
37
- exports.wireColor = 'rgb(0, 132, 0)';
61
+ exports.junctionSize = exports.MilsToMM * 20;
62
+ exports.PortArrowSize = exports.MilsToMM * 50;
63
+ exports.PortPaddingHorizontal = exports.MilsToMM * 10;
64
+ exports.PortPaddingVertical = exports.MilsToMM * 10;
65
+ exports.ColorScheme = {
66
+ BodyColor: 'rgb(255, 255, 194)',
67
+ JunctionColor: 'rgba(0, 132, 0)',
68
+ WireColor: 'rgb(0, 132, 0)',
69
+ PinLineColor: '#333',
70
+ PinNameColor: '#333',
71
+ };
38
72
  var ComponentTypes;
39
73
  (function (ComponentTypes) {
40
74
  ComponentTypes["gnd"] = "gnd";
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getPackageVersion = exports.getDefaultLibsPath = exports.getFontsPath = exports.getCurrentPath = exports.detectJSModuleType = exports.renderScript = exports.validateScript = exports.ParseErrorStrategy = exports.getSemanticTokens = exports.getScriptText = exports.prepareFile = exports.JSModuleType = void 0;
6
+ exports.pxToMM = exports.milsToMM = exports.UnitDimension = exports.getPackageVersion = exports.getDefaultLibsPath = exports.getFontsPath = exports.getCurrentPath = exports.detectJSModuleType = exports.renderScript = exports.validateScript = exports.ParseErrorStrategy = exports.getSemanticTokens = exports.getScriptText = exports.prepareFile = exports.JSModuleType = void 0;
7
7
  const fs_1 = require("fs");
8
8
  const export_js_1 = require("./export.js");
9
9
  const layout_js_1 = require("./layout.js");
@@ -19,6 +19,7 @@ const lexer_js_1 = require("./lexer.js");
19
19
  const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
20
20
  const SemanticTokenVisitor_js_1 = require("./SemanticTokenVisitor.js");
21
21
  const path_1 = __importDefault(require("path"));
22
+ const globals_js_1 = require("./globals.js");
22
23
  var JSModuleType;
23
24
  (function (JSModuleType) {
24
25
  JSModuleType["CommonJs"] = "cjs";
@@ -174,7 +175,10 @@ function renderScript(scriptData, outputPath, options) {
174
175
  const { tree, parser, hasParseError, hasError, parserTimeTaken, lexerTimeTaken } = (0, parser_js_1.parseFileWithVisitor)(visitor, scriptData);
175
176
  showStats && console.log('Lexing took:', lexerTimeTaken);
176
177
  showStats && console.log('Parsing took:', parserTimeTaken);
177
- dumpNets && console.log(visitor.dumpNets());
178
+ if (dumpNets) {
179
+ const nets = visitor.dumpNets();
180
+ console.log(nets);
181
+ }
178
182
  dumpData && (0, fs_1.writeFileSync)('dump/tree.lisp', tree.toStringTree(null, parser));
179
183
  dumpData && (0, fs_1.writeFileSync)('dump/raw-parser.txt', visitor.logger.dump());
180
184
  if (hasError || hasParseError) {
@@ -271,3 +275,37 @@ function getPackageVersion() {
271
275
  return version;
272
276
  }
273
277
  exports.getPackageVersion = getPackageVersion;
278
+ class UnitDimension {
279
+ constructor(value, type = globals_js_1.LengthUnit.mils) {
280
+ this.value = value;
281
+ this.type = type;
282
+ }
283
+ getMM() {
284
+ switch (this.type) {
285
+ case globals_js_1.LengthUnit.mm:
286
+ return this.value;
287
+ case globals_js_1.LengthUnit.mils:
288
+ return this.value * globals_js_1.MilsToMM;
289
+ case globals_js_1.LengthUnit.px:
290
+ return this.value * globals_js_1.PxToMM;
291
+ }
292
+ }
293
+ static mm(value) {
294
+ return new UnitDimension(value, globals_js_1.LengthUnit.mm);
295
+ }
296
+ static mils(value) {
297
+ return new UnitDimension(value, globals_js_1.LengthUnit.mils);
298
+ }
299
+ static px(value) {
300
+ return new UnitDimension(value, globals_js_1.LengthUnit.px);
301
+ }
302
+ }
303
+ exports.UnitDimension = UnitDimension;
304
+ function milsToMM(value) {
305
+ return value * globals_js_1.MilsToMM;
306
+ }
307
+ exports.milsToMM = milsToMM;
308
+ function pxToMM(value) {
309
+ return value * globals_js_1.PxToMM;
310
+ }
311
+ exports.pxToMM = pxToMM;
@@ -11,6 +11,7 @@ const logger_js_1 = require("./logger.js");
11
11
  const Frame_js_1 = require("./objects/Frame.js");
12
12
  const utils_js_1 = require("./utils.js");
13
13
  const types_js_1 = require("./objects/types.js");
14
+ const helpers_js_1 = require("./helpers.js");
14
15
  class LayoutEngine {
15
16
  constructor() {
16
17
  this.placeSubgraphVersion = 2;
@@ -186,7 +187,7 @@ class LayoutEngine {
186
187
  }
187
188
  placeAndSizeFrame(frame, level = 0) {
188
189
  const innerFrames = frame.innerItems;
189
- const gridSize = 20;
190
+ const gridSize = globals_js_1.defaultGridSizeUnits;
190
191
  let accumX = 0;
191
192
  let accumY = 0;
192
193
  const boundPoints = [];
@@ -326,7 +327,7 @@ class LayoutEngine {
326
327
  tmpFrame.containsTitle = true;
327
328
  tmpFrame.subgraphId = title.replace(/\s/g, "_");
328
329
  const textObject = new RenderText(title);
329
- textObject.fontSize = 16;
330
+ textObject.fontSize = globals_js_1.defaultFrameTitleTextSize;
330
331
  textObject.fontWeight = 'bold';
331
332
  textObject.symbol.refreshDrawing();
332
333
  tmpFrame.innerItems.push(textObject);
@@ -388,7 +389,12 @@ class LayoutEngine {
388
389
  }
389
390
  else {
390
391
  const symbolPinDefinitions = generateLayoutPinDefinition(component);
391
- tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions);
392
+ if (component.typeProp === 'module') {
393
+ tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions);
394
+ }
395
+ else {
396
+ tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions);
397
+ }
392
398
  }
393
399
  applyComponentParamsToSymbol(typeProp, component, tmpSymbol);
394
400
  let didSetAngle = false;
@@ -405,7 +411,7 @@ class LayoutEngine {
405
411
  component.parameters.get('flipY');
406
412
  }
407
413
  if (tmpSymbol instanceof draw_symbols_js_1.SymbolCustom && widthProp) {
408
- tmpSymbol.bodyWidth = widthProp;
414
+ tmpSymbol.bodyWidth = (0, helpers_js_1.milsToMM)(widthProp);
409
415
  }
410
416
  if (!didSetAngle && component.parameters.has('_addDirection')) {
411
417
  tmpSymbol.refreshDrawing(false);
@@ -586,6 +592,10 @@ class LayoutEngine {
586
592
  this.placeNodeAtPosition(0, 0, node1, 1);
587
593
  return;
588
594
  }
595
+ let fixedNode;
596
+ let fixedNodePin;
597
+ let floatingNode;
598
+ let floatingNodePin;
589
599
  subgraphEdges.forEach(edge => {
590
600
  const [nodeId1, pin1, nodeId2, pin2] = graph.edge(edge);
591
601
  const [, node1] = graph.node(nodeId1);
@@ -598,10 +608,6 @@ class LayoutEngine {
598
608
  originNodes.push(node1);
599
609
  originNodeGroups.set(node1.toString(), [node1]);
600
610
  }
601
- let fixedNode;
602
- let fixedNodePin;
603
- let floatingNode;
604
- let floatingNodePin;
605
611
  this.print('edge:', '[', node1, pin1, node1.isFloating, ']', '[', node2, pin2, node2.isFloating, ']');
606
612
  if (!node1.isFloating && node2.isFloating) {
607
613
  fixedNode = node1;
@@ -657,12 +663,17 @@ class LayoutEngine {
657
663
  }
658
664
  [node1, node2].forEach(item => {
659
665
  if (item instanceof RenderWire && item.isEndAutoLength()) {
660
- this.print('auto length wire', item);
661
666
  const [instance, pin] = item.getEndAuto();
662
667
  const [, targetNode] = graph.node(instance.instanceName);
668
+ this.print('wire auto length to target:', instance, pin);
663
669
  if (targetNode.isFloating) {
664
670
  throw "Cannot create auto wire with floating node! Wire id: " + item.id + " to node " + instance + " pin " + pin;
665
671
  }
672
+ const targetOriginNode = findOriginNode(targetNode);
673
+ const itemOriginNode = findOriginNode(item);
674
+ if (targetOriginNode !== itemOriginNode) {
675
+ throw "Wire auto length failed. Please specify a fixed wire length.";
676
+ }
666
677
  const [untilX, untilY] = getNodePositionAtPin(targetNode, pin);
667
678
  item.setEndAuto(untilX, untilY);
668
679
  }
@@ -827,25 +838,27 @@ class LayoutEngine {
827
838
  }
828
839
  exports.LayoutEngine = LayoutEngine;
829
840
  function getNodePositionAtPin(item, pin) {
841
+ let x = 0;
842
+ let y = 0;
830
843
  if (item instanceof RenderComponent) {
831
844
  const pinPosition = item.symbol.pinPosition(pin);
832
- return [
833
- item.x + pinPosition.x,
834
- item.y + pinPosition.y
835
- ];
845
+ x = item.x + pinPosition.x;
846
+ y = item.y + pinPosition.y;
836
847
  }
837
848
  else if (item instanceof RenderWire) {
838
849
  if (pin === 0) {
839
- return [item.x, item.y];
850
+ x = item.x;
851
+ y = item.y;
840
852
  }
841
853
  else {
842
854
  const wireEnd = item.getWireEnd();
843
- return [
844
- item.x + wireEnd.x,
845
- item.y + wireEnd.y
846
- ];
855
+ x = item.x + wireEnd.x;
856
+ y = item.y + wireEnd.y;
847
857
  }
848
858
  }
859
+ return [
860
+ (0, utils_js_1.roundValue)(x), (0, utils_js_1.roundValue)(y)
861
+ ];
849
862
  }
850
863
  function getNeighbours(graph, nodeIds) {
851
864
  return nodeIds.reduce((accum, nodeId) => {
@@ -871,11 +884,13 @@ function generateLayoutPinDefinition(component) {
871
884
  if (component.arrangeProps === null) {
872
885
  for (let i = 0; i < existingPinIds.length; i++) {
873
886
  const pinPosition = Math.floor(i / 2);
887
+ const pin = pins.get(existingPinIds[i]);
874
888
  symbolPinDefinitions.push({
875
889
  side: (i % 2 === 0) ? "left" : "right",
876
890
  pinId: existingPinIds[i],
877
- text: pins.get(existingPinIds[i]).name,
891
+ text: pin.name,
878
892
  position: pinPosition,
893
+ pinType: pin.pinType,
879
894
  });
880
895
  }
881
896
  }
@@ -891,11 +906,13 @@ function generateLayoutPinDefinition(component) {
891
906
  }
892
907
  useItems.forEach(pinId => {
893
908
  if (existingPinIds.indexOf(pinId) !== -1) {
909
+ const pin = pins.get(pinId);
894
910
  symbolPinDefinitions.push({
895
911
  side: key,
896
912
  pinId: pinId,
897
- text: pins.get(pinId).name,
898
- position: pins.get(pinId).position,
913
+ text: pin.name,
914
+ position: pin.position,
915
+ pinType: pin.pinType,
899
916
  });
900
917
  addedPins.push(pinId);
901
918
  }
@@ -1018,19 +1035,26 @@ class RenderWire extends RenderObject {
1018
1035
  this.segments.forEach(segment => {
1019
1036
  const { direction, value } = segment;
1020
1037
  let didAddPoint = false;
1038
+ let useValue;
1039
+ if (value instanceof helpers_js_1.UnitDimension) {
1040
+ useValue = value.getMM();
1041
+ }
1042
+ else {
1043
+ useValue = value;
1044
+ }
1021
1045
  if (direction === types_js_1.Direction.Down) {
1022
- tmpY += value;
1046
+ tmpY += useValue;
1023
1047
  }
1024
1048
  else if (direction === types_js_1.Direction.Up) {
1025
- tmpY -= value;
1049
+ tmpY -= useValue;
1026
1050
  }
1027
1051
  else if (direction === types_js_1.Direction.Left) {
1028
- tmpX -= value;
1052
+ tmpX -= useValue;
1029
1053
  }
1030
1054
  else if (direction === types_js_1.Direction.Right) {
1031
- tmpX += value;
1055
+ tmpX += useValue;
1032
1056
  }
1033
- else if (direction === 'auto' || direction === "auto_") {
1057
+ else if (direction === globals_js_1.WireAutoDirection.Auto || direction === globals_js_1.WireAutoDirection.Auto_) {
1034
1058
  const { valueXY = [0, 0] } = segment;
1035
1059
  const tmpPoints = this.getAutoPoints(valueXY, direction);
1036
1060
  tmpPoints.forEach(point => {
@@ -1049,9 +1073,11 @@ class RenderWire extends RenderObject {
1049
1073
  this.points = points;
1050
1074
  }
1051
1075
  getAutoPoints(value, direction) {
1052
- const inQuadrant = geometry_js_1.Geometry.getQuadrant(value[0], value[1]);
1053
- const [dx, dy] = value;
1054
- if (direction === 'auto') {
1076
+ const valueX = (0, utils_js_1.roundValue)(value[0]);
1077
+ const valueY = (0, utils_js_1.roundValue)(value[1]);
1078
+ const inQuadrant = geometry_js_1.Geometry.getQuadrant(valueX, valueY);
1079
+ const [dx, dy] = [valueX, valueY];
1080
+ if (direction === globals_js_1.WireAutoDirection.Auto) {
1055
1081
  switch (inQuadrant) {
1056
1082
  case 0:
1057
1083
  case 2:
@@ -1061,7 +1087,7 @@ class RenderWire extends RenderObject {
1061
1087
  return [[0, dy], [dx, 0]];
1062
1088
  }
1063
1089
  }
1064
- else if (direction === 'auto_') {
1090
+ else if (direction === globals_js_1.WireAutoDirection.Auto_) {
1065
1091
  switch (inQuadrant) {
1066
1092
  case 0:
1067
1093
  case 2:
@@ -1096,17 +1122,24 @@ class RenderWire extends RenderObject {
1096
1122
  let tmpY = this.y;
1097
1123
  excludeLastSegment.forEach(segment => {
1098
1124
  const { direction, value } = segment;
1125
+ let useValue;
1126
+ if (value instanceof helpers_js_1.UnitDimension) {
1127
+ useValue = value.getMM();
1128
+ }
1129
+ else {
1130
+ useValue = value;
1131
+ }
1099
1132
  if (direction === types_js_1.Direction.Down) {
1100
- tmpY += value;
1133
+ tmpY += useValue;
1101
1134
  }
1102
1135
  else if (direction === types_js_1.Direction.Up) {
1103
- tmpY -= value;
1136
+ tmpY -= useValue;
1104
1137
  }
1105
1138
  else if (direction === types_js_1.Direction.Left) {
1106
- tmpX -= value;
1139
+ tmpX -= useValue;
1107
1140
  }
1108
1141
  else if (direction === types_js_1.Direction.Right) {
1109
- tmpX += value;
1142
+ tmpX += useValue;
1110
1143
  }
1111
1144
  });
1112
1145
  let useValue = null;
@@ -1125,8 +1158,8 @@ class RenderWire extends RenderObject {
1125
1158
  case types_js_1.Direction.Down:
1126
1159
  useValue = tmpY - untilY;
1127
1160
  break;
1128
- case 'auto':
1129
- case 'auto_':
1161
+ case globals_js_1.WireAutoDirection.Auto:
1162
+ case globals_js_1.WireAutoDirection.Auto_:
1130
1163
  valueXY = [
1131
1164
  untilX - tmpX,
1132
1165
  untilY - tmpY,
@@ -1193,10 +1226,10 @@ class RenderFrame extends RenderObject {
1193
1226
  this.innerItems = [];
1194
1227
  this.translateX = 0;
1195
1228
  this.translateY = 0;
1196
- this.padding = 20;
1197
- this.gap = 20;
1229
+ this.padding = (0, helpers_js_1.milsToMM)(100);
1230
+ this.gap = (0, helpers_js_1.milsToMM)(100);
1198
1231
  this.direction = Frame_js_1.FramePlotDirection.Column;
1199
- this.borderWidth = 1;
1232
+ this.borderWidth = 5;
1200
1233
  this.subgraphId = "";
1201
1234
  this.containsTitle = false;
1202
1235
  this.frame = frame;