circuitscript 0.5.4 → 0.5.5

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 (58) hide show
  1. package/dist/cjs/BaseVisitor.js +11 -10
  2. package/dist/cjs/builtinMethods.js +6 -5
  3. package/dist/cjs/environment/environment.js +2 -2
  4. package/dist/cjs/errors.js +140 -0
  5. package/dist/cjs/execute.js +12 -5
  6. package/dist/cjs/main.js +3 -2
  7. package/dist/cjs/objects/ClassComponent.js +4 -4
  8. package/dist/cjs/objects/ExecutionScope.js +2 -2
  9. package/dist/cjs/objects/NumericValue.js +15 -0
  10. package/dist/cjs/objects/PinDefinition.js +2 -2
  11. package/dist/cjs/objects/types.js +2 -2
  12. package/dist/cjs/parser.js +3 -2
  13. package/dist/cjs/pipeline.js +21 -14
  14. package/dist/cjs/regenerate-tests.js +6 -6
  15. package/dist/cjs/render/draw_symbols.js +17 -17
  16. package/dist/cjs/render/geometry.js +6 -6
  17. package/dist/cjs/render/layout.js +325 -253
  18. package/dist/cjs/render/render.js +21 -18
  19. package/dist/cjs/semantic-tokens/getSemanticTokens.js +2 -2
  20. package/dist/cjs/sizing.js +2 -2
  21. package/dist/cjs/utils.js +13 -110
  22. package/dist/cjs/validate/validateScript.js +2 -2
  23. package/dist/cjs/visitor.js +14 -12
  24. package/dist/esm/BaseVisitor.js +2 -1
  25. package/dist/esm/builtinMethods.js +6 -5
  26. package/dist/esm/environment/environment.js +1 -1
  27. package/dist/esm/errors.js +119 -0
  28. package/dist/esm/execute.js +10 -3
  29. package/dist/esm/main.js +3 -2
  30. package/dist/esm/objects/ClassComponent.js +1 -1
  31. package/dist/esm/objects/ExecutionScope.js +1 -1
  32. package/dist/esm/objects/NumericValue.js +15 -0
  33. package/dist/esm/objects/PinDefinition.js +1 -1
  34. package/dist/esm/objects/types.js +1 -1
  35. package/dist/esm/parser.js +2 -1
  36. package/dist/esm/pipeline.js +10 -3
  37. package/dist/esm/regenerate-tests.js +6 -6
  38. package/dist/esm/render/draw_symbols.js +15 -15
  39. package/dist/esm/render/geometry.js +6 -6
  40. package/dist/esm/render/layout.js +325 -253
  41. package/dist/esm/render/render.js +22 -19
  42. package/dist/esm/semantic-tokens/getSemanticTokens.js +1 -1
  43. package/dist/esm/sizing.js +2 -2
  44. package/dist/esm/utils.js +10 -95
  45. package/dist/esm/validate/validateScript.js +1 -1
  46. package/dist/esm/visitor.js +4 -2
  47. package/dist/libs/std.cst +31 -31
  48. package/dist/types/BaseVisitor.d.ts +3 -1
  49. package/dist/types/errors.d.ts +37 -0
  50. package/dist/types/execute.d.ts +1 -1
  51. package/dist/types/helpers.d.ts +1 -1
  52. package/dist/types/objects/NumericValue.d.ts +5 -1
  53. package/dist/types/render/geometry.d.ts +4 -4
  54. package/dist/types/render/layout.d.ts +7 -1
  55. package/dist/types/utils.d.ts +2 -27
  56. package/dist/types/visitor.d.ts +1 -1
  57. package/libs/std.cst +31 -31
  58. package/package.json +1 -1
@@ -2,7 +2,7 @@ import { SVG, registerWindow } from '@svgdotjs/svg.js';
2
2
  import { ExtractDrawingRects, RenderFrameType, getBounds } from "./layout.js";
3
3
  import { applyFontsToSVG } from '../sizing.js';
4
4
  import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, MilsToMM, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, fontDisplayScale, junctionSize } from '../globals.js';
5
- import { NumericValue, numeric } from '../objects/NumericValue.js';
5
+ import { NumericValue, numeric, roundValue } from '../objects/NumericValue.js';
6
6
  import { combineMaps, getBoundsSize } from '../utils.js';
7
7
  import { milsToMM } from '../helpers.js';
8
8
  import { getPaperSize } from "./PaperSizes.js";
