circuitscript 0.1.16 → 0.1.17
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.
- package/dist/cjs/BaseVisitor.js +2 -1
- package/dist/cjs/draw_symbols.js +18 -17
- package/dist/cjs/execute.js +40 -20
- package/dist/cjs/globals.js +1 -0
- package/dist/cjs/graph.js +101 -27
- package/dist/cjs/layout.js +6 -1
- package/dist/cjs/objects/ClassComponent.js +27 -20
- package/dist/cjs/objects/ExecutionScope.js +7 -2
- package/dist/cjs/objects/Net.js +1 -1
- package/dist/cjs/objects/PinDefinition.js +55 -3
- package/dist/cjs/objects/types.js +16 -1
- package/dist/cjs/visitor.js +56 -18
- package/dist/esm/BaseVisitor.js +2 -1
- package/dist/esm/draw_symbols.js +18 -17
- package/dist/esm/execute.js +41 -21
- package/dist/esm/globals.js +1 -0
- package/dist/esm/graph.js +79 -28
- package/dist/esm/layout.js +6 -1
- package/dist/esm/objects/ClassComponent.js +28 -21
- package/dist/esm/objects/ExecutionScope.js +7 -2
- package/dist/esm/objects/Net.js +1 -1
- package/dist/esm/objects/PinDefinition.js +53 -2
- package/dist/esm/objects/types.js +15 -0
- package/dist/esm/visitor.js +58 -20
- package/dist/libs/std.cst +3 -2
- package/dist/types/BaseVisitor.d.ts +2 -1
- package/dist/types/draw_symbols.d.ts +13 -7
- package/dist/types/execute.d.ts +7 -7
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/graph.d.ts +2 -1
- package/dist/types/layout.d.ts +2 -1
- package/dist/types/objects/ClassComponent.d.ts +8 -8
- package/dist/types/objects/ExecutionScope.d.ts +5 -4
- package/dist/types/objects/Net.d.ts +2 -2
- package/dist/types/objects/PinDefinition.d.ts +17 -2
- package/dist/types/objects/types.d.ts +15 -1
- package/libs/std.cst +3 -2
- package/package.json +2 -1
package/dist/cjs/BaseVisitor.js
CHANGED
|
@@ -14,6 +14,7 @@ const utils_js_1 = require("./utils.js");
|
|
|
14
14
|
const builtinMethods_js_1 = require("./builtinMethods.js");
|
|
15
15
|
const utils_js_2 = require("./utils.js");
|
|
16
16
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
17
|
+
const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
17
18
|
class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
18
19
|
constructor(silent = false, onErrorHandler = null, environment) {
|
|
19
20
|
super();
|
|
@@ -92,7 +93,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
92
93
|
this.log2(`assigned component param ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
|
|
93
94
|
sequenceParts.push(...['instance', [leftSideReference.parentValue, trailers], rhsValue]);
|
|
94
95
|
if (leftSideReference.parentValue.typeProp === globals_js_1.ComponentTypes.net) {
|
|
95
|
-
const net = this.getScope().getNet(leftSideReference.parentValue, 1);
|
|
96
|
+
const net = this.getScope().getNet(leftSideReference.parentValue, new PinDefinition_js_1.PinId(1));
|
|
96
97
|
if (net) {
|
|
97
98
|
const trailerValue = trailers.join(".");
|
|
98
99
|
net.params.set(trailerValue, rhsValue);
|
package/dist/cjs/draw_symbols.js
CHANGED
|
@@ -8,6 +8,7 @@ const PinTypes_js_1 = require("./objects/PinTypes.js");
|
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
9
|
const types_js_1 = require("./objects/types.js");
|
|
10
10
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
11
|
+
const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
11
12
|
class SymbolGraphic {
|
|
12
13
|
constructor() {
|
|
13
14
|
this.drawPortsName = true;
|
|
@@ -563,6 +564,12 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
563
564
|
(0, helpers_js_1.milsToMM)(endY)
|
|
564
565
|
];
|
|
565
566
|
}
|
|
567
|
+
if (positionParams[0] instanceof ParamDefinition_js_1.NumericValue) {
|
|
568
|
+
positionParams[0] = new PinDefinition_js_1.PinId(positionParams[0].toNumber());
|
|
569
|
+
}
|
|
570
|
+
else if (typeof positionParams[0] === 'number' || typeof positionParams[0] === 'string') {
|
|
571
|
+
positionParams[0] = new PinDefinition_js_1.PinId(positionParams[0]);
|
|
572
|
+
}
|
|
566
573
|
drawing.addPinMM(...positionParams, lineColor);
|
|
567
574
|
const lastAddedPin = this.drawing.pins[this.drawing.pins.length - 1];
|
|
568
575
|
const [pinId, , angle] = lastAddedPin;
|
|
@@ -607,7 +614,8 @@ class SymbolPlaceholder extends SymbolGraphic {
|
|
|
607
614
|
vanchor: geometry_js_1.VerticalAlign.Middle,
|
|
608
615
|
textColor: pinNameColor,
|
|
609
616
|
});
|
|
610
|
-
|
|
617
|
+
const pinDisplayText = pinId.toString();
|
|
618
|
+
displayPinId && drawing.addLabel(endX.add(pinIdOffsetX), endY.add(pinIdOffsetY), pinDisplayText, {
|
|
611
619
|
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.defaultPinIdTextSize),
|
|
612
620
|
anchor: pinIdAlignment,
|
|
613
621
|
vanchor: pinIdVAlignment,
|
|
@@ -707,7 +715,7 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
707
715
|
leftPins.forEach(pin => {
|
|
708
716
|
const position = pin.position;
|
|
709
717
|
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
710
|
-
drawing.addPinMM(
|
|
718
|
+
drawing.addPinMM(pin.pinId, leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
|
|
711
719
|
drawing.addLabel(leftPinStart.add((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
|
|
712
720
|
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
|
|
713
721
|
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
@@ -724,7 +732,7 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
724
732
|
rightPins.forEach(pin => {
|
|
725
733
|
const position = pin.position;
|
|
726
734
|
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
727
|
-
drawing.addPinMM(
|
|
735
|
+
drawing.addPinMM(pin.pinId, rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
|
|
728
736
|
drawing.addLabel(rightPinStart.sub((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
|
|
729
737
|
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
|
|
730
738
|
anchor: geometry_js_1.HorizontalAlign.Right,
|
|
@@ -741,7 +749,7 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
741
749
|
topPins.forEach(pin => {
|
|
742
750
|
const position = pin.position;
|
|
743
751
|
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
744
|
-
drawing.addPinMM(
|
|
752
|
+
drawing.addPinMM(pin.pinId, pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
|
|
745
753
|
drawing.addLabel(pinX, topPinStart.add((0, helpers_js_1.milsToMM)(20)), pin.text, {
|
|
746
754
|
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
|
|
747
755
|
anchor: geometry_js_1.HorizontalAlign.Right,
|
|
@@ -760,7 +768,7 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
760
768
|
bottomPins.forEach(pin => {
|
|
761
769
|
const position = pin.position;
|
|
762
770
|
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
763
|
-
drawing.addPinMM(
|
|
771
|
+
drawing.addPinMM(pin.pinId, pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
|
|
764
772
|
drawing.addLabel(pinX, bottomPinStart.sub((0, helpers_js_1.milsToMM)(20)), pin.text, {
|
|
765
773
|
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolPinTextSize),
|
|
766
774
|
anchor: geometry_js_1.HorizontalAlign.Left,
|
|
@@ -846,7 +854,7 @@ class SymbolCustomModule extends SymbolCustom {
|
|
|
846
854
|
leftPins.forEach(pin => {
|
|
847
855
|
const position = pin.position;
|
|
848
856
|
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
849
|
-
drawing.addPinMM(
|
|
857
|
+
drawing.addPinMM(pin.pinId, leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
|
|
850
858
|
drawing.addModulePort(leftPinStart, pinY, this.portWidth, this.portHeight, pin.pinType);
|
|
851
859
|
drawing.addLabel(leftPinStart.add(this.portWidth).add((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
|
|
852
860
|
fontSize: (0, ParamDefinition_js_1.numeric)(40),
|
|
@@ -858,7 +866,7 @@ class SymbolCustomModule extends SymbolCustom {
|
|
|
858
866
|
rightPins.forEach(pin => {
|
|
859
867
|
const position = pin.position;
|
|
860
868
|
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
861
|
-
drawing.addPinMM(
|
|
869
|
+
drawing.addPinMM(pin.pinId, rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
|
|
862
870
|
drawing.addModulePort(rightPinStart, pinY, this.portWidth, this.portHeight, pin.pinType, -1);
|
|
863
871
|
drawing.addLabel(rightPinStart.sub(this.portWidth).sub((0, helpers_js_1.milsToMM)(20)), pinY, pin.text, {
|
|
864
872
|
fontSize: (0, ParamDefinition_js_1.numeric)(40),
|
|
@@ -870,7 +878,7 @@ class SymbolCustomModule extends SymbolCustom {
|
|
|
870
878
|
topPins.forEach(pin => {
|
|
871
879
|
const position = pin.position;
|
|
872
880
|
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
873
|
-
drawing.addPinMM(
|
|
881
|
+
drawing.addPinMM(pin.pinId, pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
|
|
874
882
|
drawing.addModulePort(pinX, topPinStart, this.portWidth, this.portHeight, pin.pinType, 1, 90);
|
|
875
883
|
drawing.addLabel(pinX, topPinStart.add(this.portWidth).add((0, helpers_js_1.milsToMM)(20)), pin.text, {
|
|
876
884
|
fontSize: (0, ParamDefinition_js_1.numeric)(40),
|
|
@@ -883,7 +891,7 @@ class SymbolCustomModule extends SymbolCustom {
|
|
|
883
891
|
bottomPins.forEach(pin => {
|
|
884
892
|
const position = pin.position;
|
|
885
893
|
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
886
|
-
drawing.addPinMM(
|
|
894
|
+
drawing.addPinMM(pin.pinId, pinX, bottomPinStart, pinX, bottomPinStart.sub(this.pinLength), defaultLineColor);
|
|
887
895
|
drawing.addModulePort(pinX, bottomPinStart, this.portWidth, this.portHeight, pin.pinType, 1, -90);
|
|
888
896
|
drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub((0, helpers_js_1.milsToMM)(20)), pin.text, {
|
|
889
897
|
fontSize: (0, ParamDefinition_js_1.numeric)(40),
|
|
@@ -922,13 +930,6 @@ class SymbolDrawing {
|
|
|
922
930
|
this.items.push(geometry_js_1.Geometry.segment([startX, startY], [endX, endY]));
|
|
923
931
|
return this;
|
|
924
932
|
}
|
|
925
|
-
addPin(pinId, startX, startY, endX, endY, lineColor) {
|
|
926
|
-
startX = (0, helpers_js_1.milsToMM)(startX);
|
|
927
|
-
startY = (0, helpers_js_1.milsToMM)(startY);
|
|
928
|
-
endX = (0, helpers_js_1.milsToMM)(endX);
|
|
929
|
-
endY = (0, helpers_js_1.milsToMM)(endY);
|
|
930
|
-
return this.addPinMM(pinId, startX, startY, endX, endY, lineColor);
|
|
931
|
-
}
|
|
932
933
|
addPinMM(pinId, startXMM, startYMM, endXMM, endYMM, lineColor) {
|
|
933
934
|
let angle = 0;
|
|
934
935
|
const tmpStartXMM = startXMM.toNumber();
|
|
@@ -1231,7 +1232,7 @@ class SymbolDrawing {
|
|
|
1231
1232
|
}
|
|
1232
1233
|
getPinPosition(pinId) {
|
|
1233
1234
|
const pin = this.pins.find(item => {
|
|
1234
|
-
return item[0].
|
|
1235
|
+
return item[0].equals(pinId);
|
|
1235
1236
|
});
|
|
1236
1237
|
if (pin) {
|
|
1237
1238
|
const [, feature, angle] = pin;
|
package/dist/cjs/execute.js
CHANGED
|
@@ -146,7 +146,7 @@ class ExecutionContext {
|
|
|
146
146
|
const tmpArrangeRight = [];
|
|
147
147
|
pins.forEach((pin, index) => {
|
|
148
148
|
const useArray = (index % 2 === 0) ? tmpArrangeLeft : tmpArrangeRight;
|
|
149
|
-
useArray.push(
|
|
149
|
+
useArray.push(pin.id);
|
|
150
150
|
});
|
|
151
151
|
const arrangeProp = new Map([
|
|
152
152
|
[globals_js_1.SymbolPinSide.Left, tmpArrangeLeft],
|
|
@@ -156,11 +156,9 @@ class ExecutionContext {
|
|
|
156
156
|
}
|
|
157
157
|
if (props.arrange !== null) {
|
|
158
158
|
component.arrangeProps = this.removeArrangePropDuplicates(props.arrange);
|
|
159
|
-
const arrangePropPins = this.getArrangePropPins(component.arrangeProps)
|
|
160
|
-
return item.toNumber();
|
|
161
|
-
});
|
|
159
|
+
const arrangePropPins = this.getArrangePropPins(component.arrangeProps);
|
|
162
160
|
pins.forEach(pin => {
|
|
163
|
-
if (arrangePropPins.
|
|
161
|
+
if (arrangePropPins.find(id => id.equals(pin.id)) === undefined) {
|
|
164
162
|
this.logWarning(`Pin ${pin.id} is not specified in arrange property`);
|
|
165
163
|
}
|
|
166
164
|
});
|
|
@@ -177,6 +175,7 @@ class ExecutionContext {
|
|
|
177
175
|
});
|
|
178
176
|
if (component.typeProp === globals_js_1.ComponentTypes.net) {
|
|
179
177
|
const netName = paramsMap.get(globals_js_1.ParamKeys.net_name);
|
|
178
|
+
const netType = paramsMap.get(globals_js_1.ParamKeys.net_type);
|
|
180
179
|
let priority = 0;
|
|
181
180
|
if (paramsMap.has(globals_js_1.ParamKeys.priority)) {
|
|
182
181
|
priority = paramsMap.get(globals_js_1.ParamKeys.priority).toNumber();
|
|
@@ -188,21 +187,26 @@ class ExecutionContext {
|
|
|
188
187
|
this.log('net found', tmpNet.namespace, tmpNet.name);
|
|
189
188
|
}
|
|
190
189
|
else {
|
|
191
|
-
tmpNet = new Net_js_1.Net(this.netNamespace, netName, priority);
|
|
190
|
+
tmpNet = new Net_js_1.Net(this.netNamespace, netName, priority, netType);
|
|
192
191
|
this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
|
|
193
192
|
}
|
|
194
|
-
const defaultPin = 1;
|
|
193
|
+
const defaultPin = new PinDefinition_js_1.PinId(1);
|
|
195
194
|
this.scope.setNet(component, defaultPin, tmpNet);
|
|
196
195
|
this.log('set net', netName, 'component', component, defaultPin);
|
|
197
196
|
}
|
|
198
197
|
const { pins: pinSides, maxPositions } = getPortSide(component.pins, component.arrangeProps);
|
|
199
198
|
component.pinsMaxPositions = maxPositions;
|
|
199
|
+
const pinIdKeys = Array.from(component.pins.keys());
|
|
200
200
|
pinSides.forEach(({ pinId, side, position }) => {
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
const matchedPinId = pinIdKeys.find(id => id.equals(pinId));
|
|
202
|
+
if (matchedPinId) {
|
|
203
|
+
const tmpPin = component.pins.get(matchedPinId);
|
|
203
204
|
tmpPin.side = side;
|
|
204
205
|
tmpPin.position = position;
|
|
205
206
|
}
|
|
207
|
+
else {
|
|
208
|
+
throw 'Not found!';
|
|
209
|
+
}
|
|
206
210
|
});
|
|
207
211
|
this.scope.instances.set(instanceName, component);
|
|
208
212
|
const pinsOutput = pins.map((pin) => {
|
|
@@ -225,15 +229,32 @@ class ExecutionContext {
|
|
|
225
229
|
if (!Array.isArray(items)) {
|
|
226
230
|
items = [items];
|
|
227
231
|
}
|
|
232
|
+
items = items.map(item => {
|
|
233
|
+
if (item instanceof ParamDefinition_js_1.NumericValue) {
|
|
234
|
+
item = item.toNumber();
|
|
235
|
+
}
|
|
236
|
+
if (item instanceof PinDefinition_js_1.PinId) {
|
|
237
|
+
return item;
|
|
238
|
+
}
|
|
239
|
+
else if (PinDefinition_js_1.PinId.isPinIdType(item)) {
|
|
240
|
+
return new PinDefinition_js_1.PinId(item);
|
|
241
|
+
}
|
|
242
|
+
return item;
|
|
243
|
+
});
|
|
244
|
+
arrangeProp.set(side, items);
|
|
245
|
+
if (!Array.isArray(items)) {
|
|
246
|
+
items = [items];
|
|
247
|
+
}
|
|
228
248
|
const uniqueItems = [];
|
|
229
249
|
items.forEach(item => {
|
|
230
|
-
if (item instanceof
|
|
231
|
-
|
|
232
|
-
|
|
250
|
+
if (item instanceof PinDefinition_js_1.PinId) {
|
|
251
|
+
const found = seenIds.find(id => id.equals(item));
|
|
252
|
+
if (!found) {
|
|
253
|
+
seenIds.push(item);
|
|
233
254
|
uniqueItems.push(item);
|
|
234
255
|
}
|
|
235
256
|
else {
|
|
236
|
-
this.logWarning(`Pin ${item.
|
|
257
|
+
this.logWarning(`Pin ${item.toString()} specified more than once in arrange property`);
|
|
237
258
|
}
|
|
238
259
|
}
|
|
239
260
|
else {
|
|
@@ -256,7 +277,7 @@ class ExecutionContext {
|
|
|
256
277
|
const items = arrangeProps.get(side);
|
|
257
278
|
if (items) {
|
|
258
279
|
items.forEach(item => {
|
|
259
|
-
if (item instanceof
|
|
280
|
+
if (item instanceof PinDefinition_js_1.PinId) {
|
|
260
281
|
pins.push(item);
|
|
261
282
|
}
|
|
262
283
|
});
|
|
@@ -378,7 +399,7 @@ class ExecutionContext {
|
|
|
378
399
|
const cloneInstanceName = component.instanceName + ':' + idNum;
|
|
379
400
|
this.scope.instances.set(cloneInstanceName, componentCopy);
|
|
380
401
|
componentCopy.instanceName = cloneInstanceName;
|
|
381
|
-
const defaultPin = 1;
|
|
402
|
+
const defaultPin = new PinDefinition_js_1.PinId(1);
|
|
382
403
|
if (this.scope.getNet(component, defaultPin) === null) {
|
|
383
404
|
const foundNet = this.resolveComponentPinNet(component, defaultPin);
|
|
384
405
|
if (foundNet !== null) {
|
|
@@ -597,7 +618,7 @@ class ExecutionContext {
|
|
|
597
618
|
else if (type === globals_js_1.ReferenceTypes.instance) {
|
|
598
619
|
const tmpComponent = parentValue;
|
|
599
620
|
if (tmpComponent.typeProp === globals_js_1.ComponentTypes.net) {
|
|
600
|
-
const usedNet = this.scope.getNet(tmpComponent, 1);
|
|
621
|
+
const usedNet = this.scope.getNet(tmpComponent, new PinDefinition_js_1.PinId(1));
|
|
601
622
|
if (usedNet) {
|
|
602
623
|
const trailerValue = trailers.join(".");
|
|
603
624
|
useValue = usedNet.params.get(trailerValue) ?? null;
|
|
@@ -691,7 +712,7 @@ class ExecutionContext {
|
|
|
691
712
|
const linkRootComponent = true;
|
|
692
713
|
const tmpRoot = childScope.componentRoot;
|
|
693
714
|
if (linkRootComponent) {
|
|
694
|
-
const netConnectedToRoot = childScope.getNet(tmpRoot, 1);
|
|
715
|
+
const netConnectedToRoot = childScope.getNet(tmpRoot, new PinDefinition_js_1.PinId(1));
|
|
695
716
|
if (netConnectedToRoot !== null) {
|
|
696
717
|
let currentNet = this.scope.getNet(currentComponent, currentPin);
|
|
697
718
|
if (currentNet === null) {
|
|
@@ -1039,10 +1060,9 @@ function getPortSide(pins, arrangeProps) {
|
|
|
1039
1060
|
position += item[0].toNumber();
|
|
1040
1061
|
}
|
|
1041
1062
|
else {
|
|
1042
|
-
|
|
1043
|
-
if (existingPinIds.indexOf(itemValue) !== -1) {
|
|
1063
|
+
if (existingPinIds.find(id => id.equals(item))) {
|
|
1044
1064
|
result.push({
|
|
1045
|
-
pinId:
|
|
1065
|
+
pinId: item,
|
|
1046
1066
|
side: useSide,
|
|
1047
1067
|
position,
|
|
1048
1068
|
order: counter
|
package/dist/cjs/globals.js
CHANGED
package/dist/cjs/graph.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.RenderItemType = exports.generateLayoutPinDefinition = exports.getWireName = exports.NetGraph = void 0;
|
|
4
27
|
const graphlib_1 = require("@dagrejs/graphlib");
|
|
@@ -9,6 +32,9 @@ const layout_js_1 = require("./layout.js");
|
|
|
9
32
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
10
33
|
const Frame_js_1 = require("./objects/Frame.js");
|
|
11
34
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
35
|
+
const types_js_1 = require("./objects/types.js");
|
|
36
|
+
const ml_matrix_1 = __importStar(require("ml-matrix"));
|
|
37
|
+
const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
12
38
|
class NetGraph {
|
|
13
39
|
constructor(logger) {
|
|
14
40
|
this.logger = logger;
|
|
@@ -75,7 +101,7 @@ class NetGraph {
|
|
|
75
101
|
if (prevNodeType === RenderItemType.Component) {
|
|
76
102
|
const matchingItem = nets.find(([comp, pin]) => {
|
|
77
103
|
return comp.instanceName === previousNode
|
|
78
|
-
&& pin
|
|
104
|
+
&& pin.equals(previousPin);
|
|
79
105
|
});
|
|
80
106
|
if (matchingItem !== undefined) {
|
|
81
107
|
useNet = matchingItem[2];
|
|
@@ -190,21 +216,71 @@ class NetGraph {
|
|
|
190
216
|
this.logger.add(params.join(' '));
|
|
191
217
|
}
|
|
192
218
|
generateNetGraph(nets) {
|
|
193
|
-
const
|
|
194
|
-
|
|
219
|
+
const uniqueNets = new Set(nets.map(([, , net]) => net));
|
|
220
|
+
const components = new Set(nets.map(([component, ,]) => component));
|
|
221
|
+
const tmpNets = Array.from(uniqueNets);
|
|
222
|
+
const gndNet = tmpNets.find(item => {
|
|
223
|
+
return item.toString() === '/GND';
|
|
195
224
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
225
|
+
const otherNets = tmpNets.filter(item => {
|
|
226
|
+
return item !== gndNet;
|
|
227
|
+
});
|
|
228
|
+
const netsIndexed = [];
|
|
229
|
+
if (gndNet) {
|
|
230
|
+
netsIndexed.push(gndNet);
|
|
231
|
+
}
|
|
232
|
+
netsIndexed.push(...otherNets);
|
|
233
|
+
const netsLength = netsIndexed.length;
|
|
234
|
+
const conductanceMatrix = ml_matrix_1.default.zeros(netsLength, netsLength);
|
|
235
|
+
components.forEach(item => {
|
|
236
|
+
if (item.typeProp === types_js_1.TypeProps.Resistor) {
|
|
237
|
+
const net1 = item.pinNets.get(1);
|
|
238
|
+
const net2 = item.pinNets.get(2);
|
|
239
|
+
const net1Index = netsIndexed.indexOf(net1);
|
|
240
|
+
const net2Index = netsIndexed.indexOf(net2);
|
|
241
|
+
const resistance = item.parameters.get('value');
|
|
242
|
+
const resistanceValue = resistance.toNumber();
|
|
243
|
+
const conductanceValue = 1 / resistanceValue;
|
|
244
|
+
const currentValue1 = conductanceMatrix.get(net1Index, net1Index);
|
|
245
|
+
const currentValue2 = conductanceMatrix.get(net2Index, net2Index);
|
|
246
|
+
const currentValue3 = conductanceMatrix.get(net1Index, net2Index);
|
|
247
|
+
const currentValue4 = conductanceMatrix.get(net2Index, net1Index);
|
|
248
|
+
conductanceMatrix.set(net1Index, net1Index, currentValue1 + conductanceValue);
|
|
249
|
+
conductanceMatrix.set(net2Index, net2Index, currentValue2 + conductanceValue);
|
|
250
|
+
conductanceMatrix.set(net1Index, net2Index, currentValue3 - conductanceValue);
|
|
251
|
+
conductanceMatrix.set(net2Index, net1Index, currentValue4 - conductanceValue);
|
|
205
252
|
}
|
|
206
|
-
graph.setEdge(netNodeName, componentNodeName, [component, pin, net]);
|
|
207
253
|
});
|
|
254
|
+
if (gndNet) {
|
|
255
|
+
conductanceMatrix.removeColumn(0);
|
|
256
|
+
conductanceMatrix.removeRow(0);
|
|
257
|
+
}
|
|
258
|
+
const netsWithoutGnd = netsIndexed.filter(net => {
|
|
259
|
+
return (net !== gndNet);
|
|
260
|
+
});
|
|
261
|
+
const netResistances = new Map();
|
|
262
|
+
try {
|
|
263
|
+
netsWithoutGnd.forEach((net, index) => {
|
|
264
|
+
if (net.type === types_js_1.NetTypes.Source) {
|
|
265
|
+
const currentVector = ml_matrix_1.default.zeros(netsWithoutGnd.length, 1);
|
|
266
|
+
currentVector.set(index, 0, 1);
|
|
267
|
+
const solution = (0, ml_matrix_1.solve)(conductanceMatrix, currentVector);
|
|
268
|
+
for (let i = 0; i < solution.rows; i++) {
|
|
269
|
+
const resValue = solution.get(i, 0);
|
|
270
|
+
if (resValue > 0) {
|
|
271
|
+
const targetNet = netsIndexed[i];
|
|
272
|
+
netResistances.set(targetNet, resValue);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
nets,
|
|
282
|
+
netResistances,
|
|
283
|
+
};
|
|
208
284
|
}
|
|
209
285
|
findNodePaths(graph, startNode, endNode, seenNodes = []) {
|
|
210
286
|
const edges = graph.nodeEdges(startNode);
|
|
@@ -265,24 +341,22 @@ function generateLayoutPinDefinition(component) {
|
|
|
265
341
|
useItems = [...items];
|
|
266
342
|
}
|
|
267
343
|
useItems.forEach(pinId => {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
addedPins.push(pinIdValue);
|
|
280
|
-
}
|
|
344
|
+
const existingPin = existingPinIds.find(pin => pin.equals(pinId));
|
|
345
|
+
if (existingPin) {
|
|
346
|
+
const pin = (0, PinDefinition_js_1.getPinDefinition)(pins, existingPin);
|
|
347
|
+
symbolPinDefinitions.push({
|
|
348
|
+
side: key,
|
|
349
|
+
pinId: pinId,
|
|
350
|
+
text: pin.name,
|
|
351
|
+
position: pin.position,
|
|
352
|
+
pinType: pin.pinType,
|
|
353
|
+
});
|
|
354
|
+
addedPins.push(pinId);
|
|
281
355
|
}
|
|
282
356
|
});
|
|
283
357
|
}
|
|
284
358
|
const unplacedPins = existingPinIds.filter(pinId => {
|
|
285
|
-
return addedPins.
|
|
359
|
+
return addedPins.find(id => id.equals(pinId)) === undefined;
|
|
286
360
|
});
|
|
287
361
|
if (unplacedPins.length > 0) {
|
|
288
362
|
component._unplacedPins = unplacedPins;
|
package/dist/cjs/layout.js
CHANGED
|
@@ -12,6 +12,7 @@ const geometry_js_1 = require("./geometry.js");
|
|
|
12
12
|
const Frame_js_1 = require("./objects/Frame.js");
|
|
13
13
|
const utils_js_1 = require("./utils.js");
|
|
14
14
|
const types_js_1 = require("./objects/types.js");
|
|
15
|
+
const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
15
16
|
const helpers_js_1 = require("./helpers.js");
|
|
16
17
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
17
18
|
const graph_js_1 = require("./graph.js");
|
|
@@ -694,7 +695,11 @@ class LayoutEngine {
|
|
|
694
695
|
}
|
|
695
696
|
if (subgraphEdges.length === 0) {
|
|
696
697
|
const [, node1] = graph.node(firstNodeId);
|
|
697
|
-
|
|
698
|
+
let defaultPin = new PinDefinition_js_1.PinId(1);
|
|
699
|
+
if (node1 instanceof RenderComponent) {
|
|
700
|
+
defaultPin = node1.component.getDefaultPin();
|
|
701
|
+
}
|
|
702
|
+
this.placeNodeAtPosition((0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0), node1, defaultPin);
|
|
698
703
|
return;
|
|
699
704
|
}
|
|
700
705
|
let fixedNode;
|
|
@@ -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
|
-
|
|
42
|
+
const pins = Array.from(this.pins.keys());
|
|
43
|
+
pins.sort();
|
|
44
|
+
return pins[0];
|
|
42
45
|
}
|
|
43
46
|
hasPin(pinId) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
59
|
-
|
|
59
|
+
for (const [pin,] of this.pins) {
|
|
60
|
+
if (pin.equals(pinId)) {
|
|
61
|
+
return pin;
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
|
-
|
|
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 ===
|
|
64
|
-
pinDef.altNames.indexOf(
|
|
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
|
-
|
|
73
|
-
|
|
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
|
|
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
|
|
42
|
+
return tmpComponent.isEqual(component) && tmpPin.equals(pin);
|
|
38
43
|
});
|
|
39
44
|
}
|
|
40
45
|
getNetWithName(name) {
|
|
@@ -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() {
|
package/dist/cjs/objects/Net.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Net = void 0;
|
|
4
4
|
class Net {
|
|
5
|
-
constructor(namespace, name, priority = 0, type =
|
|
5
|
+
constructor(namespace, name, priority = 0, type = 'any') {
|
|
6
6
|
this.params = new Map();
|
|
7
7
|
if (namespace.indexOf(' ') !== -1) {
|
|
8
8
|
throw "Invalid net namespace provided";
|