circuitscript 0.0.22 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseVisitor.js +487 -0
- package/dist/cjs/SemanticTokenVisitor.js +218 -0
- package/dist/cjs/SymbolValidatorVisitor.js +233 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +302 -0
- package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
- package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
- package/dist/cjs/draw_symbols.js +819 -0
- package/dist/cjs/execute.js +778 -0
- package/{src/export.ts → dist/cjs/export.js} +34 -56
- package/dist/cjs/fonts.js +4 -0
- package/dist/cjs/geometry.js +450 -0
- package/dist/cjs/globals.js +60 -0
- package/dist/cjs/helpers.js +269 -0
- package/dist/cjs/index.js +31 -0
- package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
- package/dist/cjs/lexer.js +111 -0
- package/dist/cjs/logger.js +17 -0
- package/dist/cjs/main.js +82 -0
- package/dist/cjs/objects/ClassComponent.js +145 -0
- package/dist/cjs/objects/ExecutionScope.js +135 -0
- package/dist/cjs/objects/Frame.js +22 -0
- package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
- package/dist/cjs/objects/ParamDefinition.js +42 -0
- package/dist/cjs/objects/PinDefinition.js +31 -0
- package/dist/cjs/objects/PinTypes.js +11 -0
- package/dist/cjs/objects/Wire.js +9 -0
- package/dist/cjs/objects/types.js +15 -0
- package/dist/cjs/parser.js +70 -0
- package/dist/cjs/regenerate-tests.js +23 -0
- package/dist/cjs/render.js +155 -0
- package/{src/server.ts → dist/cjs/server.js} +15 -21
- package/dist/cjs/sizing.js +105 -0
- package/{src/utils.ts → dist/cjs/utils.js} +25 -35
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +844 -0
- package/dist/esm/BaseVisitor.mjs +488 -0
- package/dist/esm/SemanticTokenVisitor.mjs +215 -0
- package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
- package/dist/esm/antlr/CircuitScriptLexer.mjs +276 -0
- package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
- package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
- package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
- package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
- package/{build/src/export.js → dist/esm/export.mjs} +2 -2
- package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
- package/dist/esm/helpers.mjs +252 -0
- package/dist/esm/index.mjs +15 -0
- package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
- package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
- package/{build/src/main.js → dist/esm/main.mjs} +9 -14
- package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
- package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
- package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
- package/dist/esm/objects/types.mjs +12 -0
- package/dist/esm/parser.mjs +64 -0
- package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
- package/{build/src/render.js → dist/esm/render.mjs} +7 -24
- package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
- package/{src/main.ts → dist/esm/validate.mjs} +31 -62
- package/dist/esm/visitor.mjs +838 -0
- package/dist/types/BaseVisitor.d.ts +69 -0
- package/dist/types/SemanticTokenVisitor.d.ts +36 -0
- package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
- package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
- package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
- package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
- package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
- package/{build/src → dist/types}/execute.d.ts +6 -9
- package/{build/src → dist/types}/geometry.d.ts +5 -1
- package/dist/types/helpers.d.ts +40 -0
- package/dist/types/index.d.ts +15 -0
- package/{build/src → dist/types}/layout.d.ts +10 -10
- package/{build/src → dist/types}/lexer.d.ts +2 -2
- package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
- package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
- package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
- package/{build/src → dist/types}/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +25 -0
- package/{build/src → dist/types}/render.d.ts +1 -1
- package/{build/src → dist/types}/sizing.d.ts +3 -1
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +80 -0
- package/libs/lib.cst +0 -2
- package/package.json +38 -15
- package/.editorconfig +0 -15
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -27
- package/.gitlab-ci.yml +0 -81
- package/.prettierignore +0 -8
- package/.prettierrc +0 -16
- package/__tests__/expectedResults.ts +0 -657
- package/__tests__/helpers.ts +0 -82
- package/__tests__/parseScripts.ts +0 -593
- package/__tests__/renderData/script1.cst +0 -58
- package/__tests__/renderData/script1.cst.svg +0 -1
- package/__tests__/renderData/script2.cst +0 -16
- package/__tests__/renderData/script2.cst.svg +0 -1
- package/__tests__/renderData/script3.cst +0 -30
- package/__tests__/renderData/script3.cst.svg +0 -1
- package/__tests__/renderData/script4.cst +0 -54
- package/__tests__/renderData/script4.cst.svg +0 -1
- package/__tests__/renderData/script5.cst +0 -23
- package/__tests__/renderData/script5.cst.svg +0 -1
- package/__tests__/renderData/script6.cst +0 -28
- package/__tests__/renderData/script6.cst.svg +0 -1
- package/__tests__/renderData/script7.cst +0 -26
- package/__tests__/renderData/script7.cst.svg +0 -1
- package/__tests__/renderData/script8.cst +0 -37
- package/__tests__/renderData/script8.cst.svg +0 -1
- package/__tests__/testCLI.ts +0 -68
- package/__tests__/testMathOps.ts +0 -36
- package/__tests__/testMergeWires.ts +0 -141
- package/__tests__/testParse.ts +0 -263
- package/__tests__/testRender.ts +0 -38
- package/build/src/antlr/CircuitScriptLexer.js +0 -287
- package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
- package/build/src/antlr/CircuitScriptParser.js +0 -4841
- package/build/src/helpers.d.ts +0 -1
- package/build/src/helpers.js +0 -73
- package/build/src/objects/types.js +0 -6
- package/build/src/parser.js +0 -69
- package/build/src/visitor.d.ts +0 -133
- package/build/src/visitor.js +0 -1154
- package/documentation.md +0 -238
- package/examples/example_arduino_uno.cst +0 -1146
- package/examples/example_garden_pump.cst +0 -567
- package/examples/lib.cst +0 -185
- package/jest.config.js +0 -23
- package/refresh.html +0 -42
- package/server.cjs +0 -50
- package/src/antlr/CircuitScript.g4 +0 -209
- package/src/antlr/CircuitScriptLexer.ts +0 -317
- package/src/antlr/CircuitScriptParser.ts +0 -4979
- package/src/antlr/CircuitScriptVisitor.ts +0 -420
- package/src/draw_symbols.ts +0 -1085
- package/src/execute.ts +0 -1227
- package/src/fonts.ts +0 -1
- package/src/geometry.ts +0 -638
- package/src/globals.ts +0 -67
- package/src/helpers.ts +0 -114
- package/src/lexer.ts +0 -151
- package/src/logger.ts +0 -17
- package/src/objects/ClassComponent.ts +0 -223
- package/src/objects/ExecutionScope.ts +0 -201
- package/src/objects/Frame.ts +0 -20
- package/src/objects/ParamDefinition.ts +0 -49
- package/src/objects/PinDefinition.ts +0 -49
- package/src/objects/PinTypes.ts +0 -7
- package/src/objects/Wire.ts +0 -19
- package/src/objects/types.ts +0 -66
- package/src/parser.ts +0 -106
- package/src/regenerate-tests.ts +0 -25
- package/src/render.ts +0 -260
- package/src/sizing.ts +0 -96
- package/src/visitor.ts +0 -1691
- package/tsconfig.json +0 -27
- package/tsconfig.release.json +0 -8
- /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
- /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
- /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
- /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
- /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
- /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
- /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
- /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
- /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
- /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
- /package/{build/src → dist/types}/export.d.ts +0 -0
- /package/{build/src → dist/types}/fonts.d.ts +0 -0
- /package/{build/src → dist/types}/globals.d.ts +0 -0
- /package/{build/src → dist/types}/logger.d.ts +0 -0
- /package/{build/src → dist/types}/main.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
- /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
- /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
- /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
- /package/{build/src → dist/types}/server.d.ts +0 -0
- /package/{build/src → dist/types}/utils.d.ts +0 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VerticalAlign = exports.HorizontalAlign = exports.Geometry = exports.GeometryProp = exports.Label = void 0;
|
|
7
|
+
const core_1 = __importDefault(require("@flatten-js/core"));
|
|
8
|
+
const sizing_js_1 = require("./sizing.js");
|
|
9
|
+
const globals_js_1 = require("./globals.js");
|
|
10
|
+
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
11
|
+
class Label extends core_1.default.Polygon {
|
|
12
|
+
get box() {
|
|
13
|
+
return this.polygon.box;
|
|
14
|
+
}
|
|
15
|
+
constructor(id, text, anchorPoint, polygon, style, bounds) {
|
|
16
|
+
super(polygon.vertices);
|
|
17
|
+
this.anchorPoint = [0, 0];
|
|
18
|
+
this.boundingBox = { width: -1, height: -1 };
|
|
19
|
+
this.font = 'default';
|
|
20
|
+
this.id = id;
|
|
21
|
+
this.text = text;
|
|
22
|
+
this.anchorPoint = anchorPoint;
|
|
23
|
+
this.style = style;
|
|
24
|
+
this.boundingBox = polygon.box;
|
|
25
|
+
this.polygon = polygon;
|
|
26
|
+
this.textMeasurementBounds = bounds;
|
|
27
|
+
}
|
|
28
|
+
static fromPoint(id, x, y, text, style) {
|
|
29
|
+
let useText;
|
|
30
|
+
if (typeof text === 'number') {
|
|
31
|
+
useText = text.toString();
|
|
32
|
+
}
|
|
33
|
+
else if (typeof text === 'object'
|
|
34
|
+
&& text instanceof ParamDefinition_js_1.NumericValue) {
|
|
35
|
+
useText = text.toDisplayString();
|
|
36
|
+
}
|
|
37
|
+
else if (typeof text === 'string') {
|
|
38
|
+
useText = text;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw 'Invalid string passed into label';
|
|
42
|
+
}
|
|
43
|
+
const { fontSize = 10, anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', } = style ?? {};
|
|
44
|
+
const { width, height, box } = (0, sizing_js_1.measureTextSize2)(useText, globals_js_1.defaultFont, fontSize, fontWeight, anchor, vanchor);
|
|
45
|
+
const polygonCoords = [
|
|
46
|
+
[box.x, box.y],
|
|
47
|
+
[box.x2, box.y],
|
|
48
|
+
[box.x2, box.y2],
|
|
49
|
+
[box.x, box.y2],
|
|
50
|
+
[box.x, box.y],
|
|
51
|
+
];
|
|
52
|
+
const polygon = new core_1.default.Polygon(polygonCoords);
|
|
53
|
+
return new Label(id, useText, [x, y], polygon, style, box);
|
|
54
|
+
}
|
|
55
|
+
rotate(angle, origin) {
|
|
56
|
+
const feature = super.rotate(angle, origin);
|
|
57
|
+
return new Label(this.id, this.text, this.anchorPoint, feature, this.style, this.textMeasurementBounds);
|
|
58
|
+
}
|
|
59
|
+
transform(matrix) {
|
|
60
|
+
const feature = super.transform(matrix);
|
|
61
|
+
return new Label(this.id, this.text, this.anchorPoint, feature, this.style, this.textMeasurementBounds);
|
|
62
|
+
}
|
|
63
|
+
getLabelPosition() {
|
|
64
|
+
return this.anchorPoint;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Label = Label;
|
|
68
|
+
class GeometryProp {
|
|
69
|
+
constructor(name, value) {
|
|
70
|
+
this.name = name;
|
|
71
|
+
this.value = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.GeometryProp = GeometryProp;
|
|
75
|
+
class Geometry {
|
|
76
|
+
static point(x, y) {
|
|
77
|
+
return new core_1.default.Point(x, y);
|
|
78
|
+
}
|
|
79
|
+
static line(x1, y1, x2, y2) {
|
|
80
|
+
return new core_1.default.Line(Geometry.point(x1, y1), Geometry.point(x2, y2));
|
|
81
|
+
}
|
|
82
|
+
static label(id, x, y, text, style) {
|
|
83
|
+
return Label.fromPoint(id, x, y, text, style);
|
|
84
|
+
}
|
|
85
|
+
static segment(start, end) {
|
|
86
|
+
return new core_1.default.Segment(Geometry.point(start[0], start[1]), Geometry.point(end[0], end[1]));
|
|
87
|
+
}
|
|
88
|
+
static polygon(coords) {
|
|
89
|
+
return new core_1.default.Polygon(coords);
|
|
90
|
+
}
|
|
91
|
+
static multiline(coords) {
|
|
92
|
+
const segments = [];
|
|
93
|
+
for (let i = 0; i < coords.length - 1; i++) {
|
|
94
|
+
segments.push(new core_1.default.Segment(Geometry.point(coords[i][0], coords[i][1]), Geometry.point(coords[i + 1][0], coords[i + 1][1])));
|
|
95
|
+
}
|
|
96
|
+
return new core_1.default.Multiline(segments);
|
|
97
|
+
}
|
|
98
|
+
static arc(center, radius, startAngle, endAngle, sweepDirection) {
|
|
99
|
+
return new core_1.default.Arc(Geometry.point(center[0], center[1]), radius, startAngle, endAngle, sweepDirection);
|
|
100
|
+
}
|
|
101
|
+
static getCoords(item) {
|
|
102
|
+
const points = item.vertices.map(vertex => {
|
|
103
|
+
return [vertex.x, vertex.y];
|
|
104
|
+
});
|
|
105
|
+
return points;
|
|
106
|
+
}
|
|
107
|
+
static rotateDegs(feature, angleDegrees, center) {
|
|
108
|
+
const angleRads = angleDegrees * Math.PI / 180;
|
|
109
|
+
return feature.rotate(angleRads, Geometry.point(center[0], center[1]));
|
|
110
|
+
}
|
|
111
|
+
static flip(feature, flipX, flipY) {
|
|
112
|
+
const flipMatrix = (new core_1.default.Matrix()).scale(flipX === 0 ? 1 : -1, flipY == 0 ? 1 : -1);
|
|
113
|
+
return feature.transform(flipMatrix);
|
|
114
|
+
}
|
|
115
|
+
static groupRotate(features, angle, center) {
|
|
116
|
+
const angleRads = angle * Math.PI / 180;
|
|
117
|
+
const rotateAboutPoint = Geometry.point(center[0], center[1]);
|
|
118
|
+
return features.map(feature => {
|
|
119
|
+
return feature.rotate(angleRads, rotateAboutPoint);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
static groupFlip(features, flipX, flipY) {
|
|
123
|
+
const flipMatrix = (new core_1.default.Matrix()).scale(flipX === 0 ? 1 : -1, flipY == 0 ? 1 : -1);
|
|
124
|
+
return features.map(feature => {
|
|
125
|
+
return feature.transform(flipMatrix);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
static groupBounds(features) {
|
|
129
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
130
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
131
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
132
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
133
|
+
features.forEach(feature => {
|
|
134
|
+
const box = feature.box;
|
|
135
|
+
if (feature instanceof Label
|
|
136
|
+
&& typeof feature.text === 'string'
|
|
137
|
+
&& feature.text.trim().length === 0) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (box.xmin === undefined) {
|
|
141
|
+
throw "Invalid box!";
|
|
142
|
+
}
|
|
143
|
+
minX = Math.min(minX, box.xmin);
|
|
144
|
+
minY = Math.min(minY, box.ymin);
|
|
145
|
+
maxX = Math.max(maxX, box.xmax);
|
|
146
|
+
maxY = Math.max(maxY, box.ymax);
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
start: [minX, minY],
|
|
150
|
+
end: [maxX, maxY],
|
|
151
|
+
width: maxX - minX,
|
|
152
|
+
height: maxY - minY,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
static getType(feature) {
|
|
156
|
+
if (feature instanceof Label) {
|
|
157
|
+
return 'label';
|
|
158
|
+
}
|
|
159
|
+
else if (feature instanceof core_1.default.Polygon) {
|
|
160
|
+
return 'polygon';
|
|
161
|
+
}
|
|
162
|
+
else if (feature instanceof core_1.default.Segment) {
|
|
163
|
+
return 'segment';
|
|
164
|
+
}
|
|
165
|
+
console.log('unknown type', feature);
|
|
166
|
+
}
|
|
167
|
+
static featuresToPath(items) {
|
|
168
|
+
const paths = [];
|
|
169
|
+
let isClosedPolygon = false;
|
|
170
|
+
items.forEach(item => {
|
|
171
|
+
if (item instanceof Label) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const path = [];
|
|
175
|
+
if (item instanceof core_1.default.Arc) {
|
|
176
|
+
const x = item.center.x;
|
|
177
|
+
const y = item.center.y;
|
|
178
|
+
const radius = item.r;
|
|
179
|
+
let useEndAngle = item.endAngle;
|
|
180
|
+
let extraEnd = '';
|
|
181
|
+
if (item.startAngle === 0 && item.endAngle === Geometry.FullCircleRadians) {
|
|
182
|
+
useEndAngle = 359.9999 * Math.PI / 180;
|
|
183
|
+
isClosedPolygon = true;
|
|
184
|
+
extraEnd = ' Z';
|
|
185
|
+
}
|
|
186
|
+
const startPoint = getArcPointRadians(x, y, radius, item.startAngle);
|
|
187
|
+
const endPoint = getArcPointRadians(x, y, radius, useEndAngle);
|
|
188
|
+
paths.push('M', startPoint[0], startPoint[1], 'A', radius, radius, 0, 1, 1, endPoint[0], endPoint[1], extraEnd);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
const coords = Geometry.getCoords(item);
|
|
192
|
+
if (item instanceof core_1.default.Polygon) {
|
|
193
|
+
isClosedPolygon = true;
|
|
194
|
+
}
|
|
195
|
+
for (let i = 0; i < coords.length; i++) {
|
|
196
|
+
const [x, y] = coords[i];
|
|
197
|
+
const command = (i === 0) ? 'M' : 'L';
|
|
198
|
+
path.push(`${command}`, x, y);
|
|
199
|
+
}
|
|
200
|
+
if (isClosedPolygon) {
|
|
201
|
+
path.push('Z');
|
|
202
|
+
}
|
|
203
|
+
paths.push(...path);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
path: this.roundPathValues(paths),
|
|
208
|
+
isClosedPolygon,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
static roundPathValues(pathItems) {
|
|
212
|
+
return pathItems.map(item => {
|
|
213
|
+
if (typeof item === 'number') {
|
|
214
|
+
return (+item.toFixed(7)).toString();
|
|
215
|
+
}
|
|
216
|
+
return item;
|
|
217
|
+
}).join(" ");
|
|
218
|
+
}
|
|
219
|
+
static angle(dx, dy) {
|
|
220
|
+
const line = new core_1.default.Segment(new core_1.default.Point(0, 0), new core_1.default.Point(dx, dy));
|
|
221
|
+
return line.slope * 180 / Math.PI;
|
|
222
|
+
}
|
|
223
|
+
static getQuadrant(dx, dy) {
|
|
224
|
+
const angle = Geometry.angle(dx, dy);
|
|
225
|
+
return Number(Math.floor(angle / 90));
|
|
226
|
+
}
|
|
227
|
+
static mergeWires(wirePoints) {
|
|
228
|
+
const existingSegments = [];
|
|
229
|
+
wirePoints.forEach(points => {
|
|
230
|
+
const tmpPoints = points.map(pt => {
|
|
231
|
+
return new core_1.default.Point(pt.x, pt.y);
|
|
232
|
+
});
|
|
233
|
+
for (let i = 0; i < tmpPoints.length - 1; i++) {
|
|
234
|
+
const pt1 = tmpPoints[i];
|
|
235
|
+
const pt2 = tmpPoints[i + 1];
|
|
236
|
+
const newSegments = [
|
|
237
|
+
new core_1.default.Segment(pt1, pt2)
|
|
238
|
+
];
|
|
239
|
+
for (let j = 0; j < existingSegments.length; j++) {
|
|
240
|
+
const currentSegment = existingSegments[j];
|
|
241
|
+
for (let k = 0; k < newSegments.length; k++) {
|
|
242
|
+
const newSegment = newSegments[k];
|
|
243
|
+
const segmentsAreSame = newSegment.equalTo(currentSegment) || newSegment.reverse().equalTo(currentSegment);
|
|
244
|
+
if (segmentsAreSame) {
|
|
245
|
+
newSegments.splice(k, 1);
|
|
246
|
+
j = Math.max(0, j - 1);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
const intersectPoints = currentSegment.intersect(newSegment);
|
|
250
|
+
if (intersectPoints.length > 0) {
|
|
251
|
+
const endToEndIntersect = intersectPoints.length === 1 &&
|
|
252
|
+
(currentSegment.end.equalTo(newSegment.start) || currentSegment.end.equalTo(newSegment.end) ||
|
|
253
|
+
currentSegment.start.equalTo(newSegment.start) || currentSegment.start.equalTo(newSegment.end));
|
|
254
|
+
if (endToEndIntersect) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const splitSegments = [];
|
|
258
|
+
intersectPoints.forEach(intersectPoint => {
|
|
259
|
+
const splitResult1 = currentSegment.split(intersectPoint);
|
|
260
|
+
const splitResult2 = newSegment.split(intersectPoint);
|
|
261
|
+
[...splitResult1, ...splitResult2].forEach(segment => {
|
|
262
|
+
if (segment !== null) {
|
|
263
|
+
const matchingSegmentIndex = splitSegments.findIndex(item => {
|
|
264
|
+
return item.equalTo(segment);
|
|
265
|
+
});
|
|
266
|
+
if (matchingSegmentIndex === -1 &&
|
|
267
|
+
!segment.equalTo(currentSegment) && !segment.equalTo(newSegment)) {
|
|
268
|
+
splitSegments.push(segment);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
const splitCurrentSegments = [];
|
|
274
|
+
const splitNewSegments = [];
|
|
275
|
+
splitSegments.forEach(segment => {
|
|
276
|
+
if (currentSegment.contains(segment.start) && currentSegment.contains(segment.end)) {
|
|
277
|
+
splitCurrentSegments.push(segment);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
splitNewSegments.push(segment);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
replaceSegments(existingSegments, j, splitCurrentSegments);
|
|
284
|
+
replaceSegments(newSegments, k, splitNewSegments);
|
|
285
|
+
j = Math.max(0, j - 1);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
newSegments.forEach(segment => {
|
|
290
|
+
existingSegments.push(segment);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
const trackWirePoints = [];
|
|
295
|
+
existingSegments.forEach(segment => {
|
|
296
|
+
trackWirePoints.push([segment.start.x, segment.start.y]);
|
|
297
|
+
trackWirePoints.push([segment.end.x, segment.end.y]);
|
|
298
|
+
});
|
|
299
|
+
const accumPoints = trackWirePoints.reduce((accum, point) => {
|
|
300
|
+
const found = accum.find(item => {
|
|
301
|
+
return item[0] === point[0] && item[1] === point[1];
|
|
302
|
+
});
|
|
303
|
+
if (found) {
|
|
304
|
+
found[2]++;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
accum.push([point[0], point[1], 1]);
|
|
308
|
+
}
|
|
309
|
+
return accum;
|
|
310
|
+
}, []);
|
|
311
|
+
const intersectPoints = accumPoints.reduce((accum, entry) => {
|
|
312
|
+
if (entry[2] > 2) {
|
|
313
|
+
accum.push(entry);
|
|
314
|
+
}
|
|
315
|
+
return accum;
|
|
316
|
+
}, []);
|
|
317
|
+
const segments = existingSegments.map(segment => {
|
|
318
|
+
return [
|
|
319
|
+
[segment.start.x, segment.start.y],
|
|
320
|
+
[segment.end.x, segment.end.y]
|
|
321
|
+
];
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
intersectPoints,
|
|
325
|
+
segments,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
exports.Geometry = Geometry;
|
|
330
|
+
Geometry.FullCircleRadians = 2 * Math.PI;
|
|
331
|
+
function replaceSegments(segments, index, replacedSegments) {
|
|
332
|
+
if (replacedSegments.length > 0) {
|
|
333
|
+
segments.splice(index, 1);
|
|
334
|
+
}
|
|
335
|
+
let counter = 0;
|
|
336
|
+
replacedSegments.forEach(item => {
|
|
337
|
+
if (item !== null) {
|
|
338
|
+
segments.splice(index + counter, 0, item);
|
|
339
|
+
counter++;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
return counter;
|
|
343
|
+
}
|
|
344
|
+
function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
|
|
345
|
+
let coordVectors = [];
|
|
346
|
+
if (hAnchor === HorizontalAlign.Left) {
|
|
347
|
+
if (vAnchor === VerticalAlign.Bottom) {
|
|
348
|
+
coordVectors = [
|
|
349
|
+
[0, 0],
|
|
350
|
+
[0, -1],
|
|
351
|
+
[1, -1],
|
|
352
|
+
[1, 1],
|
|
353
|
+
];
|
|
354
|
+
}
|
|
355
|
+
else if (vAnchor === VerticalAlign.Middle) {
|
|
356
|
+
coordVectors = [
|
|
357
|
+
[0, -0.5],
|
|
358
|
+
[0, 0.5],
|
|
359
|
+
[1, 0.5],
|
|
360
|
+
[1, -0.5],
|
|
361
|
+
];
|
|
362
|
+
}
|
|
363
|
+
else if (vAnchor === VerticalAlign.Top) {
|
|
364
|
+
coordVectors = [
|
|
365
|
+
[0, 0],
|
|
366
|
+
[1, 0],
|
|
367
|
+
[1, 1],
|
|
368
|
+
[0, 1],
|
|
369
|
+
];
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else if (hAnchor === HorizontalAlign.Right) {
|
|
373
|
+
if (vAnchor === VerticalAlign.Bottom) {
|
|
374
|
+
coordVectors = [
|
|
375
|
+
[0, 0],
|
|
376
|
+
[-1, 0],
|
|
377
|
+
[-1, -1],
|
|
378
|
+
[0, -1],
|
|
379
|
+
];
|
|
380
|
+
}
|
|
381
|
+
else if (vAnchor === VerticalAlign.Middle) {
|
|
382
|
+
coordVectors = [
|
|
383
|
+
[0, -0.5],
|
|
384
|
+
[0, 0.5],
|
|
385
|
+
[-1, 0.5],
|
|
386
|
+
[-1, -0.5],
|
|
387
|
+
];
|
|
388
|
+
}
|
|
389
|
+
else if (vAnchor === VerticalAlign.Top) {
|
|
390
|
+
coordVectors = [
|
|
391
|
+
[0, 0],
|
|
392
|
+
[0, 1],
|
|
393
|
+
[-1, 1],
|
|
394
|
+
[-1, 0]
|
|
395
|
+
];
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else if (hAnchor === HorizontalAlign.Middle) {
|
|
399
|
+
if (vAnchor === VerticalAlign.Bottom) {
|
|
400
|
+
coordVectors = [
|
|
401
|
+
[-0.5, 0],
|
|
402
|
+
[-0.5, -1],
|
|
403
|
+
[0.5, -1],
|
|
404
|
+
[0.5, 0]
|
|
405
|
+
];
|
|
406
|
+
}
|
|
407
|
+
else if (vAnchor === VerticalAlign.Middle) {
|
|
408
|
+
coordVectors = [
|
|
409
|
+
[-0.5, 0.5],
|
|
410
|
+
[-0.5, -0.5],
|
|
411
|
+
[0.5, -0.5],
|
|
412
|
+
[0.5, 0.5],
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
else if (vAnchor === VerticalAlign.Top) {
|
|
416
|
+
coordVectors = [
|
|
417
|
+
[0.5, 0],
|
|
418
|
+
[0.5, 1],
|
|
419
|
+
[-0.5, 1],
|
|
420
|
+
[-0.5, 0]
|
|
421
|
+
];
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return coordVectors.map(([vx, vy]) => {
|
|
425
|
+
return [
|
|
426
|
+
x + vx * width,
|
|
427
|
+
y + vy * height
|
|
428
|
+
];
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
var HorizontalAlign;
|
|
432
|
+
(function (HorizontalAlign) {
|
|
433
|
+
HorizontalAlign["Left"] = "left";
|
|
434
|
+
HorizontalAlign["Middle"] = "middle";
|
|
435
|
+
HorizontalAlign["Right"] = "right";
|
|
436
|
+
})(HorizontalAlign || (exports.HorizontalAlign = HorizontalAlign = {}));
|
|
437
|
+
var VerticalAlign;
|
|
438
|
+
(function (VerticalAlign) {
|
|
439
|
+
VerticalAlign["Top"] = "top";
|
|
440
|
+
VerticalAlign["Middle"] = "middle";
|
|
441
|
+
VerticalAlign["Bottom"] = "bottom";
|
|
442
|
+
})(VerticalAlign || (exports.VerticalAlign = VerticalAlign = {}));
|
|
443
|
+
function getArcPointRadians(centerX, centerY, radius, angleRads) {
|
|
444
|
+
const dx = Math.cos(angleRads);
|
|
445
|
+
const dy = Math.sin(angleRads);
|
|
446
|
+
return [
|
|
447
|
+
centerX + dx * radius,
|
|
448
|
+
centerY + dy * radius
|
|
449
|
+
];
|
|
450
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.wireColor = exports.junctionColor = exports.junctionSize = exports.bodyColor = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.portHeight = exports.portWidth = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = void 0;
|
|
4
|
+
var GlobalNames;
|
|
5
|
+
(function (GlobalNames) {
|
|
6
|
+
GlobalNames["__root"] = "__root";
|
|
7
|
+
GlobalNames["gnd"] = "gnd";
|
|
8
|
+
GlobalNames["DefaultResistor"] = "res";
|
|
9
|
+
GlobalNames["DefaultCapacitor"] = "cap";
|
|
10
|
+
GlobalNames["DefaultInductor"] = "ind";
|
|
11
|
+
GlobalNames["symbol"] = "symbol";
|
|
12
|
+
})(GlobalNames || (exports.GlobalNames = GlobalNames = {}));
|
|
13
|
+
exports.NoNetText = 'NO_NET';
|
|
14
|
+
var ParamKeys;
|
|
15
|
+
(function (ParamKeys) {
|
|
16
|
+
ParamKeys["__is_net"] = "__is_net";
|
|
17
|
+
ParamKeys["__is_label"] = "__is_label";
|
|
18
|
+
ParamKeys["priority"] = "priority";
|
|
19
|
+
ParamKeys["net_name"] = "net_name";
|
|
20
|
+
})(ParamKeys || (exports.ParamKeys = ParamKeys = {}));
|
|
21
|
+
var LayoutDirection;
|
|
22
|
+
(function (LayoutDirection) {
|
|
23
|
+
LayoutDirection["RIGHT"] = "RIGHT";
|
|
24
|
+
LayoutDirection["LEFT"] = "LEFT";
|
|
25
|
+
})(LayoutDirection || (exports.LayoutDirection = LayoutDirection = {}));
|
|
26
|
+
var SymbolPinSide;
|
|
27
|
+
(function (SymbolPinSide) {
|
|
28
|
+
SymbolPinSide["Left"] = "left";
|
|
29
|
+
SymbolPinSide["Right"] = "right";
|
|
30
|
+
})(SymbolPinSide || (exports.SymbolPinSide = SymbolPinSide = {}));
|
|
31
|
+
exports.portWidth = 20;
|
|
32
|
+
exports.portHeight = 2;
|
|
33
|
+
exports.defaultFont = 'Open Sans-Regular, Arial';
|
|
34
|
+
exports.defaultFontBold = 'Open Sans-Bold, Arial-Bold, Arial';
|
|
35
|
+
exports.defaultFontSize = 10;
|
|
36
|
+
exports.bodyColor = '#FFFEAF';
|
|
37
|
+
exports.junctionSize = 5;
|
|
38
|
+
exports.junctionColor = 'rgb(0, 132, 0)';
|
|
39
|
+
exports.wireColor = 'rgb(0, 132, 0)';
|
|
40
|
+
var ComponentTypes;
|
|
41
|
+
(function (ComponentTypes) {
|
|
42
|
+
ComponentTypes["gnd"] = "gnd";
|
|
43
|
+
ComponentTypes["net"] = "net";
|
|
44
|
+
ComponentTypes["label"] = "label";
|
|
45
|
+
ComponentTypes["point"] = "point";
|
|
46
|
+
})(ComponentTypes || (exports.ComponentTypes = ComponentTypes = {}));
|
|
47
|
+
var ReferenceTypes;
|
|
48
|
+
(function (ReferenceTypes) {
|
|
49
|
+
ReferenceTypes["function"] = "function";
|
|
50
|
+
ReferenceTypes["value"] = "value";
|
|
51
|
+
ReferenceTypes["variable"] = "variable";
|
|
52
|
+
ReferenceTypes["instance"] = "instance";
|
|
53
|
+
})(ReferenceTypes || (exports.ReferenceTypes = ReferenceTypes = {}));
|
|
54
|
+
var BlockTypes;
|
|
55
|
+
(function (BlockTypes) {
|
|
56
|
+
BlockTypes[BlockTypes["Branch"] = 1] = "Branch";
|
|
57
|
+
BlockTypes[BlockTypes["Join"] = 2] = "Join";
|
|
58
|
+
BlockTypes[BlockTypes["Parallel"] = 3] = "Parallel";
|
|
59
|
+
BlockTypes[BlockTypes["Point"] = 4] = "Point";
|
|
60
|
+
})(BlockTypes || (exports.BlockTypes = BlockTypes = {}));
|