circuitscript 0.0.24 → 0.0.25
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.
- package/dist/cjs/BaseVisitor.js +487 -0
- package/dist/cjs/SemanticTokenVisitor.js +218 -0
- package/dist/cjs/SymbolValidatorVisitor.js +233 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +209 -195
- package/dist/cjs/antlr/CircuitScriptParser.js +2310 -2087
- package/dist/cjs/antlr/CircuitScriptVisitor.js +4 -3
- package/dist/cjs/draw_symbols.js +67 -22
- package/dist/cjs/execute.js +51 -53
- package/dist/cjs/geometry.js +28 -8
- package/dist/cjs/helpers.js +175 -5
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/layout.js +8 -0
- package/dist/cjs/lexer.js +19 -22
- package/dist/cjs/main.js +6 -11
- package/dist/cjs/objects/ClassComponent.js +3 -0
- package/dist/cjs/objects/ExecutionScope.js +1 -0
- package/dist/cjs/objects/types.js +7 -1
- package/dist/cjs/parser.js +29 -258
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +529 -820
- package/dist/esm/BaseVisitor.mjs +488 -0
- package/dist/esm/SemanticTokenVisitor.mjs +215 -0
- package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
- package/dist/esm/antlr/CircuitScriptLexer.mjs +184 -194
- package/dist/esm/antlr/CircuitScriptParser.mjs +2279 -2084
- package/dist/esm/antlr/CircuitScriptVisitor.mjs +8 -3
- package/dist/esm/draw_symbols.mjs +67 -22
- package/dist/esm/execute.mjs +50 -52
- package/dist/esm/geometry.mjs +28 -8
- package/dist/esm/helpers.mjs +165 -6
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/layout.mjs +8 -0
- package/dist/esm/lexer.mjs +10 -10
- package/dist/esm/main.mjs +7 -12
- package/dist/esm/objects/ClassComponent.mjs +3 -0
- package/dist/esm/objects/ExecutionScope.mjs +1 -0
- package/dist/esm/objects/types.mjs +6 -0
- package/dist/esm/parser.mjs +25 -230
- package/dist/esm/validate.mjs +74 -0
- package/dist/esm/visitor.mjs +343 -640
- package/dist/types/BaseVisitor.d.ts +69 -0
- package/dist/types/SemanticTokenVisitor.d.ts +36 -0
- package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
- package/dist/types/antlr/CircuitScriptLexer.d.ts +8 -7
- package/dist/types/antlr/CircuitScriptParser.d.ts +513 -469
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +69 -59
- package/dist/types/draw_symbols.d.ts +9 -0
- package/dist/types/execute.d.ts +5 -8
- package/dist/types/geometry.d.ts +4 -0
- package/dist/types/helpers.d.ts +32 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/lexer.d.ts +2 -2
- package/dist/types/objects/ExecutionScope.d.ts +4 -1
- package/dist/types/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +15 -28
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +40 -95
- package/fonts/Inter-Bold.ttf +0 -0
- package/fonts/Inter-Regular.ttf +0 -0
- package/fonts/OpenSans-Regular.ttf +0 -0
- package/fonts/Roboto-Regular.ttf +0 -0
- package/libs/lib.cst +183 -0
- package/package.json +11 -6
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.CircuitScriptVisitor = void 0;
|
|
4
|
+
const antlr4ng_1 = require("antlr4ng");
|
|
5
|
+
class CircuitScriptVisitor extends antlr4ng_1.AbstractParseTreeVisitor {
|
|
5
6
|
}
|
|
6
|
-
exports.
|
|
7
|
+
exports.CircuitScriptVisitor = CircuitScriptVisitor;
|
package/dist/cjs/draw_symbols.js
CHANGED
|
@@ -9,6 +9,8 @@ class SymbolGraphic {
|
|
|
9
9
|
this.drawPortsName = true;
|
|
10
10
|
this.displayBounds = true;
|
|
11
11
|
this._angle = 0;
|
|
12
|
+
this._flipX = 0;
|
|
13
|
+
this._flipY = 0;
|
|
12
14
|
this.labelTexts = new Map();
|
|
13
15
|
}
|
|
14
16
|
get angle() {
|
|
@@ -17,6 +19,18 @@ class SymbolGraphic {
|
|
|
17
19
|
set angle(value) {
|
|
18
20
|
this._angle = value;
|
|
19
21
|
}
|
|
22
|
+
get flipX() {
|
|
23
|
+
return this._flipX;
|
|
24
|
+
}
|
|
25
|
+
set flipX(value) {
|
|
26
|
+
this._flipX = value;
|
|
27
|
+
}
|
|
28
|
+
get flipY() {
|
|
29
|
+
return this._flipY;
|
|
30
|
+
}
|
|
31
|
+
set flipY(value) {
|
|
32
|
+
this._flipY = value;
|
|
33
|
+
}
|
|
20
34
|
refreshDrawing(calculateSize = true) {
|
|
21
35
|
this.generateDrawing();
|
|
22
36
|
calculateSize && this.calculateSize();
|
|
@@ -42,10 +56,11 @@ class SymbolGraphic {
|
|
|
42
56
|
drawPlaceRemove(group, extra) {
|
|
43
57
|
if (extra && extra.place === false) {
|
|
44
58
|
const { start, end } = this.drawing.getBoundingBox(true);
|
|
45
|
-
|
|
59
|
+
const path = geometry_js_1.Geometry.roundPathValues([
|
|
46
60
|
"M", start[0], start[1], "L", end[0], end[1],
|
|
47
61
|
"M", end[0], start[1], "L", start[0], end[1]
|
|
48
|
-
]
|
|
62
|
+
]);
|
|
63
|
+
group.path(path)
|
|
49
64
|
.stroke({
|
|
50
65
|
width: defaultSymbolLineWidth,
|
|
51
66
|
color: 'red'
|
|
@@ -112,27 +127,33 @@ class SymbolGraphic {
|
|
|
112
127
|
}
|
|
113
128
|
switch (useAnchor) {
|
|
114
129
|
case geometry_js_1.HorizontalAlign.Left:
|
|
115
|
-
anchorStyle = 'start';
|
|
130
|
+
anchorStyle = (this.flipX === 0) ? 'start' : 'end';
|
|
116
131
|
break;
|
|
117
132
|
case geometry_js_1.HorizontalAlign.Middle:
|
|
118
133
|
anchorStyle = 'middle';
|
|
119
134
|
break;
|
|
120
135
|
case geometry_js_1.HorizontalAlign.Right:
|
|
121
|
-
anchorStyle = 'end';
|
|
136
|
+
anchorStyle = (this.flipX === 0) ? 'end' : 'start';
|
|
122
137
|
break;
|
|
123
138
|
}
|
|
124
139
|
switch (useDominantBaseline) {
|
|
125
140
|
case geometry_js_1.VerticalAlign.Top:
|
|
126
|
-
dominantBaseline = 'hanging';
|
|
141
|
+
dominantBaseline = (this.flipY === 0) ? 'hanging' : 'text-top';
|
|
127
142
|
break;
|
|
128
143
|
case geometry_js_1.VerticalAlign.Middle:
|
|
129
144
|
dominantBaseline = 'middle';
|
|
130
145
|
break;
|
|
131
146
|
case geometry_js_1.VerticalAlign.Bottom:
|
|
132
|
-
dominantBaseline = 'text-top';
|
|
147
|
+
dominantBaseline = (this.flipY === 0) ? 'text-top' : 'hanging';
|
|
133
148
|
break;
|
|
134
149
|
}
|
|
135
150
|
const position = tmpLabel.getLabelPosition();
|
|
151
|
+
if (this.flipX !== 0) {
|
|
152
|
+
position[0] *= -1;
|
|
153
|
+
}
|
|
154
|
+
if (this.flipY !== 0) {
|
|
155
|
+
position[1] *= -1;
|
|
156
|
+
}
|
|
136
157
|
const useFont = globals_js_1.defaultFont;
|
|
137
158
|
const textContainer = group.group();
|
|
138
159
|
const text = textContainer.text(tmpLabel.text)
|
|
@@ -156,11 +177,26 @@ class SymbolGraphic {
|
|
|
156
177
|
translateY = position[1];
|
|
157
178
|
useRotateAngle = this.angle;
|
|
158
179
|
}
|
|
180
|
+
translateX = this.roundValues(translateX);
|
|
181
|
+
translateY = this.roundValues(translateY);
|
|
159
182
|
text.rotate(labelAngle);
|
|
160
183
|
textContainer.translate(translateX, translateY)
|
|
161
184
|
.rotate(useRotateAngle, -translateX, -translateY);
|
|
185
|
+
const { a, b, c, d, e, f } = textContainer.matrix();
|
|
186
|
+
const newMatrix = {
|
|
187
|
+
a: this.roundValues(a),
|
|
188
|
+
b: this.roundValues(b),
|
|
189
|
+
c: this.roundValues(c),
|
|
190
|
+
d: this.roundValues(d),
|
|
191
|
+
e: this.roundValues(e),
|
|
192
|
+
f: this.roundValues(f),
|
|
193
|
+
};
|
|
194
|
+
textContainer.transform(newMatrix);
|
|
162
195
|
});
|
|
163
196
|
}
|
|
197
|
+
roundValues(value) {
|
|
198
|
+
return +value.toFixed(7);
|
|
199
|
+
}
|
|
164
200
|
flipTextAnchor(value) {
|
|
165
201
|
if (value === geometry_js_1.HorizontalAlign.Left) {
|
|
166
202
|
return geometry_js_1.HorizontalAlign.Right;
|
|
@@ -234,6 +270,8 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
234
270
|
drawing.log("=== start generate drawing ===");
|
|
235
271
|
drawing.clear();
|
|
236
272
|
drawing.angle = this._angle;
|
|
273
|
+
drawing.flipX = this._flipX;
|
|
274
|
+
drawing.flipY = this._flipY;
|
|
237
275
|
const commands = drawing.getCommands();
|
|
238
276
|
drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
|
|
239
277
|
commands.forEach(([commandName, positionParams, keywordParams]) => {
|
|
@@ -310,10 +348,9 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
310
348
|
drawing.log('add pin', ...positionParams);
|
|
311
349
|
const keywordDisplayPinId = 'display_pin_id';
|
|
312
350
|
let displayPinId = true;
|
|
313
|
-
if (keywordParams.has(keywordDisplayPinId)
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
351
|
+
if (keywordParams.has(keywordDisplayPinId)
|
|
352
|
+
&& keywordParams.get(keywordDisplayPinId) === 0) {
|
|
353
|
+
displayPinId = false;
|
|
317
354
|
}
|
|
318
355
|
let pinNameParam = null;
|
|
319
356
|
if (typeof positionParams[1] === 'string') {
|
|
@@ -343,8 +380,8 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
343
380
|
];
|
|
344
381
|
}
|
|
345
382
|
drawing.addPin(...positionParams);
|
|
346
|
-
const
|
|
347
|
-
const [pinId, , angle] =
|
|
383
|
+
const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
|
|
384
|
+
const [pinId, , angle] = lastAddedPin;
|
|
348
385
|
const [, , , endX, endY] = positionParams;
|
|
349
386
|
let pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
|
|
350
387
|
let pinNameOffsetX = 4;
|
|
@@ -437,6 +474,8 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
437
474
|
const maxRightPins = Math.max(...rightPins.map(item => item.position)) + 1;
|
|
438
475
|
const drawing = new SymbolDrawing();
|
|
439
476
|
drawing.angle = this._angle;
|
|
477
|
+
drawing.flipX = this._flipX;
|
|
478
|
+
drawing.flipY = this._flipY;
|
|
440
479
|
const bodyWidth = this.bodyWidth;
|
|
441
480
|
const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
|
|
442
481
|
drawing.addRect(0, 0, bodyWidth, bodyHeight);
|
|
@@ -504,6 +543,8 @@ class SymbolDrawing {
|
|
|
504
543
|
this.items = [];
|
|
505
544
|
this.pins = [];
|
|
506
545
|
this.angle = 0;
|
|
546
|
+
this.flipX = 0;
|
|
547
|
+
this.flipY = 0;
|
|
507
548
|
this.mainOrigin = [0, 0];
|
|
508
549
|
this.logger = null;
|
|
509
550
|
}
|
|
@@ -683,8 +724,9 @@ class SymbolDrawing {
|
|
|
683
724
|
}
|
|
684
725
|
}
|
|
685
726
|
else {
|
|
686
|
-
|
|
687
|
-
|
|
727
|
+
let tmpResult = geometry_js_1.Geometry.groupFlip([item], this.flipX, this.flipY);
|
|
728
|
+
tmpResult = geometry_js_1.Geometry.groupRotate(tmpResult, this.angle, this.mainOrigin);
|
|
729
|
+
const { path, isClosedPolygon } = this.featuresToPath(tmpResult);
|
|
688
730
|
pathItems.push({
|
|
689
731
|
path: path,
|
|
690
732
|
lineWidth: currentLineWidth,
|
|
@@ -697,9 +739,10 @@ class SymbolDrawing {
|
|
|
697
739
|
return pathItems;
|
|
698
740
|
}
|
|
699
741
|
getPinsPath() {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
742
|
+
let features = this.pins.map(item => item[1]);
|
|
743
|
+
features = geometry_js_1.Geometry.groupFlip(features, this.flipX, this.flipY);
|
|
744
|
+
features = geometry_js_1.Geometry.groupRotate(features, this.angle, this.mainOrigin);
|
|
745
|
+
const { path } = this.featuresToPath(features);
|
|
703
746
|
return path;
|
|
704
747
|
}
|
|
705
748
|
getLabels() {
|
|
@@ -720,9 +763,10 @@ class SymbolDrawing {
|
|
|
720
763
|
}
|
|
721
764
|
return accum;
|
|
722
765
|
}, []);
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
766
|
+
let features = [...drawingFeatures, ...pinFeatures];
|
|
767
|
+
features = geometry_js_1.Geometry.groupFlip(features, this.flipX, this.flipY);
|
|
768
|
+
features = geometry_js_1.Geometry.groupRotate(features, this.angle, this.mainOrigin);
|
|
769
|
+
return geometry_js_1.Geometry.groupBounds(features);
|
|
726
770
|
}
|
|
727
771
|
getPinPosition(pinId) {
|
|
728
772
|
const pin = this.pins.find(item => {
|
|
@@ -730,8 +774,9 @@ class SymbolDrawing {
|
|
|
730
774
|
});
|
|
731
775
|
if (pin) {
|
|
732
776
|
const [, feature, angle] = pin;
|
|
733
|
-
|
|
734
|
-
|
|
777
|
+
let tmpFeature = geometry_js_1.Geometry.flip(feature, this.flipX, this.flipY);
|
|
778
|
+
tmpFeature = geometry_js_1.Geometry.rotateDegs(tmpFeature, this.angle, this.mainOrigin);
|
|
779
|
+
const coords = geometry_js_1.Geometry.getCoords(tmpFeature);
|
|
735
780
|
return {
|
|
736
781
|
start: coords[0],
|
|
737
782
|
end: coords[1],
|
package/dist/cjs/execute.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPortSide = exports.isLabelComponent = exports.isNetComponent = exports.ExecutionContext = void 0;
|
|
3
|
+
exports.getPortSide = exports.isNetOnlyComponent = exports.isLabelComponent = exports.isNetComponent = exports.ExecutionContext = void 0;
|
|
4
4
|
const globals_js_1 = require("./globals.js");
|
|
5
5
|
const ClassComponent_js_1 = require("./objects/ClassComponent.js");
|
|
6
6
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
@@ -9,7 +9,7 @@ const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
|
9
9
|
const Wire_js_1 = require("./objects/Wire.js");
|
|
10
10
|
const Frame_js_1 = require("./objects/Frame.js");
|
|
11
11
|
class ExecutionContext {
|
|
12
|
-
constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger) {
|
|
12
|
+
constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, parent) {
|
|
13
13
|
this.tmpPointId = 0;
|
|
14
14
|
this.resolveNet = null;
|
|
15
15
|
this.stopFurtherExpressions = false;
|
|
@@ -24,10 +24,18 @@ class ExecutionContext {
|
|
|
24
24
|
this.scope = ExecutionScope_js_1.ExecutionScope.create();
|
|
25
25
|
this.scope.indentLevel = indentLevel;
|
|
26
26
|
this.setupRoot();
|
|
27
|
+
if (name === '__') {
|
|
28
|
+
this.scope.sequence.push([
|
|
29
|
+
ExecutionScope_js_1.SequenceAction.At,
|
|
30
|
+
this.scope.componentRoot,
|
|
31
|
+
this.scope.currentPin
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
27
34
|
this.silent = silent;
|
|
28
|
-
this.
|
|
35
|
+
this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
|
|
36
|
+
this.parentContext = parent;
|
|
29
37
|
}
|
|
30
|
-
|
|
38
|
+
log(...params) {
|
|
31
39
|
const indentOutput = ''.padStart(this.scope.indentLevel * 4, ' ');
|
|
32
40
|
const indentLevelText = this.scope.indentLevel
|
|
33
41
|
.toString()
|
|
@@ -41,18 +49,13 @@ class ExecutionContext {
|
|
|
41
49
|
}
|
|
42
50
|
setupRoot() {
|
|
43
51
|
const componentRoot = ClassComponent_js_1.ClassComponent.simple(globals_js_1.GlobalNames.__root, 1, '__root');
|
|
44
|
-
componentRoot.typeProp = globals_js_1.ComponentTypes.
|
|
52
|
+
componentRoot.typeProp = globals_js_1.ComponentTypes.point;
|
|
53
|
+
componentRoot.displayProp = 'point';
|
|
45
54
|
this.scope.instances.set(globals_js_1.GlobalNames.__root, componentRoot);
|
|
46
55
|
this.scope.currentComponent = componentRoot;
|
|
47
56
|
this.scope.currentPin = componentRoot.getDefaultPin();
|
|
48
57
|
this.scope.componentRoot = componentRoot;
|
|
49
58
|
}
|
|
50
|
-
instanceExists(instanceName) {
|
|
51
|
-
return this.scope.instances.has(instanceName);
|
|
52
|
-
}
|
|
53
|
-
getComponent(instanceName) {
|
|
54
|
-
return this.scope.instances.get(instanceName);
|
|
55
|
-
}
|
|
56
59
|
getUniqueInstanceName(className) {
|
|
57
60
|
let extraPrefix = '';
|
|
58
61
|
switch (className) {
|
|
@@ -87,7 +90,7 @@ class ExecutionContext {
|
|
|
87
90
|
const net2 = net2_exists
|
|
88
91
|
? this.scope.getNet(component2, component2Pin)
|
|
89
92
|
: null;
|
|
90
|
-
this.
|
|
93
|
+
this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
|
|
91
94
|
let returnNet;
|
|
92
95
|
if (net1 === null && net2 === null) {
|
|
93
96
|
const tmpNet = new Net_js_1.Net(this.netNamespace, this.getUniqueNetName());
|
|
@@ -149,14 +152,14 @@ class ExecutionContext {
|
|
|
149
152
|
let tmpNet;
|
|
150
153
|
if (result.found) {
|
|
151
154
|
tmpNet = result.net;
|
|
152
|
-
this.
|
|
155
|
+
this.log('net found', tmpNet.namespace, tmpNet.name);
|
|
153
156
|
}
|
|
154
157
|
else {
|
|
155
158
|
tmpNet = new Net_js_1.Net(this.netNamespace, netName, priority);
|
|
156
|
-
this.
|
|
159
|
+
this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
|
|
157
160
|
}
|
|
158
161
|
this.scope.setNet(component, 1, tmpNet);
|
|
159
|
-
this.
|
|
162
|
+
this.log('set net', netName, 'component', component);
|
|
160
163
|
}
|
|
161
164
|
const { arrange = null } = props;
|
|
162
165
|
component.arrangeProps = arrange;
|
|
@@ -175,7 +178,7 @@ class ExecutionContext {
|
|
|
175
178
|
const pinsOutput = pins.map((pin) => {
|
|
176
179
|
return pin.id + ':' + pin.name;
|
|
177
180
|
});
|
|
178
|
-
this.
|
|
181
|
+
this.log('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
|
|
179
182
|
return component;
|
|
180
183
|
}
|
|
181
184
|
printPoint(extra = '') {
|
|
@@ -185,7 +188,7 @@ class ExecutionContext {
|
|
|
185
188
|
.getNet(this.scope.currentComponent, this.scope.currentPin)
|
|
186
189
|
.toString();
|
|
187
190
|
}
|
|
188
|
-
this.
|
|
191
|
+
this.log((extra !== '' ? (extra + ' ') : '') + 'point: ' +
|
|
189
192
|
this.scope.currentComponent.instanceName +
|
|
190
193
|
' ' +
|
|
191
194
|
this.scope.currentPin + ' ' + netName);
|
|
@@ -194,7 +197,7 @@ class ExecutionContext {
|
|
|
194
197
|
const startPin = pin;
|
|
195
198
|
const nextPin = component.getNextPinAfter(startPin);
|
|
196
199
|
this.toComponent(component, startPin, { addSequence: true });
|
|
197
|
-
this.
|
|
200
|
+
this.log('move to next pin: ' + nextPin);
|
|
198
201
|
this.atComponent(component, nextPin, {
|
|
199
202
|
addSequence: true
|
|
200
203
|
});
|
|
@@ -202,11 +205,8 @@ class ExecutionContext {
|
|
|
202
205
|
return this.getCurrentPoint();
|
|
203
206
|
}
|
|
204
207
|
toComponent(component, pinId, options) {
|
|
205
|
-
this.
|
|
206
|
-
const { addSequence = false
|
|
207
|
-
if (cloneNetComponent && this.isNetOnlyComponent(component)) {
|
|
208
|
-
component = this.cloneComponent(component);
|
|
209
|
-
}
|
|
208
|
+
this.log('to component');
|
|
209
|
+
const { addSequence = false } = options ?? {};
|
|
210
210
|
if (!(component instanceof ClassComponent_js_1.ClassComponent)) {
|
|
211
211
|
throw "Not a valid component!";
|
|
212
212
|
}
|
|
@@ -226,7 +226,7 @@ class ExecutionContext {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
if (this.scope.hasNet(this.scope.currentComponent, this.scope.currentPin)) {
|
|
229
|
-
this.
|
|
229
|
+
this.log('net: ', this.scope
|
|
230
230
|
.getNet(this.scope.currentComponent, this.scope.currentPin)
|
|
231
231
|
.toString());
|
|
232
232
|
}
|
|
@@ -253,11 +253,8 @@ class ExecutionContext {
|
|
|
253
253
|
return this.getCurrentPoint();
|
|
254
254
|
}
|
|
255
255
|
atComponent(component, pinId, options) {
|
|
256
|
-
this.
|
|
257
|
-
const { addSequence = false
|
|
258
|
-
if (cloneNetComponent && this.isNetOnlyComponent(component)) {
|
|
259
|
-
component = this.cloneComponent(component);
|
|
260
|
-
}
|
|
256
|
+
this.log('at component');
|
|
257
|
+
const { addSequence = false } = options ?? {};
|
|
261
258
|
this.scope.currentComponent = component;
|
|
262
259
|
let usePinId;
|
|
263
260
|
if (pinId === null) {
|
|
@@ -282,9 +279,6 @@ class ExecutionContext {
|
|
|
282
279
|
this.printPoint();
|
|
283
280
|
return this.getCurrentPoint();
|
|
284
281
|
}
|
|
285
|
-
isNetOnlyComponent(component) {
|
|
286
|
-
return isNetComponent(component) && !isLabelComponent(component);
|
|
287
|
-
}
|
|
288
282
|
cloneComponent(component) {
|
|
289
283
|
let clonedComponent = null;
|
|
290
284
|
if (!this.scope.copyIDs.has(component.instanceName)) {
|
|
@@ -299,7 +293,7 @@ class ExecutionContext {
|
|
|
299
293
|
this.scope.instances.set(cloneInstanceName, clonedComponent);
|
|
300
294
|
clonedComponent.instanceName = cloneInstanceName;
|
|
301
295
|
this.linkComponentPinNet(component, 1, clonedComponent, 1);
|
|
302
|
-
this.
|
|
296
|
+
this.log('created clone of net component:', cloneInstanceName);
|
|
303
297
|
return clonedComponent;
|
|
304
298
|
}
|
|
305
299
|
enterBlocks(blockType) {
|
|
@@ -321,7 +315,7 @@ class ExecutionContext {
|
|
|
321
315
|
current_index: null,
|
|
322
316
|
type: blockType,
|
|
323
317
|
});
|
|
324
|
-
this.
|
|
318
|
+
this.log('enter blocks');
|
|
325
319
|
}
|
|
326
320
|
exitBlocks() {
|
|
327
321
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
@@ -342,7 +336,7 @@ class ExecutionContext {
|
|
|
342
336
|
const { entered_at: [component, pin,] } = stackRef;
|
|
343
337
|
this.atComponent(component, pin, { addSequence: true });
|
|
344
338
|
}
|
|
345
|
-
this.
|
|
339
|
+
this.log('exit blocks');
|
|
346
340
|
}
|
|
347
341
|
enterBlock(blockIndex) {
|
|
348
342
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
@@ -361,7 +355,7 @@ class ExecutionContext {
|
|
|
361
355
|
const { entered_at: [component, pin,] } = stackRef;
|
|
362
356
|
this.atComponent(component, pin, { addSequence: true });
|
|
363
357
|
}
|
|
364
|
-
this.
|
|
358
|
+
this.log(`enter inner block of type (${blockType}) >>>`);
|
|
365
359
|
this.scope.indentLevel += 1;
|
|
366
360
|
}
|
|
367
361
|
exitBlock(blockIndex) {
|
|
@@ -375,7 +369,7 @@ class ExecutionContext {
|
|
|
375
369
|
];
|
|
376
370
|
stackRef['block_index'] = null;
|
|
377
371
|
this.scope.indentLevel -= 1;
|
|
378
|
-
this.
|
|
372
|
+
this.log('exit inner block <<<');
|
|
379
373
|
if (blockType === globals_js_1.BlockTypes.Branch) {
|
|
380
374
|
const { entered_at: [component, pin, wireId] } = stackRef;
|
|
381
375
|
this.atComponent(component, pin, { addSequence: true });
|
|
@@ -414,7 +408,7 @@ class ExecutionContext {
|
|
|
414
408
|
});
|
|
415
409
|
}
|
|
416
410
|
getPointBlockLocation() {
|
|
417
|
-
this.
|
|
411
|
+
this.log('get block point');
|
|
418
412
|
for (let i = 0; i < this.scope.indentLevel; i++) {
|
|
419
413
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
|
|
420
414
|
const { entered_at } = stackRef;
|
|
@@ -423,11 +417,11 @@ class ExecutionContext {
|
|
|
423
417
|
return entered_at;
|
|
424
418
|
}
|
|
425
419
|
}
|
|
426
|
-
this.
|
|
420
|
+
this.log('did not find block point');
|
|
427
421
|
return null;
|
|
428
422
|
}
|
|
429
423
|
breakBranch() {
|
|
430
|
-
this.
|
|
424
|
+
this.log('break branch');
|
|
431
425
|
const branchesInfo = this.scope.blockStack.get(this.scope.indentLevel - 1);
|
|
432
426
|
const branchIndex = branchesInfo['block_index'];
|
|
433
427
|
const branchIndexRef = branchesInfo['inner_blocks'].get(branchIndex);
|
|
@@ -436,7 +430,7 @@ class ExecutionContext {
|
|
|
436
430
|
createFunction(functionName, __runFunc) {
|
|
437
431
|
this.scope.functions.set(functionName, __runFunc);
|
|
438
432
|
this.__functionCache[functionName] = __runFunc;
|
|
439
|
-
this.
|
|
433
|
+
this.log(`defined new function '${functionName}'`);
|
|
440
434
|
}
|
|
441
435
|
hasFunction(functionName) {
|
|
442
436
|
return this.scope.functions.has(functionName);
|
|
@@ -485,7 +479,7 @@ class ExecutionContext {
|
|
|
485
479
|
__runFunc = this.getFunction(functionName);
|
|
486
480
|
}
|
|
487
481
|
if (__runFunc === null) {
|
|
488
|
-
this.
|
|
482
|
+
this.log(`searching for function ${functionName} in upper context`);
|
|
489
483
|
const tmpResolveResult = this.resolveVariable(executionStack, functionName);
|
|
490
484
|
if (tmpResolveResult.found) {
|
|
491
485
|
__runFunc = tmpResolveResult.value;
|
|
@@ -494,17 +488,17 @@ class ExecutionContext {
|
|
|
494
488
|
throw `Invalid function ${functionName}`;
|
|
495
489
|
}
|
|
496
490
|
}
|
|
497
|
-
this.
|
|
491
|
+
this.log('save function to cache:', functionName);
|
|
498
492
|
this.__functionCache[functionName] = __runFunc;
|
|
499
493
|
}
|
|
500
494
|
else {
|
|
501
|
-
this.
|
|
495
|
+
this.log('found function in cache:', functionName);
|
|
502
496
|
__runFunc = this.__functionCache[functionName];
|
|
503
497
|
}
|
|
504
498
|
if (__runFunc !== null) {
|
|
505
|
-
this.
|
|
499
|
+
this.log(`call function '${functionName}'`);
|
|
506
500
|
const functionResult = __runFunc(functionParams, { netNamespace });
|
|
507
|
-
this.
|
|
501
|
+
this.log(`done call function '${functionName}'`);
|
|
508
502
|
return functionResult;
|
|
509
503
|
}
|
|
510
504
|
else {
|
|
@@ -512,7 +506,7 @@ class ExecutionContext {
|
|
|
512
506
|
}
|
|
513
507
|
}
|
|
514
508
|
mergeScope(childScope, namespace) {
|
|
515
|
-
this.
|
|
509
|
+
this.log('-- merging scope to parent --');
|
|
516
510
|
const currentComponent = this.scope.currentComponent;
|
|
517
511
|
const currentPin = this.scope.currentPin;
|
|
518
512
|
const currentWireId = this.scope.currentWireId;
|
|
@@ -602,16 +596,16 @@ class ExecutionContext {
|
|
|
602
596
|
this.scope.currentWireId = childScope.currentWireId + wireIdOffset;
|
|
603
597
|
}
|
|
604
598
|
this.printPoint('resume at');
|
|
605
|
-
this.
|
|
599
|
+
this.log('-- nets --');
|
|
606
600
|
const currentNets = this.scope.getNets();
|
|
607
601
|
currentNets.reduce((accum, [, , net]) => {
|
|
608
602
|
if (accum.indexOf(net) === -1) {
|
|
609
603
|
accum.push(net);
|
|
610
|
-
this.
|
|
604
|
+
this.log(`${net.namespace}${net.name} ${net.priority}`);
|
|
611
605
|
}
|
|
612
606
|
return accum;
|
|
613
607
|
}, []);
|
|
614
|
-
this.
|
|
608
|
+
this.log('-- done merging scope --');
|
|
615
609
|
}
|
|
616
610
|
addWire(segments) {
|
|
617
611
|
if (this.scope.currentComponent === null) {
|
|
@@ -630,14 +624,14 @@ class ExecutionContext {
|
|
|
630
624
|
segments.forEach(item => {
|
|
631
625
|
output.push(item.join(","));
|
|
632
626
|
});
|
|
633
|
-
this.
|
|
627
|
+
this.log('add wire: ', output.join("|"));
|
|
634
628
|
this.scope.setActive(ExecutionScope_js_1.ActiveObject.Wire, wireId);
|
|
635
629
|
this.scope.sequence.push([ExecutionScope_js_1.SequenceAction.Wire, wireId, tmp]);
|
|
636
630
|
this.scope.currentComponent.pinWires.set(this.scope.currentPin, tmp);
|
|
637
631
|
}
|
|
638
632
|
addPoint(pointId, userDefined = true) {
|
|
639
633
|
if (this.scope.instances.has(pointId)) {
|
|
640
|
-
this.
|
|
634
|
+
this.log('Warning: ' + pointId + ' is being redefined');
|
|
641
635
|
}
|
|
642
636
|
const useName = userDefined ? 'point.' + pointId : pointId;
|
|
643
637
|
const componentPoint = ClassComponent_js_1.ClassComponent.simple(useName, 1, "point");
|
|
@@ -648,7 +642,7 @@ class ExecutionContext {
|
|
|
648
642
|
return this.getCurrentPoint();
|
|
649
643
|
}
|
|
650
644
|
setProperty(nameWithProp, value) {
|
|
651
|
-
this.
|
|
645
|
+
this.log('set property', nameWithProp, 'value', value);
|
|
652
646
|
let idName;
|
|
653
647
|
let paramName;
|
|
654
648
|
let useActive = false;
|
|
@@ -717,6 +711,10 @@ function isLabelComponent(component) {
|
|
|
717
711
|
return component.parameters.has(globals_js_1.ParamKeys.__is_label);
|
|
718
712
|
}
|
|
719
713
|
exports.isLabelComponent = isLabelComponent;
|
|
714
|
+
function isNetOnlyComponent(component) {
|
|
715
|
+
return isNetComponent(component) && !isLabelComponent(component);
|
|
716
|
+
}
|
|
717
|
+
exports.isNetOnlyComponent = isNetOnlyComponent;
|
|
720
718
|
function getPortSide(pins, arrangeProps) {
|
|
721
719
|
const result = [];
|
|
722
720
|
if (arrangeProps === null) {
|
package/dist/cjs/geometry.js
CHANGED
|
@@ -53,8 +53,12 @@ class Label extends core_1.default.Polygon {
|
|
|
53
53
|
return new Label(id, useText, [x, y], polygon, style, box);
|
|
54
54
|
}
|
|
55
55
|
rotate(angle, origin) {
|
|
56
|
-
const
|
|
57
|
-
return new Label(this.id, this.text, this.anchorPoint,
|
|
56
|
+
const feature = super.rotate(angle, origin);
|
|
57
|
+
return new Label(this.id, this.text, this.anchorPoint, feature, this.style, this.textMeasurementBounds);
|
|
58
|
+
}
|
|
59
|
+
transform(matrix) {
|
|
60
|
+
const feature = super.transform(matrix);
|
|
61
|
+
return new Label(this.id, this.text, this.anchorPoint, feature, this.style, this.textMeasurementBounds);
|
|
58
62
|
}
|
|
59
63
|
getLabelPosition() {
|
|
60
64
|
return this.anchorPoint;
|
|
@@ -104,6 +108,10 @@ class Geometry {
|
|
|
104
108
|
const angleRads = angleDegrees * Math.PI / 180;
|
|
105
109
|
return feature.rotate(angleRads, Geometry.point(center[0], center[1]));
|
|
106
110
|
}
|
|
111
|
+
static flip(feature, flipX, flipY) {
|
|
112
|
+
const flipMatrix = (new core_1.default.Matrix()).scale(flipX === 0 ? 1 : -1, flipY == 0 ? 1 : -1);
|
|
113
|
+
return feature.transform(flipMatrix);
|
|
114
|
+
}
|
|
107
115
|
static groupRotate(features, angle, center) {
|
|
108
116
|
const angleRads = angle * Math.PI / 180;
|
|
109
117
|
const rotateAboutPoint = Geometry.point(center[0], center[1]);
|
|
@@ -111,6 +119,12 @@ class Geometry {
|
|
|
111
119
|
return feature.rotate(angleRads, rotateAboutPoint);
|
|
112
120
|
});
|
|
113
121
|
}
|
|
122
|
+
static groupFlip(features, flipX, flipY) {
|
|
123
|
+
const flipMatrix = (new core_1.default.Matrix()).scale(flipX === 0 ? 1 : -1, flipY == 0 ? 1 : -1);
|
|
124
|
+
return features.map(feature => {
|
|
125
|
+
return feature.transform(flipMatrix);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
114
128
|
static groupBounds(features) {
|
|
115
129
|
let minX = Number.POSITIVE_INFINITY;
|
|
116
130
|
let minY = Number.POSITIVE_INFINITY;
|
|
@@ -171,9 +185,7 @@ class Geometry {
|
|
|
171
185
|
}
|
|
172
186
|
const startPoint = getArcPointRadians(x, y, radius, item.startAngle);
|
|
173
187
|
const endPoint = getArcPointRadians(x, y, radius, useEndAngle);
|
|
174
|
-
paths.push('M
|
|
175
|
-
+ 'A ' + radius + ' ' + radius + ' 0 1 1 '
|
|
176
|
-
+ endPoint[0] + ' ' + endPoint[1] + extraEnd);
|
|
188
|
+
paths.push('M', startPoint[0], startPoint[1], 'A', radius, radius, 0, 1, 1, endPoint[0], endPoint[1], extraEnd);
|
|
177
189
|
}
|
|
178
190
|
else {
|
|
179
191
|
const coords = Geometry.getCoords(item);
|
|
@@ -183,19 +195,27 @@ class Geometry {
|
|
|
183
195
|
for (let i = 0; i < coords.length; i++) {
|
|
184
196
|
const [x, y] = coords[i];
|
|
185
197
|
const command = (i === 0) ? 'M' : 'L';
|
|
186
|
-
path.push(`${command}
|
|
198
|
+
path.push(`${command}`, x, y);
|
|
187
199
|
}
|
|
188
200
|
if (isClosedPolygon) {
|
|
189
201
|
path.push('Z');
|
|
190
202
|
}
|
|
191
|
-
paths.push(path
|
|
203
|
+
paths.push(...path);
|
|
192
204
|
}
|
|
193
205
|
});
|
|
194
206
|
return {
|
|
195
|
-
path:
|
|
207
|
+
path: this.roundPathValues(paths),
|
|
196
208
|
isClosedPolygon,
|
|
197
209
|
};
|
|
198
210
|
}
|
|
211
|
+
static roundPathValues(pathItems) {
|
|
212
|
+
return pathItems.map(item => {
|
|
213
|
+
if (typeof item === 'number') {
|
|
214
|
+
return (+item.toFixed(7)).toString();
|
|
215
|
+
}
|
|
216
|
+
return item;
|
|
217
|
+
}).join(" ");
|
|
218
|
+
}
|
|
199
219
|
static angle(dx, dy) {
|
|
200
220
|
const line = new core_1.default.Segment(new core_1.default.Point(0, 0), new core_1.default.Point(dx, dy));
|
|
201
221
|
return line.slope * 180 / Math.PI;
|