circuitscript 0.1.14 → 0.1.16

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 (39) hide show
  1. package/dist/cjs/BaseVisitor.js +96 -34
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +3 -3
  3. package/dist/cjs/antlr/CircuitScriptParser.js +868 -757
  4. package/dist/cjs/builtinMethods.js +11 -1
  5. package/dist/cjs/execute.js +18 -11
  6. package/dist/cjs/geometry.js +19 -0
  7. package/dist/cjs/globals.js +6 -2
  8. package/dist/cjs/graph.js +298 -0
  9. package/dist/cjs/helpers.js +6 -2
  10. package/dist/cjs/layout.js +27 -261
  11. package/dist/cjs/objects/types.js +27 -6
  12. package/dist/cjs/render.js +20 -14
  13. package/dist/cjs/visitor.js +32 -30
  14. package/dist/esm/BaseVisitor.js +96 -34
  15. package/dist/esm/antlr/CircuitScriptLexer.js +3 -3
  16. package/dist/esm/antlr/CircuitScriptParser.js +864 -755
  17. package/dist/esm/antlr/CircuitScriptVisitor.js +2 -0
  18. package/dist/esm/builtinMethods.js +11 -1
  19. package/dist/esm/execute.js +19 -12
  20. package/dist/esm/geometry.js +19 -0
  21. package/dist/esm/globals.js +5 -1
  22. package/dist/esm/graph.js +293 -0
  23. package/dist/esm/helpers.js +6 -2
  24. package/dist/esm/layout.js +23 -237
  25. package/dist/esm/objects/types.js +27 -6
  26. package/dist/esm/render.js +20 -14
  27. package/dist/esm/visitor.js +33 -31
  28. package/dist/types/BaseVisitor.d.ts +3 -1
  29. package/dist/types/antlr/CircuitScriptParser.d.ts +42 -26
  30. package/dist/types/antlr/CircuitScriptVisitor.d.ts +4 -0
  31. package/dist/types/draw_symbols.d.ts +1 -1
  32. package/dist/types/execute.d.ts +5 -5
  33. package/dist/types/geometry.d.ts +3 -1
  34. package/dist/types/globals.d.ts +7 -3
  35. package/dist/types/graph.d.ts +28 -0
  36. package/dist/types/layout.d.ts +6 -10
  37. package/dist/types/objects/ExecutionScope.d.ts +3 -3
  38. package/dist/types/objects/types.d.ts +16 -6
  39. package/package.json +1 -1
@@ -1,46 +1,25 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
6
  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;
27
- const graphlib_1 = __importStar(require("@dagrejs/graphlib"));
7
+ const graphlib_1 = __importDefault(require("@dagrejs/graphlib"));
28
8
  const { alg } = graphlib_1.default;
29
9
  const draw_symbols_js_1 = require("./draw_symbols.js");
30
- const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
31
10
  const globals_js_1 = require("./globals.js");
32
11
  const geometry_js_1 = require("./geometry.js");
33
- const logger_js_1 = require("./logger.js");
34
12
  const Frame_js_1 = require("./objects/Frame.js");
35
13
  const utils_js_1 = require("./utils.js");
36
14
  const types_js_1 = require("./objects/types.js");
37
15
  const helpers_js_1 = require("./helpers.js");
38
16
  const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
