circuitscript 0.1.0 → 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 (61) hide show
  1. package/dist/cjs/BaseVisitor.js +13 -8
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  3. package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
  4. package/dist/cjs/builtinMethods.js +27 -8
  5. package/dist/cjs/draw_symbols.js +314 -190
  6. package/dist/cjs/execute.js +113 -115
  7. package/dist/cjs/export.js +2 -4
  8. package/dist/cjs/geometry.js +52 -19
  9. package/dist/cjs/globals.js +12 -8
  10. package/dist/cjs/helpers.js +16 -3
  11. package/dist/cjs/layout.js +129 -125
  12. package/dist/cjs/logger.js +8 -1
  13. package/dist/cjs/objects/ClassComponent.js +22 -22
  14. package/dist/cjs/objects/ExecutionScope.js +10 -4
  15. package/dist/cjs/objects/Frame.js +2 -1
  16. package/dist/cjs/objects/ParamDefinition.js +120 -4
  17. package/dist/cjs/objects/PinDefinition.js +1 -4
  18. package/dist/cjs/render.js +40 -110
  19. package/dist/cjs/sizing.js +33 -7
  20. package/dist/cjs/utils.js +68 -2
  21. package/dist/cjs/visitor.js +214 -254
  22. package/dist/esm/BaseVisitor.mjs +15 -10
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
  25. package/dist/esm/builtinMethods.mjs +24 -8
  26. package/dist/esm/draw_symbols.mjs +316 -193
  27. package/dist/esm/execute.mjs +115 -117
  28. package/dist/esm/export.mjs +2 -4
  29. package/dist/esm/geometry.mjs +52 -19
  30. package/dist/esm/globals.mjs +12 -8
  31. package/dist/esm/helpers.mjs +17 -4
  32. package/dist/esm/layout.mjs +131 -127
  33. package/dist/esm/logger.mjs +8 -1
  34. package/dist/esm/objects/ClassComponent.mjs +21 -26
  35. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  36. package/dist/esm/objects/Frame.mjs +2 -1
  37. package/dist/esm/objects/ParamDefinition.mjs +119 -3
  38. package/dist/esm/objects/PinDefinition.mjs +0 -2
  39. package/dist/esm/render.mjs +42 -112
  40. package/dist/esm/sizing.mjs +34 -8
  41. package/dist/esm/utils.mjs +64 -1
  42. package/dist/esm/visitor.mjs +216 -256
  43. package/dist/types/BaseVisitor.d.ts +1 -1
  44. package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
  45. package/dist/types/draw_symbols.d.ts +71 -45
  46. package/dist/types/execute.d.ts +15 -10
  47. package/dist/types/geometry.d.ts +31 -19
  48. package/dist/types/globals.d.ts +14 -10
  49. package/dist/types/helpers.d.ts +2 -1
  50. package/dist/types/layout.d.ts +21 -21
  51. package/dist/types/logger.d.ts +1 -1
  52. package/dist/types/objects/ClassComponent.d.ts +19 -16
  53. package/dist/types/objects/ExecutionScope.d.ts +2 -1
  54. package/dist/types/objects/Frame.d.ts +2 -2
  55. package/dist/types/objects/ParamDefinition.d.ts +31 -2
  56. package/dist/types/objects/PinDefinition.d.ts +0 -2
  57. package/dist/types/render.d.ts +2 -1
  58. package/dist/types/utils.d.ts +6 -1
  59. package/dist/types/visitor.d.ts +4 -5
  60. package/libs/lib.cst +15 -3
  61. package/package.json +7 -3
@@ -5,11 +5,14 @@ const globals_js_1 = require("./globals.js");
5
5
  const ClassComponent_js_1 = require("./objects/ClassComponent.js");
6
6
  const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
7
7
  const Net_js_1 = require("./objects/Net.js");
8
+ const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
8
9
  const PinDefinition_js_1 = require("./objects/PinDefinition.js");
9
10
  const types_js_1 = require("./objects/types.js");
10
11
  const Wire_js_1 = require("./objects/Wire.js");
11
12
  const Frame_js_1 = require("./objects/Frame.js");
12
13
  const layout_js_1 = require("./layout.js");
