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/esm/layout.mjs
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { Graph, alg } from '@dagrejs/graphlib';
|
|
2
|
-
import { SymbolCustom, SymbolDrawing, SymbolFactory, SymbolPlaceholder, SymbolText } from "./draw_symbols.mjs";
|
|
2
|
+
import { SymbolCustom, SymbolDrawing, SymbolFactory, SymbolCustomModule, SymbolPlaceholder, SymbolText } from "./draw_symbols.mjs";
|
|
3
3
|
import { FrameAction, SequenceAction } from "./objects/ExecutionScope.mjs";
|
|
4
|
-
import { GlobalNames, ParamKeys } from './globals.mjs';
|
|
4
|
+
import { defaultFrameTitleTextSize, defaultGridSizeUnits, GlobalNames, ParamKeys, WireAutoDirection } from './globals.mjs';
|
|
5
5
|
import { NumericValue } from './objects/ParamDefinition.mjs';
|
|
6
6
|
import { Geometry } from './geometry.mjs';
|
|
7
7
|
import { Logger } from './logger.mjs';
|
|
8
8
|
import { Frame, FrameParamKeys, FramePlotDirection } from './objects/Frame.mjs';
|
|
9
|
-
import { getBoundsSize, printBounds, resizeBounds, resizeToNearestGrid, toNearestGrid } from './utils.mjs';
|
|
9
|
+
import { getBoundsSize, printBounds, resizeBounds, resizeToNearestGrid, roundValue, toNearestGrid } from './utils.mjs';
|
|
10
10
|
import { Direction } from './objects/types.mjs';
|
|
11
|
+
import { milsToMM, UnitDimension } from './helpers.mjs';
|
|
11
12
|
export class LayoutEngine {
|
|
12
13
|
logger;
|
|
13
14
|
placeSubgraphVersion = 2;
|
|
14
15
|
layoutWarnings = [];
|
|
15
|
-
|
|
16
|
+
showBaseFrame = false;
|
|
17
|
+
constructor(options = { showBaseFrame: false }) {
|
|
16
18
|
this.logger = new Logger();
|
|
19
|
+
const { showBaseFrame = false } = options ?? {};
|
|
20
|
+
this.showBaseFrame = showBaseFrame;
|
|
17
21
|
}
|
|
18
22
|
print(...params) {
|
|
19
23
|
this.logger.add(params.join(' '));
|
|
@@ -121,6 +125,11 @@ export class LayoutEngine {
|
|
|
121
125
|
const baseFrame = frameObjects[0];
|
|
122
126
|
baseFrame.padding = 0;
|
|
123
127
|
baseFrame.borderWidth = 0;
|
|
128
|
+
if (this.showBaseFrame) {
|
|
129
|
+
baseFrame.borderWidth = 5;
|
|
130
|
+
baseFrame.width = 11692 - 400 * 2;
|
|
131
|
+
baseFrame.height = 8267 - 400 * 2;
|
|
132
|
+
}
|
|
124
133
|
baseFrame.x = 0;
|
|
125
134
|
baseFrame.y = 0;
|
|
126
135
|
let textObjects = [];
|
|
@@ -133,7 +142,7 @@ export class LayoutEngine {
|
|
|
133
142
|
const result = this.prepareFrames(graph, subgraphInfo, baseFrame);
|
|
134
143
|
textObjects = result.textObjects;
|
|
135
144
|
elementFrames = result.elementFrames;
|
|
136
|
-
const logFrames =
|
|
145
|
+
const logFrames = true;
|
|
137
146
|
if (logFrames) {
|
|
138
147
|
this.print('===== dump frames =====');
|
|
139
148
|
this.dumpFrame(baseFrame);
|
|
@@ -184,7 +193,7 @@ export class LayoutEngine {
|
|
|
184
193
|
}
|
|
185
194
|
placeAndSizeFrame(frame, level = 0) {
|
|
186
195
|
const innerFrames = frame.innerItems;
|
|
187
|
-
const gridSize =
|
|
196
|
+
const gridSize = defaultGridSizeUnits;
|
|
188
197
|
let accumX = 0;
|
|
189
198
|
let accumY = 0;
|
|
190
199
|
const boundPoints = [];
|
|
@@ -257,6 +266,12 @@ export class LayoutEngine {
|
|
|
257
266
|
boundPoints.push([innerFrame.x, innerFrame.y], [innerFrame.x + frameWidth, innerFrame.y + frameHeight]);
|
|
258
267
|
});
|
|
259
268
|
frame.bounds = resizeBounds(getBoundsFromPoints(boundPoints), frame.padding);
|
|
269
|
+
if (frame.width !== null) {
|
|
270
|
+
frame.bounds.xmax = milsToMM(frame.bounds.xmin + frame.width);
|
|
271
|
+
}
|
|
272
|
+
if (frame.height !== null) {
|
|
273
|
+
frame.bounds.ymax = milsToMM(frame.bounds.ymin + frame.height);
|
|
274
|
+
}
|
|
260
275
|
}
|
|
261
276
|
dumpFrame(frame, level = 0) {
|
|
262
277
|
this.print(level, "".padStart(level * 4), 'frame, items:', frame.innerItems.length);
|
|
@@ -324,7 +339,7 @@ export class LayoutEngine {
|
|
|
324
339
|
tmpFrame.containsTitle = true;
|
|
325
340
|
tmpFrame.subgraphId = title.replace(/\s/g, "_");
|
|
326
341
|
const textObject = new RenderText(title);
|
|
327
|
-
textObject.fontSize =
|
|
342
|
+
textObject.fontSize = defaultFrameTitleTextSize;
|
|
328
343
|
textObject.fontWeight = 'bold';
|
|
329
344
|
textObject.symbol.refreshDrawing();
|
|
330
345
|
tmpFrame.innerItems.push(textObject);
|
|
@@ -386,7 +401,12 @@ export class LayoutEngine {
|
|
|
386
401
|
}
|
|
387
402
|
else {
|
|
388
403
|
const symbolPinDefinitions = generateLayoutPinDefinition(component);
|
|
389
|
-
|
|
404
|
+
if (component.typeProp === 'module') {
|
|
405
|
+
tmpSymbol = new SymbolCustomModule(symbolPinDefinitions);
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
tmpSymbol = new SymbolCustom(symbolPinDefinitions);
|
|
409
|
+
}
|
|
390
410
|
}
|
|
391
411
|
applyComponentParamsToSymbol(typeProp, component, tmpSymbol);
|
|
392
412
|
let didSetAngle = false;
|
|
@@ -403,7 +423,7 @@ export class LayoutEngine {
|
|
|
403
423
|
component.parameters.get('flipY');
|
|
404
424
|
}
|
|
405
425
|
if (tmpSymbol instanceof SymbolCustom && widthProp) {
|
|
406
|
-
tmpSymbol.bodyWidth = widthProp;
|
|
426
|
+
tmpSymbol.bodyWidth = milsToMM(widthProp);
|
|
407
427
|
}
|
|
408
428
|
if (!didSetAngle && component.parameters.has('_addDirection')) {
|
|
409
429
|
tmpSymbol.refreshDrawing(false);
|
|
@@ -489,6 +509,14 @@ export class LayoutEngine {
|
|
|
489
509
|
newFrame.borderWidth =
|
|
490
510
|
frameObject.parameters.get(FrameParamKeys.Border);
|
|
491
511
|
}
|
|
512
|
+
if (frameObject.parameters.has(FrameParamKeys.Width)) {
|
|
513
|
+
newFrame.width =
|
|
514
|
+
frameObject.parameters.get(FrameParamKeys.Width);
|
|
515
|
+
}
|
|
516
|
+
if (frameObject.parameters.has(FrameParamKeys.Height)) {
|
|
517
|
+
newFrame.height =
|
|
518
|
+
frameObject.parameters.get(FrameParamKeys.Height);
|
|
519
|
+
}
|
|
492
520
|
containerFrames.push(newFrame);
|
|
493
521
|
frameStack.push(newFrame);
|
|
494
522
|
prevFrame && prevFrame.innerItems.push(newFrame);
|
|
@@ -584,6 +612,10 @@ export class LayoutEngine {
|
|
|
584
612
|
this.placeNodeAtPosition(0, 0, node1, 1);
|
|
585
613
|
return;
|
|
586
614
|
}
|
|
615
|
+
let fixedNode;
|
|
616
|
+
let fixedNodePin;
|
|
617
|
+
let floatingNode;
|
|
618
|
+
let floatingNodePin;
|
|
587
619
|
subgraphEdges.forEach(edge => {
|
|
588
620
|
const [nodeId1, pin1, nodeId2, pin2] = graph.edge(edge);
|
|
589
621
|
const [, node1] = graph.node(nodeId1);
|
|
@@ -596,10 +628,6 @@ export class LayoutEngine {
|
|
|
596
628
|
originNodes.push(node1);
|
|
597
629
|
originNodeGroups.set(node1.toString(), [node1]);
|
|
598
630
|
}
|
|
599
|
-
let fixedNode;
|
|
600
|
-
let fixedNodePin;
|
|
601
|
-
let floatingNode;
|
|
602
|
-
let floatingNodePin;
|
|
603
631
|
this.print('edge:', '[', node1, pin1, node1.isFloating, ']', '[', node2, pin2, node2.isFloating, ']');
|
|
604
632
|
if (!node1.isFloating && node2.isFloating) {
|
|
605
633
|
fixedNode = node1;
|
|
@@ -650,19 +678,31 @@ export class LayoutEngine {
|
|
|
650
678
|
floatingNode.isFloating = false;
|
|
651
679
|
this.print('set node as not floating:', floatingNode);
|
|
652
680
|
const originNode = findOriginNode(fixedNode);
|
|
653
|
-
originNodeGroups.get(originNode)
|
|
654
|
-
|
|
681
|
+
const itemsArray = originNodeGroups.get(originNode);
|
|
682
|
+
if (itemsArray.indexOf(floatingNode) === -1) {
|
|
683
|
+
itemsArray.push(floatingNode);
|
|
684
|
+
this.print('linking node', floatingNode, 'to origin node', originNode);
|
|
685
|
+
}
|
|
686
|
+
else {
|
|
687
|
+
this.print('node is alread linked', floatingNode, 'to origin node', originNode);
|
|
688
|
+
}
|
|
655
689
|
}
|
|
656
690
|
[node1, node2].forEach(item => {
|
|
657
691
|
if (item instanceof RenderWire && item.isEndAutoLength()) {
|
|
658
|
-
this.print('auto length wire', item);
|
|
659
692
|
const [instance, pin] = item.getEndAuto();
|
|
660
693
|
const [, targetNode] = graph.node(instance.instanceName);
|
|
694
|
+
this.print('wire', item, 'auto length to target:', instance, pin);
|
|
661
695
|
if (targetNode.isFloating) {
|
|
662
696
|
throw "Cannot create auto wire with floating node! Wire id: " + item.id + " to node " + instance + " pin " + pin;
|
|
663
697
|
}
|
|
698
|
+
const targetOriginNode = findOriginNode(targetNode);
|
|
699
|
+
const itemOriginNode = findOriginNode(item);
|
|
700
|
+
if (targetOriginNode !== itemOriginNode) {
|
|
701
|
+
throw "Wire auto length failed. Please specify a fixed wire length.";
|
|
702
|
+
}
|
|
664
703
|
const [untilX, untilY] = getNodePositionAtPin(targetNode, pin);
|
|
665
704
|
item.setEndAuto(untilX, untilY);
|
|
705
|
+
this.print(`set wire auto end at: ${untilX} ${untilY}`);
|
|
666
706
|
}
|
|
667
707
|
});
|
|
668
708
|
});
|
|
@@ -824,25 +864,27 @@ export class LayoutEngine {
|
|
|
824
864
|
}
|
|
825
865
|
}
|
|
826
866
|
function getNodePositionAtPin(item, pin) {
|
|
867
|
+
let x = 0;
|
|
868
|
+
let y = 0;
|
|
827
869
|
if (item instanceof RenderComponent) {
|
|
828
870
|
const pinPosition = item.symbol.pinPosition(pin);
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
item.y + pinPosition.y
|
|
832
|
-
];
|
|
871
|
+
x = item.x + pinPosition.x;
|
|
872
|
+
y = item.y + pinPosition.y;
|
|
833
873
|
}
|
|
834
874
|
else if (item instanceof RenderWire) {
|
|
835
875
|
if (pin === 0) {
|
|
836
|
-
|
|
876
|
+
x = item.x;
|
|
877
|
+
y = item.y;
|
|
837
878
|
}
|
|
838
879
|
else {
|
|
839
880
|
const wireEnd = item.getWireEnd();
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
item.y + wireEnd.y
|
|
843
|
-
];
|
|
881
|
+
x = item.x + wireEnd.x;
|
|
882
|
+
y = item.y + wireEnd.y;
|
|
844
883
|
}
|
|
845
884
|
}
|
|
885
|
+
return [
|
|
886
|
+
roundValue(x), roundValue(y)
|
|
887
|
+
];
|
|
846
888
|
}
|
|
847
889
|
function getNeighbours(graph, nodeIds) {
|
|
848
890
|
return nodeIds.reduce((accum, nodeId) => {
|
|
@@ -868,11 +910,13 @@ function generateLayoutPinDefinition(component) {
|
|
|
868
910
|
if (component.arrangeProps === null) {
|
|
869
911
|
for (let i = 0; i < existingPinIds.length; i++) {
|
|
870
912
|
const pinPosition = Math.floor(i / 2);
|
|
913
|
+
const pin = pins.get(existingPinIds[i]);
|
|
871
914
|
symbolPinDefinitions.push({
|
|
872
915
|
side: (i % 2 === 0) ? "left" : "right",
|
|
873
916
|
pinId: existingPinIds[i],
|
|
874
|
-
text:
|
|
917
|
+
text: pin.name,
|
|
875
918
|
position: pinPosition,
|
|
919
|
+
pinType: pin.pinType,
|
|
876
920
|
});
|
|
877
921
|
}
|
|
878
922
|
}
|
|
@@ -888,11 +932,13 @@ function generateLayoutPinDefinition(component) {
|
|
|
888
932
|
}
|
|
889
933
|
useItems.forEach(pinId => {
|
|
890
934
|
if (existingPinIds.indexOf(pinId) !== -1) {
|
|
935
|
+
const pin = pins.get(pinId);
|
|
891
936
|
symbolPinDefinitions.push({
|
|
892
937
|
side: key,
|
|
893
938
|
pinId: pinId,
|
|
894
|
-
text:
|
|
895
|
-
position:
|
|
939
|
+
text: pin.name,
|
|
940
|
+
position: pin.position,
|
|
941
|
+
pinType: pin.pinType,
|
|
896
942
|
});
|
|
897
943
|
addedPins.push(pinId);
|
|
898
944
|
}
|
|
@@ -1013,19 +1059,26 @@ export class RenderWire extends RenderObject {
|
|
|
1013
1059
|
this.segments.forEach(segment => {
|
|
1014
1060
|
const { direction, value } = segment;
|
|
1015
1061
|
let didAddPoint = false;
|
|
1062
|
+
let useValue;
|
|
1063
|
+
if (value instanceof UnitDimension) {
|
|
1064
|
+
useValue = value.getMM();
|
|
1065
|
+
}
|
|
1066
|
+
else {
|
|
1067
|
+
useValue = value;
|
|
1068
|
+
}
|
|
1016
1069
|
if (direction === Direction.Down) {
|
|
1017
|
-
tmpY +=
|
|
1070
|
+
tmpY += useValue;
|
|
1018
1071
|
}
|
|
1019
1072
|
else if (direction === Direction.Up) {
|
|
1020
|
-
tmpY -=
|
|
1073
|
+
tmpY -= useValue;
|
|
1021
1074
|
}
|
|
1022
1075
|
else if (direction === Direction.Left) {
|
|
1023
|
-
tmpX -=
|
|
1076
|
+
tmpX -= useValue;
|
|
1024
1077
|
}
|
|
1025
1078
|
else if (direction === Direction.Right) {
|
|
1026
|
-
tmpX +=
|
|
1079
|
+
tmpX += useValue;
|
|
1027
1080
|
}
|
|
1028
|
-
else if (direction ===
|
|
1081
|
+
else if (direction === WireAutoDirection.Auto || direction === WireAutoDirection.Auto_) {
|
|
1029
1082
|
const { valueXY = [0, 0] } = segment;
|
|
1030
1083
|
const tmpPoints = this.getAutoPoints(valueXY, direction);
|
|
1031
1084
|
tmpPoints.forEach(point => {
|
|
@@ -1044,9 +1097,11 @@ export class RenderWire extends RenderObject {
|
|
|
1044
1097
|
this.points = points;
|
|
1045
1098
|
}
|
|
1046
1099
|
getAutoPoints(value, direction) {
|
|
1047
|
-
const
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1100
|
+
const valueX = roundValue(value[0]);
|
|
1101
|
+
const valueY = roundValue(value[1]);
|
|
1102
|
+
const inQuadrant = Geometry.getQuadrant(valueX, valueY);
|
|
1103
|
+
const [dx, dy] = [valueX, valueY];
|
|
1104
|
+
if (direction === WireAutoDirection.Auto) {
|
|
1050
1105
|
switch (inQuadrant) {
|
|
1051
1106
|
case 0:
|
|
1052
1107
|
case 2:
|
|
@@ -1056,7 +1111,7 @@ export class RenderWire extends RenderObject {
|
|
|
1056
1111
|
return [[0, dy], [dx, 0]];
|
|
1057
1112
|
}
|
|
1058
1113
|
}
|
|
1059
|
-
else if (direction ===
|
|
1114
|
+
else if (direction === WireAutoDirection.Auto_) {
|
|
1060
1115
|
switch (inQuadrant) {
|
|
1061
1116
|
case 0:
|
|
1062
1117
|
case 2:
|
|
@@ -1091,17 +1146,24 @@ export class RenderWire extends RenderObject {
|
|
|
1091
1146
|
let tmpY = this.y;
|
|
1092
1147
|
excludeLastSegment.forEach(segment => {
|
|
1093
1148
|
const { direction, value } = segment;
|
|
1149
|
+
let useValue;
|
|
1150
|
+
if (value instanceof UnitDimension) {
|
|
1151
|
+
useValue = value.getMM();
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
useValue = value;
|
|
1155
|
+
}
|
|
1094
1156
|
if (direction === Direction.Down) {
|
|
1095
|
-
tmpY +=
|
|
1157
|
+
tmpY += useValue;
|
|
1096
1158
|
}
|
|
1097
1159
|
else if (direction === Direction.Up) {
|
|
1098
|
-
tmpY -=
|
|
1160
|
+
tmpY -= useValue;
|
|
1099
1161
|
}
|
|
1100
1162
|
else if (direction === Direction.Left) {
|
|
1101
|
-
tmpX -=
|
|
1163
|
+
tmpX -= useValue;
|
|
1102
1164
|
}
|
|
1103
1165
|
else if (direction === Direction.Right) {
|
|
1104
|
-
tmpX +=
|
|
1166
|
+
tmpX += useValue;
|
|
1105
1167
|
}
|
|
1106
1168
|
});
|
|
1107
1169
|
let useValue = null;
|
|
@@ -1120,8 +1182,8 @@ export class RenderWire extends RenderObject {
|
|
|
1120
1182
|
case Direction.Down:
|
|
1121
1183
|
useValue = tmpY - untilY;
|
|
1122
1184
|
break;
|
|
1123
|
-
case
|
|
1124
|
-
case
|
|
1185
|
+
case WireAutoDirection.Auto:
|
|
1186
|
+
case WireAutoDirection.Auto_:
|
|
1125
1187
|
valueXY = [
|
|
1126
1188
|
untilX - tmpX,
|
|
1127
1189
|
untilY - tmpY,
|
|
@@ -1189,10 +1251,12 @@ export class RenderFrame extends RenderObject {
|
|
|
1189
1251
|
innerItems = [];
|
|
1190
1252
|
translateX = 0;
|
|
1191
1253
|
translateY = 0;
|
|
1192
|
-
padding =
|
|
1193
|
-
gap =
|
|
1254
|
+
padding = milsToMM(100);
|
|
1255
|
+
gap = milsToMM(100);
|
|
1194
1256
|
direction = FramePlotDirection.Column;
|
|
1195
|
-
borderWidth =
|
|
1257
|
+
borderWidth = 5;
|
|
1258
|
+
width = null;
|
|
1259
|
+
height = null;
|
|
1196
1260
|
subgraphId = "";
|
|
1197
1261
|
type;
|
|
1198
1262
|
containsTitle = false;
|
package/dist/esm/main.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { program } from 'commander';
|
|
3
3
|
import figlet from 'figlet';
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import { readFileSync, watch } from 'fs';
|
|
5
|
+
import { readFileSync, watch, existsSync } from 'fs';
|
|
6
6
|
import { prepareSVGEnvironment } from './sizing.mjs';
|
|
7
7
|
import { getDefaultLibsPath, getFontsPath, getPackageVersion, renderScript } from './helpers.mjs';
|
|
8
8
|
export default async function main() {
|
|
@@ -47,16 +47,22 @@ export default async function main() {
|
|
|
47
47
|
let scriptData;
|
|
48
48
|
if (args.length > 0 && args[0]) {
|
|
49
49
|
inputFilePath = args[0];
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
currentDirectory
|
|
50
|
+
if (existsSync(inputFilePath)) {
|
|
51
|
+
scriptData = readFileSync(inputFilePath, { encoding: 'utf-8' });
|
|
52
|
+
if (currentDirectory === null) {
|
|
53
|
+
currentDirectory = path.dirname(inputFilePath);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.error("Error: File could not be found");
|
|
58
|
+
return;
|
|
53
59
|
}
|
|
54
60
|
}
|
|
55
61
|
else if (options.input) {
|
|
56
62
|
scriptData = options.input;
|
|
57
63
|
}
|
|
58
64
|
else {
|
|
59
|
-
console.
|
|
65
|
+
console.error("Error: No input provided");
|
|
60
66
|
return;
|
|
61
67
|
}
|
|
62
68
|
const scriptOptions = {
|
|
@@ -22,8 +22,14 @@ export class ClassComponent {
|
|
|
22
22
|
followWireOrientationProp = true;
|
|
23
23
|
wireOrientationAngle = 0;
|
|
24
24
|
useWireOrientationAngle = true;
|
|
25
|
+
didSetWireOrientationAngle = false;
|
|
25
26
|
styles = {};
|
|
26
27
|
assignedRefDes = null;
|
|
28
|
+
moduleContainsExpressions;
|
|
29
|
+
moduleCounter = 0;
|
|
30
|
+
moduleExecutionContext;
|
|
31
|
+
moduleExecutionContextName;
|
|
32
|
+
modulePinIdToPortMap;
|
|
27
33
|
constructor(instanceName, numPins, className) {
|
|
28
34
|
this.instanceName = instanceName;
|
|
29
35
|
this.numPins = numPins;
|
|
@@ -11,6 +11,8 @@ export var FrameParamKeys;
|
|
|
11
11
|
FrameParamKeys["Direction"] = "direction";
|
|
12
12
|
FrameParamKeys["Padding"] = "padding";
|
|
13
13
|
FrameParamKeys["Border"] = "border";
|
|
14
|
+
FrameParamKeys["Width"] = "width";
|
|
15
|
+
FrameParamKeys["Height"] = "height";
|
|
14
16
|
})(FrameParamKeys || (FrameParamKeys = {}));
|
|
15
17
|
export var FramePlotDirection;
|
|
16
18
|
(function (FramePlotDirection) {
|
package/dist/esm/objects/Net.mjs
CHANGED
|
@@ -18,10 +18,11 @@ export class Net {
|
|
|
18
18
|
this.baseName = name;
|
|
19
19
|
}
|
|
20
20
|
toString() {
|
|
21
|
-
return this.name;
|
|
21
|
+
return this.namespace + this.name;
|
|
22
22
|
}
|
|
23
23
|
static isSame(netA, netB) {
|
|
24
|
-
return netA.
|
|
24
|
+
return netA.namespace === netB.namespace &&
|
|
25
|
+
netA.name === netB.name &&
|
|
25
26
|
netA.baseName === netB.baseName &&
|
|
26
27
|
netA.priority === netB.priority &&
|
|
27
28
|
netA.type === netB.type;
|
|
@@ -4,6 +4,20 @@ export class UndeclaredReference {
|
|
|
4
4
|
this.reference = reference;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
+
export class DeclaredReference {
|
|
8
|
+
found;
|
|
9
|
+
name;
|
|
10
|
+
trailers;
|
|
11
|
+
type;
|
|
12
|
+
value;
|
|
13
|
+
constructor(refType) {
|
|
14
|
+
this.found = refType.found;
|
|
15
|
+
this.name = refType.name;
|
|
16
|
+
this.trailers = refType.trailers;
|
|
17
|
+
this.type = refType.type;
|
|
18
|
+
this.value = refType.value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
7
21
|
export var ParseSymbolType;
|
|
8
22
|
(function (ParseSymbolType) {
|
|
9
23
|
ParseSymbolType["Variable"] = "variable";
|
|
@@ -4,7 +4,7 @@ import { prepareSVGEnvironment } from './sizing.mjs';
|
|
|
4
4
|
const mainDir = './__tests__/renderData/';
|
|
5
5
|
const fontsPath = getFontsPath();
|
|
6
6
|
const defaultLibsPath = getDefaultLibsPath();
|
|
7
|
-
async function regenerateTests() {
|
|
7
|
+
async function regenerateTests(extra = "") {
|
|
8
8
|
await prepareSVGEnvironment(fontsPath);
|
|
9
9
|
const cstFiles = [];
|
|
10
10
|
const files = fs.readdirSync(mainDir);
|
|
@@ -16,12 +16,73 @@ async function regenerateTests() {
|
|
|
16
16
|
cstFiles.forEach(file => {
|
|
17
17
|
const inputPath = mainDir + file;
|
|
18
18
|
const scriptData = fs.readFileSync(inputPath, { encoding: 'utf-8' });
|
|
19
|
-
const outputPath =
|
|
19
|
+
const outputPath = mainDir + 'svgs/' + file + extra + '.svg';
|
|
20
20
|
renderScript(scriptData, outputPath, {
|
|
21
21
|
currentDirectory: mainDir,
|
|
22
22
|
defaultLibsPath,
|
|
23
23
|
});
|
|
24
24
|
console.log('generated ', outputPath);
|
|
25
25
|
});
|
|
26
|
+
return cstFiles;
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
(async () => {
|
|
29
|
+
const generateDiff = false;
|
|
30
|
+
const nextExtra = generateDiff ? '.next' : '';
|
|
31
|
+
const cstFiles = await regenerateTests(nextExtra);
|
|
32
|
+
const allFiles = [];
|
|
33
|
+
if (generateDiff) {
|
|
34
|
+
cstFiles.forEach(file => {
|
|
35
|
+
const svg1 = 'svgs/' + file + '.svg';
|
|
36
|
+
const svg2 = 'svgs/' + file + '.next.svg';
|
|
37
|
+
const cleanedName = file.replace('script', '').replace('.cst', '');
|
|
38
|
+
allFiles.push([file, svg1, svg2, cleanedName]);
|
|
39
|
+
});
|
|
40
|
+
const sortedFiles = allFiles.sort((a, b) => {
|
|
41
|
+
const nameA = a[3];
|
|
42
|
+
const nameB = b[3];
|
|
43
|
+
const indexA = Number(nameA);
|
|
44
|
+
const indexB = Number(nameB);
|
|
45
|
+
if (indexA > indexB) {
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
else if (indexA < indexB) {
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const output = [];
|
|
56
|
+
sortedFiles.forEach(group => {
|
|
57
|
+
const [file, svg1, svg2] = group;
|
|
58
|
+
output.push(`<div class='group'>
|
|
59
|
+
<h3>${file}</h3>
|
|
60
|
+
<div class='items'>
|
|
61
|
+
<div style='margin-right: 10px'>
|
|
62
|
+
<h4>${svg1}</h4>
|
|
63
|
+
<img src='${svg1}'/>
|
|
64
|
+
</div>
|
|
65
|
+
<div>
|
|
66
|
+
<h4>${svg2}</h4>
|
|
67
|
+
<img src='${svg2}'/>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>`);
|
|
71
|
+
});
|
|
72
|
+
const result = `
|
|
73
|
+
<html>
|
|
74
|
+
<header>
|
|
75
|
+
<title>SVG compare</title>
|
|
76
|
+
<style>
|
|
77
|
+
img { border: solid thin #ccc; }
|
|
78
|
+
.items { display: flex; }
|
|
79
|
+
body { font-family: Arial; }
|
|
80
|
+
</style>
|
|
81
|
+
</header>
|
|
82
|
+
<body>
|
|
83
|
+
${output.join('')}
|
|
84
|
+
</body>
|
|
85
|
+
</html>`;
|
|
86
|
+
fs.writeFileSync(mainDir + "compiled.html", result);
|
|
87
|
+
}
|
|
88
|
+
})();
|
package/dist/esm/render.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { SVG, registerWindow } from '@svgdotjs/svg.js';
|
|
2
2
|
import { RenderFrameType, getBounds } from "./layout.mjs";
|
|
3
3
|
import { applyFontsToSVG, getCreateSVGWindow } from './sizing.mjs';
|
|
4
|
-
import { ColorScheme, ComponentTypes, ParamKeys, junctionSize } from './globals.mjs';
|
|
4
|
+
import { ColorScheme, ComponentTypes, MMToPx, ParamKeys, defaultGridSizeUnits, defaultWireLineWidth, defaultZoomScale, fontDisplayScale, junctionSize } from './globals.mjs';
|
|
5
5
|
import { NumericValue } from './objects/ParamDefinition.mjs';
|
|
6
6
|
import { getBoundsSize } from './utils.mjs';
|
|
7
|
+
import { milsToMM } from './helpers.mjs';
|
|
7
8
|
export function generateSVG2(graph) {
|
|
8
9
|
const window = getCreateSVGWindow()();
|
|
9
10
|
const document = window.document;
|
|
@@ -11,14 +12,16 @@ export function generateSVG2(graph) {
|
|
|
11
12
|
const canvas = SVG(document.documentElement);
|
|
12
13
|
applyFontsToSVG(canvas);
|
|
13
14
|
generateSVGChild(canvas, graph.components, graph.wires, graph.junctions, graph.mergedWires, graph.frameObjects, graph.textObjects);
|
|
15
|
+
const scale = MMToPx * defaultZoomScale;
|
|
14
16
|
const { x, y, width, height } = canvas.bbox();
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const scaledWidth = width * scale;
|
|
18
|
+
const scaledHeight = height * scale;
|
|
19
|
+
canvas.size(scaledWidth, scaledHeight);
|
|
20
|
+
canvas.viewbox(x, y, width, height);
|
|
21
|
+
return {
|
|
22
|
+
svg: canvas.svg(),
|
|
23
|
+
width, height,
|
|
24
|
+
};
|
|
22
25
|
}
|
|
23
26
|
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects) {
|
|
24
27
|
const displayWireId = false;
|
|
@@ -66,8 +69,8 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
66
69
|
wires.forEach(wire => {
|
|
67
70
|
wiresGroup.text(wire.id.toString())
|
|
68
71
|
.font({
|
|
69
|
-
family: '
|
|
70
|
-
size:
|
|
72
|
+
family: 'Arial',
|
|
73
|
+
size: 50 * fontDisplayScale,
|
|
71
74
|
})
|
|
72
75
|
.translate(wire.x + 5, wire.y + 5);
|
|
73
76
|
});
|
|
@@ -79,8 +82,11 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
79
82
|
const pt1 = segment[0];
|
|
80
83
|
const pt2 = segment[1];
|
|
81
84
|
mergedWireGroup.line([pt1, pt2])
|
|
82
|
-
.stroke({
|
|
83
|
-
|
|
85
|
+
.stroke({
|
|
86
|
+
width: defaultWireLineWidth,
|
|
87
|
+
color: ColorScheme.WireColor,
|
|
88
|
+
linecap: 'square'
|
|
89
|
+
})
|
|
84
90
|
.fill('none');
|
|
85
91
|
});
|
|
86
92
|
intersectPoints.forEach(point => {
|
|
@@ -109,7 +115,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
109
115
|
}
|
|
110
116
|
const tmpRect = frameGroup.rect(width, height)
|
|
111
117
|
.fill('none')
|
|
112
|
-
.stroke({ width: borderWidth, color: strokeColor });
|
|
118
|
+
.stroke({ width: milsToMM(borderWidth), color: strokeColor });
|
|
113
119
|
tmpRect.translate(item.x, item.y);
|
|
114
120
|
}
|
|
115
121
|
});
|
|
@@ -120,13 +126,14 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
120
126
|
symbol.draw(innerGroup);
|
|
121
127
|
});
|
|
122
128
|
const drawOrigin = false;
|
|
129
|
+
const originSize = milsToMM(10);
|
|
123
130
|
drawOrigin && canvas.group().translate(0, 0)
|
|
124
|
-
.circle(
|
|
125
|
-
.translate(-
|
|
131
|
+
.circle(originSize)
|
|
132
|
+
.translate(-originSize / 2, -originSize / 2)
|
|
126
133
|
.stroke('none').fill('red');
|
|
127
134
|
}
|
|
128
135
|
function drawGrid(group, canvasSize) {
|
|
129
|
-
const gridSize =
|
|
136
|
+
const gridSize = defaultGridSizeUnits;
|
|
130
137
|
const { x, y, x2, y2 } = canvasSize;
|
|
131
138
|
const gridStartX = (Math.floor(x / gridSize) - 1) * gridSize;
|
|
132
139
|
const gridStartY = (Math.floor(y / gridSize) - 1) * gridSize;
|
|
@@ -134,19 +141,20 @@ function drawGrid(group, canvasSize) {
|
|
|
134
141
|
const gridEndY = (Math.ceil(y2 / gridSize) + 1) * gridSize;
|
|
135
142
|
const numCols = Math.ceil((gridEndX - gridStartX) / gridSize);
|
|
136
143
|
const lines = [];
|
|
144
|
+
const smallOffset = milsToMM(3);
|
|
145
|
+
const startY = gridStartY - smallOffset / 2;
|
|
146
|
+
const endY = gridEndY + smallOffset;
|
|
137
147
|
for (let i = 0; i <= numCols; i++) {
|
|
138
148
|
const startX = gridStartX + i * gridSize;
|
|
139
|
-
const startY = gridStartY - 0.5;
|
|
140
|
-
const endY = gridEndY;
|
|
141
149
|
lines.push(`M ${startX} ${startY} L ${startX} ${endY}`);
|
|
142
150
|
}
|
|
151
|
+
const strokeSize = milsToMM(3);
|
|
143
152
|
group.path(lines.join(" "))
|
|
144
|
-
.fill('none')
|
|
145
153
|
.attr({
|
|
146
|
-
'stroke-dasharray':
|
|
154
|
+
'stroke-dasharray': `${strokeSize},${gridSize - strokeSize}`,
|
|
147
155
|
})
|
|
148
156
|
.stroke({
|
|
149
|
-
width:
|
|
150
|
-
color: '#
|
|
157
|
+
width: strokeSize,
|
|
158
|
+
color: '#000'
|
|
151
159
|
});
|
|
152
160
|
}
|