circuitscript 0.0.22 → 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 +302 -0
- package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
- package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
- package/dist/cjs/draw_symbols.js +819 -0
- package/dist/cjs/execute.js +778 -0
- package/{src/export.ts → dist/cjs/export.js} +34 -56
- package/dist/cjs/fonts.js +4 -0
- package/dist/cjs/geometry.js +450 -0
- package/dist/cjs/globals.js +60 -0
- package/dist/cjs/helpers.js +269 -0
- package/dist/cjs/index.js +31 -0
- package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
- package/dist/cjs/lexer.js +111 -0
- package/dist/cjs/logger.js +17 -0
- package/dist/cjs/main.js +82 -0
- package/dist/cjs/objects/ClassComponent.js +145 -0
- package/dist/cjs/objects/ExecutionScope.js +135 -0
- package/dist/cjs/objects/Frame.js +22 -0
- package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
- package/dist/cjs/objects/ParamDefinition.js +42 -0
- package/dist/cjs/objects/PinDefinition.js +31 -0
- package/dist/cjs/objects/PinTypes.js +11 -0
- package/dist/cjs/objects/Wire.js +9 -0
- package/dist/cjs/objects/types.js +15 -0
- package/dist/cjs/parser.js +70 -0
- package/dist/cjs/regenerate-tests.js +23 -0
- package/dist/cjs/render.js +155 -0
- package/{src/server.ts → dist/cjs/server.js} +15 -21
- package/dist/cjs/sizing.js +105 -0
- package/{src/utils.ts → dist/cjs/utils.js} +25 -35
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +844 -0
- 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 +276 -0
- package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
- package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
- package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
- package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
- package/{build/src/export.js → dist/esm/export.mjs} +2 -2
- package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
- package/dist/esm/helpers.mjs +252 -0
- package/dist/esm/index.mjs +15 -0
- package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
- package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
- package/{build/src/main.js → dist/esm/main.mjs} +9 -14
- package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
- package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
- package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
- package/dist/esm/objects/types.mjs +12 -0
- package/dist/esm/parser.mjs +64 -0
- package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
- package/{build/src/render.js → dist/esm/render.mjs} +7 -24
- package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
- package/{src/main.ts → dist/esm/validate.mjs} +31 -62
- package/dist/esm/visitor.mjs +838 -0
- 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/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
- package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
- package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
- package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
- package/{build/src → dist/types}/execute.d.ts +6 -9
- package/{build/src → dist/types}/geometry.d.ts +5 -1
- package/dist/types/helpers.d.ts +40 -0
- package/dist/types/index.d.ts +15 -0
- package/{build/src → dist/types}/layout.d.ts +10 -10
- package/{build/src → dist/types}/lexer.d.ts +2 -2
- package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
- package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
- package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
- package/{build/src → dist/types}/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +25 -0
- package/{build/src → dist/types}/render.d.ts +1 -1
- package/{build/src → dist/types}/sizing.d.ts +3 -1
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +80 -0
- package/libs/lib.cst +0 -2
- package/package.json +38 -15
- package/.editorconfig +0 -15
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -27
- package/.gitlab-ci.yml +0 -81
- package/.prettierignore +0 -8
- package/.prettierrc +0 -16
- package/__tests__/expectedResults.ts +0 -657
- package/__tests__/helpers.ts +0 -82
- package/__tests__/parseScripts.ts +0 -593
- package/__tests__/renderData/script1.cst +0 -58
- package/__tests__/renderData/script1.cst.svg +0 -1
- package/__tests__/renderData/script2.cst +0 -16
- package/__tests__/renderData/script2.cst.svg +0 -1
- package/__tests__/renderData/script3.cst +0 -30
- package/__tests__/renderData/script3.cst.svg +0 -1
- package/__tests__/renderData/script4.cst +0 -54
- package/__tests__/renderData/script4.cst.svg +0 -1
- package/__tests__/renderData/script5.cst +0 -23
- package/__tests__/renderData/script5.cst.svg +0 -1
- package/__tests__/renderData/script6.cst +0 -28
- package/__tests__/renderData/script6.cst.svg +0 -1
- package/__tests__/renderData/script7.cst +0 -26
- package/__tests__/renderData/script7.cst.svg +0 -1
- package/__tests__/renderData/script8.cst +0 -37
- package/__tests__/renderData/script8.cst.svg +0 -1
- package/__tests__/testCLI.ts +0 -68
- package/__tests__/testMathOps.ts +0 -36
- package/__tests__/testMergeWires.ts +0 -141
- package/__tests__/testParse.ts +0 -263
- package/__tests__/testRender.ts +0 -38
- package/build/src/antlr/CircuitScriptLexer.js +0 -287
- package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
- package/build/src/antlr/CircuitScriptParser.js +0 -4841
- package/build/src/helpers.d.ts +0 -1
- package/build/src/helpers.js +0 -73
- package/build/src/objects/types.js +0 -6
- package/build/src/parser.js +0 -69
- package/build/src/visitor.d.ts +0 -133
- package/build/src/visitor.js +0 -1154
- package/documentation.md +0 -238
- package/examples/example_arduino_uno.cst +0 -1146
- package/examples/example_garden_pump.cst +0 -567
- package/examples/lib.cst +0 -185
- package/jest.config.js +0 -23
- package/refresh.html +0 -42
- package/server.cjs +0 -50
- package/src/antlr/CircuitScript.g4 +0 -209
- package/src/antlr/CircuitScriptLexer.ts +0 -317
- package/src/antlr/CircuitScriptParser.ts +0 -4979
- package/src/antlr/CircuitScriptVisitor.ts +0 -420
- package/src/draw_symbols.ts +0 -1085
- package/src/execute.ts +0 -1227
- package/src/fonts.ts +0 -1
- package/src/geometry.ts +0 -638
- package/src/globals.ts +0 -67
- package/src/helpers.ts +0 -114
- package/src/lexer.ts +0 -151
- package/src/logger.ts +0 -17
- package/src/objects/ClassComponent.ts +0 -223
- package/src/objects/ExecutionScope.ts +0 -201
- package/src/objects/Frame.ts +0 -20
- package/src/objects/ParamDefinition.ts +0 -49
- package/src/objects/PinDefinition.ts +0 -49
- package/src/objects/PinTypes.ts +0 -7
- package/src/objects/Wire.ts +0 -19
- package/src/objects/types.ts +0 -66
- package/src/parser.ts +0 -106
- package/src/regenerate-tests.ts +0 -25
- package/src/render.ts +0 -260
- package/src/sizing.ts +0 -96
- package/src/visitor.ts +0 -1691
- package/tsconfig.json +0 -27
- package/tsconfig.release.json +0 -8
- /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
- /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
- /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
- /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
- /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
- /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
- /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
- /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
- /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
- /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
- /package/{build/src → dist/types}/export.d.ts +0 -0
- /package/{build/src → dist/types}/fonts.d.ts +0 -0
- /package/{build/src → dist/types}/globals.d.ts +0 -0
- /package/{build/src → dist/types}/logger.d.ts +0 -0
- /package/{build/src → dist/types}/main.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
- /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
- /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
- /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
- /package/{build/src → dist/types}/server.d.ts +0 -0
- /package/{build/src → dist/types}/utils.d.ts +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { AbstractParseTreeVisitor } from "antlr4ng";
|
|
2
|
+
export class CircuitScriptVisitor extends AbstractParseTreeVisitor {
|
|
3
3
|
visitScript;
|
|
4
4
|
visitExpression;
|
|
5
5
|
visitPath_blocks;
|
|
6
6
|
visitPath_block_inner;
|
|
7
7
|
visitProperty_set_expr2;
|
|
8
8
|
visitAssignment_expr2;
|
|
9
|
+
visitPin_select_expr;
|
|
10
|
+
visitComponent_modifier_expr;
|
|
9
11
|
visitData_expr_with_assignment;
|
|
10
12
|
visitAdd_component_expr;
|
|
11
13
|
visitComponent_select_expr;
|
|
12
|
-
visitPin_select_expr;
|
|
13
14
|
visitPin_select_expr2;
|
|
14
15
|
visitAt_component_expr;
|
|
15
16
|
visitTo_component_expr;
|
|
@@ -27,6 +28,7 @@ export default class CircuitScriptVisitor extends ParseTreeVisitor {
|
|
|
27
28
|
visitParameters;
|
|
28
29
|
visitProperty_set_expr;
|
|
29
30
|
visitDouble_dot_property_set_expr;
|
|
31
|
+
visitFunctionCallExpr;
|
|
30
32
|
visitAdditionExpr;
|
|
31
33
|
visitMultiplyExpr;
|
|
32
34
|
visitDataExpr;
|
|
@@ -42,6 +44,7 @@ export default class CircuitScriptVisitor extends ParseTreeVisitor {
|
|
|
42
44
|
visitFunction_args_expr;
|
|
43
45
|
visitAtom_expr;
|
|
44
46
|
visitTrailer_expr;
|
|
47
|
+
visitFunction_call_expr;
|
|
45
48
|
visitNet_namespace_expr;
|
|
46
49
|
visitFunction_return_expr;
|
|
47
50
|
visitCreate_component_expr;
|
|
@@ -52,6 +55,8 @@ export default class CircuitScriptVisitor extends ParseTreeVisitor {
|
|
|
52
55
|
visitNested_properties;
|
|
53
56
|
visitSingle_line_property;
|
|
54
57
|
visitBlank_expr;
|
|
58
|
+
visitWire_expr_direction_value;
|
|
59
|
+
visitWire_expr_direction_only;
|
|
55
60
|
visitWire_expr;
|
|
56
61
|
visitPoint_expr;
|
|
57
62
|
visitImport_expr;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { SymbolPinSide, defaultFont } from "./globals.
|
|
2
|
-
import { Geometry, GeometryProp, HorizontalAlign, Label, VerticalAlign } from "./geometry.
|
|
3
|
-
const defaultSymbolLineColor = '#333';
|
|
1
|
+
import { SymbolPinSide, defaultFont } from "./globals.mjs";
|
|
2
|
+
import { Geometry, GeometryProp, HorizontalAlign, Label, VerticalAlign } from "./geometry.mjs";
|
|
4
3
|
const defaultSymbolLineWidth = 2;
|
|
5
4
|
export class SymbolGraphic {
|
|
6
5
|
drawPortsName = true;
|
|
7
6
|
displayBounds = true;
|
|
8
7
|
drawing;
|
|
9
8
|
_angle = 0;
|
|
9
|
+
_flipX = 0;
|
|
10
|
+
_flipY = 0;
|
|
10
11
|
width;
|
|
11
12
|
height;
|
|
12
13
|
labelTexts = new Map();
|
|
@@ -16,6 +17,18 @@ export class SymbolGraphic {
|
|
|
16
17
|
set angle(value) {
|
|
17
18
|
this._angle = value;
|
|
18
19
|
}
|
|
20
|
+
get flipX() {
|
|
21
|
+
return this._flipX;
|
|
22
|
+
}
|
|
23
|
+
set flipX(value) {
|
|
24
|
+
this._flipX = value;
|
|
25
|
+
}
|
|
26
|
+
get flipY() {
|
|
27
|
+
return this._flipY;
|
|
28
|
+
}
|
|
29
|
+
set flipY(value) {
|
|
30
|
+
this._flipY = value;
|
|
31
|
+
}
|
|
19
32
|
refreshDrawing(calculateSize = true) {
|
|
20
33
|
this.generateDrawing();
|
|
21
34
|
calculateSize && this.calculateSize();
|
|
@@ -41,10 +54,11 @@ export class SymbolGraphic {
|
|
|
41
54
|
drawPlaceRemove(group, extra) {
|
|
42
55
|
if (extra && extra.place === false) {
|
|
43
56
|
const { start, end } = this.drawing.getBoundingBox(true);
|
|
44
|
-
|
|
57
|
+
const path = Geometry.roundPathValues([
|
|
45
58
|
"M", start[0], start[1], "L", end[0], end[1],
|
|
46
59
|
"M", end[0], start[1], "L", start[0], end[1]
|
|
47
|
-
]
|
|
60
|
+
]);
|
|
61
|
+
group.path(path)
|
|
48
62
|
.stroke({
|
|
49
63
|
width: defaultSymbolLineWidth,
|
|
50
64
|
color: 'red'
|
|
@@ -56,13 +70,11 @@ export class SymbolGraphic {
|
|
|
56
70
|
const [x, y] = pin.start;
|
|
57
71
|
const useX = Math.round(x * 10000) / 10000;
|
|
58
72
|
const useY = Math.round(y * 10000 / 10000);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
}
|
|
73
|
+
return {
|
|
74
|
+
x: useX,
|
|
75
|
+
y: useY,
|
|
76
|
+
angle: pin.angle,
|
|
77
|
+
};
|
|
66
78
|
}
|
|
67
79
|
drawBounds(group) {
|
|
68
80
|
const bbox = this.drawing.getBoundingBox();
|
|
@@ -113,27 +125,33 @@ export class SymbolGraphic {
|
|
|
113
125
|
}
|
|
114
126
|
switch (useAnchor) {
|
|
115
127
|
case HorizontalAlign.Left:
|
|
116
|
-
anchorStyle = 'start';
|
|
128
|
+
anchorStyle = (this.flipX === 0) ? 'start' : 'end';
|
|
117
129
|
break;
|
|
118
130
|
case HorizontalAlign.Middle:
|
|
119
131
|
anchorStyle = 'middle';
|
|
120
132
|
break;
|
|
121
133
|
case HorizontalAlign.Right:
|
|
122
|
-
anchorStyle = 'end';
|
|
134
|
+
anchorStyle = (this.flipX === 0) ? 'end' : 'start';
|
|
123
135
|
break;
|
|
124
136
|
}
|
|
125
137
|
switch (useDominantBaseline) {
|
|
126
138
|
case VerticalAlign.Top:
|
|
127
|
-
dominantBaseline = 'hanging';
|
|
139
|
+
dominantBaseline = (this.flipY === 0) ? 'hanging' : 'text-top';
|
|
128
140
|
break;
|
|
129
141
|
case VerticalAlign.Middle:
|
|
130
142
|
dominantBaseline = 'middle';
|
|
131
143
|
break;
|
|
132
144
|
case VerticalAlign.Bottom:
|
|
133
|
-
dominantBaseline = 'text-top';
|
|
145
|
+
dominantBaseline = (this.flipY === 0) ? 'text-top' : 'hanging';
|
|
134
146
|
break;
|
|
135
147
|
}
|
|
136
148
|
const position = tmpLabel.getLabelPosition();
|
|
149
|
+
if (this.flipX !== 0) {
|
|
150
|
+
position[0] *= -1;
|
|
151
|
+
}
|
|
152
|
+
if (this.flipY !== 0) {
|
|
153
|
+
position[1] *= -1;
|
|
154
|
+
}
|
|
137
155
|
const useFont = defaultFont;
|
|
138
156
|
const textContainer = group.group();
|
|
139
157
|
const text = textContainer.text(tmpLabel.text)
|
|
@@ -157,11 +175,26 @@ export class SymbolGraphic {
|
|
|
157
175
|
translateY = position[1];
|
|
158
176
|
useRotateAngle = this.angle;
|
|
159
177
|
}
|
|
178
|
+
translateX = this.roundValues(translateX);
|
|
179
|
+
translateY = this.roundValues(translateY);
|
|
160
180
|
text.rotate(labelAngle);
|
|
161
181
|
textContainer.translate(translateX, translateY)
|
|
162
182
|
.rotate(useRotateAngle, -translateX, -translateY);
|
|
183
|
+
const { a, b, c, d, e, f } = textContainer.matrix();
|
|
184
|
+
const newMatrix = {
|
|
185
|
+
a: this.roundValues(a),
|
|
186
|
+
b: this.roundValues(b),
|
|
187
|
+
c: this.roundValues(c),
|
|
188
|
+
d: this.roundValues(d),
|
|
189
|
+
e: this.roundValues(e),
|
|
190
|
+
f: this.roundValues(f),
|
|
191
|
+
};
|
|
192
|
+
textContainer.transform(newMatrix);
|
|
163
193
|
});
|
|
164
194
|
}
|
|
195
|
+
roundValues(value) {
|
|
196
|
+
return +value.toFixed(7);
|
|
197
|
+
}
|
|
165
198
|
flipTextAnchor(value) {
|
|
166
199
|
if (value === HorizontalAlign.Left) {
|
|
167
200
|
return HorizontalAlign.Right;
|
|
@@ -191,6 +224,7 @@ export class SymbolGraphic {
|
|
|
191
224
|
if (this.labelTexts.has(labelId)) {
|
|
192
225
|
return this.labelTexts.get(labelId);
|
|
193
226
|
}
|
|
227
|
+
return undefined;
|
|
194
228
|
}
|
|
195
229
|
}
|
|
196
230
|
export function SymbolFactory(name) {
|
|
@@ -198,6 +232,7 @@ export function SymbolFactory(name) {
|
|
|
198
232
|
case 'point':
|
|
199
233
|
return new SymbolPointHidden();
|
|
200
234
|
}
|
|
235
|
+
return null;
|
|
201
236
|
}
|
|
202
237
|
export class SymbolPointHidden extends SymbolGraphic {
|
|
203
238
|
generateDrawing() {
|
|
@@ -230,6 +265,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
230
265
|
drawing.log("=== start generate drawing ===");
|
|
231
266
|
drawing.clear();
|
|
232
267
|
drawing.angle = this._angle;
|
|
268
|
+
drawing.flipX = this._flipX;
|
|
269
|
+
drawing.flipY = this._flipY;
|
|
233
270
|
const commands = drawing.getCommands();
|
|
234
271
|
drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
|
|
235
272
|
commands.forEach(([commandName, positionParams, keywordParams]) => {
|
|
@@ -306,10 +343,9 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
306
343
|
drawing.log('add pin', ...positionParams);
|
|
307
344
|
const keywordDisplayPinId = 'display_pin_id';
|
|
308
345
|
let displayPinId = true;
|
|
309
|
-
if (keywordParams.has(keywordDisplayPinId)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
346
|
+
if (keywordParams.has(keywordDisplayPinId)
|
|
347
|
+
&& keywordParams.get(keywordDisplayPinId) === 0) {
|
|
348
|
+
displayPinId = false;
|
|
313
349
|
}
|
|
314
350
|
let pinNameParam = null;
|
|
315
351
|
if (typeof positionParams[1] === 'string') {
|
|
@@ -339,8 +375,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
339
375
|
];
|
|
340
376
|
}
|
|
341
377
|
drawing.addPin(...positionParams);
|
|
342
|
-
const
|
|
343
|
-
const [pinId, , angle] =
|
|
378
|
+
const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
|
|
379
|
+
const [pinId, , angle] = lastAddedPin;
|
|
344
380
|
const [, , , endX, endY] = positionParams;
|
|
345
381
|
let pinNameAlignment = HorizontalAlign.Left;
|
|
346
382
|
let pinNameOffsetX = 4;
|
|
@@ -434,6 +470,8 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
434
470
|
const maxRightPins = Math.max(...rightPins.map(item => item.position)) + 1;
|
|
435
471
|
const drawing = new SymbolDrawing();
|
|
436
472
|
drawing.angle = this._angle;
|
|
473
|
+
drawing.flipX = this._flipX;
|
|
474
|
+
drawing.flipY = this._flipY;
|
|
437
475
|
const bodyWidth = this.bodyWidth;
|
|
438
476
|
const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
|
|
439
477
|
drawing.addRect(0, 0, bodyWidth, bodyHeight);
|
|
@@ -499,6 +537,8 @@ export class SymbolDrawing {
|
|
|
499
537
|
items = [];
|
|
500
538
|
pins = [];
|
|
501
539
|
angle = 0;
|
|
540
|
+
flipX = 0;
|
|
541
|
+
flipY = 0;
|
|
502
542
|
mainOrigin = [0, 0];
|
|
503
543
|
logger = null;
|
|
504
544
|
clear() {
|
|
@@ -677,8 +717,9 @@ export class SymbolDrawing {
|
|
|
677
717
|
}
|
|
678
718
|
}
|
|
679
719
|
else {
|
|
680
|
-
|
|
681
|
-
|
|
720
|
+
let tmpResult = Geometry.groupFlip([item], this.flipX, this.flipY);
|
|
721
|
+
tmpResult = Geometry.groupRotate(tmpResult, this.angle, this.mainOrigin);
|
|
722
|
+
const { path, isClosedPolygon } = this.featuresToPath(tmpResult);
|
|
682
723
|
pathItems.push({
|
|
683
724
|
path: path,
|
|
684
725
|
lineWidth: currentLineWidth,
|
|
@@ -691,9 +732,10 @@ export class SymbolDrawing {
|
|
|
691
732
|
return pathItems;
|
|
692
733
|
}
|
|
693
734
|
getPinsPath() {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
735
|
+
let features = this.pins.map(item => item[1]);
|
|
736
|
+
features = Geometry.groupFlip(features, this.flipX, this.flipY);
|
|
737
|
+
features = Geometry.groupRotate(features, this.angle, this.mainOrigin);
|
|
738
|
+
const { path } = this.featuresToPath(features);
|
|
697
739
|
return path;
|
|
698
740
|
}
|
|
699
741
|
getLabels() {
|
|
@@ -714,24 +756,27 @@ export class SymbolDrawing {
|
|
|
714
756
|
}
|
|
715
757
|
return accum;
|
|
716
758
|
}, []);
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
759
|
+
let features = [...drawingFeatures, ...pinFeatures];
|
|
760
|
+
features = Geometry.groupFlip(features, this.flipX, this.flipY);
|
|
761
|
+
features = Geometry.groupRotate(features, this.angle, this.mainOrigin);
|
|
762
|
+
return Geometry.groupBounds(features);
|
|
720
763
|
}
|
|
721
764
|
getPinPosition(pinId) {
|
|
722
765
|
const pin = this.pins.find(item => {
|
|
723
766
|
return item[0] === pinId;
|
|
724
767
|
});
|
|
725
768
|
if (pin) {
|
|
726
|
-
const [
|
|
727
|
-
|
|
728
|
-
|
|
769
|
+
const [, feature, angle] = pin;
|
|
770
|
+
let tmpFeature = Geometry.flip(feature, this.flipX, this.flipY);
|
|
771
|
+
tmpFeature = Geometry.rotateDegs(tmpFeature, this.angle, this.mainOrigin);
|
|
772
|
+
const coords = Geometry.getCoords(tmpFeature);
|
|
729
773
|
return {
|
|
730
774
|
start: coords[0],
|
|
731
775
|
end: coords[1],
|
|
732
776
|
angle,
|
|
733
777
|
};
|
|
734
778
|
}
|
|
779
|
+
return null;
|
|
735
780
|
}
|
|
736
781
|
}
|
|
737
782
|
export class SymbolDrawingCommands extends SymbolDrawing {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { BlockTypes, ComponentTypes, GlobalNames, NoNetText, ParamKeys, ReferenceTypes } from './globals.
|
|
2
|
-
import { ClassComponent } from './objects/ClassComponent.
|
|
3
|
-
import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.
|
|
4
|
-
import { Net } from './objects/Net.
|
|
5
|
-
import { PortSide } from './objects/PinDefinition.
|
|
6
|
-
import { Wire } from './objects/Wire.
|
|
7
|
-
import { Frame } from './objects/Frame.
|
|
1
|
+
import { BlockTypes, ComponentTypes, GlobalNames, NoNetText, ParamKeys, ReferenceTypes } from './globals.mjs';
|
|
2
|
+
import { ClassComponent } from './objects/ClassComponent.mjs';
|
|
3
|
+
import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.mjs';
|
|
4
|
+
import { Net } from './objects/Net.mjs';
|
|
5
|
+
import { PortSide } from './objects/PinDefinition.mjs';
|
|
6
|
+
import { Wire } from './objects/Wire.mjs';
|
|
7
|
+
import { Frame } from './objects/Frame.mjs';
|
|
8
8
|
export class ExecutionContext {
|
|
9
9
|
name;
|
|
10
10
|
namespace;
|
|
@@ -18,7 +18,8 @@ export class ExecutionContext {
|
|
|
18
18
|
silent = false;
|
|
19
19
|
logger;
|
|
20
20
|
__functionCache = {};
|
|
21
|
-
|
|
21
|
+
parentContext;
|
|
22
|
+
constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, parent) {
|
|
22
23
|
this.name = name;
|
|
23
24
|
this.namespace = namespace;
|
|
24
25
|
this.netNamespace = netNamespace;
|
|
@@ -27,10 +28,18 @@ export class ExecutionContext {
|
|
|
27
28
|
this.scope = ExecutionScope.create();
|
|
28
29
|
this.scope.indentLevel = indentLevel;
|
|
29
30
|
this.setupRoot();
|
|
31
|
+
if (name === '__') {
|
|
32
|
+
this.scope.sequence.push([
|
|
33
|
+
SequenceAction.At,
|
|
34
|
+
this.scope.componentRoot,
|
|
35
|
+
this.scope.currentPin
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
30
38
|
this.silent = silent;
|
|
31
|
-
this.
|
|
39
|
+
this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
|
|
40
|
+
this.parentContext = parent;
|
|
32
41
|
}
|
|
33
|
-
|
|
42
|
+
log(...params) {
|
|
34
43
|
const indentOutput = ''.padStart(this.scope.indentLevel * 4, ' ');
|
|
35
44
|
const indentLevelText = this.scope.indentLevel
|
|
36
45
|
.toString()
|
|
@@ -44,18 +53,13 @@ export class ExecutionContext {
|
|
|
44
53
|
}
|
|
45
54
|
setupRoot() {
|
|
46
55
|
const componentRoot = ClassComponent.simple(GlobalNames.__root, 1, '__root');
|
|
47
|
-
componentRoot.typeProp = ComponentTypes.
|
|
56
|
+
componentRoot.typeProp = ComponentTypes.point;
|
|
57
|
+
componentRoot.displayProp = 'point';
|
|
48
58
|
this.scope.instances.set(GlobalNames.__root, componentRoot);
|
|
49
59
|
this.scope.currentComponent = componentRoot;
|
|
50
60
|
this.scope.currentPin = componentRoot.getDefaultPin();
|
|
51
61
|
this.scope.componentRoot = componentRoot;
|
|
52
62
|
}
|
|
53
|
-
instanceExists(instanceName) {
|
|
54
|
-
return this.scope.instances.has(instanceName);
|
|
55
|
-
}
|
|
56
|
-
getComponent(instanceName) {
|
|
57
|
-
return this.scope.instances.get(instanceName);
|
|
58
|
-
}
|
|
59
63
|
getUniqueInstanceName(className) {
|
|
60
64
|
let extraPrefix = '';
|
|
61
65
|
switch (className) {
|
|
@@ -90,7 +94,7 @@ export class ExecutionContext {
|
|
|
90
94
|
const net2 = net2_exists
|
|
91
95
|
? this.scope.getNet(component2, component2Pin)
|
|
92
96
|
: null;
|
|
93
|
-
this.
|
|
97
|
+
this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
|
|
94
98
|
let returnNet;
|
|
95
99
|
if (net1 === null && net2 === null) {
|
|
96
100
|
const tmpNet = new Net(this.netNamespace, this.getUniqueNetName());
|
|
@@ -118,7 +122,7 @@ export class ExecutionContext {
|
|
|
118
122
|
}
|
|
119
123
|
mergeNets(net1, net2) {
|
|
120
124
|
if (net1 === net2) {
|
|
121
|
-
return;
|
|
125
|
+
return net1;
|
|
122
126
|
}
|
|
123
127
|
let tmpNet;
|
|
124
128
|
if (net2.priority > net1.priority) {
|
|
@@ -152,14 +156,14 @@ export class ExecutionContext {
|
|
|
152
156
|
let tmpNet;
|
|
153
157
|
if (result.found) {
|
|
154
158
|
tmpNet = result.net;
|
|
155
|
-
this.
|
|
159
|
+
this.log('net found', tmpNet.namespace, tmpNet.name);
|
|
156
160
|
}
|
|
157
161
|
else {
|
|
158
162
|
tmpNet = new Net(this.netNamespace, netName, priority);
|
|
159
|
-
this.
|
|
163
|
+
this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
|
|
160
164
|
}
|
|
161
165
|
this.scope.setNet(component, 1, tmpNet);
|
|
162
|
-
this.
|
|
166
|
+
this.log('set net', netName, 'component', component);
|
|
163
167
|
}
|
|
164
168
|
const { arrange = null } = props;
|
|
165
169
|
component.arrangeProps = arrange;
|
|
@@ -178,7 +182,7 @@ export class ExecutionContext {
|
|
|
178
182
|
const pinsOutput = pins.map((pin) => {
|
|
179
183
|
return pin.id + ':' + pin.name;
|
|
180
184
|
});
|
|
181
|
-
this.
|
|
185
|
+
this.log('add symbol', instanceName, '[' + pinsOutput.join(', ') + ']');
|
|
182
186
|
return component;
|
|
183
187
|
}
|
|
184
188
|
printPoint(extra = '') {
|
|
@@ -188,7 +192,7 @@ export class ExecutionContext {
|
|
|
188
192
|
.getNet(this.scope.currentComponent, this.scope.currentPin)
|
|
189
193
|
.toString();
|
|
190
194
|
}
|
|
191
|
-
this.
|
|
195
|
+
this.log((extra !== '' ? (extra + ' ') : '') + 'point: ' +
|
|
192
196
|
this.scope.currentComponent.instanceName +
|
|
193
197
|
' ' +
|
|
194
198
|
this.scope.currentPin + ' ' + netName);
|
|
@@ -197,7 +201,7 @@ export class ExecutionContext {
|
|
|
197
201
|
const startPin = pin;
|
|
198
202
|
const nextPin = component.getNextPinAfter(startPin);
|
|
199
203
|
this.toComponent(component, startPin, { addSequence: true });
|
|
200
|
-
this.
|
|
204
|
+
this.log('move to next pin: ' + nextPin);
|
|
201
205
|
this.atComponent(component, nextPin, {
|
|
202
206
|
addSequence: true
|
|
203
207
|
});
|
|
@@ -205,11 +209,8 @@ export class ExecutionContext {
|
|
|
205
209
|
return this.getCurrentPoint();
|
|
206
210
|
}
|
|
207
211
|
toComponent(component, pinId, options) {
|
|
208
|
-
this.
|
|
209
|
-
const { addSequence = false
|
|
210
|
-
if (cloneNetComponent && this.isNetOnlyComponent(component)) {
|
|
211
|
-
component = this.cloneComponent(component);
|
|
212
|
-
}
|
|
212
|
+
this.log('to component');
|
|
213
|
+
const { addSequence = false } = options ?? {};
|
|
213
214
|
if (!(component instanceof ClassComponent)) {
|
|
214
215
|
throw "Not a valid component!";
|
|
215
216
|
}
|
|
@@ -229,7 +230,7 @@ export class ExecutionContext {
|
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
232
|
if (this.scope.hasNet(this.scope.currentComponent, this.scope.currentPin)) {
|
|
232
|
-
this.
|
|
233
|
+
this.log('net: ', this.scope
|
|
233
234
|
.getNet(this.scope.currentComponent, this.scope.currentPin)
|
|
234
235
|
.toString());
|
|
235
236
|
}
|
|
@@ -256,11 +257,8 @@ export class ExecutionContext {
|
|
|
256
257
|
return this.getCurrentPoint();
|
|
257
258
|
}
|
|
258
259
|
atComponent(component, pinId, options) {
|
|
259
|
-
this.
|
|
260
|
-
const { addSequence = false
|
|
261
|
-
if (cloneNetComponent && this.isNetOnlyComponent(component)) {
|
|
262
|
-
component = this.cloneComponent(component);
|
|
263
|
-
}
|
|
260
|
+
this.log('at component');
|
|
261
|
+
const { addSequence = false } = options ?? {};
|
|
264
262
|
this.scope.currentComponent = component;
|
|
265
263
|
let usePinId;
|
|
266
264
|
if (pinId === null) {
|
|
@@ -285,9 +283,6 @@ export class ExecutionContext {
|
|
|
285
283
|
this.printPoint();
|
|
286
284
|
return this.getCurrentPoint();
|
|
287
285
|
}
|
|
288
|
-
isNetOnlyComponent(component) {
|
|
289
|
-
return isNetComponent(component) && !isLabelComponent(component);
|
|
290
|
-
}
|
|
291
286
|
cloneComponent(component) {
|
|
292
287
|
let clonedComponent = null;
|
|
293
288
|
if (!this.scope.copyIDs.has(component.instanceName)) {
|
|
@@ -302,7 +297,7 @@ export class ExecutionContext {
|
|
|
302
297
|
this.scope.instances.set(cloneInstanceName, clonedComponent);
|
|
303
298
|
clonedComponent.instanceName = cloneInstanceName;
|
|
304
299
|
this.linkComponentPinNet(component, 1, clonedComponent, 1);
|
|
305
|
-
this.
|
|
300
|
+
this.log('created clone of net component:', cloneInstanceName);
|
|
306
301
|
return clonedComponent;
|
|
307
302
|
}
|
|
308
303
|
enterBlocks(blockType) {
|
|
@@ -324,7 +319,7 @@ export class ExecutionContext {
|
|
|
324
319
|
current_index: null,
|
|
325
320
|
type: blockType,
|
|
326
321
|
});
|
|
327
|
-
this.
|
|
322
|
+
this.log('enter blocks');
|
|
328
323
|
}
|
|
329
324
|
exitBlocks() {
|
|
330
325
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
@@ -345,7 +340,7 @@ export class ExecutionContext {
|
|
|
345
340
|
const { entered_at: [component, pin,] } = stackRef;
|
|
346
341
|
this.atComponent(component, pin, { addSequence: true });
|
|
347
342
|
}
|
|
348
|
-
this.
|
|
343
|
+
this.log('exit blocks');
|
|
349
344
|
}
|
|
350
345
|
enterBlock(blockIndex) {
|
|
351
346
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
@@ -364,7 +359,7 @@ export class ExecutionContext {
|
|
|
364
359
|
const { entered_at: [component, pin,] } = stackRef;
|
|
365
360
|
this.atComponent(component, pin, { addSequence: true });
|
|
366
361
|
}
|
|
367
|
-
this.
|
|
362
|
+
this.log(`enter inner block of type (${blockType}) >>>`);
|
|
368
363
|
this.scope.indentLevel += 1;
|
|
369
364
|
}
|
|
370
365
|
exitBlock(blockIndex) {
|
|
@@ -378,7 +373,7 @@ export class ExecutionContext {
|
|
|
378
373
|
];
|
|
379
374
|
stackRef['block_index'] = null;
|
|
380
375
|
this.scope.indentLevel -= 1;
|
|
381
|
-
this.
|
|
376
|
+
this.log('exit inner block <<<');
|
|
382
377
|
if (blockType === BlockTypes.Branch) {
|
|
383
378
|
const { entered_at: [component, pin, wireId] } = stackRef;
|
|
384
379
|
this.atComponent(component, pin, { addSequence: true });
|
|
@@ -417,7 +412,7 @@ export class ExecutionContext {
|
|
|
417
412
|
});
|
|
418
413
|
}
|
|
419
414
|
getPointBlockLocation() {
|
|
420
|
-
this.
|
|
415
|
+
this.log('get block point');
|
|
421
416
|
for (let i = 0; i < this.scope.indentLevel; i++) {
|
|
422
417
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
|
|
423
418
|
const { entered_at } = stackRef;
|
|
@@ -426,11 +421,11 @@ export class ExecutionContext {
|
|
|
426
421
|
return entered_at;
|
|
427
422
|
}
|
|
428
423
|
}
|
|
429
|
-
this.
|
|
424
|
+
this.log('did not find block point');
|
|
430
425
|
return null;
|
|
431
426
|
}
|
|
432
427
|
breakBranch() {
|
|
433
|
-
this.
|
|
428
|
+
this.log('break branch');
|
|
434
429
|
const branchesInfo = this.scope.blockStack.get(this.scope.indentLevel - 1);
|
|
435
430
|
const branchIndex = branchesInfo['block_index'];
|
|
436
431
|
const branchIndexRef = branchesInfo['inner_blocks'].get(branchIndex);
|
|
@@ -439,7 +434,7 @@ export class ExecutionContext {
|
|
|
439
434
|
createFunction(functionName, __runFunc) {
|
|
440
435
|
this.scope.functions.set(functionName, __runFunc);
|
|
441
436
|
this.__functionCache[functionName] = __runFunc;
|
|
442
|
-
this.
|
|
437
|
+
this.log(`defined new function '${functionName}'`);
|
|
443
438
|
}
|
|
444
439
|
hasFunction(functionName) {
|
|
445
440
|
return this.scope.functions.has(functionName);
|
|
@@ -488,7 +483,7 @@ export class ExecutionContext {
|
|
|
488
483
|
__runFunc = this.getFunction(functionName);
|
|
489
484
|
}
|
|
490
485
|
if (__runFunc === null) {
|
|
491
|
-
this.
|
|
486
|
+
this.log(`searching for function ${functionName} in upper context`);
|
|
492
487
|
const tmpResolveResult = this.resolveVariable(executionStack, functionName);
|
|
493
488
|
if (tmpResolveResult.found) {
|
|
494
489
|
__runFunc = tmpResolveResult.value;
|
|
@@ -497,17 +492,17 @@ export class ExecutionContext {
|
|
|
497
492
|
throw `Invalid function ${functionName}`;
|
|
498
493
|
}
|
|
499
494
|
}
|
|
500
|
-
this.
|
|
495
|
+
this.log('save function to cache:', functionName);
|
|
501
496
|
this.__functionCache[functionName] = __runFunc;
|
|
502
497
|
}
|
|
503
498
|
else {
|
|
504
|
-
this.
|
|
499
|
+
this.log('found function in cache:', functionName);
|
|
505
500
|
__runFunc = this.__functionCache[functionName];
|
|
506
501
|
}
|
|
507
502
|
if (__runFunc !== null) {
|
|
508
|
-
this.
|
|
503
|
+
this.log(`call function '${functionName}'`);
|
|
509
504
|
const functionResult = __runFunc(functionParams, { netNamespace });
|
|
510
|
-
this.
|
|
505
|
+
this.log(`done call function '${functionName}'`);
|
|
511
506
|
return functionResult;
|
|
512
507
|
}
|
|
513
508
|
else {
|
|
@@ -515,10 +510,11 @@ export class ExecutionContext {
|
|
|
515
510
|
}
|
|
516
511
|
}
|
|
517
512
|
mergeScope(childScope, namespace) {
|
|
518
|
-
this.
|
|
513
|
+
this.log('-- merging scope to parent --');
|
|
519
514
|
const currentComponent = this.scope.currentComponent;
|
|
520
515
|
const currentPin = this.scope.currentPin;
|
|
521
516
|
const currentWireId = this.scope.currentWireId;
|
|
517
|
+
const gndCopyIdOffset = 0;
|
|
522
518
|
const tmpInstances = childScope.instances;
|
|
523
519
|
const tmpNets = childScope.getNets();
|
|
524
520
|
for (const [instanceName, component] of tmpInstances) {
|
|
@@ -604,16 +600,16 @@ export class ExecutionContext {
|
|
|
604
600
|
this.scope.currentWireId = childScope.currentWireId + wireIdOffset;
|
|
605
601
|
}
|
|
606
602
|
this.printPoint('resume at');
|
|
607
|
-
this.
|
|
603
|
+
this.log('-- nets --');
|
|
608
604
|
const currentNets = this.scope.getNets();
|
|
609
605
|
currentNets.reduce((accum, [, , net]) => {
|
|
610
606
|
if (accum.indexOf(net) === -1) {
|
|
611
607
|
accum.push(net);
|
|
612
|
-
this.
|
|
608
|
+
this.log(`${net.namespace}${net.name} ${net.priority}`);
|
|
613
609
|
}
|
|
614
610
|
return accum;
|
|
615
611
|
}, []);
|
|
616
|
-
this.
|
|
612
|
+
this.log('-- done merging scope --');
|
|
617
613
|
}
|
|
618
614
|
addWire(segments) {
|
|
619
615
|
if (this.scope.currentComponent === null) {
|
|
@@ -632,14 +628,14 @@ export class ExecutionContext {
|
|
|
632
628
|
segments.forEach(item => {
|
|
633
629
|
output.push(item.join(","));
|
|
634
630
|
});
|
|
635
|
-
this.
|
|
631
|
+
this.log('add wire: ', output.join("|"));
|
|
636
632
|
this.scope.setActive(ActiveObject.Wire, wireId);
|
|
637
633
|
this.scope.sequence.push([SequenceAction.Wire, wireId, tmp]);
|
|
638
634
|
this.scope.currentComponent.pinWires.set(this.scope.currentPin, tmp);
|
|
639
635
|
}
|
|
640
636
|
addPoint(pointId, userDefined = true) {
|
|
641
637
|
if (this.scope.instances.has(pointId)) {
|
|
642
|
-
this.
|
|
638
|
+
this.log('Warning: ' + pointId + ' is being redefined');
|
|
643
639
|
}
|
|
644
640
|
const useName = userDefined ? 'point.' + pointId : pointId;
|
|
645
641
|
const componentPoint = ClassComponent.simple(useName, 1, "point");
|
|
@@ -650,7 +646,7 @@ export class ExecutionContext {
|
|
|
650
646
|
return this.getCurrentPoint();
|
|
651
647
|
}
|
|
652
648
|
setProperty(nameWithProp, value) {
|
|
653
|
-
this.
|
|
649
|
+
this.log('set property', nameWithProp, 'value', value);
|
|
654
650
|
let idName;
|
|
655
651
|
let paramName;
|
|
656
652
|
let useActive = false;
|
|
@@ -716,6 +712,9 @@ export function isNetComponent(component) {
|
|
|
716
712
|
export function isLabelComponent(component) {
|
|
717
713
|
return component.parameters.has(ParamKeys.__is_label);
|
|
718
714
|
}
|
|
715
|
+
export function isNetOnlyComponent(component) {
|
|
716
|
+
return isNetComponent(component) && !isLabelComponent(component);
|
|
717
|
+
}
|
|
719
718
|
export function getPortSide(pins, arrangeProps) {
|
|
720
719
|
const result = [];
|
|
721
720
|
if (arrangeProps === null) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComponentTypes, NoNetText } from "./globals.
|
|
2
|
-
import { NumericValue } from "./objects/ParamDefinition.
|
|
1
|
+
import { ComponentTypes, NoNetText } from "./globals.mjs";
|
|
2
|
+
import { NumericValue } from "./objects/ParamDefinition.mjs";
|
|
3
3
|
export function generateKiCADNetList(netlist) {
|
|
4
4
|
const componentsList = [];
|
|
5
5
|
const nets = {};
|