14
+ const helpers_js_1 = require("./helpers.js");
15
+ const draw_symbols_js_1 = require("./draw_symbols.js");
13
16
  class ExecutionContext {
14
17
  constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, parent) {
15
18
  this.tmpPointId = 0;
@@ -52,27 +55,14 @@ class ExecutionContext {
52
55
  }
53
56
  setupRoot() {
54
57
  const componentRoot = ClassComponent_js_1.ClassComponent.simple(globals_js_1.GlobalNames.__root, 1, '__root');
55
- componentRoot.typeProp = globals_js_1.ComponentTypes.point;
56
- componentRoot.displayProp = 'point';
58
+ componentRoot.typeProp = globals_js_1.ComponentTypes.net;
59
+ componentRoot.displayProp = this.getPointSymbol();
57
60
  this.scope.instances.set(globals_js_1.GlobalNames.__root, componentRoot);
58
- this.scope.currentComponent = componentRoot;
59
- this.scope.currentPin = componentRoot.getDefaultPin();
61
+ this.scope.setCurrent(componentRoot);
60
62
  this.scope.componentRoot = componentRoot;
61
63
  }
62
- getUniqueInstanceName(className) {
63
- let extraPrefix = '';
64
- switch (className) {
65
- case globals_js_1.GlobalNames.DefaultResistor:
66
- extraPrefix = 'R_';
67
- break;
68
- case globals_js_1.GlobalNames.DefaultCapacitor:
69
- extraPrefix = 'C_';
70
- break;
71
- case globals_js_1.GlobalNames.DefaultInductor:
72
- extraPrefix = 'L_';
73
- break;
74
- }
75
- const tmpName = extraPrefix + 'COMP_' + this.scope.unnamedCounter;
64
+ getUniqueInstanceName() {
65
+ const tmpName = 'COMP_' + this.scope.unnamedCounter;
76
66
  this.scope.unnamedCounter += 1;
77
67
  return tmpName;
78
68
  }
@@ -85,14 +75,8 @@ class ExecutionContext {
85
75
  return [this.scope.currentComponent, this.scope.currentPin];
86
76
  }
87
77
  linkComponentPinNet(component1, component1Pin, component2, component2Pin) {
88
- const net1_exists = this.scope.hasNet(component1, component1Pin);
89
- const net2_exists = this.scope.hasNet(component2, component2Pin);
90
- const net1 = net1_exists
91
- ? this.scope.getNet(component1, component1Pin)
92
- : null;
93
- const net2 = net2_exists
94
- ? this.scope.getNet(component2, component2Pin)
95
- : null;
78
+ const net1 = this.scope.getNet(component1, component1Pin);
79
+ const net2 = this.scope.getNet(component2, component2Pin);
96
80
  this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
97
81
  let returnNet;
98
82
  if (net1 === null && net2 === null) {
@@ -114,43 +98,43 @@ class ExecutionContext {
114
98
  returnNet = this.mergeNets(net1, net2);
115
99
  }
116
100
  else {
117
- return net1;
101
+ returnNet = net1;
118
102
  }
119
103
  }
104
+ this.log('final net after link: ', returnNet);
120
105
  return returnNet;
121
106
  }
122
107
  mergeNets(net1, net2) {
123
108
  if (net1 === net2) {
124
109
  return net1;
125
110
  }
126
- let tmpNet;
127
111
  if (net2.priority > net1.priority) {
128
- tmpNet = net1;
112
+ const tmpNet = net1;
129
113
  net1 = net2;
130
114
  net2 = tmpNet;
131
115
  }
132
- const scopeNets = this.scope.getNets();
133
- scopeNets.forEach(([component, pin, net]) => {
116
+ this.scope.getNets().forEach(([component, pin, net]) => {
134
117
  if (Net_js_1.Net.isSame(net, net2)) {
135
118
  this.scope.setNet(component, pin, net1);
136
119
  }
137
120
  });
138
121
  return net1;
139
122
  }
140
- createComponent(instanceName, pins, params, props) {
141
- const numPins = pins.length;
142
- const component = new ClassComponent_js_1.ClassComponent(instanceName, numPins, globals_js_1.GlobalNames.symbol);
123
+ createComponent(instanceName, pins, params, props, isModule = false) {
124
+ const className = isModule ? ClassComponent_js_1.ModuleComponent : ClassComponent_js_1.ClassComponent;
125
+ const component = new className(instanceName, pins.length);
143
126
  pins.forEach((pin) => {
144
127
  component.pins.set(pin.id, pin);
145
128
  });
146
129
  component.arrangeProps = props.arrange ?? null;
147
130
  component.displayProp = props.display ?? null;
148
131
  component.widthProp = props.width ?? null;
132
+ component.heightProp = props.height ?? null;
149
133
  component.typeProp = props.type ?? null;
150
134
  component.copyProp = props.copy ?? false;
151
135
  let useAngle = null;
152
136
  if (props.angle) {
153
- useAngle = props.angle % 360;
137
+ useAngle = props.angle.toNumber() % 360;
154
138
  if (useAngle < 0) {
155
139
  useAngle += 360;
156
140
  }
@@ -162,10 +146,12 @@ class ExecutionContext {
162
146
  component.parameters.set(param.paramName, param.paramValue);
163
147
  paramsMap.set(param.paramName, param.paramValue);
164
148
  });
165
- if (component.typeProp === globals_js_1.ComponentTypes.net
166
- || component.typeProp === globals_js_1.ComponentTypes.label) {
149
+ if (component.typeProp === globals_js_1.ComponentTypes.net) {
167
150
  const netName = paramsMap.get(globals_js_1.ParamKeys.net_name);
168
- const priority = paramsMap.get(globals_js_1.ParamKeys.priority);
151
+ let priority = 0;
152
+ if (paramsMap.has(globals_js_1.ParamKeys.priority)) {
153
+ priority = paramsMap.get(globals_js_1.ParamKeys.priority).toNumber();
154
+ }
169
155
  const result = this.resolveNet(netName, this.netNamespace);
170
156
  let tmpNet;
171
157
  if (result.found) {
@@ -179,8 +165,9 @@ class ExecutionContext {
179
165
  this.scope.setNet(component, 1, tmpNet);
180
166
  this.log('set net', netName, 'component', component);
181
167
  }
182
- const portSides = getPortSide(component.pins, component.arrangeProps);
183
- portSides.forEach(({ pinId, side, position }) => {
168
+ const { pins: pinSides, maxPositions } = getPortSide(component.pins, component.arrangeProps);
169
+ component.pinsMaxPositions = maxPositions;
170
+ pinSides.forEach(({ pinId, side, position }) => {
184
171
  if (component.pins.has(pinId)) {
185
172
  const tmpPin = component.pins.get(pinId);
186
173
  tmpPin.side = side;
@@ -211,10 +198,9 @@ class ExecutionContext {
211
198
  this.scope.currentPin + ' ' + netString);
212
199
  }
213
200
  addComponentExisting(component, pin) {
214
- const startPin = pin;
215
- const nextPin = component.getNextPinAfter(startPin);
201
+ const nextPin = component.getNextPinAfter(pin);
216
202
  this.applyComponentAngleFromWire(component, pin);
217
- this.toComponent(component, startPin, { addSequence: true });
203
+ this.toComponent(component, pin, { addSequence: true });
218
204
  this.log('move to next pin: ' + nextPin);
219
205
  this.atComponent(component, nextPin, {
220
206
  addSequence: true
@@ -250,13 +236,10 @@ class ExecutionContext {
250
236
  }
251
237
  const linkedNet = this.linkComponentPinNet(this.scope.currentComponent, this.scope.currentPin, component, pinId);
252
238
  this.applyComponentAngleFromWire(component, pinId);
253
- this.scope.currentComponent = component;
254
- this.scope.currentPin = pinId;
239
+ this.scope.setCurrent(component, pinId);
255
240
  this.scope.clearActive();
256
241
  if (addSequence) {
257
242
  if (this.scope.sequence.length > 0) {
258
- if (component.pinWires.has(pinId) && component.typeProp !== globals_js_1.ComponentTypes.point) {
259
- }
260
243
  const [entryType, , segments] = this.scope.sequence[this.scope.sequence.length - 1];
261
244
  if (entryType === ExecutionScope_js_1.SequenceAction.Wire && isWireSegmentsEndAuto(segments)) {
262
245
  segments[segments.length - 1].until = [
@@ -274,7 +257,6 @@ class ExecutionContext {
274
257
  atComponent(component, pinId, options) {
275
258
  this.log('at component');
276
259
  const { addSequence = false } = options ?? {};
277
- this.scope.currentComponent = component;
278
260
  let usePinId;
279
261
  if (pinId === null) {
280
262
  usePinId = component.getDefaultPin();
@@ -287,9 +269,7 @@ class ExecutionContext {
287
269
  throw 'Invalid pin number ' + pinId + ' in ' + component;
288
270
  }
289
271
  }
290
- if (usePinId) {
291
- this.scope.currentPin = usePinId;
292
- }
272
+ this.scope.setCurrent(component, usePinId);
293
273
  this.scope.clearActive();
294
274
  if (addSequence) {
295
275
  this.scope.sequence.push([ExecutionScope_js_1.SequenceAction.At,
@@ -316,12 +296,9 @@ class ExecutionContext {
316
296
  return componentCopy;
317
297
  }
318
298
  enterBlocks(blockType) {
319
- if (blockType === globals_js_1.BlockTypes.Point) {
320
- this.addPoint(`_point.${this.name}.${this.tmpPointId}`, false);
321
- this.tmpPointId += 1;
322
- }
323
- else if (blockType === globals_js_1.BlockTypes.Parallel) {
324
- this.addPoint(`_parallel.${this.name}.${this.tmpPointId}`, false);
299
+ if (blockType === globals_js_1.BlockTypes.Point || blockType === globals_js_1.BlockTypes.Parallel) {
300
+ const key = blockType === globals_js_1.BlockTypes.Point ? 'point' : 'parallel';
301
+ this.addPoint(`_${key}.${this.name}.${this.tmpPointId}`, false);
325
302
  this.tmpPointId += 1;
326
303
  }
327
304
  this.scope.blockStack.set(this.scope.indentLevel, {
@@ -342,8 +319,7 @@ class ExecutionContext {
342
319
  if (blockType === globals_js_1.BlockTypes.Join || blockType === globals_js_1.BlockTypes.Parallel) {
343
320
  const { final_point: finalPoint } = stackRef;
344
321
  const [component, pin, wireId] = finalPoint;
345
- this.scope.currentComponent = component;
346
- this.scope.currentPin = pin;
322
+ this.scope.setCurrent(component, pin);
347
323
  this.scope.currentWireId = wireId;
348
324
  if (wireId !== -1) {
349
325
  this.scope.sequence.push([
@@ -366,8 +342,7 @@ class ExecutionContext {
366
342
  ignore_last_net: false,
367
343
  });
368
344
  if (blockType === globals_js_1.BlockTypes.Join || blockType === globals_js_1.BlockTypes.Point) {
369
- this.scope.currentComponent = null;
370
- this.scope.currentPin = null;
345
+ this.scope.setCurrent(null);
371
346
  this.scope.currentWireId = -1;
372
347
  }
373
348
  else if (blockType === globals_js_1.BlockTypes.Parallel) {
@@ -584,7 +559,6 @@ class ExecutionContext {
584
559
  }
585
560
  const wireIdOffset = this.scope.wires.length;
586
561
  const frameIdOffset = this.scope.frames.length;
587
- let incrementGndLinkId = 0;
588
562
  childScope.sequence.forEach(sequenceAction => {
589
563
  const [action] = sequenceAction;
590
564
  if (action === ExecutionScope_js_1.SequenceAction.Wire) {
@@ -597,20 +571,6 @@ class ExecutionContext {
597
571
  this.scope.sequence.push([ExecutionScope_js_1.SequenceAction.WireJump, jumpWireId, 1]);
598
572
  }
599
573
  else if (action === ExecutionScope_js_1.SequenceAction.At || action === ExecutionScope_js_1.SequenceAction.To) {
600
- const tmpComponent = sequenceAction[1];
601
- if (tmpComponent.typeProp === globals_js_1.ComponentTypes.net
602
- && tmpComponent.parameters.get(globals_js_1.ParamKeys.net_name) === 'gnd') {
603
- tmpComponent._copyID = gndCopyIdOffset + incrementGndLinkId;
604
- incrementGndLinkId += 1;
605
- }
606
- else if (tmpComponent === tmpRoot) {
607
- if (currentWireId !== -1) {
608
- sequenceAction = [ExecutionScope_js_1.SequenceAction.WireJump, currentWireId];
609
- }
610
- else {
611
- sequenceAction = [action, currentComponent, currentPin];
612
- }
613
- }
614
574
  this.scope.sequence.push(sequenceAction);
615
575
  }
616
576
  else if (action === ExecutionScope_js_1.SequenceAction.Frame) {
@@ -624,13 +584,11 @@ class ExecutionContext {
624
584
  }
625
585
  });
626
586
  if (childScope.currentComponent === childScope.componentRoot) {
627
- this.scope.currentComponent = currentComponent;
628
- this.scope.currentPin = currentPin;
587
+ this.scope.setCurrent(currentComponent, currentPin);
629
588
  this.scope.currentWireId = currentWireId;
630
589
  }
631
590
  else {
632
- this.scope.currentComponent = childScope.currentComponent;
633
- this.scope.currentPin = childScope.currentPin;
591
+ this.scope.setCurrent(childScope.currentComponent, childScope.currentPin);
634
592
  this.scope.currentWireId = childScope.currentWireId + wireIdOffset;
635
593
  }
636
594
  this.printPoint('resume at');
@@ -660,7 +618,15 @@ class ExecutionContext {
660
618
  this.scope.wires.push(new Wire_js_1.Wire(tmp));
661
619
  const output = [];
662
620
  segments.forEach(item => {
663
- output.push(item.join(","));
621
+ const tmpArray = item.map(item2 => {
622
+ if (item2 instanceof helpers_js_1.UnitDimension) {
623
+ return item2.value;
624
+ }
625
+ else {
626
+ return item2;
627
+ }
628
+ });
629
+ output.push(tmpArray.join(","));
664
630
  });
665
631
  this.log('add wire: ', output.join("|"));
666
632
  this.scope.setActive(ExecutionScope_js_1.ActiveObject.Wire, wireId);
@@ -677,12 +643,26 @@ class ExecutionContext {
677
643
  }
678
644
  const useName = userDefined ? 'point.' + pointId : pointId;
679
645
  const componentPoint = ClassComponent_js_1.ClassComponent.simple(useName, 1, "point");
680
- componentPoint.displayProp = "point";
681
- componentPoint.typeProp = globals_js_1.ComponentTypes.point;
646
+ componentPoint.displayProp = this.getPointSymbol();
647
+ componentPoint.typeProp = globals_js_1.ComponentTypes.net;
682
648
  this.scope.instances.set(pointId, componentPoint);
683
649
  this.toComponent(componentPoint, 1, { addSequence: true });
684
650
  return this.getCurrentPoint();
685
651
  }
652
+ getPointSymbol() {
653
+ return new draw_symbols_js_1.SymbolDrawingCommands(() => {
654
+ return [
655
+ [draw_symbols_js_1.PlaceHolderCommands.pin,
656
+ [(0, ParamDefinition_js_1.numeric)(1), (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0),
657
+ (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
658
+ new Map([
659
+ ["display_pin_id", false]
660
+ ]),
661
+ null
662
+ ]
663
+ ];
664
+ });
665
+ }
686
666
  setProperty(nameWithProp, value) {
687
667
  this.log('set property', nameWithProp, 'value', value);
688
668
  let idName;
@@ -715,11 +695,6 @@ class ExecutionContext {
715
695
  }
716
696
  }
717
697
  }
718
- setCurrentComponentStyle(styles) {
719
- for (const key in styles) {
720
- this.scope.currentComponent.styles[key] = styles[key];
721
- }
722
- }
723
698
  applyComponentAngleFromWire(component, pin, opposite = false) {
724
699
  if (this.componentAngleFollowsWire
725
700
  && component.followWireOrientationProp
@@ -770,23 +745,23 @@ class ExecutionContext {
770
745
  return;
771
746
  }
772
747
  this.log('set component angle from wire, target angle:', targetAngle, ', component angle:', component.angleProp, 'pin angle:', connectedPinPos.angle);
773
- let useAngle = (targetAngle - connectedPinPos.angle) % 360;
748
+ let useAngle = (targetAngle - connectedPinPos.angle.toNumber()) % 360;
774
749
  if (useAngle < 0) {
775
750
  useAngle += 360;
776
751
  }
777
752
  if (useAngle === 90) {
778
- component.setParam('angle', 90);
753
+ component.setParam(globals_js_1.ParamKeys.angle, (0, ParamDefinition_js_1.numeric)(90));
779
754
  }
780
755
  else if (useAngle === 180) {
781
756
  if (component.angleProp === 0 || component.angleProp === 180) {
782
- component.setParam('flipX', 1);
757
+ component.setParam(globals_js_1.ParamKeys.flipX, 1);
783
758
  }
784
759
  else if (component.angleProp === 90 || component.angleProp === 270) {
785
- component.setParam('flipY', 1);
760
+ component.setParam(globals_js_1.ParamKeys.flipY, 1);
786
761
  }
787
762
  }
788
763
  else if (useAngle === 270) {
789
- component.setParam('angle', 270);
764
+ component.setParam(globals_js_1.ParamKeys.angle, (0, ParamDefinition_js_1.numeric)(270));
790
765
  }
791
766
  component.wireOrientationAngle = useAngle;
792
767
  component.didSetWireOrientationAngle = true;
@@ -822,6 +797,12 @@ function isWireSegmentsEndAuto(segments) {
822
797
  }
823
798
  function getPortSide(pins, arrangeProps) {
824
799
  const result = [];
800
+ const maxPositions = {
801
+ [globals_js_1.SymbolPinSide.Left]: 0,
802
+ [globals_js_1.SymbolPinSide.Right]: 0,
803
+ [globals_js_1.SymbolPinSide.Top]: 0,
804
+ [globals_js_1.SymbolPinSide.Bottom]: 0,
805
+ };
825
806
  if (arrangeProps === null) {
826
807
  let counter = 0;
827
808
  for (const [pinId] of pins) {
@@ -833,6 +814,14 @@ function getPortSide(pins, arrangeProps) {
833
814
  });
834
815
  counter++;
835
816
  }
817
+ const leftSideItems = result.filter(item => {
818
+ return item.side === PinDefinition_js_1.PortSide.WEST;
819
+ });
820
+ const rightSideItems = result.filter(item => {
821
+ return item.side === PinDefinition_js_1.PortSide.EAST;
822
+ });
823
+ maxPositions[globals_js_1.SymbolPinSide.Left] = leftSideItems.length;
824
+ maxPositions[globals_js_1.SymbolPinSide.Right] = rightSideItems.length;
836
825
  }
837
826
  else {
838
827
  let counter = pins.size;
@@ -846,36 +835,45 @@ function getPortSide(pins, arrangeProps) {
846
835
  useItems = [...items];
847
836
  }
848
837
  let useSide = PinDefinition_js_1.PortSide.WEST;
849
- if (key === 'left') {
850
- useSide = PinDefinition_js_1.PortSide.WEST;
851
- }
852
- else if (key === 'right') {
853
- useSide = PinDefinition_js_1.PortSide.EAST;
854
- }
855
- else if (key === 'top') {
856
- useSide = PinDefinition_js_1.PortSide.NORTH;
857
- }
858
- else if (key === 'bottom') {
859
- useSide = PinDefinition_js_1.PortSide.SOUTH;
838
+ switch (key) {
839
+ case globals_js_1.SymbolPinSide.Left:
840
+ useSide = PinDefinition_js_1.PortSide.WEST;
841
+ break;
842
+ case globals_js_1.SymbolPinSide.Right:
843
+ useSide = PinDefinition_js_1.PortSide.EAST;
844
+ break;
845
+ case globals_js_1.SymbolPinSide.Top:
846
+ useSide = PinDefinition_js_1.PortSide.NORTH;
847
+ break;
848
+ case globals_js_1.SymbolPinSide.Bottom:
849
+ useSide = PinDefinition_js_1.PortSide.SOUTH;
850
+ break;
860
851
  }
861
852
  let position = 0;
862
853
  useItems.forEach(item => {
863
854
  if (typeof item === 'object' && Array.isArray(item)) {
864
- position += item[0];
855
+ position += item[0].toNumber();
865
856
  }
866
- if (existingPinIds.indexOf(item) !== -1) {
867
- result.push({
868
- pinId: item,
869
- side: useSide,
870
- position,
871
- order: counter
872
- });
873
- counter--;
874
- position += 1;
857
+ else {
858
+ const itemValue = item.toNumber();
859
+ if (existingPinIds.indexOf(itemValue) !== -1) {
860
+ result.push({
861
+ pinId: itemValue,
862
+ side: useSide,
863
+ position,
864
+ order: counter
865
+ });
866
+ counter--;
867
+ position += 1;
868
+ }
875
869
  }
876
870
  });
871
+ maxPositions[key] = position;
877
872
  }
878
873
  }
879
- return result;
874
+ return {
875
+ pins: result,
876
+ maxPositions,
877
+ };
880
878
  }
881
879
  exports.getPortSide = getPortSide;
@@ -50,10 +50,8 @@ function generateKiCADNetList(netlist) {
50
50
  }
51
51
  }
52
52
  else {
53
- if (instance.typeProp !== globals_js_1.ComponentTypes.label &&
54
- instance.typeProp !== globals_js_1.ComponentTypes.net &&
55
- instance.typeProp !== globals_js_1.ComponentTypes.point &&
56
- instance.typeProp !== globals_js_1.ComponentTypes.frame &&
53
+ if (instance.typeProp !== globals_js_1.ComponentTypes.net &&
54
+ instance.typeProp !== globals_js_1.ComponentTypes.graphic &&
57
55
  instance.typeProp !== null) {
58
56
  console.log('Skipping', instance.instanceName);
59
57
  }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.VerticalAlign = exports.HorizontalAlign = exports.Geometry = exports.GeometryProp = exports.Textbox = void 0;
6
+ exports.VerticalAlignProp = exports.HorizontalAlignProp = exports.VerticalAlign = exports.HorizontalAlign = exports.Geometry = exports.GeometryProp = exports.Textbox = void 0;
7
7
  const core_1 = __importDefault(require("@flatten-js/core"));
8
8
  const sizing_js_1 = require("./sizing.js");
9
9
  const globals_js_1 = require("./globals.js");
@@ -16,7 +16,9 @@ class Textbox extends core_1.default.Polygon {
16
16
  }
17
17
  constructor(id, text, anchorPoint, polygon, style, bounds, label) {
18
18
  super(polygon.vertices);
19
- this.anchorPoint = [0, 0];
19
+ this.anchorPoint = [
20
+ (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)
21
+ ];
20
22
  this.boundingBox = { width: -1, height: -1 };
21
23
  this.font = 'default';
22
24
  this.id = id;
@@ -43,8 +45,8 @@ class Textbox extends core_1.default.Polygon {
43
45
  else {
44
46
  throw 'Invalid string passed into textbox';
45
47
  }
46
- const { fontSize = 10, anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', portType = null, } = style ?? {};
47
- const { width, height, box } = (0, sizing_js_1.measureTextSize2)(useText, globals_js_1.defaultFont, fontSize * globals_js_1.fontDisplayScale, fontWeight, anchor, vanchor);
48
+ const { fontSize = (0, ParamDefinition_js_1.numeric)(50), anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', portType = null, } = style ?? {};
49
+ const { box } = (0, sizing_js_1.measureTextSize2)(useText, globals_js_1.defaultFont, fontSize.mul(globals_js_1.fontDisplayScale).toNumber(), fontWeight, anchor, vanchor);
48
50
  let polygonCoords = [];
49
51
  let anchorOffsetX = 0;
50
52
  let anchorOffsetY = 0;
@@ -103,20 +105,31 @@ class Textbox extends core_1.default.Polygon {
103
105
  anchorOffsetY += paddingVert / 2;
104
106
  }
105
107
  const polygon = new core_1.default.Polygon(polygonCoords);
106
- return new Textbox(id, useText, [x + anchorOffsetX, y + anchorOffsetY], polygon, style, box, label);
108
+ return new Textbox(id, useText, [x.add(anchorOffsetX), y.add(anchorOffsetY)], polygon, style, box, label);
107
109
  }
108
110
  rotate(angle, origin) {
109
111
  const feature = super.rotate(angle, origin);
110
112
  const newAnchorPoint = this.transformAnchorPoint(segment => segment.rotate(angle, origin));
111
- return new Textbox(this.id, this.text, newAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
113
+ const tmpAnchorPoint = [
114
+ (0, ParamDefinition_js_1.numeric)(newAnchorPoint[0]),
115
+ (0, ParamDefinition_js_1.numeric)(newAnchorPoint[1])
116
+ ];
117
+ return new Textbox(this.id, this.text, tmpAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
112
118
  }
113
119
  transform(matrix) {
114
120
  const feature = super.transform(matrix);
115
121
  const newAnchorPoint = this.transformAnchorPoint(segment => segment.transform(matrix));
116
- return new Textbox(this.id, this.text, newAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
122
+ const tmpAnchorPoint = [
123
+ (0, ParamDefinition_js_1.numeric)(newAnchorPoint[0]),
124
+ (0, ParamDefinition_js_1.numeric)(newAnchorPoint[1])
125
+ ];
126
+ return new Textbox(this.id, this.text, tmpAnchorPoint, feature, this.style, this.textMeasurementBounds, this.label);
117
127
  }
118
128
  transformAnchorPoint(callback) {
119
- const anchorPointSegment = new core_1.default.Segment(new core_1.default.Point(0, 0), new core_1.default.Point(this.anchorPoint));
129
+ const anchorPointSegment = new core_1.default.Segment(new core_1.default.Point(0, 0), new core_1.default.Point([
130
+ this.anchorPoint[0].toNumber(),
131
+ this.anchorPoint[1].toNumber(),
132
+ ]));
120
133
  const newSegment = callback(anchorPointSegment);
121
134
  const lastPoint = newSegment.vertices[newSegment.vertices.length - 1];
122
135
  return [
@@ -137,7 +150,7 @@ class GeometryProp {
137
150
  exports.GeometryProp = GeometryProp;
138
151
  class Geometry {
139
152
  static point(x, y) {
140
- return new core_1.default.Point(x, y);
153
+ return new core_1.default.Point(x.toNumber(), y.toNumber());
141
154
  }
142
155
  static line(x1, y1, x2, y2) {
143
156
  return new core_1.default.Line(Geometry.point(x1, y1), Geometry.point(x2, y2));
@@ -152,7 +165,12 @@ class Geometry {
152
165
  return new core_1.default.Segment(Geometry.point(start[0], start[1]), Geometry.point(end[0], end[1]));
153
166
  }
154
167
  static polygon(coords) {
155
- return new core_1.default.Polygon(coords);
168
+ return new core_1.default.Polygon(coords.map(item => {
169
+ return [
170
+ item[0].toNumber(),
171
+ item[1].toNumber(),
172
+ ];
173
+ }));
156
174
  }
157
175
  static multiline(coords) {
158
176
  const segments = [];
@@ -162,11 +180,13 @@ class Geometry {
162
180
  return new core_1.default.Multiline(segments);
163
181
  }
164
182
  static arc(center, radius, startAngle, endAngle, sweepDirection) {
165
- return new core_1.default.Arc(Geometry.point(center[0], center[1]), radius, startAngle, endAngle, sweepDirection);
183
+ return new core_1.default.Arc(Geometry.point(center[0], center[1]), radius.toNumber(), startAngle.toNumber(), endAngle.toNumber(), sweepDirection);
166
184
  }
167
185
  static getCoords(item) {
168
186
  const points = item.vertices.map(vertex => {
169
- return [vertex.x, vertex.y];
187
+ return [
188
+ (0, ParamDefinition_js_1.numeric)(vertex.x), (0, ParamDefinition_js_1.numeric)(vertex.y)
189
+ ];
170
190
  });
171
191
  return points;
172
192
  }
@@ -213,10 +233,10 @@ class Geometry {
213
233
  if (feature instanceof Textbox) {
214
234
  const [x, y] = feature.anchorPoint;
215
235
  box = {
216
- xmin: box.xmin + x,
217
- ymin: box.ymin + y,
218
- xmax: box.xmax + x,
219
- ymax: box.ymax + y
236
+ xmin: box.xmin + x.toNumber(),
237
+ ymin: box.ymin + y.toNumber(),
238
+ xmax: box.xmax + x.toNumber(),
239
+ ymax: box.ymax + y.toNumber()
220
240
  };
221
241
  }
222
242
  if (box.xmin === undefined) {
@@ -273,7 +293,7 @@ class Geometry {
273
293
  for (let i = 0; i < coords.length; i++) {
274
294
  const [x, y] = coords[i];
275
295
  const command = (i === 0) ? 'M' : 'L';
276
- path.push(`${command}`, x, y);
296
+ path.push(`${command}`, x.toNumber(), y.toNumber());
277
297
  }
278
298
  if (isClosedPolygon) {
279
299
  path.push('Z');
@@ -306,8 +326,8 @@ class Geometry {
306
326
  const existingSegments = [];
307
327
  wirePoints.forEach(points => {
308
328
  const tmpPoints = points.map(pt => {
309
- const roundedX = (0, utils_js_1.roundValue)(pt.x);
310
- const roundedY = (0, utils_js_1.roundValue)(pt.y);
329
+ const roundedX = (0, utils_js_1.roundValue)(pt.x).toNumber();
330
+ const roundedY = (0, utils_js_1.roundValue)(pt.y).toNumber();
311
331
  return new core_1.default.Point(roundedX, roundedY);
312
332
  });
313
333
  for (let i = 0; i < tmpPoints.length - 1; i++) {
@@ -520,6 +540,19 @@ var VerticalAlign;
520
540
  VerticalAlign["Middle"] = "middle";
521
541
  VerticalAlign["Bottom"] = "bottom";
522
542
  })(VerticalAlign || (exports.VerticalAlign = VerticalAlign = {}));
543
+ var HorizontalAlignProp;
544
+ (function (HorizontalAlignProp) {
545
+ HorizontalAlignProp["Start"] = "start";
546
+ HorizontalAlignProp["Middle"] = "middle";
547
+ HorizontalAlignProp["End"] = "end";
548
+ })(HorizontalAlignProp || (exports.HorizontalAlignProp = HorizontalAlignProp = {}));
549
+ var VerticalAlignProp;
550
+ (function (VerticalAlignProp) {
551
+ VerticalAlignProp["Hanging"] = "hanging";
552
+ VerticalAlignProp["Middle"] = "middle";
553
+ VerticalAlignProp["Central"] = "central";
554
+ VerticalAlignProp["TextTop"] = "text-top";
555
+ })(VerticalAlignProp || (exports.VerticalAlignProp = VerticalAlignProp = {}));
523
556
  function getArcPointRadians(centerX, centerY, radius, angleRads) {
524
557
  const dx = Math.cos(angleRads);
525
558
  const dy = Math.sin(angleRads);