circuitscript 0.0.38 → 0.1.2
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 +69 -46
- package/dist/cjs/SymbolValidatorVisitor.js +1 -1
- package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
- package/dist/cjs/antlr/CircuitScriptParser.js +580 -613
- package/dist/cjs/builtinMethods.js +32 -10
- package/dist/cjs/draw_symbols.js +375 -233
- package/dist/cjs/execute.js +142 -131
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +14 -9
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +143 -151
- package/dist/cjs/logger.js +8 -1
- package/dist/cjs/objects/ClassComponent.js +22 -22
- package/dist/cjs/objects/ExecutionScope.js +10 -4
- package/dist/cjs/objects/Frame.js +4 -1
- package/dist/cjs/objects/ParamDefinition.js +120 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/objects/types.js +41 -0
- package/dist/cjs/render.js +41 -110
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +92 -2
- package/dist/cjs/visitor.js +279 -284
- package/dist/esm/BaseVisitor.mjs +70 -47
- package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
- package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
- package/dist/esm/antlr/CircuitScriptParser.mjs +580 -613
- package/dist/esm/builtinMethods.mjs +29 -10
- package/dist/esm/draw_symbols.mjs +381 -238
- package/dist/esm/execute.mjs +144 -133
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +13 -8
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +144 -153
- package/dist/esm/logger.mjs +8 -1
- package/dist/esm/objects/ClassComponent.mjs +21 -26
- package/dist/esm/objects/ExecutionScope.mjs +10 -4
- package/dist/esm/objects/Frame.mjs +4 -1
- package/dist/esm/objects/ParamDefinition.mjs +119 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/objects/types.mjs +42 -0
- package/dist/esm/render.mjs +44 -113
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +86 -1
- package/dist/esm/visitor.mjs +281 -286
- package/dist/types/BaseVisitor.d.ts +3 -2
- package/dist/types/antlr/CircuitScriptParser.d.ts +5 -3
- package/dist/types/draw_symbols.d.ts +81 -49
- package/dist/types/execute.d.ts +16 -11
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +15 -10
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +22 -21
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +19 -16
- package/dist/types/objects/ExecutionScope.d.ts +2 -1
- package/dist/types/objects/Frame.d.ts +5 -3
- package/dist/types/objects/ParamDefinition.d.ts +31 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/objects/types.d.ts +7 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +9 -1
- package/dist/types/visitor.d.ts +5 -5
- package/libs/lib.cst +102 -32
- package/package.json +7 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SymbolDrawingCommands } from '../draw_symbols.mjs';
|
|
2
2
|
import { PinDefinition, PinIdType } from './PinDefinition.mjs';
|
|
3
3
|
import { PinTypes } from './PinTypes.mjs';
|
|
4
|
+
import { ParamKeys } from '../globals.mjs';
|
|
4
5
|
export class ClassComponent {
|
|
5
6
|
instanceName;
|
|
6
7
|
numPins;
|
|
@@ -8,14 +9,15 @@ export class ClassComponent {
|
|
|
8
9
|
pins = new Map();
|
|
9
10
|
pinNets = new Map();
|
|
10
11
|
pinWires = new Map();
|
|
12
|
+
pinsMaxPositions = {};
|
|
11
13
|
_cachedPins;
|
|
12
14
|
_cachedParams;
|
|
13
|
-
className;
|
|
14
15
|
_copyID = null;
|
|
15
16
|
_copyFrom = null;
|
|
16
17
|
arrangeProps = null;
|
|
17
18
|
displayProp = null;
|
|
18
19
|
widthProp = null;
|
|
20
|
+
heightProp = null;
|
|
19
21
|
typeProp = null;
|
|
20
22
|
copyProp = false;
|
|
21
23
|
angleProp = 0;
|
|
@@ -23,17 +25,10 @@ export class ClassComponent {
|
|
|
23
25
|
wireOrientationAngle = 0;
|
|
24
26
|
useWireOrientationAngle = true;
|
|
25
27
|
didSetWireOrientationAngle = false;
|
|
26
|
-
styles = {};
|
|
27
28
|
assignedRefDes = null;
|
|
28
|
-
|
|
29
|
-
moduleCounter = 0;
|
|
30
|
-
moduleExecutionContext;
|
|
31
|
-
moduleExecutionContextName;
|
|
32
|
-
modulePinIdToPortMap;
|
|
33
|
-
constructor(instanceName, numPins, className) {
|
|
29
|
+
constructor(instanceName, numPins) {
|
|
34
30
|
this.instanceName = instanceName;
|
|
35
31
|
this.numPins = numPins;
|
|
36
|
-
this.className = className;
|
|
37
32
|
}
|
|
38
33
|
setupPins() {
|
|
39
34
|
for (let i = 1; i < this.numPins + 1; i++) {
|
|
@@ -110,25 +105,26 @@ export class ClassComponent {
|
|
|
110
105
|
toString() {
|
|
111
106
|
return this.instanceName;
|
|
112
107
|
}
|
|
113
|
-
static simple(instanceName, numPins
|
|
114
|
-
const component = new ClassComponent(instanceName, numPins
|
|
108
|
+
static simple(instanceName, numPins) {
|
|
109
|
+
const component = new ClassComponent(instanceName, numPins);
|
|
115
110
|
component.setupPins();
|
|
116
111
|
return component;
|
|
117
112
|
}
|
|
118
113
|
isEqual(other) {
|
|
119
114
|
return this.instanceName === other.instanceName
|
|
120
115
|
&& this.numPins === other.numPins
|
|
121
|
-
&& this.className === other.className
|
|
122
116
|
&& this._copyID === other._copyID
|
|
123
117
|
&& this.arrangeProps === other.arrangeProps
|
|
124
|
-
&& this.displayProp === other.displayProp
|
|
118
|
+
&& ((this.displayProp === null && other.displayProp === null)
|
|
119
|
+
||
|
|
120
|
+
(this.displayProp !== null && other.displayProp !== null && this.displayProp.eq(other.displayProp)))
|
|
125
121
|
&& this.widthProp === other.widthProp
|
|
126
122
|
&& this.typeProp === other.typeProp
|
|
127
123
|
&& this._cachedPins === other._cachedPins
|
|
128
124
|
&& this._cachedParams === other._cachedParams;
|
|
129
125
|
}
|
|
130
126
|
clone() {
|
|
131
|
-
const component = new ClassComponent(this.instanceName, this.numPins
|
|
127
|
+
const component = new ClassComponent(this.instanceName, this.numPins);
|
|
132
128
|
component._copyID = this._copyID;
|
|
133
129
|
component.arrangeProps = this.arrangeProps;
|
|
134
130
|
component.widthProp = this.widthProp;
|
|
@@ -136,17 +132,12 @@ export class ClassComponent {
|
|
|
136
132
|
component.angleProp = this.angleProp;
|
|
137
133
|
component.followWireOrientationProp = this.followWireOrientationProp;
|
|
138
134
|
component.useWireOrientationAngle = this.useWireOrientationAngle;
|
|
139
|
-
if (this.displayProp) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
else if (this.displayProp instanceof SymbolDrawingCommands) {
|
|
144
|
-
component.displayProp =
|
|
145
|
-
this.displayProp.clone();
|
|
146
|
-
}
|
|
135
|
+
if (this.displayProp instanceof SymbolDrawingCommands) {
|
|
136
|
+
component.displayProp =
|
|
137
|
+
this.displayProp.clone();
|
|
147
138
|
}
|
|
148
139
|
for (const [key, value] of this.parameters) {
|
|
149
|
-
if (key ===
|
|
140
|
+
if (key === ParamKeys.flipX || key === ParamKeys.flipY || key === ParamKeys.angle) {
|
|
150
141
|
continue;
|
|
151
142
|
}
|
|
152
143
|
component.parameters.set(key, value);
|
|
@@ -154,10 +145,14 @@ export class ClassComponent {
|
|
|
154
145
|
for (const [key, value] of this.pins) {
|
|
155
146
|
component.pins.set(key, value);
|
|
156
147
|
}
|
|
157
|
-
for (const key in this.styles) {
|
|
158
|
-
component.styles[key] = this.styles[key];
|
|
159
|
-
}
|
|
160
148
|
component.refreshCache();
|
|
161
149
|
return component;
|
|
162
150
|
}
|
|
163
151
|
}
|
|
152
|
+
export class ModuleComponent extends ClassComponent {
|
|
153
|
+
moduleContainsExpressions;
|
|
154
|
+
moduleCounter = 0;
|
|
155
|
+
moduleExecutionContext;
|
|
156
|
+
moduleExecutionContextName;
|
|
157
|
+
modulePinIdToPortMap;
|
|
158
|
+
}
|
|
@@ -46,10 +46,7 @@ export class ExecutionScope {
|
|
|
46
46
|
}
|
|
47
47
|
getNet(component, pin) {
|
|
48
48
|
const result = this.findNet(component, pin);
|
|
49
|
-
|
|
50
|
-
return result[2];
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
49
|
+
return result ? result[2] : null;
|
|
53
50
|
}
|
|
54
51
|
setNet(component, pin, net) {
|
|
55
52
|
const pair = this.findNet(component, pin);
|
|
@@ -112,6 +109,15 @@ export class ExecutionScope {
|
|
|
112
109
|
this.currentWireId = -1;
|
|
113
110
|
this.currentFrameId = -1;
|
|
114
111
|
}
|
|
112
|
+
setCurrent(component, pin = null) {
|
|
113
|
+
this.currentComponent = component;
|
|
114
|
+
if (component !== null) {
|
|
115
|
+
this.currentPin = (pin === null) ? component.getDefaultPin() : pin;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.currentPin = null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
115
121
|
}
|
|
116
122
|
export var SequenceAction;
|
|
117
123
|
(function (SequenceAction) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { FrameType } from "../globals.mjs";
|
|
1
2
|
export class Frame {
|
|
2
3
|
parameters = new Map();
|
|
3
4
|
frameId;
|
|
4
5
|
frameType;
|
|
5
|
-
constructor(frameId, frameType) {
|
|
6
|
+
constructor(frameId, frameType = FrameType.Frame) {
|
|
6
7
|
this.frameId = frameId;
|
|
7
8
|
this.frameType = frameType;
|
|
8
9
|
}
|
|
@@ -17,6 +18,8 @@ export var FrameParamKeys;
|
|
|
17
18
|
FrameParamKeys["Height"] = "height";
|
|
18
19
|
FrameParamKeys["PaperSize"] = "paper_size";
|
|
19
20
|
FrameParamKeys["SheetType"] = "sheet_type";
|
|
21
|
+
FrameParamKeys["SheetNumber"] = "sheet_number";
|
|
22
|
+
FrameParamKeys["SheetTotal"] = "sheet_total";
|
|
20
23
|
})(FrameParamKeys || (FrameParamKeys = {}));
|
|
21
24
|
export var FramePlotDirection;
|
|
22
25
|
(function (FramePlotDirection) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getNumberExponential, getNumberExponentialText, resolveToNumericValue } from "../utils";
|
|
2
|
+
import { Big } from 'big.js';
|
|
1
3
|
export class ParamDefinition {
|
|
2
4
|
paramName;
|
|
3
5
|
paramValue;
|
|
@@ -8,8 +10,26 @@ export class ParamDefinition {
|
|
|
8
10
|
}
|
|
9
11
|
export class NumericValue {
|
|
10
12
|
value;
|
|
11
|
-
|
|
13
|
+
valuePart;
|
|
14
|
+
prefixPart;
|
|
15
|
+
constructor(value, prefix = 0) {
|
|
12
16
|
this.value = value;
|
|
17
|
+
if (typeof value === 'string') {
|
|
18
|
+
const matches = value.match(/^([\d]+(?:.[\d]+)?)([\w]*)$/);
|
|
19
|
+
if (matches) {
|
|
20
|
+
this.valuePart = new Big(matches[1]);
|
|
21
|
+
this.prefixPart = getNumberExponential(matches[2]);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error("Invalid numeric value: " + value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.valuePart = new Big(value);
|
|
29
|
+
this.prefixPart = prefix;
|
|
30
|
+
this.value = this.valuePart.toString()
|
|
31
|
+
+ getNumberExponentialText(prefix);
|
|
32
|
+
}
|
|
13
33
|
}
|
|
14
34
|
toString() {
|
|
15
35
|
return 'numeric:' + this.value;
|
|
@@ -18,11 +38,57 @@ export class NumericValue {
|
|
|
18
38
|
if (typeof this.value === 'number') {
|
|
19
39
|
return this.value.toString();
|
|
20
40
|
}
|
|
21
|
-
else
|
|
22
|
-
return this.
|
|
41
|
+
else {
|
|
42
|
+
return this.valuePart.toString()
|
|
43
|
+
+ getNumberExponentialText(this.prefixPart);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
toNumber() {
|
|
47
|
+
return this.toBigNumber().toNumber();
|
|
48
|
+
}
|
|
49
|
+
toBigNumber() {
|
|
50
|
+
return this.valuePart.mul(new Big(Math.pow(10, this.prefixPart)));
|
|
51
|
+
}
|
|
52
|
+
div(value) {
|
|
53
|
+
if (typeof value === 'number') {
|
|
54
|
+
value = numeric(value);
|
|
55
|
+
}
|
|
56
|
+
return resolveToNumericValue(this.toBigNumber().div(value.toBigNumber()));
|
|
57
|
+
}
|
|
58
|
+
mul(value) {
|
|
59
|
+
if (typeof value === 'number') {
|
|
60
|
+
value = numeric(value);
|
|
23
61
|
}
|
|
62
|
+
return resolveToNumericValue(this.toBigNumber().mul(value.toBigNumber()));
|
|
63
|
+
}
|
|
64
|
+
add(value) {
|
|
65
|
+
if (typeof value === 'number') {
|
|
66
|
+
value = numeric(value);
|
|
67
|
+
}
|
|
68
|
+
return resolveToNumericValue(this.toBigNumber().add(value.toBigNumber()));
|
|
69
|
+
}
|
|
70
|
+
sub(value) {
|
|
71
|
+
if (typeof value === 'number') {
|
|
72
|
+
value = numeric(value);
|
|
73
|
+
}
|
|
74
|
+
return resolveToNumericValue(this.toBigNumber().sub(value.toBigNumber()));
|
|
75
|
+
}
|
|
76
|
+
mod(value) {
|
|
77
|
+
if (typeof value === 'number') {
|
|
78
|
+
value = numeric(value);
|
|
79
|
+
}
|
|
80
|
+
return resolveToNumericValue(this.toBigNumber().mod(value.toBigNumber()));
|
|
81
|
+
}
|
|
82
|
+
neg() {
|
|
83
|
+
return resolveToNumericValue(this.toBigNumber().neg());
|
|
84
|
+
}
|
|
85
|
+
eq(value) {
|
|
86
|
+
return this.toBigNumber().eq(value.toBigNumber());
|
|
24
87
|
}
|
|
25
88
|
}
|
|
89
|
+
export function numeric(value) {
|
|
90
|
+
return new NumericValue(value);
|
|
91
|
+
}
|
|
26
92
|
export class PercentageValue {
|
|
27
93
|
value;
|
|
28
94
|
constructor(value) {
|
|
@@ -31,4 +97,54 @@ export class PercentageValue {
|
|
|
31
97
|
toString() {
|
|
32
98
|
return this.value.toString();
|
|
33
99
|
}
|
|
100
|
+
toNumber() {
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export class WrappedNumber {
|
|
105
|
+
value;
|
|
106
|
+
constructor(value) {
|
|
107
|
+
this.value = value;
|
|
108
|
+
}
|
|
109
|
+
toString() {
|
|
110
|
+
return this.value.toString();
|
|
111
|
+
}
|
|
112
|
+
toNumber() {
|
|
113
|
+
return this.value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export class NumberOperator {
|
|
117
|
+
prepare(value) {
|
|
118
|
+
if (typeof value === 'number') {
|
|
119
|
+
return new WrappedNumber(value);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
multiply(value1, value2) {
|
|
126
|
+
const big1 = new Big(value1.toNumber());
|
|
127
|
+
const big2 = new Big(value2.toNumber());
|
|
128
|
+
return resolveToNumericValue(big1.mul(big2));
|
|
129
|
+
}
|
|
130
|
+
divide(value1, value2) {
|
|
131
|
+
const big1 = new Big(value1.toNumber());
|
|
132
|
+
const big2 = new Big(value2.toNumber());
|
|
133
|
+
return resolveToNumericValue(big1.div(big2));
|
|
134
|
+
}
|
|
135
|
+
addition(value1, value2) {
|
|
136
|
+
const big1 = new Big(value1.toNumber());
|
|
137
|
+
const big2 = new Big(value2.toNumber());
|
|
138
|
+
return resolveToNumericValue(big1.add(big2));
|
|
139
|
+
}
|
|
140
|
+
subtraction(value1, value2) {
|
|
141
|
+
const big1 = new Big(value1.toNumber());
|
|
142
|
+
const big2 = new Big(value2.toNumber());
|
|
143
|
+
return resolveToNumericValue(big1.sub(big2));
|
|
144
|
+
}
|
|
145
|
+
modulus(value1, value2) {
|
|
146
|
+
const big1 = new Big(value1.toNumber());
|
|
147
|
+
const big2 = new Big(value2.toNumber());
|
|
148
|
+
return resolveToNumericValue(big1.mod(big2));
|
|
149
|
+
}
|
|
34
150
|
}
|
|
@@ -6,6 +6,17 @@ export class UndeclaredReference {
|
|
|
6
6
|
throwMessage() {
|
|
7
7
|
return `Unknown symbol: ${this.reference.name}`;
|
|
8
8
|
}
|
|
9
|
+
toString() {
|
|
10
|
+
return 'undefined';
|
|
11
|
+
}
|
|
12
|
+
nameString() {
|
|
13
|
+
const { name, trailers = [] } = this.reference;
|
|
14
|
+
let extra = '';
|
|
15
|
+
if (trailers.length > 0) {
|
|
16
|
+
extra = '.' + trailers.join('.');
|
|
17
|
+
}
|
|
18
|
+
return name + extra;
|
|
19
|
+
}
|
|
9
20
|
}
|
|
10
21
|
export class DeclaredReference {
|
|
11
22
|
found;
|
|
@@ -13,16 +24,47 @@ export class DeclaredReference {
|
|
|
13
24
|
trailers;
|
|
14
25
|
type;
|
|
15
26
|
value;
|
|
27
|
+
parentValue;
|
|
16
28
|
constructor(refType) {
|
|
17
29
|
this.found = refType.found;
|
|
18
30
|
this.name = refType.name;
|
|
19
31
|
this.trailers = refType.trailers;
|
|
20
32
|
this.type = refType.type;
|
|
21
33
|
this.value = refType.value;
|
|
34
|
+
this.parentValue = refType.parentValue;
|
|
22
35
|
}
|
|
23
36
|
toString() {
|
|
24
37
|
return `[DeclaredReference name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
|
|
25
38
|
}
|
|
39
|
+
toDisplayString() {
|
|
40
|
+
let returnValue = undefined;
|
|
41
|
+
if (this.parentValue) {
|
|
42
|
+
const trailersString = this.trailers.join(".");
|
|
43
|
+
if (this.type === 'instance') {
|
|
44
|
+
returnValue = this.parentValue.parameters.get(trailersString);
|
|
45
|
+
}
|
|
46
|
+
else if (this.type === 'variable') {
|
|
47
|
+
returnValue = this.parentValue[trailersString];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
returnValue = this.value;
|
|
52
|
+
}
|
|
53
|
+
if (returnValue !== undefined) {
|
|
54
|
+
if (returnValue !== null) {
|
|
55
|
+
if (returnValue.toDisplayString) {
|
|
56
|
+
return returnValue.toDisplayString();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return returnValue.toString();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return 'null';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw 'Could not find string value: ' + this;
|
|
67
|
+
}
|
|
26
68
|
}
|
|
27
69
|
export var ParseSymbolType;
|
|
28
70
|
(function (ParseSymbolType) {
|
package/dist/esm/render.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SVG, registerWindow } from '@svgdotjs/svg.js';
|
|
2
2
|
import { ExtractDrawingRects, RenderFrameType, getBounds } from "./layout.mjs";
|
|
3
3
|
import { applyFontsToSVG, getCreateSVGWindow } from './sizing.mjs';
|
|
4
|
-
import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, ParamKeys, RenderFlags,
|
|
4
|
+
import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from './globals.mjs';
|
|
5
5
|
import { NumericValue } from './objects/ParamDefinition.mjs';
|
|
6
|
-
import { getBoundsSize } from './utils.mjs';
|
|
7
|
-
import { getPaperSize, milsToMM
|
|
6
|
+
import { combineMaps, getBoundsSize } from './utils.mjs';
|
|
7
|
+
import { getPaperSize, milsToMM } from './helpers.mjs';
|
|
8
8
|
import SVGtoPDF from 'svg-to-pdfkit';
|
|
9
9
|
import { FrameParamKeys } from './objects/Frame.mjs';
|
|
10
10
|
import { SymbolPlaceholder } from './draw_symbols.mjs';
|
|
@@ -16,11 +16,12 @@ function createSvgCanvas() {
|
|
|
16
16
|
applyFontsToSVG(canvas);
|
|
17
17
|
return canvas;
|
|
18
18
|
}
|
|
19
|
-
export function renderSheetsToSVG(sheetFrames) {
|
|
19
|
+
export function renderSheetsToSVG(sheetFrames, logger) {
|
|
20
20
|
const canvas = createSvgCanvas();
|
|
21
21
|
sheetFrames.forEach((sheet, index) => {
|
|
22
22
|
const sheetGroup = canvas.group();
|
|
23
|
-
sheetGroup.id('sheet-' + index);
|
|
23
|
+
sheetGroup.id('sheet-' + index).addClass('sheet');
|
|
24
|
+
logger.add('rendering sheet: sheet-' + index);
|
|
24
25
|
const { components, wires, junctions, mergedWires, frames, textObjects } = sheet;
|
|
25
26
|
const allFrames = [sheet.frame, ...frames];
|
|
26
27
|
let gridBounds = null;
|
|
@@ -29,6 +30,7 @@ export function renderSheetsToSVG(sheetFrames) {
|
|
|
29
30
|
let yOffset = 0;
|
|
30
31
|
let sheetYOffset = 0;
|
|
31
32
|
if (sheet.frame.frame) {
|
|
33
|
+
logger.add('drawing frame');
|
|
32
34
|
const frameComponent = sheet.frame.frame.parameters
|
|
33
35
|
.get(FrameParamKeys.SheetType);
|
|
34
36
|
if (frameComponent) {
|
|
@@ -41,15 +43,18 @@ export function renderSheetsToSVG(sheetFrames) {
|
|
|
41
43
|
let widthMM = 0;
|
|
42
44
|
let heightMM = 0;
|
|
43
45
|
if (frameRects[0]) {
|
|
44
|
-
originalWidthMM = milsToMM(frameRects[0].width);
|
|
45
|
-
originalHeightMM = milsToMM(frameRects[0].height);
|
|
46
|
+
originalWidthMM = milsToMM(frameRects[0].width).toNumber();
|
|
47
|
+
originalHeightMM = milsToMM(frameRects[0].height).toNumber();
|
|
48
|
+
logger.add('first frame size: ' + originalWidthMM + ' ' + originalHeightMM);
|
|
46
49
|
}
|
|
47
50
|
if (frameRects[1]) {
|
|
48
|
-
widthMM = milsToMM(frameRects[1].width);
|
|
49
|
-
heightMM = milsToMM(frameRects[1].height);
|
|
51
|
+
widthMM = milsToMM(frameRects[1].width).toNumber();
|
|
52
|
+
heightMM = milsToMM(frameRects[1].height).toNumber();
|
|
53
|
+
logger.add('second frame size: ' + widthMM + ' ' + heightMM);
|
|
50
54
|
}
|
|
51
55
|
xOffset = (originalWidthMM - widthMM) / 2;
|
|
52
56
|
yOffset = (originalHeightMM - heightMM) / 2;
|
|
57
|
+
logger.add('offset', xOffset, yOffset);
|
|
53
58
|
sheetYOffset = index * (originalHeightMM + defaultPageSpacingMM);
|
|
54
59
|
gridBounds = {
|
|
55
60
|
xmin: 0,
|
|
@@ -60,8 +65,10 @@ export function renderSheetsToSVG(sheetFrames) {
|
|
|
60
65
|
extendGrid = false;
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
logger.add('sheet contents offset: ' + xOffset + ' ' + yOffset);
|
|
69
|
+
logger.add('generating svg children in sheet');
|
|
70
|
+
const sheetElements = sheetGroup.group().addClass('sheet-elements');
|
|
71
|
+
generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridBounds, extendGrid, logger);
|
|
65
72
|
sheetElements.translate(xOffset, yOffset);
|
|
66
73
|
sheetGroup.translate(0, sheetYOffset);
|
|
67
74
|
});
|
|
@@ -105,16 +112,18 @@ export function generatePdfOutput(doc, canvas, sheetSize, sheetSizeDefined, zoom
|
|
|
105
112
|
}
|
|
106
113
|
});
|
|
107
114
|
}
|
|
108
|
-
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridBounds, extendGrid) {
|
|
115
|
+
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridBounds, extendGrid, logger) {
|
|
109
116
|
const displayWireId = false;
|
|
110
117
|
if (gridBounds === null) {
|
|
118
|
+
logger.add('get grid bounds');
|
|
111
119
|
gridBounds = getBounds(components, wires, junctions, frameObjects);
|
|
112
120
|
}
|
|
113
|
-
|
|
121
|
+
logger.add('grid bounds', gridBounds.xmin, gridBounds.ymin, gridBounds.xmax, gridBounds.ymax);
|
|
122
|
+
drawGrid(canvas.group().translate(0, 0), gridBounds, extendGrid, logger);
|
|
114
123
|
components.forEach(item => {
|
|
115
124
|
const { x, y, width, height } = item;
|
|
116
125
|
const symbolGroup = canvas.group();
|
|
117
|
-
symbolGroup.translate(x, y);
|
|
126
|
+
symbolGroup.translate(x.toNumber(), y.toNumber());
|
|
118
127
|
const { symbol = null } = item;
|
|
119
128
|
if (symbol !== null && symbol) {
|
|
120
129
|
const extra = {};
|
|
@@ -151,7 +160,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
151
160
|
family: 'Arial',
|
|
152
161
|
size: 50 * fontDisplayScale,
|
|
153
162
|
})
|
|
154
|
-
.translate(wire.x
|
|
163
|
+
.translate(wire.x.add(5).toNumber(), wire.y.add(5).toNumber());
|
|
155
164
|
});
|
|
156
165
|
}
|
|
157
166
|
const mergedWireGroup = canvas.group();
|
|
@@ -185,7 +194,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
185
194
|
drawSheetFrameBorder(frameGroup, item);
|
|
186
195
|
}
|
|
187
196
|
else {
|
|
188
|
-
if (borderWidth > 0) {
|
|
197
|
+
if (borderWidth.toNumber() > 0) {
|
|
189
198
|
if (item.type === RenderFrameType.Container) {
|
|
190
199
|
strokeColor = '#111';
|
|
191
200
|
}
|
|
@@ -197,24 +206,27 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
197
206
|
}
|
|
198
207
|
const tmpRect = frameGroup.rect(width, height)
|
|
199
208
|
.fill('none')
|
|
200
|
-
.stroke({
|
|
201
|
-
|
|
209
|
+
.stroke({
|
|
210
|
+
width: milsToMM(borderWidth).toNumber(),
|
|
211
|
+
color: strokeColor
|
|
212
|
+
});
|
|
213
|
+
tmpRect.translate(item.x.toNumber(), item.y.toNumber());
|
|
202
214
|
}
|
|
203
215
|
}
|
|
204
216
|
});
|
|
205
217
|
textObjects.forEach(item => {
|
|
206
218
|
const { x, y, symbol } = item;
|
|
207
219
|
const innerGroup = canvas.group();
|
|
208
|
-
innerGroup.translate(x, y);
|
|
220
|
+
innerGroup.translate(x.toNumber(), y.toNumber());
|
|
209
221
|
symbol.draw(innerGroup);
|
|
210
222
|
});
|
|
211
|
-
const originSize = milsToMM(10);
|
|
223
|
+
const originSize = milsToMM(10).toNumber();
|
|
212
224
|
RenderFlags.ShowOrigin && canvas.group().translate(0, 0)
|
|
213
225
|
.circle(originSize)
|
|
214
226
|
.translate(-originSize / 2, -originSize / 2)
|
|
215
227
|
.stroke('none').fill('red');
|
|
216
228
|
}
|
|
217
|
-
function drawGrid(group, canvasSize, extendGrid) {
|
|
229
|
+
function drawGrid(group, canvasSize, extendGrid, logger) {
|
|
218
230
|
const gridSize = defaultGridSizeUnits;
|
|
219
231
|
const { xmin, ymin, xmax, ymax } = canvasSize;
|
|
220
232
|
const extraValue = extendGrid ? 1 : 0;
|
|
@@ -228,8 +240,12 @@ function drawGrid(group, canvasSize, extendGrid) {
|
|
|
228
240
|
: (ymax - ymin);
|
|
229
241
|
const numCols = Math.floor((gridEndX - gridStartX) / gridSize)
|
|
230
242
|
+ (extendGrid ? 1 : 0);
|
|
243
|
+
const originSize = milsToMM(10).toNumber();
|
|
244
|
+
RenderFlags.ShowGridOrigin && group.circle(originSize)
|
|
245
|
+
.translate(-originSize / 2, -originSize / 2)
|
|
246
|
+
.stroke('none').fill('blue');
|
|
231
247
|
const lines = [];
|
|
232
|
-
const smallOffset = milsToMM(3);
|
|
248
|
+
const smallOffset = milsToMM(3).toNumber();
|
|
233
249
|
const startY = gridStartY - smallOffset / 2;
|
|
234
250
|
const endY = gridEndY + smallOffset;
|
|
235
251
|
for (let i = 0; i < numCols; i++) {
|
|
@@ -237,12 +253,13 @@ function drawGrid(group, canvasSize, extendGrid) {
|
|
|
237
253
|
lines.push(`M ${startX} ${startY} L ${startX} ${endY}`);
|
|
238
254
|
}
|
|
239
255
|
const strokeSize = milsToMM(3);
|
|
240
|
-
group.
|
|
256
|
+
group.addClass('grid')
|
|
257
|
+
.path(lines.join(" "))
|
|
241
258
|
.attr({
|
|
242
|
-
'stroke-dasharray': `${strokeSize},${gridSize - strokeSize}`,
|
|
259
|
+
'stroke-dasharray': `${strokeSize.toNumber()},${gridSize - strokeSize.toNumber()}`,
|
|
243
260
|
})
|
|
244
261
|
.stroke({
|
|
245
|
-
width: strokeSize,
|
|
262
|
+
width: strokeSize.toNumber(),
|
|
246
263
|
color: '#000'
|
|
247
264
|
});
|
|
248
265
|
}
|
|
@@ -254,98 +271,12 @@ function drawSheetFrameBorder(frameGroup, frame) {
|
|
|
254
271
|
if (displayProp) {
|
|
255
272
|
const sheetFrameGroup = frameGroup.group();
|
|
256
273
|
const symbol = new SymbolPlaceholder(displayProp);
|
|
274
|
+
symbol.drawing.variables = combineMaps(frameComponent.parameters, frameParams);
|
|
257
275
|
symbol.refreshDrawing();
|
|
258
276
|
symbol.draw(sheetFrameGroup);
|
|
259
277
|
const offsetX = milsToMM(frameComponent.getParam('offset_x'));
|
|
260
278
|
const offsetY = milsToMM(frameComponent.getParam('offset_y'));
|
|
261
|
-
sheetFrameGroup.translate(-offsetX, -offsetY);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
function drawSheetFrameBorderDirect(frameGroup, frame, borderWidth, strokeColor, width, height) {
|
|
266
|
-
const commonStroke = {
|
|
267
|
-
width: milsToMM(borderWidth),
|
|
268
|
-
color: strokeColor
|
|
269
|
-
};
|
|
270
|
-
const commonFont = {
|
|
271
|
-
family: defaultFont,
|
|
272
|
-
size: 50 * fontDisplayScale,
|
|
273
|
-
'dominant-baseline': 'middle',
|
|
274
|
-
'text-anchor': 'middle',
|
|
275
|
-
};
|
|
276
|
-
let rows = 1;
|
|
277
|
-
let columns = 1;
|
|
278
|
-
let showGridReference = true;
|
|
279
|
-
if (PaperGridReferences[frame.size]) {
|
|
280
|
-
[rows, columns] = PaperGridReferences[frame.size];
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
showGridReference = false;
|
|
284
|
-
}
|
|
285
|
-
if (!showGridReference) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
const outerMargin = 2;
|
|
289
|
-
const outerWidth = width + outerMargin * 2;
|
|
290
|
-
const outerHeight = height + outerMargin * 2;
|
|
291
|
-
const outerRect = frameGroup.rect(outerWidth, outerHeight)
|
|
292
|
-
.fill('none')
|
|
293
|
-
.stroke(commonStroke);
|
|
294
|
-
outerRect.translate(frame.x - outerMargin, frame.y - outerMargin);
|
|
295
|
-
const gridWidth = outerWidth / columns;
|
|
296
|
-
const gridHeight = outerHeight / rows;
|
|
297
|
-
const pathPoints = [];
|
|
298
|
-
for (let i = 1; i < rows + 1; i++) {
|
|
299
|
-
const lineStartX = frame.x - outerMargin;
|
|
300
|
-
const lineStartX2 = frame.x - outerMargin + outerWidth - outerMargin;
|
|
301
|
-
const lineY = frame.y - outerMargin + (gridHeight * i);
|
|
302
|
-
if (i < rows) {
|
|
303
|
-
pathPoints.push(...[
|
|
304
|
-
"M", lineStartX, lineY, "L", lineStartX + outerMargin, lineY,
|
|
305
|
-
"M", lineStartX2, lineY, "L", lineStartX2 + outerMargin, lineY
|
|
306
|
-
]);
|
|
279
|
+
sheetFrameGroup.translate(-offsetX.toNumber(), -offsetY.toNumber());
|
|
307
280
|
}
|
|
308
|
-
const displayValue = String.fromCharCode(i + 64);
|
|
309
|
-
frameGroup.text(displayValue)
|
|
310
|
-
.font(commonFont)
|
|
311
|
-
.translate(lineStartX + outerMargin / 2, lineY - gridHeight / 2);
|
|
312
|
-
frameGroup.text(displayValue)
|
|
313
|
-
.font(commonFont)
|
|
314
|
-
.translate(lineStartX2 + outerMargin / 2, lineY - gridHeight / 2);
|
|
315
|
-
}
|
|
316
|
-
for (let i = 1; i < columns + 1; i++) {
|
|
317
|
-
const lineStartY = frame.y - outerMargin;
|
|
318
|
-
const lineStartY2 = frame.y - outerMargin + outerHeight - outerMargin;
|
|
319
|
-
const lineX = frame.x - outerMargin + (gridWidth * i);
|
|
320
|
-
if (i < columns) {
|
|
321
|
-
pathPoints.push(...[
|
|
322
|
-
"M", lineX, lineStartY, "L", lineX, lineStartY + outerMargin,
|
|
323
|
-
"M", lineX, lineStartY2, "L", lineX, lineStartY2 + outerMargin
|
|
324
|
-
]);
|
|
325
|
-
}
|
|
326
|
-
frameGroup.text(i.toString())
|
|
327
|
-
.font(commonFont)
|
|
328
|
-
.translate(lineX - gridWidth / 2, lineStartY + outerMargin / 2 + milsToMM(10));
|
|
329
|
-
frameGroup.text(i.toString())
|
|
330
|
-
.font(commonFont)
|
|
331
|
-
.translate(lineX - gridWidth / 2, lineStartY2 + outerMargin / 2 + milsToMM(10));
|
|
332
|
-
}
|
|
333
|
-
frameGroup.path(pathPoints).stroke(commonStroke);
|
|
334
|
-
const titleWidth = milsToMM(3000);
|
|
335
|
-
const titleHeight = milsToMM(1000);
|
|
336
|
-
const rowHeight = milsToMM(200);
|
|
337
|
-
const points = [
|
|
338
|
-
"M", width - titleWidth, height,
|
|
339
|
-
"L", width - titleWidth, height - titleHeight,
|
|
340
|
-
"L", width, height - titleHeight,
|
|
341
|
-
"M", width - titleWidth, height - rowHeight,
|
|
342
|
-
"L", width, height - rowHeight,
|
|
343
|
-
"M", width - titleWidth, height - rowHeight * 2,
|
|
344
|
-
"L", width, height - rowHeight * 2,
|
|
345
|
-
"M", width - titleWidth, height - rowHeight * 3,
|
|
346
|
-
"L", width, height - rowHeight * 3
|
|
347
|
-
];
|
|
348
|
-
frameGroup.path(points).stroke(commonStroke).fill('none');
|
|
349
|
-
if (frame.containsTitle) {
|
|
350
281
|
}
|
|
351
282
|
}
|