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,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.SymbolPointHidden = exports.SymbolFactory = exports.SymbolGraphic = void 0;
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(-originSize / 2, -originSize / 2)
98
+ group.circle(originSize.toNumber())
99
+ .translate(originSize.neg().half().toNumber(), originSize.neg().half().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: labelAngle = 0, textColor = "#333", } = tmpLabel.style ?? {};
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) ? 'start' : 'end';
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 = 'middle';
153
+ anchorStyle = geometry_js_1.HorizontalAlignProp.Middle;
143
154
  break;
144
155
  case geometry_js_1.HorizontalAlign.Right:
145
- anchorStyle = (this.flipX === 0) ? 'end' : 'start';
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) ? 'hanging' : 'text-top';
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 = 'middle';
166
+ dominantBaseline = geometry_js_1.VerticalAlignProp.Central;
154
167
  break;
155
168
  case geometry_js_1.VerticalAlign.Bottom:
156
- dominantBaseline = (this.flipY === 0) ? 'text-top' : 'hanging';
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] *= -1;
175
+ position[0] = position[0].neg();
162
176
  }
163
177
  if (this.flipY !== 0) {
164
- position[1] *= -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 = -position[0];
172
- translateY = -position[1];
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
- const drawTextBounds = false;
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).fill('red')
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
- .scale(this.flipX !== 0 ? -1 : 1, 1, -box.xmin, box.ymin);
273
+ .rotate(labelAngle, -box.xmin, -box.ymin);
258
274
  }
