circuitscript 0.0.38 → 0.1.2
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 +69 -46
- package/dist/cjs/SymbolValidatorVisitor.js +1 -1
- package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
- package/dist/cjs/antlr/CircuitScriptParser.js +580 -613
- package/dist/cjs/builtinMethods.js +32 -10
- package/dist/cjs/draw_symbols.js +375 -233
- package/dist/cjs/execute.js +142 -131
- package/dist/cjs/export.js +2 -4
- package/dist/cjs/geometry.js +52 -19
- package/dist/cjs/globals.js +14 -9
- package/dist/cjs/helpers.js +16 -3
- package/dist/cjs/layout.js +143 -151
- package/dist/cjs/logger.js +8 -1
- package/dist/cjs/objects/ClassComponent.js +22 -22
- package/dist/cjs/objects/ExecutionScope.js +10 -4
- package/dist/cjs/objects/Frame.js +4 -1
- package/dist/cjs/objects/ParamDefinition.js +120 -4
- package/dist/cjs/objects/PinDefinition.js +1 -4
- package/dist/cjs/objects/types.js +41 -0
- package/dist/cjs/render.js +41 -110
- package/dist/cjs/sizing.js +33 -7
- package/dist/cjs/utils.js +92 -2
- package/dist/cjs/visitor.js +279 -284
- package/dist/esm/BaseVisitor.mjs +70 -47
- package/dist/esm/SymbolValidatorVisitor.mjs +1 -1
- package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
- package/dist/esm/antlr/CircuitScriptParser.mjs +580 -613
- package/dist/esm/builtinMethods.mjs +29 -10
- package/dist/esm/draw_symbols.mjs +381 -238
- package/dist/esm/execute.mjs +144 -133
- package/dist/esm/export.mjs +2 -4
- package/dist/esm/geometry.mjs +52 -19
- package/dist/esm/globals.mjs +13 -8
- package/dist/esm/helpers.mjs +17 -4
- package/dist/esm/layout.mjs +144 -153
- package/dist/esm/logger.mjs +8 -1
- package/dist/esm/objects/ClassComponent.mjs +21 -26
- package/dist/esm/objects/ExecutionScope.mjs +10 -4
- package/dist/esm/objects/Frame.mjs +4 -1
- package/dist/esm/objects/ParamDefinition.mjs +119 -3
- package/dist/esm/objects/PinDefinition.mjs +0 -2
- package/dist/esm/objects/types.mjs +42 -0
- package/dist/esm/render.mjs +44 -113
- package/dist/esm/sizing.mjs +34 -8
- package/dist/esm/utils.mjs +86 -1
- package/dist/esm/visitor.mjs +281 -286
- package/dist/types/BaseVisitor.d.ts +3 -2
- package/dist/types/antlr/CircuitScriptParser.d.ts +5 -3
- package/dist/types/draw_symbols.d.ts +81 -49
- package/dist/types/execute.d.ts +16 -11
- package/dist/types/geometry.d.ts +31 -19
- package/dist/types/globals.d.ts +15 -10
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +22 -21
- package/dist/types/logger.d.ts +1 -1
- package/dist/types/objects/ClassComponent.d.ts +19 -16
- package/dist/types/objects/ExecutionScope.d.ts +2 -1
- package/dist/types/objects/Frame.d.ts +5 -3
- package/dist/types/objects/ParamDefinition.d.ts +31 -2
- package/dist/types/objects/PinDefinition.d.ts +0 -2
- package/dist/types/objects/types.d.ts +7 -2
- package/dist/types/render.d.ts +2 -1
- package/dist/types/utils.d.ts +9 -1
- package/dist/types/visitor.d.ts +5 -5
- package/libs/lib.cst +102 -32
- package/package.json +7 -3
package/dist/esm/layout.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Graph, alg } from '@dagrejs/graphlib';
|
|
2
|
-
import { SymbolCustom, SymbolDrawing,
|
|
2
|
+
import { SymbolCustom, SymbolDrawing, SymbolCustomModule, SymbolPlaceholder, SymbolText, PlaceHolderCommands } from "./draw_symbols.mjs";
|
|
3
3
|
import { FrameAction, SequenceAction } from "./objects/ExecutionScope.mjs";
|
|
4
|
-
import { defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType,
|
|
5
|
-
import { NumericValue } from './objects/ParamDefinition.mjs';
|
|
4
|
+
import { ComponentTypes, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, ParamKeys, SymbolPinSide, WireAutoDirection } from './globals.mjs';
|
|
6
5
|
import { Geometry } from './geometry.mjs';
|
|
7
6
|
import { Logger } from './logger.mjs';
|
|
8
7
|
import { Frame, FrameParamKeys, FramePlotDirection } from './objects/Frame.mjs';
|
|
9
|
-
import { getBoundsSize, printBounds, resizeBounds, resizeToNearestGrid, roundValue, toNearestGrid } from './utils.mjs';
|
|
8
|
+
import { combineMaps, getBoundsSize, printBounds, resizeBounds, resizeToNearestGrid, roundValue, toNearestGrid } from './utils.mjs';
|
|
10
9
|
import { Direction } from './objects/types.mjs';
|
|
11
10
|
import { milsToMM, UnitDimension } from './helpers.mjs';
|
|
11
|
+
import { numeric, NumericValue } from './objects/ParamDefinition.mjs';
|
|
12
12
|
export class LayoutEngine {
|
|
13
13
|
logger;
|
|
14
14
|
placeSubgraphVersion = 2;
|
|
@@ -114,8 +114,8 @@ export class LayoutEngine {
|
|
|
114
114
|
const allLines = wires.map(wire => {
|
|
115
115
|
return wire.points.map(pt => {
|
|
116
116
|
return {
|
|
117
|
-
x: wire.x
|
|
118
|
-
y: wire.y
|
|
117
|
+
x: wire.x.add(pt.x),
|
|
118
|
+
y: wire.y.add(pt.y),
|
|
119
119
|
};
|
|
120
120
|
});
|
|
121
121
|
});
|
|
@@ -126,7 +126,7 @@ export class LayoutEngine {
|
|
|
126
126
|
intersectPoints,
|
|
127
127
|
});
|
|
128
128
|
intersectPoints.forEach(([x, y]) => {
|
|
129
|
-
junctions.push(new RenderJunction(x, y));
|
|
129
|
+
junctions.push(new RenderJunction(numeric(x), numeric(y)));
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
return {
|
|
@@ -136,15 +136,15 @@ export class LayoutEngine {
|
|
|
136
136
|
}
|
|
137
137
|
placeFrames(graph, subgraphInfo, frameObjects) {
|
|
138
138
|
const baseFrame = frameObjects[0];
|
|
139
|
-
baseFrame.padding = 0;
|
|
140
|
-
baseFrame.borderWidth = 0;
|
|
139
|
+
baseFrame.padding = numeric(0);
|
|
140
|
+
baseFrame.borderWidth = numeric(0);
|
|
141
141
|
if (this.showBaseFrame) {
|
|
142
|
-
baseFrame.borderWidth = 5;
|
|
142
|
+
baseFrame.borderWidth = numeric(5);
|
|
143
143
|
baseFrame.width = 11692 - 400 * 2;
|
|
144
144
|
baseFrame.height = 8267 - 400 * 2;
|
|
145
145
|
}
|
|
146
|
-
baseFrame.x = 0;
|
|
147
|
-
baseFrame.y = 0;
|
|
146
|
+
baseFrame.x = numeric(0);
|
|
147
|
+
baseFrame.y = numeric(0);
|
|
148
148
|
let textObjects = [];
|
|
149
149
|
let elementFrames = [];
|
|
150
150
|
baseFrame.bounds = {
|
|
@@ -190,18 +190,18 @@ export class LayoutEngine {
|
|
|
190
190
|
const innerItems = frame.innerItems;
|
|
191
191
|
innerItems.forEach(innerFrame => {
|
|
192
192
|
if (innerFrame.frame.frameType === FrameType.Sheet) {
|
|
193
|
-
innerFrame.x = 0;
|
|
194
|
-
innerFrame.y = 0;
|
|
193
|
+
innerFrame.x = numeric(0);
|
|
194
|
+
innerFrame.y = numeric(0);
|
|
195
195
|
}
|
|
196
196
|
else {
|
|
197
|
-
innerFrame.x
|
|
198
|
-
innerFrame.y
|
|
197
|
+
innerFrame.x = innerFrame.x.add(frame.x);
|
|
198
|
+
innerFrame.y = innerFrame.y.add(frame.y);
|
|
199
199
|
}
|
|
200
200
|
if (innerFrame.type === RenderFrameType.Elements) {
|
|
201
201
|
this.print(level, "".padStart(level * 4), 'element frame', innerFrame.x, innerFrame.y);
|
|
202
202
|
innerFrame.innerItems.forEach(item2 => {
|
|
203
|
-
item2.x
|
|
204
|
-
item2.y
|
|
203
|
+
item2.x = item2.x.add(innerFrame.x).sub(innerFrame.translateX);
|
|
204
|
+
item2.y = item2.y.add(innerFrame.y).sub(innerFrame.translateY);
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
207
|
else {
|
|
@@ -213,8 +213,8 @@ export class LayoutEngine {
|
|
|
213
213
|
placeAndSizeFrame(frame, level = 0) {
|
|
214
214
|
const innerFrames = frame.innerItems;
|
|
215
215
|
const gridSize = defaultGridSizeUnits;
|
|
216
|
-
let accumX = 0;
|
|
217
|
-
let accumY = 0;
|
|
216
|
+
let accumX = numeric(0);
|
|
217
|
+
let accumY = numeric(0);
|
|
218
218
|
const boundPoints = [];
|
|
219
219
|
const frameSizes = innerFrames.map(innerFrame => {
|
|
220
220
|
if (innerFrame.type === RenderFrameType.Elements) {
|
|
@@ -242,7 +242,7 @@ export class LayoutEngine {
|
|
|
242
242
|
return accum;
|
|
243
243
|
}
|
|
244
244
|
return accum + width +
|
|
245
|
-
((index + 1 < frameSizes.length) ? frame.gap : 0);
|
|
245
|
+
((index + 1 < frameSizes.length) ? frame.gap.toNumber() : 0);
|
|
246
246
|
}, 0);
|
|
247
247
|
}
|
|
248
248
|
else {
|
|
@@ -266,47 +266,55 @@ export class LayoutEngine {
|
|
|
266
266
|
innerFrames.forEach(innerFrame => {
|
|
267
267
|
const { width: frameWidth, height: frameHeight } = getBoundsSize(innerFrame.bounds);
|
|
268
268
|
if (innerFrame.containsTitle) {
|
|
269
|
-
innerFrame.x = offsetX
|
|
270
|
-
innerFrame.y = offsetY
|
|
271
|
-
accumY
|
|
269
|
+
innerFrame.x = offsetX.add(accumX).add(toNearestGrid(widthForTitle / 2 - frameWidth / 2, gridSize));
|
|
270
|
+
innerFrame.y = offsetY.add(accumY);
|
|
271
|
+
accumY = accumY.add(frameHeight).add(frame.gap);
|
|
272
272
|
}
|
|
273
273
|
else {
|
|
274
274
|
if (frame.direction === FramePlotDirection.Column) {
|
|
275
|
-
innerFrame.x = offsetX
|
|
276
|
-
innerFrame.y = offsetY
|
|
277
|
-
accumY
|
|
275
|
+
innerFrame.x = offsetX.add(accumX).add(toNearestGrid(maxWidth / 2 - frameWidth / 2, gridSize));
|
|
276
|
+
innerFrame.y = offsetY.add(accumY);
|
|
277
|
+
accumY = accumY.add(frameHeight).add(frame.gap);
|
|
278
278
|
}
|
|
279
279
|
else if (frame.direction === FramePlotDirection.Row) {
|
|
280
|
-
innerFrame.x = offsetX
|
|
281
|
-
innerFrame.y = offsetY
|
|
282
|
-
accumX
|
|
280
|
+
innerFrame.x = offsetX.add(centeredOffsetX).add(accumX);
|
|
281
|
+
innerFrame.y = offsetY.add(accumY);
|
|
282
|
+
accumX = accumX.add(frameWidth).add(frame.gap);
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
-
boundPoints.push([innerFrame.x, innerFrame.y], [innerFrame.x
|
|
285
|
+
boundPoints.push([innerFrame.x, innerFrame.y], [innerFrame.x.add(frameWidth), innerFrame.y.add(frameHeight)]);
|
|
286
286
|
});
|
|
287
|
-
const
|
|
287
|
+
const tmpBoundPoints = boundPoints.map(item => {
|
|
288
|
+
return [
|
|
289
|
+
item[0].toNumber(),
|
|
290
|
+
item[1].toNumber(),
|
|
291
|
+
];
|
|
292
|
+
});
|
|
293
|
+
const contentsBounds = resizeBounds(getBoundsFromPoints(tmpBoundPoints), frame.padding.toNumber());
|
|
288
294
|
if (frame.frame.parameters.has(FrameParamKeys.SheetType)) {
|
|
289
295
|
const frameComponent = frame.frame.parameters.get(FrameParamKeys.SheetType);
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
296
|
+
const frameDrawing = frameComponent.displayProp;
|
|
297
|
+
frameDrawing.variables = combineMaps(frameComponent.parameters, frame.frame.parameters);
|
|
298
|
+
const rects = ExtractDrawingRects(frameDrawing);
|
|
299
|
+
let frameWidth = numeric(0);
|
|
300
|
+
let frameHeight = numeric(0);
|
|
293
301
|
if (rects[1]) {
|
|
294
302
|
frameWidth = milsToMM(rects[1].width);
|
|
295
303
|
frameHeight = milsToMM(rects[1].height);
|
|
296
304
|
}
|
|
297
305
|
const contentsWidth = contentsBounds.xmax - contentsBounds.xmin;
|
|
298
306
|
const contentsHeight = contentsBounds.ymax - contentsBounds.ymin;
|
|
299
|
-
const frameOffsetX = toNearestGrid((frameWidth - contentsWidth) / 2, gridSize);
|
|
300
|
-
const frameOffsetY = toNearestGrid((frameHeight - contentsHeight) / 2, gridSize);
|
|
307
|
+
const frameOffsetX = toNearestGrid((frameWidth.toNumber() - contentsWidth) / 2, gridSize);
|
|
308
|
+
const frameOffsetY = toNearestGrid((frameHeight.toNumber() - contentsHeight) / 2, gridSize);
|
|
301
309
|
innerFrames.forEach(innerFrame => {
|
|
302
|
-
innerFrame.x
|
|
303
|
-
innerFrame.y
|
|
310
|
+
innerFrame.x = innerFrame.x.add(frameOffsetX);
|
|
311
|
+
innerFrame.y = innerFrame.y.add(frameOffsetY);
|
|
304
312
|
});
|
|
305
313
|
frame.bounds = {
|
|
306
314
|
xmin: 0,
|
|
307
315
|
ymin: 0,
|
|
308
|
-
xmax: frameWidth,
|
|
309
|
-
ymax: frameHeight
|
|
316
|
+
xmax: frameWidth.toNumber(),
|
|
317
|
+
ymax: frameHeight.toNumber(),
|
|
310
318
|
};
|
|
311
319
|
}
|
|
312
320
|
else {
|
|
@@ -373,13 +381,14 @@ export class LayoutEngine {
|
|
|
373
381
|
}, []);
|
|
374
382
|
if (frame.type === RenderFrameType.Container) {
|
|
375
383
|
const frameObject = frame.frame;
|
|
376
|
-
|
|
384
|
+
const isSheetFrame = frameObject.frameType === FrameType.Sheet;
|
|
385
|
+
if (frameObject.parameters.has(FrameParamKeys.Title) && !isSheetFrame) {
|
|
377
386
|
const title = frameObject.parameters.get(FrameParamKeys.Title);
|
|
378
387
|
const tmpFrame = new RenderFrame(new Frame(-2), RenderFrameType.Elements);
|
|
379
388
|
tmpFrame.containsTitle = true;
|
|
380
389
|
tmpFrame.subgraphId = title.replace(/\s/g, "_");
|
|
381
390
|
const textObject = new RenderText(title);
|
|
382
|
-
textObject.fontSize = defaultFrameTitleTextSize;
|
|
391
|
+
textObject.fontSize = numeric(defaultFrameTitleTextSize);
|
|
383
392
|
textObject.fontWeight = 'bold';
|
|
384
393
|
textObject.symbol.refreshDrawing();
|
|
385
394
|
tmpFrame.innerItems.push(textObject);
|
|
@@ -390,8 +399,8 @@ export class LayoutEngine {
|
|
|
390
399
|
xmax: tmpBox.start[0] + tmpBox.width,
|
|
391
400
|
ymax: tmpBox.start[1] + tmpBox.height
|
|
392
401
|
};
|
|
393
|
-
textObject.x = 0;
|
|
394
|
-
textObject.y = 0;
|
|
402
|
+
textObject.x = numeric(0);
|
|
403
|
+
textObject.y = numeric(0);
|
|
395
404
|
frame.innerItems.splice(0, 0, tmpFrame);
|
|
396
405
|
this.printLevel(level, frame, 'added text', tmpFrame);
|
|
397
406
|
textObjects.push(textObject);
|
|
@@ -424,46 +433,43 @@ export class LayoutEngine {
|
|
|
424
433
|
const tmpInstanceName = component.instanceName;
|
|
425
434
|
if (!graph.hasNode(tmpInstanceName)) {
|
|
426
435
|
this.print('create instance', tmpInstanceName);
|
|
427
|
-
|
|
436
|
+
const { displayProp = null, widthProp = null, heightProp = null } = component;
|
|
428
437
|
let tmpSymbol;
|
|
429
|
-
if (displayProp
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
if (displayProp !== null) {
|
|
434
|
-
if (displayProp instanceof SymbolDrawing) {
|
|
435
|
-
tmpSymbol = new SymbolPlaceholder(displayProp);
|
|
436
|
-
tmpSymbol.drawing.logger = this.logger;
|
|
437
|
-
}
|
|
438
|
-
else if (typeof displayProp === "string") {
|
|
439
|
-
tmpSymbol = SymbolFactory(displayProp);
|
|
440
|
-
}
|
|
438
|
+
if (displayProp instanceof SymbolDrawing) {
|
|
439
|
+
tmpSymbol = new SymbolPlaceholder(displayProp);
|
|
440
|
+
tmpSymbol.drawing.logger = this.logger;
|
|
441
441
|
}
|
|
442
442
|
else {
|
|
443
443
|
const symbolPinDefinitions = generateLayoutPinDefinition(component);
|
|
444
|
-
if (component.typeProp ===
|
|
445
|
-
tmpSymbol = new SymbolCustomModule(symbolPinDefinitions);
|
|
444
|
+
if (component.typeProp === ComponentTypes.module) {
|
|
445
|
+
tmpSymbol = new SymbolCustomModule(symbolPinDefinitions, component.pinsMaxPositions);
|
|
446
446
|
}
|
|
447
447
|
else {
|
|
448
|
-
tmpSymbol = new SymbolCustom(symbolPinDefinitions);
|
|
448
|
+
tmpSymbol = new SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
|
|
449
449
|
}
|
|
450
450
|
}
|
|
451
|
-
applyComponentParamsToSymbol(
|
|
451
|
+
applyComponentParamsToSymbol(component, tmpSymbol);
|
|
452
452
|
let didSetAngle = false;
|
|
453
|
-
if (component.parameters.has(
|
|
453
|
+
if (component.parameters.has(ParamKeys.angle)) {
|
|
454
454
|
didSetAngle = true;
|
|
455
|
-
|
|
455
|
+
const value = component.parameters.get(ParamKeys.angle).toNumber();
|
|
456
|
+
tmpSymbol.angle = value;
|
|
456
457
|
}
|
|
457
|
-
if (component.parameters.has(
|
|
458
|
+
if (component.parameters.has(ParamKeys.flipX)) {
|
|
458
459
|
tmpSymbol.flipX =
|
|
459
|
-
component.parameters.get(
|
|
460
|
+
component.parameters.get(ParamKeys.flipX);
|
|
460
461
|
}
|
|
461
|
-
if (component.parameters.has(
|
|
462
|
+
if (component.parameters.has(ParamKeys.flipY)) {
|
|
462
463
|
tmpSymbol.flipY =
|
|
463
|
-
component.parameters.get(
|
|
464
|
+
component.parameters.get(ParamKeys.flipY);
|
|
464
465
|
}
|
|
465
|
-
if (tmpSymbol instanceof SymbolCustom
|
|
466
|
-
|
|
466
|
+
if (tmpSymbol instanceof SymbolCustom) {
|
|
467
|
+
if (widthProp) {
|
|
468
|
+
tmpSymbol.bodyWidth = milsToMM(widthProp);
|
|
469
|
+
}
|
|
470
|
+
if (heightProp) {
|
|
471
|
+
tmpSymbol.bodyHeight = milsToMM(heightProp);
|
|
472
|
+
}
|
|
467
473
|
}
|
|
468
474
|
if (!didSetAngle && component.parameters.has('_addDirection')) {
|
|
469
475
|
tmpSymbol.refreshDrawing(false);
|
|
@@ -485,7 +491,7 @@ export class LayoutEngine {
|
|
|
485
491
|
}
|
|
486
492
|
else if (action === SequenceAction.Wire) {
|
|
487
493
|
const [, wireId, wireSegments] = sequence[i];
|
|
488
|
-
const wire = new RenderWire(0, 0, wireSegments);
|
|
494
|
+
const wire = new RenderWire(numeric(0), numeric(0), wireSegments);
|
|
489
495
|
wire.id = wireId;
|
|
490
496
|
let useNetName = null;
|
|
491
497
|
if (previousNode !== null) {
|
|
@@ -649,7 +655,7 @@ export class LayoutEngine {
|
|
|
649
655
|
}
|
|
650
656
|
if (subgraphEdges.length === 0) {
|
|
651
657
|
const [, node1] = graph.node(firstNodeId);
|
|
652
|
-
this.placeNodeAtPosition(0, 0, node1, 1);
|
|
658
|
+
this.placeNodeAtPosition(numeric(0), numeric(0), node1, 1);
|
|
653
659
|
return;
|
|
654
660
|
}
|
|
655
661
|
let fixedNode;
|
|
@@ -662,7 +668,7 @@ export class LayoutEngine {
|
|
|
662
668
|
const [, node2] = graph.node(nodeId2);
|
|
663
669
|
if (nodeId1 === firstNodeId && !firstNodePlaced) {
|
|
664
670
|
this.print('first node placed at origin');
|
|
665
|
-
this.placeNodeAtPosition(0, 0, node1, pin1);
|
|
671
|
+
this.placeNodeAtPosition(numeric(0), numeric(0), node1, pin1);
|
|
666
672
|
firstNodePlaced = true;
|
|
667
673
|
node1.isFloating = false;
|
|
668
674
|
originNodes.push(node1);
|
|
@@ -685,7 +691,7 @@ export class LayoutEngine {
|
|
|
685
691
|
originNodes.push(node1);
|
|
686
692
|
originNodeGroups.set(node1.toString(), [node1]);
|
|
687
693
|
this.print('creating new origin node at', node1);
|
|
688
|
-
this.placeNodeAtPosition(0, 0, node1, pin1);
|
|
694
|
+
this.placeNodeAtPosition(numeric(0), numeric(0), node1, pin1);
|
|
689
695
|
node1.isFloating = false;
|
|
690
696
|
fixedNode = node1;
|
|
691
697
|
fixedNodePin = pin1;
|
|
@@ -702,7 +708,7 @@ export class LayoutEngine {
|
|
|
702
708
|
else {
|
|
703
709
|
const [x1, y1] = getNodePositionAtPin(node1, pin1);
|
|
704
710
|
const [x2, y2] = getNodePositionAtPin(node2, pin2);
|
|
705
|
-
if (x1
|
|
711
|
+
if (!x1.eq(x2) && !y1.eq(y2)) {
|
|
706
712
|
if (node1 instanceof RenderWire &&
|
|
707
713
|
node2 instanceof RenderComponent) {
|
|
708
714
|
const refdes = node2.component.assignedRefDes;
|
|
@@ -779,8 +785,8 @@ export class LayoutEngine {
|
|
|
779
785
|
this.print('merging origin node groups, fixed:', keepOriginNode, ', other:', otherOriginNode);
|
|
780
786
|
const [x, y] = getNodePositionAtPin(fixedNode, fixedNodePin);
|
|
781
787
|
const [otherNodeOriginX, otherNodeOriginY] = getNodePositionAtPin(mergedNode, mergedNodePin);
|
|
782
|
-
const offsetX = x
|
|
783
|
-
const offsetY = y
|
|
788
|
+
const offsetX = x.sub(otherNodeOriginX);
|
|
789
|
+
const offsetY = y.sub(otherNodeOriginY);
|
|
784
790
|
this.print('offset of other origin:', offsetX, offsetY);
|
|
785
791
|
const otherItemsLinkedToOriginNode = originNodeGroups.get(otherOriginNode);
|
|
786
792
|
this.print('nodes in other origin:', otherItemsLinkedToOriginNode);
|
|
@@ -802,7 +808,7 @@ export class LayoutEngine {
|
|
|
802
808
|
const [, node2] = graph.node(nodeId2);
|
|
803
809
|
if (nodeId1 === firstNodeId && !firstNodePlaced) {
|
|
804
810
|
this.print('first node placed at origin');
|
|
805
|
-
this.placeNodeAtPosition(0, 0, node1, pin1);
|
|
811
|
+
this.placeNodeAtPosition(numeric(0), numeric(0), node1, pin1);
|
|
806
812
|
firstNodePlaced = true;
|
|
807
813
|
node1.isFloating = false;
|
|
808
814
|
}
|
|
@@ -848,14 +854,14 @@ export class LayoutEngine {
|
|
|
848
854
|
});
|
|
849
855
|
}
|
|
850
856
|
translateNodeBy(offsetX, offsetY, item) {
|
|
851
|
-
item.x
|
|
852
|
-
item.y
|
|
857
|
+
item.x = item.x.add(offsetX);
|
|
858
|
+
item.y = item.y.add(offsetY);
|
|
853
859
|
}
|
|
854
860
|
placeNodeAtPosition(fromX, fromY, item, pin, depth = 0) {
|
|
855
861
|
if (item instanceof RenderComponent) {
|
|
856
862
|
const pinPosition = item.symbol.pinPosition(pin);
|
|
857
|
-
item.x = fromX
|
|
858
|
-
item.y = fromY
|
|
863
|
+
item.x = fromX.sub(pinPosition.x);
|
|
864
|
+
item.y = fromY.sub(pinPosition.y);
|
|
859
865
|
}
|
|
860
866
|
else if (item instanceof RenderWire) {
|
|
861
867
|
if (pin === 0) {
|
|
@@ -864,8 +870,8 @@ export class LayoutEngine {
|
|
|
864
870
|
}
|
|
865
871
|
else {
|
|
866
872
|
const wireEnd = item.getWireEnd();
|
|
867
|
-
item.x = fromX
|
|
868
|
-
item.y = fromY
|
|
873
|
+
item.x = fromX.sub(wireEnd.x);
|
|
874
|
+
item.y = fromY.sub(wireEnd.y);
|
|
869
875
|
}
|
|
870
876
|
}
|
|
871
877
|
this.print(this.padLevel(depth), 'place', item, 'pin', pin, 'at', item.x, item.y);
|
|
@@ -904,12 +910,12 @@ export class LayoutEngine {
|
|
|
904
910
|
}
|
|
905
911
|
}
|
|
906
912
|
function getNodePositionAtPin(item, pin) {
|
|
907
|
-
let x = 0;
|
|
908
|
-
let y = 0;
|
|
913
|
+
let x = numeric(0);
|
|
914
|
+
let y = numeric(0);
|
|
909
915
|
if (item instanceof RenderComponent) {
|
|
910
916
|
const pinPosition = item.symbol.pinPosition(pin);
|
|
911
|
-
x = item.x
|
|
912
|
-
y = item.y
|
|
917
|
+
x = item.x.add(pinPosition.x);
|
|
918
|
+
y = item.y.add(pinPosition.y);
|
|
913
919
|
}
|
|
914
920
|
else if (item instanceof RenderWire) {
|
|
915
921
|
if (pin === 0) {
|
|
@@ -918,8 +924,8 @@ function getNodePositionAtPin(item, pin) {
|
|
|
918
924
|
}
|
|
919
925
|
else {
|
|
920
926
|
const wireEnd = item.getWireEnd();
|
|
921
|
-
x = item.x
|
|
922
|
-
y = item.y
|
|
927
|
+
x = item.x.add(wireEnd.x);
|
|
928
|
+
y = item.y.add(wireEnd.y);
|
|
923
929
|
}
|
|
924
930
|
}
|
|
925
931
|
return [
|
|
@@ -952,7 +958,7 @@ function generateLayoutPinDefinition(component) {
|
|
|
952
958
|
const pinPosition = Math.floor(i / 2);
|
|
953
959
|
const pin = pins.get(existingPinIds[i]);
|
|
954
960
|
symbolPinDefinitions.push({
|
|
955
|
-
side: (i % 2 === 0) ?
|
|
961
|
+
side: (i % 2 === 0) ? SymbolPinSide.Left : SymbolPinSide.Right,
|
|
956
962
|
pinId: existingPinIds[i],
|
|
957
963
|
text: pin.name,
|
|
958
964
|
position: pinPosition,
|
|
@@ -971,24 +977,24 @@ function generateLayoutPinDefinition(component) {
|
|
|
971
977
|
useItems = [...items];
|
|
972
978
|
}
|
|
973
979
|
useItems.forEach(pinId => {
|
|
974
|
-
if (
|
|
975
|
-
const
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
980
|
+
if (pinId instanceof NumericValue) {
|
|
981
|
+
const pinIdValue = pinId.toNumber();
|
|
982
|
+
if (existingPinIds.indexOf(pinIdValue) !== -1) {
|
|
983
|
+
const pin = pins.get(pinIdValue);
|
|
984
|
+
symbolPinDefinitions.push({
|
|
985
|
+
side: key,
|
|
986
|
+
pinId: pinIdValue,
|
|
987
|
+
text: pin.name,
|
|
988
|
+
position: pin.position,
|
|
989
|
+
pinType: pin.pinType,
|
|
990
|
+
});
|
|
991
|
+
addedPins.push(pinIdValue);
|
|
992
|
+
}
|
|
984
993
|
}
|
|
985
994
|
});
|
|
986
995
|
}
|
|
987
|
-
const unplacedPins =
|
|
988
|
-
|
|
989
|
-
if (addedPins.indexOf(item) === -1) {
|
|
990
|
-
unplacedPins.push(item);
|
|
991
|
-
}
|
|
996
|
+
const unplacedPins = existingPinIds.filter(pinId => {
|
|
997
|
+
return addedPins.indexOf(pinId) === -1;
|
|
992
998
|
});
|
|
993
999
|
if (unplacedPins.length > 0) {
|
|
994
1000
|
throw "'arrange' property is defined, but not all pins are specified: " + unplacedPins.join(",");
|
|
@@ -996,28 +1002,12 @@ function generateLayoutPinDefinition(component) {
|
|
|
996
1002
|
}
|
|
997
1003
|
return symbolPinDefinitions;
|
|
998
1004
|
}
|
|
999
|
-
function applyComponentParamsToSymbol(
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
if (component.assignedRefDes !== null) {
|
|
1004
|
-
symbol.setLabelValue("refdes", component.assignedRefDes);
|
|
1005
|
-
}
|
|
1006
|
-
for (const [key, value] of component.parameters) {
|
|
1007
|
-
if (key !== 'refdes' && key !== 'net_name') {
|
|
1008
|
-
let useValue;
|
|
1009
|
-
if (typeof value == 'object' && (value instanceof NumericValue)) {
|
|
1010
|
-
useValue = value.toDisplayString();
|
|
1011
|
-
}
|
|
1012
|
-
else if (typeof value === 'number') {
|
|
1013
|
-
useValue = value.toString();
|
|
1014
|
-
}
|
|
1015
|
-
else if (typeof value === 'string') {
|
|
1016
|
-
useValue = value;
|
|
1017
|
-
}
|
|
1018
|
-
symbol.setLabelValue(key, useValue);
|
|
1019
|
-
}
|
|
1005
|
+
export function applyComponentParamsToSymbol(component, symbol) {
|
|
1006
|
+
const newMap = new Map(component.parameters);
|
|
1007
|
+
if (!newMap.has('refdes')) {
|
|
1008
|
+
newMap.set('refdes', component.assignedRefDes ?? "?");
|
|
1020
1009
|
}
|
|
1010
|
+
symbol.drawing.variables = newMap;
|
|
1021
1011
|
}
|
|
1022
1012
|
function calculateSymbolAngle(symbol, pin, direction) {
|
|
1023
1013
|
let directionVector = 0;
|
|
@@ -1045,21 +1035,21 @@ export function getBounds(components, wires, junctions, frames) {
|
|
|
1045
1035
|
const bbox = item.symbol.drawing.getBoundingBox();
|
|
1046
1036
|
const [x1, y1] = bbox.start;
|
|
1047
1037
|
const [x2, y2] = bbox.end;
|
|
1048
|
-
points.push([x1 + item.x, y1 + item.y]);
|
|
1049
|
-
points.push([x2 + item.x, y2 + item.y]);
|
|
1038
|
+
points.push([x1 + item.x.toNumber(), y1 + item.y.toNumber()]);
|
|
1039
|
+
points.push([x2 + item.x.toNumber(), y2 + item.y.toNumber()]);
|
|
1050
1040
|
});
|
|
1051
1041
|
wires.forEach(wire => {
|
|
1052
1042
|
wire.points.forEach(point => {
|
|
1053
|
-
points.push([wire.x
|
|
1043
|
+
points.push([wire.x.add(point.x).toNumber(), wire.y.add(point.y).toNumber()]);
|
|
1054
1044
|
});
|
|
1055
1045
|
});
|
|
1056
1046
|
junctions.forEach(item => {
|
|
1057
|
-
points.push([item.x, item.y]);
|
|
1047
|
+
points.push([item.x.toNumber(), item.y.toNumber()]);
|
|
1058
1048
|
});
|
|
1059
1049
|
frames.forEach(item => {
|
|
1060
1050
|
const { width, height } = getBoundsSize(item.bounds);
|
|
1061
|
-
points.push([item.x, item.y]);
|
|
1062
|
-
points.push([item.x + width, item.y + height]);
|
|
1051
|
+
points.push([item.x.toNumber(), item.y.toNumber()]);
|
|
1052
|
+
points.push([item.x.toNumber() + width, item.y.toNumber() + height]);
|
|
1063
1053
|
});
|
|
1064
1054
|
return getBoundsFromPoints(points);
|
|
1065
1055
|
}
|
|
@@ -1075,8 +1065,8 @@ function getBoundsFromPoints(points) {
|
|
|
1075
1065
|
};
|
|
1076
1066
|
}
|
|
1077
1067
|
export class RenderObject {
|
|
1078
|
-
x = -1;
|
|
1079
|
-
y = -1;
|
|
1068
|
+
x = numeric(-1);
|
|
1069
|
+
y = numeric(-1);
|
|
1080
1070
|
isFloating = true;
|
|
1081
1071
|
floatingRelativeTo = [];
|
|
1082
1072
|
}
|
|
@@ -1119,7 +1109,7 @@ export class RenderWire extends RenderObject {
|
|
|
1119
1109
|
tmpX += useValue;
|
|
1120
1110
|
}
|
|
1121
1111
|
else if (direction === WireAutoDirection.Auto || direction === WireAutoDirection.Auto_) {
|
|
1122
|
-
const { valueXY = [0, 0] } = segment;
|
|
1112
|
+
const { valueXY = [numeric(0), numeric(0)] } = segment;
|
|
1123
1113
|
const tmpPoints = this.getAutoPoints(valueXY, direction);
|
|
1124
1114
|
tmpPoints.forEach(point => {
|
|
1125
1115
|
if (point[0] !== 0 || point[1] !== 0) {
|
|
@@ -1137,8 +1127,8 @@ export class RenderWire extends RenderObject {
|
|
|
1137
1127
|
this.points = points;
|
|
1138
1128
|
}
|
|
1139
1129
|
getAutoPoints(value, direction) {
|
|
1140
|
-
const valueX = roundValue(value[0]);
|
|
1141
|
-
const valueY = roundValue(value[1]);
|
|
1130
|
+
const valueX = roundValue(value[0]).toNumber();
|
|
1131
|
+
const valueY = roundValue(value[1]).toNumber();
|
|
1142
1132
|
const inQuadrant = Geometry.getQuadrant(valueX, valueY);
|
|
1143
1133
|
const [dx, dy] = [valueX, valueY];
|
|
1144
1134
|
if (direction === WireAutoDirection.Auto) {
|
|
@@ -1194,16 +1184,16 @@ export class RenderWire extends RenderObject {
|
|
|
1194
1184
|
useValue = value;
|
|
1195
1185
|
}
|
|
1196
1186
|
if (direction === Direction.Down) {
|
|
1197
|
-
tmpY
|
|
1187
|
+
tmpY = tmpY.add(useValue);
|
|
1198
1188
|
}
|
|
1199
1189
|
else if (direction === Direction.Up) {
|
|
1200
|
-
tmpY
|
|
1190
|
+
tmpY = tmpY.sub(useValue);
|
|
1201
1191
|
}
|
|
1202
1192
|
else if (direction === Direction.Left) {
|
|
1203
|
-
tmpX
|
|
1193
|
+
tmpX = tmpX.sub(useValue);
|
|
1204
1194
|
}
|
|
1205
1195
|
else if (direction === Direction.Right) {
|
|
1206
|
-
tmpX
|
|
1196
|
+
tmpX = tmpX.add(useValue);
|
|
1207
1197
|
}
|
|
1208
1198
|
});
|
|
1209
1199
|
let useValue = null;
|
|
@@ -1211,22 +1201,22 @@ export class RenderWire extends RenderObject {
|
|
|
1211
1201
|
const lastSegment = this.segments[this.segments.length - 1];
|
|
1212
1202
|
switch (lastSegment.direction) {
|
|
1213
1203
|
case Direction.Left:
|
|
1214
|
-
useValue = tmpX
|
|
1204
|
+
useValue = tmpX.sub(untilX);
|
|
1215
1205
|
break;
|
|
1216
1206
|
case Direction.Right:
|
|
1217
|
-
useValue = untilX
|
|
1207
|
+
useValue = untilX.sub(tmpX);
|
|
1218
1208
|
break;
|
|
1219
1209
|
case Direction.Up:
|
|
1220
|
-
useValue = untilY
|
|
1210
|
+
useValue = untilY.sub(tmpY);
|
|
1221
1211
|
break;
|
|
1222
1212
|
case Direction.Down:
|
|
1223
|
-
useValue = tmpY
|
|
1213
|
+
useValue = tmpY.sub(untilY);
|
|
1224
1214
|
break;
|
|
1225
1215
|
case WireAutoDirection.Auto:
|
|
1226
1216
|
case WireAutoDirection.Auto_:
|
|
1227
1217
|
valueXY = [
|
|
1228
|
-
untilX
|
|
1229
|
-
untilY
|
|
1218
|
+
untilX.sub(tmpX),
|
|
1219
|
+
untilY.sub(tmpY),
|
|
1230
1220
|
];
|
|
1231
1221
|
useValue = 0;
|
|
1232
1222
|
break;
|
|
@@ -1264,7 +1254,7 @@ export class RenderComponent extends RenderObject {
|
|
|
1264
1254
|
}
|
|
1265
1255
|
export class RenderText extends RenderObject {
|
|
1266
1256
|
symbol;
|
|
1267
|
-
_fontSize = 12;
|
|
1257
|
+
_fontSize = numeric(12);
|
|
1268
1258
|
_fontWeight = 'regular';
|
|
1269
1259
|
get fontSize() {
|
|
1270
1260
|
return this._fontSize;
|
|
@@ -1293,11 +1283,10 @@ export class RenderFrame extends RenderObject {
|
|
|
1293
1283
|
translateY = 0;
|
|
1294
1284
|
padding = milsToMM(100);
|
|
1295
1285
|
gap = milsToMM(100);
|
|
1286
|
+
borderWidth = numeric(5);
|
|
1296
1287
|
direction = FramePlotDirection.Column;
|
|
1297
|
-
borderWidth = 5;
|
|
1298
1288
|
width = null;
|
|
1299
1289
|
height = null;
|
|
1300
|
-
size = null;
|
|
1301
1290
|
subgraphId = "";
|
|
1302
1291
|
type;
|
|
1303
1292
|
containsTitle = false;
|
|
@@ -1314,7 +1303,8 @@ export class RenderFrame extends RenderObject {
|
|
|
1314
1303
|
else if (this.type === RenderFrameType.Elements) {
|
|
1315
1304
|
name = 'elements_' + this.subgraphId;
|
|
1316
1305
|
}
|
|
1317
|
-
return name + ": " + this.x + "," + this.y
|
|
1306
|
+
return name + ": " + this.x + "," + this.y
|
|
1307
|
+
+ " bounds:" + (this.bounds && printBounds(this.bounds));
|
|
1318
1308
|
}
|
|
1319
1309
|
}
|
|
1320
1310
|
export var RenderFrameType;
|
|
@@ -1339,8 +1329,9 @@ export function CalculatePinPositions(component) {
|
|
|
1339
1329
|
}
|
|
1340
1330
|
else {
|
|
1341
1331
|
const symbolPinDefinitions = generateLayoutPinDefinition(component);
|
|
1342
|
-
tmpSymbol = new SymbolCustom(symbolPinDefinitions);
|
|
1332
|
+
tmpSymbol = new SymbolCustom(symbolPinDefinitions, component.pinsMaxPositions);
|
|
1343
1333
|
}
|
|
1334
|
+
applyComponentParamsToSymbol(component, tmpSymbol);
|
|
1344
1335
|
tmpSymbol.refreshDrawing();
|
|
1345
1336
|
const pins = component.pins;
|
|
1346
1337
|
pins.forEach((value, key) => {
|
package/dist/esm/logger.mjs
CHANGED
|
@@ -4,7 +4,14 @@ export class Logger {
|
|
|
4
4
|
this.add((new Date()).toISOString());
|
|
5
5
|
this.add('starting logger...');
|
|
6
6
|
}
|
|
7
|
-
add(
|
|
7
|
+
add(...args) {
|
|
8
|
+
let message = "";
|
|
9
|
+
if (args.length === 1) {
|
|
10
|
+
message = args[0].toString();
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
message = args.join(" ");
|
|
14
|
+
}
|
|
8
15
|
this.logs.push((new Date()).toISOString() + " | " + message);
|
|
9
16
|
}
|
|
10
17
|
dump() {
|