circuitscript 0.0.28 → 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 +383 -103
- package/dist/cjs/execute.js +39 -14
- package/dist/cjs/geometry.js +79 -18
- package/dist/cjs/globals.js +41 -7
- 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 +84 -14
- package/dist/cjs/render.js +22 -15
- 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 +378 -102
- package/dist/esm/execute.mjs +40 -15
- package/dist/esm/geometry.mjs +79 -17
- package/dist/esm/globals.mjs +40 -6
- 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 +85 -15
- package/dist/esm/render.mjs +23 -16
- 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 +24 -6
- package/dist/types/execute.d.ts +5 -4
- package/dist/types/geometry.d.ts +5 -3
- package/dist/types/globals.d.ts +38 -6
- 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 +78 -55
- package/package.json +1 -1
package/dist/cjs/main.js
CHANGED
|
@@ -52,16 +52,22 @@ async function main() {
|
|
|
52
52
|
let scriptData;
|
|
53
53
|
if (args.length > 0 && args[0]) {
|
|
54
54
|
inputFilePath = args[0];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
currentDirectory
|
|
55
|
+
if ((0, fs_1.existsSync)(inputFilePath)) {
|
|
56
|
+
scriptData = (0, fs_1.readFileSync)(inputFilePath, { encoding: 'utf-8' });
|
|
57
|
+
if (currentDirectory === null) {
|
|
58
|
+
currentDirectory = path_1.default.dirname(inputFilePath);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.error("Error: File could not be found");
|
|
63
|
+
return;
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
else if (options.input) {
|
|
61
67
|
scriptData = options.input;
|
|
62
68
|
}
|
|
63
69
|
else {
|
|
64
|
-
console.
|
|
70
|
+
console.error("Error: No input provided");
|
|
65
71
|
return;
|
|
66
72
|
}
|
|
67
73
|
const scriptOptions = {
|
|
@@ -21,8 +21,10 @@ class ClassComponent {
|
|
|
21
21
|
this.followWireOrientationProp = true;
|
|
22
22
|
this.wireOrientationAngle = 0;
|
|
23
23
|
this.useWireOrientationAngle = true;
|
|
24
|
+
this.didSetWireOrientationAngle = false;
|
|
24
25
|
this.styles = {};
|
|
25
26
|
this.assignedRefDes = null;
|
|
27
|
+
this.moduleCounter = 0;
|
|
26
28
|
this.instanceName = instanceName;
|
|
27
29
|
this.numPins = numPins;
|
|
28
30
|
this.className = className;
|
package/dist/cjs/objects/Net.js
CHANGED
|
@@ -16,10 +16,11 @@ class Net {
|
|
|
16
16
|
this.baseName = name;
|
|
17
17
|
}
|
|
18
18
|
toString() {
|
|
19
|
-
return this.name;
|
|
19
|
+
return this.namespace + this.name;
|
|
20
20
|
}
|
|
21
21
|
static isSame(netA, netB) {
|
|
22
|
-
return netA.
|
|
22
|
+
return netA.namespace === netB.namespace &&
|
|
23
|
+
netA.name === netB.name &&
|
|
23
24
|
netA.baseName === netB.baseName &&
|
|
24
25
|
netA.priority === netB.priority &&
|
|
25
26
|
netA.type === netB.type;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PinTypes = void 0;
|
|
3
|
+
exports.AllPinTypes = exports.PinTypes = void 0;
|
|
4
4
|
var PinTypes;
|
|
5
5
|
(function (PinTypes) {
|
|
6
6
|
PinTypes["Any"] = "any";
|
|
@@ -9,3 +9,9 @@ var PinTypes;
|
|
|
9
9
|
PinTypes["IO"] = "io";
|
|
10
10
|
PinTypes["Power"] = "power";
|
|
11
11
|
})(PinTypes || (exports.PinTypes = PinTypes = {}));
|
|
12
|
+
exports.AllPinTypes = [
|
|
13
|
+
PinTypes.Any,
|
|
14
|
+
PinTypes.Input,
|
|
15
|
+
PinTypes.Output,
|
|
16
|
+
PinTypes.IO,
|
|
17
|
+
];
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Direction = exports.ParseSymbolType = exports.UndeclaredReference = void 0;
|
|
3
|
+
exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = void 0;
|
|
4
4
|
class UndeclaredReference {
|
|
5
5
|
constructor(reference) {
|
|
6
6
|
this.reference = reference;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
exports.UndeclaredReference = UndeclaredReference;
|
|
10
|
+
class DeclaredReference {
|
|
11
|
+
constructor(refType) {
|
|
12
|
+
this.found = refType.found;
|
|
13
|
+
this.name = refType.name;
|
|
14
|
+
this.trailers = refType.trailers;
|
|
15
|
+
this.type = refType.type;
|
|
16
|
+
this.value = refType.value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DeclaredReference = DeclaredReference;
|
|
10
20
|
var ParseSymbolType;
|
|
11
21
|
(function (ParseSymbolType) {
|
|
12
22
|
ParseSymbolType["Variable"] = "variable";
|
|
@@ -5,19 +5,89 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const helpers_js_1 = require("./helpers.js");
|
|
8
|
+
const sizing_js_1 = require("./sizing.js");
|
|
8
9
|
const mainDir = './__tests__/renderData/';
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const fontsPath = (0, helpers_js_1.getFontsPath)();
|
|
11
|
+
const defaultLibsPath = (0, helpers_js_1.getDefaultLibsPath)();
|
|
12
|
+
async function regenerateTests(extra = "") {
|
|
13
|
+
await (0, sizing_js_1.prepareSVGEnvironment)(fontsPath);
|
|
14
|
+
const cstFiles = [];
|
|
15
|
+
const files = fs_1.default.readdirSync(mainDir);
|
|
16
|
+
files.forEach(file => {
|
|
17
|
+
if (file.endsWith('.cst')) {
|
|
18
|
+
cstFiles.push(file);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
cstFiles.forEach(file => {
|
|
22
|
+
const inputPath = mainDir + file;
|
|
23
|
+
const scriptData = fs_1.default.readFileSync(inputPath, { encoding: 'utf-8' });
|
|
24
|
+
const outputPath = mainDir + 'svgs/' + file + extra + '.svg';
|
|
25
|
+
(0, helpers_js_1.renderScript)(scriptData, outputPath, {
|
|
26
|
+
currentDirectory: mainDir,
|
|
27
|
+
defaultLibsPath,
|
|
28
|
+
});
|
|
29
|
+
console.log('generated ', outputPath);
|
|
30
|
+
});
|
|
31
|
+
return cstFiles;
|
|
32
|
+
}
|
|
33
|
+
(async () => {
|
|
34
|
+
const generateDiff = false;
|
|
35
|
+
const nextExtra = generateDiff ? '.next' : '';
|
|
36
|
+
const cstFiles = await regenerateTests(nextExtra);
|
|
37
|
+
const allFiles = [];
|
|
38
|
+
if (generateDiff) {
|
|
39
|
+
cstFiles.forEach(file => {
|
|
40
|
+
const svg1 = 'svgs/' + file + '.svg';
|
|
41
|
+
const svg2 = 'svgs/' + file + '.next.svg';
|
|
42
|
+
const cleanedName = file.replace('script', '').replace('.cst', '');
|
|
43
|
+
allFiles.push([file, svg1, svg2, cleanedName]);
|
|
44
|
+
});
|
|
45
|
+
const sortedFiles = allFiles.sort((a, b) => {
|
|
46
|
+
const nameA = a[3];
|
|
47
|
+
const nameB = b[3];
|
|
48
|
+
const indexA = Number(nameA);
|
|
49
|
+
const indexB = Number(nameB);
|
|
50
|
+
if (indexA > indexB) {
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
else if (indexA < indexB) {
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const output = [];
|
|
61
|
+
sortedFiles.forEach(group => {
|
|
62
|
+
const [file, svg1, svg2] = group;
|
|
63
|
+
output.push(`<div class='group'>
|
|
64
|
+
<h3>${file}</h3>
|
|
65
|
+
<div class='items'>
|
|
66
|
+
<div style='margin-right: 10px'>
|
|
67
|
+
<h4>${svg1}</h4>
|
|
68
|
+
<img src='${svg1}'/>
|
|
69
|
+
</div>
|
|
70
|
+
<div>
|
|
71
|
+
<h4>${svg2}</h4>
|
|
72
|
+
<img src='${svg2}'/>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>`);
|
|
76
|
+
});
|
|
77
|
+
const result = `
|
|
78
|
+
<html>
|
|
79
|
+
<header>
|
|
80
|
+
<title>SVG compare</title>
|
|
81
|
+
<style>
|
|
82
|
+
img { border: solid thin #ccc; }
|
|
83
|
+
.items { display: flex; }
|
|
84
|
+
body { font-family: Arial; }
|
|
85
|
+
</style>
|
|
86
|
+
</header>
|
|
87
|
+
<body>
|
|
88
|
+
${output.join('')}
|
|
89
|
+
</body>
|
|
90
|
+
</html>`;
|
|
91
|
+
fs_1.default.writeFileSync(mainDir + "compiled.html", result);
|
|
14
92
|
}
|
|
15
|
-
});
|
|
16
|
-
const useCurrentDir = './examples/';
|
|
17
|
-
cstFiles.forEach(file => {
|
|
18
|
-
const inputPath = mainDir + file;
|
|
19
|
-
const scriptData = fs_1.default.readFileSync(inputPath, { encoding: 'utf-8' });
|
|
20
|
-
const outputPath = inputPath + '.svg';
|
|
21
|
-
(0, helpers_js_1.renderScript)(scriptData, outputPath, { currentDirectory: useCurrentDir });
|
|
22
|
-
console.log('generated ', outputPath);
|
|
23
|
-
});
|
|
93
|
+
})();
|
package/dist/cjs/render.js
CHANGED
|
@@ -7,6 +7,7 @@ const sizing_js_1 = require("./sizing.js");
|
|
|
7
7
|
const globals_js_1 = require("./globals.js");
|
|
8
8
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
9
9
|
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const helpers_js_1 = require("./helpers.js");
|
|
10
11
|
function generateSVG2(graph) {
|
|
11
12
|
const window = (0, sizing_js_1.getCreateSVGWindow)()();
|
|
12
13
|
const document = window.document;
|
|
@@ -15,10 +16,10 @@ function generateSVG2(graph) {
|
|
|
15
16
|
(0, sizing_js_1.applyFontsToSVG)(canvas);
|
|
16
17
|
generateSVGChild(canvas, graph.components, graph.wires, graph.junctions, graph.mergedWires, graph.frameObjects, graph.textObjects);
|
|
17
18
|
const { x, y, width, height } = canvas.bbox();
|
|
18
|
-
const margin =
|
|
19
|
+
const margin = (0, helpers_js_1.milsToMM)(10);
|
|
19
20
|
const widthAndMargin = width + margin * 2;
|
|
20
21
|
const heightAndMargin = height + margin * 2;
|
|
21
|
-
const scale =
|
|
22
|
+
const scale = globals_js_1.MMToPx * globals_js_1.defaultZoomScale;
|
|
22
23
|
canvas.size(widthAndMargin * scale, heightAndMargin * scale);
|
|
23
24
|
canvas.viewbox(x - margin, y - margin, widthAndMargin, heightAndMargin);
|
|
24
25
|
return canvas.svg();
|
|
@@ -61,7 +62,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
63
64
|
symbolGroup.rect(width, height)
|
|
64
|
-
.fill(globals_js_1.
|
|
65
|
+
.fill(globals_js_1.ColorScheme.BodyColor)
|
|
65
66
|
.stroke({ width: 1, color: '#333' });
|
|
66
67
|
}
|
|
67
68
|
});
|
|
@@ -83,14 +84,18 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
83
84
|
const pt1 = segment[0];
|
|
84
85
|
const pt2 = segment[1];
|
|
85
86
|
mergedWireGroup.line([pt1, pt2])
|
|
86
|
-
.stroke({
|
|
87
|
+
.stroke({
|
|
88
|
+
width: globals_js_1.defaultWireLineWidth,
|
|
89
|
+
color: globals_js_1.ColorScheme.WireColor,
|
|
90
|
+
linecap: 'square'
|
|
91
|
+
})
|
|
87
92
|
.fill('none');
|
|
88
93
|
});
|
|
89
94
|
intersectPoints.forEach(point => {
|
|
90
95
|
const [x, y, count] = point;
|
|
91
96
|
mergedWireGroup.circle(globals_js_1.junctionSize)
|
|
92
97
|
.translate(x - globals_js_1.junctionSize / 2, y - globals_js_1.junctionSize / 2)
|
|
93
|
-
.fill(globals_js_1.
|
|
98
|
+
.fill(globals_js_1.ColorScheme.JunctionColor)
|
|
94
99
|
.stroke('none');
|
|
95
100
|
});
|
|
96
101
|
});
|
|
@@ -112,7 +117,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
112
117
|
}
|
|
113
118
|
const tmpRect = frameGroup.rect(width, height)
|
|
114
119
|
.fill('none')
|
|
115
|
-
.stroke({ width: borderWidth, color: strokeColor });
|
|
120
|
+
.stroke({ width: (0, helpers_js_1.milsToMM)(borderWidth), color: strokeColor });
|
|
116
121
|
tmpRect.translate(item.x, item.y);
|
|
117
122
|
}
|
|
118
123
|
});
|
|
@@ -123,13 +128,14 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
123
128
|
symbol.draw(innerGroup);
|
|
124
129
|
});
|
|
125
130
|
const drawOrigin = false;
|
|
131
|
+
const originSize = (0, helpers_js_1.milsToMM)(10);
|
|
126
132
|
drawOrigin && canvas.group().translate(0, 0)
|
|
127
|
-
.circle(
|
|
128
|
-
.translate(-
|
|
133
|
+
.circle(originSize)
|
|
134
|
+
.translate(-originSize / 2, -originSize / 2)
|
|
129
135
|
.stroke('none').fill('red');
|
|
130
136
|
}
|
|
131
137
|
function drawGrid(group, canvasSize) {
|
|
132
|
-
const gridSize =
|
|
138
|
+
const gridSize = globals_js_1.defaultGridSizeUnits;
|
|
133
139
|
const { x, y, x2, y2 } = canvasSize;
|
|
134
140
|
const gridStartX = (Math.floor(x / gridSize) - 1) * gridSize;
|
|
135
141
|
const gridStartY = (Math.floor(y / gridSize) - 1) * gridSize;
|
|
@@ -137,19 +143,20 @@ function drawGrid(group, canvasSize) {
|
|
|
137
143
|
const gridEndY = (Math.ceil(y2 / gridSize) + 1) * gridSize;
|
|
138
144
|
const numCols = Math.ceil((gridEndX - gridStartX) / gridSize);
|
|
139
145
|
const lines = [];
|
|
146
|
+
const smallOffset = (0, helpers_js_1.milsToMM)(3);
|
|
147
|
+
const startY = gridStartY - smallOffset / 2;
|
|
148
|
+
const endY = gridEndY + smallOffset;
|
|
140
149
|
for (let i = 0; i <= numCols; i++) {
|
|
141
150
|
const startX = gridStartX + i * gridSize;
|
|
142
|
-
const startY = gridStartY - 0.5;
|
|
143
|
-
const endY = gridEndY;
|
|
144
151
|
lines.push(`M ${startX} ${startY} L ${startX} ${endY}`);
|
|
145
152
|
}
|
|
153
|
+
const strokeSize = (0, helpers_js_1.milsToMM)(3);
|
|
146
154
|
group.path(lines.join(" "))
|
|
147
|
-
.fill('none')
|
|
148
155
|
.attr({
|
|
149
|
-
'stroke-dasharray':
|
|
156
|
+
'stroke-dasharray': `${strokeSize},${gridSize - strokeSize}`,
|
|
150
157
|
})
|
|
151
158
|
.stroke({
|
|
152
|
-
width:
|
|
153
|
-
color: '#
|
|
159
|
+
width: strokeSize,
|
|
160
|
+
color: '#000'
|
|
154
161
|
});
|
|
155
162
|
}
|
package/dist/cjs/sizing.js
CHANGED
|
@@ -23,13 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.measureTextSize2 = exports.
|
|
26
|
+
exports.measureTextSize2 = exports.applyFontsToSVG = exports.getCreateSVGWindow = exports.prepareSVGEnvironment = void 0;
|
|
27
27
|
const svg_js_1 = require("@svgdotjs/svg.js");
|
|
28
28
|
const geometry_js_1 = require("./geometry.js");
|
|
29
29
|
const globals_js_1 = require("./globals.js");
|
|
30
30
|
const helpers_js_1 = require("./helpers.js");
|
|
31
31
|
let MainCanvas = null;
|
|
32
|
-
const supportedFonts = {
|
|
32
|
+
const supportedFonts = {
|
|
33
|
+
'Arial': 'Arial.ttf',
|
|
34
|
+
};
|
|
33
35
|
let globalCreateSVGWindow;
|
|
34
36
|
async function prepareSVGEnvironment(fontsPath) {
|
|
35
37
|
const moduleType = (0, helpers_js_1.detectJSModuleType)();
|
|
@@ -54,10 +56,6 @@ exports.getCreateSVGWindow = getCreateSVGWindow;
|
|
|
54
56
|
function applyFontsToSVG(canvas) {
|
|
55
57
|
}
|
|
56
58
|
exports.applyFontsToSVG = applyFontsToSVG;
|
|
57
|
-
async function measureTextSize(text, fontFamily, fontSize) {
|
|
58
|
-
return measureTextSize2(text, fontFamily, fontSize);
|
|
59
|
-
}
|
|
60
|
-
exports.measureTextSize = measureTextSize;
|
|
61
59
|
const measureTextSizeCache = {};
|
|
62
60
|
const measureTextSizeCacheHits = {};
|
|
63
61
|
function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regular', anchor = geometry_js_1.HorizontalAlign.Left, vanchor = geometry_js_1.VerticalAlign.Bottom) {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
3
|
+
exports.roundValue = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
4
4
|
class SimpleStopwatch {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.startTime = new Date();
|
|
@@ -28,11 +28,17 @@ function printBounds(bounds) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.printBounds = printBounds;
|
|
31
|
+
function hasRemainder(value, value2) {
|
|
32
|
+
const tmpValue = Math.abs(value) / value2;
|
|
33
|
+
const flooredValue = Math.floor(tmpValue);
|
|
34
|
+
const diff = tmpValue - flooredValue;
|
|
35
|
+
return diff;
|
|
36
|
+
}
|
|
31
37
|
function resizeToNearestGrid(bounds, gridSize = 20) {
|
|
32
|
-
const addXMin = (bounds.xmin
|
|
33
|
-
const addYMin = (bounds.ymin
|
|
34
|
-
const addXMax = (bounds.xmax
|
|
35
|
-
const addYMax = (bounds.ymax
|
|
38
|
+
const addXMin = hasRemainder(bounds.xmin, gridSize) === 0 ? -1 : 0;
|
|
39
|
+
const addYMin = hasRemainder(bounds.ymin, gridSize) === 0 ? -1 : 0;
|
|
40
|
+
const addXMax = hasRemainder(bounds.xmax, gridSize) === 0 ? 1 : 0;
|
|
41
|
+
const addYMax = hasRemainder(bounds.ymax, gridSize) === 0 ? 1 : 0;
|
|
36
42
|
return {
|
|
37
43
|
xmin: Math.floor((bounds.xmin + addXMin) / gridSize) * gridSize,
|
|
38
44
|
ymin: Math.floor((bounds.ymin + addYMin) / gridSize) * gridSize,
|
|
@@ -52,3 +58,21 @@ function getBoundsSize(bounds) {
|
|
|
52
58
|
};
|
|
53
59
|
}
|
|
54
60
|
exports.getBoundsSize = getBoundsSize;
|
|
61
|
+
function getPortType(component) {
|
|
62
|
+
const drawingCommands = component.displayProp;
|
|
63
|
+
let foundPinType = null;
|
|
64
|
+
const commands = drawingCommands.getCommands();
|
|
65
|
+
commands.some(item => {
|
|
66
|
+
if (item[0] === 'label' && item[2].has('portType')) {
|
|
67
|
+
foundPinType = item[2].get('portType');
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
});
|
|
72
|
+
return foundPinType;
|
|
73
|
+
}
|
|
74
|
+
exports.getPortType = getPortType;
|
|
75
|
+
function roundValue(value) {
|
|
76
|
+
return +value.toFixed(7);
|
|
77
|
+
}
|
|
78
|
+
exports.roundValue = roundValue;
|