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.
Files changed (64) hide show
  1. package/dist/cjs/BaseVisitor.js +6 -1
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +204 -200
  3. package/dist/cjs/antlr/CircuitScriptParser.js +1066 -1173
  4. package/dist/cjs/draw_symbols.js +330 -87
  5. package/dist/cjs/execute.js +41 -14
  6. package/dist/cjs/geometry.js +79 -18
  7. package/dist/cjs/globals.js +37 -6
  8. package/dist/cjs/helpers.js +75 -5
  9. package/dist/cjs/layout.js +107 -43
  10. package/dist/cjs/main.js +10 -4
  11. package/dist/cjs/objects/ClassComponent.js +2 -0
  12. package/dist/cjs/objects/ExecutionScope.js +1 -1
  13. package/dist/cjs/objects/Frame.js +2 -0
  14. package/dist/cjs/objects/Net.js +3 -2
  15. package/dist/cjs/objects/PinTypes.js +7 -1
  16. package/dist/cjs/objects/types.js +11 -1
  17. package/dist/cjs/regenerate-tests.js +64 -3
  18. package/dist/cjs/render.js +29 -21
  19. package/dist/cjs/sizing.js +4 -6
  20. package/dist/cjs/utils.js +29 -5
  21. package/dist/cjs/visitor.js +176 -10
  22. package/dist/esm/BaseVisitor.mjs +6 -1
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +204 -200
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +1061 -1171
  25. package/dist/esm/antlr/CircuitScriptVisitor.mjs +3 -0
  26. package/dist/esm/draw_symbols.mjs +324 -85
  27. package/dist/esm/execute.mjs +42 -15
  28. package/dist/esm/geometry.mjs +79 -17
  29. package/dist/esm/globals.mjs +36 -5
  30. package/dist/esm/helpers.mjs +74 -5
  31. package/dist/esm/layout.mjs +110 -46
  32. package/dist/esm/main.mjs +11 -5
  33. package/dist/esm/objects/ClassComponent.mjs +6 -0
  34. package/dist/esm/objects/ExecutionScope.mjs +1 -1
  35. package/dist/esm/objects/Frame.mjs +2 -0
  36. package/dist/esm/objects/Net.mjs +3 -2
  37. package/dist/esm/objects/PinTypes.mjs +6 -0
  38. package/dist/esm/objects/types.mjs +14 -0
  39. package/dist/esm/regenerate-tests.mjs +64 -3
  40. package/dist/esm/render.mjs +30 -22
  41. package/dist/esm/sizing.mjs +3 -4
  42. package/dist/esm/utils.mjs +26 -4
  43. package/dist/esm/visitor.mjs +179 -13
  44. package/dist/types/antlr/CircuitScriptLexer.d.ts +42 -41
  45. package/dist/types/antlr/CircuitScriptParser.d.ts +144 -133
  46. package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -0
  47. package/dist/types/draw_symbols.d.ts +15 -2
  48. package/dist/types/execute.d.ts +5 -4
  49. package/dist/types/geometry.d.ts +4 -3
  50. package/dist/types/globals.d.ts +32 -3
  51. package/dist/types/helpers.d.ts +12 -0
  52. package/dist/types/layout.d.ts +8 -2
  53. package/dist/types/objects/ClassComponent.d.ts +8 -0
  54. package/dist/types/objects/Frame.d.ts +3 -1
  55. package/dist/types/objects/PinTypes.d.ts +1 -0
  56. package/dist/types/objects/Wire.d.ts +4 -2
  57. package/dist/types/objects/types.d.ts +8 -0
  58. package/dist/types/render.d.ts +5 -1
  59. package/dist/types/sizing.d.ts +0 -4
  60. package/dist/types/utils.d.ts +3 -0
  61. package/dist/types/visitor.d.ts +8 -1
  62. package/fonts/Arial.ttf +0 -0
  63. package/libs/lib.cst +58 -41
  64. package/package.json +5 -1
