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.
- package/dist/cjs/BaseVisitor.js +2 -1
- package/dist/cjs/draw_symbols.js +18 -17
- package/dist/cjs/execute.js +45 -26
- package/dist/cjs/export.js +3 -3
- package/dist/cjs/globals.js +1 -0
- package/dist/cjs/graph.js +101 -27
- package/dist/cjs/helpers.js +55 -22
- package/dist/cjs/layout.js +6 -1
- package/dist/cjs/objects/ClassComponent.js +27 -20
- package/dist/cjs/objects/ExecutionScope.js +9 -4
- package/dist/cjs/objects/Net.js +2 -1
- package/dist/cjs/objects/PinDefinition.js +55 -3
- package/dist/cjs/objects/types.js +17 -1
- package/dist/cjs/visitor.js +78 -20
- package/dist/esm/BaseVisitor.js +2 -1
- package/dist/esm/draw_symbols.js +18 -17
- package/dist/esm/execute.js +46 -27
- package/dist/esm/export.js +1 -1
- package/dist/esm/globals.js +1 -0
- package/dist/esm/graph.js +79 -28
- package/dist/esm/helpers.js +46 -21
- package/dist/esm/layout.js +6 -1
- package/dist/esm/objects/ClassComponent.js +28 -21
- package/dist/esm/objects/ExecutionScope.js +9 -4
- package/dist/esm/objects/Net.js +2 -1
- package/dist/esm/objects/PinDefinition.js +53 -2
- package/dist/esm/objects/types.js +16 -0
- package/dist/esm/visitor.js +80 -22
- 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/export.d.ts +2 -2
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/graph.d.ts +2 -1
- package/dist/types/helpers.d.ts +15 -2
- package/dist/types/layout.d.ts +2 -1
- package/dist/types/objects/ClassComponent.d.ts +8 -8
- package/dist/types/objects/ExecutionScope.d.ts +7 -6
- package/dist/types/objects/Net.d.ts +3 -2
- package/dist/types/objects/PinDefinition.d.ts +17 -2
- package/dist/types/objects/types.d.ts +17 -2
- package/dist/types/visitor.d.ts +1 -0
- 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
|
});
|
|
@@ -343,13 +364,12 @@ class ExecutionContext {
|
|
|
343
364
|
if (pinId === null) {
|
|
344
365
|
usePinId = component.getDefaultPin();
|
|
345
366
|
}
|
|
367
|
+
else if (component.hasPin(pinId)) {
|
|
368
|
+
usePinId = component.getPin(pinId);
|
|
369
|
+
}
|
|
346
370
|
else {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
throw 'Invalid pin number ' + pinId + ' in ' + component;
|
|
352
|
-
}
|
|
371
|
+
throw new utils_js_1.RuntimeExecutionError('Invalid pin number '
|
|
372
|
+
+ pinId + ' in ' + component);
|
|
353
373
|
}
|
|
354
374
|
this.scope.setCurrent(component, usePinId);
|
|
355
375
|
if (!this.scope.hasNet(component, pinId)) {
|
|
@@ -378,7 +398,7 @@ class ExecutionContext {
|
|
|
378
398
|
const cloneInstanceName = component.instanceName + ':' + idNum;
|
|
379
399
|
this.scope.instances.set(cloneInstanceName, componentCopy);
|
|
380
400
|
componentCopy.instanceName = cloneInstanceName;
|
|
381
|
-
const defaultPin = 1;
|
|
401
|
+
const defaultPin = new PinDefinition_js_1.PinId(1);
|
|
382
402
|
if (this.scope.getNet(component, defaultPin) === null) {
|
|
383
403
|
const foundNet = this.resolveComponentPinNet(component, defaultPin);
|
|
384
404
|
if (foundNet !== null) {
|
|
@@ -597,7 +617,7 @@ class ExecutionContext {
|
|
|
597
617
|
else if (type === globals_js_1.ReferenceTypes.instance) {
|
|
598
618
|
const tmpComponent = parentValue;
|
|
599
619
|
if (tmpComponent.typeProp === globals_js_1.ComponentTypes.net) {
|
|
600
|
-
const usedNet = this.scope.getNet(tmpComponent, 1);
|
|
620
|
+
const usedNet = this.scope.getNet(tmpComponent, new PinDefinition_js_1.PinId(1));
|
|
601
621
|
if (usedNet) {
|
|
602
622
|
const trailerValue = trailers.join(".");
|
|
603
623
|
useValue = usedNet.params.get(trailerValue) ?? null;
|
|
@@ -691,7 +711,7 @@ class ExecutionContext {
|
|
|
691
711
|
const linkRootComponent = true;
|
|
692
712
|
const tmpRoot = childScope.componentRoot;
|
|
693
713
|
if (linkRootComponent) {
|
|
694
|
-
const netConnectedToRoot = childScope.getNet(tmpRoot, 1);
|
|
714
|
+
const netConnectedToRoot = childScope.getNet(tmpRoot, new PinDefinition_js_1.PinId(1));
|
|
695
715
|
if (netConnectedToRoot !== null) {
|
|
696
716
|
let currentNet = this.scope.getNet(currentComponent, currentPin);
|
|
697
717
|
if (currentNet === null) {
|
|
@@ -1039,10 +1059,9 @@ function getPortSide(pins, arrangeProps) {
|
|
|
1039
1059
|
position += item[0].toNumber();
|
|
1040
1060
|
}
|
|
1041
1061
|
else {
|
|
1042
|
-
|
|
1043
|
-
if (existingPinIds.indexOf(itemValue) !== -1) {
|
|
1062
|
+
if (existingPinIds.find(id => id.equals(item))) {
|
|
1044
1063
|
result.push({
|
|
1045
|
-
pinId:
|
|
1064
|
+
pinId: item,
|
|
1046
1065
|
side: useSide,
|
|
1047
1066
|
position,
|
|
1048
1067
|
order: counter
|
package/dist/cjs/export.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SExpObject = exports._id = exports.IdObject = exports.printTree = exports.
|
|
3
|
+
exports.SExpObject = exports._id = exports.IdObject = exports.printTree = exports.generateKiCadNetList = void 0;
|
|
4
4
|
const globals_js_1 = require("./globals.js");
|
|
5
5
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
6
|
-
function
|
|
6
|
+
function generateKiCadNetList(netlist) {
|
|
7
7
|
const componentsList = [];
|
|
8
8
|
const nets = {};
|
|
9
9
|
const missingFootprints = [];
|
|
@@ -81,7 +81,7 @@ function generateKiCADNetList(netlist) {
|
|
|
81
81
|
missingFootprints
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
exports.
|
|
84
|
+
exports.generateKiCadNetList = generateKiCadNetList;
|
|
85
85
|
function printTree(tree, level = 0) {
|
|
86
86
|
const output = [];
|
|
87
87
|
if (!Array.isArray(tree)) {
|
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/helpers.js
CHANGED
|
@@ -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.getPaperSize = exports.isSupportedPaperSize = exports.PaperGridReferences = exports.pxToMM = exports.milsToMM = exports.UnitDimension = exports.detectJSModuleType = exports.renderScript = exports.validateScript = exports.ParseErrorStrategy = exports.getSemanticTokens = exports.prepareFile = exports.JSModuleType = void 0;
|
|
6
|
+
exports.getPaperSize = exports.isSupportedPaperSize = exports.PaperGridReferences = exports.pxToMM = exports.milsToMM = exports.UnitDimension = exports.detectJSModuleType = exports.KiCadNetListOutputHandler = exports.ParseOutputHandler = exports.renderScriptCustom = exports.renderScript = exports.validateScript = exports.ParseErrorStrategy = exports.getSemanticTokens = exports.prepareFile = exports.JSModuleType = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const pdfkit_1 = __importDefault(require("pdfkit"));
|
|
@@ -158,6 +158,13 @@ async function validateScript(filePath, scriptData, options) {
|
|
|
158
158
|
}
|
|
159
159
|
exports.validateScript = validateScript;
|
|
160
160
|
async function renderScript(scriptData, outputPath, options) {
|
|
161
|
+
const parseHandlers = [
|
|
162
|
+
new KiCadNetListOutputHandler(),
|
|
163
|
+
];
|
|
164
|
+
return renderScriptCustom(scriptData, outputPath, options, parseHandlers);
|
|
165
|
+
}
|
|
166
|
+
exports.renderScript = renderScript;
|
|
167
|
+
async function renderScriptCustom(scriptData, outputPath, options, parseHandlers) {
|
|
161
168
|
const { dumpNets = false, dumpData = false, showStats = false, environment } = options;
|
|
162
169
|
const errors = [];
|
|
163
170
|
const onErrorHandler = (message, context, error) => {
|
|
@@ -206,6 +213,12 @@ async function renderScript(scriptData, outputPath, options) {
|
|
|
206
213
|
(0, utils_js_1.printWarnings)(visitor.getWarnings());
|
|
207
214
|
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
208
215
|
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
216
|
+
try {
|
|
217
|
+
visitor.annotateComponents();
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
throw new utils_js_1.RenderError(`Error during component annotation: ${err}`, 'annotation');
|
|
221
|
+
}
|
|
209
222
|
if (dumpNets) {
|
|
210
223
|
const nets = visitor.dumpNets();
|
|
211
224
|
nets.forEach(item => console.log(item.join(" | ")));
|
|
@@ -218,12 +231,6 @@ async function renderScript(scriptData, outputPath, options) {
|
|
|
218
231
|
let svgOutput = "";
|
|
219
232
|
if (errors.length === 0) {
|
|
220
233
|
const { frameComponent } = visitor.applySheetFrameComponent();
|
|
221
|
-
try {
|
|
222
|
-
visitor.annotateComponents();
|
|
223
|
-
}
|
|
224
|
-
catch (err) {
|
|
225
|
-
throw new utils_js_1.RenderError(`Error during component annotation: ${err}`, 'annotation');
|
|
226
|
-
}
|
|
227
234
|
const { sequence, nets } = visitor.getGraph();
|
|
228
235
|
const tmpSequence = (0, utils_js_1.generateDebugSequenceAction)(sequence).map(item => (0, utils_js_1.sequenceActionString)(item));
|
|
229
236
|
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-sequence.txt', tmpSequence.join('\n'));
|
|
@@ -232,21 +239,18 @@ async function renderScript(scriptData, outputPath, options) {
|
|
|
232
239
|
let outputDefaultZoom = globals_js_1.defaultZoomScale;
|
|
233
240
|
if (outputPath) {
|
|
234
241
|
fileExtension = path_1.default.extname(outputPath).substring(1);
|
|
235
|
-
if (fileExtension === "pdf") {
|
|
236
|
-
outputDefaultZoom = 1;
|
|
237
|
-
}
|
|
238
242
|
}
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
243
|
+
for (let i = 0; i < parseHandlers.length; i++) {
|
|
244
|
+
const handler = parseHandlers[i];
|
|
245
|
+
if (handler.beforeRender) {
|
|
246
|
+
const keepParsing = handler.parse(visitor, outputPath, fileExtension);
|
|
247
|
+
if (!keepParsing) {
|
|
248
|
+
return {
|
|
249
|
+
svgOutput: null,
|
|
250
|
+
errors
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
250
254
|
}
|
|
251
255
|
const logger = new logger_js_1.Logger();
|
|
252
256
|
const graphEngine = new graph_js_1.NetGraph(logger);
|
|
@@ -275,6 +279,9 @@ async function renderScript(scriptData, outputPath, options) {
|
|
|
275
279
|
showStats && console.log('Render took:', generateSvgTimer.lap());
|
|
276
280
|
dumpData && (0, fs_1.writeFileSync)(dumpDirectory + 'raw-render.txt', renderLogger.dump());
|
|
277
281
|
try {
|
|
282
|
+
if (fileExtension === "pdf") {
|
|
283
|
+
outputDefaultZoom = 1;
|
|
284
|
+
}
|
|
278
285
|
svgOutput = (0, render_js_1.generateSvgOutput)(svgCanvas, outputDefaultZoom);
|
|
279
286
|
}
|
|
280
287
|
catch (err) {
|
|
@@ -325,7 +332,33 @@ async function renderScript(scriptData, outputPath, options) {
|
|
|
325
332
|
errors
|
|
326
333
|
};
|
|
327
334
|
}
|
|
328
|
-
exports.
|
|
335
|
+
exports.renderScriptCustom = renderScriptCustom;
|
|
336
|
+
class ParseOutputHandler {
|
|
337
|
+
constructor() {
|
|
338
|
+
this.beforeRender = false;
|
|
339
|
+
this.afterRender = false;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
exports.ParseOutputHandler = ParseOutputHandler;
|
|
343
|
+
class KiCadNetListOutputHandler extends ParseOutputHandler {
|
|
344
|
+
constructor() {
|
|
345
|
+
super(...arguments);
|
|
346
|
+
this.beforeRender = true;
|
|
347
|
+
}
|
|
348
|
+
parse(visitor, outputPath, fileExtension) {
|
|
349
|
+
if (outputPath !== null && fileExtension === "net") {
|
|
350
|
+
const { tree: kiCadNetList, missingFootprints } = (0, export_js_1.generateKiCadNetList)(visitor.getNetList());
|
|
351
|
+
missingFootprints.forEach(entry => {
|
|
352
|
+
console.log(`${entry.refdes} (${entry.instanceName}) does not have footprint`);
|
|
353
|
+
});
|
|
354
|
+
(0, fs_1.writeFileSync)(outputPath, (0, export_js_1.printTree)(kiCadNetList));
|
|
355
|
+
console.log('Generated file', outputPath);
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
exports.KiCadNetListOutputHandler = KiCadNetListOutputHandler;
|
|
329
362
|
function detectJSModuleType() {
|
|
330
363
|
if (typeof __filename === 'undefined' &&
|
|
331
364
|
typeof __dirname === 'undefined') {
|
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;
|