@@ -259,25 +259,25 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
259
259
  frameObjects.forEach(item => {
260
260
  const { bounds, borderWidth } = item;
261
261
  const { width, height } = getBoundsSize(bounds);
262
- let strokeColor = '#111';
262
+ const useWidth = roundValue(width).toNumber();
263
+ const useHeight = roundValue(height).toNumber();
264
+ const useBorderWidth = roundValue(borderWidth).toNumber();
265
+ let strokeColor = item.borderColor ?? '#111';
263
266
  if (item.frame.frameType === FrameType.Sheet) {
264
267
  drawSheetFrameBorder(frameGroup, item);
265
268
  }
266
269
  else {
267
- if (borderWidth.toNumber() > 0) {
268
- if (item.renderType === RenderFrameType.Container) {
269
- strokeColor = '#111';
270
- }
271
- else if (item.renderType === RenderFrameType.Elements) {
270
+ if (useBorderWidth > 0) {
271
+ if (item.renderType === RenderFrameType.Elements) {
272
272
  strokeColor = '#aaa';
273
273
  if (!RenderFlags.ShowElementFrames) {
274
274
  return;
275
275
  }
276
276
  }
277
- const tmpRect = frameGroup.rect(width, height)
277
+ const tmpRect = frameGroup.rect(useWidth, useHeight)
278
278
  .fill('none')
279
279
  .stroke({
280
- width: milsToMM(borderWidth).toNumber(),
280
+ width: milsToMM(useBorderWidth).toNumber(),
281
281
  color: strokeColor
282
282
  });
283
283
  tmpRect.translate(item.x.toNumber(), item.y.toNumber());
@@ -299,17 +299,20 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
299
299
  function drawGrid(group, gridProperties, logger) {
300
300
  const { gridBounds: canvasSize, extendGrid, style: gridStyle = "dots", color: gridColor = "#000", backgroundColor = "", } = gridProperties;
301
301
  const gridSize = defaultGridSizeUnits;
302
- const { xmin, ymin, xmax, ymax } = canvasSize;
303
302
  const extraValue = extendGrid ? 1 : 0;
304
- const gridStartX = (numeric(Math.floor(xmin / gridSize)).sub(extraValue)).mul(gridSize);
305
- const gridStartY = (numeric(Math.floor(ymin / gridSize)).sub(extraValue)).mul(gridSize);
303
+ const xmin = roundValue(canvasSize.xmin);
304
+ const ymin = roundValue(canvasSize.ymin);
305
+ const xmax = roundValue(canvasSize.xmax);
306
+ const ymax = roundValue(canvasSize.ymax);
307
+ const gridStartX = xmin.div(gridSize).floor().sub(extraValue).mul(gridSize);
308
+ const gridStartY = ymin.div(gridSize).floor().sub(extraValue).mul(gridSize);
306
309
  const gridEndX = extendGrid
307
- ? (numeric(Math.ceil(xmax / gridSize)).add(extraValue)).mul(gridSize)
308
- : (numeric(xmax).sub(xmin));
310
+ ? xmax.div(gridSize).ceil().add(extraValue).mul(gridSize)
311
+ : xmax;
309
312
  const gridEndY = extendGrid
310
- ? (numeric(Math.ceil(ymax / gridSize)).add(extraValue)).mul(gridSize)
311
- : (numeric(ymax).sub(ymin));
312
- const numCols = Math.floor(gridEndX.sub(gridStartX).div(gridSize).toNumber())
313
+ ? ymax.div(gridSize).ceil().add(extraValue).mul(gridSize)
314
+ : ymax;
315
+ const numCols = gridEndX.sub(gridStartX).div(gridSize).floor().toNumber()
313
316
  + (extendGrid ? 1 : 0);
314
317
  const originSize = milsToMM(10).toNumber();
315
318
  RenderFlags.ShowGridOrigin && group.circle(originSize)
@@ -326,8 +329,8 @@ function drawGrid(group, gridProperties, logger) {
326
329
  lines.push(`M ${startX} ${startY.toNumber()} L ${startX} ${endY.toNumber()}`);
327
330
  }
328
331
  if (backgroundColor !== "") {
329
- const width = gridEndX.sub(gridStartX).toNumber();
330
- const height = gridEndY.sub(gridStartY).toNumber();
332
+ const width = gridEndX.sub(gridStartX).roundDp().toNumber();
333
+ const height = gridEndY.sub(gridStartY).roundDp().toNumber();
331
334
  group
332
335
  .rect(width, height).fill(backgroundColor)
333
336
  .translate(gridStartX.toNumber(), gridStartY.toNumber());
@@ -1,6 +1,6 @@
1
1
  import { prepareFile } from "../helpers.js";
2
2
  import { prepareTokens, SemanticTokensVisitor } from "./SemanticTokenVisitor.js";
3
- import { ParseError } from "../utils.js";
3
+ import { ParseError } from "../errors.js";
4
4
  export async function getSemanticTokens(filePath, scriptData, options) {
5
5
  const { parser, lexer, tokens } = prepareFile(scriptData);
6
6
  const tree = parser.script();
@@ -16,7 +16,7 @@ export function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regul
16
16
  case VerticalAlign.Top:
17
17
  dominantBaseline = VerticalAlignProp.Hanging;
18
18
  break;
19
- case VerticalAlign.Middle:
19
+ case VerticalAlign.Center:
20
20
  dominantBaseline = VerticalAlignProp.Central;
21
21
  break;
22
22
  case VerticalAlign.Bottom:
@@ -28,7 +28,7 @@ export function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regul
28
28
  case HorizontalAlign.Left:
29
29
  useAnchor = HorizontalAlignProp.Start;
30
30
  break;
31
- case HorizontalAlign.Middle:
31
+ case HorizontalAlign.Center:
32
32
  useAnchor = HorizontalAlignProp.Middle;
33
33
  break;
34
34
  case HorizontalAlign.Right:
package/dist/esm/utils.js CHANGED
@@ -1,8 +1,9 @@
1
- import { ParserRuleContext } from "antlr4ng";
2
1
  import { ClassComponent } from "./objects/ClassComponent.js";
3
2
  import { SequenceAction } from './objects/ExecutionScope.js';
4
3
  import { BlockTypes } from "./objects/BlockTypes.js";
5
4
  import { DeclaredReference, AnyReference } from './objects/types.js';
5
+ import { getLinePositionAsString } from "./errors.js";
6
+ import { roundValue } from "./objects/NumericValue.js";
6
7
  export class SimpleStopwatch {
7
8
  startTime;
8
9
  constructor() {
@@ -40,14 +41,17 @@ export function resizeToNearestGrid(bounds, gridSize = 20) {
40
41
  const addXMax = hasRemainder(bounds.xmax, gridSize) === 0 ? 1 : 0;
41
42
  const addYMax = hasRemainder(bounds.ymax, gridSize) === 0 ? 1 : 0;
42
43
  return {
43
- xmin: Math.floor((bounds.xmin + addXMin) / gridSize) * gridSize,
44
- ymin: Math.floor((bounds.ymin + addYMin) / gridSize) * gridSize,
45
- xmax: Math.ceil((bounds.xmax + addXMax) / gridSize) * gridSize,
46
- ymax: Math.ceil((bounds.ymax + addYMax) / gridSize) * gridSize,
44
+ xmin: roundValue(Math.floor((bounds.xmin + addXMin) / gridSize) * gridSize).toNumber(),
45
+ ymin: roundValue(Math.floor((bounds.ymin + addYMin) / gridSize) * gridSize).toNumber(),
46
+ xmax: roundValue(Math.ceil((bounds.xmax + addXMax) / gridSize) * gridSize).toNumber(),
47
+ ymax: roundValue(Math.ceil((bounds.ymax + addYMax) / gridSize) * gridSize).toNumber(),
47
48
  };
48
49
  }
49
50
  export function toNearestGrid(value, gridSize) {
50
- return Math.floor(value / gridSize) * gridSize;
51
+ return roundValue(value / gridSize).floor().mul(gridSize).toNumber();
52
+ }
53
+ export function toNearestGrid2(value, gridSize) {
54
+ return roundValue(value / gridSize).ceil().mul(gridSize).toNumber();
51
55
  }
52
56
  export function getBoundsSize(bounds) {
53
57
  return {
@@ -69,18 +73,6 @@ export function getPortType(component) {
69
73
  });
70
74
  return foundPinType;
71
75
  }
72
- export function throwWithContext(context, messageOrError) {
73
- if (messageOrError instanceof BaseError) {
74
- throw messageOrError;
75
- }
76
- throwWithTokenRange(messageOrError, context.start, context.stop);
77
- }
78
- export function throwWithToken(message, token) {
79
- throw new ParseError(message, token);
80
- }
81
- export function throwWithTokenRange(message, startToken, endToken) {
82
- throw new ParseError(message, startToken, endToken);
83
- }
84
76
  export function combineMaps(map1, map2) {
85
77
  const newMap = new Map(map1);
86
78
  map2.forEach((value, key) => {
@@ -174,83 +166,6 @@ export function getBlockTypeString(type) {
174
166
  }
175
167
  return returnValue;
176
168
  }
177
- export class BaseError extends Error {
178
- name = 'BaseError';
179
- message;
180
- startToken;
181
- endToken;
182
- filePath;
183
- constructor(message, startTokenOrCtx, endToken, filePath) {
184
- super(message);
185
- this.message = message;
186
- if (startTokenOrCtx instanceof ParserRuleContext) {
187
- this.startToken = startTokenOrCtx.start;
188
- this.endToken = startTokenOrCtx.stop;
189
- }
190
- else {
191
- this.startToken = startTokenOrCtx;
192
- this.endToken = endToken;
193
- }
194
- this.filePath = filePath;
195
- }
196
- toString() {
197
- const parts = [this.name];
198
- const linePosition = getLinePositionAsString({
199
- start: this.startToken,
200
- stop: this.endToken
201
- });
202
- if (linePosition !== null) {
203
- parts.push(linePosition);
204
- }
205
- parts.push(`: ${this.message}`);
206
- return parts.join('');
207
- }
208
- }
209
- export function getLinePositionAsString(ctx) {
210
- if (ctx === null || ctx === undefined) {
211
- return null;
212
- }
213
- const { start: startToken, stop: stopToken } = ctx;
214
- let result = null;
215
- if (startToken) {
216
- const { line, column } = startToken;
217
- let stopLine = 0;
218
- let stopCol = 0;
219
- if (stopToken && (stopToken.line !== startToken.line || stopToken.column !== startToken.column)) {
220
- stopLine = stopToken.line;
221
- stopCol = stopToken.column + (stopToken.stop - stopToken.start);
222
- }
223
- else if (startToken === stopToken || startToken) {
224
- stopLine = line;
225
- stopCol = column + 1 + (startToken.stop - startToken.start);
226
- }
227
- else {
228
- stopCol = -1;
229
- }
230
- result = ` at ${line}:${column + 1}`;
231
- if (stopCol !== -1) {
232
- result += `-${stopLine}:${stopCol + 1}`;
233
- }
234
- }
235
- return result;
236
- }
237
- export class ParseSyntaxError extends BaseError {
238
- name = 'ParseSyntaxError';
239
- }
240
- export class ParseError extends ParseSyntaxError {
241
- name = 'ParseError';
242
- }
243
- export class RuntimeExecutionError extends BaseError {
244
- name = 'RuntimeExecutionError';
245
- }
246
- export class RenderError extends Error {
247
- stage;
248
- constructor(message, stage) {
249
- super(message);
250
- this.name = 'RenderError';
251
- this.stage = stage;
252
- }
253
- }
254
169
  export function printWarnings(warnings) {
255
170
  const warningMessages = [];
256
171
  warnings.forEach(item => {
@@ -1,5 +1,5 @@
1
1
  import { prepareFile, ParseErrorStrategy, TokenErrorListener } from "../helpers.js";
2
- import { ParseError } from "../utils.js";
2
+ import { ParseError } from "../errors.js";
3
3
  import { SymbolValidatorResolveVisitor } from "./SymbolValidatorResolveVisitor.js";
4
4
  import { SymbolValidatorVisitor } from "./SymbolValidatorVisitor.js";
5
5
  export async function validateScript(filePath, scriptData, options) {
@@ -10,7 +10,8 @@ import { BlockTypes } from "./objects/BlockTypes.js";
10
10
  import { unwrapValue } from "./utils.js";
11
11
  import { PlaceHolderCommands, SymbolDrawingCommands } from './render/draw_symbols.js';
12
12
  import { BaseVisitor } from './BaseVisitor.js';
13
- import { getPortType, RuntimeExecutionError } from './utils.js';
13
+ import { getPortType } from './utils.js';
14
+ import { RuntimeExecutionError } from './errors.js';
14
15
  import { UnitDimension } from './helpers.js';
15
16
  import { FrameParamKeys } from './objects/Frame.js';
16
17
  import { ComponentAnnotater } from './annotate/ComponentAnnotater.js';
@@ -1024,8 +1025,9 @@ export class ParserVisitor extends BaseVisitor {
1024
1025
  if (segments.length === 0) {
1025
1026
  this.throwWithContext(ctx, "Invalid wire expression");
1026
1027
  }
1027
- const newWire = this.getExecutor().addWire(segments);
1028
+ const newWire = this.getExecutor().addWire(segments, ctx);
1028
1029
  this.creationCtx.set(newWire, ctx);
1030
+ this.wireCtxLinks.set(newWire, ctx);
1029
1031
  };
1030
1032
  visitPoint_expr = (ctx) => {
1031
1033
  const ctxDataExpr = ctx.data_expr();
package/dist/libs/std.cst CHANGED
@@ -7,7 +7,7 @@ def net(net_name, net_type = "any"):
7
7
  display: create graphic (params):
8
8
  hline: -50, 0, 100
9
9
  vpin: 1, 0, 50, -50, display_id=false
10
- label: params.net_name, 0, -15, fontSize=50, anchor="middle"
10
+ label: params.net_name, 0, -15, fontSize=50, anchor="center"
11
11
  type: "net"
12
12
  params:
13
13
  net_name: net_name
@@ -39,7 +39,7 @@ def port(value, portType="input"):
39
39
  copy: true
40
40
  display: create graphic (params):
41
41
  text_color: "#222"
42
- label: params.value, 0, 0, fontSize=40, anchor="left", vanchor="middle", portType=portType
42
+ label: params.value, 0, 0, fontSize=40, anchor="left", vanchor="center", portType=portType
43
43
  pin: 1, 0, 0, 0, 0, display_id=false
44
44
  type: "port"
45
45
  params:
@@ -58,7 +58,7 @@ def res(value):
58
58
  hpin: 1, -width/2 - 30, 0, 30, display_id=false
59
59
  hpin: 2, width/2 + 30, 0, -30, display_id=false
60
60
  label: params.refdes, -width/2, -height/2 - 20, fontSize=50, anchor="left"
61
- label: params.value, 0, 0, fontSize=30, anchor="middle", vanchor="middle"
61
+ label: params.value, 0, 0, fontSize=30, anchor="center", vanchor="center"
62
62
  type: "res"
63
63
  params:
64
64
  value: value
@@ -78,8 +78,8 @@ def cap(value):
78
78
  hline: -width/2, -20, width
79
79
  vpin: 1, 0, -100, 80, display_id=false
80
80
  vpin: 2, 0, 100, -80, display_id=false
81
- label: params.refdes, 80, -30, fontSize=50, anchor="left", vanchor="middle"
82
- label: params.value, 80, 30, fontSize=50, anchor = "left", vanchor="middle"
81
+ label: params.refdes, 80, -30, fontSize=50, anchor="left", vanchor="center"
82
+ label: params.value, 80, 30, fontSize=50, anchor = "left", vanchor="center"
83
83
  type: "cap"
84
84
  params:
85
85
  value: value
@@ -101,7 +101,7 @@ def ind(value):
101
101
  hpin: 1, -width/2 - 100, 0, 100, display_id=false
102
102
  hpin: 2, width/2 + 100, 0, -100, display_id=false
103
103
  label: (params.refdes, -width/2, -height/2 - 25 , fontSize=50, anchor="left")
104
- label: (params.value, 0, 50, fontSize=50, anchor="middle", vanchor="middle")
104
+ label: (params.value, 0, 50, fontSize=50, anchor="center", vanchor="center")
105
105
  params:
106
106
  value: value
107
107
 
@@ -119,7 +119,7 @@ def diode():
119
119
  vline: width/2, -height/2, height
120
120
  hpin: 1, -width/2-100, 0, 100 # cathode
121
121
  hpin: 2, width/2 + 100, 0, -100 # anode
122
- label: params.refdes, 0, -100, fontSize=50, anchor="middle", vanchor="top"
122
+ label: params.refdes, 0, -100, fontSize=50, anchor="center", vanchor="top"
123
123
 
124
124
  def led(color):
125
125
  width = 100
@@ -140,8 +140,8 @@ def led(color):
140
140
  "M", 180, 60, "L", 180, 90, "L", 150, 90)
141
141
  hpin: 1, width/2 + 100, 0, -100 # cathode
142
142
  hpin: 2, -width/2-100, 0, 100 # anode
143
- label: params.refdes, 0, -100, fontSize=50, anchor="middle", vanchor="top"
144
- label: params.color, 0, 100, fontSize=40, anchor="middle", vanchor="bottom"
143
+ label: params.refdes, 0, -100, fontSize=50, anchor="center", vanchor="top"
144
+ label: params.color, 0, 100, fontSize=40, anchor="center", vanchor="bottom"
145
145
  params:
146
146
  size: "0603"
147
147
  color: color
@@ -159,7 +159,7 @@ def cgnd():
159
159
  hline: -10, 5, 20
160
160
  hline: -5, 10, 10
161
161
  vpin: 1, 0, -10, 10, display_id=false
162
- label: params.net_name, 0, 22, fontSize=50, anchor="middle"
162
+ label: params.net_name, 0, 22, fontSize=50, anchor="center"
163
163
  type: "net"
164
164
  params:
165
165
  net_name: net_name
@@ -175,7 +175,7 @@ def dgnd(net_name="GND"):
175
175
  display: create graphic (params):
176
176
  triangle: 0, 0, 0, height, width
177
177
  vpin: 1, 0, -50, 50, display_id=false
178
- label: params.net_name, 0, height + 50, fontSize=50, anchor="middle", vanchor="middle"
178
+ label: params.net_name, 0, height + 50, fontSize=50, anchor="center", vanchor="center"
179
179
  type: "net"
180
180
  params:
181
181
  net_name: net_name
@@ -296,30 +296,30 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
296
296
  content: i
297
297
  offset: tmp_x + tmp_width * ratio_x * (0.5 + (i-1)), tmp_y + inner_frame_margin * 0.5 + 2
298
298
  fontSize: fontSize
299
- anchor: "middle"
300
- vanchor: "middle"
299
+ anchor: "center"
300
+ vanchor: "center"
301
301
 
302
302
  text:
303
303
  content: i
304
304
  offset: tmp_x + tmp_width * ratio_x * (0.5 + (i-1)), tmp_y + tmp_height - inner_frame_margin * 0.5 + 2
305
305
  fontSize: fontSize
306
- anchor: "middle"
307
- vanchor: "middle"
306
+ anchor: "center"
307
+ vanchor: "center"
308
308
 
309
309
  for index, val in enumerate(row_display_value):
310
310
  text:
311
311
  content: val
312
312
  offset: tmp_x + inner_frame_margin * 0.5, tmp_y + tmp_height * ratio_y * (0.5 + index)
313
313
  fontSize: fontSize
314
- anchor: "middle"
315
- vanchor: "middle"
314
+ anchor: "center"
315
+ vanchor: "center"
316
316
 
317
317
  text:
318
318
  content: val
319
319
  offset: tmp_x + tmp_width - inner_frame_margin * 0.5, tmp_y + tmp_height * ratio_y * (0.5 + index)
320
320
  fontSize: fontSize
321
- anchor: "middle"
322
- vanchor: "middle"
321
+ anchor: "center"
322
+ vanchor: "center"
323
323
 
324
324
  # Draw title frame
325
325
  text:
@@ -375,47 +375,47 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
375
375
  grid_height: paper_height - 2 * margin_y
376
376
 
377
377
  def sheet_A1():
378
- paper_width = toMils(841)
379
- paper_height = toMils(594)
378
+ paper_width = to_mils(841)
379
+ paper_height = to_mils(594)
380
380
  margin = 400
381
381
 
382
382
  return sheet_generator("A1", paper_width, paper_height, margin, margin,
383
383
  range(1, 17), ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"])
384
384
 
385
385
  def sheet_A2():
386
- paper_width = toMils(594)
387
- paper_height = toMils(420)
386
+ paper_width = to_mils(594)
387
+ paper_height = to_mils(420)
388
388
  margin = 400
389
389
 
390
390
  return sheet_generator("A2", paper_width, paper_height, margin, margin,
391
391
  range(1, 13), ["A", "B", "C", "D", "E", "F", "G", "H"])
392
392
 
393
393
  def sheet_A3():
394
- paper_width = toMils(420)
395
- paper_height = toMils(297)
394
+ paper_width = to_mils(420)
395
+ paper_height = to_mils(297)
396
396
  margin = 400
397
397
 
398
398
  return sheet_generator("A3", paper_width, paper_height, margin, margin,
399
399
  range(1, 9), ["A", "B", "C", "D", "E", "F"])
400
400
 
401
401
  def sheet_A4():
402
- paper_width = toMils(297)
403
- paper_height = toMils(210)
402
+ paper_width = to_mils(297)
403
+ paper_height = to_mils(210)
404
404
  margin = 400
405
405
 
406
406
  return sheet_generator("A4", paper_width, paper_height, margin, margin,
407
407
  range(1, 7), ["A", "B", "C", "D"])
408
408
 
409
409
  def sheet_A5():
410
- paper_width = toMils(210)
411
- paper_height = toMils(148)
410
+ paper_width = to_mils(210)
411
+ paper_height = to_mils(148)
412
412
  margin = 400
413
413
 
414
414
  return sheet_generator("A5", paper_width, paper_height, margin, margin, range(1, 5), ["A", "B", "C"])
415
415
 
416
416
  def sheet_A6(revision="V1"):
417
- paper_width = toMils(148)
418
- paper_height = toMils(105)
417
+ paper_width = to_mils(148)
418
+ paper_height = to_mils(105)
419
419
  margin = 400
420
420
 
421
421
  tmp_sheet = sheet_generator("A6", paper_width, paper_height, margin, margin, range(1, 4), ["A", "B"])
@@ -7,10 +7,11 @@ import { Net } from "./objects/Net.js";
7
7
  import { CallableParameter, ComplexType, Direction, FunctionDefinedParameter, AnyReference, ImportedLibrary, NewContextOptions, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
8
8
  import { CommonTokenStream, ParserRuleContext } from 'antlr4ng';
9
9
  import { ExecutionWarning } from "./utils.js";
10
- import { BaseError } from './utils.js';
10
+ import { BaseError } from './errors.js';
11
11
  import { ExecutionScope } from './objects/ExecutionScope.js';
12
12
  import { NodeScriptEnvironment } from "./environment/environment.js";
13
13
  import { PinId } from './objects/PinDefinition.js';
14
+ import { Wire } from './objects/Wire.js';
14
15
  export declare class BaseVisitor extends CircuitScriptParserVisitor<ComplexType | AnyReference | any> {
15
16
  startingContext: ExecutionContext;
16
17
  executionStack: ExecutionContext[];
@@ -23,6 +24,7 @@ export declare class BaseVisitor extends CircuitScriptParserVisitor<ComplexType
23
24
  acceptedDirections: Direction[];
24
25
  protected resultData: Map<ParserRuleContext, any>;
25
26
  protected componentCtxLinks: Map<ParserRuleContext, ClassComponent>;
27
+ wireCtxLinks: Map<Wire, ParserRuleContext>;
26
28
  onErrorHandler: OnErrorHandler | null;
27
29
  environment: NodeScriptEnvironment;
28
30
  protected importedFiles: ImportLibraryFile[];
@@ -0,0 +1,37 @@
1
+ import { Token, ParserRuleContext } from "antlr4ng";
2
+ import { Wire } from "./objects/Wire.js";
3
+ export declare class BaseError extends Error {
4
+ name: string;
5
+ message: string;
6
+ startToken?: Token;
7
+ endToken?: Token;
8
+ filePath?: string;
9
+ constructor(message: string, startTokenOrCtx?: Token | ParserRuleContext, endToken?: Token, filePath?: string, options?: ErrorOptions);
10
+ toString(): string;
11
+ }
12
+ export declare function getLinePositionAsString(ctx: ParserRuleContext): string | null;
13
+ export declare function throwWithContext(context: ParserRuleContext, messageOrError: string | BaseError): void;
14
+ export declare function throwWithTokenRange(message: string, startToken: Token, endToken?: Token): void;
15
+ export declare class RenderError extends Error {
16
+ stage?: string;
17
+ constructor(message: string, stage?: string, options?: ErrorOptions);
18
+ }
19
+ export declare class AutoWireFailedError_ extends Error {
20
+ name: string;
21
+ wire: Wire;
22
+ constructor(message: string, wire: Wire);
23
+ }
24
+ export declare class AutoWireFailedError extends BaseError {
25
+ name: string;
26
+ }
27
+ export declare class RuntimeExecutionError extends BaseError {
28
+ name: string;
29
+ }
30
+ export declare class ParseSyntaxError extends BaseError {
31
+ name: string;
32
+ }
33
+ export declare class ParseError extends ParseSyntaxError {
34
+ name: string;
35
+ }
36
+ export declare function collectErrorChain(error: Error): Error[];
37
+ export declare function printErrorChain(error: Error): void;
@@ -92,7 +92,7 @@ export declare class ExecutionContext {
92
92
  resolveTrailers(type: ReferenceTypes, item: any, trailers?: string[]): AnyReference;
93
93
  callFunction(functionReference: AnyReference, functionParams: CallableParameter[], executionStack: ExecutionContext[], netNamespace: string): CFunctionResult;
94
94
  mergeScope(childScope: ExecutionScope, namespace: string): ClassComponent[];
95
- addWire(segments: [string, (number | UnitDimension)?][]): Wire;
95
+ addWire(segments: [string, (number | UnitDimension)?][], ctx: ParserRuleContext): Wire;
96
96
  addPoint(pointId: string, userDefined?: boolean): ComponentPin;
97
97
  private getPointSymbol;
98
98
  applyComponentAngleFromWire(component: ClassComponent, pin: number, opposite?: boolean): void;
@@ -1,5 +1,5 @@
1
1
  import { ParserRuleContext } from "antlr4ng";
2
- import { BaseError } from "./utils.js";
2
+ import { BaseError } from './errors.js';
3
3
  import { ATNSimulator, BaseErrorListener, CommonTokenStream, DefaultErrorStrategy, Parser, RecognitionException, Recognizer, Token } from "antlr4ng";
4
4
  import { CircuitScriptParser, ScriptContext } from "./antlr/CircuitScriptParser.js";
5
5
  import { CircuitScriptLexer } from "./antlr/CircuitScriptLexer.js";
@@ -7,6 +7,7 @@ export declare class NumericValue {
7
7
  prefixPart: number;
8
8
  constructor(value: string | number | Big, prefix?: number);
9
9
  toString(): string;
10
+ copy(): NumericValue;
10
11
  toDisplayString(): string;
11
12
  toNumber(): number;
12
13
  toBigNumber(): Big;
@@ -18,6 +19,9 @@ export declare class NumericValue {
18
19
  mod(value: NumericValue | number): NumericValue;
19
20
  neg(): NumericValue;
20
21
  eq(value: NumericValue): boolean;
22
+ floor(): NumericValue;
23
+ ceil(): NumericValue;
24
+ roundDp(): NumericValue;
21
25
  }
22
26
  export type NumberOperatorType = NumericValue | PercentageValue | WrappedNumber;
23
27
  export declare class NumberOperator {
@@ -32,4 +36,4 @@ export declare function numeric(value: number | string): NumericValue;
32
36
  export declare function getNumberExponentialText(value: number): string;
33
37
  export declare function getNumberExponential(value: string): number;
34
38
  export declare function resolveToNumericValue(value: Big): NumericValue;
35
- export declare function roundValue(value: NumericValue): NumericValue;
39
+ export declare function roundValue(value: NumericValue | number): NumericValue;
@@ -14,8 +14,8 @@ export type LabelStyle = {
14
14
  fontSize?: NumericValue;
15
15
  fontWeight?: string;
16
16
  angle?: NumericValue;
17
- anchor?: HorizontalAlign.Left | HorizontalAlign.Middle | HorizontalAlign.Right;
18
- vanchor?: VerticalAlign.Top | VerticalAlign.Middle | VerticalAlign.Bottom;
17
+ anchor?: HorizontalAlign.Left | HorizontalAlign.Center | HorizontalAlign.Right;
18
+ vanchor?: VerticalAlign.Top | VerticalAlign.Center | VerticalAlign.Bottom;
19
19
  textColor?: string;
20
20
  portType?: null | PinTypes;
21
21
  };
@@ -84,12 +84,12 @@ export declare class Geometry {
84
84
  type WirePointCount = [x: number, y: number, count: number];
85
85
  export declare enum HorizontalAlign {
86
86
  Left = "left",
87
- Middle = "middle",
87
+ Center = "center",
88
88
  Right = "right"
89
89
  }
90
90
  export declare enum VerticalAlign {
91
91
  Top = "top",
92
- Middle = "middle",
92
+ Center = "center",
93
93
  Bottom = "bottom"
94
94
  }
95
95
  export declare enum HorizontalAlignProp {
@@ -118,15 +118,21 @@ export declare class RenderFrame extends RenderObject {
118
118
  padding: NumericValue;
119
119
  gap: NumericValue;
120
120
  borderWidth: NumericValue;
121
+ borderColor: string;
121
122
  direction: FramePlotDirection;
122
123
  width: NumericValue | null;
123
124
  height: NumericValue | null;
124
125
  subgraphId: string;
125
126
  renderType: RenderFrameType;
126
127
  containsTitle: boolean;
128
+ overwriteAlignParamsForTitleLayout: boolean;
129
+ virtual: boolean;
130
+ didResize: boolean;
131
+ lineIndex: number;
127
132
  frameId: number;
128
- constructor(frame: Frame, type?: RenderFrameType);
133
+ constructor(frame: Frame, type?: RenderFrameType, virtual?: boolean);
129
134
  toString(): string;
135
+ static createContainer(gap: NumericValue): RenderFrame;
130
136
  }
131
137
  export declare enum RenderFrameType {
132
138
  Container = 1,
@@ -1,4 +1,4 @@
1
- import { ParserRuleContext, Token } from "antlr4ng";
1
+ import { ParserRuleContext } from "antlr4ng";
2
2
  import { ClassComponent } from "./objects/ClassComponent.js";
3
3
  import { SequenceAction, SequenceItem } from './objects/ExecutionScope.js';
4
4
  import { BlockTypes } from "./objects/BlockTypes.js";
@@ -24,43 +24,18 @@ export declare function resizeBounds(bounds: BoundBox, value: number): BoundBox;
24
24
  export declare function printBounds(bounds: BoundBox): string;
25
25
  export declare function resizeToNearestGrid(bounds: BoundBox, gridSize?: number): BoundBox;
26
26
  export declare function toNearestGrid(value: number, gridSize: number): number;
27
+ export declare function toNearestGrid2(value: number, gridSize: number): number;
27
28
  export declare function getBoundsSize(bounds: BoundBox): {
28
29
  width: number;
29
30
  height: number;
30
31
  };
31
32
  export declare function getPortType(component: ClassComponent): string | null;
32
- export declare function throwWithContext(context: ParserRuleContext, messageOrError: string | BaseError): void;
33
- export declare function throwWithToken(message: string, token: Token): void;
34
- export declare function throwWithTokenRange(message: string, startToken: Token, endToken?: Token): void;
35
33
  export declare function combineMaps(map1: Map<string, any>, map2: Map<string, any>): Map<string, any>;
36
34
  export declare function isPointWithinArea(point: [x: number, y: number], bounds: BoundBox2): boolean;
37
35
  export declare function areasOverlap(area1: BoundBox2, area2: BoundBox2): boolean;
38
36
  export declare function sequenceActionString(sequenceAction: SequenceAction): string;
39
37
  export declare function generateDebugSequenceAction(sequence: SequenceItem[]): string[];
40
38
  export declare function getBlockTypeString(type: BlockTypes): string;
41
- export declare class BaseError extends Error {
42
- name: string;
43
- message: string;
44
- startToken?: Token;
45
- endToken?: Token;
46
- filePath?: string;
47
- constructor(message: string, startTokenOrCtx?: Token | ParserRuleContext, endToken?: Token, filePath?: string);
48
- toString(): string;
49
- }
50
- export declare function getLinePositionAsString(ctx: ParserRuleContext): string | null;
51
- export declare class ParseSyntaxError extends BaseError {
52
- name: string;
53
- }
54
- export declare class ParseError extends ParseSyntaxError {
55
- name: string;
56
- }
57
- export declare class RuntimeExecutionError extends BaseError {
58
- name: string;
59
- }
60
- export declare class RenderError extends Error {
61
- stage?: string;
62
- constructor(message: string, stage?: string);
63
- }
64
39
  export type ExecutionWarning = {
65
40
  message: string;
66
41
  fileName?: string;