circuitscript 0.0.29 → 0.0.32
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 +41 -14
- package/dist/cjs/geometry.js +79 -18
- package/dist/cjs/globals.js +37 -6
- package/dist/cjs/helpers.js +75 -5
- package/dist/cjs/layout.js +107 -43
- 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/Frame.js +2 -0
- 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 +29 -21
- 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 +42 -15
- package/dist/esm/geometry.mjs +79 -17
- package/dist/esm/globals.mjs +36 -5
- package/dist/esm/helpers.mjs +74 -5
- package/dist/esm/layout.mjs +110 -46
- 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/Frame.mjs +2 -0
- 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 +30 -22
- 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 +32 -3
- package/dist/types/helpers.d.ts +12 -0
- package/dist/types/layout.d.ts +8 -2
- package/dist/types/objects/ClassComponent.d.ts +8 -0
- package/dist/types/objects/Frame.d.ts +3 -1
- 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/render.d.ts +5 -1
- 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 +5 -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,12 +772,14 @@ 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
|
}
|
|
754
779
|
enterFrame() {
|
|
755
780
|
const frameId = this.scope.frames.length + 1;
|
|
756
781
|
const frameObject = new Frame_js_1.Frame(frameId);
|
|
782
|
+
this.log('Enter frame', frameId);
|
|
757
783
|
this.scope.frames.push(frameObject);
|
|
758
784
|
this.scope.sequence.push([ExecutionScope_js_1.SequenceAction.Frame,
|
|
759
785
|
frameObject, ExecutionScope_js_1.FrameAction.Enter]);
|
|
@@ -765,6 +791,7 @@ class ExecutionContext {
|
|
|
765
791
|
const frame = this.scope.frames[frameId - 1];
|
|
766
792
|
this.scope.sequence.push([ExecutionScope_js_1.SequenceAction.Frame,
|
|
767
793
|
frame, ExecutionScope_js_1.FrameAction.Exit]);
|
|
794
|
+
this.log('Leave frame', frameId);
|
|
768
795
|
}
|
|
769
796
|
}
|
|
770
797
|
exports.ExecutionContext = ExecutionContext;
|
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.MMToPt = 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,49 @@ 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.MMToPt = 2.8346456693;
|
|
43
|
+
exports.PxToMM = 0.2645833;
|
|
29
44
|
exports.portWidth = 20;
|
|
30
45
|
exports.portHeight = 2;
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
46
|
+
exports.defaultGridSizeUnits = exports.MilsToMM * 100;
|
|
47
|
+
exports.defaultZoomScale = 2.5;
|
|
48
|
+
exports.fontDisplayScale = 0.032;
|
|
49
|
+
exports.defaultSymbolLineWidth = exports.MilsToMM * 6;
|
|
50
|
+
exports.defaultWireLineWidth = exports.MilsToMM * 6;
|
|
51
|
+
exports.defaultPinNameTextSize = 40;
|
|
52
|
+
exports.defaultPinIdTextSize = 30;
|
|
53
|
+
exports.CustomSymbolPinTextSize = exports.defaultPinNameTextSize;
|
|
54
|
+
exports.CustomSymbolPinIdSize = exports.defaultPinIdTextSize;
|
|
55
|
+
exports.CustomSymbolRefDesSize = 50;
|
|
56
|
+
exports.CustomSymbolParamTextSize = 40;
|
|
57
|
+
exports.defaultFrameTitleTextSize = 60;
|
|
58
|
+
exports.displayUnits = LengthUnit.mils;
|
|
59
|
+
exports.defaultFont = 'Arial';
|
|
60
|
+
exports.defaultFontBold = 'Arial';
|
|
33
61
|
exports.defaultFontSize = 10;
|
|
34
|
-
exports.junctionSize =
|
|
62
|
+
exports.junctionSize = exports.MilsToMM * 20;
|
|
63
|
+
exports.PortArrowSize = exports.MilsToMM * 50;
|
|
64
|
+
exports.PortPaddingHorizontal = exports.MilsToMM * 10;
|
|
65
|
+
exports.PortPaddingVertical = exports.MilsToMM * 10;
|
|
35
66
|
exports.ColorScheme = {
|
|
36
67
|
BodyColor: 'rgb(255, 255, 194)',
|
|
37
68
|
JunctionColor: 'rgba(0, 132, 0)',
|
|
38
69
|
WireColor: 'rgb(0, 132, 0)',
|
|
39
|
-
PinLineColor: '
|
|
40
|
-
PinNameColor: '
|
|
70
|
+
PinLineColor: '#333',
|
|
71
|
+
PinNameColor: '#333',
|
|
41
72
|
};
|
|
42
73
|
var ComponentTypes;
|
|
43
74
|
(function (ComponentTypes) {
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -3,8 +3,10 @@ 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
|
+
const pdfkit_1 = __importDefault(require("pdfkit"));
|
|
9
|
+
const svg_to_pdfkit_1 = __importDefault(require("svg-to-pdfkit"));
|
|
8
10
|
const export_js_1 = require("./export.js");
|
|
9
11
|
const layout_js_1 = require("./layout.js");
|
|
10
12
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
@@ -19,6 +21,7 @@ const lexer_js_1 = require("./lexer.js");
|
|
|
19
21
|
const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
|
|
20
22
|
const SemanticTokenVisitor_js_1 = require("./SemanticTokenVisitor.js");
|
|
21
23
|
const path_1 = __importDefault(require("path"));
|
|
24
|
+
const globals_js_1 = require("./globals.js");
|
|
22
25
|
var JSModuleType;
|
|
23
26
|
(function (JSModuleType) {
|
|
24
27
|
JSModuleType["CommonJs"] = "cjs";
|
|
@@ -174,7 +177,10 @@ function renderScript(scriptData, outputPath, options) {
|
|
|
174
177
|
const { tree, parser, hasParseError, hasError, parserTimeTaken, lexerTimeTaken } = (0, parser_js_1.parseFileWithVisitor)(visitor, scriptData);
|
|
175
178
|
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
176
179
|
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
177
|
-
|
|
180
|
+
if (dumpNets) {
|
|
181
|
+
const nets = visitor.dumpNets();
|
|
182
|
+
console.log(nets);
|
|
183
|
+
}
|
|
178
184
|
dumpData && (0, fs_1.writeFileSync)('dump/tree.lisp', tree.toStringTree(null, parser));
|
|
179
185
|
dumpData && (0, fs_1.writeFileSync)('dump/raw-parser.txt', visitor.logger.dump());
|
|
180
186
|
if (hasError || hasParseError) {
|
|
@@ -215,17 +221,47 @@ function renderScript(scriptData, outputPath, options) {
|
|
|
215
221
|
dumpData && (0, fs_1.writeFileSync)('dump/raw-sequence.txt', tmpSequence.join('\n'));
|
|
216
222
|
let svgOutput = null;
|
|
217
223
|
try {
|
|
218
|
-
|
|
224
|
+
let fileExtension = null;
|
|
225
|
+
let showBaseFrame = false;
|
|
226
|
+
if (outputPath) {
|
|
227
|
+
fileExtension = path_1.default.extname(outputPath).substring(1);
|
|
228
|
+
if (fileExtension === 'pdf') {
|
|
229
|
+
showBaseFrame = true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const layoutEngine = new layout_js_1.LayoutEngine({
|
|
233
|
+
showBaseFrame,
|
|
234
|
+
});
|
|
219
235
|
const layoutTimer = new utils_js_1.SimpleStopwatch();
|
|
220
236
|
const graph = layoutEngine.runLayout(sequence, nets);
|
|
221
237
|
layoutEngine.printWarnings();
|
|
222
238
|
showStats && console.log('Layout took:', layoutTimer.lap());
|
|
223
239
|
dumpData && (0, fs_1.writeFileSync)('dump/raw-layout.txt', layoutEngine.logger.dump());
|
|
224
240
|
const generateSvgTimer = new utils_js_1.SimpleStopwatch();
|
|
225
|
-
|
|
241
|
+
const { svg: generatedSvg, width: svgWidth, height: svgHeight } = (0, render_js_1.generateSVG2)(graph);
|
|
242
|
+
svgOutput = generatedSvg;
|
|
226
243
|
showStats && console.log('Render took:', generateSvgTimer.lap());
|
|
227
244
|
if (outputPath) {
|
|
228
|
-
(
|
|
245
|
+
if (fileExtension === 'svg') {
|
|
246
|
+
(0, fs_1.writeFileSync)(outputPath, svgOutput);
|
|
247
|
+
}
|
|
248
|
+
else if (fileExtension === 'pdf') {
|
|
249
|
+
const doc = new pdfkit_1.default({
|
|
250
|
+
layout: 'landscape',
|
|
251
|
+
size: 'A4',
|
|
252
|
+
});
|
|
253
|
+
const outputStream = (0, fs_1.createWriteStream)(outputPath);
|
|
254
|
+
const paperWidthMM = 297;
|
|
255
|
+
const paperHeightMM = 210;
|
|
256
|
+
const xOffset = (paperWidthMM - svgWidth) / 2;
|
|
257
|
+
const yOffset = (paperHeightMM - svgHeight) / 2;
|
|
258
|
+
(0, svg_to_pdfkit_1.default)(doc, svgOutput, xOffset * globals_js_1.MMToPt, yOffset * globals_js_1.MMToPt);
|
|
259
|
+
doc.pipe(outputStream);
|
|
260
|
+
doc.end();
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
throw "Invalid output format";
|
|
264
|
+
}
|
|
229
265
|
console.log('Generated file', outputPath);
|
|
230
266
|
}
|
|
231
267
|
}
|
|
@@ -271,3 +307,37 @@ function getPackageVersion() {
|
|
|
271
307
|
return version;
|
|
272
308
|
}
|
|
273
309
|
exports.getPackageVersion = getPackageVersion;
|
|
310
|
+
class UnitDimension {
|
|
311
|
+
constructor(value, type = globals_js_1.LengthUnit.mils) {
|
|
312
|
+
this.value = value;
|
|
313
|
+
this.type = type;
|
|
314
|
+
}
|
|
315
|
+
getMM() {
|
|
316
|
+
switch (this.type) {
|
|
317
|
+
case globals_js_1.LengthUnit.mm:
|
|
318
|
+
return this.value;
|
|
319
|
+
case globals_js_1.LengthUnit.mils:
|
|
320
|
+
return this.value * globals_js_1.MilsToMM;
|
|
321
|
+
case globals_js_1.LengthUnit.px:
|
|
322
|
+
return this.value * globals_js_1.PxToMM;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
static mm(value) {
|
|
326
|
+
return new UnitDimension(value, globals_js_1.LengthUnit.mm);
|
|
327
|
+
}
|
|
328
|
+
static mils(value) {
|
|
329
|
+
return new UnitDimension(value, globals_js_1.LengthUnit.mils);
|
|
330
|
+
}
|
|
331
|
+
static px(value) {
|
|
332
|
+
return new UnitDimension(value, globals_js_1.LengthUnit.px);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
exports.UnitDimension = UnitDimension;
|
|
336
|
+
function milsToMM(value) {
|
|
337
|
+
return value * globals_js_1.MilsToMM;
|
|
338
|
+
}
|
|
339
|
+
exports.milsToMM = milsToMM;
|
|
340
|
+
function pxToMM(value) {
|
|
341
|
+
return value * globals_js_1.PxToMM;
|
|
342
|
+
}
|
|
343
|
+
exports.pxToMM = pxToMM;
|