circuitscript 0.1.16 → 0.1.18

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 (45) hide show
  1. package/dist/cjs/BaseVisitor.js +2 -1
  2. package/dist/cjs/draw_symbols.js +18 -17
  3. package/dist/cjs/execute.js +45 -26
  4. package/dist/cjs/export.js +3 -3
  5. package/dist/cjs/globals.js +1 -0
  6. package/dist/cjs/graph.js +101 -27
  7. package/dist/cjs/helpers.js +55 -22
  8. package/dist/cjs/layout.js +6 -1
  9. package/dist/cjs/objects/ClassComponent.js +27 -20
  10. package/dist/cjs/objects/ExecutionScope.js +9 -4
  11. package/dist/cjs/objects/Net.js +2 -1
  12. package/dist/cjs/objects/PinDefinition.js +55 -3
  13. package/dist/cjs/objects/types.js +17 -1
  14. package/dist/cjs/visitor.js +78 -20
  15. package/dist/esm/BaseVisitor.js +2 -1
  16. package/dist/esm/draw_symbols.js +18 -17
  17. package/dist/esm/execute.js +46 -27
  18. package/dist/esm/export.js +1 -1
  19. package/dist/esm/globals.js +1 -0
  20. package/dist/esm/graph.js +79 -28
  21. package/dist/esm/helpers.js +46 -21
  22. package/dist/esm/layout.js +6 -1
  23. package/dist/esm/objects/ClassComponent.js +28 -21
  24. package/dist/esm/objects/ExecutionScope.js +9 -4
  25. package/dist/esm/objects/Net.js +2 -1
  26. package/dist/esm/objects/PinDefinition.js +53 -2
  27. package/dist/esm/objects/types.js +16 -0
  28. package/dist/esm/visitor.js +80 -22
  29. package/dist/libs/std.cst +3 -2
  30. package/dist/types/BaseVisitor.d.ts +2 -1
  31. package/dist/types/draw_symbols.d.ts +13 -7
  32. package/dist/types/execute.d.ts +7 -7
  33. package/dist/types/export.d.ts +2 -2
  34. package/dist/types/globals.d.ts +1 -0
  35. package/dist/types/graph.d.ts +2 -1
  36. package/dist/types/helpers.d.ts +15 -2
  37. package/dist/types/layout.d.ts +2 -1
  38. package/dist/types/objects/ClassComponent.d.ts +8 -8
  39. package/dist/types/objects/ExecutionScope.d.ts +7 -6
  40. package/dist/types/objects/Net.d.ts +3 -2
  41. package/dist/types/objects/PinDefinition.d.ts +17 -2
  42. package/dist/types/objects/types.d.ts +17 -2
  43. package/dist/types/visitor.d.ts +1 -0
  44. package/libs/std.cst +3 -2
  45. package/package.json +2 -1
@@ -5,6 +5,7 @@ const draw_symbols_js_1 = require("../draw_symbols.js");
5
5
  const PinDefinition_js_1 = require("./PinDefinition.js");
6
6
  const PinTypes_js_1 = require("./PinTypes.js");
7
7
  const globals_js_1 = require("../globals.js");
