circuitscript 0.4.0 → 0.5.0
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 +16 -10
- package/dist/cjs/BomGeneration.js +3 -3
- package/dist/cjs/ComponentMatchConditions.js +2 -2
- package/dist/cjs/annotate/RefdesAnnotationVisitor.js +4 -0
- package/dist/cjs/builtinMethods.js +10 -10
- package/dist/cjs/execute.js +25 -23
- package/dist/cjs/globals.js +7 -14
- package/dist/cjs/helpers.js +4 -3
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/lexer.js +8 -4
- package/dist/cjs/objects/BlockTypes.js +10 -0
- package/dist/cjs/objects/NumericValue.js +196 -0
- package/dist/cjs/objects/ParamDefinition.js +1 -149
- package/dist/cjs/objects/PercentageValue.js +15 -0
- package/dist/cjs/objects/PinDefinition.js +2 -2
- package/dist/cjs/objects/WrappedNumber.js +15 -0
- package/dist/cjs/pipeline.js +2 -2
- package/dist/cjs/render/draw_symbols.js +78 -78
- package/dist/cjs/render/export.js +2 -2
- package/dist/cjs/render/geometry.js +11 -12
- package/dist/cjs/render/graph.js +2 -2
- package/dist/cjs/render/layout.js +46 -46
- package/dist/cjs/render/render.js +19 -19
- package/dist/cjs/semantic-tokens/SemanticTokenVisitor.js +59 -59
- package/dist/cjs/utils.js +21 -83
- package/dist/cjs/visitor.js +45 -31
- package/dist/esm/BaseVisitor.js +8 -2
- package/dist/esm/BomGeneration.js +1 -1
- package/dist/esm/ComponentMatchConditions.js +1 -1
- package/dist/esm/annotate/RefdesAnnotationVisitor.js +4 -0
- package/dist/esm/builtinMethods.js +2 -2
- package/dist/esm/execute.js +4 -2
- package/dist/esm/globals.js +1 -8
- package/dist/esm/helpers.js +3 -2
- package/dist/esm/index.js +6 -2
- package/dist/esm/lexer.js +8 -4
- package/dist/esm/objects/BlockTypes.js +7 -0
- package/dist/esm/objects/NumericValue.js +189 -0
- package/dist/esm/objects/ParamDefinition.js +0 -148
- package/dist/esm/objects/PercentageValue.js +12 -0
- package/dist/esm/objects/PinDefinition.js +1 -1
- package/dist/esm/objects/WrappedNumber.js +12 -0
- package/dist/esm/pipeline.js +2 -2
- package/dist/esm/render/draw_symbols.js +2 -2
- package/dist/esm/render/export.js +1 -1
- package/dist/esm/render/geometry.js +1 -2
- package/dist/esm/render/graph.js +1 -1
- package/dist/esm/render/layout.js +2 -2
- package/dist/esm/render/render.js +1 -1
- package/dist/esm/semantic-tokens/SemanticTokenVisitor.js +58 -58
- package/dist/esm/utils.js +16 -74
- package/dist/esm/visitor.js +17 -3
- package/dist/types/ComponentMatchConditions.d.ts +1 -1
- package/dist/types/annotate/RefdesAnnotationVisitor.d.ts +3 -1
- package/dist/types/execute.d.ts +4 -2
- package/dist/types/globals.d.ts +1 -7
- package/dist/types/helpers.d.ts +2 -2
- package/dist/types/index.d.ts +6 -2
- package/dist/types/lexer.d.ts +1 -0
- package/dist/types/objects/BlockTypes.d.ts +6 -0
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/objects/ExecutionScope.d.ts +2 -1
- package/dist/types/objects/NumericValue.d.ts +35 -0
- package/dist/types/objects/ParamDefinition.d.ts +0 -41
- package/dist/types/objects/PercentageValue.d.ts +6 -0
- package/dist/types/objects/PinDefinition.d.ts +1 -1
- package/dist/types/objects/WrappedNumber.d.ts +6 -0
- package/dist/types/objects/types.d.ts +2 -1
- package/dist/types/render/draw_symbols.d.ts +1 -1
- package/dist/types/render/geometry.d.ts +1 -1
- package/dist/types/render/layout.d.ts +1 -1
- package/dist/types/semantic-tokens/SemanticTokenVisitor.d.ts +3 -4
- package/dist/types/utils.d.ts +1 -7
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ const utils_js_1 = require("../utils.js");
|
|
|
14
14
|
const types_js_1 = require("../objects/types.js");
|
|
15
15
|
const PinDefinition_js_1 = require("../objects/PinDefinition.js");
|
|
16
16
|
const helpers_js_1 = require("../helpers.js");
|
|
17
|
-
const
|
|
17
|
+
const NumericValue_js_1 = require("../objects/NumericValue.js");
|
|
18
18
|
const graph_js_1 = require("./graph.js");
|
|
19
19
|
class LayoutEngine {
|
|
20
20
|
constructor(logger, options = { showBaseFrame: false }) {
|
|
@@ -170,7 +170,7 @@ class LayoutEngine {
|
|
|
170
170
|
lines,
|
|
171
171
|
});
|
|
172
172
|
intersectPoints.forEach(([x, y]) => {
|
|
173
|
-
junctions.push(new RenderJunction((0,
|
|
173
|
+
junctions.push(new RenderJunction((0, NumericValue_js_1.numeric)(x), (0, NumericValue_js_1.numeric)(y), renderNet));
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -181,15 +181,15 @@ class LayoutEngine {
|
|
|
181
181
|
}
|
|
182
182
|
placeFrames(graph, subgraphInfo, frameObjects) {
|
|
183
183
|
const baseFrame = frameObjects[0];
|
|
184
|
-
baseFrame.padding = (0,
|
|
185
|
-
baseFrame.borderWidth = (0,
|
|
184
|
+
baseFrame.padding = (0, NumericValue_js_1.numeric)(0);
|
|
185
|
+
baseFrame.borderWidth = (0, NumericValue_js_1.numeric)(0);
|
|
186
186
|
if (this.showBaseFrame) {
|
|
187
|
-
baseFrame.borderWidth = (0,
|
|
188
|
-
baseFrame.width = (0,
|
|
189
|
-
baseFrame.height = (0,
|
|
187
|
+
baseFrame.borderWidth = (0, NumericValue_js_1.numeric)(5);
|
|
188
|
+
baseFrame.width = (0, NumericValue_js_1.numeric)(11692 - 400 * 2);
|
|
189
|
+
baseFrame.height = (0, NumericValue_js_1.numeric)(8267 - 400 * 2);
|
|
190
190
|
}
|
|
191
|
-
baseFrame.x = (0,
|
|
192
|
-
baseFrame.y = (0,
|
|
191
|
+
baseFrame.x = (0, NumericValue_js_1.numeric)(0);
|
|
192
|
+
baseFrame.y = (0, NumericValue_js_1.numeric)(0);
|
|
193
193
|
baseFrame.bounds = {
|
|
194
194
|
xmin: 0, ymin: 0,
|
|
195
195
|
xmax: 0, ymax: 0,
|
|
@@ -235,8 +235,8 @@ class LayoutEngine {
|
|
|
235
235
|
const innerItems = frame.innerItems;
|
|
236
236
|
innerItems.forEach(innerFrame => {
|
|
237
237
|
if (innerFrame.frame.frameType === globals_js_1.FrameType.Sheet) {
|
|
238
|
-
innerFrame.x = (0,
|
|
239
|
-
innerFrame.y = (0,
|
|
238
|
+
innerFrame.x = (0, NumericValue_js_1.numeric)(0);
|
|
239
|
+
innerFrame.y = (0, NumericValue_js_1.numeric)(0);
|
|
240
240
|
}
|
|
241
241
|
else {
|
|
242
242
|
innerFrame.x = innerFrame.x.add(frame.x);
|
|
@@ -298,10 +298,10 @@ class LayoutEngine {
|
|
|
298
298
|
else {
|
|
299
299
|
accumRowWidth = maxWidth;
|
|
300
300
|
}
|
|
301
|
-
let frameWidth = (0,
|
|
302
|
-
let frameHeight = (0,
|
|
303
|
-
let frameXMin = (0,
|
|
304
|
-
let frameYMin = (0,
|
|
301
|
+
let frameWidth = (0, NumericValue_js_1.numeric)(0);
|
|
302
|
+
let frameHeight = (0, NumericValue_js_1.numeric)(0);
|
|
303
|
+
let frameXMin = (0, NumericValue_js_1.numeric)(0);
|
|
304
|
+
let frameYMin = (0, NumericValue_js_1.numeric)(0);
|
|
305
305
|
const frameParams = frame.frame.parameters;
|
|
306
306
|
const avoidAreas = [];
|
|
307
307
|
if (frameParams.has(Frame_js_1.FrameParamKeys.SheetType)) {
|
|
@@ -311,8 +311,8 @@ class LayoutEngine {
|
|
|
311
311
|
frameDrawing.variables = (0, utils_js_1.combineMaps)(frameComponent.parameters, frameParams);
|
|
312
312
|
const rects = ExtractDrawingRects(frameDrawing);
|
|
313
313
|
const drawableRect = rects.find(rect => rect.className === 'plot-area');
|
|
314
|
-
let frameMinX = (0,
|
|
315
|
-
let frameMinY = (0,
|
|
314
|
+
let frameMinX = (0, NumericValue_js_1.numeric)(0);
|
|
315
|
+
let frameMinY = (0, NumericValue_js_1.numeric)(0);
|
|
316
316
|
if (drawableRect) {
|
|
317
317
|
frameMinX = (0, helpers_js_1.milsToMM)(drawableRect.x);
|
|
318
318
|
frameMinY = (0, helpers_js_1.milsToMM)(drawableRect.y);
|
|
@@ -364,14 +364,14 @@ class LayoutEngine {
|
|
|
364
364
|
if (frameParams.has(Frame_js_1.FrameParamKeys.TitleAlign)) {
|
|
365
365
|
title_align = frameParams.get(Frame_js_1.FrameParamKeys.TitleAlign);
|
|
366
366
|
}
|
|
367
|
-
let accumX = (0,
|
|
368
|
-
let accumY = (0,
|
|
367
|
+
let accumX = (0, NumericValue_js_1.numeric)(0);
|
|
368
|
+
let accumY = (0, NumericValue_js_1.numeric)(0);
|
|
369
369
|
innerFrames.forEach((innerFrame, index) => {
|
|
370
370
|
const { width: innerFrameWidth, height: innerFrameHeight } = (0, utils_js_1.getBoundsSize)(innerFrame.bounds);
|
|
371
371
|
let arrangeLineAttempts = 0;
|
|
372
372
|
const maxAttempts = 10;
|
|
373
|
-
let innerFrameX = (0,
|
|
374
|
-
let innerFrameY = (0,
|
|
373
|
+
let innerFrameX = (0, NumericValue_js_1.numeric)(0);
|
|
374
|
+
let innerFrameY = (0, NumericValue_js_1.numeric)(0);
|
|
375
375
|
if (innerFrame.containsTitle) {
|
|
376
376
|
innerFrame.x = offsetX.add(accumX);
|
|
377
377
|
innerFrame.y = offsetY.add(accumY);
|
|
@@ -395,9 +395,9 @@ class LayoutEngine {
|
|
|
395
395
|
const doesOverlapAreasToAvoid = overlaps.length > 0;
|
|
396
396
|
if (boundPoints.length > 0 && (doesExceedFrameHeight || doesOverlapAreasToAvoid)) {
|
|
397
397
|
innerFrameY = offsetY;
|
|
398
|
-
const nextX = (0,
|
|
398
|
+
const nextX = (0, NumericValue_js_1.numeric)(xmax).sub(offsetX).add(frame.gap);
|
|
399
399
|
innerFrameX = offsetX.add(nextX);
|
|
400
|
-
accumY = (0,
|
|
400
|
+
accumY = (0, NumericValue_js_1.numeric)(0);
|
|
401
401
|
accumX = nextX;
|
|
402
402
|
}
|
|
403
403
|
arrangeLineAttempts++;
|
|
@@ -426,9 +426,9 @@ class LayoutEngine {
|
|
|
426
426
|
if (boundPoints.length > 0 && (doesExceedFrameWidth || doesOverlapAreasToAvoid)) {
|
|
427
427
|
innerFrameX = offsetX.add(centeredOffsetX);
|
|
428
428
|
const { ymax } = getBoundsFromPoints(boundPoints);
|
|
429
|
-
const nextY = (0,
|
|
429
|
+
const nextY = (0, NumericValue_js_1.numeric)(ymax).sub(offsetY).add(frame.gap);
|
|
430
430
|
innerFrameY = offsetY.add(nextY);
|
|
431
|
-
accumX = (0,
|
|
431
|
+
accumX = (0, NumericValue_js_1.numeric)(0);
|
|
432
432
|
accumY = nextY;
|
|
433
433
|
}
|
|
434
434
|
else {
|
|
@@ -466,18 +466,18 @@ class LayoutEngine {
|
|
|
466
466
|
frameParams.get(Frame_js_1.FrameParamKeys.VerticalAlign);
|
|
467
467
|
}
|
|
468
468
|
if (frameParams.has(Frame_js_1.FrameParamKeys.SheetType)) {
|
|
469
|
-
frameXMin = (0,
|
|
470
|
-
frameYMin = (0,
|
|
469
|
+
frameXMin = (0, NumericValue_js_1.numeric)(0);
|
|
470
|
+
frameYMin = (0, NumericValue_js_1.numeric)(0);
|
|
471
471
|
}
|
|
472
472
|
else {
|
|
473
|
-
frameXMin = (0,
|
|
474
|
-
frameYMin = (0,
|
|
473
|
+
frameXMin = (0, NumericValue_js_1.numeric)(contentsBounds.xmin);
|
|
474
|
+
frameYMin = (0, NumericValue_js_1.numeric)(contentsBounds.ymin);
|
|
475
475
|
}
|
|
476
476
|
if (frameWidth.toNumber() === 0) {
|
|
477
|
-
frameWidth = (0,
|
|
477
|
+
frameWidth = (0, NumericValue_js_1.numeric)(contentsWidth);
|
|
478
478
|
}
|
|
479
479
|
if (frameHeight.toNumber() === 0) {
|
|
480
|
-
frameHeight = (0,
|
|
480
|
+
frameHeight = (0, NumericValue_js_1.numeric)(contentsHeight);
|
|
481
481
|
}
|
|
482
482
|
const titleFrame = innerFrames.find(frame => {
|
|
483
483
|
return frame.containsTitle;
|
|
@@ -607,7 +607,7 @@ class LayoutEngine {
|
|
|
607
607
|
tmpFrame.containsTitle = true;
|
|
608
608
|
tmpFrame.subgraphId = title.replace(/\s/g, "_");
|
|
609
609
|
const textObject = new RenderText(title);
|
|
610
|
-
textObject.fontSize = (0,
|
|
610
|
+
textObject.fontSize = (0, NumericValue_js_1.numeric)(globals_js_1.defaultFrameTitleTextSize);
|
|
611
611
|
textObject.fontWeight = 'bold';
|
|
612
612
|
textObject.symbol.refreshDrawing();
|
|
613
613
|
tmpFrame.innerItems.push(textObject);
|
|
@@ -618,8 +618,8 @@ class LayoutEngine {
|
|
|
618
618
|
xmax: tmpBox.start[0] + tmpBox.width,
|
|
619
619
|
ymax: tmpBox.start[1] + tmpBox.height
|
|
620
620
|
};
|
|
621
|
-
textObject.x = (0,
|
|
622
|
-
textObject.y = (0,
|
|
621
|
+
textObject.x = (0, NumericValue_js_1.numeric)(0);
|
|
622
|
+
textObject.y = (0, NumericValue_js_1.numeric)(0);
|
|
623
623
|
frame.innerItems.splice(0, 0, tmpFrame);
|
|
624
624
|
this.printLevel(level, frame, 'added text', tmpFrame);
|
|
625
625
|
textObjects.push(textObject);
|
|
@@ -702,7 +702,7 @@ class LayoutEngine {
|
|
|
702
702
|
const componentUnit = node1.component.getUnit(unitId);
|
|
703
703
|
defaultPin = componentUnit.pinsFlat[0].id;
|
|
704
704
|
}
|
|
705
|
-
this.placeNodeAtPosition((0,
|
|
705
|
+
this.placeNodeAtPosition((0, NumericValue_js_1.numeric)(0), (0, NumericValue_js_1.numeric)(0), node1, defaultPin);
|
|
706
706
|
return;
|
|
707
707
|
}
|
|
708
708
|
let fixedNode;
|
|
@@ -730,7 +730,7 @@ class LayoutEngine {
|
|
|
730
730
|
originNodes.push(node1);
|
|
731
731
|
originNodeGroups.set(node1.toString(), [node1]);
|
|
732
732
|
this.print('creating new origin node at', node1);
|
|
733
|
-
this.placeNodeAtPosition((0,
|
|
733
|
+
this.placeNodeAtPosition((0, NumericValue_js_1.numeric)(0), (0, NumericValue_js_1.numeric)(0), node1, pin1);
|
|
734
734
|
node1.isFloating = false;
|
|
735
735
|
fixedNode = node1;
|
|
736
736
|
fixedNodePin = pin1;
|
|
@@ -899,8 +899,8 @@ class LayoutEngine {
|
|
|
899
899
|
}
|
|
900
900
|
exports.LayoutEngine = LayoutEngine;
|
|
901
901
|
function getNodePositionAtPin(item, pin) {
|
|
902
|
-
let x = (0,
|
|
903
|
-
let y = (0,
|
|
902
|
+
let x = (0, NumericValue_js_1.numeric)(0);
|
|
903
|
+
let y = (0, NumericValue_js_1.numeric)(0);
|
|
904
904
|
if (item instanceof RenderComponent) {
|
|
905
905
|
const pinPosition = item.symbol.pinPosition(pin);
|
|
906
906
|
x = item.x.add(pinPosition.x);
|
|
@@ -918,7 +918,7 @@ function getNodePositionAtPin(item, pin) {
|
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
920
|
return [
|
|
921
|
-
(0,
|
|
921
|
+
(0, NumericValue_js_1.roundValue)(x), (0, NumericValue_js_1.roundValue)(y)
|
|
922
922
|
];
|
|
923
923
|
}
|
|
924
924
|
function getNeighbours(graph, nodeIds) {
|
|
@@ -1038,8 +1038,8 @@ function getBoundsFromPoints(points) {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
class RenderObject {
|
|
1040
1040
|
constructor() {
|
|
1041
|
-
this.x = (0,
|
|
1042
|
-
this.y = (0,
|
|
1041
|
+
this.x = (0, NumericValue_js_1.numeric)(-1);
|
|
1042
|
+
this.y = (0, NumericValue_js_1.numeric)(-1);
|
|
1043
1043
|
this.isFloating = true;
|
|
1044
1044
|
this.floatingRelativeTo = [];
|
|
1045
1045
|
}
|
|
@@ -1084,7 +1084,7 @@ class RenderWire extends RenderObject {
|
|
|
1084
1084
|
tmpX += useValue;
|
|
1085
1085
|
}
|
|
1086
1086
|
else if (direction === globals_js_1.WireAutoDirection.Auto || direction === globals_js_1.WireAutoDirection.Auto_) {
|
|
1087
|
-
const { valueXY = [(0,
|
|
1087
|
+
const { valueXY = [(0, NumericValue_js_1.numeric)(0), (0, NumericValue_js_1.numeric)(0)] } = segment;
|
|
1088
1088
|
const tmpPoints = this.getAutoPoints(valueXY, direction);
|
|
1089
1089
|
tmpPoints.forEach(point => {
|
|
1090
1090
|
if (point[0] !== 0 || point[1] !== 0) {
|
|
@@ -1102,8 +1102,8 @@ class RenderWire extends RenderObject {
|
|
|
1102
1102
|
this.points = points;
|
|
1103
1103
|
}
|
|
1104
1104
|
getAutoPoints(value, direction) {
|
|
1105
|
-
const valueX = (0,
|
|
1106
|
-
const valueY = (0,
|
|
1105
|
+
const valueX = (0, NumericValue_js_1.roundValue)(value[0]).toNumber();
|
|
1106
|
+
const valueY = (0, NumericValue_js_1.roundValue)(value[1]).toNumber();
|
|
1107
1107
|
const inQuadrant = geometry_js_1.Geometry.getQuadrant(valueX, valueY);
|
|
1108
1108
|
const [dx, dy] = [valueX, valueY];
|
|
1109
1109
|
if (direction === globals_js_1.WireAutoDirection.Auto) {
|
|
@@ -1244,7 +1244,7 @@ class RenderText extends RenderObject {
|
|
|
1244
1244
|
}
|
|
1245
1245
|
constructor(text) {
|
|
1246
1246
|
super();
|
|
1247
|
-
this._fontSize = (0,
|
|
1247
|
+
this._fontSize = (0, NumericValue_js_1.numeric)(12);
|
|
1248
1248
|
this._fontWeight = 'regular';
|
|
1249
1249
|
this.symbol = new draw_symbols_js_1.SymbolText(text);
|
|
1250
1250
|
}
|
|
@@ -1259,7 +1259,7 @@ class RenderFrame extends RenderObject {
|
|
|
1259
1259
|
this.translateY = 0;
|
|
1260
1260
|
this.padding = (0, helpers_js_1.milsToMM)(100);
|
|
1261
1261
|
this.gap = (0, helpers_js_1.milsToMM)(100);
|
|
1262
|
-
this.borderWidth = (0,
|
|
1262
|
+
this.borderWidth = (0, NumericValue_js_1.numeric)(5);
|
|
1263
1263
|
this.direction = Frame_js_1.FramePlotDirection.Row;
|
|
1264
1264
|
this.width = null;
|
|
1265
1265
|
this.height = null;
|
|
@@ -8,7 +8,7 @@ const svg_js_1 = require("@svgdotjs/svg.js");
|
|
|
8
8
|
const layout_js_1 = require("./layout.js");
|
|
9
9
|
const sizing_js_1 = require("../sizing.js");
|
|
10
10
|
const globals_js_1 = require("../globals.js");
|
|
11
|
-
const
|
|
11
|
+
const NumericValue_js_1 = require("../objects/NumericValue.js");
|
|
12
12
|
const utils_js_1 = require("../utils.js");
|
|
13
13
|
const helpers_js_1 = require("../helpers.js");
|
|
14
14
|
const PaperSizes_js_1 = require("./PaperSizes.js");
|
|
@@ -37,7 +37,7 @@ function renderSheetsToSVG(sheetFrames, logger) {
|
|
|
37
37
|
let extendGrid = true;
|
|
38
38
|
let xOffset = 0;
|
|
39
39
|
let yOffset = 0;
|
|
40
|
-
let sheetYOffset = (0,
|
|
40
|
+
let sheetYOffset = (0, NumericValue_js_1.numeric)(0);
|
|
41
41
|
if (sheet.frame.frame) {
|
|
42
42
|
logger.add('drawing frame');
|
|
43
43
|
const frameComponent = sheet.frame.frame.parameters
|
|
@@ -48,10 +48,10 @@ function renderSheetsToSVG(sheetFrames, logger) {
|
|
|
48
48
|
throw 'Invalid graphic object for sheet frame';
|
|
49
49
|
}
|
|
50
50
|
const frameRects = (0, layout_js_1.ExtractDrawingRects)(frameComponentUnit.displayProp) ?? [];
|
|
51
|
-
let originalWidthMM = (0,
|
|
52
|
-
let originalHeightMM = (0,
|
|
53
|
-
let widthMM = (0,
|
|
54
|
-
let heightMM = (0,
|
|
51
|
+
let originalWidthMM = (0, NumericValue_js_1.numeric)(0);
|
|
52
|
+
let originalHeightMM = (0, NumericValue_js_1.numeric)(0);
|
|
53
|
+
let widthMM = (0, NumericValue_js_1.numeric)(0);
|
|
54
|
+
let heightMM = (0, NumericValue_js_1.numeric)(0);
|
|
55
55
|
const paperRect = frameRects.find(item => item.className === 'paper-area');
|
|
56
56
|
const plotRect = frameRects.find(item => item.className === 'plot-area');
|
|
57
57
|
if (paperRect) {
|
|
@@ -149,7 +149,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
149
149
|
}
|
|
150
150
|
else if (item.component.parameters.has('value')) {
|
|
151
151
|
let tmpValue = item.component.parameters.get('value');
|
|
152
|
-
if (tmpValue instanceof
|
|
152
|
+
if (tmpValue instanceof NumericValue_js_1.NumericValue) {
|
|
153
153
|
tmpValue = tmpValue.value;
|
|
154
154
|
}
|
|
155
155
|
extra.value = tmpValue;
|
|
@@ -232,15 +232,15 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
232
232
|
})
|
|
233
233
|
.fill('none');
|
|
234
234
|
const halfJunctionSize = globals_js_1.junctionSize.half();
|
|
235
|
-
const highlightJunctionSize = (0,
|
|
235
|
+
const highlightJunctionSize = (0, NumericValue_js_1.numeric)(globals_js_1.junctionSize.toNumber() + displayHighlightWidth);
|
|
236
236
|
const tmpHighlightExtraSize = highlightJunctionSize.half();
|
|
237
237
|
intersectPoints.forEach(point => {
|
|
238
238
|
const [x, y,] = point;
|
|
239
|
-
const translateX = (0,
|
|
240
|
-
const translateY = (0,
|
|
239
|
+
const translateX = (0, NumericValue_js_1.numeric)(x).sub(halfJunctionSize);
|
|
240
|
+
const translateY = (0, NumericValue_js_1.numeric)(y).sub(halfJunctionSize);
|
|
241
241
|
if (displayHighlight && displayHighlightColor !== null) {
|
|
242
|
-
const tmpTranslateX = (0,
|
|
243
|
-
const tmpTranslateY = (0,
|
|
242
|
+
const tmpTranslateX = (0, NumericValue_js_1.numeric)(x).sub(tmpHighlightExtraSize);
|
|
243
|
+
const tmpTranslateY = (0, NumericValue_js_1.numeric)(y).sub(tmpHighlightExtraSize);
|
|
244
244
|
mergedWireHighlightGroup.circle(highlightJunctionSize.toNumber())
|
|
245
245
|
.translate(tmpTranslateX.toNumber(), tmpTranslateY.toNumber())
|
|
246
246
|
.fill(displayHighlightColor)
|
|
@@ -298,14 +298,14 @@ function drawGrid(group, canvasSize, extendGrid, logger) {
|
|
|
298
298
|
const gridSize = globals_js_1.defaultGridSizeUnits;
|
|
299
299
|
const { xmin, ymin, xmax, ymax } = canvasSize;
|
|
300
300
|
const extraValue = extendGrid ? 1 : 0;
|
|
301
|
-
const gridStartX = ((0,
|
|
302
|
-
const gridStartY = ((0,
|
|
301
|
+
const gridStartX = ((0, NumericValue_js_1.numeric)(Math.floor(xmin / gridSize)).sub(extraValue)).mul(gridSize);
|
|
302
|
+
const gridStartY = ((0, NumericValue_js_1.numeric)(Math.floor(ymin / gridSize)).sub(extraValue)).mul(gridSize);
|
|
303
303
|
const gridEndX = extendGrid
|
|
304
|
-
? ((0,
|
|
305
|
-
: ((0,
|
|
304
|
+
? ((0, NumericValue_js_1.numeric)(Math.ceil(xmax / gridSize)).add(extraValue)).mul(gridSize)
|
|
305
|
+
: ((0, NumericValue_js_1.numeric)(xmax).sub(xmin));
|
|
306
306
|
const gridEndY = extendGrid
|
|
307
|
-
? ((0,
|
|
308
|
-
: ((0,
|
|
307
|
+
? ((0, NumericValue_js_1.numeric)(Math.ceil(ymax / gridSize)).add(extraValue)).mul(gridSize)
|
|
308
|
+
: ((0, NumericValue_js_1.numeric)(ymax).sub(ymin));
|
|
309
309
|
const numCols = Math.floor(gridEndX.sub(gridStartX).div(gridSize).toNumber())
|
|
310
310
|
+ (extendGrid ? 1 : 0);
|
|
311
311
|
const originSize = (0, helpers_js_1.milsToMM)(10).toNumber();
|
|
@@ -316,7 +316,7 @@ function drawGrid(group, canvasSize, extendGrid, logger) {
|
|
|
316
316
|
const smallOffset = (0, helpers_js_1.milsToMM)(3);
|
|
317
317
|
const startY = gridStartY.sub(smallOffset.half());
|
|
318
318
|
const endY = gridEndY.add(smallOffset);
|
|
319
|
-
const numericGridSize = (0,
|
|
319
|
+
const numericGridSize = (0, NumericValue_js_1.numeric)(gridSize);
|
|
320
320
|
for (let i = 0; i < numCols; i++) {
|
|
321
321
|
const startX = gridStartX.add(numericGridSize.mul(i)).toNumber();
|
|
322
322
|
lines.push(`M ${startX} ${startY.toNumber()} L ${startX} ${endY.toNumber()}`);
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.prepareTokens = exports.SemanticTokensVisitor = void 0;
|
|
4
4
|
const CircuitScriptParser_js_1 = require("../antlr/CircuitScriptParser.js");
|
|
5
5
|
const BaseVisitor_js_1 = require("../BaseVisitor.js");
|
|
6
|
-
const builtinMethods_js_1 = require("../builtinMethods.js");
|
|
7
6
|
const globals_js_1 = require("../globals.js");
|
|
8
7
|
class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
9
8
|
constructor(silent = false, onErrorHandler = null, environment, lexer, script) {
|
|
@@ -26,13 +25,6 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
26
25
|
this.addSemanticToken(id, ['declaration'], 'parameter');
|
|
27
26
|
});
|
|
28
27
|
};
|
|
29
|
-
this.visitFunction_call_expr = (ctx) => {
|
|
30
|
-
const modifiers = [];
|
|
31
|
-
if (builtinMethods_js_1.buildInMethodNamesList.indexOf(ctx.ID().getText()) !== -1) {
|
|
32
|
-
modifiers.push('defaultLibrary');
|
|
33
|
-
}
|
|
34
|
-
this.addSemanticToken(ctx.ID(), modifiers, 'function');
|
|
35
|
-
};
|
|
36
28
|
this.visitFunction_def_expr = (ctx) => {
|
|
37
29
|
const functionName = ctx.ID().getText();
|
|
38
30
|
this.addSemanticToken(ctx.ID(), ['declaration'], 'function');
|
|
@@ -46,17 +38,13 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
46
38
|
this.executionStack.pop();
|
|
47
39
|
};
|
|
48
40
|
this.visitCreateExpr = (ctx) => {
|
|
49
|
-
this.addSemanticToken(ctx.Create(), ['defaultLibrary'], 'function');
|
|
50
41
|
this.visit(ctx.create_expr());
|
|
51
42
|
};
|
|
52
43
|
this.visitCreate_component_expr = (ctx) => {
|
|
53
|
-
ctx.
|
|
54
|
-
this.visit(property_expr);
|
|
55
|
-
});
|
|
44
|
+
this.visitResult(ctx.properties_block());
|
|
56
45
|
};
|
|
57
46
|
this.visitCreate_graphic_expr = (ctx) => {
|
|
58
|
-
|
|
59
|
-
this.visitResult(graphicsExpressionsCtx);
|
|
47
|
+
this.visitResult(ctx.graphic_expressions_block());
|
|
60
48
|
};
|
|
61
49
|
this.visitProperty_key_expr = (ctx) => {
|
|
62
50
|
let useValue = null;
|
|
@@ -90,27 +78,36 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
90
78
|
this.addSemanticToken(useValue, [], 'property');
|
|
91
79
|
}
|
|
92
80
|
};
|
|
93
|
-
this.visitValueAtomExpr = (ctx) => {
|
|
94
|
-
const ctxValueExpr = ctx.value_expr();
|
|
95
|
-
const ctxAtomExpr = ctx.atom_expr();
|
|
96
|
-
if (ctxValueExpr) {
|
|
97
|
-
this.visit(ctxValueExpr);
|
|
98
|
-
}
|
|
99
|
-
else if (ctxAtomExpr) {
|
|
100
|
-
this.visit(ctxAtomExpr);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
81
|
this.visitAssignment_expr = (ctx) => {
|
|
104
82
|
this.visit(ctx.callable_expr());
|
|
105
83
|
this.visit(ctx.data_expr());
|
|
106
84
|
};
|
|
107
85
|
this.visitCallable_expr = (ctx) => {
|
|
108
|
-
|
|
109
|
-
|
|
86
|
+
const id = ctx.ID();
|
|
87
|
+
if (!id)
|
|
88
|
+
return;
|
|
89
|
+
if (ctx.parent instanceof CircuitScriptParser_js_1.Assignment_exprContext) {
|
|
90
|
+
this.addSemanticToken(id, [], 'variable');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const trailers = ctx.trailer();
|
|
94
|
+
if (trailers && trailers.length > 0) {
|
|
95
|
+
const firstTrailer = trailers[0];
|
|
96
|
+
if (firstTrailer.LParen()) {
|
|
97
|
+
this.addSemanticToken(id, [], 'function');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
110
100
|
}
|
|
111
101
|
};
|
|
112
|
-
this.
|
|
113
|
-
|
|
102
|
+
this.visitImport_simple = (ctx) => {
|
|
103
|
+
};
|
|
104
|
+
this.visitImport_specific_or_all = (ctx) => {
|
|
105
|
+
const funcNames = ctx.ID();
|
|
106
|
+
if (funcNames && funcNames.length > 0) {
|
|
107
|
+
funcNames.forEach(funcName => {
|
|
108
|
+
this.addSemanticToken(funcName, ['defaultLibrary'], 'function');
|
|
109
|
+
});
|
|
110
|
+
}
|
|
114
111
|
};
|
|
115
112
|
this.visitFor_expr = (ctx) => {
|
|
116
113
|
ctx.ID().forEach(item => {
|
|
@@ -121,7 +118,12 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
121
118
|
};
|
|
122
119
|
this.visitAnnotation_comment_expr = (ctx) => {
|
|
123
120
|
this.addSemanticToken(ctx.ANNOTATION_START(), [], 'comment');
|
|
124
|
-
|
|
121
|
+
const ids = ctx.ID();
|
|
122
|
+
if (ids && ids.length > 0) {
|
|
123
|
+
ids.forEach(id => {
|
|
124
|
+
this.addSemanticToken(id, [], 'comment');
|
|
125
|
+
});
|
|
126
|
+
}
|
|
125
127
|
};
|
|
126
128
|
this.lexer = lexer;
|
|
127
129
|
this.script = script;
|
|
@@ -135,20 +137,21 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
135
137
|
let stringValue = "";
|
|
136
138
|
let textPart = "";
|
|
137
139
|
if (this.lexer.symbolicNames[token.type] !== null && this.lexer.symbolicNames[token.type] !== undefined) {
|
|
138
|
-
stringValue = this.lexer.symbolicNames[token.type];
|
|
140
|
+
stringValue = this.lexer.symbolicNames[token.type] ?? '';
|
|
139
141
|
if (stringValue !== "NEWLINE") {
|
|
140
142
|
textPart = this.script.substring(token.start, token.stop + 1);
|
|
141
143
|
}
|
|
142
144
|
else {
|
|
143
|
-
textPart = token.text
|
|
145
|
+
textPart = token.text || '';
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
else if (this.lexer.literalNames[token.type] !== null && this.lexer.literalNames[token.type] !== undefined) {
|
|
147
|
-
stringValue = this.lexer.literalNames[token.type];
|
|
149
|
+
stringValue = this.lexer.literalNames[token.type] ?? '';
|
|
148
150
|
textPart = this.script.substring(token.start, token.stop + 1);
|
|
149
151
|
}
|
|
150
152
|
else {
|
|
151
|
-
stringValue = token.
|
|
153
|
+
stringValue = token.text ?? '';
|
|
154
|
+
textPart = token.text || '';
|
|
152
155
|
}
|
|
153
156
|
return {
|
|
154
157
|
line: token.line,
|
|
@@ -157,6 +160,7 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
157
160
|
tokenType: tokenType !== null ? tokenType : stringValue,
|
|
158
161
|
tokenModifiers: modifiers,
|
|
159
162
|
textValue: textPart,
|
|
163
|
+
path: '',
|
|
160
164
|
};
|
|
161
165
|
}
|
|
162
166
|
dumpTokens() {
|
|
@@ -171,38 +175,39 @@ class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
171
175
|
exports.SemanticTokensVisitor = SemanticTokensVisitor;
|
|
172
176
|
function prepareTokens(tokens, lexer, script) {
|
|
173
177
|
const parsedTokens = [];
|
|
174
|
-
|
|
178
|
+
for (const item of tokens) {
|
|
175
179
|
if (item.type !== -1) {
|
|
176
180
|
let stringValue = "";
|
|
177
181
|
let textPart = "";
|
|
178
182
|
if (lexer.symbolicNames[item.type] !== null && lexer.symbolicNames[item.type] !== undefined) {
|
|
179
|
-
stringValue = lexer.symbolicNames[item.type];
|
|
183
|
+
stringValue = lexer.symbolicNames[item.type] ?? '';
|
|
180
184
|
if (stringValue !== "NEWLINE") {
|
|
181
185
|
textPart = script.substring(item.start, item.stop + 1);
|
|
182
186
|
}
|
|
183
187
|
else {
|
|
184
|
-
textPart = item.text
|
|
188
|
+
textPart = item.text || '';
|
|
185
189
|
}
|
|
186
190
|
}
|
|
187
|
-
else if (lexer.literalNames[item.type] !== null && lexer.literalNames[item.type] !== undefined) {
|
|
188
|
-
stringValue = lexer.literalNames[item.type];
|
|
189
|
-
textPart = script.substring(item.start, item.stop + 1);
|
|
190
|
-
}
|
|
191
191
|
else {
|
|
192
|
-
stringValue = item.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
192
|
+
stringValue = item.text ?? '';
|
|
193
|
+
textPart = item.text || '';
|
|
194
|
+
}
|
|
195
|
+
if (textPart !== '') {
|
|
196
|
+
const tokenType = resolveTokenType(stringValue);
|
|
197
|
+
if (tokenType !== '') {
|
|
198
|
+
parsedTokens.push({
|
|
199
|
+
line: item.line,
|
|
200
|
+
column: item.column,
|
|
201
|
+
length: item.stop - item.start + 1,
|
|
202
|
+
tokenType: tokenType,
|
|
203
|
+
tokenModifiers: resolveTokenModifiers(stringValue),
|
|
204
|
+
textValue: textPart,
|
|
205
|
+
path: '',
|
|
206
|
+
});
|
|
207
|
+
}
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
|
-
}
|
|
210
|
+
}
|
|
206
211
|
return parsedTokens;
|
|
207
212
|
}
|
|
208
213
|
exports.prepareTokens = prepareTokens;
|
|
@@ -211,15 +216,10 @@ const languageKeywords = [
|
|
|
211
216
|
'graphic', 'wire', 'pin', 'add', 'at', 'to',
|
|
212
217
|
'point', 'join', 'parallel', 'return', 'def', 'from', 'import',
|
|
213
218
|
'true', 'false', 'nc', 'sheet', 'frame', 'if', 'else', 'for', 'in',
|
|
214
|
-
];
|
|
215
|
-
const operatorKeywords = [
|
|
216
219
|
'at', 'to', 'wire', 'add', 'frame', 'join', 'parallel', 'point'
|
|
217
220
|
];
|
|
218
221
|
function resolveTokenType(tokenType) {
|
|
219
|
-
if (
|
|
220
|
-
return 'graphKeyword';
|
|
221
|
-
}
|
|
222
|
-
else if (languageKeywords.indexOf(tokenType.toLowerCase()) !== -1) {
|
|
222
|
+
if (languageKeywords.indexOf(tokenType.toLowerCase()) !== -1) {
|
|
223
223
|
return 'keyword';
|
|
224
224
|
}
|
|
225
225
|
else {
|
|
@@ -239,7 +239,7 @@ function resolveTokenType(tokenType) {
|
|
|
239
239
|
case 'COMMENT':
|
|
240
240
|
return 'comment';
|
|
241
241
|
}
|
|
242
|
-
return
|
|
242
|
+
return '';
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
function resolveTokenModifiers(tokenType) {
|