17
+ const graph_js_1 = require("./graph.js");
39
18
  class LayoutEngine {
40
- constructor(options = { showBaseFrame: false }) {
19
+ constructor(logger, options = { showBaseFrame: false }) {
41
20
  this.layoutWarnings = [];
42
21
  this.showBaseFrame = false;
43
- this.logger = new logger_js_1.Logger();
22
+ this.logger = logger;
44
23
  const { showBaseFrame = false } = options ?? {};
45
24
  this.showBaseFrame = showBaseFrame;
46
25
  }
@@ -54,30 +33,8 @@ class LayoutEngine {
54
33
  const padding = ''.padStart(value * 4, ' ');
55
34
  return "[" + value + "]" + padding;
56
35
  }
57
- runLayout(sequence, nets) {
58
- const logNodesAndEdges = true;
36
+ runLayout(graph, containerFrames, nets) {
59
37
  const renderNets = this.collectRenderNets(nets);
60
- this.print('===== creating graph and populating with nodes =====');
61
- const { graph, containerFrames } = this.generateLayoutGraph(sequence, nets);
62
- this.print('===== done populating graph =====');
63
- this.print('');
64
- if (logNodesAndEdges) {
65
- this.print('===== graph edges =====');
66
- const allEdges = graph.edges();
67
- allEdges.forEach(edge => {
68
- const [nodeId1, pin1, nodeId2, pin2] = graph.edge(edge);
69
- this.print(nodeId1, 'pin', pin1, '-----', nodeId2, 'pin', pin2);
70
- });
71
- this.print('===== end edges =====');
72
- this.print();
73
- this.print('===== graph nodes =====');
74
- const nodes = graph.nodes();
75
- nodes.forEach(node => {
76
- this.print(`name:${node}, value:${graph.node(node)}`);
77
- });
78
- this.print('===== end nodes =====');
79
- this.print('');
80
- }
81
38
  const subgraphInfo = this.sizeSubGraphs(graph);
82
39
  const dumpSubgraphInfo = true;
83
40
  if (dumpSubgraphInfo) {
@@ -137,8 +94,19 @@ class LayoutEngine {
137
94
  const value = net.params.get(globals_js_1.NetGraphicsParams.LineWidth);
138
95
  renderNet.lineWidth = (0, helpers_js_1.milsToMM)(value).toNumber();
139
96
  }
140
- if (net.params.has(globals_js_1.NetGraphicsParams.Highight)) {
141
- renderNet.highlight = net.params.get(globals_js_1.NetGraphicsParams.Highight);
97
+ if (net.params.has(globals_js_1.NetGraphicsParams.Highlight)) {
98
+ renderNet.highlight =
99
+ net.params.get(globals_js_1.NetGraphicsParams.Highlight);
100
+ }
101
+ if (net.params.has(globals_js_1.NetGraphicsParams.HighlightWidth)) {
102
+ renderNet.highlightWidth =
103
+ (0, helpers_js_1.milsToMM)(net.params.get(globals_js_1.NetGraphicsParams.HighlightWidth))
104
+ .toNumber();
105
+ }
106
+ if (net.params.has(globals_js_1.NetGraphicsParams.HighlightOpacity)) {
107
+ renderNet.highlightOpacity =
108
+ net.params.get(globals_js_1.NetGraphicsParams.HighlightOpacity)
109
+ .toNumber();
142
110
  }
143
111
  renderNets.set(net.toString(), renderNet);
144
112
  });
@@ -192,12 +160,13 @@ class LayoutEngine {
192
160
  });
193
161
  }
194
162
  else {
195
- const { intersectPoints, segments } = geometry_js_1.Geometry.mergeWires(allLines);
163
+ const { intersectPoints, segments, lines } = geometry_js_1.Geometry.mergeWires(allLines);
196
164
  mergedWires.push({
197
165
  netName: netName,
198
166
  segments,
199
167
  intersectPoints,
200
168
  net: renderNet,
169
+ lines,
201
170
  });
202
171
  intersectPoints.forEach(([x, y]) => {
203
172
  junctions.push(new RenderJunction((0, ParamDefinition_js_1.numeric)(x), (0, ParamDefinition_js_1.numeric)(y), renderNet));
@@ -572,7 +541,7 @@ class LayoutEngine {
572
541
  return item.component.instanceName;
573
542
  }
574
543
  else if (item instanceof RenderWire) {
575
- return getWireName(item.id);
544
+ return (0, graph_js_1.getWireName)(item.id);
576
545
  }
577
546
  return null;
578
547
  }));
@@ -656,158 +625,6 @@ class LayoutEngine {
656
625
  }
657
626
  }
658
627
  }