259
- if (drawTextBounds) {
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).fill('#cccccc')
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
- .rotate(labelAngle);
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 (drawOrigin) {
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 + magnitude
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 + magnitude,
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
- switch (angle) {
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 (angle === 0 || angle === 90 || angle === 180 || angle === 270) {
598
+ if (angleValue === 0 || angleValue === 90 || angleValue === 180 || angleValue === 270) {
590
599
  const usePinName = pinNameParam ?? "";
591
- usePinName !== "" && drawing.addLabel(endX + pinNameOffsetX, endY, usePinName, {
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 + pinIdOffsetX, endY + pinIdOffsetY, pinId.toString(), {
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
@@ -613,6 +622,7 @@ var PlaceHolderCommands;
613
622
  PlaceHolderCommands["arc"] = "arc";
614
623
  PlaceHolderCommands["circle"] = "circle";
615
624
  PlaceHolderCommands["rect"] = "rect";
625
+ PlaceHolderCommands["crect"] = "crect";
616
626
  PlaceHolderCommands["triangle"] = "triangle";
617
627
  PlaceHolderCommands["pin"] = "pin";
618
628
  PlaceHolderCommands["hpin"] = "hpin";
@@ -631,59 +641,77 @@ var PlaceHolderCommands;
631
641
  PlaceHolderCommands["for"] = "for";
632
642
  })(PlaceHolderCommands || (exports.PlaceHolderCommands = PlaceHolderCommands = {}));
633
643
  class SymbolCustom extends SymbolGraphic {
634
- constructor(pinDefinition) {
644
+ constructor(pinDefinition, pinMaxPositions) {
635
645
  super();
636
646
  this.pinDefinition = [];
637
647
  this.bodyWidth = (0, helpers_js_1.milsToMM)(400);
648
+ this.bodyHeight = (0, helpers_js_1.milsToMM)(100);
638
649
  this.pinLength = (0, helpers_js_1.milsToMM)(100);
639
650
  this.width = (0, helpers_js_1.milsToMM)(100);
640
651
  this.height = (0, helpers_js_1.milsToMM)(100);
641
652
  this.pinSpacing = (0, helpers_js_1.milsToMM)(100);
642
653
  this.pinTextPadding = (0, helpers_js_1.milsToMM)(5);
643
654
  this.pins = [];
655
+ this._cacheLeftPins = [];
656
+ this._cacheRightPins = [];
657
+ this._cacheTopPins = [];
658
+ this._cacheBottomPins = [];
644
659
  this.pinDefinition = pinDefinition;
660
+ this.pinMaxPositions = pinMaxPositions;
645
661
  }
646
662
  generateDrawing() {
647
- const leftPins = this.pinDefinition.filter(item => {
648
- return item.side === globals_js_1.SymbolPinSide.Left;
649
- });
650
- const rightPins = this.pinDefinition.filter(item => {
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;
663
+ const leftPins = this.getPins(globals_js_1.SymbolPinSide.Left);
664
+ const rightPins = this.getPins(globals_js_1.SymbolPinSide.Right);
665
+ const topPins = this.getPins(globals_js_1.SymbolPinSide.Top);
666
+ const bottomPins = this.getPins(globals_js_1.SymbolPinSide.Bottom);
655
667
  this.drawing.clear();
656
668
  const drawing = this.drawing;
657
669
  drawing.angle = this._angle;
658
670
  drawing.flipX = this._flipX;
659
671
  drawing.flipY = this._flipY;
660
- const bodyWidth = this.bodyWidth;
661
- const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
672
+ const { bodyWidth, bodyHeight } = this.calculateSize();
662
673
  const defaultLineColor = globals_js_1.ColorScheme.PinLineColor;
663
674
  drawing.addSetLineColor(defaultLineColor);
664
- drawing.addSetLineWidth(5);
665
- drawing.addRectMM(0, 0, bodyWidth, bodyHeight);
666
- this.generateDrawingPins(drawing, bodyWidth, bodyHeight, leftPins, rightPins, defaultLineColor);
675
+ drawing.addSetLineWidth((0, ParamDefinition_js_1.numeric)(5));
676
+ const xBody = bodyWidth.half().neg();
677
+ const yBody = bodyHeight.half().neg();
678
+ drawing.addRectMM(xBody, yBody, bodyWidth, bodyHeight);
679
+ this.generateDrawingPins(drawing, bodyWidth, bodyHeight, {
680
+ left: leftPins, right: rightPins, top: topPins, bottom: bottomPins
681
+ }, defaultLineColor);
667
682
  this.drawing = drawing;
668
683
  this._cacheLeftPins = leftPins;
669
684
  this._cacheRightPins = rightPins;
685
+ this._cacheTopPins = topPins;
686
+ this._cacheBottomPins = bottomPins;
670
687
  }
671
- generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, leftPins, rightPins, defaultLineColor) {
672
- const leftPinStart = -bodyWidthMM / 2;
673
- const rightPinStart = bodyWidthMM / 2;
674
- const pinStartY = -bodyHeightMM / 2;
688
+ getPins(side) {
689
+ const pins = this.pinDefinition.filter(item => {
690
+ return item.side === side;
691
+ });
692
+ return pins;
693
+ }
694
+ generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, pins, defaultLineColor) {
695
+ const { left: leftPins, right: rightPins, top: topPins, bottom: bottomPins } = pins;
696
+ const leftPinStart = bodyWidthMM.neg().half();
697
+ const rightPinStart = bodyWidthMM.half();
698
+ const topPinStart = bodyHeightMM.neg().half();
699
+ const bottomPinStart = bodyHeightMM.half();
700
+ const pinStartY = bodyHeightMM.neg().half();
701
+ const pinStartX = bodyWidthMM.neg().half();
702
+ const tmpPinSpacing = this.pinSpacing.toNumber();
675
703
  leftPins.forEach(pin => {
676
704
  const position = pin.position;
677
- const pinY = pinStartY + (position + 1) * this.pinSpacing;
678
- drawing.addPinMM(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
679
- drawing.addLabel(leftPinStart + (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
680
- fontSize: globals_js_1.CustomSymbolPinTextSize,
705
+ const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
706
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
707
+ drawing.addLabel(leftPinStart.add((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
708
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
681
709
  anchor: geometry_js_1.HorizontalAlign.Left,
682
710
  vanchor: geometry_js_1.VerticalAlign.Middle,
683
711
  textColor: globals_js_1.ColorScheme.PinNameColor,
684
712
  });
685
- drawing.addLabel(leftPinStart - (0, helpers_js_1.milsToMM)(10), pinY - (0, helpers_js_1.milsToMM)(10), pin.pinId.toString(), {
686
- fontSize: globals_js_1.CustomSymbolPinIdSize,
713
+ drawing.addLabel(leftPinStart.sub((0, helpers_js_1.milsToMM)(10)), pinY.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
714
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
687
715
  anchor: geometry_js_1.HorizontalAlign.Right,
688
716
  vanchor: geometry_js_1.VerticalAlign.Bottom,
689
717
  textColor: defaultLineColor
@@ -691,32 +719,70 @@ class SymbolCustom extends SymbolGraphic {
691
719
  });
692
720
  rightPins.forEach(pin => {
693
721
  const position = pin.position;
694
- const pinY = pinStartY + (position + 1) * this.pinSpacing;
695
- drawing.addPinMM(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
696
- drawing.addLabel(rightPinStart - (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
697
- fontSize: globals_js_1.CustomSymbolPinTextSize,
722
+ const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
723
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
724
+ drawing.addLabel(rightPinStart.sub((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
725
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
698
726
  anchor: geometry_js_1.HorizontalAlign.Right,
699
727
  vanchor: geometry_js_1.VerticalAlign.Middle,
700
728
  textColor: globals_js_1.ColorScheme.PinNameColor,
701
729
  });
702
- drawing.addLabel(rightPinStart + (0, helpers_js_1.milsToMM)(10), pinY - (0, helpers_js_1.milsToMM)(10), pin.pinId.toString(), {
703
- fontSize: globals_js_1.CustomSymbolPinIdSize,
730
+ drawing.addLabel(rightPinStart.add((0, helpers_js_1.milsToMM)(10)), pinY.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
731
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
704
732
  anchor: geometry_js_1.HorizontalAlign.Left,
705
733
  vanchor: geometry_js_1.VerticalAlign.Bottom,
706
734
  textColor: defaultLineColor
707
735
  });
708
736
  });
737
+ topPins.forEach(pin => {
738
+ const position = pin.position;
739
+ const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
740
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
741
+ drawing.addLabel(pinX, topPinStart.add((0, helpers_js_1.milsToMM)(20)), pin.text, {
742
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
743
+ anchor: geometry_js_1.HorizontalAlign.Right,
744
+ vanchor: geometry_js_1.VerticalAlign.Middle,
745
+ textColor: globals_js_1.ColorScheme.PinNameColor,
746
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
747
+ });
748
+ drawing.addLabel(pinX.sub((0, helpers_js_1.milsToMM)(10)), topPinStart.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
749
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
750
+ anchor: geometry_js_1.HorizontalAlign.Left,
751
+ vanchor: geometry_js_1.VerticalAlign.Bottom,
752
+ textColor: defaultLineColor,
753
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
754
+ });
755
+ });
756
+ bottomPins.forEach(pin => {
757
+ const position = pin.position;
758
+ const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
759
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
760
+ drawing.addLabel(pinX, bottomPinStart.sub((0, helpers_js_1.milsToMM)(20)), pin.text, {
761
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
762
+ anchor: geometry_js_1.HorizontalAlign.Left,
763
+ vanchor: geometry_js_1.VerticalAlign.Middle,
764
+ textColor: globals_js_1.ColorScheme.PinNameColor,
765
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
766
+ });
767
+ drawing.addLabel(pinX.sub((0, helpers_js_1.milsToMM)(10)), bottomPinStart.add((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
768
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
769
+ anchor: geometry_js_1.HorizontalAlign.Right,
770
+ vanchor: geometry_js_1.VerticalAlign.Bottom,
771
+ textColor: defaultLineColor,
772
+ angle: (0, ParamDefinition_js_1.numeric)(-90)
773
+ });
774
+ });
709
775
  const instanceName = drawing.variables.get('refdes');
710
- instanceName && drawing.addLabel(-bodyWidthMM / 2, -bodyHeightMM / 2 - (0, helpers_js_1.milsToMM)(20), instanceName, {
711
- fontSize: globals_js_1.CustomSymbolRefDesSize,
776
+ instanceName && drawing.addLabel(bodyWidthMM.neg().half(), bodyHeightMM.neg().half().sub((0, helpers_js_1.milsToMM)(20)), instanceName, {
777
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolRefDesSize),
712
778
  anchor: geometry_js_1.HorizontalAlign.Left,
713
779
  });
714
780
  const acceptedMPNKeys = ['MPN', 'mpn', 'manufacturer_pn'];
715
781
  acceptedMPNKeys.some(key => {
716
782
  const labelValue = drawing.variables.get(key);
717
783
  if (labelValue !== undefined) {
718
- drawing.addLabel(-bodyWidthMM / 2, bodyHeightMM / 2 + (0, helpers_js_1.milsToMM)(20), labelValue, {
719
- fontSize: globals_js_1.CustomSymbolParamTextSize,
784
+ drawing.addLabel(bodyWidthMM.neg().half(), bodyHeightMM.half().add((0, helpers_js_1.milsToMM)(20)), labelValue, {
785
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolParamTextSize),
720
786
  anchor: geometry_js_1.HorizontalAlign.Left,
721
787
  vanchor: geometry_js_1.VerticalAlign.Top,
722
788
  });
@@ -724,29 +790,59 @@ class SymbolCustom extends SymbolGraphic {
724
790
  });
725
791
  }
726
792
  calculateSize() {
727
- this.width = this.bodyWidth + 2 * this.pinLength;
728
- this.height = (1 + Math.max(this._cacheLeftPins.length, this._cacheRightPins.length)) * this.pinSpacing;
793
+ const tmpPinSpacing = this.pinSpacing.toNumber();
794
+ const tmpPinLength = this.pinLength.toNumber();
795
+ 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;
796
+ const bodyWidthFromPins = (0, ParamDefinition_js_1.numeric)((1 + Math.max(maxTopPins, maxBottomPins)) * tmpPinSpacing);
797
+ const bodyWidth = Math.max(bodyWidthFromPins.toNumber(), this.bodyWidth.toNumber());
798
+ let tmpBodyHeight = 0;
799
+ if (maxLeftPins === 0 && maxRightPins === 0) {
800
+ tmpBodyHeight = 3;
801
+ }
802
+ else {
803
+ tmpBodyHeight = (1 + Math.max(maxLeftPins, maxRightPins));
804
+ }
805
+ const bodyHeight = Math.max(tmpBodyHeight * tmpPinSpacing, this.bodyHeight.toNumber());
806
+ const useHeight = bodyHeight
807
+ + ((this._cacheTopPins.length > 0) ? tmpPinLength : 0)
808
+ + ((this._cacheBottomPins.length > 0) ? tmpPinLength : 0);
809
+ const useWidth = bodyWidth
810
+ + ((this._cacheLeftPins.length > 0) ? tmpPinLength : 0)
811
+ + ((this._cacheRightPins.length > 0) ? tmpPinLength : 0);
812
+ this.width = (0, ParamDefinition_js_1.numeric)(useWidth);
813
+ this.height = (0, ParamDefinition_js_1.numeric)(useHeight);
814
+ return {
815
+ bodyWidth: (0, ParamDefinition_js_1.numeric)(bodyWidth),
816
+ bodyHeight: (0, ParamDefinition_js_1.numeric)(bodyHeight),
817
+ width: this.width,
818
+ height: this.height
819
+ };
729
820
  }
730
821
  }
731
822
  exports.SymbolCustom = SymbolCustom;
732
823
  class SymbolCustomModule extends SymbolCustom {
733
824
  constructor() {
734
825
  super(...arguments);
735
- this.pinLength = 0;
826
+ this.pinLength = (0, helpers_js_1.milsToMM)(0);
736
827
  this.portWidth = (0, helpers_js_1.milsToMM)(100);
737
828
  this.portHeight = (0, helpers_js_1.milsToMM)(50);
738
829
  }
739
- generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, leftPins, rightPins, defaultLineColor) {
740
- const leftPinStart = -bodyWidthMM / 2;
741
- const rightPinStart = bodyWidthMM / 2;
742
- const pinStartY = -bodyHeightMM / 2;
830
+ generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, pins, defaultLineColor) {
831
+ const leftPinStart = bodyWidthMM.neg().half();
832
+ const rightPinStart = bodyWidthMM.half();
833
+ const topPinStart = bodyHeightMM.neg().half();
834
+ const bottomPinStart = bodyHeightMM.half();
835
+ const pinStartY = bodyHeightMM.neg().half();
836
+ const pinStartX = bodyWidthMM.neg().half();
837
+ const tmpPinSpacing = this.pinSpacing.toNumber();
838
+ const { left: leftPins, right: rightPins, top: topPins, bottom: bottomPins } = pins;
743
839
  leftPins.forEach(pin => {
744
840
  const position = pin.position;
745
- const pinY = pinStartY + (position + 1) * this.pinSpacing;
746
- drawing.addPinMM(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
841
+ const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
842
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
747
843
  drawing.addModulePort(leftPinStart, pinY, this.portWidth, this.portHeight, pin.pinType);
748
- drawing.addLabel(leftPinStart + this.portWidth + (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
749
- fontSize: 40,
844
+ drawing.addLabel(leftPinStart.add(this.portWidth).add((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
845
+ fontSize: (0, ParamDefinition_js_1.numeric)(40),
750
846
  anchor: geometry_js_1.HorizontalAlign.Left,
751
847
  vanchor: geometry_js_1.VerticalAlign.Middle,
752
848
  textColor: globals_js_1.ColorScheme.PinNameColor,
@@ -754,16 +850,42 @@ class SymbolCustomModule extends SymbolCustom {
754
850
  });
755
851
  rightPins.forEach(pin => {
756
852
  const position = pin.position;
757
- const pinY = pinStartY + (position + 1) * this.pinSpacing;
758
- drawing.addPinMM(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
853
+ const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
854
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
759
855
  drawing.addModulePort(rightPinStart, pinY, this.portWidth, this.portHeight, pin.pinType, -1);
760
- drawing.addLabel(rightPinStart - this.portWidth - (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
761
- fontSize: 40,
856
+ drawing.addLabel(rightPinStart.sub(this.portWidth).sub((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
857
+ fontSize: (0, ParamDefinition_js_1.numeric)(40),
762
858
  anchor: geometry_js_1.HorizontalAlign.Right,
763
859
  vanchor: geometry_js_1.VerticalAlign.Middle,
764
860
  textColor: globals_js_1.ColorScheme.PinNameColor,
765
861
  });
766
862
  });
863
+ topPins.forEach(pin => {
864
+ const position = pin.position;
865
+ const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
866
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
867
+ drawing.addModulePort(pinX, topPinStart, this.portWidth, this.portHeight, pin.pinType, 1, 90);
868
+ drawing.addLabel(pinX, topPinStart.add(this.portWidth).add((0, helpers_js_1.milsToMM)(20)), pin.text, {
869
+ fontSize: (0, ParamDefinition_js_1.numeric)(40),
870
+ anchor: geometry_js_1.HorizontalAlign.Right,
871
+ vanchor: geometry_js_1.VerticalAlign.Middle,
872
+ textColor: globals_js_1.ColorScheme.PinNameColor,
873
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
874
+ });
875
+ });
876
+ bottomPins.forEach(pin => {
877
+ const position = pin.position;
878
+ const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
879
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, bottomPinStart, pinX, bottomPinStart.sub(this.pinLength), defaultLineColor);
880
+ drawing.addModulePort(pinX, bottomPinStart, this.portWidth, this.portHeight, pin.pinType, 1, -90);
881
+ drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub((0, helpers_js_1.milsToMM)(20)), pin.text, {
882
+ fontSize: (0, ParamDefinition_js_1.numeric)(40),
883
+ anchor: geometry_js_1.HorizontalAlign.Left,
884
+ vanchor: geometry_js_1.VerticalAlign.Middle,
885
+ textColor: globals_js_1.ColorScheme.PinNameColor,
886
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
887
+ });
888
+ });
767
889
  }
768
890
  }
769
891
  exports.SymbolCustomModule = SymbolCustomModule;
@@ -774,7 +896,7 @@ class SymbolDrawing {
774
896
  this.angle = 0;
775
897
  this.flipX = 0;
776
898
  this.flipY = 0;
777
- this.mainOrigin = [0, 0];
899
+ this.mainOrigin = [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)];
778
900
  this.logger = null;
779
901
  this.variables = new Map();
780
902
  }
@@ -802,26 +924,30 @@ class SymbolDrawing {
802
924
  }
803
925
  addPinMM(pinId, startXMM, startYMM, endXMM, endYMM, lineColor) {
804
926
  let angle = 0;
805
- if (startXMM === endXMM) {
806
- if (startYMM > endYMM) {
927
+ const tmpStartXMM = startXMM.toNumber();
928
+ const tmpEndXMM = endXMM.toNumber();
929
+ const tmpStartYMM = startYMM.toNumber();
930
+ const tmpEndYMM = endYMM.toNumber();
931
+ if (tmpStartXMM === tmpEndXMM) {
932
+ if (tmpStartYMM > tmpEndYMM) {
807
933
  angle = 270;
808
934
  }
809
- else if (startYMM < endYMM) {
935
+ else if (tmpStartYMM < tmpEndYMM) {
810
936
  angle = 90;
811
937
  }
812
938
  }
813
939
  else {
814
- if (startXMM < endXMM) {
940
+ if (tmpStartXMM < tmpEndXMM) {
815
941
  angle = 0;
816
942
  }
817
- else if (startXMM > endXMM) {
943
+ else if (tmpStartXMM > tmpEndXMM) {
818
944
  angle = 180;
819
945
  }
820
946
  }
821
947
  this.pins.push([
822
948
  pinId,
823
949
  geometry_js_1.Geometry.segment([startXMM, startYMM], [endXMM, endYMM]),
824
- angle,
950
+ (0, ParamDefinition_js_1.numeric)(angle),
825
951
  lineColor
826
952
  ]);
827
953
  return this;
@@ -830,32 +956,28 @@ class SymbolDrawing {
830
956
  startX = (0, helpers_js_1.milsToMM)(startX);
831
957
  startY = (0, helpers_js_1.milsToMM)(startY);
832
958
  value = (0, helpers_js_1.milsToMM)(value);
833
- this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX, startY + value]));
959
+ this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX, startY.add(value)]));
834
960
  return this;
835
961
  }
836
962
  addHLine(startX, startY, value) {
837
963
  startX = (0, helpers_js_1.milsToMM)(startX);
838
964
  startY = (0, helpers_js_1.milsToMM)(startY);
839
965
  value = (0, helpers_js_1.milsToMM)(value);
840
- this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX + value, startY]));
966
+ this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX.add(value), startY]));
841
967
  return this;
842
968
  }
843
- addRect(centerX, centerY, width, height) {
844
- centerX = (0, helpers_js_1.milsToMM)(centerX);
845
- centerY = (0, helpers_js_1.milsToMM)(centerY);
846
- width = (0, helpers_js_1.milsToMM)(width);
847
- height = (0, helpers_js_1.milsToMM)(height);
848
- return this.addRectMM(centerX, centerY, width, height);
969
+ addRect(x, y, width, height) {
970
+ return this.addRectMM((0, helpers_js_1.milsToMM)(x), (0, helpers_js_1.milsToMM)(y), (0, helpers_js_1.milsToMM)(width), (0, helpers_js_1.milsToMM)(height));
849
971
  }
850
- addRectMM(centerX, centerY, width, height) {
851
- const width2 = width / 2;
852
- const height2 = height / 2;
972
+ addRectMM(x, y, width, height) {
973
+ const x2 = x.add(width);
974
+ const y2 = y.add(height);
853
975
  this.items.push(geometry_js_1.Geometry.polygon([
854
- [centerX - width2, centerY - height2],
855
- [centerX + width2, centerY - height2],
856
- [centerX + width2, centerY + height2],
857
- [centerX - width2, centerY + height2],
858
- [centerX - width2, centerY - height2]
976
+ [x, y],
977
+ [x2, y],
978
+ [x2, y2],
979
+ [x, y2],
980
+ [x, y]
859
981
  ]));
860
982
  return this;
861
983
  }
@@ -867,25 +989,15 @@ class SymbolDrawing {
867
989
  width = (0, helpers_js_1.milsToMM)(width);
868
990
  const line = geometry_js_1.Geometry.line(startX, startY, endX, endY);
869
991
  const normLine = line.norm;
870
- const dx1 = normLine.x * width / 2;
871
- const dy1 = normLine.y * width / 2;
872
- const dx2 = normLine.x * -width / 2;
873
- const dy2 = normLine.y * -width / 2;
992
+ const dx1 = (0, ParamDefinition_js_1.numeric)(normLine.x).mul(width).half();
993
+ const dy1 = (0, ParamDefinition_js_1.numeric)(normLine.y).mul(width).half();
994
+ const dx2 = (0, ParamDefinition_js_1.numeric)(normLine.x).mul(width.neg()).half();
995
+ const dy2 = (0, ParamDefinition_js_1.numeric)(normLine.y).mul(width.neg()).half();
874
996
  this.items.push(geometry_js_1.Geometry.polygon([
875
- [dx1 + startX, dy1 + startY],
876
- [dx2 + startX, dy2 + startY],
997
+ [dx1.add(startX), dy1.add(startY)],
998
+ [dx2.add(startX), dy2.add(startY)],
877
999
  [endX, endY],
878
- [dx1 + startX, dy1 + startY],
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]
1000
+ [dx1.add(startX), dy1.add(startY)],
889
1001
  ]));
890
1002
  return this;
891
1003
  }
@@ -905,54 +1017,59 @@ class SymbolDrawing {
905
1017
  this.items.push(geometry_js_1.Geometry.textbox(null, x, y, textValue, style));
906
1018
  return this;
907
1019
  }
908
- addModulePort(x, y, width, height, portType = PinTypes_js_1.PinTypes.Any, scaleX = 1) {
909
- const height2 = height / 2;
1020
+ addModulePort(x, y, width, height, portType = PinTypes_js_1.PinTypes.Any, scaleX = 1, angle = 0) {
1021
+ const height2 = height.half();
910
1022
  let path = [];
911
1023
  const arrowSize = (0, helpers_js_1.milsToMM)(30);
912
1024
  if (portType === PinTypes_js_1.PinTypes.Any) {
913
1025
  path = [
914
- [0, -height2],
915
- [width, -height2],
916
- [width, +height2],
917
- [0, +height2],
918
- [0, -height2]
1026
+ [(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
1027
+ [width, height2.neg()],
1028
+ [width, height2],
1029
+ [(0, ParamDefinition_js_1.numeric)(0), height2],
1030
+ [(0, ParamDefinition_js_1.numeric)(0), height2.neg()]
919
1031
  ];
920
1032
  }
921
1033
  else if (portType === PinTypes_js_1.PinTypes.Output) {
922
1034
  path = [
923
- [arrowSize, -height2],
924
- [width, -height2],
1035
+ [arrowSize, height2.neg()],
1036
+ [width, height2.neg()],
925
1037
  [width, height2],
926
1038
  [arrowSize, height2],
927
- [0, 0],
928
- [arrowSize, -height2]
1039
+ [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
1040
+ [arrowSize, height2.neg()]
929
1041
  ];
930
1042
  }
931
1043
  else if (portType === PinTypes_js_1.PinTypes.Input) {
932
1044
  path = [
933
- [0, -height2],
934
- [width - arrowSize, -height2],
935
- [width, 0],
936
- [width - arrowSize, height2],
937
- [0, +height2],
938
- [0, -height2],
1045
+ [(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
1046
+ [width.sub(arrowSize), height2.neg()],
1047
+ [width, (0, ParamDefinition_js_1.numeric)(0)],
1048
+ [width.sub(arrowSize), height2],
1049
+ [(0, ParamDefinition_js_1.numeric)(0), height2],
1050
+ [(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
939
1051
  ];
940
1052
  }
941
1053
  else if (portType === PinTypes_js_1.PinTypes.IO) {
942
1054
  path = [
943
- [arrowSize, -height2],
944
- [width - arrowSize, -height2],
945
- [width, 0],
946
- [width - arrowSize, +height2],
947
- [arrowSize, +height2],
948
- [0, 0],
949
- [0 + arrowSize, -height2],
1055
+ [arrowSize, height2.neg()],
1056
+ [width.sub(arrowSize), height2.neg()],
1057
+ [width, (0, ParamDefinition_js_1.numeric)(0)],
1058
+ [width.sub(arrowSize), height2],
1059
+ [arrowSize, height2],
1060
+ [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
1061
+ [arrowSize, height2.neg()],
950
1062
  ];
951
1063
  }
952
1064
  path = path.map(point => {
953
- return [x + point[0] * scaleX, y + point[1]];
1065
+ return [
1066
+ x.add(point[0].mul(scaleX)),
1067
+ y.add(point[1])
1068
+ ];
954
1069
  });
955
- this.items.push(geometry_js_1.Geometry.polygon(path));
1070
+ const polygon = geometry_js_1.Geometry.polygon(path)
1071
+ .rotate(angle * Math.PI / 180, geometry_js_1.Geometry.point(x, y));
1072
+ this.items.push(polygon);
956
1073
  return this;
957
1074
  }
958
1075
  addPath(...pathParts) {
@@ -961,6 +1078,9 @@ class SymbolDrawing {
961
1078
  accum = accum.concat(tmp.split(" "));
962
1079
  }
963
1080
  else if (typeof tmp === "number") {
1081
+ accum.push((0, ParamDefinition_js_1.numeric)(tmp));
1082
+ }
1083
+ else if (tmp instanceof ParamDefinition_js_1.NumericValue) {
964
1084
  accum.push(tmp);
965
1085
  }
966
1086
  return accum;
@@ -973,14 +1093,14 @@ class SymbolDrawing {
973
1093
  if (currentObj !== null) {
974
1094
  geomObjects.push(currentObj);
975
1095
  }
976
- const x = (0, helpers_js_1.milsToMM)(Number(parts[i + 1]));
977
- const y = (0, helpers_js_1.milsToMM)(Number(parts[i + 2]));
1096
+ const x = (0, helpers_js_1.milsToMM)(parts[i + 1]);
1097
+ const y = (0, helpers_js_1.milsToMM)(parts[i + 2]);
978
1098
  currentObj = [[x, y]];
979
1099
  i += 2;
980
1100
  }
981
1101
  else if (command === 'L') {
982
- const x = (0, helpers_js_1.milsToMM)(Number(parts[i + 1]));
983
- const y = (0, helpers_js_1.milsToMM)(Number(parts[i + 2]));
1102
+ const x = (0, helpers_js_1.milsToMM)(parts[i + 1]);
1103
+ const y = (0, helpers_js_1.milsToMM)(parts[i + 2]);
984
1104
  currentObj.push([x, y]);
985
1105
  i += 2;
986
1106
  }
@@ -1026,8 +1146,8 @@ class SymbolDrawing {
1026
1146
  x = (0, helpers_js_1.milsToMM)(x);
1027
1147
  y = (0, helpers_js_1.milsToMM)(y);
1028
1148
  radius = (0, helpers_js_1.milsToMM)(radius);
1029
- startAngle = startAngle * Math.PI / 180;
1030
- endAngle = endAngle * Math.PI / 180;
1149
+ startAngle = startAngle.mul(Math.PI).div(180);
1150
+ endAngle = endAngle.mul(Math.PI).div(180);
1031
1151
  this.items.push(geometry_js_1.Geometry.arc([x, y], radius, startAngle, endAngle, true));
1032
1152
  return this;
1033
1153
  }
@@ -1037,7 +1157,7 @@ class SymbolDrawing {
1037
1157
  }
1038
1158
  getPaths() {
1039
1159
  let currentFill = "#fff";
1040
- let currentLineWidth = 1;
1160
+ let currentLineWidth = (0, ParamDefinition_js_1.numeric)(1);
1041
1161
  let currentLineColor = '#333';
1042
1162
  const pathItems = [];
1043
1163
  this.items.forEach(item => {
@@ -1104,7 +1224,7 @@ class SymbolDrawing {
1104
1224
  }
1105
1225
  getPinPosition(pinId) {
1106
1226
  const pin = this.pins.find(item => {
1107
- return item[0] === pinId;
1227
+ return item[0].toNumber() === pinId;
1108
1228
  });
1109
1229
  if (pin) {
1110
1230
  const [, feature, angle] = pin;
@@ -1142,5 +1262,8 @@ class SymbolDrawingCommands extends SymbolDrawing {
1142
1262
  cloned.variables = this.variables;
1143
1263
  return cloned;
1144
1264
  }
1265
+ eq(other) {
1266
+ return this.callback === other.callback;
1267
+ }
1145
1268
  }
1146
1269
  exports.SymbolDrawingCommands = SymbolDrawingCommands;