circuitscript 0.1.0 → 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 +13 -8
- package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
- package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
- package/dist/cjs/builtinMethods.js +27 -8
- package/dist/cjs/draw_symbols.js +314 -190
- package/dist/cjs/execute.js +113 -115
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +12 -8
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +129 -125
- 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 +2 -1
- package/dist/cjs/objects/ParamDefinition.js +120 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/render.js +40 -110
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +68 -2
- package/dist/cjs/visitor.js +214 -254
- package/dist/esm/BaseVisitor.mjs +15 -10
- package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
- package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
- package/dist/esm/builtinMethods.mjs +24 -8
- package/dist/esm/draw_symbols.mjs +316 -193
- package/dist/esm/execute.mjs +115 -117
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +12 -8
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +131 -127
- 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 +2 -1
- package/dist/esm/objects/ParamDefinition.mjs +119 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/render.mjs +42 -112
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +64 -1
- package/dist/esm/visitor.mjs +216 -256
- package/dist/types/BaseVisitor.d.ts +1 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
- package/dist/types/draw_symbols.d.ts +71 -45
- package/dist/types/execute.d.ts +15 -10
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +14 -10
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +21 -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 +2 -2
- package/dist/types/objects/ParamDefinition.d.ts +31 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +6 -1
- package/dist/types/visitor.d.ts +4 -5
- package/libs/lib.cst +15 -3
- package/package.json +7 -3
package/dist/cjs/draw_symbols.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SymbolDrawingCommands = exports.SymbolDrawing = exports.SymbolCustomModule = exports.SymbolCustom = exports.PlaceHolderCommands = exports.SymbolPlaceholder = exports.SymbolText = exports.
|
|
3
|
+
exports.SymbolDrawingCommands = exports.SymbolDrawing = exports.SymbolCustomModule = exports.SymbolCustom = exports.PlaceHolderCommands = exports.SymbolPlaceholder = exports.SymbolText = exports.SymbolGraphic = void 0;
|
|
4
4
|
const helpers_js_1 = require("./helpers.js");
|
|
5
5
|
const globals_js_1 = require("./globals.js");
|
|
6
6
|
const geometry_js_1 = require("./geometry.js");
|
|
7
7
|
const PinTypes_js_1 = require("./objects/PinTypes.js");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
9
|
const types_js_1 = require("./objects/types.js");
|
|
10
|
+
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
10
11
|
class SymbolGraphic {
|
|
11
12
|
constructor() {
|
|
12
13
|
this.drawPortsName = true;
|
|
@@ -14,6 +15,8 @@ class SymbolGraphic {
|
|
|
14
15
|
this._angle = 0;
|
|
15
16
|
this._flipX = 0;
|
|
16
17
|
this._flipY = 0;
|
|
18
|
+
this.width = (0, ParamDefinition_js_1.numeric)(-1);
|
|
19
|
+
this.height = (0, ParamDefinition_js_1.numeric)(-1);
|
|
17
20
|
this.labelTexts = new Map();
|
|
18
21
|
this.drawing = new SymbolDrawing();
|
|
19
22
|
}
|
|
@@ -41,15 +44,21 @@ class SymbolGraphic {
|
|
|
41
44
|
}
|
|
42
45
|
calculateSize() {
|
|
43
46
|
const { width, height } = this.drawing.getBoundingBox();
|
|
44
|
-
this.width = width;
|
|
45
|
-
this.height = height;
|
|
46
|
-
}
|
|
47
|
-
size() {
|
|
47
|
+
this.width = (0, ParamDefinition_js_1.numeric)(width);
|
|
48
|
+
this.height = (0, ParamDefinition_js_1.numeric)(height);
|
|
48
49
|
return {
|
|
50
|
+
bodyWidth: (0, ParamDefinition_js_1.numeric)(-1),
|
|
51
|
+
bodyHeight: (0, ParamDefinition_js_1.numeric)(-1),
|
|
49
52
|
width: this.width,
|
|
50
53
|
height: this.height
|
|
51
54
|
};
|
|
52
55
|
}
|
|
56
|
+
size() {
|
|
57
|
+
return {
|
|
58
|
+
width: this.width.toNumber(),
|
|
59
|
+
height: this.height.toNumber(),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
53
62
|
draw(group, extra) {
|
|
54
63
|
const innerGroup = group.group();
|
|
55
64
|
this.drawBody(innerGroup);
|
|
@@ -86,15 +95,15 @@ class SymbolGraphic {
|
|
|
86
95
|
drawBounds(group) {
|
|
87
96
|
const bbox = this.drawing.getBoundingBox();
|
|
88
97
|
const originSize = (0, helpers_js_1.milsToMM)(10);
|
|
89
|
-
group.circle(originSize)
|
|
90
|
-
.translate(
|
|
98
|
+
group.circle(originSize.toNumber())
|
|
99
|
+
.translate(originSize.neg().div(2).toNumber(), originSize.neg().div(2).toNumber())
|
|
91
100
|
.fill('red')
|
|
92
101
|
.stroke('none');
|
|
93
102
|
group.rect(bbox.width, bbox.height)
|
|
94
103
|
.translate(bbox.start[0], bbox.start[1])
|
|
95
104
|
.fill('none')
|
|
96
105
|
.stroke({
|
|
97
|
-
width: (0, helpers_js_1.milsToMM)(2),
|
|
106
|
+
width: (0, helpers_js_1.milsToMM)(2).toNumber(),
|
|
98
107
|
color: '#ccc',
|
|
99
108
|
});
|
|
100
109
|
}
|
|
@@ -104,7 +113,7 @@ class SymbolGraphic {
|
|
|
104
113
|
const { path, lineColor, fillColor, lineWidth } = pathInfo;
|
|
105
114
|
group.path(path)
|
|
106
115
|
.stroke({
|
|
107
|
-
width: lineWidth,
|
|
116
|
+
width: lineWidth.toNumber(),
|
|
108
117
|
color: lineColor,
|
|
109
118
|
})
|
|
110
119
|
.fill(fillColor);
|
|
@@ -124,7 +133,8 @@ class SymbolGraphic {
|
|
|
124
133
|
const labels = this.drawing.getLabels();
|
|
125
134
|
labels.forEach(label => {
|
|
126
135
|
const tmpLabel = label;
|
|
127
|
-
const { fontSize = 50, anchor = geometry_js_1.HorizontalAlign.Left, vanchor = geometry_js_1.VerticalAlign.Bottom, fontWeight = 'regular', angle:
|
|
136
|
+
const { fontSize = (0, ParamDefinition_js_1.numeric)(50), anchor = geometry_js_1.HorizontalAlign.Left, vanchor = geometry_js_1.VerticalAlign.Bottom, fontWeight = 'regular', angle: tmpLabelAngle = (0, ParamDefinition_js_1.numeric)(0), textColor = "#333", } = tmpLabel.style ?? {};
|
|
137
|
+
const labelAngle = tmpLabelAngle.toNumber();
|
|
128
138
|
let anchorStyle = 'start';
|
|
129
139
|
let dominantBaseline = 'auto';
|
|
130
140
|
let useAnchor = anchor;
|
|
@@ -136,40 +146,44 @@ class SymbolGraphic {
|
|
|
136
146
|
}
|
|
137
147
|
switch (useAnchor) {
|
|
138
148
|
case geometry_js_1.HorizontalAlign.Left:
|
|
139
|
-
anchorStyle = (this.flipX === 0)
|
|
149
|
+
anchorStyle = (this.flipX === 0)
|
|
150
|
+
? geometry_js_1.HorizontalAlignProp.Start : geometry_js_1.HorizontalAlignProp.End;
|
|
140
151
|
break;
|
|
141
152
|
case geometry_js_1.HorizontalAlign.Middle:
|
|
142
|
-
anchorStyle =
|
|
153
|
+
anchorStyle = geometry_js_1.HorizontalAlignProp.Middle;
|
|
143
154
|
break;
|
|
144
155
|
case geometry_js_1.HorizontalAlign.Right:
|
|
145
|
-
anchorStyle = (this.flipX === 0)
|
|
156
|
+
anchorStyle = (this.flipX === 0)
|
|
157
|
+
? geometry_js_1.HorizontalAlignProp.End : geometry_js_1.HorizontalAlignProp.Start;
|
|
146
158
|
break;
|
|
147
159
|
}
|
|
148
160
|
switch (useDominantBaseline) {
|
|
149
161
|
case geometry_js_1.VerticalAlign.Top:
|
|
150
|
-
dominantBaseline = (this.flipY === 0)
|
|
162
|
+
dominantBaseline = (this.flipY === 0)
|
|
163
|
+
? geometry_js_1.VerticalAlignProp.Hanging : geometry_js_1.VerticalAlignProp.TextTop;
|
|
151
164
|
break;
|
|
152
165
|
case geometry_js_1.VerticalAlign.Middle:
|
|
153
|
-
dominantBaseline =
|
|
166
|
+
dominantBaseline = geometry_js_1.VerticalAlignProp.Central;
|
|
154
167
|
break;
|
|
155
168
|
case geometry_js_1.VerticalAlign.Bottom:
|
|
156
|
-
dominantBaseline = (this.flipY === 0)
|
|
169
|
+
dominantBaseline = (this.flipY === 0)
|
|
170
|
+
? geometry_js_1.VerticalAlignProp.TextTop : geometry_js_1.VerticalAlignProp.Hanging;
|
|
157
171
|
break;
|
|
158
172
|
}
|
|
159
173
|
const position = tmpLabel.getLabelPosition();
|
|
160
174
|
if (this.flipX !== 0) {
|
|
161
|
-
position[0]
|
|
175
|
+
position[0] = position[0].neg();
|
|
162
176
|
}
|
|
163
177
|
if (this.flipY !== 0) {
|
|
164
|
-
position[1]
|
|
178
|
+
position[1] = position[1].neg();
|
|
165
179
|
}
|
|
166
180
|
const useFont = globals_js_1.defaultFont;
|
|
167
181
|
const textContainer = group.group();
|
|
168
182
|
let translateX, translateY;
|
|
169
183
|
let useRotateAngle = 0;
|
|
170
184
|
if (isRotation180) {
|
|
171
|
-
translateX =
|
|
172
|
-
translateY =
|
|
185
|
+
translateX = position[0].neg();
|
|
186
|
+
translateY = position[1].neg();
|
|
173
187
|
useRotateAngle = 0;
|
|
174
188
|
}
|
|
175
189
|
else {
|
|
@@ -239,7 +253,7 @@ class SymbolGraphic {
|
|
|
239
253
|
}
|
|
240
254
|
textContainer.path(path)
|
|
241
255
|
.stroke({
|
|
242
|
-
width: (0, helpers_js_1.milsToMM)(5),
|
|
256
|
+
width: (0, helpers_js_1.milsToMM)(5).toNumber(),
|
|
243
257
|
color: '#333'
|
|
244
258
|
})
|
|
245
259
|
.fill('none')
|
|
@@ -247,47 +261,55 @@ class SymbolGraphic {
|
|
|
247
261
|
.translate(boundsTranslateX, boundsY - paddingVert);
|
|
248
262
|
}
|
|
249
263
|
}
|
|
250
|
-
|
|
251
|
-
const drawBoxBounds = false;
|
|
252
|
-
const drawOrigin = false;
|
|
253
|
-
if (drawBoxBounds) {
|
|
264
|
+
if (globals_js_1.RenderFlags.ShowLabelBoxBounds) {
|
|
254
265
|
const box = tmpLabel.box;
|
|
255
|
-
textContainer.rect(box.width, box.height)
|
|
266
|
+
textContainer.rect(box.width, box.height)
|
|
267
|
+
.fill('none')
|
|
268
|
+
.stroke({
|
|
269
|
+
width: 0.1,
|
|
270
|
+
color: 'blue',
|
|
271
|
+
})
|
|
256
272
|
.translate(box.xmin, box.ymin)
|
|
257
|
-
.
|
|
273
|
+
.rotate(labelAngle, -box.xmin, -box.ymin);
|
|
258
274
|
}
|
|
259
|
-
if (
|
|
275
|
+
if (globals_js_1.RenderFlags.ShowLabelBounds) {
|
|
260
276
|
const textBounds = tmpLabel.textMeasurementBounds;
|
|
261
277
|
const xOffset = (this.flipX !== 0) ? textBounds.width : 0;
|
|
262
|
-
textContainer.rect(textBounds.width, textBounds.height)
|
|
278
|
+
textContainer.rect(textBounds.width, textBounds.height)
|
|
279
|
+
.fill('none')
|
|
280
|
+
.stroke({
|
|
281
|
+
width: 0.1,
|
|
282
|
+
color: 'red',
|
|
283
|
+
})
|
|
263
284
|
.translate(textBounds.x - xOffset, textBounds.y);
|
|
264
285
|
}
|
|
265
|
-
textContainer.translate(translateX, translateY)
|
|
266
|
-
.rotate(useRotateAngle, -translateX, -translateY);
|
|
286
|
+
textContainer.translate(translateX.toNumber(), translateY.toNumber())
|
|
287
|
+
.rotate(useRotateAngle, -translateX.toNumber(), -translateY.toNumber());
|
|
267
288
|
textContainer.text(tmpLabel.text)
|
|
268
289
|
.fill(textColor)
|
|
269
290
|
.font({
|
|
270
291
|
family: useFont,
|
|
271
|
-
size: fontSize * globals_js_1.fontDisplayScale,
|
|
292
|
+
size: fontSize.toNumber() * globals_js_1.fontDisplayScale,
|
|
272
293
|
anchor: anchorStyle,
|
|
273
294
|
'dominant-baseline': dominantBaseline,
|
|
274
295
|
weight: fontWeight,
|
|
275
296
|
})
|
|
276
|
-
.
|
|
297
|
+
.attr("xml:space", "preserve")
|
|
298
|
+
.rotate(labelAngle, 0, 0);
|
|
277
299
|
const { a, b, c, d, e, f } = textContainer.matrix();
|
|
278
300
|
const newMatrix = {
|
|
279
|
-
a: (0, utils_js_1.roundValue)(a),
|
|
280
|
-
b: (0, utils_js_1.roundValue)(b),
|
|
281
|
-
c: (0, utils_js_1.roundValue)(c),
|
|
282
|
-
d: (0, utils_js_1.roundValue)(d),
|
|
283
|
-
e: (0, utils_js_1.roundValue)(e),
|
|
284
|
-
f: (0, utils_js_1.roundValue)(f),
|
|
301
|
+
a: (0, utils_js_1.roundValue)((0, ParamDefinition_js_1.numeric)(a)).toNumber(),
|
|
302
|
+
b: (0, utils_js_1.roundValue)((0, ParamDefinition_js_1.numeric)(b)).toNumber(),
|
|
303
|
+
c: (0, utils_js_1.roundValue)((0, ParamDefinition_js_1.numeric)(c)).toNumber(),
|
|
304
|
+
d: (0, utils_js_1.roundValue)((0, ParamDefinition_js_1.numeric)(d)).toNumber(),
|
|
305
|
+
e: (0, utils_js_1.roundValue)((0, ParamDefinition_js_1.numeric)(e)).toNumber(),
|
|
306
|
+
f: (0, utils_js_1.roundValue)((0, ParamDefinition_js_1.numeric)(f)).toNumber(),
|
|
285
307
|
};
|
|
286
308
|
textContainer.transform(newMatrix);
|
|
287
|
-
if (
|
|
288
|
-
const originSize = (0, helpers_js_1.milsToMM)(10);
|
|
309
|
+
if (globals_js_1.RenderFlags.ShowLabelOrigin) {
|
|
310
|
+
const originSize = (0, helpers_js_1.milsToMM)(10).toNumber();
|
|
289
311
|
textContainer.circle(originSize)
|
|
290
|
-
.translate(originSize / 2, originSize / 2)
|
|
312
|
+
.translate(-originSize / 2, -originSize / 2)
|
|
291
313
|
.fill('green');
|
|
292
314
|
}
|
|
293
315
|
});
|
|
@@ -316,34 +338,17 @@ class SymbolGraphic {
|
|
|
316
338
|
}
|
|
317
339
|
}
|
|
318
340
|
exports.SymbolGraphic = SymbolGraphic;
|
|
319
|
-
function SymbolFactory(name) {
|
|
320
|
-
switch (name) {
|
|
321
|
-
case 'point':
|
|
322
|
-
return new SymbolPointHidden();
|
|
323
|
-
}
|
|
324
|
-
return null;
|
|
325
|
-
}
|
|
326
|
-
exports.SymbolFactory = SymbolFactory;
|
|
327
|
-
class SymbolPointHidden extends SymbolGraphic {
|
|
328
|
-
generateDrawing() {
|
|
329
|
-
const drawing = this.drawing;
|
|
330
|
-
drawing.clear();
|
|
331
|
-
drawing.addPin(1, 0, 0, 0, 0);
|
|
332
|
-
this.drawing = drawing;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
exports.SymbolPointHidden = SymbolPointHidden;
|
|
336
341
|
class SymbolText extends SymbolGraphic {
|
|
337
342
|
constructor(text) {
|
|
338
343
|
super();
|
|
339
|
-
this.fontSize = 40;
|
|
344
|
+
this.fontSize = (0, ParamDefinition_js_1.numeric)(40);
|
|
340
345
|
this.fontWeight = 'regular';
|
|
341
346
|
this.text = text;
|
|
342
347
|
}
|
|
343
348
|
generateDrawing() {
|
|
344
349
|
const drawing = this.drawing;
|
|
345
350
|
drawing.clear();
|
|
346
|
-
drawing.addTextbox(0, 0, this.text, {
|
|
351
|
+
drawing.addTextbox((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), this.text, {
|
|
347
352
|
fontSize: this.fontSize,
|
|
348
353
|
anchor: geometry_js_1.HorizontalAlign.Middle,
|
|
349
354
|
fontWeight: this.fontWeight,
|
|
@@ -364,7 +369,7 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
364
369
|
[PlaceHolderCommands.units, ['mils'], {}],
|
|
365
370
|
[PlaceHolderCommands.lineColor, [globals_js_1.ColorScheme.PinLineColor], {}],
|
|
366
371
|
[PlaceHolderCommands.textColor, [globals_js_1.ColorScheme.PinNameColor], {}],
|
|
367
|
-
[PlaceHolderCommands.lineWidth, [5], {}],
|
|
372
|
+
[PlaceHolderCommands.lineWidth, [(0, ParamDefinition_js_1.numeric)(5)], {}],
|
|
368
373
|
...drawing.getCommands()
|
|
369
374
|
];
|
|
370
375
|
drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
|
|
@@ -419,7 +424,7 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
419
424
|
drawing.addArc(...positionParams);
|
|
420
425
|
break;
|
|
421
426
|
case PlaceHolderCommands.circle:
|
|
422
|
-
drawing.addArc(...positionParams, 0, 360);
|
|
427
|
+
drawing.addArc(...positionParams, (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(360));
|
|
423
428
|
break;
|
|
424
429
|
case PlaceHolderCommands.triangle:
|
|
425
430
|
drawing.addTriangle(...positionParams);
|
|
@@ -452,8 +457,8 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
452
457
|
case PlaceHolderCommands.text: {
|
|
453
458
|
const style = this.parseLabelStyle(keywordParams);
|
|
454
459
|
const content = keywordParams.get('content');
|
|
455
|
-
let offsetX = 0;
|
|
456
|
-
let offsetY = 0;
|
|
460
|
+
let offsetX = (0, ParamDefinition_js_1.numeric)(0);
|
|
461
|
+
let offsetY = (0, ParamDefinition_js_1.numeric)(0);
|
|
457
462
|
if (keywordParams.has('offset')) {
|
|
458
463
|
const offset = keywordParams.get('offset');
|
|
459
464
|
offsetX = offset[0];
|
|
@@ -505,6 +510,9 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
505
510
|
let displayPinId = true;
|
|
506
511
|
if (keywordParams.has(keywordDisplayPinId)) {
|
|
507
512
|
const value = keywordParams.get(keywordDisplayPinId);
|
|
513
|
+
if (value instanceof ParamDefinition_js_1.NumericValue && value.toNumber() === 0) {
|
|
514
|
+
displayPinId = false;
|
|
515
|
+
}
|
|
508
516
|
if (value === 0 || value === false) {
|
|
509
517
|
displayPinId = false;
|
|
510
518
|
}
|
|
@@ -528,7 +536,7 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
528
536
|
startX,
|
|
529
537
|
startY,
|
|
530
538
|
startX,
|
|
531
|
-
startY
|
|
539
|
+
startY.add(magnitude)
|
|
532
540
|
];
|
|
533
541
|
}
|
|
534
542
|
else if (commandName === PlaceHolderCommands.hpin) {
|
|
@@ -537,7 +545,7 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
537
545
|
positionParams[0],
|
|
538
546
|
startX,
|
|
539
547
|
startY,
|
|
540
|
-
startX
|
|
548
|
+
startX.add(magnitude),
|
|
541
549
|
startY
|
|
542
550
|
];
|
|
543
551
|
}
|
|
@@ -559,11 +567,12 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
559
567
|
const offset1 = 15;
|
|
560
568
|
const offset2 = 15;
|
|
561
569
|
let pinNameOffsetX = (0, helpers_js_1.milsToMM)(offset1);
|
|
562
|
-
let pinIdOffsetX = 0;
|
|
570
|
+
let pinIdOffsetX = (0, ParamDefinition_js_1.numeric)(0);
|
|
563
571
|
let pinIdAlignment = geometry_js_1.HorizontalAlign.Left;
|
|
564
572
|
let pinIdVAlignment = geometry_js_1.VerticalAlign.Bottom;
|
|
565
573
|
let pinIdOffsetY = (0, helpers_js_1.milsToMM)(-offset2);
|
|
566
|
-
|
|
574
|
+
const angleValue = angle.toNumber();
|
|
575
|
+
switch (angleValue) {
|
|
567
576
|
case 0:
|
|
568
577
|
pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
|
|
569
578
|
pinNameOffsetX = (0, helpers_js_1.milsToMM)(offset1);
|
|
@@ -586,16 +595,16 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
586
595
|
pinIdVAlignment = geometry_js_1.VerticalAlign.Top;
|
|
587
596
|
break;
|
|
588
597
|
}
|
|
589
|
-
if (
|
|
598
|
+
if (angleValue === 0 || angleValue === 90 || angleValue === 180 || angleValue === 270) {
|
|
590
599
|
const usePinName = pinNameParam ?? "";
|
|
591
|
-
usePinName !== "" && drawing.addLabel(endX
|
|
592
|
-
fontSize: globals_js_1.defaultPinNameTextSize,
|
|
600
|
+
usePinName !== "" && drawing.addLabel(endX.add(pinNameOffsetX), endY, usePinName, {
|
|
601
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.defaultPinNameTextSize),
|
|
593
602
|
anchor: pinNameAlignment,
|
|
594
603
|
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
595
604
|
textColor: pinNameColor,
|
|
596
605
|
});
|
|
597
|
-
displayPinId && drawing.addLabel(endX
|
|
598
|
-
fontSize: globals_js_1.defaultPinIdTextSize,
|
|
606
|
+
displayPinId && drawing.addLabel(endX.add(pinIdOffsetX), endY.add(pinIdOffsetY), pinId.toDisplayString(), {
|
|
607
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.defaultPinIdTextSize),
|
|
599
608
|
anchor: pinIdAlignment,
|
|
600
609
|
vanchor: pinIdVAlignment,
|
|
601
610
|
textColor: lineColor
|
|
@@ -631,59 +640,75 @@ var PlaceHolderCommands;
|
|
|
631
640
|
PlaceHolderCommands["for"] = "for";
|
|
632
641
|
})(PlaceHolderCommands || (exports.PlaceHolderCommands = PlaceHolderCommands = {}));
|
|
633
642
|
class SymbolCustom extends SymbolGraphic {
|
|
634
|
-
constructor(pinDefinition) {
|
|
643
|
+
constructor(pinDefinition, pinMaxPositions) {
|
|
635
644
|
super();
|
|
636
645
|
this.pinDefinition = [];
|
|
637
646
|
this.bodyWidth = (0, helpers_js_1.milsToMM)(400);
|
|
647
|
+
this.bodyHeight = (0, helpers_js_1.milsToMM)(100);
|
|
638
648
|
this.pinLength = (0, helpers_js_1.milsToMM)(100);
|
|
639
649
|
this.width = (0, helpers_js_1.milsToMM)(100);
|
|
640
650
|
this.height = (0, helpers_js_1.milsToMM)(100);
|
|
641
651
|
this.pinSpacing = (0, helpers_js_1.milsToMM)(100);
|
|
642
652
|
this.pinTextPadding = (0, helpers_js_1.milsToMM)(5);
|
|
643
653
|
this.pins = [];
|
|
654
|
+
this._cacheLeftPins = [];
|
|
655
|
+
this._cacheRightPins = [];
|
|
656
|
+
this._cacheTopPins = [];
|
|
657
|
+
this._cacheBottomPins = [];
|
|
644
658
|
this.pinDefinition = pinDefinition;
|
|
659
|
+
this.pinMaxPositions = pinMaxPositions;
|
|
645
660
|
}
|
|
646
661
|
generateDrawing() {
|
|
647
|
-
const leftPins = this.
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
const
|
|
651
|
-
return item.side === globals_js_1.SymbolPinSide.Right;
|
|
652
|
-
});
|
|
653
|
-
const maxLeftPins = Math.max(...leftPins.map(item => item.position)) + 1;
|
|
654
|
-
const maxRightPins = Math.max(...rightPins.map(item => item.position)) + 1;
|
|
662
|
+
const leftPins = this.getPins(globals_js_1.SymbolPinSide.Left);
|
|
663
|
+
const rightPins = this.getPins(globals_js_1.SymbolPinSide.Right);
|
|
664
|
+
const topPins = this.getPins(globals_js_1.SymbolPinSide.Top);
|
|
665
|
+
const bottomPins = this.getPins(globals_js_1.SymbolPinSide.Bottom);
|
|
655
666
|
this.drawing.clear();
|
|
656
667
|
const drawing = this.drawing;
|
|
657
668
|
drawing.angle = this._angle;
|
|
658
669
|
drawing.flipX = this._flipX;
|
|
659
670
|
drawing.flipY = this._flipY;
|
|
660
|
-
const bodyWidth = this.
|
|
661
|
-
const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
|
|
671
|
+
const { bodyWidth, bodyHeight } = this.calculateSize();
|
|
662
672
|
const defaultLineColor = globals_js_1.ColorScheme.PinLineColor;
|
|
663
673
|
drawing.addSetLineColor(defaultLineColor);
|
|
664
|
-
drawing.addSetLineWidth(5);
|
|
665
|
-
drawing.addRectMM(0, 0, bodyWidth, bodyHeight);
|
|
666
|
-
this.generateDrawingPins(drawing, bodyWidth, bodyHeight,
|
|
674
|
+
drawing.addSetLineWidth((0, ParamDefinition_js_1.numeric)(5));
|
|
675
|
+
drawing.addRectMM((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), bodyWidth, bodyHeight);
|
|
676
|
+
this.generateDrawingPins(drawing, bodyWidth, bodyHeight, {
|
|
677
|
+
left: leftPins, right: rightPins, top: topPins, bottom: bottomPins
|
|
678
|
+
}, defaultLineColor);
|
|
667
679
|
this.drawing = drawing;
|
|
668
680
|
this._cacheLeftPins = leftPins;
|
|
669
681
|
this._cacheRightPins = rightPins;
|
|
682
|
+
this._cacheTopPins = topPins;
|
|
683
|
+
this._cacheBottomPins = bottomPins;
|
|
670
684
|
}
|
|
671
|
-
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
|
|
685
|
+
getPins(side) {
|
|
686
|
+
const pins = this.pinDefinition.filter(item => {
|
|
687
|
+
return item.side === side;
|
|
688
|
+
});
|
|
689
|
+
return pins;
|
|
690
|
+
}
|
|
691
|
+
generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, pins, defaultLineColor) {
|
|
692
|
+
const { left: leftPins, right: rightPins, top: topPins, bottom: bottomPins } = pins;
|
|
693
|
+
const leftPinStart = bodyWidthMM.neg().div(2);
|
|
694
|
+
const rightPinStart = bodyWidthMM.div(2);
|
|
695
|
+
const topPinStart = bodyHeightMM.neg().div(2);
|
|
696
|
+
const bottomPinStart = bodyHeightMM.div(2);
|
|
697
|
+
const pinStartY = bodyHeightMM.neg().div(2);
|
|
698
|
+
const pinStartX = bodyWidthMM.neg().div(2);
|
|
699
|
+
const tmpPinSpacing = this.pinSpacing.toNumber();
|
|
675
700
|
leftPins.forEach(pin => {
|
|
676
701
|
const position = pin.position;
|
|
677
|
-
const pinY = pinStartY
|
|
678
|
-
drawing.addPinMM(pin.pinId, leftPinStart
|
|
679
|
-
drawing.addLabel(leftPinStart
|
|
680
|
-
fontSize: globals_js_1.CustomSymbolPinTextSize,
|
|
702
|
+
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
703
|
+
drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
|
|
704
|
+
drawing.addLabel(leftPinStart.add((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
|
|
705
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
|
|
681
706
|
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
682
707
|
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
683
708
|
textColor: globals_js_1.ColorScheme.PinNameColor,
|
|
684
709
|
});
|
|
685
|
-
drawing.addLabel(leftPinStart
|
|
686
|
-
fontSize: globals_js_1.CustomSymbolPinIdSize,
|
|
710
|
+
drawing.addLabel(leftPinStart.sub((0, helpers_js_1.milsToMM)(10)), pinY.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
|
|
711
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
|
|
687
712
|
anchor: geometry_js_1.HorizontalAlign.Right,
|
|
688
713
|
vanchor: geometry_js_1.VerticalAlign.Bottom,
|
|
689
714
|
textColor: defaultLineColor
|
|
@@ -691,32 +716,70 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
691
716
|
});
|
|
692
717
|
rightPins.forEach(pin => {
|
|
693
718
|
const position = pin.position;
|
|
694
|
-
const pinY = pinStartY
|
|
695
|
-
drawing.addPinMM(pin.pinId, rightPinStart
|
|
696
|
-
drawing.addLabel(rightPinStart
|
|
697
|
-
fontSize: globals_js_1.CustomSymbolPinTextSize,
|
|
719
|
+
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
720
|
+
drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
|
|
721
|
+
drawing.addLabel(rightPinStart.sub((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
|
|
722
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
|
|
698
723
|
anchor: geometry_js_1.HorizontalAlign.Right,
|
|
699
724
|
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
700
725
|
textColor: globals_js_1.ColorScheme.PinNameColor,
|
|
701
726
|
});
|
|
702
|
-
drawing.addLabel(rightPinStart
|
|
703
|
-
fontSize: globals_js_1.CustomSymbolPinIdSize,
|
|
727
|
+
drawing.addLabel(rightPinStart.add((0, helpers_js_1.milsToMM)(10)), pinY.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
|
|
728
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
|
|
704
729
|
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
705
730
|
vanchor: geometry_js_1.VerticalAlign.Bottom,
|
|
706
731
|
textColor: defaultLineColor
|
|
707
732
|
});
|
|
708
733
|
});
|
|
734
|
+
topPins.forEach(pin => {
|
|
735
|
+
const position = pin.position;
|
|
736
|
+
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
737
|
+
drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
|
|
738
|
+
drawing.addLabel(pinX, topPinStart.add((0, helpers_js_1.milsToMM)(20)), pin.text, {
|
|
739
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
|
|
740
|
+
anchor: geometry_js_1.HorizontalAlign.Right,
|
|
741
|
+
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
742
|
+
textColor: globals_js_1.ColorScheme.PinNameColor,
|
|
743
|
+
angle: (0, ParamDefinition_js_1.numeric)(-90),
|
|
744
|
+
});
|
|
745
|
+
drawing.addLabel(pinX.sub((0, helpers_js_1.milsToMM)(10)), topPinStart.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
|
|
746
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
|
|
747
|
+
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
748
|
+
vanchor: geometry_js_1.VerticalAlign.Bottom,
|
|
749
|
+
textColor: defaultLineColor,
|
|
750
|
+
angle: (0, ParamDefinition_js_1.numeric)(-90),
|
|
751
|
+
});
|
|
752
|
+
});
|
|
753
|
+
bottomPins.forEach(pin => {
|
|
754
|
+
const position = pin.position;
|
|
755
|
+
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
756
|
+
drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
|
|
757
|
+
drawing.addLabel(pinX, bottomPinStart.sub((0, helpers_js_1.milsToMM)(20)), pin.text, {
|
|
758
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
|
|
759
|
+
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
760
|
+
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
761
|
+
textColor: globals_js_1.ColorScheme.PinNameColor,
|
|
762
|
+
angle: (0, ParamDefinition_js_1.numeric)(-90),
|
|
763
|
+
});
|
|
764
|
+
drawing.addLabel(pinX.sub((0, helpers_js_1.milsToMM)(10)), bottomPinStart.add((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
|
|
765
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
|
|
766
|
+
anchor: geometry_js_1.HorizontalAlign.Right,
|
|
767
|
+
vanchor: geometry_js_1.VerticalAlign.Bottom,
|
|
768
|
+
textColor: defaultLineColor,
|
|
769
|
+
angle: (0, ParamDefinition_js_1.numeric)(-90)
|
|
770
|
+
});
|
|
771
|
+
});
|
|
709
772
|
const instanceName = drawing.variables.get('refdes');
|
|
710
|
-
instanceName && drawing.addLabel(
|
|
711
|
-
fontSize: globals_js_1.CustomSymbolRefDesSize,
|
|
773
|
+
instanceName && drawing.addLabel(bodyWidthMM.neg().div(2), bodyHeightMM.neg().div(2).sub((0, helpers_js_1.milsToMM)(20)), instanceName, {
|
|
774
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolRefDesSize),
|
|
712
775
|
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
713
776
|
});
|
|
714
777
|
const acceptedMPNKeys = ['MPN', 'mpn', 'manufacturer_pn'];
|
|
715
778
|
acceptedMPNKeys.some(key => {
|
|
716
779
|
const labelValue = drawing.variables.get(key);
|
|
717
780
|
if (labelValue !== undefined) {
|
|
718
|
-
drawing.addLabel(
|
|
719
|
-
fontSize: globals_js_1.CustomSymbolParamTextSize,
|
|
781
|
+
drawing.addLabel(bodyWidthMM.neg().div(2), bodyHeightMM.div(2).add((0, helpers_js_1.milsToMM)(20)), labelValue, {
|
|
782
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolParamTextSize),
|
|
720
783
|
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
721
784
|
vanchor: geometry_js_1.VerticalAlign.Top,
|
|
722
785
|
});
|
|
@@ -724,29 +787,59 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
724
787
|
});
|
|
725
788
|
}
|
|
726
789
|
calculateSize() {
|
|
727
|
-
|
|
728
|
-
|
|
790
|
+
const tmpPinSpacing = this.pinSpacing.toNumber();
|
|
791
|
+
const tmpPinLength = this.pinLength.toNumber();
|
|
792
|
+
const { [globals_js_1.SymbolPinSide.Top]: maxTopPins, [globals_js_1.SymbolPinSide.Bottom]: maxBottomPins, [globals_js_1.SymbolPinSide.Left]: maxLeftPins, [globals_js_1.SymbolPinSide.Right]: maxRightPins } = this.pinMaxPositions;
|
|
793
|
+
const bodyWidthFromPins = (0, ParamDefinition_js_1.numeric)((1 + Math.max(maxTopPins, maxBottomPins)) * tmpPinSpacing);
|
|
794
|
+
const bodyWidth = Math.max(bodyWidthFromPins.toNumber(), this.bodyWidth.toNumber());
|
|
795
|
+
let tmpBodyHeight = 0;
|
|
796
|
+
if (maxLeftPins === 0 && maxRightPins === 0) {
|
|
797
|
+
tmpBodyHeight = 3;
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
tmpBodyHeight = (1 + Math.max(maxLeftPins, maxRightPins));
|
|
801
|
+
}
|
|
802
|
+
const bodyHeight = Math.max(tmpBodyHeight * tmpPinSpacing, this.bodyHeight.toNumber());
|
|
803
|
+
const useHeight = bodyHeight
|
|
804
|
+
+ ((this._cacheTopPins.length > 0) ? tmpPinLength : 0)
|
|
805
|
+
+ ((this._cacheBottomPins.length > 0) ? tmpPinLength : 0);
|
|
806
|
+
const useWidth = bodyWidth
|
|
807
|
+
+ ((this._cacheLeftPins.length > 0) ? tmpPinLength : 0)
|
|
808
|
+
+ ((this._cacheRightPins.length > 0) ? tmpPinLength : 0);
|
|
809
|
+
this.width = (0, ParamDefinition_js_1.numeric)(useWidth);
|
|
810
|
+
this.height = (0, ParamDefinition_js_1.numeric)(useHeight);
|
|
811
|
+
return {
|
|
812
|
+
bodyWidth: (0, ParamDefinition_js_1.numeric)(bodyWidth),
|
|
813
|
+
bodyHeight: (0, ParamDefinition_js_1.numeric)(bodyHeight),
|
|
814
|
+
width: this.width,
|
|
815
|
+
height: this.height
|
|
816
|
+
};
|
|
729
817
|
}
|
|
730
818
|
}
|
|
731
819
|
exports.SymbolCustom = SymbolCustom;
|
|
732
820
|
class SymbolCustomModule extends SymbolCustom {
|
|
733
821
|
constructor() {
|
|
734
822
|
super(...arguments);
|
|
735
|
-
this.pinLength = 0;
|
|
823
|
+
this.pinLength = (0, helpers_js_1.milsToMM)(0);
|
|
736
824
|
this.portWidth = (0, helpers_js_1.milsToMM)(100);
|
|
737
825
|
this.portHeight = (0, helpers_js_1.milsToMM)(50);
|
|
738
826
|
}
|
|
739
|
-
generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM,
|
|
740
|
-
const leftPinStart =
|
|
741
|
-
const rightPinStart = bodyWidthMM
|
|
742
|
-
const
|
|
827
|
+
generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, pins, defaultLineColor) {
|
|
828
|
+
const leftPinStart = bodyWidthMM.neg().div(2);
|
|
829
|
+
const rightPinStart = bodyWidthMM.div(2);
|
|
830
|
+
const topPinStart = bodyHeightMM.neg().div(2);
|
|
831
|
+
const bottomPinStart = bodyHeightMM.div(2);
|
|
832
|
+
const pinStartY = bodyHeightMM.neg().div(2);
|
|
833
|
+
const pinStartX = bodyWidthMM.neg().div(2);
|
|
834
|
+
const tmpPinSpacing = this.pinSpacing.toNumber();
|
|
835
|
+
const { left: leftPins, right: rightPins, top: topPins, bottom: bottomPins } = pins;
|
|
743
836
|
leftPins.forEach(pin => {
|
|
744
837
|
const position = pin.position;
|
|
745
|
-
const pinY = pinStartY
|
|
746
|
-
drawing.addPinMM(pin.pinId, leftPinStart
|
|
838
|
+
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
839
|
+
drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
|
|
747
840
|
drawing.addModulePort(leftPinStart, pinY, this.portWidth, this.portHeight, pin.pinType);
|
|
748
|
-
drawing.addLabel(leftPinStart
|
|
749
|
-
fontSize: 40,
|
|
841
|
+
drawing.addLabel(leftPinStart.add(this.portWidth).add((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
|
|
842
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(40),
|
|
750
843
|
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
751
844
|
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
752
845
|
textColor: globals_js_1.ColorScheme.PinNameColor,
|
|
@@ -754,14 +847,40 @@ class SymbolCustomModule extends SymbolCustom {
|
|
|
754
847
|
});
|
|
755
848
|
rightPins.forEach(pin => {
|
|
756
849
|
const position = pin.position;
|
|
757
|
-
const pinY = pinStartY
|
|
758
|
-
drawing.addPinMM(pin.pinId, rightPinStart
|
|
850
|
+
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
851
|
+
drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
|
|
759
852
|
drawing.addModulePort(rightPinStart, pinY, this.portWidth, this.portHeight, pin.pinType, -1);
|
|
760
|
-
drawing.addLabel(rightPinStart
|
|
761
|
-
fontSize: 40,
|
|
853
|
+
drawing.addLabel(rightPinStart.sub(this.portWidth).sub((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
|
|
854
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(40),
|
|
855
|
+
anchor: geometry_js_1.HorizontalAlign.Right,
|
|
856
|
+
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
857
|
+
textColor: globals_js_1.ColorScheme.PinNameColor,
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
topPins.forEach(pin => {
|
|
861
|
+
const position = pin.position;
|
|
862
|
+
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
863
|
+
drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
|
|
864
|
+
drawing.addModulePort(pinX, topPinStart, this.portWidth, this.portHeight, pin.pinType, 1, 90);
|
|
865
|
+
drawing.addLabel(pinX, topPinStart.add(this.portWidth).add((0, helpers_js_1.milsToMM)(20)), pin.text, {
|
|
866
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(40),
|
|
762
867
|
anchor: geometry_js_1.HorizontalAlign.Right,
|
|
763
868
|
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
764
869
|
textColor: globals_js_1.ColorScheme.PinNameColor,
|
|
870
|
+
angle: (0, ParamDefinition_js_1.numeric)(-90),
|
|
871
|
+
});
|
|
872
|
+
});
|
|
873
|
+
bottomPins.forEach(pin => {
|
|
874
|
+
const position = pin.position;
|
|
875
|
+
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
876
|
+
drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, bottomPinStart, pinX, bottomPinStart.sub(this.pinLength), defaultLineColor);
|
|
877
|
+
drawing.addModulePort(pinX, bottomPinStart, this.portWidth, this.portHeight, pin.pinType, 1, -90);
|
|
878
|
+
drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub((0, helpers_js_1.milsToMM)(20)), pin.text, {
|
|
879
|
+
fontSize: (0, ParamDefinition_js_1.numeric)(40),
|
|
880
|
+
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
881
|
+
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
882
|
+
textColor: globals_js_1.ColorScheme.PinNameColor,
|
|
883
|
+
angle: (0, ParamDefinition_js_1.numeric)(-90),
|
|
765
884
|
});
|
|
766
885
|
});
|
|
767
886
|
}
|
|
@@ -774,7 +893,7 @@ class SymbolDrawing {
|
|
|
774
893
|
this.angle = 0;
|
|
775
894
|
this.flipX = 0;
|
|
776
895
|
this.flipY = 0;
|
|
777
|
-
this.mainOrigin = [0, 0];
|
|
896
|
+
this.mainOrigin = [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)];
|
|
778
897
|
this.logger = null;
|
|
779
898
|
this.variables = new Map();
|
|
780
899
|
}
|
|
@@ -802,26 +921,30 @@ class SymbolDrawing {
|
|
|
802
921
|
}
|
|
803
922
|
addPinMM(pinId, startXMM, startYMM, endXMM, endYMM, lineColor) {
|
|
804
923
|
let angle = 0;
|
|
805
|
-
|
|
806
|
-
|
|
924
|
+
const tmpStartXMM = startXMM.toNumber();
|
|
925
|
+
const tmpEndXMM = endXMM.toNumber();
|
|
926
|
+
const tmpStartYMM = startYMM.toNumber();
|
|
927
|
+
const tmpEndYMM = endYMM.toNumber();
|
|
928
|
+
if (tmpStartXMM === tmpEndXMM) {
|
|
929
|
+
if (tmpStartYMM > tmpEndYMM) {
|
|
807
930
|
angle = 270;
|
|
808
931
|
}
|
|
809
|
-
else if (
|
|
932
|
+
else if (tmpStartYMM < tmpEndYMM) {
|
|
810
933
|
angle = 90;
|
|
811
934
|
}
|
|
812
935
|
}
|
|
813
936
|
else {
|
|
814
|
-
if (
|
|
937
|
+
if (tmpStartXMM < tmpEndXMM) {
|
|
815
938
|
angle = 0;
|
|
816
939
|
}
|
|
817
|
-
else if (
|
|
940
|
+
else if (tmpStartXMM > tmpEndXMM) {
|
|
818
941
|
angle = 180;
|
|
819
942
|
}
|
|
820
943
|
}
|
|
821
944
|
this.pins.push([
|
|
822
945
|
pinId,
|
|
823
946
|
geometry_js_1.Geometry.segment([startXMM, startYMM], [endXMM, endYMM]),
|
|
824
|
-
angle,
|
|
947
|
+
(0, ParamDefinition_js_1.numeric)(angle),
|
|
825
948
|
lineColor
|
|
826
949
|
]);
|
|
827
950
|
return this;
|
|
@@ -830,14 +953,14 @@ class SymbolDrawing {
|
|
|
830
953
|
startX = (0, helpers_js_1.milsToMM)(startX);
|
|
831
954
|
startY = (0, helpers_js_1.milsToMM)(startY);
|
|
832
955
|
value = (0, helpers_js_1.milsToMM)(value);
|
|
833
|
-
this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX, startY
|
|
956
|
+
this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX, startY.add(value)]));
|
|
834
957
|
return this;
|
|
835
958
|
}
|
|
836
959
|
addHLine(startX, startY, value) {
|
|
837
960
|
startX = (0, helpers_js_1.milsToMM)(startX);
|
|
838
961
|
startY = (0, helpers_js_1.milsToMM)(startY);
|
|
839
962
|
value = (0, helpers_js_1.milsToMM)(value);
|
|
840
|
-
this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX
|
|
963
|
+
this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX.add(value), startY]));
|
|
841
964
|
return this;
|
|
842
965
|
}
|
|
843
966
|
addRect(centerX, centerY, width, height) {
|
|
@@ -848,14 +971,14 @@ class SymbolDrawing {
|
|
|
848
971
|
return this.addRectMM(centerX, centerY, width, height);
|
|
849
972
|
}
|
|
850
973
|
addRectMM(centerX, centerY, width, height) {
|
|
851
|
-
const width2 = width
|
|
852
|
-
const height2 = height
|
|
974
|
+
const width2 = width.div(2);
|
|
975
|
+
const height2 = height.div(2);
|
|
853
976
|
this.items.push(geometry_js_1.Geometry.polygon([
|
|
854
|
-
[centerX
|
|
855
|
-
[centerX
|
|
856
|
-
[centerX
|
|
857
|
-
[centerX
|
|
858
|
-
[centerX
|
|
977
|
+
[centerX.sub(width2), centerY.sub(height2)],
|
|
978
|
+
[centerX.add(width2), centerY.sub(height2)],
|
|
979
|
+
[centerX.add(width2), centerY.add(height2)],
|
|
980
|
+
[centerX.sub(width2), centerY.add(height2)],
|
|
981
|
+
[centerX.sub(width2), centerY.sub(height2)]
|
|
859
982
|
]));
|
|
860
983
|
return this;
|
|
861
984
|
}
|
|
@@ -867,25 +990,15 @@ class SymbolDrawing {
|
|
|
867
990
|
width = (0, helpers_js_1.milsToMM)(width);
|
|
868
991
|
const line = geometry_js_1.Geometry.line(startX, startY, endX, endY);
|
|
869
992
|
const normLine = line.norm;
|
|
870
|
-
const dx1 = normLine.x
|
|
871
|
-
const dy1 = normLine.y
|
|
872
|
-
const dx2 = normLine.x
|
|
873
|
-
const dy2 = normLine.y
|
|
993
|
+
const dx1 = (0, ParamDefinition_js_1.numeric)(normLine.x).mul(width).div(2);
|
|
994
|
+
const dy1 = (0, ParamDefinition_js_1.numeric)(normLine.y).mul(width).div(2);
|
|
995
|
+
const dx2 = (0, ParamDefinition_js_1.numeric)(normLine.x).mul(width.neg()).div(2);
|
|
996
|
+
const dy2 = (0, ParamDefinition_js_1.numeric)(normLine.y).mul(width.neg()).div(2);
|
|
874
997
|
this.items.push(geometry_js_1.Geometry.polygon([
|
|
875
|
-
[dx1
|
|
876
|
-
[dx2
|
|
998
|
+
[dx1.add(startX), dy1.add(startY)],
|
|
999
|
+
[dx2.add(startX), dy2.add(startY)],
|
|
877
1000
|
[endX, endY],
|
|
878
|
-
[dx1
|
|
879
|
-
]));
|
|
880
|
-
return this;
|
|
881
|
-
}
|
|
882
|
-
addRect2(x, y, x2, y2) {
|
|
883
|
-
this.items.push(geometry_js_1.Geometry.polygon([
|
|
884
|
-
[x, y],
|
|
885
|
-
[x2, y],
|
|
886
|
-
[x2, y2],
|
|
887
|
-
[x, y2],
|
|
888
|
-
[x, y]
|
|
1001
|
+
[dx1.add(startX), dy1.add(startY)],
|
|
889
1002
|
]));
|
|
890
1003
|
return this;
|
|
891
1004
|
}
|
|
@@ -905,54 +1018,59 @@ class SymbolDrawing {
|
|
|
905
1018
|
this.items.push(geometry_js_1.Geometry.textbox(null, x, y, textValue, style));
|
|
906
1019
|
return this;
|
|
907
1020
|
}
|
|
908
|
-
addModulePort(x, y, width, height, portType = PinTypes_js_1.PinTypes.Any, scaleX = 1) {
|
|
909
|
-
const height2 = height
|
|
1021
|
+
addModulePort(x, y, width, height, portType = PinTypes_js_1.PinTypes.Any, scaleX = 1, angle = 0) {
|
|
1022
|
+
const height2 = height.div(2);
|
|
910
1023
|
let path = [];
|
|
911
1024
|
const arrowSize = (0, helpers_js_1.milsToMM)(30);
|
|
912
1025
|
if (portType === PinTypes_js_1.PinTypes.Any) {
|
|
913
1026
|
path = [
|
|
914
|
-
[0,
|
|
915
|
-
[width,
|
|
916
|
-
[width,
|
|
917
|
-
[0,
|
|
918
|
-
[0,
|
|
1027
|
+
[(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
|
|
1028
|
+
[width, height2.neg()],
|
|
1029
|
+
[width, height2],
|
|
1030
|
+
[(0, ParamDefinition_js_1.numeric)(0), height2],
|
|
1031
|
+
[(0, ParamDefinition_js_1.numeric)(0), height2.neg()]
|
|
919
1032
|
];
|
|
920
1033
|
}
|
|
921
1034
|
else if (portType === PinTypes_js_1.PinTypes.Output) {
|
|
922
1035
|
path = [
|
|
923
|
-
[arrowSize,
|
|
924
|
-
[width,
|
|
1036
|
+
[arrowSize, height2.neg()],
|
|
1037
|
+
[width, height2.neg()],
|
|
925
1038
|
[width, height2],
|
|
926
1039
|
[arrowSize, height2],
|
|
927
|
-
[0, 0],
|
|
928
|
-
[arrowSize,
|
|
1040
|
+
[(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
|
|
1041
|
+
[arrowSize, height2.neg()]
|
|
929
1042
|
];
|
|
930
1043
|
}
|
|
931
1044
|
else if (portType === PinTypes_js_1.PinTypes.Input) {
|
|
932
1045
|
path = [
|
|
933
|
-
[0,
|
|
934
|
-
[width
|
|
935
|
-
[width, 0],
|
|
936
|
-
[width
|
|
937
|
-
[0,
|
|
938
|
-
[0,
|
|
1046
|
+
[(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
|
|
1047
|
+
[width.sub(arrowSize), height2.neg()],
|
|
1048
|
+
[width, (0, ParamDefinition_js_1.numeric)(0)],
|
|
1049
|
+
[width.sub(arrowSize), height2],
|
|
1050
|
+
[(0, ParamDefinition_js_1.numeric)(0), height2],
|
|
1051
|
+
[(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
|
|
939
1052
|
];
|
|
940
1053
|
}
|
|
941
1054
|
else if (portType === PinTypes_js_1.PinTypes.IO) {
|
|
942
1055
|
path = [
|
|
943
|
-
[arrowSize,
|
|
944
|
-
[width
|
|
945
|
-
[width, 0],
|
|
946
|
-
[width
|
|
947
|
-
[arrowSize,
|
|
948
|
-
[0, 0],
|
|
949
|
-
[
|
|
1056
|
+
[arrowSize, height2.neg()],
|
|
1057
|
+
[width.sub(arrowSize), height2.neg()],
|
|
1058
|
+
[width, (0, ParamDefinition_js_1.numeric)(0)],
|
|
1059
|
+
[width.sub(arrowSize), height2],
|
|
1060
|
+
[arrowSize, height2],
|
|
1061
|
+
[(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
|
|
1062
|
+
[arrowSize, height2.neg()],
|
|
950
1063
|
];
|
|
951
1064
|
}
|
|
952
1065
|
path = path.map(point => {
|
|
953
|
-
return [
|
|
1066
|
+
return [
|
|
1067
|
+
x.add(point[0].mul(scaleX)),
|
|
1068
|
+
y.add(point[1])
|
|
1069
|
+
];
|
|
954
1070
|
});
|
|
955
|
-
|
|
1071
|
+
const polygon = geometry_js_1.Geometry.polygon(path)
|
|
1072
|
+
.rotate(angle * Math.PI / 180, geometry_js_1.Geometry.point(x, y));
|
|
1073
|
+
this.items.push(polygon);
|
|
956
1074
|
return this;
|
|
957
1075
|
}
|
|
958
1076
|
addPath(...pathParts) {
|
|
@@ -961,6 +1079,9 @@ class SymbolDrawing {
|
|
|
961
1079
|
accum = accum.concat(tmp.split(" "));
|
|
962
1080
|
}
|
|
963
1081
|
else if (typeof tmp === "number") {
|
|
1082
|
+
accum.push((0, ParamDefinition_js_1.numeric)(tmp));
|
|
1083
|
+
}
|
|
1084
|
+
else if (tmp instanceof ParamDefinition_js_1.NumericValue) {
|
|
964
1085
|
accum.push(tmp);
|
|
965
1086
|
}
|
|
966
1087
|
return accum;
|
|
@@ -973,14 +1094,14 @@ class SymbolDrawing {
|
|
|
973
1094
|
if (currentObj !== null) {
|
|
974
1095
|
geomObjects.push(currentObj);
|
|
975
1096
|
}
|
|
976
|
-
const x = (0, helpers_js_1.milsToMM)(
|
|
977
|
-
const y = (0, helpers_js_1.milsToMM)(
|
|
1097
|
+
const x = (0, helpers_js_1.milsToMM)(parts[i + 1]);
|
|
1098
|
+
const y = (0, helpers_js_1.milsToMM)(parts[i + 2]);
|
|
978
1099
|
currentObj = [[x, y]];
|
|
979
1100
|
i += 2;
|
|
980
1101
|
}
|
|
981
1102
|
else if (command === 'L') {
|
|
982
|
-
const x = (0, helpers_js_1.milsToMM)(
|
|
983
|
-
const y = (0, helpers_js_1.milsToMM)(
|
|
1103
|
+
const x = (0, helpers_js_1.milsToMM)(parts[i + 1]);
|
|
1104
|
+
const y = (0, helpers_js_1.milsToMM)(parts[i + 2]);
|
|
984
1105
|
currentObj.push([x, y]);
|
|
985
1106
|
i += 2;
|
|
986
1107
|
}
|
|
@@ -1026,8 +1147,8 @@ class SymbolDrawing {
|
|
|
1026
1147
|
x = (0, helpers_js_1.milsToMM)(x);
|
|
1027
1148
|
y = (0, helpers_js_1.milsToMM)(y);
|
|
1028
1149
|
radius = (0, helpers_js_1.milsToMM)(radius);
|
|
1029
|
-
startAngle = startAngle
|
|
1030
|
-
endAngle = endAngle
|
|
1150
|
+
startAngle = startAngle.mul(Math.PI).div(180);
|
|
1151
|
+
endAngle = endAngle.mul(Math.PI).div(180);
|
|
1031
1152
|
this.items.push(geometry_js_1.Geometry.arc([x, y], radius, startAngle, endAngle, true));
|
|
1032
1153
|
return this;
|
|
1033
1154
|
}
|
|
@@ -1037,7 +1158,7 @@ class SymbolDrawing {
|
|
|
1037
1158
|
}
|
|
1038
1159
|
getPaths() {
|
|
1039
1160
|
let currentFill = "#fff";
|
|
1040
|
-
let currentLineWidth = 1;
|
|
1161
|
+
let currentLineWidth = (0, ParamDefinition_js_1.numeric)(1);
|
|
1041
1162
|
let currentLineColor = '#333';
|
|
1042
1163
|
const pathItems = [];
|
|
1043
1164
|
this.items.forEach(item => {
|
|
@@ -1104,7 +1225,7 @@ class SymbolDrawing {
|
|
|
1104
1225
|
}
|
|
1105
1226
|
getPinPosition(pinId) {
|
|
1106
1227
|
const pin = this.pins.find(item => {
|
|
1107
|
-
return item[0] === pinId;
|
|
1228
|
+
return item[0].toNumber() === pinId;
|
|
1108
1229
|
});
|
|
1109
1230
|
if (pin) {
|
|
1110
1231
|
const [, feature, angle] = pin;
|
|
@@ -1142,5 +1263,8 @@ class SymbolDrawingCommands extends SymbolDrawing {
|
|
|
1142
1263
|
cloned.variables = this.variables;
|
|
1143
1264
|
return cloned;
|
|
1144
1265
|
}
|
|
1266
|
+
eq(other) {
|
|
1267
|
+
return this.callback === other.callback;
|
|
1268
|
+
}
|
|
1145
1269
|
}
|
|
1146
1270
|
exports.SymbolDrawingCommands = SymbolDrawingCommands;
|