circuitscript 0.0.38 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/cjs/BaseVisitor.js +69 -46
  2. package/dist/cjs/SymbolValidatorVisitor.js +1 -1
  3. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  4. package/dist/cjs/antlr/CircuitScriptParser.js +580 -613
  5. package/dist/cjs/builtinMethods.js +32 -10
  6. package/dist/cjs/draw_symbols.js +375 -233
  7. package/dist/cjs/execute.js +142 -131
  8. package/dist/cjs/export.js +2 -4
  9. package/dist/cjs/geometry.js +52 -19
  10. package/dist/cjs/globals.js +14 -9
  11. package/dist/cjs/helpers.js +16 -3
  12. package/dist/cjs/layout.js +143 -151
  13. package/dist/cjs/logger.js +8 -1
  14. package/dist/cjs/objects/ClassComponent.js +22 -22
  15. package/dist/cjs/objects/ExecutionScope.js +10 -4
  16. package/dist/cjs/objects/Frame.js +4 -1
  17. package/dist/cjs/objects/ParamDefinition.js +120 -4
  18. package/dist/cjs/objects/PinDefinition.js +1 -4
  19. package/dist/cjs/objects/types.js +41 -0
  20. package/dist/cjs/render.js +41 -110
  21. package/dist/cjs/sizing.js +33 -7
  22. package/dist/cjs/utils.js +92 -2
  23. package/dist/cjs/visitor.js +279 -284
  24. package/dist/esm/BaseVisitor.mjs +70 -47
  25. package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
  26. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  27. package/dist/esm/antlr/CircuitScriptParser.mjs +580 -613
  28. package/dist/esm/builtinMethods.mjs +29 -10
  29. package/dist/esm/draw_symbols.mjs +381 -238
  30. package/dist/esm/execute.mjs +144 -133
  31. package/dist/esm/export.mjs +2 -4
  32. package/dist/esm/geometry.mjs +52 -19
  33. package/dist/esm/globals.mjs +13 -8
  34. package/dist/esm/helpers.mjs +17 -4
  35. package/dist/esm/layout.mjs +144 -153
  36. package/dist/esm/logger.mjs +8 -1
  37. package/dist/esm/objects/ClassComponent.mjs +21 -26
  38. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  39. package/dist/esm/objects/Frame.mjs +4 -1
  40. package/dist/esm/objects/ParamDefinition.mjs +119 -3
  41. package/dist/esm/objects/PinDefinition.mjs +0 -2
  42. package/dist/esm/objects/types.mjs +42 -0
  43. package/dist/esm/render.mjs +44 -113
  44. package/dist/esm/sizing.mjs +34 -8
  45. package/dist/esm/utils.mjs +86 -1
  46. package/dist/esm/visitor.mjs +281 -286
  47. package/dist/types/BaseVisitor.d.ts +3 -2
  48. package/dist/types/antlr/CircuitScriptParser.d.ts +5 -3
  49. package/dist/types/draw_symbols.d.ts +81 -49
  50. package/dist/types/execute.d.ts +16 -11
  51. package/dist/types/geometry.d.ts +31 -19
  52. package/dist/types/globals.d.ts +15 -10
  53. package/dist/types/helpers.d.ts +2 -1
  54. package/dist/types/layout.d.ts +22 -21
  55. package/dist/types/logger.d.ts +1 -1
  56. package/dist/types/objects/ClassComponent.d.ts +19 -16
  57. package/dist/types/objects/ExecutionScope.d.ts +2 -1
  58. package/dist/types/objects/Frame.d.ts +5 -3
  59. package/dist/types/objects/ParamDefinition.d.ts +31 -2
  60. package/dist/types/objects/PinDefinition.d.ts +0 -2
  61. package/dist/types/objects/types.d.ts +7 -2
  62. package/dist/types/render.d.ts +2 -1
  63. package/dist/types/utils.d.ts +9 -1
  64. package/dist/types/visitor.d.ts +5 -5
  65. package/libs/lib.cst +102 -32
  66. package/package.json +7 -3