@@ -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
- constructor() {
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 = false;
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 = 20;
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 = 16;
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
- tmpSymbol = new SymbolCustom(symbolPinDefinitions);
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).push(floatingNode);
654
- this.print('linking node', floatingNode, 'to origin node', originNode);
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
- return [
830
- item.x + pinPosition.x,
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
- return [item.x, item.y];
876
+ x = item.x;
877
+ y = item.y;
837
878
  }
838
879
  else {
839
880
  const wireEnd = item.getWireEnd();
840
- return [
841
- item.x + wireEnd.x,
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: pins.get(existingPinIds[i]).name,
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: pins.get(pinId).name,
895
- position: pins.get(pinId).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 += value;
1070
+ tmpY += useValue;
1018
1071
  }
1019
1072
  else if (direction === Direction.Up) {
1020
- tmpY -= value;
1073
+ tmpY -= useValue;
1021
1074
  }
1022
1075
  else if (direction === Direction.Left) {
1023
- tmpX -= value;
1076
+ tmpX -= useValue;
1024
1077
  }
1025
1078
  else if (direction === Direction.Right) {
1026
- tmpX += value;
1079
+ tmpX += useValue;
1027
1080
  }
1028
- else if (direction === 'auto' || direction === "auto_") {
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 inQuadrant = Geometry.getQuadrant(value[0], value[1]);
1048
- const [dx, dy] = value;
1049
- if (direction === 'auto') {
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 === 'auto_') {
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 += value;
1157
+ tmpY += useValue;
1096
1158
  }
1097
1159
  else if (direction === Direction.Up) {
1098
- tmpY -= value;
1160
+ tmpY -= useValue;
1099
1161
  }
1100
1162
  else if (direction === Direction.Left) {
1101
- tmpX -= value;
1163
+ tmpX -= useValue;
1102
1164
  }
1103
1165
  else if (direction === Direction.Right) {
1104
- tmpX += value;
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 'auto':
1124
- case 'auto_':
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 = 20;
1193
- gap = 20;
1254
+ padding = milsToMM(100);
1255
+ gap = milsToMM(100);
1194
1256
  direction = FramePlotDirection.Column;
1195
- borderWidth = 1;
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
- scriptData = readFileSync(inputFilePath, { encoding: 'utf-8' });
51
- if (currentDirectory === null) {
52
- currentDirectory = path.dirname(inputFilePath);
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.log("Error: No input provided");
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;
@@ -89,7 +89,7 @@ export class ExecutionScope {
89
89
  }
90
90
  });
91
91
  return sortedNet.map(([component, pin, net]) => {
92
- return [net.namespace + net.name, component.instanceName, pin];
92
+ return [net.toString(), component.instanceName, pin];
93
93
  });
94
94
  }
95
95
  printNets() {
@@ -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) {
@@ -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.name === netB.name &&
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;
@@ -6,3 +6,9 @@ export var PinTypes;
6
6
  PinTypes["IO"] = "io";
7
7
  PinTypes["Power"] = "power";
8
8
  })(PinTypes || (PinTypes = {}));
9
+ export const AllPinTypes = [
10
+ PinTypes.Any,
11
+ PinTypes.Input,
12
+ PinTypes.Output,
13
+ PinTypes.IO,
14
+ ];
@@ -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 = inputPath + '.svg';
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
- regenerateTests();
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
+ })();
@@ -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 margin = 5;
16
- const widthAndMargin = width + margin * 2;
17
- const heightAndMargin = height + margin * 2;
18
- const scale = 1;
19
- canvas.size(widthAndMargin * scale, heightAndMargin * scale);
20
- canvas.viewbox(x - margin, y - margin, widthAndMargin, heightAndMargin);
21
- return canvas.svg();
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: 'Inter',
70
- size: 10,
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({ width: 1, color: ColorScheme.WireColor,
83
- linecap: 'square' })
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(5)
125
- .translate(-5 / 2, -5 / 2)
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 = 20;
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': '1,' + (gridSize - 1),
154
+ 'stroke-dasharray': `${strokeSize},${gridSize - strokeSize}`,
147
155
  })
148
156
  .stroke({
149
- width: 1,
150
- color: '#aaa'
157
+ width: strokeSize,
158
+ color: '#000'
151
159
  });
152
160
  }