8
+ const utils_js_1 = require("../utils.js");
8
9
  class ClassComponent {
9
10
  constructor(instanceName, numPins) {
10
11
  this.parameters = new Map();
@@ -33,47 +34,53 @@ class ClassComponent {
33
34
  setupPins() {
34
35
  for (let i = 1; i < this.numPins + 1; i++) {
35
36
  const pinIndex = i;
36
- this.pins.set(pinIndex, new PinDefinition_js_1.PinDefinition(pinIndex, PinDefinition_js_1.PinIdType.Int, pinIndex.toString(), PinTypes_js_1.PinTypes.Any));
37
+ this.pins.set(new PinDefinition_js_1.PinId(pinIndex), new PinDefinition_js_1.PinDefinition(pinIndex, PinDefinition_js_1.PinIdType.Int, pinIndex.toString(), PinTypes_js_1.PinTypes.Any));
37
38
  }
38
39
  this.refreshPinsCache();
39
40
  }
40
41
  getDefaultPin() {
41
- return 1;
42
+ const pins = Array.from(this.pins.keys());
43
+ pins.sort();
44
+ return pins[0];
42
45
  }
43
46
  hasPin(pinId) {
44
- if (typeof pinId === 'number') {
45
- return this.pins.has(pinId);
46
- }
47
- else {
48
- for (const [, pinDef] of this.pins) {
49
- if (pinDef.name === pinId ||
50
- pinDef.altNames.indexOf(pinId) !== -1) {
51
- return true;
52
- }
47
+ for (const [pin, pinDef] of this.pins) {
48
+ if (pin.equals(pinId)) {
49
+ return true;
50
+ }
51
+ if (pinId.getType() === PinDefinition_js_1.PinIdType.Str && (pinDef.name === pinId.getValue() ||
52
+ pinDef.altNames.indexOf(pinId.getValue()) !== -1)) {
53
+ return true;
53
54
  }
54
55
  }
55
56
  return false;
56
57
  }
57
58
  getPin(pinId) {
58
- if (typeof pinId === 'number') {
59
- return pinId;
59
+ for (const [pin,] of this.pins) {
60
+ if (pin.equals(pinId)) {
61
+ return pin;
62
+ }
60
63
  }
61
- else {
64
+ if (pinId.getType() === PinDefinition_js_1.PinIdType.Str) {
65
+ const pinIdStringValue = pinId.getValue();
62
66
  for (const [pin, pinDef] of this.pins) {
63
- if (pinDef.name === pinId ||
64
- pinDef.altNames.indexOf(pinId) !== -1) {
67
+ if (pinDef.name === pinIdStringValue ||
68
+ pinDef.altNames.indexOf(pinIdStringValue) !== -1) {
65
69
  return pin;
66
70
  }
67
71
  }
68
- return -1;
69
72
  }
73
+ throw new utils_js_1.RuntimeExecutionError(`Could not find pin '${pinId}' on component '${this.instanceName}'`);
70
74
  }
71
75
  getNextPinAfter(pinIndex) {
72
- if (pinIndex + 1 <= this.numPins) {
73
- return pinIndex + 1;
76
+ const pins = Array.from(this.pins.keys());
77
+ pins.sort();
78
+ const index = pins.findIndex(tmp => tmp.equals(pinIndex));
79
+ if (index + 1 < pins.length) {
80
+ return pins[index + 1];
74
81
  }
75
82
  else {
76
- return 1;
83
+ return this.getDefaultPin();
77
84
  }
78
85
  }
79
86
  setParam(key, value) {
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActiveObject = exports.FrameAction = exports.SequenceAction = exports.ExecutionScope = void 0;
4
4
  const CircuitScriptParser_js_1 = require("../antlr/CircuitScriptParser.js");
5
+ const PinDefinition_js_1 = require("./PinDefinition.js");
6
+ const utils_js_1 = require("../utils.js");
5
7
  class ExecutionScope {
6
8
  constructor(scopeId) {
7
9
  this.nets = [];
@@ -33,8 +35,11 @@ class ExecutionScope {
33
35
  return scope;
34
36
  }
35
37
  findNet(component, pin) {
38
+ if (!(pin instanceof PinDefinition_js_1.PinId)) {
39
+ throw new utils_js_1.RuntimeExecutionError('Invalid value for PinId: ' + pin);
40
+ }
36
41
  return this.nets.find(([tmpComponent, tmpPin]) => {
37
- return tmpComponent.isEqual(component) && tmpPin === pin;
42
+ return tmpComponent.isEqual(component) && tmpPin.equals(pin);
38
43
  });
39
44
  }
40
45
  getNetWithName(name) {
@@ -82,8 +87,8 @@ class ExecutionScope {
82
87
  const sortedNet = [...this.nets].sort((a, b) => {
83
88
  const netA = a[2];
84
89
  const netB = b[2];
85
- const netAId = netA.namespace + netA.name;
86
- const netBId = netB.namespace + b[2].name;
90
+ const netAId = netA.toString();
91
+ const netBId = netB.toString();
87
92
  if (netAId > netBId) {
88
93
  return 1;
89
94
  }
@@ -95,7 +100,7 @@ class ExecutionScope {
95
100
  }
96
101
  });
97
102
  return sortedNet.map(([component, pin, net]) => {
98
- return [net.toString(), component.instanceName, pin];
103
+ return [net.toString(), component.instanceName, pin.value];
99
104
  });
100
105
  }
101
106
  printNets() {
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Net = void 0;
4
+ const types_js_1 = require("./types.js");
4
5
  class Net {
5
- constructor(namespace, name, priority = 0, type = null) {
6
+ constructor(namespace, name, priority = 0, type = types_js_1.NetTypes.Any) {
6
7
  this.params = new Map();
7
8
  if (namespace.indexOf(' ') !== -1) {
8
9
  throw "Invalid net namespace provided";
@@ -1,13 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PortSide = exports.PinIdType = exports.PinDefinition = void 0;
3
+ exports.getPinDefinition = exports.isPinId = exports.PortSide = exports.PinIdType = exports.PinDefinition = exports.PinId = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ const ParamDefinition_js_1 = require("./ParamDefinition.js");
4
6
  const PinTypes_js_1 = require("./PinTypes.js");
7
+ class PinId {
8
+ constructor(value) {
9
+ if (typeof value !== 'string' && typeof value !== 'number') {
10
+ throw new utils_js_1.RuntimeExecutionError("Invalid value for PinId: " + value);
11
+ }
12
+ this.value = value;
13
+ this.type = typeof value === 'number' ? PinIdType.Int : PinIdType.Str;
14
+ }
15
+ getValue() {
16
+ return this.value;
17
+ }
18
+ getType() {
19
+ return this.type;
20
+ }
21
+ isNumeric() {
22
+ return this.type === PinIdType.Int;
23
+ }
24
+ isString() {
25
+ return this.type === PinIdType.Str;
26
+ }
27
+ toString() {
28
+ return this.value.toString();
29
+ }
30
+ equals(other) {
31
+ if (other instanceof PinId) {
32
+ return this.value === other.value;
33
+ }
34
+ return this.value === other;
35
+ }
36
+ static from(value) {
37
+ if (value instanceof ParamDefinition_js_1.NumericValue) {
38
+ return new PinId(value.toNumber());
39
+ }
40
+ return new PinId(value);
41
+ }
42
+ static isPinIdType(value) {
43
+ return (typeof value === 'number' || typeof value === 'string');
44
+ }
45
+ }
46
+ exports.PinId = PinId;
5
47
  class PinDefinition {
6
48
  constructor(id, idType, name, pinType = PinTypes_js_1.PinTypes.Any, altNames = []) {
7
49
  this.side = PortSide.EAST;
8
50
  this.position = -1;
9
- this.id = id;
10
- this.idType = idType;
51
+ this.id = id instanceof PinId ? id : new PinId(id);
52
+ this.idType = this.id.getType();
11
53
  this.pinType = pinType;
12
54
  this.name = name;
13
55
  this.altNames = altNames;
@@ -26,3 +68,13 @@ var PortSide;
26
68
  PortSide["SOUTH"] = "SOUTH";
27
69
  PortSide["NORTH"] = "NORTH";
28
70
  })(PortSide || (exports.PortSide = PortSide = {}));
71
+ function isPinId(item) {
72
+ return item instanceof PinId || (typeof item === 'number' || typeof item === 'string');
73
+ }
74
+ exports.isPinId = isPinId;
75
+ function getPinDefinition(map, id) {
76
+ const keys = Array.from(map.keys());
77
+ const tmpKey = keys.find(item => item.equals(id));
78
+ return map.get(tmpKey);
79
+ }
80
+ exports.getPinDefinition = getPinDefinition;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
3
+ exports.NetTypes = exports.TypeProps = exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
4
4
  const globals_js_1 = require("../globals.js");
5
5
  const utils_js_1 = require("../utils.js");
6
6
  class CFunctionEntry {
@@ -107,3 +107,19 @@ var Direction;
107
107
  Direction["Down"] = "down";
108
108
  Direction["Up"] = "up";
109
109
  })(Direction || (exports.Direction = Direction = {}));
110
+ var TypeProps;
111
+ (function (TypeProps) {
112
+ TypeProps["Net"] = "net";
113
+ TypeProps["Port"] = "port";
114
+ TypeProps["Graphic"] = "graphic";
115
+ TypeProps["Module"] = "module";
116
+ TypeProps["Resistor"] = "res";
117
+ TypeProps["Capacitor"] = "cap";
118
+ TypeProps["Inductor"] = "ind";
119
+ TypeProps["Diode"] = "diode";
120
+ })(TypeProps || (exports.TypeProps = TypeProps = {}));
121
+ var NetTypes;
122
+ (function (NetTypes) {
123
+ NetTypes["Any"] = "any";
124
+ NetTypes["Source"] = "source";
125
+ })(NetTypes || (exports.NetTypes = NetTypes = {}));
@@ -22,19 +22,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
22
22
  this.setResult(ctx, [id, value]);
23
23
  };
24
24
  this.visitPin_select_expr = (ctx) => {
25
- let value = null;
25
+ let pinId = null;
26
26
  const ctxData = ctx.data_expr();
27
27
  const result = this.visitResult(ctxData);
28
+ let pinValue;
28
29
  if (result instanceof ParamDefinition_js_1.NumericValue) {
29
- value = result.toNumber();
30
+ pinValue = result.toNumber();
30
31
  }
31
32
  else if (typeof result === 'string') {
32
- value = result;
33
+ pinValue = result;
33
34
  }
34
35
  else {
35
- throw new utils_js_2.RuntimeExecutionError("Invalid value for pin", ctx);
36
+ throw new utils_js_2.RuntimeExecutionError("Invalid select pin: " + result, ctx);
36
37
  }
37
- this.setResult(ctx, value);
38
+ if (pinValue !== undefined) {
39
+ pinId = new PinDefinition_js_1.PinId(pinValue);
40
+ }
41
+ this.setResult(ctx, pinId);
38
42
  };
39
43
  this.visitAdd_component_expr = (ctx) => {
40
44
  const [component, pinValue] = this.visitResult(ctx.data_expr_with_assignment());
@@ -221,11 +225,18 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
221
225
  }
222
226
  }
223
227
  else {
224
- if (!(value instanceof ParamDefinition_js_1.NumericValue)) {
228
+ if (!(value instanceof ParamDefinition_js_1.NumericValue) && !(typeof value === 'string')) {
225
229
  throw new utils_js_2.RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
226
230
  }
227
231
  else {
228
- checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
232
+ let useValue;
233
+ if (value instanceof ParamDefinition_js_1.NumericValue) {
234
+ useValue = value.toNumber();
235
+ }
236
+ else if (typeof value === 'string') {
237
+ useValue = value;
238
+ }
239
+ value && checkPinExistsAndNotDuplicated(useValue, ctx);
229
240
  }
230
241
  }
231
242
  }
@@ -265,7 +276,6 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
265
276
  scope.exitContext();
266
277
  scope.popOnPropertyHandler();
267
278
  const properties = this.getPropertyExprList(ctx.property_expr());
268
- const pins = this.parseCreateComponentPins(properties.get('pins'));
269
279
  let instanceName = this.getExecutor().getUniqueInstanceName();
270
280
  const propParams = properties.get('params');
271
281
  const params = this.parseCreateComponentParams(propParams);
@@ -278,11 +288,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
278
288
  }
279
289
  instanceName += `${globals_js_1.Delimiter1}${appendValue}`;
280
290
  }
281
- const arrange = properties.has('arrange') ?
291
+ const arrangeProp = properties.has('arrange') ?
282
292
  properties.get('arrange') : null;
283
- const display = properties.has('display') ?
293
+ const displayProp = properties.has('display') ?
284
294
  properties.get('display') : null;
285
- const type = properties.has('type') ?
295
+ const typeProp = properties.has('type') ?
286
296
  properties.get('type') : null;
287
297
  const copy = properties.has('copy') ?
288
298
  properties.get('copy') : false;
@@ -294,8 +304,29 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
294
304
  properties.get(globals_js_1.ParamKeys.angle) : null;
295
305
  const followWireOrientation = properties.has('followWireOrientation') ?
296
306
  properties.get('followWireOrientation') : true;
307
+ let pins = [];
308
+ if (displayProp !== null && arrangeProp === null
309
+ && typeProp !== types_js_1.TypeProps.Graphic) {
310
+ const drawCommands = displayProp.getCommands();
311
+ drawCommands.forEach(command => {
312
+ const [commandValue,] = command;
313
+ if (commandValue === draw_symbols_js_1.PlaceHolderCommands.vpin
314
+ || commandValue === draw_symbols_js_1.PlaceHolderCommands.hpin
315
+ || commandValue === draw_symbols_js_1.PlaceHolderCommands.pin) {
316
+ const id = PinDefinition_js_1.PinId.from(command[1][0]);
317
+ const pinType = id.getType();
318
+ const pinName = id.toString();
319
+ pins.push(new PinDefinition_js_1.PinDefinition(id, pinType, pinName, PinTypes_js_1.PinTypes.Any));
320
+ }
321
+ });
322
+ }
323
+ else {
324
+ pins = this.parseCreateComponentPins(properties.get('pins'));
325
+ }
297
326
  const props = {
298
- arrange, display, type, width, height, copy,
327
+ arrange: arrangeProp,
328
+ display: displayProp,
329
+ type: typeProp, width, height, copy,
299
330
  angle, followWireOrientation
300
331
  };
301
332
  try {
@@ -807,14 +838,21 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
807
838
  this.visitPin_select_expr2 = (ctx) => {
808
839
  const ctxStringValue = ctx.STRING_VALUE();
809
840
  const ctxIntegerValue = ctx.INTEGER_VALUE();
810
- let result = null;
841
+ let pinIdValue;
842
+ let pinId = null;
811
843
  if (ctxStringValue) {
812
- result = this.prepareStringValue(ctxStringValue.getText());
844
+ pinIdValue = this.prepareStringValue(ctxStringValue.getText());
813
845
  }
814
846
  else if (ctxIntegerValue) {
815
- result = Number(ctxIntegerValue.getText());
847
+ pinIdValue = Number(ctxIntegerValue.getText());
816
848
  }
817
- this.setResult(ctx, result);
849
+ if (pinIdValue !== undefined) {
850
+ pinId = new PinDefinition_js_1.PinId(pinIdValue);
851
+ }
852
+ else {
853
+ throw new utils_js_2.RuntimeExecutionError("Invalid select pin", ctx);
854
+ }
855
+ this.setResult(ctx, pinId);
818
856
  };
819
857
  this.visitAt_block_pin_expr = (ctx) => {
820
858
  const executor = this.getExecutor();
@@ -1206,7 +1244,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1206
1244
  return item;
1207
1245
  }
1208
1246
  else {
1209
- return (0, ParamDefinition_js_1.numeric)(nameToPinId.get(item));
1247
+ return new PinDefinition_js_1.PinId(nameToPinId.get(item));
1210
1248
  }
1211
1249
  });
1212
1250
  if (items.length > 0) {
@@ -1297,7 +1335,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1297
1335
  getGraph() {
1298
1336
  const executor = this.getExecutor();
1299
1337
  const fullSequence = executor.scope.sequence;
1300
- const tmpNet = executor.scope.getNet(executor.scope.componentRoot, 1);
1338
+ const tmpNet = executor.scope.getNet(executor.scope.componentRoot, new PinDefinition_js_1.PinId(1));
1301
1339
  const sequence = (tmpNet === null)
1302
1340
  ? fullSequence.slice(1) : fullSequence;
1303
1341
  const nets = executor.scope.getNets();
@@ -1342,8 +1380,28 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1342
1380
  this.log('Failed to annotate:', instance.instanceName);
1343
1381
  }
1344
1382
  });
1345
- this.log('===== annotate done =====');
1346
- this.log('');
1383
+ this.log('===== annotate components done =====');
1384
+ this.log('===== rename nets =====');
1385
+ this.renameNetsWithRefdes();
1386
+ this.log('===== rename nets done =====');
1387
+ }
1388
+ renameNetsWithRefdes() {
1389
+ const nets = this.getScope().getNets();
1390
+ const seenNets = [];
1391
+ const uniqueNets = new Set(nets.map(([, , net]) => net));
1392
+ const fullNetNames = Array.from(uniqueNets).map(item => item.toString());
1393
+ nets.forEach(([component, pin, net]) => {
1394
+ if (net.priority === 0 && seenNets.indexOf(net) === -1
1395
+ && component.typeProp !== types_js_1.TypeProps.Module
1396
+ && component.typeProp !== types_js_1.TypeProps.Net) {
1397
+ net.name = net.baseName =
1398
+ `NET-(${component.assignedRefDes}-${pin.toString()})`;
1399
+ if (fullNetNames.indexOf(net.toString()) !== -1) {
1400
+ throw new utils_js_2.RuntimeExecutionError('Net renaming failed due to clash: ' + net);
1401
+ }
1402
+ seenNets.push(net);
1403
+ }
1404
+ });
1347
1405
  }
1348
1406
  applySheetFrameComponent() {
1349
1407
  const baseScope = this.getScope();
@@ -11,6 +11,7 @@ import { isReference, unwrapValue as unwrapValue } from "./utils.js";
11
11
  import { linkBuiltInMethods } from './builtinMethods.js';
12
12
  import { resolveToNumericValue, RuntimeExecutionError, throwWithContext } from './utils.js';
13
13
  import { SequenceAction } from './objects/ExecutionScope.js';
14
+ import { PinId } from './objects/PinDefinition.js';
14
15
  export class BaseVisitor extends CircuitScriptVisitor {
15
16
  indentLevel = 0;
16
17
  startingContext;
@@ -171,7 +172,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
171
172
  this.log2(`assigned component param ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
172
173
  sequenceParts.push(...['instance', [leftSideReference.parentValue, trailers], rhsValue]);
173
174
  if (leftSideReference.parentValue.typeProp === ComponentTypes.net) {
174
- const net = this.getScope().getNet(leftSideReference.parentValue, 1);
175
+ const net = this.getScope().getNet(leftSideReference.parentValue, new PinId(1));
175
176
  if (net) {
176
177
  const trailerValue = trailers.join(".");
177
178
  net.params.set(trailerValue, rhsValue);
@@ -5,6 +5,7 @@ import { PinTypes } from "./objects/PinTypes.js";
5
5
  import { roundValue, RuntimeExecutionError, throwWithContext } from "./utils.js";
6
6
  import { DeclaredReference, UndeclaredReference } from "./objects/types.js";
7
7
  import { numeric, NumericValue } from "./objects/ParamDefinition.js";
8
+ import { PinId } from "./objects/PinDefinition.js";
8
9
  export class SymbolGraphic {
9
10
  drawPortsName = true;
10
11
  displayBounds = false;
@@ -560,6 +561,12 @@ export class SymbolPlaceholder extends SymbolGraphic {
560
561
  milsToMM(endY)
561
562
  ];
562
563
  }
564
+ if (positionParams[0] instanceof NumericValue) {
565
+ positionParams[0] = new PinId(positionParams[0].toNumber());
566
+ }
567
+ else if (typeof positionParams[0] === 'number' || typeof positionParams[0] === 'string') {
568
+ positionParams[0] = new PinId(positionParams[0]);
569
+ }
563
570
  drawing.addPinMM(...positionParams, lineColor);
564
571
  const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
565
572
  const [pinId, , angle] = lastAddedPin;
@@ -604,7 +611,8 @@ export class SymbolPlaceholder extends SymbolGraphic {
604
611
  vanchor: VerticalAlign.Middle,
605
612
  textColor: pinNameColor,
606
613
  });
607
- displayPinId && drawing.addLabel(endX.add(pinIdOffsetX), endY.add(pinIdOffsetY), pinId.toDisplayString(), {
614
+ const pinDisplayText = pinId.toString();
615
+ displayPinId && drawing.addLabel(endX.add(pinIdOffsetX), endY.add(pinIdOffsetY), pinDisplayText, {
608
616
  fontSize: numeric(defaultPinIdTextSize),
609
617
  anchor: pinIdAlignment,
610
618
  vanchor: pinIdVAlignment,
@@ -704,7 +712,7 @@ export class SymbolCustom extends SymbolGraphic {
704
712
  leftPins.forEach(pin => {
705
713
  const position = pin.position;
706
714
  const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
707
- drawing.addPinMM(numeric(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
715
+ drawing.addPinMM(pin.pinId, leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
708
716
  drawing.addLabel(leftPinStart.add(milsToMM(20)), pinY, pin.text, {
709
717
  fontSize: numeric(CustomSymbolPinTextSize),
710
718
  anchor: HorizontalAlign.Left,
@@ -721,7 +729,7 @@ export class SymbolCustom extends SymbolGraphic {
721
729
  rightPins.forEach(pin => {
722
730
  const position = pin.position;
723
731
  const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
724
- drawing.addPinMM(numeric(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
732
+ drawing.addPinMM(pin.pinId, rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
725
733
  drawing.addLabel(rightPinStart.sub(milsToMM(20)), pinY, pin.text, {
726
734
  fontSize: numeric(CustomSymbolPinTextSize),
727
735
  anchor: HorizontalAlign.Right,
@@ -738,7 +746,7 @@ export class SymbolCustom extends SymbolGraphic {
738
746
  topPins.forEach(pin => {
739
747
  const position = pin.position;
740
748
  const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
741
- drawing.addPinMM(numeric(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
749
+ drawing.addPinMM(pin.pinId, pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
742
750
  drawing.addLabel(pinX, topPinStart.add(milsToMM(20)), pin.text, {
743
751
  fontSize: numeric(CustomSymbolPinTextSize),
744
752
  anchor: HorizontalAlign.Right,
@@ -757,7 +765,7 @@ export class SymbolCustom extends SymbolGraphic {
757
765
  bottomPins.forEach(pin => {
758
766
  const position = pin.position;
759
767
  const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
760
- drawing.addPinMM(numeric(pin.pinId), pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
768
+ drawing.addPinMM(pin.pinId, pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
761
769
  drawing.addLabel(pinX, bottomPinStart.sub(milsToMM(20)), pin.text, {
762
770
  fontSize: numeric(CustomSymbolPinTextSize),
763
771
  anchor: HorizontalAlign.Left,
@@ -839,7 +847,7 @@ export class SymbolCustomModule extends SymbolCustom {
839
847
  leftPins.forEach(pin => {
840
848
  const position = pin.position;
841
849
  const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
842
- drawing.addPinMM(numeric(pin.pinId), leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
850
+ drawing.addPinMM(pin.pinId, leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
843
851
  drawing.addModulePort(leftPinStart, pinY, this.portWidth, this.portHeight, pin.pinType);
844
852
  drawing.addLabel(leftPinStart.add(this.portWidth).add(milsToMM(20)), pinY, pin.text, {
845
853
  fontSize: numeric(40),
@@ -851,7 +859,7 @@ export class SymbolCustomModule extends SymbolCustom {
851
859
  rightPins.forEach(pin => {
852
860
  const position = pin.position;
853
861
  const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
854
- drawing.addPinMM(numeric(pin.pinId), rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
862
+ drawing.addPinMM(pin.pinId, rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
855
863
  drawing.addModulePort(rightPinStart, pinY, this.portWidth, this.portHeight, pin.pinType, -1);
856
864
  drawing.addLabel(rightPinStart.sub(this.portWidth).sub(milsToMM(20)), pinY, pin.text, {
857
865
  fontSize: numeric(40),
@@ -863,7 +871,7 @@ export class SymbolCustomModule extends SymbolCustom {
863
871
  topPins.forEach(pin => {
864
872
  const position = pin.position;
865
873
  const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
866
- drawing.addPinMM(numeric(pin.pinId), pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
874
+ drawing.addPinMM(pin.pinId, pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
867
875
  drawing.addModulePort(pinX, topPinStart, this.portWidth, this.portHeight, pin.pinType, 1, 90);
868
876
  drawing.addLabel(pinX, topPinStart.add(this.portWidth).add(milsToMM(20)), pin.text, {
869
877
  fontSize: numeric(40),
@@ -876,7 +884,7 @@ export class SymbolCustomModule extends SymbolCustom {
876
884
  bottomPins.forEach(pin => {
877
885
  const position = pin.position;
878
886
  const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
879
- drawing.addPinMM(numeric(pin.pinId), pinX, bottomPinStart, pinX, bottomPinStart.sub(this.pinLength), defaultLineColor);
887
+ drawing.addPinMM(pin.pinId, pinX, bottomPinStart, pinX, bottomPinStart.sub(this.pinLength), defaultLineColor);
880
888
  drawing.addModulePort(pinX, bottomPinStart, this.portWidth, this.portHeight, pin.pinType, 1, -90);
881
889
  drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub(milsToMM(20)), pin.text, {
882
890
  fontSize: numeric(40),
@@ -912,13 +920,6 @@ export class SymbolDrawing {
912
920
  this.items.push(Geometry.segment([startX, startY], [endX, endY]));
913
921
  return this;
914
922
  }
915
- addPin(pinId, startX, startY, endX, endY, lineColor) {
916
- startX = milsToMM(startX);
917
- startY = milsToMM(startY);
918
- endX = milsToMM(endX);
919
- endY = milsToMM(endY);
920
- return this.addPinMM(pinId, startX, startY, endX, endY, lineColor);
921
- }
922
923
  addPinMM(pinId, startXMM, startYMM, endXMM, endYMM, lineColor) {
923
924
  let angle = 0;
924
925
  const tmpStartXMM = startXMM.toNumber();
@@ -1221,7 +1222,7 @@ export class SymbolDrawing {
1221
1222
  }
1222
1223
  getPinPosition(pinId) {
1223
1224
  const pin = this.pins.find(item => {
1224
- return item[0].toNumber() === pinId;
1225
+ return item[0].equals(pinId);
1225
1226
  });
1226
1227
  if (pin) {
1227
1228
  const [, feature, angle] = pin;