@@ -1,11 +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
+ const types_js_1 = require("./objects/types.js");
10
+ const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
9
11
  class SymbolGraphic {
10
12
  constructor() {
11
13
  this.drawPortsName = true;
@@ -13,7 +15,10 @@ class SymbolGraphic {
13
15
  this._angle = 0;
14
16
  this._flipX = 0;
15
17
  this._flipY = 0;
18
+ this.width = (0, ParamDefinition_js_1.numeric)(-1);
19
+ this.height = (0, ParamDefinition_js_1.numeric)(-1);
16
20
  this.labelTexts = new Map();
21
+ this.drawing = new SymbolDrawing();
17
22
  }
18
23
  get angle() {
19
24
  return (this._angle % 360);
@@ -39,15 +44,21 @@ class SymbolGraphic {
39
44
  }
40
45
  calculateSize() {
41
46
  const { width, height } = this.drawing.getBoundingBox();
42
- this.width = width;
43
- this.height = height;
44
- }
45
- size() {
47
+ this.width = (0, ParamDefinition_js_1.numeric)(width);
48
+ this.height = (0, ParamDefinition_js_1.numeric)(height);
46
49
  return {
50
+ bodyWidth: (0, ParamDefinition_js_1.numeric)(-1),
51
+ bodyHeight: (0, ParamDefinition_js_1.numeric)(-1),
47
52
  width: this.width,
48
53
  height: this.height
49
54
  };
50
55
  }
56
+ size() {
57
+ return {
58
+ width: this.width.toNumber(),
59
+ height: this.height.toNumber(),
60
+ };
61
+ }
51
62
  draw(group, extra) {
52
63
  const innerGroup = group.group();
53
64
  this.drawBody(innerGroup);
@@ -84,15 +95,15 @@ class SymbolGraphic {
84
95
  drawBounds(group) {
85
96
  const bbox = this.drawing.getBoundingBox();
86
97
  const originSize = (0, helpers_js_1.milsToMM)(10);
87
- group.circle(originSize)
88
- .translate(-originSize / 2, -originSize / 2)
98
+ group.circle(originSize.toNumber())
99
+ .translate(originSize.neg().div(2).toNumber(), originSize.neg().div(2).toNumber())
89
100
  .fill('red')
90
101
  .stroke('none');
91
102
  group.rect(bbox.width, bbox.height)
92
103
  .translate(bbox.start[0], bbox.start[1])
93
104
  .fill('none')
94
105
  .stroke({
95
- width: (0, helpers_js_1.milsToMM)(2),
106
+ width: (0, helpers_js_1.milsToMM)(2).toNumber(),
96
107
  color: '#ccc',
97
108
  });
98
109
  }
@@ -102,7 +113,7 @@ class SymbolGraphic {
102
113
  const { path, lineColor, fillColor, lineWidth } = pathInfo;
103
114
  group.path(path)
104
115
  .stroke({
105
- width: lineWidth,
116
+ width: lineWidth.toNumber(),
106
117
  color: lineColor,
107
118
  })
108
119
  .fill(fillColor);
@@ -122,7 +133,8 @@ class SymbolGraphic {
122
133
  const labels = this.drawing.getLabels();
123
134
  labels.forEach(label => {
124
135
  const tmpLabel = label;
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 ?? {};
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();
126
138
  let anchorStyle = 'start';
127
139
  let dominantBaseline = 'auto';
128
140
  let useAnchor = anchor;
@@ -134,40 +146,44 @@ class SymbolGraphic {
134
146
  }
135
147
  switch (useAnchor) {
136
148
  case geometry_js_1.HorizontalAlign.Left:
137
- anchorStyle = (this.flipX === 0) ? 'start' : 'end';
149
+ anchorStyle = (this.flipX === 0)
150
+ ? geometry_js_1.HorizontalAlignProp.Start : geometry_js_1.HorizontalAlignProp.End;
138
151
  break;
139
152
  case geometry_js_1.HorizontalAlign.Middle:
140
- anchorStyle = 'middle';
153
+ anchorStyle = geometry_js_1.HorizontalAlignProp.Middle;
141
154
  break;
142
155
  case geometry_js_1.HorizontalAlign.Right:
143
- anchorStyle = (this.flipX === 0) ? 'end' : 'start';
156
+ anchorStyle = (this.flipX === 0)
157
+ ? geometry_js_1.HorizontalAlignProp.End : geometry_js_1.HorizontalAlignProp.Start;
144
158
  break;
145
159
  }
146
160
  switch (useDominantBaseline) {
147
161
  case geometry_js_1.VerticalAlign.Top:
148
- dominantBaseline = (this.flipY === 0) ? 'hanging' : 'text-top';
162
+ dominantBaseline = (this.flipY === 0)
163
+ ? geometry_js_1.VerticalAlignProp.Hanging : geometry_js_1.VerticalAlignProp.TextTop;
149
164
  break;
150
165
  case geometry_js_1.VerticalAlign.Middle:
151
- dominantBaseline = 'middle';
166
+ dominantBaseline = geometry_js_1.VerticalAlignProp.Central;
152
167
  break;
153
168
  case geometry_js_1.VerticalAlign.Bottom:
154
- dominantBaseline = (this.flipY === 0) ? 'text-top' : 'hanging';
169
+ dominantBaseline = (this.flipY === 0)
170
+ ? geometry_js_1.VerticalAlignProp.TextTop : geometry_js_1.VerticalAlignProp.Hanging;
155
171
  break;
156
172
  }
157
173
  const position = tmpLabel.getLabelPosition();
158
174
  if (this.flipX !== 0) {
159
- position[0] *= -1;
175
+ position[0] = position[0].neg();
160
176
  }
161
177
  if (this.flipY !== 0) {
162
- position[1] *= -1;
178
+ position[1] = position[1].neg();
163
179
  }
164
180
  const useFont = globals_js_1.defaultFont;
165
181
  const textContainer = group.group();
166
182
  let translateX, translateY;
167
183
  let useRotateAngle = 0;
168
184
  if (isRotation180) {
169
- translateX = -position[0];
170
- translateY = -position[1];
185
+ translateX = position[0].neg();
186
+ translateY = position[1].neg();
171
187
  useRotateAngle = 0;
172
188
  }
173
189
  else {
@@ -237,7 +253,7 @@ class SymbolGraphic {
237
253
  }
238
254
  textContainer.path(path)
239
255
  .stroke({
240
- width: (0, helpers_js_1.milsToMM)(5),
256
+ width: (0, helpers_js_1.milsToMM)(5).toNumber(),
241
257
  color: '#333'
242
258
  })
243
259
  .fill('none')
@@ -245,47 +261,55 @@ class SymbolGraphic {
245
261
  .translate(boundsTranslateX, boundsY - paddingVert);
246
262
  }
247
263
  }
248
- const drawTextBounds = false;
249
- const drawBoxBounds = false;
250
- const drawOrigin = false;
251
- if (drawBoxBounds) {
264
+ if (globals_js_1.RenderFlags.ShowLabelBoxBounds) {
252
265
  const box = tmpLabel.box;
253
- 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
+ })
254
272
  .translate(box.xmin, box.ymin)
255
- .scale(this.flipX !== 0 ? -1 : 1, 1, -box.xmin, box.ymin);
273
+ .rotate(labelAngle, -box.xmin, -box.ymin);
256
274
  }
257
- if (drawTextBounds) {
275
+ if (globals_js_1.RenderFlags.ShowLabelBounds) {
258
276
  const textBounds = tmpLabel.textMeasurementBounds;
259
277
  const xOffset = (this.flipX !== 0) ? textBounds.width : 0;
260
- 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
+ })
261
284
  .translate(textBounds.x - xOffset, textBounds.y);
262
285
  }
263
- textContainer.translate(translateX, translateY)
264
- .rotate(useRotateAngle, -translateX, -translateY);
286
+ textContainer.translate(translateX.toNumber(), translateY.toNumber())
287
+ .rotate(useRotateAngle, -translateX.toNumber(), -translateY.toNumber());
265
288
  textContainer.text(tmpLabel.text)
266
289
  .fill(textColor)
267
290
  .font({
268
291
  family: useFont,
269
- size: fontSize * globals_js_1.fontDisplayScale,
292
+ size: fontSize.toNumber() * globals_js_1.fontDisplayScale,
270
293
  anchor: anchorStyle,
271
294
  'dominant-baseline': dominantBaseline,
272
295
  weight: fontWeight,
273
296
  })
274
- .rotate(labelAngle);
297
+ .attr("xml:space", "preserve")
298
+ .rotate(labelAngle, 0, 0);
275
299
  const { a, b, c, d, e, f } = textContainer.matrix();
276
300
  const newMatrix = {
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),
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(),
283
307
  };
284
308
  textContainer.transform(newMatrix);
285
- if (drawOrigin) {
286
- 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();
287
311
  textContainer.circle(originSize)
288
- .translate(originSize / 2, originSize / 2)
312
+ .translate(-originSize / 2, -originSize / 2)
289
313
  .fill('green');
290
314
  }
291
315
  });
@@ -312,43 +336,19 @@ class SymbolGraphic {
312
336
  return geometry_js_1.VerticalAlign.Middle;
313
337
  }
314
338
  }
315
- setLabelValue(labelId, labelValue) {
316
- this.labelTexts.set(labelId, labelValue);
317
- }
318
- getLabelValue(labelId) {
319
- if (this.labelTexts.has(labelId)) {
320
- return this.labelTexts.get(labelId);
321
- }
322
- return undefined;
323
- }
324
339
  }
325
340
  exports.SymbolGraphic = SymbolGraphic;
326
- function SymbolFactory(name) {
327
- switch (name) {
328
- case 'point':
329
- return new SymbolPointHidden();
330
- }
331
- return null;
332
- }
333
- exports.SymbolFactory = SymbolFactory;
334
- class SymbolPointHidden extends SymbolGraphic {
335
- generateDrawing() {
336
- const drawing = new SymbolDrawing();
337
- drawing.addPin(1, 0, 0, 0, 0);
338
- this.drawing = drawing;
339
- }
340
- }
341
- exports.SymbolPointHidden = SymbolPointHidden;
342
341
  class SymbolText extends SymbolGraphic {
343
342
  constructor(text) {
344
343
  super();
345
- this.fontSize = 40;
344
+ this.fontSize = (0, ParamDefinition_js_1.numeric)(40);
346
345
  this.fontWeight = 'regular';
347
346
  this.text = text;
348
347
  }
349
348
  generateDrawing() {
350
- const drawing = new SymbolDrawing();
351
- drawing.addTextbox(0, 0, this.text, {
349
+ const drawing = this.drawing;
350
+ drawing.clear();
351
+ drawing.addTextbox((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), this.text, {
352
352
  fontSize: this.fontSize,
353
353
  anchor: geometry_js_1.HorizontalAlign.Middle,
354
354
  fontWeight: this.fontWeight,
@@ -369,13 +369,23 @@ class SymbolPlaceholder extends SymbolGraphic {
369
369
  [PlaceHolderCommands.units, ['mils'], {}],
370
370
  [PlaceHolderCommands.lineColor, [globals_js_1.ColorScheme.PinLineColor], {}],
371
371
  [PlaceHolderCommands.textColor, [globals_js_1.ColorScheme.PinNameColor], {}],
372
- [PlaceHolderCommands.lineWidth, [5], {}],
372
+ [PlaceHolderCommands.lineWidth, [(0, ParamDefinition_js_1.numeric)(5)], {}],
373
373
  ...drawing.getCommands()
374
374
  ];
375
375
  drawing.log('id: ', drawing.id, 'angle: ', this._angle, "commands:", commands.length);
376
376
  let lineColor = "#333";
377
377
  let textColor = "#333";
378
- commands.forEach(([commandName, positionParams, keywordParams]) => {
378
+ commands.forEach(([commandName, positionParams, keywordParams, ctx]) => {
379
+ positionParams = positionParams.map(param => {
380
+ return this.resolveReference(param);
381
+ });
382
+ if (keywordParams instanceof Map) {
383
+ const tmpKeywordParams = new Map(keywordParams);
384
+ tmpKeywordParams.forEach((value, key) => {
385
+ tmpKeywordParams.set(key, this.resolveReference(value));
386
+ });
387
+ keywordParams = tmpKeywordParams;
388
+ }
379
389
  switch (commandName) {
380
390
  case PlaceHolderCommands.rect:
381
391
  drawing.log('add rect', ...positionParams);
@@ -414,7 +424,7 @@ class SymbolPlaceholder extends SymbolGraphic {
414
424
  drawing.addArc(...positionParams);
415
425
  break;
416
426
  case PlaceHolderCommands.circle:
417
- drawing.addArc(...positionParams, 0, 360);
427
+ drawing.addArc(...positionParams, (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(360));
418
428
  break;
419
429
  case PlaceHolderCommands.triangle:
420
430
  drawing.addTriangle(...positionParams);
@@ -431,23 +441,24 @@ class SymbolPlaceholder extends SymbolGraphic {
431
441
  if (style['textColor'] === undefined) {
432
442
  style['textColor'] = textColor;
433
443
  }
434
- positionParams = [...positionParams];
435
- positionParams.push(style);
436
- const labelId = positionParams[0];
437
- const tmpPositionParams = [...positionParams];
438
- const tmpLabelValue = this.getLabelValue(labelId);
439
- if (tmpLabelValue !== undefined) {
440
- tmpPositionParams[3] = tmpLabelValue;
441
- }
444
+ const tmpPositionParams = [
445
+ positionParams[1], positionParams[2],
446
+ positionParams[0], style
447
+ ];
442
448
  drawing.log('add label', JSON.stringify(tmpPositionParams));
443
- drawing.addLabelId(...tmpPositionParams);
449
+ try {
450
+ drawing.addLabelMils(...tmpPositionParams);
451
+ }
452
+ catch (err) {
453
+ (0, utils_js_1.throwWithContext)(ctx, err);
454
+ }
444
455
  break;
445
456
  }
446
457
  case PlaceHolderCommands.text: {
447
458
  const style = this.parseLabelStyle(keywordParams);
448
459
  const content = keywordParams.get('content');
449
- let offsetX = 0;
450
- let offsetY = 0;
460
+ let offsetX = (0, ParamDefinition_js_1.numeric)(0);
461
+ let offsetY = (0, ParamDefinition_js_1.numeric)(0);
451
462
  if (keywordParams.has('offset')) {
452
463
  const offset = keywordParams.get('offset');
453
464
  offsetX = offset[0];
@@ -464,13 +475,30 @@ class SymbolPlaceholder extends SymbolGraphic {
464
475
  });
465
476
  drawing.log("=== end generate drawing ===");
466
477
  }
478
+ resolveReference(param) {
479
+ if (param instanceof types_js_1.DeclaredReference) {
480
+ return param.value;
481
+ }
482
+ else if (param instanceof types_js_1.UndeclaredReference) {
483
+ throw "Undefined symbol: " + param.nameString();
484
+ }
485
+ return param;
486
+ }
467
487
  parseLabelStyle(keywordParams) {
468
488
  const keywords = ['fontSize', 'anchor', 'vanchor',
469
- 'angle', 'textColor', 'portType'];
489
+ 'angle', 'textColor', 'portType', 'bold'];
470
490
  const style = {};
471
491
  keywords.forEach(item => {
472
492
  if (keywordParams.has(item)) {
473
493
  style[item] = keywordParams.get(item);
494
+ if (item === 'bold') {
495
+ if (keywordParams.get(item) === true) {
496
+ style['fontWeight'] = 'bold';
497
+ }
498
+ else {
499
+ style['fontWeight'] = 'normal';
500
+ }
501
+ }
474
502
  }
475
503
  });
476
504
  return style;
@@ -482,6 +510,9 @@ class SymbolPlaceholder extends SymbolGraphic {
482
510
  let displayPinId = true;
483
511
  if (keywordParams.has(keywordDisplayPinId)) {
484
512
  const value = keywordParams.get(keywordDisplayPinId);
513
+ if (value instanceof ParamDefinition_js_1.NumericValue && value.toNumber() === 0) {
514
+ displayPinId = false;
515
+ }
485
516
  if (value === 0 || value === false) {
486
517
  displayPinId = false;
487
518
  }
@@ -505,7 +536,7 @@ class SymbolPlaceholder extends SymbolGraphic {
505
536
  startX,
506
537
  startY,
507
538
  startX,
508
- startY + magnitude
539
+ startY.add(magnitude)
509
540
  ];
510
541
  }
511
542
  else if (commandName === PlaceHolderCommands.hpin) {
@@ -514,7 +545,7 @@ class SymbolPlaceholder extends SymbolGraphic {
514
545
  positionParams[0],
515
546
  startX,
516
547
  startY,
517
- startX + magnitude,
548
+ startX.add(magnitude),
518
549
  startY
519
550
  ];
520
551
  }
@@ -536,11 +567,12 @@ class SymbolPlaceholder extends SymbolGraphic {
536
567
  const offset1 = 15;
537
568
  const offset2 = 15;
538
569
  let pinNameOffsetX = (0, helpers_js_1.milsToMM)(offset1);
539
- let pinIdOffsetX = 0;
570
+ let pinIdOffsetX = (0, ParamDefinition_js_1.numeric)(0);
540
571
  let pinIdAlignment = geometry_js_1.HorizontalAlign.Left;
541
572
  let pinIdVAlignment = geometry_js_1.VerticalAlign.Bottom;
542
573
  let pinIdOffsetY = (0, helpers_js_1.milsToMM)(-offset2);
543
- switch (angle) {
574
+ const angleValue = angle.toNumber();
575
+ switch (angleValue) {
544
576
  case 0:
545
577
  pinNameAlignment = geometry_js_1.HorizontalAlign.Left;
546
578
  pinNameOffsetX = (0, helpers_js_1.milsToMM)(offset1);
@@ -563,16 +595,16 @@ class SymbolPlaceholder extends SymbolGraphic {
563
595
  pinIdVAlignment = geometry_js_1.VerticalAlign.Top;
564
596
  break;
565
597
  }
566
- if (angle === 0 || angle === 90 || angle === 180 || angle === 270) {
598
+ if (angleValue === 0 || angleValue === 90 || angleValue === 180 || angleValue === 270) {
567
599
  const usePinName = pinNameParam ?? "";
568
- usePinName !== "" && drawing.addLabel(endX + pinNameOffsetX, endY, usePinName, {
569
- 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),
570
602
  anchor: pinNameAlignment,
571
603
  vanchor: geometry_js_1.VerticalAlign.Middle,
572
604
  textColor: pinNameColor,
573
605
  });
574
- displayPinId && drawing.addLabel(endX + pinIdOffsetX, endY + pinIdOffsetY, pinId.toString(), {
575
- 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),
576
608
  anchor: pinIdAlignment,
577
609
  vanchor: pinIdVAlignment,
578
610
  textColor: lineColor
@@ -608,58 +640,75 @@ var PlaceHolderCommands;
608
640
  PlaceHolderCommands["for"] = "for";
609
641
  })(PlaceHolderCommands || (exports.PlaceHolderCommands = PlaceHolderCommands = {}));
610
642
  class SymbolCustom extends SymbolGraphic {
611
- constructor(pinDefinition) {
643
+ constructor(pinDefinition, pinMaxPositions) {
612
644
  super();
613
645
  this.pinDefinition = [];
614
646
  this.bodyWidth = (0, helpers_js_1.milsToMM)(400);
647
+ this.bodyHeight = (0, helpers_js_1.milsToMM)(100);
615
648
  this.pinLength = (0, helpers_js_1.milsToMM)(100);
616
649
  this.width = (0, helpers_js_1.milsToMM)(100);
617
650
  this.height = (0, helpers_js_1.milsToMM)(100);
618
651
  this.pinSpacing = (0, helpers_js_1.milsToMM)(100);
619
652
  this.pinTextPadding = (0, helpers_js_1.milsToMM)(5);
620
653
  this.pins = [];
654
+ this._cacheLeftPins = [];
655
+ this._cacheRightPins = [];
656
+ this._cacheTopPins = [];
657
+ this._cacheBottomPins = [];
621
658
  this.pinDefinition = pinDefinition;
659
+ this.pinMaxPositions = pinMaxPositions;
622
660
  }
623
661
  generateDrawing() {
624
- const leftPins = this.pinDefinition.filter(item => {
625
- return item.side === globals_js_1.SymbolPinSide.Left;
626
- });
627
- const rightPins = this.pinDefinition.filter(item => {
628
- return item.side === globals_js_1.SymbolPinSide.Right;
629
- });
630
- const maxLeftPins = Math.max(...leftPins.map(item => item.position)) + 1;
631
- const maxRightPins = Math.max(...rightPins.map(item => item.position)) + 1;
632
- const drawing = new SymbolDrawing();
662
+ const leftPins = this.getPins(globals_js_1.SymbolPinSide.Left);
663
+ const rightPins = this.getPins(globals_js_1.SymbolPinSide.Right);
664
+ const topPins = this.getPins(globals_js_1.SymbolPinSide.Top);
665
+ const bottomPins = this.getPins(globals_js_1.SymbolPinSide.Bottom);
666
+ this.drawing.clear();
667
+ const drawing = this.drawing;
633
668
  drawing.angle = this._angle;
634
669
  drawing.flipX = this._flipX;
635
670
  drawing.flipY = this._flipY;
636
- const bodyWidth = this.bodyWidth;
637
- const bodyHeight = (1 + Math.max(maxLeftPins, maxRightPins)) * this.pinSpacing;
671
+ const { bodyWidth, bodyHeight } = this.calculateSize();
638
672
  const defaultLineColor = globals_js_1.ColorScheme.PinLineColor;
639
673
  drawing.addSetLineColor(defaultLineColor);
640
- drawing.addSetLineWidth(5);
641
- drawing.addRectMM(0, 0, bodyWidth, bodyHeight);
642
- this.generateDrawingPins(drawing, bodyWidth, bodyHeight, leftPins, rightPins, defaultLineColor);
674
+ drawing.addSetLineWidth((0, ParamDefinition_js_1.numeric)(5));
675
+ drawing.addRectMM((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), bodyWidth, bodyHeight);
676
+ this.generateDrawingPins(drawing, bodyWidth, bodyHeight, {
677
+ left: leftPins, right: rightPins, top: topPins, bottom: bottomPins
678
+ }, defaultLineColor);
643
679
  this.drawing = drawing;
644
680
  this._cacheLeftPins = leftPins;
645
681
  this._cacheRightPins = rightPins;
682
+ this._cacheTopPins = topPins;
683
+ this._cacheBottomPins = bottomPins;
646
684
  }
647
- generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, leftPins, rightPins, defaultLineColor) {
648
- const leftPinStart = -bodyWidthMM / 2;
649
- const rightPinStart = bodyWidthMM / 2;
650
- 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().div(2);
694
+ const rightPinStart = bodyWidthMM.div(2);
695
+ const topPinStart = bodyHeightMM.neg().div(2);
696
+ const bottomPinStart = bodyHeightMM.div(2);
697
+ const pinStartY = bodyHeightMM.neg().div(2);
698
+ const pinStartX = bodyWidthMM.neg().div(2);
699
+ const tmpPinSpacing = this.pinSpacing.toNumber();
651
700
  leftPins.forEach(pin => {
652
701
  const position = pin.position;
653
- const pinY = pinStartY + (position + 1) * this.pinSpacing;
654
- drawing.addPinMM(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
655
- drawing.addLabel(leftPinStart + (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
656
- fontSize: globals_js_1.CustomSymbolPinTextSize,
702
+ const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
703
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
704
+ drawing.addLabel(leftPinStart.add((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
705
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
657
706
  anchor: geometry_js_1.HorizontalAlign.Left,
658
707
  vanchor: geometry_js_1.VerticalAlign.Middle,
659
708
  textColor: globals_js_1.ColorScheme.PinNameColor,
660
709
  });
661
- drawing.addLabel(leftPinStart - (0, helpers_js_1.milsToMM)(10), pinY - (0, helpers_js_1.milsToMM)(10), pin.pinId.toString(), {
662
- fontSize: globals_js_1.CustomSymbolPinIdSize,
710
+ drawing.addLabel(leftPinStart.sub((0, helpers_js_1.milsToMM)(10)), pinY.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
711
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
663
712
  anchor: geometry_js_1.HorizontalAlign.Right,
664
713
  vanchor: geometry_js_1.VerticalAlign.Bottom,
665
714
  textColor: defaultLineColor
@@ -667,32 +716,70 @@ class SymbolCustom extends SymbolGraphic {
667
716
  });
668
717
  rightPins.forEach(pin => {
669
718
  const position = pin.position;
670
- const pinY = pinStartY + (position + 1) * this.pinSpacing;
671
- drawing.addPinMM(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
672
- drawing.addLabel(rightPinStart - (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
673
- fontSize: globals_js_1.CustomSymbolPinTextSize,
719
+ const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
720
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
721
+ drawing.addLabel(rightPinStart.sub((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
722
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
674
723
  anchor: geometry_js_1.HorizontalAlign.Right,
675
724
  vanchor: geometry_js_1.VerticalAlign.Middle,
676
725
  textColor: globals_js_1.ColorScheme.PinNameColor,
677
726
  });
678
- drawing.addLabel(rightPinStart + (0, helpers_js_1.milsToMM)(10), pinY - (0, helpers_js_1.milsToMM)(10), pin.pinId.toString(), {
679
- fontSize: globals_js_1.CustomSymbolPinIdSize,
727
+ drawing.addLabel(rightPinStart.add((0, helpers_js_1.milsToMM)(10)), pinY.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
728
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
680
729
  anchor: geometry_js_1.HorizontalAlign.Left,
681
730
  vanchor: geometry_js_1.VerticalAlign.Bottom,
682
731
  textColor: defaultLineColor
683
732
  });
684
733
  });
685
- const instanceName = this.getLabelValue("refdes");
686
- instanceName && drawing.addLabel(-bodyWidthMM / 2, -bodyHeightMM / 2 - (0, helpers_js_1.milsToMM)(20), instanceName, {
687
- fontSize: globals_js_1.CustomSymbolRefDesSize,
734
+ topPins.forEach(pin => {
735
+ const position = pin.position;
736
+ const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
737
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
738
+ drawing.addLabel(pinX, topPinStart.add((0, helpers_js_1.milsToMM)(20)), pin.text, {
739
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
740
+ anchor: geometry_js_1.HorizontalAlign.Right,
741
+ vanchor: geometry_js_1.VerticalAlign.Middle,
742
+ textColor: globals_js_1.ColorScheme.PinNameColor,
743
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
744
+ });
745
+ drawing.addLabel(pinX.sub((0, helpers_js_1.milsToMM)(10)), topPinStart.sub((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
746
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
747
+ anchor: geometry_js_1.HorizontalAlign.Left,
748
+ vanchor: geometry_js_1.VerticalAlign.Bottom,
749
+ textColor: defaultLineColor,
750
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
751
+ });
752
+ });
753
+ bottomPins.forEach(pin => {
754
+ const position = pin.position;
755
+ const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
756
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
757
+ drawing.addLabel(pinX, bottomPinStart.sub((0, helpers_js_1.milsToMM)(20)), pin.text, {
758
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
759
+ anchor: geometry_js_1.HorizontalAlign.Left,
760
+ vanchor: geometry_js_1.VerticalAlign.Middle,
761
+ textColor: globals_js_1.ColorScheme.PinNameColor,
762
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
763
+ });
764
+ drawing.addLabel(pinX.sub((0, helpers_js_1.milsToMM)(10)), bottomPinStart.add((0, helpers_js_1.milsToMM)(10)), pin.pinId.toString(), {
765
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinIdSize),
766
+ anchor: geometry_js_1.HorizontalAlign.Right,
767
+ vanchor: geometry_js_1.VerticalAlign.Bottom,
768
+ textColor: defaultLineColor,
769
+ angle: (0, ParamDefinition_js_1.numeric)(-90)
770
+ });
771
+ });
772
+ const instanceName = drawing.variables.get('refdes');
773
+ instanceName && drawing.addLabel(bodyWidthMM.neg().div(2), bodyHeightMM.neg().div(2).sub((0, helpers_js_1.milsToMM)(20)), instanceName, {
774
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolRefDesSize),
688
775
  anchor: geometry_js_1.HorizontalAlign.Left,
689
776
  });
690
777
  const acceptedMPNKeys = ['MPN', 'mpn', 'manufacturer_pn'];
691
778
  acceptedMPNKeys.some(key => {
692
- const labelValue = this.getLabelValue(key);
779
+ const labelValue = drawing.variables.get(key);
693
780
  if (labelValue !== undefined) {
694
- drawing.addLabel(-bodyWidthMM / 2, bodyHeightMM / 2 + (0, helpers_js_1.milsToMM)(20), labelValue, {
695
- fontSize: globals_js_1.CustomSymbolParamTextSize,
781
+ drawing.addLabel(bodyWidthMM.neg().div(2), bodyHeightMM.div(2).add((0, helpers_js_1.milsToMM)(20)), labelValue, {
782
+ fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolParamTextSize),
696
783
  anchor: geometry_js_1.HorizontalAlign.Left,
697
784
  vanchor: geometry_js_1.VerticalAlign.Top,
698
785
  });
@@ -700,29 +787,59 @@ class SymbolCustom extends SymbolGraphic {
700
787
  });
701
788
  }
702
789
  calculateSize() {
703
- this.width = this.bodyWidth + 2 * this.pinLength;
704
- 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 { [globals_js_1.SymbolPinSide.Top]: maxTopPins, [globals_js_1.SymbolPinSide.Bottom]: maxBottomPins, [globals_js_1.SymbolPinSide.Left]: maxLeftPins, [globals_js_1.SymbolPinSide.Right]: maxRightPins } = this.pinMaxPositions;
793
+ const bodyWidthFromPins = (0, ParamDefinition_js_1.numeric)((1 + Math.max(maxTopPins, maxBottomPins)) * tmpPinSpacing);
794
+ const bodyWidth = Math.max(bodyWidthFromPins.toNumber(), this.bodyWidth.toNumber());
795
+ let tmpBodyHeight = 0;
796
+ if (maxLeftPins === 0 && maxRightPins === 0) {
797
+ tmpBodyHeight = 3;
798
+ }
799
+ else {
800
+ tmpBodyHeight = (1 + Math.max(maxLeftPins, maxRightPins));
801
+ }
802
+ const bodyHeight = Math.max(tmpBodyHeight * tmpPinSpacing, this.bodyHeight.toNumber());
803
+ const useHeight = bodyHeight
804
+ + ((this._cacheTopPins.length > 0) ? tmpPinLength : 0)
805
+ + ((this._cacheBottomPins.length > 0) ? tmpPinLength : 0);
806
+ const useWidth = bodyWidth
807
+ + ((this._cacheLeftPins.length > 0) ? tmpPinLength : 0)
808
+ + ((this._cacheRightPins.length > 0) ? tmpPinLength : 0);
809
+ this.width = (0, ParamDefinition_js_1.numeric)(useWidth);
810
+ this.height = (0, ParamDefinition_js_1.numeric)(useHeight);
811
+ return {
812
+ bodyWidth: (0, ParamDefinition_js_1.numeric)(bodyWidth),
813
+ bodyHeight: (0, ParamDefinition_js_1.numeric)(bodyHeight),
814
+ width: this.width,
815
+ height: this.height
816
+ };
705
817
  }
706
818
  }
707
819
  exports.SymbolCustom = SymbolCustom;
708
820
  class SymbolCustomModule extends SymbolCustom {
709
821
  constructor() {
710
822
  super(...arguments);
711
- this.pinLength = 0;
823
+ this.pinLength = (0, helpers_js_1.milsToMM)(0);
712
824
  this.portWidth = (0, helpers_js_1.milsToMM)(100);
713
825
  this.portHeight = (0, helpers_js_1.milsToMM)(50);
714
826
  }
715
- generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, leftPins, rightPins, defaultLineColor) {
716
- const leftPinStart = -bodyWidthMM / 2;
717
- const rightPinStart = bodyWidthMM / 2;
718
- const pinStartY = -bodyHeightMM / 2;
827
+ generateDrawingPins(drawing, bodyWidthMM, bodyHeightMM, pins, defaultLineColor) {
828
+ const leftPinStart = bodyWidthMM.neg().div(2);
829
+ const rightPinStart = bodyWidthMM.div(2);
830
+ const topPinStart = bodyHeightMM.neg().div(2);
831
+ const bottomPinStart = bodyHeightMM.div(2);
832
+ const pinStartY = bodyHeightMM.neg().div(2);
833
+ const pinStartX = bodyWidthMM.neg().div(2);
834
+ const tmpPinSpacing = this.pinSpacing.toNumber();
835
+ const { left: leftPins, right: rightPins, top: topPins, bottom: bottomPins } = pins;
719
836
  leftPins.forEach(pin => {
720
837
  const position = pin.position;
721
- const pinY = pinStartY + (position + 1) * this.pinSpacing;
722
- drawing.addPinMM(pin.pinId, leftPinStart - this.pinLength, pinY, leftPinStart, pinY, defaultLineColor);
838
+ const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
839
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
723
840
  drawing.addModulePort(leftPinStart, pinY, this.portWidth, this.portHeight, pin.pinType);
724
- drawing.addLabel(leftPinStart + this.portWidth + (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
725
- fontSize: 40,
841
+ drawing.addLabel(leftPinStart.add(this.portWidth).add((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
842
+ fontSize: (0, ParamDefinition_js_1.numeric)(40),
726
843
  anchor: geometry_js_1.HorizontalAlign.Left,
727
844
  vanchor: geometry_js_1.VerticalAlign.Middle,
728
845
  textColor: globals_js_1.ColorScheme.PinNameColor,
@@ -730,14 +847,40 @@ class SymbolCustomModule extends SymbolCustom {
730
847
  });
731
848
  rightPins.forEach(pin => {
732
849
  const position = pin.position;
733
- const pinY = pinStartY + (position + 1) * this.pinSpacing;
734
- drawing.addPinMM(pin.pinId, rightPinStart + this.pinLength, pinY, rightPinStart, pinY, defaultLineColor);
850
+ const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
851
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
735
852
  drawing.addModulePort(rightPinStart, pinY, this.portWidth, this.portHeight, pin.pinType, -1);
736
- drawing.addLabel(rightPinStart - this.portWidth - (0, helpers_js_1.milsToMM)(20), pinY, pin.text, {
737
- fontSize: 40,
853
+ drawing.addLabel(rightPinStart.sub(this.portWidth).sub((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
854
+ fontSize: (0, ParamDefinition_js_1.numeric)(40),
855
+ anchor: geometry_js_1.HorizontalAlign.Right,
856
+ vanchor: geometry_js_1.VerticalAlign.Middle,
857
+ textColor: globals_js_1.ColorScheme.PinNameColor,
858
+ });
859
+ });
860
+ topPins.forEach(pin => {
861
+ const position = pin.position;
862
+ const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
863
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
864
+ drawing.addModulePort(pinX, topPinStart, this.portWidth, this.portHeight, pin.pinType, 1, 90);
865
+ drawing.addLabel(pinX, topPinStart.add(this.portWidth).add((0, helpers_js_1.milsToMM)(20)), pin.text, {
866
+ fontSize: (0, ParamDefinition_js_1.numeric)(40),
738
867
  anchor: geometry_js_1.HorizontalAlign.Right,
739
868
  vanchor: geometry_js_1.VerticalAlign.Middle,
740
869
  textColor: globals_js_1.ColorScheme.PinNameColor,
870
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
871
+ });
872
+ });
873
+ bottomPins.forEach(pin => {
874
+ const position = pin.position;
875
+ const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
876
+ drawing.addPinMM((0, ParamDefinition_js_1.numeric)(pin.pinId), pinX, bottomPinStart, pinX, bottomPinStart.sub(this.pinLength), defaultLineColor);
877
+ drawing.addModulePort(pinX, bottomPinStart, this.portWidth, this.portHeight, pin.pinType, 1, -90);
878
+ drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub((0, helpers_js_1.milsToMM)(20)), pin.text, {
879
+ fontSize: (0, ParamDefinition_js_1.numeric)(40),
880
+ anchor: geometry_js_1.HorizontalAlign.Left,
881
+ vanchor: geometry_js_1.VerticalAlign.Middle,
882
+ textColor: globals_js_1.ColorScheme.PinNameColor,
883
+ angle: (0, ParamDefinition_js_1.numeric)(-90),
741
884
  });
742
885
  });
743
886
  }
@@ -750,8 +893,9 @@ class SymbolDrawing {
750
893
  this.angle = 0;
751
894
  this.flipX = 0;
752
895
  this.flipY = 0;
753
- this.mainOrigin = [0, 0];
896
+ this.mainOrigin = [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)];
754
897
  this.logger = null;
898
+ this.variables = new Map();
755
899
  }
756
900
  clear() {
757
901
  this.items = [];
@@ -777,26 +921,30 @@ class SymbolDrawing {
777
921
  }
778
922
  addPinMM(pinId, startXMM, startYMM, endXMM, endYMM, lineColor) {
779
923
  let angle = 0;
780
- if (startXMM === endXMM) {
781
- if (startYMM > endYMM) {
924
+ const tmpStartXMM = startXMM.toNumber();
925
+ const tmpEndXMM = endXMM.toNumber();
926
+ const tmpStartYMM = startYMM.toNumber();
927
+ const tmpEndYMM = endYMM.toNumber();
928
+ if (tmpStartXMM === tmpEndXMM) {
929
+ if (tmpStartYMM > tmpEndYMM) {
782
930
  angle = 270;
783
931
  }
784
- else if (startYMM < endYMM) {
932
+ else if (tmpStartYMM < tmpEndYMM) {
785
933
  angle = 90;
786
934
  }
787
935
  }
788
936
  else {
789
- if (startXMM < endXMM) {
937
+ if (tmpStartXMM < tmpEndXMM) {
790
938
  angle = 0;
791
939
  }
792
- else if (startXMM > endXMM) {
940
+ else if (tmpStartXMM > tmpEndXMM) {
793
941
  angle = 180;
794
942
  }
795
943
  }
796
944
  this.pins.push([
797
945
  pinId,
798
946
  geometry_js_1.Geometry.segment([startXMM, startYMM], [endXMM, endYMM]),
799
- angle,
947
+ (0, ParamDefinition_js_1.numeric)(angle),
800
948
  lineColor
801
949
  ]);
802
950
  return this;
@@ -805,14 +953,14 @@ class SymbolDrawing {
805
953
  startX = (0, helpers_js_1.milsToMM)(startX);
806
954
  startY = (0, helpers_js_1.milsToMM)(startY);
807
955
  value = (0, helpers_js_1.milsToMM)(value);
808
- this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX, startY + value]));
956
+ this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX, startY.add(value)]));
809
957
  return this;
810
958
  }
811
959
  addHLine(startX, startY, value) {
812
960
  startX = (0, helpers_js_1.milsToMM)(startX);
813
961
  startY = (0, helpers_js_1.milsToMM)(startY);
814
962
  value = (0, helpers_js_1.milsToMM)(value);
815
- this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX + value, startY]));
963
+ this.items.push(geometry_js_1.Geometry.segment([startX, startY], [startX.add(value), startY]));
816
964
  return this;
817
965
  }
818
966
  addRect(centerX, centerY, width, height) {
@@ -823,14 +971,14 @@ class SymbolDrawing {
823
971
  return this.addRectMM(centerX, centerY, width, height);
824
972
  }
825
973
  addRectMM(centerX, centerY, width, height) {
826
- const width2 = width / 2;
827
- const height2 = height / 2;
974
+ const width2 = width.div(2);
975
+ const height2 = height.div(2);
828
976
  this.items.push(geometry_js_1.Geometry.polygon([
829
- [centerX - width2, centerY - height2],
830
- [centerX + width2, centerY - height2],
831
- [centerX + width2, centerY + height2],
832
- [centerX - width2, centerY + height2],
833
- [centerX - width2, centerY - height2]
977
+ [centerX.sub(width2), centerY.sub(height2)],
978
+ [centerX.add(width2), centerY.sub(height2)],
979
+ [centerX.add(width2), centerY.add(height2)],
980
+ [centerX.sub(width2), centerY.add(height2)],
981
+ [centerX.sub(width2), centerY.sub(height2)]
834
982
  ]));
835
983
  return this;
836
984
  }
@@ -842,25 +990,15 @@ class SymbolDrawing {
842
990
  width = (0, helpers_js_1.milsToMM)(width);
843
991
  const line = geometry_js_1.Geometry.line(startX, startY, endX, endY);
844
992
  const normLine = line.norm;
845
- const dx1 = normLine.x * width / 2;
846
- const dy1 = normLine.y * width / 2;
847
- const dx2 = normLine.x * -width / 2;
848
- const dy2 = normLine.y * -width / 2;
993
+ const dx1 = (0, ParamDefinition_js_1.numeric)(normLine.x).mul(width).div(2);
994
+ const dy1 = (0, ParamDefinition_js_1.numeric)(normLine.y).mul(width).div(2);
995
+ const dx2 = (0, ParamDefinition_js_1.numeric)(normLine.x).mul(width.neg()).div(2);
996
+ const dy2 = (0, ParamDefinition_js_1.numeric)(normLine.y).mul(width.neg()).div(2);
849
997
  this.items.push(geometry_js_1.Geometry.polygon([
850
- [dx1 + startX, dy1 + startY],
851
- [dx2 + startX, dy2 + startY],
998
+ [dx1.add(startX), dy1.add(startY)],
999
+ [dx2.add(startX), dy2.add(startY)],
852
1000
  [endX, endY],
853
- [dx1 + startX, dy1 + startY],
854
- ]));
855
- return this;
856
- }
857
- addRect2(x, y, x2, y2) {
858
- this.items.push(geometry_js_1.Geometry.polygon([
859
- [x, y],
860
- [x2, y],
861
- [x2, y2],
862
- [x, y2],
863
- [x, y]
1001
+ [dx1.add(startX), dy1.add(startY)],
864
1002
  ]));
865
1003
  return this;
866
1004
  }
@@ -868,10 +1006,10 @@ class SymbolDrawing {
868
1006
  this.items.push(geometry_js_1.Geometry.label(null, x, y, textValue, style));
869
1007
  return this;
870
1008
  }
871
- addLabelId(id, x, y, textValue, style) {
1009
+ addLabelMils(x, y, textValue, style) {
872
1010
  x = (0, helpers_js_1.milsToMM)(x);
873
1011
  y = (0, helpers_js_1.milsToMM)(y);
874
- this.items.push(geometry_js_1.Geometry.label(id, x, y, textValue, style));
1012
+ this.items.push(geometry_js_1.Geometry.label(null, x, y, textValue, style));
875
1013
  return this;
876
1014
  }
877
1015
  addTextbox(x, y, textValue, style) {
@@ -880,54 +1018,59 @@ class SymbolDrawing {
880
1018
  this.items.push(geometry_js_1.Geometry.textbox(null, x, y, textValue, style));
881
1019
  return this;
882
1020
  }
883
- addModulePort(x, y, width, height, portType = PinTypes_js_1.PinTypes.Any, scaleX = 1) {
884
- const height2 = height / 2;
1021
+ addModulePort(x, y, width, height, portType = PinTypes_js_1.PinTypes.Any, scaleX = 1, angle = 0) {
1022
+ const height2 = height.div(2);
885
1023
  let path = [];
886
1024
  const arrowSize = (0, helpers_js_1.milsToMM)(30);
887
1025
  if (portType === PinTypes_js_1.PinTypes.Any) {
888
1026
  path = [
889
- [0, -height2],
890
- [width, -height2],
891
- [width, +height2],
892
- [0, +height2],
893
- [0, -height2]
1027
+ [(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
1028
+ [width, height2.neg()],
1029
+ [width, height2],
1030
+ [(0, ParamDefinition_js_1.numeric)(0), height2],
1031
+ [(0, ParamDefinition_js_1.numeric)(0), height2.neg()]
894
1032
  ];
895
1033
  }
896
1034
  else if (portType === PinTypes_js_1.PinTypes.Output) {
897
1035
  path = [
898
- [arrowSize, -height2],
899
- [width, -height2],
1036
+ [arrowSize, height2.neg()],
1037
+ [width, height2.neg()],
900
1038
  [width, height2],
901
1039
  [arrowSize, height2],
902
- [0, 0],
903
- [arrowSize, -height2]
1040
+ [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
1041
+ [arrowSize, height2.neg()]
904
1042
  ];
905
1043
  }
906
1044
  else if (portType === PinTypes_js_1.PinTypes.Input) {
907
1045
  path = [
908
- [0, -height2],
909
- [width - arrowSize, -height2],
910
- [width, 0],
911
- [width - arrowSize, height2],
912
- [0, +height2],
913
- [0, -height2],
1046
+ [(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
1047
+ [width.sub(arrowSize), height2.neg()],
1048
+ [width, (0, ParamDefinition_js_1.numeric)(0)],
1049
+ [width.sub(arrowSize), height2],
1050
+ [(0, ParamDefinition_js_1.numeric)(0), height2],
1051
+ [(0, ParamDefinition_js_1.numeric)(0), height2.neg()],
914
1052
  ];
915
1053
  }
916
1054
  else if (portType === PinTypes_js_1.PinTypes.IO) {
917
1055
  path = [
918
- [arrowSize, -height2],
919
- [width - arrowSize, -height2],
920
- [width, 0],
921
- [width - arrowSize, +height2],
922
- [arrowSize, +height2],
923
- [0, 0],
924
- [0 + arrowSize, -height2],
1056
+ [arrowSize, height2.neg()],
1057
+ [width.sub(arrowSize), height2.neg()],
1058
+ [width, (0, ParamDefinition_js_1.numeric)(0)],
1059
+ [width.sub(arrowSize), height2],
1060
+ [arrowSize, height2],
1061
+ [(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
1062
+ [arrowSize, height2.neg()],
925
1063
  ];
926
1064
  }
927
1065
  path = path.map(point => {
928
- return [x + point[0] * scaleX, y + point[1]];
1066
+ return [
1067
+ x.add(point[0].mul(scaleX)),
1068
+ y.add(point[1])
1069
+ ];
929
1070
  });
930
- this.items.push(geometry_js_1.Geometry.polygon(path));
1071
+ const polygon = geometry_js_1.Geometry.polygon(path)
1072
+ .rotate(angle * Math.PI / 180, geometry_js_1.Geometry.point(x, y));
1073
+ this.items.push(polygon);
931
1074
  return this;
932
1075
  }
933
1076
  addPath(...pathParts) {
@@ -936,6 +1079,9 @@ class SymbolDrawing {
936
1079
  accum = accum.concat(tmp.split(" "));
937
1080
  }
938
1081
  else if (typeof tmp === "number") {
1082
+ accum.push((0, ParamDefinition_js_1.numeric)(tmp));
1083
+ }
1084
+ else if (tmp instanceof ParamDefinition_js_1.NumericValue) {
939
1085
  accum.push(tmp);
940
1086
  }
941
1087
  return accum;
@@ -948,14 +1094,14 @@ class SymbolDrawing {
948
1094
  if (currentObj !== null) {
949
1095
  geomObjects.push(currentObj);
950
1096
  }
951
- const x = (0, helpers_js_1.milsToMM)(Number(parts[i + 1]));
952
- const y = (0, helpers_js_1.milsToMM)(Number(parts[i + 2]));
1097
+ const x = (0, helpers_js_1.milsToMM)(parts[i + 1]);
1098
+ const y = (0, helpers_js_1.milsToMM)(parts[i + 2]);
953
1099
  currentObj = [[x, y]];
954
1100
  i += 2;
955
1101
  }
956
1102
  else if (command === 'L') {
957
- const x = (0, helpers_js_1.milsToMM)(Number(parts[i + 1]));
958
- const y = (0, helpers_js_1.milsToMM)(Number(parts[i + 2]));
1103
+ const x = (0, helpers_js_1.milsToMM)(parts[i + 1]);
1104
+ const y = (0, helpers_js_1.milsToMM)(parts[i + 2]);
959
1105
  currentObj.push([x, y]);
960
1106
  i += 2;
961
1107
  }
@@ -1001,8 +1147,8 @@ class SymbolDrawing {
1001
1147
  x = (0, helpers_js_1.milsToMM)(x);
1002
1148
  y = (0, helpers_js_1.milsToMM)(y);
1003
1149
  radius = (0, helpers_js_1.milsToMM)(radius);
1004
- startAngle = startAngle * Math.PI / 180;
1005
- endAngle = endAngle * Math.PI / 180;
1150
+ startAngle = startAngle.mul(Math.PI).div(180);
1151
+ endAngle = endAngle.mul(Math.PI).div(180);
1006
1152
  this.items.push(geometry_js_1.Geometry.arc([x, y], radius, startAngle, endAngle, true));
1007
1153
  return this;
1008
1154
  }
@@ -1012,7 +1158,7 @@ class SymbolDrawing {
1012
1158
  }
1013
1159
  getPaths() {
1014
1160
  let currentFill = "#fff";
1015
- let currentLineWidth = 1;
1161
+ let currentLineWidth = (0, ParamDefinition_js_1.numeric)(1);
1016
1162
  let currentLineColor = '#333';
1017
1163
  const pathItems = [];
1018
1164
  this.items.forEach(item => {
@@ -1079,7 +1225,7 @@ class SymbolDrawing {
1079
1225
  }
1080
1226
  getPinPosition(pinId) {
1081
1227
  const pin = this.pins.find(item => {
1082
- return item[0] === pinId;
1228
+ return item[0].toNumber() === pinId;
1083
1229
  });
1084
1230
  if (pin) {
1085
1231
  const [, feature, angle] = pin;
@@ -1097,32 +1243,28 @@ class SymbolDrawing {
1097
1243
  }
1098
1244
  exports.SymbolDrawing = SymbolDrawing;
1099
1245
  class SymbolDrawingCommands extends SymbolDrawing {
1100
- constructor(commands) {
1246
+ constructor(callback) {
1101
1247
  super();
1102
1248
  this.id = "";
1103
- this.commands = commands;
1249
+ this.commands = [];
1250
+ this.paramIds = [];
1251
+ this.callback = callback;
1104
1252
  this.id = Math.random().toString().slice(2);
1105
1253
  }
1254
+ runCommands() {
1255
+ this.commands = this.callback(this.variables);
1256
+ }
1106
1257
  getCommands() {
1258
+ this.runCommands();
1107
1259
  return this.commands;
1108
1260
  }
1109
1261
  clone() {
1110
- const tmpCommands = this.commands.map(item => {
1111
- if (item[0] === PlaceHolderCommands.label) {
1112
- const commandName = item[0];
1113
- const positionParams = item[1];
1114
- const keywordParams = item[2];
1115
- const newMap = new Map();
1116
- for (const [key, value] of keywordParams) {
1117
- newMap.set(key, value);
1118
- }
1119
- return [commandName, positionParams, newMap];
1120
- }
1121
- else {
1122
- return [...item];
1123
- }
1124
- });
1125
- return new SymbolDrawingCommands(tmpCommands);
1262
+ const cloned = new SymbolDrawingCommands(this.callback);
1263
+ cloned.variables = this.variables;
1264
+ return cloned;
1265
+ }
1266
+ eq(other) {
1267
+ return this.callback === other.callback;
1126
1268
  }
1127
1269
  }
1128
1270
  exports.SymbolDrawingCommands = SymbolDrawingCommands;