circuitscript 0.0.29 → 0.0.32

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 (64) hide show
  1. package/dist/cjs/BaseVisitor.js +6 -1
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +204 -200
  3. package/dist/cjs/antlr/CircuitScriptParser.js +1066 -1173
  4. package/dist/cjs/draw_symbols.js +330 -87
  5. package/dist/cjs/execute.js +41 -14
  6. package/dist/cjs/geometry.js +79 -18
  7. package/dist/cjs/globals.js +37 -6
  8. package/dist/cjs/helpers.js +75 -5
  9. package/dist/cjs/layout.js +107 -43
  10. package/dist/cjs/main.js +10 -4
  11. package/dist/cjs/objects/ClassComponent.js +2 -0
  12. package/dist/cjs/objects/ExecutionScope.js +1 -1
  13. package/dist/cjs/objects/Frame.js +2 -0
  14. package/dist/cjs/objects/Net.js +3 -2
  15. package/dist/cjs/objects/PinTypes.js +7 -1
  16. package/dist/cjs/objects/types.js +11 -1
  17. package/dist/cjs/regenerate-tests.js +64 -3
  18. package/dist/cjs/render.js +29 -21
  19. package/dist/cjs/sizing.js +4 -6
  20. package/dist/cjs/utils.js +29 -5
  21. package/dist/cjs/visitor.js +176 -10
  22. package/dist/esm/BaseVisitor.mjs +6 -1
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +204 -200
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +1061 -1171
  25. package/dist/esm/antlr/CircuitScriptVisitor.mjs +3 -0
  26. package/dist/esm/draw_symbols.mjs +324 -85
  27. package/dist/esm/execute.mjs +42 -15
  28. package/dist/esm/geometry.mjs +79 -17
  29. package/dist/esm/globals.mjs +36 -5
  30. package/dist/esm/helpers.mjs +74 -5
  31. package/dist/esm/layout.mjs +110 -46
  32. package/dist/esm/main.mjs +11 -5
  33. package/dist/esm/objects/ClassComponent.mjs +6 -0
  34. package/dist/esm/objects/ExecutionScope.mjs +1 -1
  35. package/dist/esm/objects/Frame.mjs +2 -0
  36. package/dist/esm/objects/Net.mjs +3 -2
  37. package/dist/esm/objects/PinTypes.mjs +6 -0
  38. package/dist/esm/objects/types.mjs +14 -0
  39. package/dist/esm/regenerate-tests.mjs +64 -3
  40. package/dist/esm/render.mjs +30 -22
  41. package/dist/esm/sizing.mjs +3 -4
  42. package/dist/esm/utils.mjs +26 -4
  43. package/dist/esm/visitor.mjs +179 -13
  44. package/dist/types/antlr/CircuitScriptLexer.d.ts +42 -41
  45. package/dist/types/antlr/CircuitScriptParser.d.ts +144 -133
  46. package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -0
  47. package/dist/types/draw_symbols.d.ts +15 -2
  48. package/dist/types/execute.d.ts +5 -4
  49. package/dist/types/geometry.d.ts +4 -3
  50. package/dist/types/globals.d.ts +32 -3
  51. package/dist/types/helpers.d.ts +12 -0
  52. package/dist/types/layout.d.ts +8 -2
  53. package/dist/types/objects/ClassComponent.d.ts +8 -0
  54. package/dist/types/objects/Frame.d.ts +3 -1
  55. package/dist/types/objects/PinTypes.d.ts +1 -0
  56. package/dist/types/objects/Wire.d.ts +4 -2
  57. package/dist/types/objects/types.d.ts +8 -0
  58. package/dist/types/render.d.ts +5 -1
  59. package/dist/types/sizing.d.ts +0 -4
  60. package/dist/types/utils.d.ts +3 -0
  61. package/dist/types/visitor.d.ts +8 -1
  62. package/fonts/Arial.ttf +0 -0
  63. package/libs/lib.cst +58 -41
  64. package/package.json +5 -1
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SymbolDrawingCommands = exports.SymbolDrawing = 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.SymbolPointHidden = exports.SymbolFactory = exports.SymbolGraphic = void 0;
4
+ const helpers_js_1 = require("./helpers.js");
4
5
  const globals_js_1 = require("./globals.js");
5
6
  const geometry_js_1 = require("./geometry.js");
6
7
  const PinTypes_js_1 = require("./objects/PinTypes.js");
