circuitscript 0.0.29 → 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 +330 -87
- package/dist/cjs/execute.js +39 -14
- package/dist/cjs/geometry.js +79 -18
- package/dist/cjs/globals.js +36 -6
- 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 +64 -3
- package/dist/cjs/render.js +20 -14
- package/dist/cjs/sizing.js +4 -6
- package/dist/cjs/utils.js +29 -5
- package/dist/cjs/visitor.js +176 -10
- package/dist/esm/BaseVisitor.mjs +6 -1
- package/dist/esm/antlr/CircuitScriptLexer.mjs +204 -200
- package/dist/esm/antlr/CircuitScriptParser.mjs +1061 -1171
- package/dist/esm/antlr/CircuitScriptVisitor.mjs +3 -0
- package/dist/esm/draw_symbols.mjs +324 -85
- package/dist/esm/execute.mjs +40 -15
- package/dist/esm/geometry.mjs +79 -17
- package/dist/esm/globals.mjs +35 -5
- 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 +64 -3
- package/dist/esm/render.mjs +21 -15
- package/dist/esm/sizing.mjs +3 -4
- package/dist/esm/utils.mjs +26 -4
- package/dist/esm/visitor.mjs +179 -13
- package/dist/types/antlr/CircuitScriptLexer.d.ts +42 -41
- package/dist/types/antlr/CircuitScriptParser.d.ts +144 -133
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -0
- package/dist/types/draw_symbols.d.ts +15 -2
- package/dist/types/execute.d.ts +5 -4
- package/dist/types/geometry.d.ts +4 -3
- package/dist/types/globals.d.ts +31 -3
- 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 +58 -41
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { milsToMM } from "./helpers.mjs";
|
|
2
|
+
import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "./globals.mjs";
|
|
2
3
|
import { Geometry, GeometryProp, HorizontalAlign, Textbox, VerticalAlign } from "./geometry.mjs";
|
|
3
4
|
import { PinTypes } from "./objects/PinTypes.mjs";
|
|
4
|
-
|
|
5
|
+
import { roundValue } from "./utils.mjs";
|
|
5
6
|
export class SymbolGraphic {
|
|
6
7
|
drawPortsName = true;
|
|
7
|
-
displayBounds =
|
|
8
|
+
displayBounds = false;
|
|
8
9
|
drawing;
|
|
9
10
|
_angle = 0;
|
|
10
11
|
_flipX = 0;
|
|
@@ -51,6 +52,7 @@ export class SymbolGraphic {
|
|
|
51
52
|
this.drawPins(innerGroup);
|
|
52
53
|
this.drawLabels(innerGroup);
|
|
53
54
|
this.drawPlaceRemove(innerGroup, extra);
|
|
55
|
+
this.displayBounds && this.drawBounds(group);
|
|
54
56
|
}
|
|
55
57
|
drawPlaceRemove(group, extra) {
|
|
56
58
|
if (extra && extra.place === false) {
|
|
@@ -69,8 +71,8 @@ export class SymbolGraphic {
|
|
|
69
71
|
pinPosition(id) {
|
|
70
72
|
const pin = this.drawing.getPinPosition(id);
|
|
71
73
|
const [x, y] = pin.start;
|
|
72
|
-
const useX =
|
|
73
|
-
const useY =
|
|
74
|
+
const useX = roundValue(x);
|
|
75
|
+
const useY = roundValue(y);
|
|
74
76
|
return {
|
|
75
77
|
x: useX,
|
|
76
78
|
y: useY,
|
|
@@ -79,15 +81,16 @@ export class SymbolGraphic {
|
|
|
79
81
|
}
|
|
80
82
|
drawBounds(group) {
|
|
81
83
|
const bbox = this.drawing.getBoundingBox();
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
const originSize = milsToMM(10);
|
|
85
|
+
group.circle(originSize)
|
|
86
|
+
.translate(-originSize / 2, -originSize / 2)
|
|
84
87
|
.fill('red')
|
|
85
88
|
.stroke('none');
|
|
86
89
|
group.rect(bbox.width, bbox.height)
|
|
87
90
|
.translate(bbox.start[0], bbox.start[1])
|
|
88
91
|
.fill('none')
|
|
89
92
|
.stroke({
|
|
90
|
-
width:
|
|
93
|
+
width: milsToMM(2),
|
|
91
94
|
color: '#ccc',
|
|
92
95
|
});
|
|
93
96
|
}
|
|
@@ -117,7 +120,7 @@ export class SymbolGraphic {
|
|
|
117
120
|
const labels = this.drawing.getLabels();
|
|
118
121
|
labels.forEach(label => {
|
|
119
122
|
const tmpLabel = label;
|
|
120
|
-
const { fontSize =
|
|
123
|
+
const { fontSize = 50, anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', angle: labelAngle = 0, textColor = "#333", } = tmpLabel.style ?? {};
|
|
121
124
|
let anchorStyle = 'start';
|
|
122
125
|
let dominantBaseline = 'auto';
|
|
123
126
|
let useAnchor = anchor;
|
|
@@ -158,15 +161,6 @@ export class SymbolGraphic {
|
|
|
158
161
|
}
|
|
159
162
|
const useFont = defaultFont;
|
|
160
163
|
const textContainer = group.group();
|
|
161
|
-
const text = textContainer.text(tmpLabel.text)
|
|
162
|
-
.fill(textColor)
|
|
163
|
-
.font({
|
|
164
|
-
family: useFont,
|
|
165
|
-
size: fontSize,
|
|
166
|
-
anchor: anchorStyle,
|
|
167
|
-
'dominant-baseline': dominantBaseline,
|
|
168
|
-
weight: fontWeight,
|
|
169
|
-
});
|
|
170
164
|
let translateX, translateY;
|
|
171
165
|
let useRotateAngle = 0;
|
|
172
166
|
if (isRotation180) {
|
|
@@ -179,26 +173,121 @@ export class SymbolGraphic {
|
|
|
179
173
|
translateY = position[1];
|
|
180
174
|
useRotateAngle = this.angle;
|
|
181
175
|
}
|
|
182
|
-
translateX =
|
|
183
|
-
translateY =
|
|
184
|
-
|
|
176
|
+
translateX = roundValue(translateX);
|
|
177
|
+
translateY = roundValue(translateY);
|
|
178
|
+
const { portType = null } = tmpLabel.style;
|
|
179
|
+
if (portType !== null) {
|
|
180
|
+
const { x: boundsX, y: boundsY } = tmpLabel.textMeasurementBounds;
|
|
181
|
+
const paddingHorizontal = PortPaddingHorizontal;
|
|
182
|
+
const paddingVert = PortPaddingVertical;
|
|
183
|
+
const boundsWidth = tmpLabel.textMeasurementBounds.width
|
|
184
|
+
+ paddingHorizontal * 2;
|
|
185
|
+
const boundsHeight = tmpLabel.textMeasurementBounds.height
|
|
186
|
+
+ paddingVert * 2;
|
|
187
|
+
let path = [];
|
|
188
|
+
let boundsTranslateX = -paddingHorizontal;
|
|
189
|
+
switch (portType) {
|
|
190
|
+
case PinTypes.Input:
|
|
191
|
+
path = ['M', 0, 0,
|
|
192
|
+
'L', boundsWidth, 0,
|
|
193
|
+
'L', boundsWidth, boundsHeight,
|
|
194
|
+
'L', 0, boundsHeight,
|
|
195
|
+
'L', -PortArrowSize, boundsHeight / 2,
|
|
196
|
+
'Z',
|
|
197
|
+
];
|
|
198
|
+
break;
|
|
199
|
+
case PinTypes.Output:
|
|
200
|
+
path = ['M', 0, 0,
|
|
201
|
+
'L', boundsWidth, 0,
|
|
202
|
+
'L', boundsWidth + PortArrowSize,
|
|
203
|
+
boundsHeight / 2,
|
|
204
|
+
'L', boundsWidth, boundsHeight,
|
|
205
|
+
'L', 0, boundsHeight,
|
|
206
|
+
'Z',
|
|
207
|
+
];
|
|
208
|
+
break;
|
|
209
|
+
case PinTypes.IO:
|
|
210
|
+
path = ['M', 0, 0,
|
|
211
|
+
'L', boundsWidth, 0,
|
|
212
|
+
'L', boundsWidth + PortArrowSize,
|
|
213
|
+
boundsHeight / 2,
|
|
214
|
+
'L', boundsWidth, boundsHeight,
|
|
215
|
+
'L', 0, boundsHeight,
|
|
216
|
+
'L', -PortArrowSize, boundsHeight / 2,
|
|
217
|
+
'Z',
|
|
218
|
+
];
|
|
219
|
+
break;
|
|
220
|
+
case PinTypes.Any:
|
|
221
|
+
case PinTypes.Power:
|
|
222
|
+
path = ['M', 0, 0,
|
|
223
|
+
'L', boundsWidth, 0,
|
|
224
|
+
'L', boundsWidth, boundsHeight,
|
|
225
|
+
'L', 0, boundsHeight,
|
|
226
|
+
'Z',
|
|
227
|
+
];
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
if (path.length > 0) {
|
|
231
|
+
let flip = 1;
|
|
232
|
+
if (this.flipX !== 0) {
|
|
233
|
+
flip = -1;
|
|
234
|
+
boundsTranslateX = paddingHorizontal;
|
|
235
|
+
}
|
|
236
|
+
textContainer.path(path)
|
|
237
|
+
.stroke({
|
|
238
|
+
width: milsToMM(5),
|
|
239
|
+
color: '#333'
|
|
240
|
+
})
|
|
241
|
+
.fill('none')
|
|
242
|
+
.scale(flip, 1, 0, 0)
|
|
243
|
+
.translate(boundsTranslateX, boundsY - paddingVert);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const drawTextBounds = false;
|
|
247
|
+
const drawBoxBounds = false;
|
|
248
|
+
const drawOrigin = false;
|
|
249
|
+
if (drawBoxBounds) {
|
|
250
|
+
const box = tmpLabel.box;
|
|
251
|
+
textContainer.rect(box.width, box.height).fill('red')
|
|
252
|
+
.translate(box.xmin, box.ymin)
|
|
253
|
+
.scale(this.flipX !== 0 ? -1 : 1, 1, -box.xmin, box.ymin);
|
|
254
|
+
}
|
|
255
|
+
if (drawTextBounds) {
|
|
256
|
+
const textBounds = tmpLabel.textMeasurementBounds;
|
|
257
|
+
const xOffset = (this.flipX !== 0) ? textBounds.width : 0;
|
|
258
|
+
textContainer.rect(textBounds.width, textBounds.height).fill('#cccccc')
|
|
259
|
+
.translate(textBounds.x - xOffset, textBounds.y);
|
|
260
|
+
}
|
|
185
261
|
textContainer.translate(translateX, translateY)
|
|
186
262
|
.rotate(useRotateAngle, -translateX, -translateY);
|
|
263
|
+
textContainer.text(tmpLabel.text)
|
|
264
|
+
.fill(textColor)
|
|
265
|
+
.font({
|
|
266
|
+
family: useFont,
|
|
267
|
+
size: fontSize * fontDisplayScale,
|
|
268
|
+
anchor: anchorStyle,
|
|
269
|
+
'dominant-baseline': dominantBaseline,
|
|
270
|
+
weight: fontWeight,
|
|
271
|
+
})
|
|
272
|
+
.rotate(labelAngle);
|
|
187
273
|
const { a, b, c, d, e, f } = textContainer.matrix();
|
|
188
274
|
const newMatrix = {
|
|
189
|
-
a:
|
|
190
|
-
b:
|
|
191
|
-
c:
|
|
192
|
-
d:
|
|
193
|
-
e:
|
|
194
|
-
f:
|
|
275
|
+
a: roundValue(a),
|
|
276
|
+
b: roundValue(b),
|
|
277
|
+
c: roundValue(c),
|
|
278
|
+
d: roundValue(d),
|
|
279
|
+
e: roundValue(e),
|
|
280
|
+
f: roundValue(f),
|
|
195
281
|
};
|
|
196
282
|
textContainer.transform(newMatrix);
|
|
283
|
+
if (drawOrigin) {
|
|
284
|
+
const originSize = milsToMM(10);
|
|
285
|
+
textContainer.circle(originSize)
|
|
286
|
+
.translate(originSize / 2, originSize / 2)
|
|
287
|
+
.fill('green');
|
|
288
|
+
}
|
|
197
289
|
});
|
|
198
290
|
}
|
|
199
|
-
roundValues(value) {
|
|
200
|
-
return +value.toFixed(7);
|
|
201
|
-
}
|
|
202
291
|
flipTextAnchor(value) {
|
|
203
292
|
if (value === HorizontalAlign.Left) {
|
|
204
293
|
return HorizontalAlign.Right;
|
|
@@ -247,7 +336,7 @@ export class SymbolPointHidden extends SymbolGraphic {
|
|
|
247
336
|
}
|
|
248
337
|
export class SymbolText extends SymbolGraphic {
|
|
249
338
|
text;
|
|
250
|
-
fontSize =
|
|
339
|
+
fontSize = 40;
|
|
251
340
|
fontWeight = 'regular';
|
|
252
341
|
constructor(text) {
|
|
253
342
|
super();
|
|
@@ -272,8 +361,10 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
272
361
|
drawing.flipX = this._flipX;
|
|
273
362
|
drawing.flipY = this._flipY;
|
|
274
363
|
const commands = [
|
|
364
|
+
[PlaceHolderCommands.units, ['mils'], {}],
|
|
275
365
|
[PlaceHolderCommands.lineColor, [ColorScheme.PinLineColor], {}],
|
|
276
366
|
[PlaceHolderCommands.textColor, [ColorScheme.PinNameColor], {}],
|
|
367
|
+
[PlaceHolderCommands.lineWidth, [5], {}],
|
|
277
368
|
...drawing.getCommands()
|
|
278
369
|
];
|
|
279
370
|
drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
|
|
@@ -360,12 +451,17 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
360
451
|
drawing.addTextbox(offsetX, offsetY, content, style);
|
|
361
452
|
break;
|
|
362
453
|
}
|
|
454
|
+
case PlaceHolderCommands.units: {
|
|
455
|
+
drawing.addSetUnits(...positionParams);
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
363
458
|
}
|
|
364
459
|
});
|
|
365
460
|
drawing.log("=== end generate drawing ===");
|
|
366
461
|
}
|
|
367
462
|
parseLabelStyle(keywordParams) {
|
|
368
|
-
const keywords = ['fontSize', 'anchor', 'vanchor',
|
|
463
|
+
const keywords = ['fontSize', 'anchor', 'vanchor',
|
|
464
|
+
'angle', 'textColor', 'portType'];
|
|
369
465
|
const style = {};
|
|
370
466
|
keywords.forEach(item => {
|
|
371
467
|
if (keywordParams.has(item)) {
|
|
@@ -376,6 +472,7 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
376
472
|
}
|
|
377
473
|
drawPinParams(drawing, commandName, keywordParams, positionParams, lineColor, pinNameColor) {
|
|
378
474
|
drawing.log('add pin', ...positionParams);
|
|
475
|
+
positionParams = [...positionParams];
|
|
379
476
|
const keywordDisplayPinId = 'display_pin_id';
|
|
380
477
|
let displayPinId = true;
|
|
381
478
|
if (keywordParams.has(keywordDisplayPinId)) {
|
|
@@ -394,10 +491,10 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
394
491
|
pinNameParam = positionParams[1];
|
|
395
492
|
positionParams = [positionParams[0], ...positionParams.slice(2)];
|
|
396
493
|
}
|
|
397
|
-
const startX = positionParams[1];
|
|
398
|
-
const startY = positionParams[2];
|
|
494
|
+
const startX = milsToMM(positionParams[1]);
|
|
495
|
+
const startY = milsToMM(positionParams[2]);
|
|
399
496
|
if (commandName === PlaceHolderCommands.vpin) {
|
|
400
|
-
const magnitude = positionParams[3];
|
|
497
|
+
const magnitude = milsToMM(positionParams[3]);
|
|
401
498
|
positionParams = [
|
|
402
499
|
positionParams[0],
|
|
403
500
|
startX,
|
|
@@ -407,7 +504,7 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
407
504
|
];
|
|
408
505
|
}
|
|
409
506
|
else if (commandName === PlaceHolderCommands.hpin) {
|
|
410
|
-
const magnitude = positionParams[3];
|
|
507
|
+
const magnitude = milsToMM(positionParams[3]);
|
|
411
508
|
positionParams = [
|
|
412
509
|
positionParams[0],
|
|
413
510
|
startX,
|
|
@@ -416,49 +513,61 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
416
513
|
startY
|
|
417
514
|
];
|
|
418
515
|
}
|
|
419
|
-
|
|
516
|
+
else {
|
|
517
|
+
const [, , , endX, endY] = positionParams;
|
|
518
|
+
positionParams = [
|
|
519
|
+
positionParams[0],
|
|
520
|
+
startX,
|
|
521
|
+
startY,
|
|
522
|
+
milsToMM(endX),
|
|
523
|
+
milsToMM(endY)
|
|
524
|
+
];
|
|
525
|
+
}
|
|
526
|
+
drawing.addPinMM(...positionParams, lineColor);
|
|
420
527
|
const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
|
|
421
528
|
const [pinId, , angle] = lastAddedPin;
|
|
422
529
|
const [, , , endX, endY] = positionParams;
|
|
423
530
|
let pinNameAlignment = HorizontalAlign.Left;
|
|
424
|
-
|
|
531
|
+
const offset1 = 15;
|
|
532
|
+
const offset2 = 15;
|
|
533
|
+
let pinNameOffsetX = milsToMM(offset1);
|
|
425
534
|
let pinIdOffsetX = 0;
|
|
426
535
|
let pinIdAlignment = HorizontalAlign.Left;
|
|
427
536
|
let pinIdVAlignment = VerticalAlign.Bottom;
|
|
428
|
-
let pinIdOffsetY = -
|
|
537
|
+
let pinIdOffsetY = milsToMM(-offset2);
|
|
429
538
|
switch (angle) {
|
|
430
539
|
case 0:
|
|
431
540
|
pinNameAlignment = HorizontalAlign.Left;
|
|
432
|
-
pinNameOffsetX =
|
|
541
|
+
pinNameOffsetX = milsToMM(offset1);
|
|
433
542
|
pinIdAlignment = HorizontalAlign.Right;
|
|
434
|
-
pinIdOffsetX = -
|
|
543
|
+
pinIdOffsetX = milsToMM(-offset2);
|
|
435
544
|
break;
|
|
436
545
|
case 90:
|
|
437
546
|
case 180:
|
|
438
547
|
pinNameAlignment = HorizontalAlign.Right;
|
|
439
|
-
pinNameOffsetX = -
|
|
548
|
+
pinNameOffsetX = milsToMM(-offset1);
|
|
440
549
|
pinIdAlignment = HorizontalAlign.Left;
|
|
441
|
-
pinIdOffsetX =
|
|
550
|
+
pinIdOffsetX = milsToMM(offset2);
|
|
442
551
|
break;
|
|
443
552
|
case 270:
|
|
444
553
|
pinNameAlignment = HorizontalAlign.Left;
|
|
445
|
-
pinNameOffsetX =
|
|
554
|
+
pinNameOffsetX = milsToMM(offset1);
|
|
446
555
|
pinIdAlignment = HorizontalAlign.Left;
|
|
447
|
-
pinIdOffsetX =
|
|
448
|
-
pinIdOffsetY =
|
|
556
|
+
pinIdOffsetX = milsToMM(offset2);
|
|
557
|
+
pinIdOffsetY = milsToMM(offset2);
|
|
449
558
|
pinIdVAlignment = VerticalAlign.Top;
|
|
450
559
|
break;
|
|
451
560
|
}
|
|
452
561
|
if (angle === 0 || angle === 90 || angle === 180 || angle === 270) {
|
|
453
562
|
const usePinName = pinNameParam ?? "";
|
|
454
563
|
usePinName !== "" && drawing.addLabel(endX + pinNameOffsetX, endY, usePinName, {
|
|
455
|
-
fontSize:
|
|
564
|
+
fontSize: defaultPinNameTextSize,
|
|
456
565
|
anchor: pinNameAlignment,
|
|
457
566
|
vanchor: VerticalAlign.Middle,
|
|
458
567
|
textColor: pinNameColor,
|
|
459
568
|
});
|
|
460
569
|
displayPinId && drawing.addLabel(endX + pinIdOffsetX, endY + pinIdOffsetY, pinId.toString(), {
|
|
461
|
-
fontSize:
|
|
570
|
+
fontSize: defaultPinIdTextSize,
|
|
462
571
|
anchor: pinIdAlignment,
|
|
463
572
|
vanchor: pinIdVAlignment,
|
|
464
573
|
textColor: lineColor
|
|
@@ -489,15 +598,16 @@ export var PlaceHolderCommands;
|
|
|
489
598
|
PlaceHolderCommands["lineColor"] = "lineColor";
|
|
490
599
|
PlaceHolderCommands["textColor"] = "textColor";
|
|
491
600
|
PlaceHolderCommands["text"] = "text";
|
|
601
|
+
PlaceHolderCommands["units"] = "units";
|
|
492
602
|
})(PlaceHolderCommands || (PlaceHolderCommands = {}));
|
|
493
603
|
export class SymbolCustom extends SymbolGraphic {
|
|
494
604
|
pinDefinition = [];
|
|
495
|
-
bodyWidth =
|
|
496
|
-
pinLength =
|
|
497
|
-
width = 100;
|
|
498
|
-
height = 100;
|
|
499
|
-
pinSpacing =
|
|
500
|
-
pinTextPadding = 5;
|
|
605
|
+
bodyWidth = milsToMM(400);
|
|
606
|
+
pinLength = milsToMM(100);
|
|
607
|
+
width = milsToMM(100);
|
|
608
|
+
height = milsToMM(100);
|
|
609
|
+
pinSpacing = milsToMM(100);
|
|
610
|
+
pinTextPadding = milsToMM(5);
|
|
501
611
|
pins = [];
|
|
502
612
|
_cacheLeftPins;
|
|
503
613
|
_cacheRightPins;
|
|
@@ -522,22 +632,29 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
522
632
|
const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
|
|
523
633
|
const defaultLineColor = ColorScheme.PinLineColor;
|
|
524
634
|
drawing.addSetLineColor(defaultLineColor);
|
|
525
|
-
drawing.
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
635
|
+
drawing.addSetLineWidth(5);
|
|
636
|
+
drawing.addRectMM(0, 0, bodyWidth, bodyHeight);
|
|
637
|
+
this.generateDrawingPins(drawing, bodyWidth, bodyHeight, leftPins, rightPins, defaultLineColor);
|
|
638
|
+
this.drawing = drawing;
|
|
639
|
+
this._cacheLeftPins = leftPins;
|
|
640
|
+
this._cacheRightPins = rightPins;
|
|
641
|
+
}
|
|
642
|
+
generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, leftPins, rightPins, defaultLineColor) {
|
|
643
|
+
const leftPinStart = -bodyWidthMM / 2;
|
|
644
|
+
const rightPinStart = bodyWidthMM / 2;
|
|
645
|
+
const pinStartY = -bodyHeightMM / 2;
|
|
529
646
|
leftPins.forEach(pin => {
|
|
530
647
|
const position = pin.position;
|
|
531
648
|
const pinY = pinStartY + (position + 1) * this.pinSpacing;
|
|
532
|
-
drawing.
|
|
533
|
-
drawing.addLabel(leftPinStart +
|
|
534
|
-
fontSize:
|
|
649
|
+
drawing.addPinMM(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
|
|
650
|
+
drawing.addLabel(leftPinStart + milsToMM(20), pinY, pin.text, {
|
|
651
|
+
fontSize: CustomSymbolPinTextSize,
|
|
535
652
|
anchor: HorizontalAlign.Left,
|
|
536
653
|
vanchor: VerticalAlign.Middle,
|
|
537
654
|
textColor: ColorScheme.PinNameColor,
|
|
538
655
|
});
|
|
539
|
-
drawing.addLabel(leftPinStart -
|
|
540
|
-
fontSize:
|
|
656
|
+
drawing.addLabel(leftPinStart - milsToMM(10), pinY - milsToMM(10), pin.pinId.toString(), {
|
|
657
|
+
fontSize: CustomSymbolPinIdSize,
|
|
541
658
|
anchor: HorizontalAlign.Right,
|
|
542
659
|
vanchor: VerticalAlign.Bottom,
|
|
543
660
|
textColor: defaultLineColor
|
|
@@ -546,45 +663,76 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
546
663
|
rightPins.forEach(pin => {
|
|
547
664
|
const position = pin.position;
|
|
548
665
|
const pinY = pinStartY + (position + 1) * this.pinSpacing;
|
|
549
|
-
drawing.
|
|
550
|
-
drawing.addLabel(rightPinStart -
|
|
551
|
-
fontSize:
|
|
666
|
+
drawing.addPinMM(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
|
|
667
|
+
drawing.addLabel(rightPinStart - milsToMM(20), pinY, pin.text, {
|
|
668
|
+
fontSize: CustomSymbolPinTextSize,
|
|
552
669
|
anchor: HorizontalAlign.Right,
|
|
553
670
|
vanchor: VerticalAlign.Middle,
|
|
554
671
|
textColor: ColorScheme.PinNameColor,
|
|
555
672
|
});
|
|
556
|
-
drawing.addLabel(rightPinStart +
|
|
557
|
-
fontSize:
|
|
673
|
+
drawing.addLabel(rightPinStart + milsToMM(10), pinY - milsToMM(10), pin.pinId.toString(), {
|
|
674
|
+
fontSize: CustomSymbolPinIdSize,
|
|
558
675
|
anchor: HorizontalAlign.Left,
|
|
559
676
|
vanchor: VerticalAlign.Bottom,
|
|
560
677
|
textColor: defaultLineColor
|
|
561
678
|
});
|
|
562
679
|
});
|
|
563
680
|
const instanceName = this.getLabelValue("refdes");
|
|
564
|
-
instanceName && drawing.addLabel(-
|
|
565
|
-
fontSize:
|
|
681
|
+
instanceName && drawing.addLabel(-bodyWidthMM / 2, -bodyHeightMM / 2 - milsToMM(20), instanceName, {
|
|
682
|
+
fontSize: CustomSymbolRefDesSize,
|
|
566
683
|
anchor: HorizontalAlign.Left,
|
|
567
684
|
});
|
|
568
685
|
const acceptedMPNKeys = ['MPN', 'mpn', 'manufacturer_pn'];
|
|
569
686
|
acceptedMPNKeys.some(key => {
|
|
570
687
|
const labelValue = this.getLabelValue(key);
|
|
571
688
|
if (labelValue !== undefined) {
|
|
572
|
-
drawing.addLabel(-
|
|
573
|
-
fontSize:
|
|
689
|
+
drawing.addLabel(-bodyWidthMM / 2, bodyHeightMM / 2 + milsToMM(20), labelValue, {
|
|
690
|
+
fontSize: CustomSymbolParamTextSize,
|
|
574
691
|
anchor: HorizontalAlign.Left,
|
|
575
692
|
vanchor: VerticalAlign.Top,
|
|
576
693
|
});
|
|
577
694
|
}
|
|
578
695
|
});
|
|
579
|
-
this.drawing = drawing;
|
|
580
|
-
this._cacheLeftPins = leftPins;
|
|
581
|
-
this._cacheRightPins = rightPins;
|
|
582
696
|
}
|
|
583
697
|
calculateSize() {
|
|
584
698
|
this.width = this.bodyWidth + 2 * this.pinLength;
|
|
585
699
|
this.height = (1 + Math.max(this._cacheLeftPins.length, this._cacheRightPins.length)) * this.pinSpacing;
|
|
586
700
|
}
|
|
587
701
|
}
|
|
702
|
+
export class SymbolCustomModule extends SymbolCustom {
|
|
703
|
+
pinLength = 0;
|
|
704
|
+
portWidth = milsToMM(100);
|
|
705
|
+
portHeight = milsToMM(50);
|
|
706
|
+
generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, leftPins, rightPins, defaultLineColor) {
|
|
707
|
+
const leftPinStart = -bodyWidthMM / 2;
|
|
708
|
+
const rightPinStart = bodyWidthMM / 2;
|
|
709
|
+
const pinStartY = -bodyHeightMM / 2;
|
|
710
|
+
leftPins.forEach(pin => {
|
|
711
|
+
const position = pin.position;
|
|
712
|
+
const pinY = pinStartY + (position + 1) * this.pinSpacing;
|
|
713
|
+
drawing.addPinMM(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
|
|
714
|
+
drawing.addModulePort(leftPinStart, pinY, this.portWidth, this.portHeight, pin.pinType);
|
|
715
|
+
drawing.addLabel(leftPinStart + this.portWidth + milsToMM(20), pinY, pin.text, {
|
|
716
|
+
fontSize: 40,
|
|
717
|
+
anchor: HorizontalAlign.Left,
|
|
718
|
+
vanchor: VerticalAlign.Middle,
|
|
719
|
+
textColor: ColorScheme.PinNameColor,
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
rightPins.forEach(pin => {
|
|
723
|
+
const position = pin.position;
|
|
724
|
+
const pinY = pinStartY + (position + 1) * this.pinSpacing;
|
|
725
|
+
drawing.addPinMM(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
|
|
726
|
+
drawing.addModulePort(rightPinStart, pinY, this.portWidth, this.portHeight, pin.pinType, -1);
|
|
727
|
+
drawing.addLabel(rightPinStart - this.portWidth - milsToMM(20), pinY, pin.text, {
|
|
728
|
+
fontSize: 40,
|
|
729
|
+
anchor: HorizontalAlign.Right,
|
|
730
|
+
vanchor: VerticalAlign.Middle,
|
|
731
|
+
textColor: ColorScheme.PinNameColor,
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
588
736
|
export class SymbolDrawing {
|
|
589
737
|
items = [];
|
|
590
738
|
pins = [];
|
|
@@ -601,44 +749,68 @@ export class SymbolDrawing {
|
|
|
601
749
|
this.logger && this.logger.add(params.join(' '));
|
|
602
750
|
}
|
|
603
751
|
addLine(startX, startY, endX, endY) {
|
|
752
|
+
startX = milsToMM(startX);
|
|
753
|
+
startY = milsToMM(startY);
|
|
754
|
+
endX = milsToMM(endX);
|
|
755
|
+
endY = milsToMM(endY);
|
|
604
756
|
this.items.push(Geometry.segment([startX, startY], [endX, endY]));
|
|
605
757
|
return this;
|
|
606
758
|
}
|
|
607
759
|
addPin(pinId, startX, startY, endX, endY, lineColor) {
|
|
760
|
+
startX = milsToMM(startX);
|
|
761
|
+
startY = milsToMM(startY);
|
|
762
|
+
endX = milsToMM(endX);
|
|
763
|
+
endY = milsToMM(endY);
|
|
764
|
+
return this.addPinMM(pinId, startX, startY, endX, endY, lineColor);
|
|
765
|
+
}
|
|
766
|
+
addPinMM(pinId, startXMM, startYMM, endXMM, endYMM, lineColor) {
|
|
608
767
|
let angle = 0;
|
|
609
|
-
if (
|
|
610
|
-
if (
|
|
768
|
+
if (startXMM === endXMM) {
|
|
769
|
+
if (startYMM > endYMM) {
|
|
611
770
|
angle = 270;
|
|
612
771
|
}
|
|
613
|
-
else if (
|
|
772
|
+
else if (startYMM < endYMM) {
|
|
614
773
|
angle = 90;
|
|
615
774
|
}
|
|
616
775
|
}
|
|
617
776
|
else {
|
|
618
|
-
if (
|
|
777
|
+
if (startXMM < endXMM) {
|
|
619
778
|
angle = 0;
|
|
620
779
|
}
|
|
621
|
-
else if (
|
|
780
|
+
else if (startXMM > endXMM) {
|
|
622
781
|
angle = 180;
|
|
623
782
|
}
|
|
624
783
|
}
|
|
625
784
|
this.pins.push([
|
|
626
785
|
pinId,
|
|
627
|
-
Geometry.segment([
|
|
786
|
+
Geometry.segment([startXMM, startYMM], [endXMM, endYMM]),
|
|
628
787
|
angle,
|
|
629
788
|
lineColor
|
|
630
789
|
]);
|
|
631
790
|
return this;
|
|
632
791
|
}
|
|
633
792
|
addVLine(startX, startY, value) {
|
|
793
|
+
startX = milsToMM(startX);
|
|
794
|
+
startY = milsToMM(startY);
|
|
795
|
+
value = milsToMM(value);
|
|
634
796
|
this.items.push(Geometry.segment([startX, startY], [startX, startY + value]));
|
|
635
797
|
return this;
|
|
636
798
|
}
|
|
637
799
|
addHLine(startX, startY, value) {
|
|
800
|
+
startX = milsToMM(startX);
|
|
801
|
+
startY = milsToMM(startY);
|
|
802
|
+
value = milsToMM(value);
|
|
638
803
|
this.items.push(Geometry.segment([startX, startY], [startX + value, startY]));
|
|
639
804
|
return this;
|
|
640
805
|
}
|
|
641
806
|
addRect(centerX, centerY, width, height) {
|
|
807
|
+
centerX = milsToMM(centerX);
|
|
808
|
+
centerY = milsToMM(centerY);
|
|
809
|
+
width = milsToMM(width);
|
|
810
|
+
height = milsToMM(height);
|
|
811
|
+
return this.addRectMM(centerX, centerY, width, height);
|
|
812
|
+
}
|
|
813
|
+
addRectMM(centerX, centerY, width, height) {
|
|
642
814
|
const width2 = width / 2;
|
|
643
815
|
const height2 = height / 2;
|
|
644
816
|
this.items.push(Geometry.polygon([
|
|
@@ -651,6 +823,11 @@ export class SymbolDrawing {
|
|
|
651
823
|
return this;
|
|
652
824
|
}
|
|
653
825
|
addTriangle(startX, startY, endX, endY, width) {
|
|
826
|
+
startX = milsToMM(startX);
|
|
827
|
+
startY = milsToMM(startY);
|
|
828
|
+
endX = milsToMM(endX);
|
|
829
|
+
endY = milsToMM(endY);
|
|
830
|
+
width = milsToMM(width);
|
|
654
831
|
const line = Geometry.line(startX, startY, endX, endY);
|
|
655
832
|
const normLine = line.norm;
|
|
656
833
|
const dx1 = normLine.x * width / 2;
|
|
@@ -680,13 +857,67 @@ export class SymbolDrawing {
|
|
|
680
857
|
return this;
|
|
681
858
|
}
|
|
682
859
|
addLabelId(id, x, y, textValue, style) {
|
|
860
|
+
x = milsToMM(x);
|
|
861
|
+
y = milsToMM(y);
|
|
683
862
|
this.items.push(Geometry.label(id, x, y, textValue, style));
|
|
684
863
|
return this;
|
|
685
864
|
}
|
|
686
865
|
addTextbox(x, y, textValue, style) {
|
|
866
|
+
x = milsToMM(x);
|
|
867
|
+
y = milsToMM(y);
|
|
687
868
|
this.items.push(Geometry.textbox(null, x, y, textValue, style));
|
|
688
869
|
return this;
|
|
689
870
|
}
|
|
871
|
+
addModulePort(x, y, width, height, portType = PinTypes.Any, scaleX = 1) {
|
|
872
|
+
const height2 = height / 2;
|
|
873
|
+
let path = [];
|
|
874
|
+
const arrowSize = milsToMM(30);
|
|
875
|
+
if (portType === PinTypes.Any) {
|
|
876
|
+
path = [
|
|
877
|
+
[0, -height2],
|
|
878
|
+
[width, -height2],
|
|
879
|
+
[width, +height2],
|
|
880
|
+
[0, +height2],
|
|
881
|
+
[0, -height2]
|
|
882
|
+
];
|
|
883
|
+
}
|
|
884
|
+
else if (portType === PinTypes.Output) {
|
|
885
|
+
path = [
|
|
886
|
+
[arrowSize, -height2],
|
|
887
|
+
[width, -height2],
|
|
888
|
+
[width, height2],
|
|
889
|
+
[arrowSize, height2],
|
|
890
|
+
[0, 0],
|
|
891
|
+
[arrowSize, -height2]
|
|
892
|
+
];
|
|
893
|
+
}
|
|
894
|
+
else if (portType === PinTypes.Input) {
|
|
895
|
+
path = [
|
|
896
|
+
[0, -height2],
|
|
897
|
+
[width - arrowSize, -height2],
|
|
898
|
+
[width, 0],
|
|
899
|
+
[width - arrowSize, height2],
|
|
900
|
+
[0, +height2],
|
|
901
|
+
[0, -height2],
|
|
902
|
+
];
|
|
903
|
+
}
|
|
904
|
+
else if (portType === PinTypes.IO) {
|
|
905
|
+
path = [
|
|
906
|
+
[arrowSize, -height2],
|
|
907
|
+
[width - arrowSize, -height2],
|
|
908
|
+
[width, 0],
|
|
909
|
+
[width - arrowSize, +height2],
|
|
910
|
+
[arrowSize, +height2],
|
|
911
|
+
[0, 0],
|
|
912
|
+
[0 + arrowSize, -height2],
|
|
913
|
+
];
|
|
914
|
+
}
|
|
915
|
+
path = path.map(point => {
|
|
916
|
+
return [x + point[0] * scaleX, y + point[1]];
|
|
917
|
+
});
|
|
918
|
+
this.items.push(Geometry.polygon(path));
|
|
919
|
+
return this;
|
|
920
|
+
}
|
|
690
921
|
addPath(...pathParts) {
|
|
691
922
|
const parts = pathParts.reduce((accum, tmp) => {
|
|
692
923
|
if (typeof tmp === "string") {
|
|
@@ -705,14 +936,14 @@ export class SymbolDrawing {
|
|
|
705
936
|
if (currentObj !== null) {
|
|
706
937
|
geomObjects.push(currentObj);
|
|
707
938
|
}
|
|
708
|
-
const x = Number(parts[i + 1]);
|
|
709
|
-
const y = Number(parts[i + 2]);
|
|
939
|
+
const x = milsToMM(Number(parts[i + 1]));
|
|
940
|
+
const y = milsToMM(Number(parts[i + 2]));
|
|
710
941
|
currentObj = [[x, y]];
|
|
711
942
|
i += 2;
|
|
712
943
|
}
|
|
713
944
|
else if (command === 'L') {
|
|
714
|
-
const x = Number(parts[i + 1]);
|
|
715
|
-
const y = Number(parts[i + 2]);
|
|
945
|
+
const x = milsToMM(Number(parts[i + 1]));
|
|
946
|
+
const y = milsToMM(Number(parts[i + 2]));
|
|
716
947
|
currentObj.push([x, y]);
|
|
717
948
|
i += 2;
|
|
718
949
|
}
|
|
@@ -738,6 +969,7 @@ export class SymbolDrawing {
|
|
|
738
969
|
return this;
|
|
739
970
|
}
|
|
740
971
|
addSetLineWidth(value) {
|
|
972
|
+
value = milsToMM(value);
|
|
741
973
|
this.items.push(new GeometryProp('lineWidth', value));
|
|
742
974
|
return this;
|
|
743
975
|
}
|
|
@@ -754,11 +986,18 @@ export class SymbolDrawing {
|
|
|
754
986
|
return this;
|
|
755
987
|
}
|
|
756
988
|
addArc(x, y, radius, startAngle, endAngle) {
|
|
989
|
+
x = milsToMM(x);
|
|
990
|
+
y = milsToMM(y);
|
|
991
|
+
radius = milsToMM(radius);
|
|
757
992
|
startAngle = startAngle * Math.PI / 180;
|
|
758
993
|
endAngle = endAngle * Math.PI / 180;
|
|
759
994
|
this.items.push(Geometry.arc([x, y], radius, startAngle, endAngle, true));
|
|
760
995
|
return this;
|
|
761
996
|
}
|
|
997
|
+
addSetUnits(value) {
|
|
998
|
+
this.items.push(new GeometryProp('units', value));
|
|
999
|
+
return this;
|
|
1000
|
+
}
|
|
762
1001
|
getPaths() {
|
|
763
1002
|
let currentFill = "#fff";
|
|
764
1003
|
let currentLineWidth = 1;
|