circuitscript 0.0.29 → 0.0.32
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 +6 -1
- package/dist/cjs/antlr/CircuitScriptLexer.js +204 -200
- package/dist/cjs/antlr/CircuitScriptParser.js +1066 -1173
- package/dist/cjs/draw_symbols.js +330 -87
- package/dist/cjs/execute.js +41 -14
- package/dist/cjs/geometry.js +79 -18
- package/dist/cjs/globals.js +37 -6
- package/dist/cjs/helpers.js +75 -5
- package/dist/cjs/layout.js +107 -43
- package/dist/cjs/main.js +10 -4
- package/dist/cjs/objects/ClassComponent.js +2 -0
- package/dist/cjs/objects/ExecutionScope.js +1 -1
- package/dist/cjs/objects/Frame.js +2 -0
- package/dist/cjs/objects/Net.js +3 -2
- package/dist/cjs/objects/PinTypes.js +7 -1
- package/dist/cjs/objects/types.js +11 -1
- package/dist/cjs/regenerate-tests.js +64 -3
- package/dist/cjs/render.js +29 -21
- package/dist/cjs/sizing.js +4 -6
- package/dist/cjs/utils.js +29 -5
- package/dist/cjs/visitor.js +176 -10
- package/dist/esm/BaseVisitor.mjs +6 -1
- package/dist/esm/antlr/CircuitScriptLexer.mjs +204 -200
- package/dist/esm/antlr/CircuitScriptParser.mjs +1061 -1171
- package/dist/esm/antlr/CircuitScriptVisitor.mjs +3 -0
- package/dist/esm/draw_symbols.mjs +324 -85
- package/dist/esm/execute.mjs +42 -15
- package/dist/esm/geometry.mjs +79 -17
- package/dist/esm/globals.mjs +36 -5
- package/dist/esm/helpers.mjs +74 -5
- package/dist/esm/layout.mjs +110 -46
- package/dist/esm/main.mjs +11 -5
- package/dist/esm/objects/ClassComponent.mjs +6 -0
- package/dist/esm/objects/ExecutionScope.mjs +1 -1
- package/dist/esm/objects/Frame.mjs +2 -0
- package/dist/esm/objects/Net.mjs +3 -2
- package/dist/esm/objects/PinTypes.mjs +6 -0
- package/dist/esm/objects/types.mjs +14 -0
- package/dist/esm/regenerate-tests.mjs +64 -3
- package/dist/esm/render.mjs +30 -22
- package/dist/esm/sizing.mjs +3 -4
- package/dist/esm/utils.mjs +26 -4
- package/dist/esm/visitor.mjs +179 -13
- package/dist/types/antlr/CircuitScriptLexer.d.ts +42 -41
- package/dist/types/antlr/CircuitScriptParser.d.ts +144 -133
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -0
- package/dist/types/draw_symbols.d.ts +15 -2
- package/dist/types/execute.d.ts +5 -4
- package/dist/types/geometry.d.ts +4 -3
- package/dist/types/globals.d.ts +32 -3
- package/dist/types/helpers.d.ts +12 -0
- package/dist/types/layout.d.ts +8 -2
- package/dist/types/objects/ClassComponent.d.ts +8 -0
- package/dist/types/objects/Frame.d.ts +3 -1
- package/dist/types/objects/PinTypes.d.ts +1 -0
- package/dist/types/objects/Wire.d.ts +4 -2
- package/dist/types/objects/types.d.ts +8 -0
- package/dist/types/render.d.ts +5 -1
- package/dist/types/sizing.d.ts +0 -4
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/visitor.d.ts +8 -1
- package/fonts/Arial.ttf +0 -0
- package/libs/lib.cst +58 -41
- package/package.json +5 -1
package/dist/cjs/layout.js
CHANGED
|
@@ -11,11 +11,15 @@ const logger_js_1 = require("./logger.js");
|
|
|
11
11
|
const Frame_js_1 = require("./objects/Frame.js");
|
|
12
12
|
const utils_js_1 = require("./utils.js");
|
|
13
13
|
const types_js_1 = require("./objects/types.js");
|
|
14
|
+
const helpers_js_1 = require("./helpers.js");
|
|
14
15
|
class LayoutEngine {
|
|
15
|
-
constructor() {
|
|
16
|
+
constructor(options = { showBaseFrame: false }) {
|
|
16
17
|
this.placeSubgraphVersion = 2;
|
|
17
18
|
this.layoutWarnings = [];
|
|
19
|
+
this.showBaseFrame = false;
|
|
18
20
|
this.logger = new logger_js_1.Logger();
|
|
21
|
+
const { showBaseFrame = false } = options ?? {};
|
|
22
|
+
this.showBaseFrame = showBaseFrame;
|
|
19
23
|
}
|
|
20
24
|
print(...params) {
|
|
21
25
|
this.logger.add(params.join(' '));
|
|
@@ -123,6 +127,11 @@ class LayoutEngine {
|
|
|
123
127
|
const baseFrame = frameObjects[0];
|
|
124
128
|
baseFrame.padding = 0;
|
|
125
129
|
baseFrame.borderWidth = 0;
|
|
130
|
+
if (this.showBaseFrame) {
|
|
131
|
+
baseFrame.borderWidth = 5;
|
|
132
|
+
baseFrame.width = 11692 - 400 * 2;
|
|
133
|
+
baseFrame.height = 8267 - 400 * 2;
|
|
134
|
+
}
|
|
126
135
|
baseFrame.x = 0;
|
|
127
136
|
baseFrame.y = 0;
|
|
128
137
|
let textObjects = [];
|
|
@@ -135,7 +144,7 @@ class LayoutEngine {
|
|
|
135
144
|
const result = this.prepareFrames(graph, subgraphInfo, baseFrame);
|
|
136
145
|
textObjects = result.textObjects;
|
|
137
146
|
elementFrames = result.elementFrames;
|
|
138
|
-
const logFrames =
|
|
147
|
+
const logFrames = true;
|
|
139
148
|
if (logFrames) {
|
|
140
149
|
this.print('===== dump frames =====');
|
|
141
150
|
this.dumpFrame(baseFrame);
|
|
@@ -186,7 +195,7 @@ class LayoutEngine {
|
|
|
186
195
|
}
|
|
187
196
|
placeAndSizeFrame(frame, level = 0) {
|
|
188
197
|
const innerFrames = frame.innerItems;
|
|
189
|
-
const gridSize =
|
|
198
|
+
const gridSize = globals_js_1.defaultGridSizeUnits;
|
|
190
199
|
let accumX = 0;
|
|
191
200
|
let accumY = 0;
|
|
192
201
|
const boundPoints = [];
|
|
@@ -259,6 +268,12 @@ class LayoutEngine {
|
|
|
259
268
|
boundPoints.push([innerFrame.x, innerFrame.y], [innerFrame.x + frameWidth, innerFrame.y + frameHeight]);
|
|
260
269
|
});
|
|
261
270
|
frame.bounds = (0, utils_js_1.resizeBounds)(getBoundsFromPoints(boundPoints), frame.padding);
|
|
271
|
+
if (frame.width !== null) {
|
|
272
|
+
frame.bounds.xmax = (0, helpers_js_1.milsToMM)(frame.bounds.xmin + frame.width);
|
|
273
|
+
}
|
|
274
|
+
if (frame.height !== null) {
|
|
275
|
+
frame.bounds.ymax = (0, helpers_js_1.milsToMM)(frame.bounds.ymin + frame.height);
|
|
276
|
+
}
|
|
262
277
|
}
|
|
263
278
|
dumpFrame(frame, level = 0) {
|
|
264
279
|
this.print(level, "".padStart(level * 4), 'frame, items:', frame.innerItems.length);
|
|
@@ -326,7 +341,7 @@ class LayoutEngine {
|
|
|
326
341
|
tmpFrame.containsTitle = true;
|
|
327
342
|
tmpFrame.subgraphId = title.replace(/\s/g, "_");
|
|
328
343
|
const textObject = new RenderText(title);
|
|
329
|
-
textObject.fontSize =
|
|
344
|
+
textObject.fontSize = globals_js_1.defaultFrameTitleTextSize;
|
|
330
345
|
textObject.fontWeight = 'bold';
|
|
331
346
|
textObject.symbol.refreshDrawing();
|
|
332
347
|
tmpFrame.innerItems.push(textObject);
|
|
@@ -388,7 +403,12 @@ class LayoutEngine {
|
|
|
388
403
|
}
|
|
389
404
|
else {
|
|
390
405
|
const symbolPinDefinitions = generateLayoutPinDefinition(component);
|
|
391
|
-
|
|
406
|
+
if (component.typeProp === 'module') {
|
|
407
|
+
tmpSymbol = new draw_symbols_js_1.SymbolCustomModule(symbolPinDefinitions);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions);
|
|
411
|
+
}
|
|
392
412
|
}
|
|
393
413
|
applyComponentParamsToSymbol(typeProp, component, tmpSymbol);
|
|
394
414
|
let didSetAngle = false;
|
|
@@ -405,7 +425,7 @@ class LayoutEngine {
|
|
|
405
425
|
component.parameters.get('flipY');
|
|
406
426
|
}
|
|
407
427
|
if (tmpSymbol instanceof draw_symbols_js_1.SymbolCustom && widthProp) {
|
|
408
|
-
tmpSymbol.bodyWidth = widthProp;
|
|
428
|
+
tmpSymbol.bodyWidth = (0, helpers_js_1.milsToMM)(widthProp);
|
|
409
429
|
}
|
|
410
430
|
if (!didSetAngle && component.parameters.has('_addDirection')) {
|
|
411
431
|
tmpSymbol.refreshDrawing(false);
|
|
@@ -491,6 +511,14 @@ class LayoutEngine {
|
|
|
491
511
|
newFrame.borderWidth =
|
|
492
512
|
frameObject.parameters.get(Frame_js_1.FrameParamKeys.Border);
|
|
493
513
|
}
|
|
514
|
+
if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Width)) {
|
|
515
|
+
newFrame.width =
|
|
516
|
+
frameObject.parameters.get(Frame_js_1.FrameParamKeys.Width);
|
|
517
|
+
}
|
|
518
|
+
if (frameObject.parameters.has(Frame_js_1.FrameParamKeys.Height)) {
|
|
519
|
+
newFrame.height =
|
|
520
|
+
frameObject.parameters.get(Frame_js_1.FrameParamKeys.Height);
|
|
521
|
+
}
|
|
494
522
|
containerFrames.push(newFrame);
|
|
495
523
|
frameStack.push(newFrame);
|
|
496
524
|
prevFrame && prevFrame.innerItems.push(newFrame);
|
|
@@ -586,6 +614,10 @@ class LayoutEngine {
|
|
|
586
614
|
this.placeNodeAtPosition(0, 0, node1, 1);
|
|
587
615
|
return;
|
|
588
616
|
}
|
|
617
|
+
let fixedNode;
|
|
618
|
+
let fixedNodePin;
|
|
619
|
+
let floatingNode;
|
|
620
|
+
let floatingNodePin;
|
|
589
621
|
subgraphEdges.forEach(edge => {
|
|
590
622
|
const [nodeId1, pin1, nodeId2, pin2] = graph.edge(edge);
|
|
591
623
|
const [, node1] = graph.node(nodeId1);
|
|
@@ -598,10 +630,6 @@ class LayoutEngine {
|
|
|
598
630
|
originNodes.push(node1);
|
|
599
631
|
originNodeGroups.set(node1.toString(), [node1]);
|
|
600
632
|
}
|
|
601
|
-
let fixedNode;
|
|
602
|
-
let fixedNodePin;
|
|
603
|
-
let floatingNode;
|
|
604
|
-
let floatingNodePin;
|
|
605
633
|
this.print('edge:', '[', node1, pin1, node1.isFloating, ']', '[', node2, pin2, node2.isFloating, ']');
|
|
606
634
|
if (!node1.isFloating && node2.isFloating) {
|
|
607
635
|
fixedNode = node1;
|
|
@@ -652,19 +680,31 @@ class LayoutEngine {
|
|
|
652
680
|
floatingNode.isFloating = false;
|
|
653
681
|
this.print('set node as not floating:', floatingNode);
|
|
654
682
|
const originNode = findOriginNode(fixedNode);
|
|
655
|
-
originNodeGroups.get(originNode)
|
|
656
|
-
|
|
683
|
+
const itemsArray = originNodeGroups.get(originNode);
|
|
684
|
+
if (itemsArray.indexOf(floatingNode) === -1) {
|
|
685
|
+
itemsArray.push(floatingNode);
|
|
686
|
+
this.print('linking node', floatingNode, 'to origin node', originNode);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
this.print('node is alread linked', floatingNode, 'to origin node', originNode);
|
|
690
|
+
}
|
|
657
691
|
}
|
|
658
692
|
[node1, node2].forEach(item => {
|
|
659
693
|
if (item instanceof RenderWire && item.isEndAutoLength()) {
|
|
660
|
-
this.print('auto length wire', item);
|
|
661
694
|
const [instance, pin] = item.getEndAuto();
|
|
662
695
|
const [, targetNode] = graph.node(instance.instanceName);
|
|
696
|
+
this.print('wire', item, 'auto length to target:', instance, pin);
|
|
663
697
|
if (targetNode.isFloating) {
|
|
664
698
|
throw "Cannot create auto wire with floating node! Wire id: " + item.id + " to node " + instance + " pin " + pin;
|
|
665
699
|
}
|
|
700
|
+
const targetOriginNode = findOriginNode(targetNode);
|
|
701
|
+
const itemOriginNode = findOriginNode(item);
|
|
702
|
+
if (targetOriginNode !== itemOriginNode) {
|
|
703
|
+
throw "Wire auto length failed. Please specify a fixed wire length.";
|
|
704
|
+
}
|
|
666
705
|
const [untilX, untilY] = getNodePositionAtPin(targetNode, pin);
|
|
667
706
|
item.setEndAuto(untilX, untilY);
|
|
707
|
+
this.print(`set wire auto end at: ${untilX} ${untilY}`);
|
|
668
708
|
}
|
|
669
709
|
});
|
|
670
710
|
});
|
|
@@ -827,25 +867,27 @@ class LayoutEngine {
|
|
|
827
867
|
}
|
|
828
868
|
exports.LayoutEngine = LayoutEngine;
|
|
829
869
|
function getNodePositionAtPin(item, pin) {
|
|
870
|
+
let x = 0;
|
|
871
|
+
let y = 0;
|
|
830
872
|
if (item instanceof RenderComponent) {
|
|
831
873
|
const pinPosition = item.symbol.pinPosition(pin);
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
item.y + pinPosition.y
|
|
835
|
-
];
|
|
874
|
+
x = item.x + pinPosition.x;
|
|
875
|
+
y = item.y + pinPosition.y;
|
|
836
876
|
}
|
|
837
877
|
else if (item instanceof RenderWire) {
|
|
838
878
|
if (pin === 0) {
|
|
839
|
-
|
|
879
|
+
x = item.x;
|
|
880
|
+
y = item.y;
|
|
840
881
|
}
|
|
841
882
|
else {
|
|
842
883
|
const wireEnd = item.getWireEnd();
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
item.y + wireEnd.y
|
|
846
|
-
];
|
|
884
|
+
x = item.x + wireEnd.x;
|
|
885
|
+
y = item.y + wireEnd.y;
|
|
847
886
|
}
|
|
848
887
|
}
|
|
888
|
+
return [
|
|
889
|
+
(0, utils_js_1.roundValue)(x), (0, utils_js_1.roundValue)(y)
|
|
890
|
+
];
|
|
849
891
|
}
|
|
850
892
|
function getNeighbours(graph, nodeIds) {
|
|
851
893
|
return nodeIds.reduce((accum, nodeId) => {
|
|
@@ -871,11 +913,13 @@ function generateLayoutPinDefinition(component) {
|
|
|
871
913
|
if (component.arrangeProps === null) {
|
|
872
914
|
for (let i = 0; i < existingPinIds.length; i++) {
|
|
873
915
|
const pinPosition = Math.floor(i / 2);
|
|
916
|
+
const pin = pins.get(existingPinIds[i]);
|
|
874
917
|
symbolPinDefinitions.push({
|
|
875
918
|
side: (i % 2 === 0) ? "left" : "right",
|
|
876
919
|
pinId: existingPinIds[i],
|
|
877
|
-
text:
|
|
920
|
+
text: pin.name,
|
|
878
921
|
position: pinPosition,
|
|
922
|
+
pinType: pin.pinType,
|
|
879
923
|
});
|
|
880
924
|
}
|
|
881
925
|
}
|
|
@@ -891,11 +935,13 @@ function generateLayoutPinDefinition(component) {
|
|
|
891
935
|
}
|
|
892
936
|
useItems.forEach(pinId => {
|
|
893
937
|
if (existingPinIds.indexOf(pinId) !== -1) {
|
|
938
|
+
const pin = pins.get(pinId);
|
|
894
939
|
symbolPinDefinitions.push({
|
|
895
940
|
side: key,
|
|
896
941
|
pinId: pinId,
|
|
897
|
-
text:
|
|
898
|
-
position:
|
|
942
|
+
text: pin.name,
|
|
943
|
+
position: pin.position,
|
|
944
|
+
pinType: pin.pinType,
|
|
899
945
|
});
|
|
900
946
|
addedPins.push(pinId);
|
|
901
947
|
}
|
|
@@ -1018,19 +1064,26 @@ class RenderWire extends RenderObject {
|
|
|
1018
1064
|
this.segments.forEach(segment => {
|
|
1019
1065
|
const { direction, value } = segment;
|
|
1020
1066
|
let didAddPoint = false;
|
|
1067
|
+
let useValue;
|
|
1068
|
+
if (value instanceof helpers_js_1.UnitDimension) {
|
|
1069
|
+
useValue = value.getMM();
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
useValue = value;
|
|
1073
|
+
}
|
|
1021
1074
|
if (direction === types_js_1.Direction.Down) {
|
|
1022
|
-
tmpY +=
|
|
1075
|
+
tmpY += useValue;
|
|
1023
1076
|
}
|
|
1024
1077
|
else if (direction === types_js_1.Direction.Up) {
|
|
1025
|
-
tmpY -=
|
|
1078
|
+
tmpY -= useValue;
|
|
1026
1079
|
}
|
|
1027
1080
|
else if (direction === types_js_1.Direction.Left) {
|
|
1028
|
-
tmpX -=
|
|
1081
|
+
tmpX -= useValue;
|
|
1029
1082
|
}
|
|
1030
1083
|
else if (direction === types_js_1.Direction.Right) {
|
|
1031
|
-
tmpX +=
|
|
1084
|
+
tmpX += useValue;
|
|
1032
1085
|
}
|
|
1033
|
-
else if (direction ===
|
|
1086
|
+
else if (direction === globals_js_1.WireAutoDirection.Auto || direction === globals_js_1.WireAutoDirection.Auto_) {
|
|
1034
1087
|
const { valueXY = [0, 0] } = segment;
|
|
1035
1088
|
const tmpPoints = this.getAutoPoints(valueXY, direction);
|
|
1036
1089
|
tmpPoints.forEach(point => {
|
|
@@ -1049,9 +1102,11 @@ class RenderWire extends RenderObject {
|
|
|
1049
1102
|
this.points = points;
|
|
1050
1103
|
}
|
|
1051
1104
|
getAutoPoints(value, direction) {
|
|
1052
|
-
const
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1105
|
+
const valueX = (0, utils_js_1.roundValue)(value[0]);
|
|
1106
|
+
const valueY = (0, utils_js_1.roundValue)(value[1]);
|
|
1107
|
+
const inQuadrant = geometry_js_1.Geometry.getQuadrant(valueX, valueY);
|
|
1108
|
+
const [dx, dy] = [valueX, valueY];
|
|
1109
|
+
if (direction === globals_js_1.WireAutoDirection.Auto) {
|
|
1055
1110
|
switch (inQuadrant) {
|
|
1056
1111
|
case 0:
|
|
1057
1112
|
case 2:
|
|
@@ -1061,7 +1116,7 @@ class RenderWire extends RenderObject {
|
|
|
1061
1116
|
return [[0, dy], [dx, 0]];
|
|
1062
1117
|
}
|
|
1063
1118
|
}
|
|
1064
|
-
else if (direction ===
|
|
1119
|
+
else if (direction === globals_js_1.WireAutoDirection.Auto_) {
|
|
1065
1120
|
switch (inQuadrant) {
|
|
1066
1121
|
case 0:
|
|
1067
1122
|
case 2:
|
|
@@ -1096,17 +1151,24 @@ class RenderWire extends RenderObject {
|
|
|
1096
1151
|
let tmpY = this.y;
|
|
1097
1152
|
excludeLastSegment.forEach(segment => {
|
|
1098
1153
|
const { direction, value } = segment;
|
|
1154
|
+
let useValue;
|
|
1155
|
+
if (value instanceof helpers_js_1.UnitDimension) {
|
|
1156
|
+
useValue = value.getMM();
|
|
1157
|
+
}
|
|
1158
|
+
else {
|
|
1159
|
+
useValue = value;
|
|
1160
|
+
}
|
|
1099
1161
|
if (direction === types_js_1.Direction.Down) {
|
|
1100
|
-
tmpY +=
|
|
1162
|
+
tmpY += useValue;
|
|
1101
1163
|
}
|
|
1102
1164
|
else if (direction === types_js_1.Direction.Up) {
|
|
1103
|
-
tmpY -=
|
|
1165
|
+
tmpY -= useValue;
|
|
1104
1166
|
}
|
|
1105
1167
|
else if (direction === types_js_1.Direction.Left) {
|
|
1106
|
-
tmpX -=
|
|
1168
|
+
tmpX -= useValue;
|
|
1107
1169
|
}
|
|
1108
1170
|
else if (direction === types_js_1.Direction.Right) {
|
|
1109
|
-
tmpX +=
|
|
1171
|
+
tmpX += useValue;
|
|
1110
1172
|
}
|
|
1111
1173
|
});
|
|
1112
1174
|
let useValue = null;
|
|
@@ -1125,8 +1187,8 @@ class RenderWire extends RenderObject {
|
|
|
1125
1187
|
case types_js_1.Direction.Down:
|
|
1126
1188
|
useValue = tmpY - untilY;
|
|
1127
1189
|
break;
|
|
1128
|
-
case
|
|
1129
|
-
case
|
|
1190
|
+
case globals_js_1.WireAutoDirection.Auto:
|
|
1191
|
+
case globals_js_1.WireAutoDirection.Auto_:
|
|
1130
1192
|
valueXY = [
|
|
1131
1193
|
untilX - tmpX,
|
|
1132
1194
|
untilY - tmpY,
|
|
@@ -1193,10 +1255,12 @@ class RenderFrame extends RenderObject {
|
|
|
1193
1255
|
this.innerItems = [];
|
|
1194
1256
|
this.translateX = 0;
|
|
1195
1257
|
this.translateY = 0;
|
|
1196
|
-
this.padding =
|
|
1197
|
-
this.gap =
|
|
1258
|
+
this.padding = (0, helpers_js_1.milsToMM)(100);
|
|
1259
|
+
this.gap = (0, helpers_js_1.milsToMM)(100);
|
|
1198
1260
|
this.direction = Frame_js_1.FramePlotDirection.Column;
|
|
1199
|
-
this.borderWidth =
|
|
1261
|
+
this.borderWidth = 5;
|
|
1262
|
+
this.width = null;
|
|
1263
|
+
this.height = null;
|
|
1200
1264
|
this.subgraphId = "";
|
|
1201
1265
|
this.containsTitle = false;
|
|
1202
1266
|
this.frame = frame;
|
package/dist/cjs/main.js
CHANGED
|
@@ -52,16 +52,22 @@ async function main() {
|
|
|
52
52
|
let scriptData;
|
|
53
53
|
if (args.length > 0 && args[0]) {
|
|
54
54
|
inputFilePath = args[0];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
currentDirectory
|
|
55
|
+
if ((0, fs_1.existsSync)(inputFilePath)) {
|
|
56
|
+
scriptData = (0, fs_1.readFileSync)(inputFilePath, { encoding: 'utf-8' });
|
|
57
|
+
if (currentDirectory === null) {
|
|
58
|
+
currentDirectory = path_1.default.dirname(inputFilePath);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.error("Error: File could not be found");
|
|
63
|
+
return;
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
else if (options.input) {
|
|
61
67
|
scriptData = options.input;
|
|
62
68
|
}
|
|
63
69
|
else {
|
|
64
|
-
console.
|
|
70
|
+
console.error("Error: No input provided");
|
|
65
71
|
return;
|
|
66
72
|
}
|
|
67
73
|
const scriptOptions = {
|
|
@@ -21,8 +21,10 @@ class ClassComponent {
|
|
|
21
21
|
this.followWireOrientationProp = true;
|
|
22
22
|
this.wireOrientationAngle = 0;
|
|
23
23
|
this.useWireOrientationAngle = true;
|
|
24
|
+
this.didSetWireOrientationAngle = false;
|
|
24
25
|
this.styles = {};
|
|
25
26
|
this.assignedRefDes = null;
|
|
27
|
+
this.moduleCounter = 0;
|
|
26
28
|
this.instanceName = instanceName;
|
|
27
29
|
this.numPins = numPins;
|
|
28
30
|
this.className = className;
|
|
@@ -14,6 +14,8 @@ var FrameParamKeys;
|
|
|
14
14
|
FrameParamKeys["Direction"] = "direction";
|
|
15
15
|
FrameParamKeys["Padding"] = "padding";
|
|
16
16
|
FrameParamKeys["Border"] = "border";
|
|
17
|
+
FrameParamKeys["Width"] = "width";
|
|
18
|
+
FrameParamKeys["Height"] = "height";
|
|
17
19
|
})(FrameParamKeys || (exports.FrameParamKeys = FrameParamKeys = {}));
|
|
18
20
|
var FramePlotDirection;
|
|
19
21
|
(function (FramePlotDirection) {
|
package/dist/cjs/objects/Net.js
CHANGED
|
@@ -16,10 +16,11 @@ class Net {
|
|
|
16
16
|
this.baseName = name;
|
|
17
17
|
}
|
|
18
18
|
toString() {
|
|
19
|
-
return this.name;
|
|
19
|
+
return this.namespace + this.name;
|
|
20
20
|
}
|
|
21
21
|
static isSame(netA, netB) {
|
|
22
|
-
return netA.
|
|
22
|
+
return netA.namespace === netB.namespace &&
|
|
23
|
+
netA.name === netB.name &&
|
|
23
24
|
netA.baseName === netB.baseName &&
|
|
24
25
|
netA.priority === netB.priority &&
|
|
25
26
|
netA.type === netB.type;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PinTypes = void 0;
|
|
3
|
+
exports.AllPinTypes = exports.PinTypes = void 0;
|
|
4
4
|
var PinTypes;
|
|
5
5
|
(function (PinTypes) {
|
|
6
6
|
PinTypes["Any"] = "any";
|
|
@@ -9,3 +9,9 @@ var PinTypes;
|
|
|
9
9
|
PinTypes["IO"] = "io";
|
|
10
10
|
PinTypes["Power"] = "power";
|
|
11
11
|
})(PinTypes || (exports.PinTypes = PinTypes = {}));
|
|
12
|
+
exports.AllPinTypes = [
|
|
13
|
+
PinTypes.Any,
|
|
14
|
+
PinTypes.Input,
|
|
15
|
+
PinTypes.Output,
|
|
16
|
+
PinTypes.IO,
|
|
17
|
+
];
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Direction = exports.ParseSymbolType = exports.UndeclaredReference = void 0;
|
|
3
|
+
exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = void 0;
|
|
4
4
|
class UndeclaredReference {
|
|
5
5
|
constructor(reference) {
|
|
6
6
|
this.reference = reference;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
exports.UndeclaredReference = UndeclaredReference;
|
|
10
|
+
class DeclaredReference {
|
|
11
|
+
constructor(refType) {
|
|
12
|
+
this.found = refType.found;
|
|
13
|
+
this.name = refType.name;
|
|
14
|
+
this.trailers = refType.trailers;
|
|
15
|
+
this.type = refType.type;
|
|
16
|
+
this.value = refType.value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DeclaredReference = DeclaredReference;
|
|
10
20
|
var ParseSymbolType;
|
|
11
21
|
(function (ParseSymbolType) {
|
|
12
22
|
ParseSymbolType["Variable"] = "variable";
|
|
@@ -9,7 +9,7 @@ const sizing_js_1 = require("./sizing.js");
|
|
|
9
9
|
const mainDir = './__tests__/renderData/';
|
|
10
10
|
const fontsPath = (0, helpers_js_1.getFontsPath)();
|
|
11
11
|
const defaultLibsPath = (0, helpers_js_1.getDefaultLibsPath)();
|
|
12
|
-
async function regenerateTests() {
|
|
12
|
+
async function regenerateTests(extra = "") {
|
|
13
13
|
await (0, sizing_js_1.prepareSVGEnvironment)(fontsPath);
|
|
14
14
|
const cstFiles = [];
|
|
15
15
|
const files = fs_1.default.readdirSync(mainDir);
|
|
@@ -21,12 +21,73 @@ async function regenerateTests() {
|
|
|
21
21
|
cstFiles.forEach(file => {
|
|
22
22
|
const inputPath = mainDir + file;
|
|
23
23
|
const scriptData = fs_1.default.readFileSync(inputPath, { encoding: 'utf-8' });
|
|
24
|
-
const outputPath =
|
|
24
|
+
const outputPath = mainDir + 'svgs/' + file + extra + '.svg';
|
|
25
25
|
(0, helpers_js_1.renderScript)(scriptData, outputPath, {
|
|
26
26
|
currentDirectory: mainDir,
|
|
27
27
|
defaultLibsPath,
|
|
28
28
|
});
|
|
29
29
|
console.log('generated ', outputPath);
|
|
30
30
|
});
|
|
31
|
+
return cstFiles;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
(async () => {
|
|
34
|
+
const generateDiff = false;
|
|
35
|
+
const nextExtra = generateDiff ? '.next' : '';
|
|
36
|
+
const cstFiles = await regenerateTests(nextExtra);
|
|
37
|
+
const allFiles = [];
|
|
38
|
+
if (generateDiff) {
|
|
39
|
+
cstFiles.forEach(file => {
|
|
40
|
+
const svg1 = 'svgs/' + file + '.svg';
|
|
41
|
+
const svg2 = 'svgs/' + file + '.next.svg';
|
|
42
|
+
const cleanedName = file.replace('script', '').replace('.cst', '');
|
|
43
|
+
allFiles.push([file, svg1, svg2, cleanedName]);
|
|
44
|
+
});
|
|
45
|
+
const sortedFiles = allFiles.sort((a, b) => {
|
|
46
|
+
const nameA = a[3];
|
|
47
|
+
const nameB = b[3];
|
|
48
|
+
const indexA = Number(nameA);
|
|
49
|
+
const indexB = Number(nameB);
|
|
50
|
+
if (indexA > indexB) {
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
else if (indexA < indexB) {
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const output = [];
|
|
61
|
+
sortedFiles.forEach(group => {
|
|
62
|
+
const [file, svg1, svg2] = group;
|
|
63
|
+
output.push(`<div class='group'>
|
|
64
|
+
<h3>${file}</h3>
|
|
65
|
+
<div class='items'>
|
|
66
|
+
<div style='margin-right: 10px'>
|
|
67
|
+
<h4>${svg1}</h4>
|
|
68
|
+
<img src='${svg1}'/>
|
|
69
|
+
</div>
|
|
70
|
+
<div>
|
|
71
|
+
<h4>${svg2}</h4>
|
|
72
|
+
<img src='${svg2}'/>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>`);
|
|
76
|
+
});
|
|
77
|
+
const result = `
|
|
78
|
+
<html>
|
|
79
|
+
<header>
|
|
80
|
+
<title>SVG compare</title>
|
|
81
|
+
<style>
|
|
82
|
+
img { border: solid thin #ccc; }
|
|
83
|
+
.items { display: flex; }
|
|
84
|
+
body { font-family: Arial; }
|
|
85
|
+
</style>
|
|
86
|
+
</header>
|
|
87
|
+
<body>
|
|
88
|
+
${output.join('')}
|
|
89
|
+
</body>
|
|
90
|
+
</html>`;
|
|
91
|
+
fs_1.default.writeFileSync(mainDir + "compiled.html", result);
|
|
92
|
+
}
|
|
93
|
+
})();
|
package/dist/cjs/render.js
CHANGED
|
@@ -7,6 +7,7 @@ const sizing_js_1 = require("./sizing.js");
|
|
|
7
7
|
const globals_js_1 = require("./globals.js");
|
|
8
8
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
9
9
|
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const helpers_js_1 = require("./helpers.js");
|
|
10
11
|
function generateSVG2(graph) {
|
|
11
12
|
const window = (0, sizing_js_1.getCreateSVGWindow)()();
|
|
12
13
|
const document = window.document;
|
|
@@ -14,14 +15,16 @@ function generateSVG2(graph) {
|
|
|
14
15
|
const canvas = (0, svg_js_1.SVG)(document.documentElement);
|
|
15
16
|
(0, sizing_js_1.applyFontsToSVG)(canvas);
|
|
16
17
|
generateSVGChild(canvas, graph.components, graph.wires, graph.junctions, graph.mergedWires, graph.frameObjects, graph.textObjects);
|
|
18
|
+
const scale = globals_js_1.MMToPx * globals_js_1.defaultZoomScale;
|
|
17
19
|
const { x, y, width, height } = canvas.bbox();
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const scaledWidth = width * scale;
|
|
21
|
+
const scaledHeight = height * scale;
|
|
22
|
+
canvas.size(scaledWidth, scaledHeight);
|
|
23
|
+
canvas.viewbox(x, y, width, height);
|
|
24
|
+
return {
|
|
25
|
+
svg: canvas.svg(),
|
|
26
|
+
width, height,
|
|
27
|
+
};
|
|
25
28
|
}
|
|
26
29
|
exports.generateSVG2 = generateSVG2;
|
|
27
30
|
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects) {
|
|
@@ -70,8 +73,8 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
70
73
|
wires.forEach(wire => {
|
|
71
74
|
wiresGroup.text(wire.id.toString())
|
|
72
75
|
.font({
|
|
73
|
-
family: '
|
|
74
|
-
size:
|
|
76
|
+
family: 'Arial',
|
|
77
|
+
size: 50 * globals_js_1.fontDisplayScale,
|
|
75
78
|
})
|
|
76
79
|
.translate(wire.x + 5, wire.y + 5);
|
|
77
80
|
});
|
|
@@ -83,8 +86,11 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
83
86
|
const pt1 = segment[0];
|
|
84
87
|
const pt2 = segment[1];
|
|
85
88
|
mergedWireGroup.line([pt1, pt2])
|
|
86
|
-
.stroke({
|
|
87
|
-
|
|
89
|
+
.stroke({
|
|
90
|
+
width: globals_js_1.defaultWireLineWidth,
|
|
91
|
+
color: globals_js_1.ColorScheme.WireColor,
|
|
92
|
+
linecap: 'square'
|
|
93
|
+
})
|
|
88
94
|
.fill('none');
|
|
89
95
|
});
|
|
90
96
|
intersectPoints.forEach(point => {
|
|
@@ -113,7 +119,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
113
119
|
}
|
|
114
120
|
const tmpRect = frameGroup.rect(width, height)
|
|
115
121
|
.fill('none')
|
|
116
|
-
.stroke({ width: borderWidth, color: strokeColor });
|
|
122
|
+
.stroke({ width: (0, helpers_js_1.milsToMM)(borderWidth), color: strokeColor });
|
|
117
123
|
tmpRect.translate(item.x, item.y);
|
|
118
124
|
}
|
|
119
125
|
});
|
|
@@ -124,13 +130,14 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
124
130
|
symbol.draw(innerGroup);
|
|
125
131
|
});
|
|
126
132
|
const drawOrigin = false;
|
|
133
|
+
const originSize = (0, helpers_js_1.milsToMM)(10);
|
|
127
134
|
drawOrigin && canvas.group().translate(0, 0)
|
|
128
|
-
.circle(
|
|
129
|
-
.translate(-
|
|
135
|
+
.circle(originSize)
|
|
136
|
+
.translate(-originSize / 2, -originSize / 2)
|
|
130
137
|
.stroke('none').fill('red');
|
|
131
138
|
}
|
|
132
139
|
function drawGrid(group, canvasSize) {
|
|
133
|
-
const gridSize =
|
|
140
|
+
const gridSize = globals_js_1.defaultGridSizeUnits;
|
|
134
141
|
const { x, y, x2, y2 } = canvasSize;
|
|
135
142
|
const gridStartX = (Math.floor(x / gridSize) - 1) * gridSize;
|
|
136
143
|
const gridStartY = (Math.floor(y / gridSize) - 1) * gridSize;
|
|
@@ -138,19 +145,20 @@ function drawGrid(group, canvasSize) {
|
|
|
138
145
|
const gridEndY = (Math.ceil(y2 / gridSize) + 1) * gridSize;
|
|
139
146
|
const numCols = Math.ceil((gridEndX - gridStartX) / gridSize);
|
|
140
147
|
const lines = [];
|
|
148
|
+
const smallOffset = (0, helpers_js_1.milsToMM)(3);
|
|
149
|
+
const startY = gridStartY - smallOffset / 2;
|
|
150
|
+
const endY = gridEndY + smallOffset;
|
|
141
151
|
for (let i = 0; i <= numCols; i++) {
|
|
142
152
|
const startX = gridStartX + i * gridSize;
|
|
143
|
-
const startY = gridStartY - 0.5;
|
|
144
|
-
const endY = gridEndY;
|
|
145
153
|
lines.push(`M ${startX} ${startY} L ${startX} ${endY}`);
|
|
146
154
|
}
|
|
155
|
+
const strokeSize = (0, helpers_js_1.milsToMM)(3);
|
|
147
156
|
group.path(lines.join(" "))
|
|
148
|
-
.fill('none')
|
|
149
157
|
.attr({
|
|
150
|
-
'stroke-dasharray':
|
|
158
|
+
'stroke-dasharray': `${strokeSize},${gridSize - strokeSize}`,
|
|
151
159
|
})
|
|
152
160
|
.stroke({
|
|
153
|
-
width:
|
|
154
|
-
color: '#
|
|
161
|
+
width: strokeSize,
|
|
162
|
+
color: '#000'
|
|
155
163
|
});
|
|
156
164
|
}
|