7
- const defaultSymbolLineWidth = 2;
8
+ const utils_js_1 = require("./utils.js");
8
9
  class SymbolGraphic {
9
10
  constructor() {
10
11
  this.drawPortsName = true;
11
- this.displayBounds = true;
12
+ this.displayBounds = false;
12
13
  this._angle = 0;
13
14
  this._flipX = 0;
14
15
  this._flipY = 0;
@@ -53,6 +54,7 @@ class SymbolGraphic {
53
54
  this.drawPins(innerGroup);
54
55
  this.drawLabels(innerGroup);
55
56
  this.drawPlaceRemove(innerGroup, extra);
57
+ this.displayBounds && this.drawBounds(group);
56
58
  }
57
59
  drawPlaceRemove(group, extra) {
58
60
  if (extra && extra.place === false) {
@@ -63,7 +65,7 @@ class SymbolGraphic {
63
65
  ]);
64
66
  group.path(path)
65
67
  .stroke({
66
- width: defaultSymbolLineWidth,
68
+ width: globals_js_1.defaultSymbolLineWidth,
67
69
  color: 'red'
68
70
  });
69
71
  }
@@ -71,8 +73,8 @@ class SymbolGraphic {
71
73
  pinPosition(id) {
72
74
  const pin = this.drawing.getPinPosition(id);
73
75
  const [x, y] = pin.start;
74
- const useX = Math.round(x * 10000) / 10000;
75
- const useY = Math.round(y * 10000 / 10000);
76
+ const useX = (0, utils_js_1.roundValue)(x);
77
+ const useY = (0, utils_js_1.roundValue)(y);
76
78
  return {
77
79
  x: useX,
78
80
  y: useY,
@@ -81,15 +83,16 @@ class SymbolGraphic {
81
83
  }
82
84
  drawBounds(group) {
83
85
  const bbox = this.drawing.getBoundingBox();
84
- group.circle(3)
85
- .translate(-3 / 2, -3 / 2)
86
+ const originSize = (0, helpers_js_1.milsToMM)(10);
87
+ group.circle(originSize)
88
+ .translate(-originSize / 2, -originSize / 2)
86
89
  .fill('red')
87
90
  .stroke('none');
88
91
  group.rect(bbox.width, bbox.height)
89
92
  .translate(bbox.start[0], bbox.start[1])
90
93
  .fill('none')
91
94
  .stroke({
92
- width: 1,
95
+ width: (0, helpers_js_1.milsToMM)(2),
93
96
  color: '#ccc',
94
97
  });
95
98
  }
@@ -110,7 +113,7 @@ class SymbolGraphic {
110
113
  pinPaths.forEach(({ path, lineColor }) => {
111
114
  group.path(path)
112
115
  .stroke({
113
- width: defaultSymbolLineWidth,
116
+ width: globals_js_1.defaultSymbolLineWidth,
114
117
  color: lineColor
115
118
  });
116
119
  });
@@ -119,7 +122,7 @@ class SymbolGraphic {
119
122
  const labels = this.drawing.getLabels();
120
123
  labels.forEach(label => {
121
124
  const tmpLabel = label;
122
- const { fontSize = 10, anchor = geometry_js_1.HorizontalAlign.Left, vanchor = geometry_js_1.VerticalAlign.Bottom, fontWeight = 'regular', angle: labelAngle = 0, textColor = "#333", } = tmpLabel.style ?? {};
125
+ const { fontSize = 50, anchor = geometry_js_1.HorizontalAlign.Left, vanchor = geometry_js_1.VerticalAlign.Bottom, fontWeight = 'regular', angle: labelAngle = 0, textColor = "#333", } = tmpLabel.style ?? {};
123
126
  let anchorStyle = 'start';
124
127
  let dominantBaseline = 'auto';
125
128
  let useAnchor = anchor;
@@ -160,15 +163,6 @@ class SymbolGraphic {
160
163
  }
161
164
  const useFont = globals_js_1.defaultFont;
162
165
  const textContainer = group.group();
163
- const text = textContainer.text(tmpLabel.text)
164
- .fill(textColor)
165
- .font({
166
- family: useFont,
167
- size: fontSize,
168
- anchor: anchorStyle,
169
- 'dominant-baseline': dominantBaseline,
170
- weight: fontWeight,
171
- });
172
166
  let translateX, translateY;
173
167
  let useRotateAngle = 0;
174
168
  if (isRotation180) {
@@ -181,26 +175,121 @@ class SymbolGraphic {
181
175
  translateY = position[1];
182
176
  useRotateAngle = this.angle;
183
177
  }
184
- translateX = this.roundValues(translateX);
185
- translateY = this.roundValues(translateY);
186
- text.rotate(labelAngle);
178
+ translateX = (0, utils_js_1.roundValue)(translateX);
179
+ translateY = (0, utils_js_1.roundValue)(translateY);
180
+ const { portType = null } = tmpLabel.style;
181
+ if (portType !== null) {
182
+ const { x: boundsX, y: boundsY } = tmpLabel.textMeasurementBounds;
183
+ const paddingHorizontal = globals_js_1.PortPaddingHorizontal;
184
+ const paddingVert = globals_js_1.PortPaddingVertical;
185
+ const boundsWidth = tmpLabel.textMeasurementBounds.width
186
+ + paddingHorizontal * 2;
187
+ const boundsHeight = tmpLabel.textMeasurementBounds.height
188
+ + paddingVert * 2;
189
+ let path = [];
190
+ let boundsTranslateX = -paddingHorizontal;
191
+ switch (portType) {
192
+ case PinTypes_js_1.PinTypes.Input:
193
+ path = ['M', 0, 0,
194
+ 'L', boundsWidth, 0,
195
+ 'L', boundsWidth, boundsHeight,
196
+ 'L', 0, boundsHeight,
197
+ 'L', -globals_js_1.PortArrowSize, boundsHeight / 2,
198
+ 'Z',
199
+ ];
200
+ break;
201
+ case PinTypes_js_1.PinTypes.Output:
202
+ path = ['M', 0, 0,
203
+ 'L', boundsWidth, 0,
204
+ 'L', boundsWidth + globals_js_1.PortArrowSize,
205
+ boundsHeight / 2,
206
+ 'L', boundsWidth, boundsHeight,
207
+ 'L', 0, boundsHeight,
208
+ 'Z',
209
+ ];
210
+ break;
211
+ case PinTypes_js_1.PinTypes.IO:
212
+ path = ['M', 0, 0,
213
+ 'L', boundsWidth, 0,
214
+ 'L', boundsWidth + globals_js_1.PortArrowSize,
215
+ boundsHeight / 2,
216
+ 'L', boundsWidth, boundsHeight,
217
+ 'L', 0, boundsHeight,
218
+ 'L', -globals_js_1.PortArrowSize, boundsHeight / 2,
219
+ 'Z',
220
+ ];
221
+ break;
222
+ case PinTypes_js_1.PinTypes.Any:
223
+ case PinTypes_js_1.PinTypes.Power:
224
+ path = ['M', 0, 0,
225
+ 'L', boundsWidth, 0,
226
+ 'L', boundsWidth, boundsHeight,
227
+ 'L', 0, boundsHeight,
228
+ 'Z',
229
+ ];
230
+ break;
231
+ }
232
+ if (path.length > 0) {
233
+ let flip = 1;
234
+ if (this.flipX !== 0) {
235
+ flip = -1;
236
+ boundsTranslateX = paddingHorizontal;
237
+ }
238
+ textContainer.path(path)
239
+ .stroke({
240
+ width: (0, helpers_js_1.milsToMM)(5),
241
+ color: '#333'
242
+ })
243
+ .fill('none')
244
+ .scale(flip, 1, 0, 0)
245
+ .translate(boundsTranslateX, boundsY - paddingVert);
246
+ }
247
+ }
248
+ const drawTextBounds = false;
249
+ const drawBoxBounds = false;
250
+ const drawOrigin = false;
251
+ if (drawBoxBounds) {
252
+ const box = tmpLabel.box;
253
+ textContainer.rect(box.width, box.height).fill('red')
254
+ .translate(box.xmin, box.ymin)
255
+ .scale(this.flipX !== 0 ? -1 : 1, 1, -box.xmin, box.ymin);
256
+ }
257
+ if (drawTextBounds) {
258
+ const textBounds = tmpLabel.textMeasurementBounds;
259
+ const xOffset = (this.flipX !== 0) ? textBounds.width : 0;
260
+ textContainer.rect(textBounds.width, textBounds.height).fill('#cccccc')
261
+ .translate(textBounds.x - xOffset, textBounds.y);
262
+ }
187
263
  textContainer.translate(translateX, translateY)
188
264
  .rotate(useRotateAngle, -translateX, -translateY);
265
+ textContainer.text(tmpLabel.text)
266
+ .fill(textColor)
267
+ .font({
268
+ family: useFont,
269
+ size: fontSize * globals_js_1.fontDisplayScale,
270
+ anchor: anchorStyle,
271
+ 'dominant-baseline': dominantBaseline,
272
+ weight: fontWeight,
273
+ })
274
+ .rotate(labelAngle);
189
275
  const { a, b, c, d, e, f } = textContainer.matrix();
190
276
  const newMatrix = {
191
- a: this.roundValues(a),
192
- b: this.roundValues(b),
193
- c: this.roundValues(c),
194
- d: this.roundValues(d),
195
- e: this.roundValues(e),
196
- f: this.roundValues(f),
277
+ a: (0, utils_js_1.roundValue)(a),
278
+ b: (0, utils_js_1.roundValue)(b),
279
+ c: (0, utils_js_1.roundValue)(c),
280
+ d: (0, utils_js_1.roundValue)(d),
281
+ e: (0, utils_js_1.roundValue)(e),
282
+ f: (0, utils_js_1.roundValue)(f),
197
283
  };
198
284
  textContainer.transform(newMatrix);
285
+ if (drawOrigin) {
286
+ const originSize = (0, helpers_js_1.milsToMM)(10);
287
+ textContainer.circle(originSize)
288
+ .translate(originSize / 2, originSize / 2)
289
+ .fill('green');
290
+ }
199
291
  });
200
292
  }
201
- roundValues(value) {
202
- return +value.toFixed(7);
203
- }
204
293
  flipTextAnchor(value) {
205
294
  if (value === geometry_js_1.HorizontalAlign.Left) {
206
295
  return geometry_js_1.HorizontalAlign.Right;
@@ -253,7 +342,7 @@ exports.SymbolPointHidden = SymbolPointHidden;
253
342
  class SymbolText extends SymbolGraphic {
254
343
  constructor(text) {
255
344
  super();
256
- this.fontSize = 10;
345
+ this.fontSize = 40;
257
346
  this.fontWeight = 'regular';
258
347
  this.text = text;
259
348
  }
@@ -277,8 +366,10 @@ class SymbolPlaceholder extends SymbolGraphic {
277
366
  drawing.flipX = this._flipX;
278
367
  drawing.flipY = this._flipY;
279
368
  const commands = [
369
+ [PlaceHolderCommands.units, ['mils'], {}],
280
370
  [PlaceHolderCommands.lineColor, [globals_js_1.ColorScheme.PinLineColor], {}],
281
371
  [PlaceHolderCommands.textColor, [globals_js_1.ColorScheme.PinNameColor], {}],
372
+ [PlaceHolderCommands.lineWidth, [5], {}],
282
373
  ...drawing.getCommands()
283
374
  ];
284
375
  drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
@@ -365,12 +456,17 @@ class SymbolPlaceholder extends SymbolGraphic {
365
456
  drawing.addTextbox(offsetX, offsetY, content, style);
366
457
  break;
367
458
  }
459
+ case PlaceHolderCommands.units: {
460
+ drawing.addSetUnits(...positionParams);
461
+ break;
462
+ }
368
463
  }
369
464
  });
370
465
  drawing.log("=== end generate drawing ===");
371
466
  }
372
467
  parseLabelStyle(keywordParams) {
373
- const keywords = ['fontSize', 'anchor', 'vanchor', 'angle', 'textColor'];
468
+ const keywords = ['fontSize', 'anchor', 'vanchor',
469
+ 'angle', 'textColor', 'portType'];
374
470
  const style = {};
375
471
  keywords.forEach(item => {
376
472
  if (keywordParams.has(item)) {
@@ -381,6 +477,7 @@ class SymbolPlaceholder extends SymbolGraphic {
381
477
  }
382
478
  drawPinParams(drawing, commandName, keywordParams, positionParams, lineColor, pinNameColor) {
383
479
  drawing.log('add pin', ...positionParams);
480
+ positionParams = [...positionParams];
384
481
  const keywordDisplayPinId = 'display_pin_id';
385
482
  let displayPinId = true;
386
483
  if (keywordParams.has(keywordDisplayPinId)) {
@@ -399,10 +496,10 @@ class SymbolPlaceholder extends SymbolGraphic {
399
496
  pinNameParam = positionParams[1];
400
497
  positionParams = [positionParams[0], ...positionParams.slice(2)];
401
498
  }
402
- const startX = positionParams[1];
403
- const startY = positionParams[2];
499
+ const startX = (0, helpers_js_1.milsToMM)(positionParams[1]);
500
+ const startY = (0, helpers_js_1.milsToMM)(positionParams[2]);
404
501
  if (commandName === PlaceHolderCommands.vpin) {
405
- const magnitude = positionParams[3];
502
+ const magnitude = (0, helpers_js_1.milsToMM)(positionParams[3]);
406
503
  positionParams = [
407
504
  positionParams[0],
408
505
  startX,
@@ -412,7 +509,7 @@ class SymbolPlaceholder extends SymbolGraphic {
412
509
  ];
413
510
  }
414
511
  else if (commandName === PlaceHolderCommands.hpin) {
415
- const magnitude = positionParams[3];
512
+ const magnitude = (0, helpers_js_1.milsToMM)(positionParams[3]);
416
513
  positionParams = [
417
514
  positionParams[0],
418
515
  startX,
@@ -421,49 +518,61 @@ class SymbolPlaceholder extends SymbolGraphic {
421
518
  startY
422
519
  ];
423
520
  }
424
- drawing.addPin(...positionParams, lineColor);
521
+ else {
522
+ const [, , , endX, endY] = positionParams;
523
+ positionParams = [
524
+ positionParams[0],
525
+ startX,
526
+ startY,
527
+ (0, helpers_js_1.milsToMM)(endX),
528
+ (0, helpers_js_1.milsToMM)(endY)
529
+ ];
530
+ }
531
+ drawing.addPinMM(...positionParams, lineColor);
425
532
  const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
426
533
  const [pinId, , angle] = lastAddedPin;
427
534
  const [, , , endX, endY] = positionParams;
428
535
  let pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
429
- let pinNameOffsetX = 4;
536
+ const offset1 = 15;
537
+ const offset2 = 15;
538
+ let pinNameOffsetX = (0, helpers_js_1.milsToMM)(offset1);
430
539
  let pinIdOffsetX = 0;
431
540
  let pinIdAlignment = geometry_js_1.HorizontalAlign.Left;
432
541
  let pinIdVAlignment = geometry_js_1.VerticalAlign.Bottom;
433
- let pinIdOffsetY = -2;
542
+ let pinIdOffsetY = (0, helpers_js_1.milsToMM)(-offset2);
434
543
  switch (angle) {
435
544
  case 0:
436
545
  pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
437
- pinNameOffsetX = 4;
546
+ pinNameOffsetX = (0, helpers_js_1.milsToMM)(offset1);
438
547
  pinIdAlignment = geometry_js_1.HorizontalAlign.Right;
439
- pinIdOffsetX = -2;
548
+ pinIdOffsetX = (0, helpers_js_1.milsToMM)(-offset2);
440
549
  break;
441
550
  case 90:
442
551
  case 180:
443
552
  pinNameAlignment = geometry_js_1.HorizontalAlign.Right;
444
- pinNameOffsetX = -4;
553
+ pinNameOffsetX = (0, helpers_js_1.milsToMM)(-offset1);
445
554
  pinIdAlignment = geometry_js_1.HorizontalAlign.Left;
446
- pinIdOffsetX = 2;
555
+ pinIdOffsetX = (0, helpers_js_1.milsToMM)(offset2);
447
556
  break;
448
557
  case 270:
449
558
  pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
450
- pinNameOffsetX = 4;
559
+ pinNameOffsetX = (0, helpers_js_1.milsToMM)(offset1);
451
560
  pinIdAlignment = geometry_js_1.HorizontalAlign.Left;
452
- pinIdOffsetX = 2;
453
- pinIdOffsetY = 2;
561
+ pinIdOffsetX = (0, helpers_js_1.milsToMM)(offset2);
562
+ pinIdOffsetY = (0, helpers_js_1.milsToMM)(offset2);
454
563
  pinIdVAlignment = geometry_js_1.VerticalAlign.Top;
455
564
  break;
456
565
  }
457
566
  if (angle === 0 || angle === 90 || angle === 180 || angle === 270) {
458
567
  const usePinName = pinNameParam ?? "";
459
568
  usePinName !== "" && drawing.addLabel(endX + pinNameOffsetX, endY, usePinName, {
460
- fontSize: 10,
569
+ fontSize: globals_js_1.defaultPinNameTextSize,
461
570
  anchor: pinNameAlignment,
462
571
  vanchor: geometry_js_1.VerticalAlign.Middle,
463
572
  textColor: pinNameColor,
464
573
  });
465
574
  displayPinId && drawing.addLabel(endX + pinIdOffsetX, endY + pinIdOffsetY, pinId.toString(), {
466
- fontSize: 8,
575
+ fontSize: globals_js_1.defaultPinIdTextSize,
467
576
  anchor: pinIdAlignment,
468
577
  vanchor: pinIdVAlignment,
469
578
  textColor: lineColor
@@ -495,17 +604,18 @@ var PlaceHolderCommands;
495
604
  PlaceHolderCommands["lineColor"] = "lineColor";
496
605
  PlaceHolderCommands["textColor"] = "textColor";
497
606
  PlaceHolderCommands["text"] = "text";
607
+ PlaceHolderCommands["units"] = "units";
498
608
  })(PlaceHolderCommands || (exports.PlaceHolderCommands = PlaceHolderCommands = {}));
499
609
  class SymbolCustom extends SymbolGraphic {
500
610
  constructor(pinDefinition) {
501
611
  super();
502
612
  this.pinDefinition = [];
503
- this.bodyWidth = 100;
504
- this.pinLength = 20;
505
- this.width = 100;
506
- this.height = 100;
507
- this.pinSpacing = 20;
508
- this.pinTextPadding = 5;
613
+ this.bodyWidth = (0, helpers_js_1.milsToMM)(400);
614
+ this.pinLength = (0, helpers_js_1.milsToMM)(100);
615
+ this.width = (0, helpers_js_1.milsToMM)(100);
616
+ this.height = (0, helpers_js_1.milsToMM)(100);
617
+ this.pinSpacing = (0, helpers_js_1.milsToMM)(100);
618
+ this.pinTextPadding = (0, helpers_js_1.milsToMM)(5);
509
619
  this.pins = [];
510
620
  this.pinDefinition = pinDefinition;
511
621
  }
@@ -526,22 +636,29 @@ class SymbolCustom extends SymbolGraphic {
526
636
  const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
527
637
  const defaultLineColor = globals_js_1.ColorScheme.PinLineColor;
528
638
  drawing.addSetLineColor(defaultLineColor);
529
- drawing.addRect(0, 0, bodyWidth, bodyHeight);
530
- const leftPinStart = -bodyWidth / 2;
531
- const rightPinStart = bodyWidth / 2;
532
- const pinStartY = -bodyHeight / 2;
639
+ drawing.addSetLineWidth(5);
640
+ drawing.addRectMM(0, 0, bodyWidth, bodyHeight);
641
+ this.generateDrawingPins(drawing, bodyWidth, bodyHeight, leftPins, rightPins, defaultLineColor);
642
+ this.drawing = drawing;
643
+ this._cacheLeftPins = leftPins;
644
+ this._cacheRightPins = rightPins;
645
+ }
646
+ generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, leftPins, rightPins, defaultLineColor) {
647
+ const leftPinStart = -bodyWidthMM / 2;
648
+ const rightPinStart = bodyWidthMM / 2;
649
+ const pinStartY = -bodyHeightMM / 2;
533
650
  leftPins.forEach(pin => {
534
651
  const position = pin.position;
535
652
  const pinY = pinStartY + (position + 1) * this.pinSpacing;
536
- drawing.addPin(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
537
- drawing.addLabel(leftPinStart + 4, pinY, pin.text, {
538
- fontSize: 10,
653
+ drawing.addPinMM(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
654
+ drawing.addLabel(leftPinStart + (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
655
+ fontSize: globals_js_1.CustomSymbolPinTextSize,
539
656
  anchor: geometry_js_1.HorizontalAlign.Left,
540
657
  vanchor: geometry_js_1.VerticalAlign.Middle,
541
658
  textColor: globals_js_1.ColorScheme.PinNameColor,
542
659
  });
543
- drawing.addLabel(leftPinStart - 2, pinY - 2, pin.pinId.toString(), {
544
- fontSize: 8,
660
+ drawing.addLabel(leftPinStart - (0, helpers_js_1.milsToMM)(10), pinY - (0, helpers_js_1.milsToMM)(10), pin.pinId.toString(), {
661
+ fontSize: globals_js_1.CustomSymbolPinIdSize,
545
662
  anchor: geometry_js_1.HorizontalAlign.Right,
546
663
  vanchor: geometry_js_1.VerticalAlign.Bottom,
547
664
  textColor: defaultLineColor
@@ -550,39 +667,36 @@ class SymbolCustom extends SymbolGraphic {
550
667
  rightPins.forEach(pin => {
551
668
  const position = pin.position;
552
669
  const pinY = pinStartY + (position + 1) * this.pinSpacing;
553
- drawing.addPin(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
554
- drawing.addLabel(rightPinStart - 4, pinY, pin.text, {
555
- fontSize: 10,
670
+ drawing.addPinMM(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
671
+ drawing.addLabel(rightPinStart - (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
672
+ fontSize: globals_js_1.CustomSymbolPinTextSize,
556
673
  anchor: geometry_js_1.HorizontalAlign.Right,
557
674
  vanchor: geometry_js_1.VerticalAlign.Middle,
558
675
  textColor: globals_js_1.ColorScheme.PinNameColor,
559
676
  });
560
- drawing.addLabel(rightPinStart + 2, pinY - 2, pin.pinId.toString(), {
561
- fontSize: 8,
677
+ drawing.addLabel(rightPinStart + (0, helpers_js_1.milsToMM)(10), pinY - (0, helpers_js_1.milsToMM)(10), pin.pinId.toString(), {
678
+ fontSize: globals_js_1.CustomSymbolPinIdSize,
562
679
  anchor: geometry_js_1.HorizontalAlign.Left,
563
680
  vanchor: geometry_js_1.VerticalAlign.Bottom,
564
681
  textColor: defaultLineColor
565
682
  });
566
683
  });
567
684
  const instanceName = this.getLabelValue("refdes");
568
- instanceName && drawing.addLabel(-bodyWidth / 2, -bodyHeight / 2 - 4, instanceName, {
569
- fontSize: 10,
685
+ instanceName && drawing.addLabel(-bodyWidthMM / 2, -bodyHeightMM / 2 - (0, helpers_js_1.milsToMM)(20), instanceName, {
686
+ fontSize: globals_js_1.CustomSymbolRefDesSize,
570
687
  anchor: geometry_js_1.HorizontalAlign.Left,
571
688
  });
572
689
  const acceptedMPNKeys = ['MPN', 'mpn', 'manufacturer_pn'];
573
690
  acceptedMPNKeys.some(key => {
574
691
  const labelValue = this.getLabelValue(key);
575
692
  if (labelValue !== undefined) {
576
- drawing.addLabel(-bodyWidth / 2, bodyHeight / 2 + 4, labelValue, {
577
- fontSize: 10,
693
+ drawing.addLabel(-bodyWidthMM / 2, bodyHeightMM / 2 + (0, helpers_js_1.milsToMM)(20), labelValue, {
694
+ fontSize: globals_js_1.CustomSymbolParamTextSize,
578
695
  anchor: geometry_js_1.HorizontalAlign.Left,
579
696
  vanchor: geometry_js_1.VerticalAlign.Top,
580
697
  });
581
698
  }
582
699
  });
583
- this.drawing = drawing;
584
- this._cacheLeftPins = leftPins;
585
- this._cacheRightPins = rightPins;
586
700
  }
587
701
  calculateSize() {
588
702
  this.width = this.bodyWidth + 2 * this.pinLength;
@@ -590,6 +704,44 @@ class SymbolCustom extends SymbolGraphic {
590
704
  }
591
705
  }
592
706
  exports.SymbolCustom = SymbolCustom;
707
+ class SymbolCustomModule extends SymbolCustom {
708
+ constructor() {
709
+ super(...arguments);
710
+ this.pinLength = 0;
711
+ this.portWidth = (0, helpers_js_1.milsToMM)(100);
712
+ this.portHeight = (0, helpers_js_1.milsToMM)(50);
713
+ }
714
+ generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, leftPins, rightPins, defaultLineColor) {
715
+ const leftPinStart = -bodyWidthMM / 2;
716
+ const rightPinStart = bodyWidthMM / 2;
717
+ const pinStartY = -bodyHeightMM / 2;
718
+ leftPins.forEach(pin => {
719
+ const position = pin.position;
720
+ const pinY = pinStartY + (position + 1) * this.pinSpacing;
721
+ drawing.addPinMM(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
722
+ drawing.addModulePort(leftPinStart, pinY, this.portWidth, this.portHeight, pin.pinType);
723
+ drawing.addLabel(leftPinStart + this.portWidth + (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
724
+ fontSize: 40,
725
+ anchor: geometry_js_1.HorizontalAlign.Left,
726
+ vanchor: geometry_js_1.VerticalAlign.Middle,
727
+ textColor: globals_js_1.ColorScheme.PinNameColor,
728
+ });
729
+ });
730
+ rightPins.forEach(pin => {
731
+ const position = pin.position;
732
+ const pinY = pinStartY + (position + 1) * this.pinSpacing;
733
+ drawing.addPinMM(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
734
+ drawing.addModulePort(rightPinStart, pinY, this.portWidth, this.portHeight, pin.pinType, -1);
735
+ drawing.addLabel(rightPinStart - this.portWidth - (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
736
+ fontSize: 40,
737
+ anchor: geometry_js_1.HorizontalAlign.Right,
738
+ vanchor: geometry_js_1.VerticalAlign.Middle,
739
+ textColor: globals_js_1.ColorScheme.PinNameColor,
740
+ });
741
+ });
742
+ }
743
+ }
744
+ exports.SymbolCustomModule = SymbolCustomModule;
593
745
  class SymbolDrawing {
594
746
  constructor() {
595
747
  this.items = [];
@@ -608,44 +760,68 @@ class SymbolDrawing {
608
760
  this.logger && this.logger.add(params.join(' '));
609
761
  }
610
762
  addLine(startX, startY, endX, endY) {
763
+ startX = (0, helpers_js_1.milsToMM)(startX);
764
+ startY = (0, helpers_js_1.milsToMM)(startY);
765
+ endX = (0, helpers_js_1.milsToMM)(endX);
766
+ endY = (0, helpers_js_1.milsToMM)(endY);
611
767
  this.items.push(geometry_js_1.Geometry.segment([startX, startY], [endX, endY]));
612
768
  return this;
613
769
  }
614
770
  addPin(pinId, startX, startY, endX, endY, lineColor) {
771
+ startX = (0, helpers_js_1.milsToMM)(startX);
772
+ startY = (0, helpers_js_1.milsToMM)(startY);
773
+ endX = (0, helpers_js_1.milsToMM)(endX);
774
+ endY = (0, helpers_js_1.milsToMM)(endY);
775
+ return this.addPinMM(pinId, startX, startY, endX, endY, lineColor);
776
+ }
777
+ addPinMM(pinId, startXMM, startYMM, endXMM, endYMM, lineColor) {
615
778
  let angle = 0;
616
- if (startX === endX) {
617
- if (startY > endY) {
779
+ if (startXMM === endXMM) {
780
+ if (startYMM > endYMM) {
618
781
  angle = 270;
619
782
  }
620
- else if (startY < endY) {
783
+ else if (startYMM < endYMM) {
621
784
  angle = 90;
622
785
  }
623
786
  }
624
787
  else {
625
- if (startX < endX) {
788
+ if (startXMM < endXMM) {
626
789
  angle = 0;
627
790
  }
628
- else if (startX > endX) {
791
+ else if (startXMM > endXMM) {
629
792
  angle = 180;
630
793
  }
631
794
  }
632
795
  this.pins.push([
633
796
  pinId,
634
- geometry_js_1.Geometry.segment([startX, startY], [endX, endY]),
797
+ geometry_js_1.Geometry.segment([startXMM, startYMM], [endXMM, endYMM]),
635
798
  angle,
636
799
  lineColor
637
800
  ]);
638
801
  return this;
639
802
  }
640
803
  addVLine(startX, startY, value) {
804
+ startX = (0, helpers_js_1.milsToMM)(startX);
805
+ startY = (0, helpers_js_1.milsToMM)(startY);
806
+ value = (0, helpers_js_1.milsToMM)(value);
641
807
  this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX, startY + value]));
642
808
  return this;
643
809
  }
644
810
  addHLine(startX, startY, value) {
811
+ startX = (0, helpers_js_1.milsToMM)(startX);
812
+ startY = (0, helpers_js_1.milsToMM)(startY);
813
+ value = (0, helpers_js_1.milsToMM)(value);
645
814
  this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX + value, startY]));
646
815
  return this;
647
816
  }
648
817
  addRect(centerX, centerY, width, height) {
818
+ centerX = (0, helpers_js_1.milsToMM)(centerX);
819
+ centerY = (0, helpers_js_1.milsToMM)(centerY);
820
+ width = (0, helpers_js_1.milsToMM)(width);
821
+ height = (0, helpers_js_1.milsToMM)(height);
822
+ return this.addRectMM(centerX, centerY, width, height);
823
+ }
824
+ addRectMM(centerX, centerY, width, height) {
649
825
  const width2 = width / 2;
650
826
  const height2 = height / 2;
651
827
  this.items.push(geometry_js_1.Geometry.polygon([
@@ -658,6 +834,11 @@ class SymbolDrawing {
658
834
  return this;
659
835
  }
660
836
  addTriangle(startX, startY, endX, endY, width) {
837
+ startX = (0, helpers_js_1.milsToMM)(startX);
838
+ startY = (0, helpers_js_1.milsToMM)(startY);
839
+ endX = (0, helpers_js_1.milsToMM)(endX);
840
+ endY = (0, helpers_js_1.milsToMM)(endY);
841
+ width = (0, helpers_js_1.milsToMM)(width);
661
842
  const line = geometry_js_1.Geometry.line(startX, startY, endX, endY);
662
843
  const normLine = line.norm;
663
844
  const dx1 = normLine.x * width / 2;
@@ -687,13 +868,67 @@ class SymbolDrawing {
687
868
  return this;
688
869
  }
689
870
  addLabelId(id, x, y, textValue, style) {
871
+ x = (0, helpers_js_1.milsToMM)(x);
872
+ y = (0, helpers_js_1.milsToMM)(y);
690
873
  this.items.push(geometry_js_1.Geometry.label(id, x, y, textValue, style));
691
874
  return this;
692
875
  }
693
876
  addTextbox(x, y, textValue, style) {
877
+ x = (0, helpers_js_1.milsToMM)(x);
878
+ y = (0, helpers_js_1.milsToMM)(y);
694
879
  this.items.push(geometry_js_1.Geometry.textbox(null, x, y, textValue, style));
695
880
  return this;
696
881
  }
882
+ addModulePort(x, y, width, height, portType = PinTypes_js_1.PinTypes.Any, scaleX = 1) {
883
+ const height2 = height / 2;
884
+ let path = [];
885
+ const arrowSize = (0, helpers_js_1.milsToMM)(30);
886
+ if (portType === PinTypes_js_1.PinTypes.Any) {
887
+ path = [
888
+ [0, -height2],
889
+ [width, -height2],
890
+ [width, +height2],
891
+ [0, +height2],
892
+ [0, -height2]
893
+ ];
894
+ }
895
+ else if (portType === PinTypes_js_1.PinTypes.Output) {
896
+ path = [
897
+ [arrowSize, -height2],
898
+ [width, -height2],
899
+ [width, height2],
900
+ [arrowSize, height2],
901
+ [0, 0],
902
+ [arrowSize, -height2]
903
+ ];
904
+ }
905
+ else if (portType === PinTypes_js_1.PinTypes.Input) {
906
+ path = [
907
+ [0, -height2],
908
+ [width - arrowSize, -height2],
909
+ [width, 0],
910
+ [width - arrowSize, height2],
911
+ [0, +height2],
912
+ [0, -height2],
913
+ ];
914
+ }
915
+ else if (portType === PinTypes_js_1.PinTypes.IO) {
916
+ path = [
917
+ [arrowSize, -height2],
918
+ [width - arrowSize, -height2],
919
+ [width, 0],
920
+ [width - arrowSize, +height2],
921
+ [arrowSize, +height2],
922
+ [0, 0],
923
+ [0 + arrowSize, -height2],
924
+ ];
925
+ }
926
+ path = path.map(point => {
927
+ return [x + point[0] * scaleX, y + point[1]];
928
+ });
929
+ this.items.push(geometry_js_1.Geometry.polygon(path));
930
+ return this;
931
+ }
697
932
  addPath(...pathParts) {
698
933
  const parts = pathParts.reduce((accum, tmp) => {
699
934
  if (typeof tmp === "string") {
@@ -712,14 +947,14 @@ class SymbolDrawing {
712
947
  if (currentObj !== null) {
713
948
  geomObjects.push(currentObj);
714
949
  }
715
- const x = Number(parts[i + 1]);
716
- const y = Number(parts[i + 2]);
950
+ const x = (0, helpers_js_1.milsToMM)(Number(parts[i + 1]));
951
+ const y = (0, helpers_js_1.milsToMM)(Number(parts[i + 2]));
717
952
  currentObj = [[x, y]];
718
953
  i += 2;
719
954
  }
720
955
  else if (command === 'L') {
721
- const x = Number(parts[i + 1]);
722
- const y = Number(parts[i + 2]);
956
+ const x = (0, helpers_js_1.milsToMM)(Number(parts[i + 1]));
957
+ const y = (0, helpers_js_1.milsToMM)(Number(parts[i + 2]));
723
958
  currentObj.push([x, y]);
724
959
  i += 2;
725
960
  }
@@ -745,6 +980,7 @@ class SymbolDrawing {
745
980
  return this;
746
981
  }
747
982
  addSetLineWidth(value) {
983
+ value = (0, helpers_js_1.milsToMM)(value);
748
984
  this.items.push(new geometry_js_1.GeometryProp('lineWidth', value));
749
985
  return this;
750
986
  }
@@ -761,11 +997,18 @@ class SymbolDrawing {
761
997
  return this;
762
998
  }
763
999
  addArc(x, y, radius, startAngle, endAngle) {
1000
+ x = (0, helpers_js_1.milsToMM)(x);
1001
+ y = (0, helpers_js_1.milsToMM)(y);
1002
+ radius = (0, helpers_js_1.milsToMM)(radius);
764
1003
  startAngle = startAngle * Math.PI / 180;
765
1004
  endAngle = endAngle * Math.PI / 180;
766
1005
  this.items.push(geometry_js_1.Geometry.arc([x, y], radius, startAngle, endAngle, true));
767
1006
  return this;
768
1007
  }
1008
+ addSetUnits(value) {
1009
+ this.items.push(new geometry_js_1.GeometryProp('units', value));
1010
+ return this;
1011
+ }
769
1012
  getPaths() {
770
1013
  let currentFill = "#fff";
771
1014
  let currentLineWidth = 1;