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