659
- generateLayoutGraph(sequence, nets) {
660
- let previousNode = null;
661
- let previousPin = null;
662
- const graph = new graphlib_1.Graph({
663
- directed: true,
664
- compound: true,
665
- });
666
- this.print('sequence length:', sequence.length);
667
- const baseFrame = new RenderFrame(new Frame_js_1.Frame(Frame_js_1.FixedFrameIds.BaseFrame));
668
- const frameStack = [baseFrame];
669
- const containerFrames = [baseFrame];
670
- sequence.forEach((sequenceStep, index) => {
671
- const action = sequenceStep[0];
672
- let tmpComponent;
673
- switch (action) {
674
- case ExecutionScope_js_1.SequenceAction.To:
675
- case ExecutionScope_js_1.SequenceAction.At: {
676
- this.print(...sequenceStep);
677
- const [, component, pin] = sequenceStep;
678
- const tmpInstanceName = component.instanceName;
679
- if (!graph.hasNode(tmpInstanceName)) {
680
- this.print('create instance', tmpInstanceName);
681
- const { displayProp = null } = component;
682
- let tmpSymbol;
683
- if (displayProp instanceof draw_symbols_js_1.SymbolDrawing) {
684
- tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(displayProp);
685
- tmpSymbol.drawing.logger = this.logger;
686
- }
687
- else {
688
- const symbolPinDefinitions = generateLayoutPinDefinition(component);
689
- if (component.typeProp === globals_js_1.ComponentTypes.module) {
690
- tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions, component.pinsMaxPositions);
691
- }
692
- else {
693
- tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
694
- }
695
- }
696
- applyComponentParamsToSymbol(component, tmpSymbol);
697
- tmpSymbol.refreshDrawing();
698
- const { width: useWidth, height: useHeight } = tmpSymbol.size();
699
- tmpComponent = new RenderComponent(component, useWidth, useHeight);
700
- tmpComponent.symbol = tmpSymbol;
701
- graph.setNode(tmpInstanceName, [RenderItemType.Component, tmpComponent, index]);
702
- const currentFrame = frameStack[frameStack.length - 1];
703
- currentFrame && currentFrame.innerItems.push(tmpComponent);
704
- }
705
- if (action === ExecutionScope_js_1.SequenceAction.To && previousNode && previousPin) {
706
- this.setGraphEdge(graph, previousNode, tmpInstanceName, makeEdgeValue(previousNode, previousPin, tmpInstanceName, pin, index));
707
- }
708
- previousNode = tmpInstanceName;
709
- previousPin = pin;
710
- break;
711
- }
712
- case ExecutionScope_js_1.SequenceAction.Wire: {
713
- const [, wireId, wireSegments] = sequenceStep;
714
- let useNet;
715
- if (previousNode !== null) {
716
- const [prevNodeType, prevNodeItem] = graph.node(previousNode);
717
- if (prevNodeType === RenderItemType.Component) {
718
- const matchingItem = nets.find(([comp, pin]) => {
719
- return comp.instanceName === previousNode
720
- && pin === previousPin;
721
- });
722
- if (matchingItem !== undefined) {
723
- useNet = matchingItem[2];
724
- }
725
- }
726
- else if (prevNodeType === RenderItemType.Wire) {
727
- useNet = prevNodeItem.net;
728
- }
729
- }
730
- const wire = new RenderWire(useNet, (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), wireSegments);
731
- wire.id = wireId;
732
- wire.netName = useNet.toString();
733
- const wireName = getWireName(wire.id);
734
- graph.setNode(wireName, [RenderItemType.Wire, wire, index]);
735
- this.setGraphEdge(graph, previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, index));
736
- previousNode = wireName;
737
- previousPin = 1;
738
- const wireSegmentsInfo = wireSegments.map(item => {
739
- const tmp = {
740
- direction: item.direction,
741
- value: item.value,
742
- };
743
- if (item.valueXY) {
744
- tmp.valueXY = item.valueXY;
745
- }
746
- if (item.until) {
747
- tmp.until = [item.until[0].toString(), item.until[1]];
748
- }
749
- return tmp;
750
- });
751
- this.print(ExecutionScope_js_1.SequenceAction.Wire, wireId, JSON.stringify(wireSegmentsInfo));
752
- break;
753
- }
754
- case ExecutionScope_js_1.SequenceAction.WireJump: {
755
- this.print(...sequenceStep);
756
- const wireId = sequenceStep[1];
757
- const wireName = getWireName(wireId);
758
- let wirePin = 1;
759
- if (sequenceStep.length === 3) {
760
- wirePin = sequenceStep[2];
761
- }
762
- previousNode = wireName;
763
- previousPin = wirePin;
764
- break;
765
- }
766
- case ExecutionScope_js_1.SequenceAction.Frame: {
767
- const [, frameObject, frameAction] = sequenceStep;
768
- if (frameAction === ExecutionScope_js_1.FrameAction.Enter) {
769
- const prevFrame = frameStack[frameStack.length - 1];
770
- const newFrame = new RenderFrame(frameObject);
771
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Direction)) {
772
- newFrame.direction =
773
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Direction);
774
- }
775
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Padding)) {
776
- newFrame.padding = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Padding));
777
- }
778
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Border)) {
779
- newFrame.borderWidth =
780
- frameObject.parameters.get(Frame_js_1.FrameParamKeys.Border);
781
- }
782
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Width)) {
783
- newFrame.width = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Width));
784
- }
785
- if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Height)) {
786
- newFrame.height = (0, helpers_js_1.milsToMM)(frameObject.parameters.get(Frame_js_1.FrameParamKeys.Height));
787
- }
788
- containerFrames.push(newFrame);
789
- frameStack.push(newFrame);
790
- prevFrame && prevFrame.innerItems.push(newFrame);
791
- }
792
- else if (frameAction === ExecutionScope_js_1.FrameAction.Exit) {
793
- frameStack.pop();
794
- }
795
- break;
796
- }
797
- }
798
- });
799
- return {
800
- graph,
801
- containerFrames,
802
- };
803
- }
804
- setGraphEdge(graph, node1, node2, edgeValue) {
805
- if (!graph.isDirected && graph.hasEdge(node1, node2)) {
806
- this.print(`Warning: edge already exists ${node1} ${node2}`);
807
- }
808
- graph.setEdge(node1, node2, edgeValue);
809
- this.print(`created edge: node1:${node1} node2:${node2} edgeValue:${edgeValue}`);
810
- }
811
628
  sizeSubGraphs(graph) {
812
629
  const subGraphs = alg.components(graph);
813
630
  const subGraphsStarts = [];
@@ -835,10 +652,10 @@ class LayoutEngine {
835
652
  const wires = [];
836
653
  innerGraph.forEach(nodeId => {
837
654
  const [nodeType, item,] = graph.node(nodeId);
838
- if (nodeType === RenderItemType.Component) {
655
+ if (nodeType === graph_js_1.RenderItemType.Component) {
839
656
  renderItems.push(item);
840
657
  }
841
- else if (nodeType === RenderItemType.Wire) {
658
+ else if (nodeType === graph_js_1.RenderItemType.Wire) {
842
659
  wires.push(item);
843
660
  }
844
661
  });
@@ -1106,52 +923,6 @@ function getNeighbours(graph, nodeIds) {
1106
923
  return accum;
1107
924
  }, []);
1108
925
  }
1109
- function makeEdgeValue(instanceName1, instancePin1, instanceName2, instancePin2, priority) {
1110
- return [instanceName1, instancePin1, instanceName2, instancePin2, priority];
1111
- }
1112
- function getWireName(wireId) {
1113
- return 'wire:' + wireId;
1114
- }
1115
- function generateLayoutPinDefinition(component) {
1116
- const pins = component.pins;
1117
- const symbolPinDefinitions = [];
1118
- const existingPinIds = Array.from(pins.keys());
1119
- const arrangeProps = component.arrangeProps ?? [];
1120
- const addedPins = [];
1121
- for (const [key, items] of arrangeProps) {
1122
- let useItems;
1123
- if (!Array.isArray(items)) {
1124
- useItems = [items];
1125
- }
1126
- else {
1127
- useItems = [...items];
1128
- }
1129
- useItems.forEach(pinId => {
1130
- if (pinId instanceof ParamDefinition_js_1.NumericValue) {
1131
- const pinIdValue = pinId.toNumber();
1132
- if (existingPinIds.indexOf(pinIdValue) !== -1) {
1133
- const pin = pins.get(pinIdValue);
1134
- symbolPinDefinitions.push({
1135
- side: key,
1136
- pinId: pinIdValue,
1137
- text: pin.name,
1138
- position: pin.position,
1139
- pinType: pin.pinType,
1140
- });
1141
- addedPins.push(pinIdValue);
1142
- }
1143
- }
1144
- });
1145
- }
1146
- const unplacedPins = existingPinIds.filter(pinId => {
1147
- return addedPins.indexOf(pinId) === -1;
1148
- });
1149
- if (unplacedPins.length > 0) {
1150
- component._unplacedPins = unplacedPins;
1151
- console.warn("Warning: There are unplaced pins: " + unplacedPins);
1152
- }
1153
- return symbolPinDefinitions;
1154
- }
1155
926
  function applyComponentParamsToSymbol(component, symbol) {
1156
927
  const { widthProp = null, heightProp = null } = component;
1157
928
  const newMap = new Map(component.parameters);
@@ -1401,7 +1172,7 @@ class RenderWire extends RenderObject {
1401
1172
  this.refreshPoints();
1402
1173
  }
1403
1174
  toString() {
1404
- return getWireName(this.id);
1175
+ return (0, graph_js_1.getWireName)(this.id);
1405
1176
  }
1406
1177
  }
1407
1178
  exports.RenderWire = RenderWire;
@@ -1500,7 +1271,7 @@ function CalculatePinPositions(component) {
1500
1271
  tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(component.displayProp);
1501
1272
  }
1502
1273
  else {
1503
- const symbolPinDefinitions = generateLayoutPinDefinition(component);
1274
+ const symbolPinDefinitions = (0, graph_js_1.generateLayoutPinDefinition)(component);
1504
1275
  tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
1505
1276
  }
1506
1277
  applyComponentParamsToSymbol(component, tmpSymbol);
@@ -1536,8 +1307,3 @@ exports.ExtractDrawingRects = ExtractDrawingRects;
1536
1307
  function isPointOverlap(x, y, other) {
1537
1308
  return (x >= other.x && y >= other.y && x <= (other.x + other.width) && y <= (other.y + other.height));
1538
1309
  }
1539
- var RenderItemType;
1540
- (function (RenderItemType) {
1541
- RenderItemType["Wire"] = "wire";
1542
- RenderItemType["Component"] = "component";
1543
- })(RenderItemType || (RenderItemType = {}));
@@ -1,25 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = void 0;
3
+ exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
4
+ const globals_js_1 = require("../globals.js");
4
5
  const utils_js_1 = require("../utils.js");
6
+ class CFunctionEntry {
7
+ constructor(name, execute, source, uniqueId) {
8
+ this.name = name;
9
+ this.execute = execute;
10
+ this.uniqueId = uniqueId;
11
+ this.source = source;
12
+ }
13
+ toString() {
14
+ return `[Function: ${this.name}]`;
15
+ }
16
+ }
17
+ exports.CFunctionEntry = CFunctionEntry;
18
+ ;
5
19
  class AnyReference {
6
20
  constructor(refType) {
7
21
  this.found = false;
8
22
  this.trailers = [];
9
- if (refType.value instanceof AnyReference) {
23
+ this.referenceName = 'AnyReference';
24
+ if (refType.value instanceof AnyReference
25
+ && refType.value.type !== globals_js_1.ReferenceTypes.function) {
10
26
  throw new utils_js_1.RuntimeExecutionError("Nested reference types!");
11
27
  }
12
28
  this.found = refType.found;
13
29
  this.name = refType.name;
14
30
  this.trailers = refType.trailers;
15
- this.type = refType.type;
31
+ this.type = refType.type ?? globals_js_1.ReferenceTypes.unknown;
16
32
  this.value = refType.value;
17
33
  this.parentValue = refType.parentValue;
18
34
  }
35
+ toString() {
36
+ return `[${this.referenceName} name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
37
+ }
19
38
  }
20
39
  exports.AnyReference = AnyReference;
21
- class UndeclaredReference {
40
+ class UndeclaredReference extends AnyReference {
22
41
  constructor(reference) {
42
+ super(reference);
23
43
  this.reference = reference;
24
44
  }
25
45
  throwMessage() {
@@ -39,8 +59,9 @@ class UndeclaredReference {
39
59
  }
40
60
  exports.UndeclaredReference = UndeclaredReference;
41
61
  class DeclaredReference extends AnyReference {
42
- toString() {
43
- return `[DeclaredReference name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
62
+ constructor() {
63
+ super(...arguments);
64
+ this.referenceName = 'DeclaredReference';
44
65
  }
45
66
  toDisplayString() {
46
67
  let returnValue = undefined;
@@ -181,12 +181,14 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
181
181
  const mergedWireHighlightGroup = canvas.group();
182
182
  const mergedWireGroup = canvas.group();
183
183
  mergedWires.forEach(tmpItem => {
184
- const { segments, intersectPoints, net = null } = tmpItem;
184
+ const { intersectPoints, net = null, lines = null } = tmpItem;
185
185
  let useJunctionColor = globals_js_1.ColorScheme.JunctionColor;
186
186
  let useColor = globals_js_1.ColorScheme.WireColor;
187
187
  let useLineWidth = globals_js_1.defaultWireLineWidth;
188
188
  let displayHighlight = false;
189
189
  let displayHighlightColor = null;
190
+ let displayHighlightOpacity = 0.3;
191
+ let displayHighlightWidth = 5 * globals_js_1.MilsToMM;
190
192
  if (net !== null) {
191
193
  useColor = net.color ?? globals_js_1.ColorScheme.WireColor;
192
194
  useJunctionColor = net.color ?? globals_js_1.ColorScheme.JunctionColor;
@@ -194,25 +196,29 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
194
196
  if (net.highlight !== null) {
195
197
  displayHighlight = true;
196
198
  displayHighlightColor = net.highlight ?? null;
199
+ if (net.highlightOpacity !== undefined) {
200
+ displayHighlightOpacity = net.highlightOpacity;
201
+ }
202
+ if (net.highlightWidth !== undefined) {
203
+ displayHighlightWidth = net.highlightWidth;
204
+ }
197
205
  }
198
206
  }
199
207
  const pathItems = [];
200
- const highlightExtraSize = 5 * globals_js_1.MilsToMM;
201
- segments.forEach(segment => {
202
- const pt1 = segment[0];
203
- const pt2 = segment[1];
204
- pathItems.push(...[
205
- 'M', pt1[0], pt1[1],
206
- 'L', pt2[0], pt2[1]
207
- ]);
208
+ const useLines = lines ?? [];
209
+ useLines.forEach(line => {
210
+ line.forEach((point, index) => {
211
+ const commandType = (index === 0) ? 'M' : 'L';
212
+ pathItems.push(...[commandType, point[0], point[1]]);
213
+ });
208
214
  });
209
215
  if (displayHighlight) {
210
216
  mergedWireHighlightGroup.path(pathItems)
211
217
  .stroke({
212
- width: useLineWidth + highlightExtraSize,
218
+ width: useLineWidth + displayHighlightWidth,
213
219
  color: displayHighlightColor,
214
- opacity: 0.3,
215
- linecap: 'square'
220
+ opacity: displayHighlightOpacity,
221
+ linecap: 'butt'
216
222
  })
217
223
  .fill('none');
218
224
  }
@@ -220,11 +226,11 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
220
226
  .stroke({
221
227
  width: useLineWidth,
222
228
  color: useColor,
223
- linecap: 'square'
229
+ linecap: 'butt'
224
230
  })
225
231
  .fill('none');
226
232
  const halfJunctionSize = globals_js_1.junctionSize.half();
227
- const highlightJunctionSize = (0, ParamDefinition_js_1.numeric)(globals_js_1.junctionSize.toNumber() + highlightExtraSize);
233
+ const highlightJunctionSize = (0, ParamDefinition_js_1.numeric)(globals_js_1.junctionSize.toNumber() + displayHighlightWidth);
228
234
  const tmpHighlightExtraSize = highlightJunctionSize.half();
229
235
  intersectPoints.forEach(point => {
230
236
  const [x, y,] = point;
@@ -381,7 +381,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
381
381
  if (ctxNestedProperties) {
382
382
  const nestedKeyValues = this.visitResult(ctxNestedProperties);
383
383
  nestedKeyValues.forEach((value, key) => {
384
- parameters.push(['keyword', key, value]);
384
+ parameters.push(['keyword', key, (0, utils_js_1.unwrapValue)(value)]);
385
385
  });
386
386
  }
387
387
  else {
@@ -539,36 +539,36 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
539
539
  this.setResult(ctx, result);
540
540
  };
541
541
  this.visitData_expr_with_assignment = (ctx) => {
542
- let component = null;
543
- let componentCtx = null;
542
+ let dataResult = null;
543
+ let componentCtx;
544
544
  const ctxDataExpr = ctx.data_expr();
545
545
  const ctxAssignmentExpr = ctx.assignment_expr();
546
546
  if (ctxDataExpr) {
547
- component = this.visitResult(ctxDataExpr);
548
- component = (0, utils_js_1.unwrapValue)(component);
547
+ dataResult = this.visitResult(ctxDataExpr);
549
548
  componentCtx = ctxDataExpr;
550
- if (component === null || component === undefined) {
551
- this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
552
- }
553
549
  }
554
550
  else if (ctxAssignmentExpr) {
555
- component = this.visitResult(ctxAssignmentExpr);
551
+ dataResult = this.visitResult(ctxAssignmentExpr);
556
552
  componentCtx = ctxAssignmentExpr;
557
553
  }
558
- if (component instanceof ClassComponent_js_1.ClassComponent
559
- && component.copyProp) {
560
- component = this.getExecutor().copyComponent(component);
561
- }
562
- if (component instanceof types_js_1.UndeclaredReference) {
563
- const { reference: { trailers = [], parentValue = null } } = component;
554
+ if (dataResult instanceof types_js_1.AnyReference) {
555
+ const { trailers = [], parentValue = null } = dataResult;
564
556
  if (parentValue instanceof ClassComponent_js_1.ClassComponent
565
557
  && trailers.length > 0
566
558
  && trailers[0] === globals_js_1.ModuleContainsKeyword) {
567
- component = parentValue;
568
- this.placeModuleContains(component);
559
+ dataResult = parentValue;
560
+ this.placeModuleContains(dataResult);
569
561
  }
570
562
  }
571
- if (component && component instanceof ClassComponent_js_1.ClassComponent) {
563
+ dataResult = (0, utils_js_1.unwrapValue)(dataResult);
564
+ if (dataResult === null || dataResult === undefined) {
565
+ this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
566
+ }
567
+ if (dataResult instanceof ClassComponent_js_1.ClassComponent
568
+ && dataResult.copyProp) {
569
+ dataResult = this.getExecutor().copyComponent(dataResult);
570
+ }
571
+ if (dataResult && dataResult instanceof ClassComponent_js_1.ClassComponent) {
572
572
  const modifiers = ctx.component_modifier_expr();
573
573
  modifiers.forEach(modifier => {
574
574
  const modifierText = modifier.ID(0).getText();
@@ -585,23 +585,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
585
585
  if (modifierText === globals_js_1.ParamKeys.flip) {
586
586
  const flipValue = result;
587
587
  if (flipValue.indexOf('x') !== -1) {
588
- component.setParam(globals_js_1.ParamKeys.flipX, 1);
588
+ dataResult.setParam(globals_js_1.ParamKeys.flipX, 1);
589
589
  shouldIgnoreWireOrientation = true;
590
590
  }
591
591
  if (flipValue.indexOf('y') !== -1) {
592
- component.setParam(globals_js_1.ParamKeys.flipY, 1);
592
+ dataResult.setParam(globals_js_1.ParamKeys.flipY, 1);
593
593
  shouldIgnoreWireOrientation = true;
594
594
  }
595
595
  }
596
596
  else if (modifierText === globals_js_1.ParamKeys.angle) {
597
- component.setParam(globals_js_1.ParamKeys.angle, result);
597
+ dataResult.setParam(globals_js_1.ParamKeys.angle, result);
598
598
  shouldIgnoreWireOrientation = true;
599
599
  }
600
600
  else if (modifierText === 'anchor') {
601
- component.setParam('anchor', result);
601
+ dataResult.setParam('anchor', result);
602
602
  }
603
603
  if (shouldIgnoreWireOrientation) {
604
- component.useWireOrientationAngle = false;
604
+ dataResult.useWireOrientationAngle = false;
605
605
  }
606
606
  });
607
607
  }
@@ -611,15 +611,15 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
611
611
  pinValue = this.visitResult(ctxPinSelectExpr);
612
612
  }
613
613
  else {
614
- if (component instanceof ClassComponent_js_1.ClassComponent) {
615
- pinValue = component.getDefaultPin();
614
+ if (dataResult instanceof ClassComponent_js_1.ClassComponent) {
615
+ pinValue = dataResult.getDefaultPin();
616
616
  }
617
617
  else {
618
- const undeclaredRef = component;
618
+ const undeclaredRef = dataResult;
619
619
  this.throwWithContext(componentCtx, 'Invalid component: ' + undeclaredRef.reference.name);
620
620
  }
621
621
  }
622
- this.setResult(ctx, [component, pinValue]);
622
+ this.setResult(ctx, [dataResult, pinValue]);
623
623
  };
624
624
  this.visitUnaryOperatorExpr = (ctx) => {
625
625
  let value = this.visitResult(ctx.data_expr());
@@ -749,8 +749,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
749
749
  this.setResult(ctx, result);
750
750
  };
751
751
  this.visitAdditionExpr = (ctx) => {
752
- const value1 = this.resolveDataExpr(ctx.data_expr(0));
753
- const value2 = this.resolveDataExpr(ctx.data_expr(1));
752
+ const value1 = (0, utils_js_1.unwrapValue)(this.resolveDataExpr(ctx.data_expr(0)));
753
+ const value2 = (0, utils_js_1.unwrapValue)(this.resolveDataExpr(ctx.data_expr(1)));
754
754
  if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
755
755
  let tmpValue1 = value1;
756
756
  if (value1 instanceof ParamDefinition_js_1.NumericValue) {
@@ -779,6 +779,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
779
779
  };
780
780
  this.visitFunction_def_expr = (ctx) => {
781
781
  const functionName = ctx.ID().getText();
782
+ const uniqueFunctionID = '__._' + ctx.start.line + '_'
783
+ + ctx.start.column + '_' + functionName + '_' + ctx.getText();
782
784
  let funcDefinedParameters = [];
783
785
  const ctxFunctionArgsExpr = ctx.function_args_expr();
784
786
  if (ctxFunctionArgsExpr) {
@@ -800,7 +802,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
800
802
  nextLastExecution.mergeScope(lastExecution.scope, executionContextName);
801
803
  return [lastExecution, returnValue];
802
804
  };
803
- this.getExecutor().createFunction(functionName, __runFunc);
805
+ this.getExecutor().createFunction(functionName, __runFunc, ctx, uniqueFunctionID);
804
806
  };
805
807
  this.visitPin_select_expr2 = (ctx) => {
806
808
  const ctxStringValue = ctx.STRING_VALUE();