circuitscript 0.1.0 → 0.1.3

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