circuitscript 0.1.11 → 0.1.12
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 +78 -51
- package/dist/cjs/antlr/CircuitScriptParser.js +1059 -949
- package/dist/cjs/builtinMethods.js +5 -1
- package/dist/cjs/execute.js +43 -22
- package/dist/cjs/globals.js +7 -1
- package/dist/cjs/layout.js +50 -16
- package/dist/cjs/objects/ExecutionScope.js +3 -0
- package/dist/cjs/objects/Net.js +1 -0
- package/dist/cjs/objects/ParamDefinition.js +3 -0
- package/dist/cjs/objects/types.js +19 -10
- package/dist/cjs/render.js +48 -6
- package/dist/cjs/utils.js +16 -1
- package/dist/cjs/visitor.js +69 -52
- package/dist/esm/BaseVisitor.js +72 -45
- package/dist/esm/antlr/CircuitScriptParser.js +1052 -944
- package/dist/esm/antlr/CircuitScriptVisitor.js +4 -2
- package/dist/esm/builtinMethods.js +6 -2
- package/dist/esm/execute.js +43 -22
- package/dist/esm/globals.js +6 -0
- package/dist/esm/layout.js +53 -17
- package/dist/esm/objects/ExecutionScope.js +3 -0
- package/dist/esm/objects/Net.js +1 -0
- package/dist/esm/objects/ParamDefinition.js +4 -1
- package/dist/esm/objects/types.js +21 -15
- package/dist/esm/render.js +49 -7
- package/dist/esm/utils.js +13 -0
- package/dist/esm/visitor.js +57 -40
- package/dist/types/BaseVisitor.d.ts +2 -2
- package/dist/types/antlr/CircuitScriptParser.d.ts +99 -83
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -4
- package/dist/types/execute.d.ts +1 -0
- package/dist/types/globals.d.ts +5 -0
- package/dist/types/layout.d.ts +16 -3
- package/dist/types/objects/ExecutionScope.d.ts +15 -3
- package/dist/types/objects/Net.d.ts +1 -0
- package/dist/types/objects/types.d.ts +25 -18
- package/dist/types/utils.d.ts +3 -1
- package/dist/types/visitor.d.ts +3 -2
- package/package.json +1 -1
- /package/dist/libs/{lib.cst → std.cst} +0 -0
- /package/libs/{lib.cst → std.cst} +0 -0
|
@@ -2,9 +2,11 @@ import { AbstractParseTreeVisitor } from "antlr4ng";
|
|
|
2
2
|
export class CircuitScriptVisitor extends AbstractParseTreeVisitor {
|
|
3
3
|
visitScript;
|
|
4
4
|
visitExpression;
|
|
5
|
+
visitFlow_expressions;
|
|
6
|
+
visitGraph_expressions;
|
|
7
|
+
visitGraph_linear_expression;
|
|
5
8
|
visitExpressions_block;
|
|
6
|
-
|
|
7
|
-
visitPath_block_inner;
|
|
9
|
+
visitPath_block;
|
|
8
10
|
visitProperty_set_expr2;
|
|
9
11
|
visitAssignment_expr2;
|
|
10
12
|
visitPin_select_expr;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { numeric, NumericValue } from "./objects/ParamDefinition.js";
|
|
3
|
-
import { resolveToNumericValue } from "./utils.js";
|
|
3
|
+
import { prepareValue, resolveToNumericValue } from "./utils.js";
|
|
4
4
|
const builtInMethods = [
|
|
5
5
|
['enumerate', enumerate],
|
|
6
6
|
['toMils', toMils],
|
|
@@ -15,7 +15,10 @@ export const buildInMethodNamesList = builtInMethods.map(item => item[0]);
|
|
|
15
15
|
export function linkBuiltInMethods(context, visitor) {
|
|
16
16
|
context.createFunction('print', (params) => {
|
|
17
17
|
const args = getPositionParams(params);
|
|
18
|
-
const items = args.map(item =>
|
|
18
|
+
const items = args.map(item => {
|
|
19
|
+
const value = prepareValue(item);
|
|
20
|
+
return toString(value);
|
|
21
|
+
});
|
|
19
22
|
if (visitor.printToConsole) {
|
|
20
23
|
console.log('::', ...items);
|
|
21
24
|
}
|
|
@@ -75,6 +78,7 @@ function toMils(value) {
|
|
|
75
78
|
return resolveToNumericValue(bigValue);
|
|
76
79
|
}
|
|
77
80
|
function objectLength(obj) {
|
|
81
|
+
obj = prepareValue(obj);
|
|
78
82
|
if (Array.isArray(obj)) {
|
|
79
83
|
return numeric(obj.length);
|
|
80
84
|
}
|
package/dist/esm/execute.js
CHANGED
|
@@ -357,6 +357,10 @@ export class ExecutionContext {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
this.scope.setCurrent(component, usePinId);
|
|
360
|
+
if (!this.scope.hasNet(component, pinId)) {
|
|
361
|
+
const tmpNet = new Net(this.netNamespace, this.getUniqueNetName());
|
|
362
|
+
this.scope.setNet(component, pinId, tmpNet);
|
|
363
|
+
}
|
|
360
364
|
this.scope.clearActive();
|
|
361
365
|
if (addSequence) {
|
|
362
366
|
this.scope.sequence.push([SequenceAction.At,
|
|
@@ -400,13 +404,14 @@ export class ExecutionContext {
|
|
|
400
404
|
this.tmpPointId += 1;
|
|
401
405
|
}
|
|
402
406
|
this.scope.blockStack.set(this.scope.indentLevel, {
|
|
403
|
-
|
|
407
|
+
start_point: [
|
|
404
408
|
this.scope.currentComponent,
|
|
405
409
|
this.scope.currentPin,
|
|
406
410
|
this.scope.currentWireId
|
|
407
411
|
],
|
|
412
|
+
end_point: null,
|
|
408
413
|
inner_blocks: new Map(),
|
|
409
|
-
current_index:
|
|
414
|
+
current_index: 0,
|
|
410
415
|
type: blockType,
|
|
411
416
|
});
|
|
412
417
|
this.log('enter blocks');
|
|
@@ -415,7 +420,7 @@ export class ExecutionContext {
|
|
|
415
420
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
416
421
|
const { type: blockType } = stackRef;
|
|
417
422
|
if (blockType === BlockTypes.Join || blockType === BlockTypes.Parallel) {
|
|
418
|
-
const {
|
|
423
|
+
const { end_point: finalPoint } = stackRef;
|
|
419
424
|
const [component, pin, wireId] = finalPoint;
|
|
420
425
|
this.scope.setCurrent(component, pin);
|
|
421
426
|
this.scope.currentWireId = wireId;
|
|
@@ -426,17 +431,22 @@ export class ExecutionContext {
|
|
|
426
431
|
}
|
|
427
432
|
}
|
|
428
433
|
else if (blockType === BlockTypes.Point) {
|
|
429
|
-
const {
|
|
434
|
+
const { start_point: [component, pin,] } = stackRef;
|
|
430
435
|
this.atComponent(component, pin, { addSequence: true });
|
|
431
436
|
}
|
|
437
|
+
this.scope.blockStack.delete(this.scope.indentLevel);
|
|
432
438
|
this.log('exit blocks');
|
|
433
439
|
}
|
|
440
|
+
closeAllBlocks() {
|
|
441
|
+
if (this.scope.blockStack.has(this.scope.indentLevel)) {
|
|
442
|
+
this.exitBlocks();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
434
445
|
enterBlock(blockIndex) {
|
|
435
446
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
436
|
-
stackRef['block_index'] = blockIndex;
|
|
437
447
|
const { type: blockType } = stackRef;
|
|
438
448
|
const blockTypeName = getBlockTypeString(blockType);
|
|
439
|
-
stackRef
|
|
449
|
+
stackRef.inner_blocks.set(blockIndex, {
|
|
440
450
|
last_net: null,
|
|
441
451
|
ignore_last_net: false,
|
|
442
452
|
});
|
|
@@ -445,7 +455,7 @@ export class ExecutionContext {
|
|
|
445
455
|
this.scope.currentWireId = -1;
|
|
446
456
|
}
|
|
447
457
|
else if (blockType === BlockTypes.Parallel) {
|
|
448
|
-
const {
|
|
458
|
+
const { start_point: [component, pin,] } = stackRef;
|
|
449
459
|
this.atComponent(component, pin, { addSequence: true });
|
|
450
460
|
}
|
|
451
461
|
this.log(`enter inner block of type (${blockTypeName}) >>>`);
|
|
@@ -454,17 +464,16 @@ export class ExecutionContext {
|
|
|
454
464
|
exitBlock(blockIndex) {
|
|
455
465
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1);
|
|
456
466
|
const { type: blockType } = stackRef;
|
|
457
|
-
const blockIndexRef = stackRef
|
|
458
|
-
blockIndexRef
|
|
467
|
+
const blockIndexRef = stackRef.inner_blocks.get(blockIndex);
|
|
468
|
+
blockIndexRef.last_net = [
|
|
459
469
|
this.scope.currentComponent,
|
|
460
470
|
this.scope.currentPin,
|
|
461
471
|
this.scope.currentWireId
|
|
462
472
|
];
|
|
463
|
-
stackRef['block_index'] = null;
|
|
464
473
|
this.scope.indentLevel -= 1;
|
|
465
474
|
this.log('exit inner block <<<');
|
|
466
475
|
if (blockType === BlockTypes.Branch) {
|
|
467
|
-
const {
|
|
476
|
+
const { start_point: [component, pin, wireId] } = stackRef;
|
|
468
477
|
this.atComponent(component, pin, { addSequence: true });
|
|
469
478
|
if (wireId !== -1) {
|
|
470
479
|
this.scope.sequence.push([SequenceAction.WireJump, wireId, 1]);
|
|
@@ -475,14 +484,14 @@ export class ExecutionContext {
|
|
|
475
484
|
const pointIdName = `${Delimiter1}${getBlockTypeString(blockType)}`;
|
|
476
485
|
this.addPoint(`${pointIdName}.${this.name}.${this.tmpPointId}`, false);
|
|
477
486
|
this.tmpPointId += 1;
|
|
478
|
-
stackRef
|
|
487
|
+
stackRef.end_point = [
|
|
479
488
|
this.scope.currentComponent,
|
|
480
489
|
this.scope.currentPin,
|
|
481
490
|
this.scope.currentWireId
|
|
482
491
|
];
|
|
483
492
|
}
|
|
484
493
|
else {
|
|
485
|
-
const {
|
|
494
|
+
const { end_point: finalPoint } = stackRef;
|
|
486
495
|
const [component, pin,] = finalPoint;
|
|
487
496
|
this.toComponent(component, pin, { addSequence: true });
|
|
488
497
|
}
|
|
@@ -504,10 +513,10 @@ export class ExecutionContext {
|
|
|
504
513
|
this.log('get block point');
|
|
505
514
|
for (let i = 0; i < this.scope.indentLevel; i++) {
|
|
506
515
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
|
|
507
|
-
const {
|
|
508
|
-
const component =
|
|
516
|
+
const { start_point } = stackRef;
|
|
517
|
+
const component = start_point[0];
|
|
509
518
|
if (component.instanceName.startsWith(`${Delimiter1}point.`)) {
|
|
510
|
-
return
|
|
519
|
+
return start_point;
|
|
511
520
|
}
|
|
512
521
|
}
|
|
513
522
|
this.log('did not find block point');
|
|
@@ -548,8 +557,8 @@ export class ExecutionContext {
|
|
|
548
557
|
});
|
|
549
558
|
}
|
|
550
559
|
else {
|
|
551
|
-
|
|
552
|
-
|
|
560
|
+
let isVariable = context.scope.variables.has(idName);
|
|
561
|
+
let isComponentInstance = context.scope.instances.has(idName);
|
|
553
562
|
if (isVariable || isComponentInstance) {
|
|
554
563
|
const scopeList = isVariable ? context.scope.variables
|
|
555
564
|
: context.scope.instances;
|
|
@@ -558,11 +567,25 @@ export class ExecutionContext {
|
|
|
558
567
|
if (trailers.length > 0) {
|
|
559
568
|
parentValue = useValue;
|
|
560
569
|
const trailersPath = trailers.join(".");
|
|
570
|
+
if (!isComponentInstance && (parentValue instanceof ClassComponent)) {
|
|
571
|
+
isComponentInstance = true;
|
|
572
|
+
isVariable = false;
|
|
573
|
+
}
|
|
561
574
|
if (isVariable) {
|
|
562
575
|
useValue = parentValue[trailersPath];
|
|
563
576
|
}
|
|
564
577
|
else if (isComponentInstance) {
|
|
565
|
-
|
|
578
|
+
const tmpComponent = parentValue;
|
|
579
|
+
if (tmpComponent.typeProp === ComponentTypes.net) {
|
|
580
|
+
const usedNet = this.scope.getNet(tmpComponent, 1);
|
|
581
|
+
if (usedNet) {
|
|
582
|
+
const trailerValue = trailers.join(".");
|
|
583
|
+
useValue = usedNet.params.get(trailerValue) ?? null;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
useValue = parentValue.parameters.get(trailersPath);
|
|
588
|
+
}
|
|
566
589
|
}
|
|
567
590
|
}
|
|
568
591
|
return new DeclaredReference({
|
|
@@ -618,9 +641,7 @@ export class ExecutionContext {
|
|
|
618
641
|
}
|
|
619
642
|
mergeScope(childScope, namespace) {
|
|
620
643
|
this.log('-- merging scope to parent --');
|
|
621
|
-
const currentComponent = this.scope
|
|
622
|
-
const currentPin = this.scope.currentPin;
|
|
623
|
-
const currentWireId = this.scope.currentWireId;
|
|
644
|
+
const { currentComponent, currentPin, currentWireId } = this.scope;
|
|
624
645
|
const tmpInstances = childScope.instances;
|
|
625
646
|
const tmpNets = childScope.getNets();
|
|
626
647
|
for (const [instanceName, component] of tmpInstances) {
|
package/dist/esm/globals.js
CHANGED
|
@@ -100,6 +100,12 @@ export var BlockTypes;
|
|
|
100
100
|
BlockTypes[BlockTypes["Parallel"] = 3] = "Parallel";
|
|
101
101
|
BlockTypes[BlockTypes["Point"] = 4] = "Point";
|
|
102
102
|
})(BlockTypes || (BlockTypes = {}));
|
|
103
|
+
export var NetGraphicsParams;
|
|
104
|
+
(function (NetGraphicsParams) {
|
|
105
|
+
NetGraphicsParams["Color"] = "color";
|
|
106
|
+
NetGraphicsParams["Highight"] = "highlight";
|
|
107
|
+
NetGraphicsParams["LineWidth"] = "lineWidth";
|
|
108
|
+
})(NetGraphicsParams || (NetGraphicsParams = {}));
|
|
103
109
|
export var FrameType;
|
|
104
110
|
(function (FrameType) {
|
|
105
111
|
FrameType[FrameType["Frame"] = 1] = "Frame";
|
package/dist/esm/layout.js
CHANGED
|
@@ -2,7 +2,7 @@ import graphlib, { Graph } from '@dagrejs/graphlib';
|
|
|
2
2
|
const { alg } = graphlib;
|
|
3
3
|
import { SymbolCustom, SymbolDrawing, SymbolCustomModule, SymbolPlaceholder, SymbolText, PlaceHolderCommands } from "./draw_symbols.js";
|
|
4
4
|
import { FrameAction, SequenceAction } from "./objects/ExecutionScope.js";
|
|
5
|
-
import { ComponentTypes, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, ParamKeys, WireAutoDirection } from './globals.js';
|
|
5
|
+
import { ComponentTypes, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, NetGraphicsParams, ParamKeys, WireAutoDirection } from './globals.js';
|
|
6
6
|
import { Geometry, HorizontalAlign, VerticalAlign } from './geometry.js';
|
|
7
7
|
import { Logger } from './logger.js';
|
|
8
8
|
import { FixedFrameIds, Frame, FrameParamKeys, FramePlotDirection } from './objects/Frame.js';
|
|
@@ -31,6 +31,7 @@ export class LayoutEngine {
|
|
|
31
31
|
}
|
|
32
32
|
runLayout(sequence, nets) {
|
|
33
33
|
const logNodesAndEdges = true;
|
|
34
|
+
const renderNets = this.collectRenderNets(nets);
|
|
34
35
|
this.print('===== creating graph and populating with nodes =====');
|
|
35
36
|
const { graph, containerFrames } = this.generateLayoutGraph(sequence, nets);
|
|
36
37
|
this.print('===== done populating graph =====');
|
|
@@ -83,7 +84,7 @@ export class LayoutEngine {
|
|
|
83
84
|
}
|
|
84
85
|
wireGroups.get(netName).push(wire);
|
|
85
86
|
});
|
|
86
|
-
const { junctions, mergedWires } = this.findJunctions(wireGroups);
|
|
87
|
+
const { junctions, mergedWires } = this.findJunctions(wireGroups, renderNets);
|
|
87
88
|
return {
|
|
88
89
|
frame: sheet,
|
|
89
90
|
frames,
|
|
@@ -91,11 +92,33 @@ export class LayoutEngine {
|
|
|
91
92
|
wires,
|
|
92
93
|
textObjects,
|
|
93
94
|
junctions,
|
|
94
|
-
mergedWires
|
|
95
|
+
mergedWires
|
|
95
96
|
};
|
|
96
97
|
});
|
|
97
98
|
return sheetFrameObjects;
|
|
98
99
|
}
|
|
100
|
+
collectRenderNets(nets) {
|
|
101
|
+
const renderNets = new Map();
|
|
102
|
+
const uniqueNets = new Set(nets.map(([, , net]) => net));
|
|
103
|
+
uniqueNets.forEach(net => {
|
|
104
|
+
const renderNet = {
|
|
105
|
+
netName: net.toString(),
|
|
106
|
+
net,
|
|
107
|
+
};
|
|
108
|
+
if (net.params.has(NetGraphicsParams.Color)) {
|
|
109
|
+
renderNet.color = net.params.get(NetGraphicsParams.Color);
|
|
110
|
+
}
|
|
111
|
+
if (net.params.has(NetGraphicsParams.LineWidth)) {
|
|
112
|
+
const value = net.params.get(NetGraphicsParams.LineWidth);
|
|
113
|
+
renderNet.lineWidth = milsToMM(value).toNumber();
|
|
114
|
+
}
|
|
115
|
+
if (net.params.has(NetGraphicsParams.Highight)) {
|
|
116
|
+
renderNet.highlight = net.params.get(NetGraphicsParams.Highight);
|
|
117
|
+
}
|
|
118
|
+
renderNets.set(net.toString(), renderNet);
|
|
119
|
+
});
|
|
120
|
+
return renderNets;
|
|
121
|
+
}
|
|
99
122
|
flattenFrameItems(frame) {
|
|
100
123
|
const items = [];
|
|
101
124
|
frame.innerItems.forEach(item => {
|
|
@@ -107,11 +130,11 @@ export class LayoutEngine {
|
|
|
107
130
|
});
|
|
108
131
|
return items;
|
|
109
132
|
}
|
|
110
|
-
findJunctions(wireGroups) {
|
|
133
|
+
findJunctions(wireGroups, nets) {
|
|
111
134
|
const junctions = [];
|
|
112
135
|
const mergedWires = [];
|
|
113
136
|
const debugSegments = false;
|
|
114
|
-
for (const [
|
|
137
|
+
for (const [netName, wires] of wireGroups) {
|
|
115
138
|
const allLines = wires.map(wire => {
|
|
116
139
|
return wire.points.map(pt => {
|
|
117
140
|
return {
|
|
@@ -120,6 +143,10 @@ export class LayoutEngine {
|
|
|
120
143
|
};
|
|
121
144
|
});
|
|
122
145
|
});
|
|
146
|
+
let renderNet = null;
|
|
147
|
+
if (nets.has(netName)) {
|
|
148
|
+
renderNet = nets.get(netName);
|
|
149
|
+
}
|
|
123
150
|
if (debugSegments) {
|
|
124
151
|
const tmpSegments = [];
|
|
125
152
|
allLines.forEach(wire => {
|
|
@@ -133,20 +160,22 @@ export class LayoutEngine {
|
|
|
133
160
|
}
|
|
134
161
|
});
|
|
135
162
|
mergedWires.push({
|
|
136
|
-
netName:
|
|
163
|
+
netName: netName,
|
|
137
164
|
segments: tmpSegments,
|
|
138
165
|
intersectPoints: [],
|
|
166
|
+
net: renderNet,
|
|
139
167
|
});
|
|
140
168
|
}
|
|
141
169
|
else {
|
|
142
170
|
const { intersectPoints, segments } = Geometry.mergeWires(allLines);
|
|
143
171
|
mergedWires.push({
|
|
144
|
-
netName:
|
|
172
|
+
netName: netName,
|
|
145
173
|
segments,
|
|
146
174
|
intersectPoints,
|
|
175
|
+
net: renderNet,
|
|
147
176
|
});
|
|
148
177
|
intersectPoints.forEach(([x, y]) => {
|
|
149
|
-
junctions.push(new RenderJunction(numeric(x), numeric(y)));
|
|
178
|
+
junctions.push(new RenderJunction(numeric(x), numeric(y), renderNet));
|
|
150
179
|
});
|
|
151
180
|
}
|
|
152
181
|
}
|
|
@@ -657,22 +686,25 @@ export class LayoutEngine {
|
|
|
657
686
|
}
|
|
658
687
|
case SequenceAction.Wire: {
|
|
659
688
|
const [, wireId, wireSegments] = sequenceStep;
|
|
660
|
-
|
|
661
|
-
wire.id = wireId;
|
|
662
|
-
let useNetName = null;
|
|
689
|
+
let useNet;
|
|
663
690
|
if (previousNode !== null) {
|
|
664
691
|
const [prevNodeType, prevNodeItem] = graph.node(previousNode);
|
|
665
692
|
if (prevNodeType === RenderItemType.Component) {
|
|
666
693
|
const matchingItem = nets.find(([comp, pin]) => {
|
|
667
|
-
return comp.instanceName === previousNode
|
|
694
|
+
return comp.instanceName === previousNode
|
|
695
|
+
&& pin === previousPin;
|
|
668
696
|
});
|
|
669
|
-
|
|
697
|
+
if (matchingItem !== undefined) {
|
|
698
|
+
useNet = matchingItem[2];
|
|
699
|
+
}
|
|
670
700
|
}
|
|
671
701
|
else if (prevNodeType === RenderItemType.Wire) {
|
|
672
|
-
|
|
702
|
+
useNet = prevNodeItem.net;
|
|
673
703
|
}
|
|
674
704
|
}
|
|
675
|
-
wire
|
|
705
|
+
const wire = new RenderWire(useNet, numeric(0), numeric(0), wireSegments);
|
|
706
|
+
wire.id = wireId;
|
|
707
|
+
wire.netName = useNet.toString();
|
|
676
708
|
const wireName = getWireName(wire.id);
|
|
677
709
|
graph.setNode(wireName, [RenderItemType.Wire, wire, index]);
|
|
678
710
|
this.setGraphEdge(graph, previousNode, wireName, makeEdgeValue(previousNode, previousPin, wireName, 0, index));
|
|
@@ -1188,8 +1220,10 @@ export class RenderWire extends RenderObject {
|
|
|
1188
1220
|
segments = [];
|
|
1189
1221
|
points = [];
|
|
1190
1222
|
netName;
|
|
1191
|
-
|
|
1223
|
+
net;
|
|
1224
|
+
constructor(net, x, y, segments) {
|
|
1192
1225
|
super();
|
|
1226
|
+
this.net = net;
|
|
1193
1227
|
this.x = x;
|
|
1194
1228
|
this.y = y;
|
|
1195
1229
|
this.segments = segments;
|
|
@@ -1428,9 +1462,11 @@ export var RenderFrameType;
|
|
|
1428
1462
|
export class RenderJunction {
|
|
1429
1463
|
x;
|
|
1430
1464
|
y;
|
|
1431
|
-
|
|
1465
|
+
net;
|
|
1466
|
+
constructor(x, y, net) {
|
|
1432
1467
|
this.x = x;
|
|
1433
1468
|
this.y = y;
|
|
1469
|
+
this.net = net;
|
|
1434
1470
|
}
|
|
1435
1471
|
}
|
|
1436
1472
|
export function CalculatePinPositions(component) {
|
|
@@ -103,6 +103,9 @@ export class ExecutionScope {
|
|
|
103
103
|
console.log(netName.padEnd(10), '=>', instanceName, pin);
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
+
setVariable(name, value) {
|
|
107
|
+
this.variables.set(name, value);
|
|
108
|
+
}
|
|
106
109
|
setActive(type, item) {
|
|
107
110
|
this.clearActive();
|
|
108
111
|
if (type === ActiveObject.Wire) {
|
package/dist/esm/objects/Net.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNumberExponential, getNumberExponentialText, resolveToNumericValue } from "../utils.js";
|
|
1
|
+
import { getNumberExponential, getNumberExponentialText, isReference, resolveToNumericValue } from "../utils.js";
|
|
2
2
|
import { Big } from 'big.js';
|
|
3
3
|
export class ParamDefinition {
|
|
4
4
|
paramName;
|
|
@@ -121,6 +121,9 @@ export class NumberOperator {
|
|
|
121
121
|
if (typeof value === 'number') {
|
|
122
122
|
return new WrappedNumber(value);
|
|
123
123
|
}
|
|
124
|
+
else if (isReference(value)) {
|
|
125
|
+
return value.value;
|
|
126
|
+
}
|
|
124
127
|
else {
|
|
125
128
|
return value;
|
|
126
129
|
}
|
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
import { RuntimeExecutionError } from '../utils.js';
|
|
2
|
+
export class AnyReference {
|
|
3
|
+
found = false;
|
|
4
|
+
name;
|
|
5
|
+
trailers = [];
|
|
6
|
+
type;
|
|
7
|
+
value;
|
|
8
|
+
parentValue;
|
|
9
|
+
constructor(refType) {
|
|
10
|
+
if (refType.value instanceof AnyReference) {
|
|
11
|
+
throw new RuntimeExecutionError("Nested reference types!");
|
|
12
|
+
}
|
|
13
|
+
this.found = refType.found;
|
|
14
|
+
this.name = refType.name;
|
|
15
|
+
this.trailers = refType.trailers;
|
|
16
|
+
this.type = refType.type;
|
|
17
|
+
this.value = refType.value;
|
|
18
|
+
this.parentValue = refType.parentValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
1
21
|
export class UndeclaredReference {
|
|
2
22
|
reference;
|
|
3
23
|
constructor(reference) {
|
|
@@ -18,21 +38,7 @@ export class UndeclaredReference {
|
|
|
18
38
|
return name + extra;
|
|
19
39
|
}
|
|
20
40
|
}
|
|
21
|
-
export class DeclaredReference {
|
|
22
|
-
found;
|
|
23
|
-
name;
|
|
24
|
-
trailers;
|
|
25
|
-
type;
|
|
26
|
-
value;
|
|
27
|
-
parentValue;
|
|
28
|
-
constructor(refType) {
|
|
29
|
-
this.found = refType.found;
|
|
30
|
-
this.name = refType.name;
|
|
31
|
-
this.trailers = refType.trailers;
|
|
32
|
-
this.type = refType.type;
|
|
33
|
-
this.value = refType.value;
|
|
34
|
-
this.parentValue = refType.parentValue;
|
|
35
|
-
}
|
|
41
|
+
export class DeclaredReference extends AnyReference {
|
|
36
42
|
toString() {
|
|
37
43
|
return `[DeclaredReference name: ${this.name} trailers:${this.trailers} found: ${this.found}]`;
|
|
38
44
|
}
|
package/dist/esm/render.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SVG, registerWindow } from '@svgdotjs/svg.js';
|
|
2
2
|
import { ExtractDrawingRects, RenderFrameType, getBounds } from "./layout.js";
|
|
3
3
|
import { applyFontsToSVG } from './sizing.js';
|
|
4
|
-
import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from './globals.js';
|
|
4
|
+
import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, MilsToMM, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from './globals.js';
|
|
5
5
|
import { numeric, NumericValue } from './objects/ParamDefinition.js';
|
|
6
6
|
import { combineMaps, getBoundsSize } from './utils.js';
|
|
7
7
|
import { getPaperSize, milsToMM } from './helpers.js';
|
|
@@ -169,28 +169,70 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
169
169
|
.translate(wire.x.add(5).toNumber(), wire.y.add(5).toNumber());
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
|
+
const mergedWireHighlightGroup = canvas.group();
|
|
172
173
|
const mergedWireGroup = canvas.group();
|
|
173
174
|
mergedWires.forEach(tmpItem => {
|
|
174
|
-
const { segments, intersectPoints } = tmpItem;
|
|
175
|
+
const { segments, intersectPoints, net = null } = tmpItem;
|
|
176
|
+
let useJunctionColor = ColorScheme.JunctionColor;
|
|
177
|
+
let useColor = ColorScheme.WireColor;
|
|
178
|
+
let useLineWidth = defaultWireLineWidth;
|
|
179
|
+
let displayHighlight = false;
|
|
180
|
+
let displayHighlightColor = null;
|
|
181
|
+
if (net !== null) {
|
|
182
|
+
useColor = net.color ?? ColorScheme.WireColor;
|
|
183
|
+
useJunctionColor = net.color ?? ColorScheme.JunctionColor;
|
|
184
|
+
useLineWidth = net.lineWidth ?? defaultWireLineWidth;
|
|
185
|
+
if (net.highlight !== null) {
|
|
186
|
+
displayHighlight = true;
|
|
187
|
+
displayHighlightColor = net.highlight ?? null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const pathItems = [];
|
|
191
|
+
const highlightExtraSize = 5 * MilsToMM;
|
|
175
192
|
segments.forEach(segment => {
|
|
176
193
|
const pt1 = segment[0];
|
|
177
194
|
const pt2 = segment[1];
|
|
178
|
-
|
|
195
|
+
pathItems.push(...[
|
|
196
|
+
'M', pt1[0], pt1[1],
|
|
197
|
+
'L', pt2[0], pt2[1]
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
if (displayHighlight) {
|
|
201
|
+
mergedWireHighlightGroup.path(pathItems)
|
|
179
202
|
.stroke({
|
|
180
|
-
width:
|
|
181
|
-
color:
|
|
203
|
+
width: useLineWidth + highlightExtraSize,
|
|
204
|
+
color: displayHighlightColor,
|
|
205
|
+
opacity: 0.3,
|
|
182
206
|
linecap: 'square'
|
|
183
207
|
})
|
|
184
208
|
.fill('none');
|
|
185
|
-
}
|
|
209
|
+
}
|
|
210
|
+
mergedWireGroup.path(pathItems)
|
|
211
|
+
.stroke({
|
|
212
|
+
width: useLineWidth,
|
|
213
|
+
color: useColor,
|
|
214
|
+
linecap: 'square'
|
|
215
|
+
})
|
|
216
|
+
.fill('none');
|
|
186
217
|
const halfJunctionSize = junctionSize.half();
|
|
218
|
+
const highlightJunctionSize = numeric(junctionSize.toNumber() + highlightExtraSize);
|
|
219
|
+
const tmpHighlightExtraSize = highlightJunctionSize.half();
|
|
187
220
|
intersectPoints.forEach(point => {
|
|
188
221
|
const [x, y,] = point;
|
|
189
222
|
const translateX = numeric(x).sub(halfJunctionSize);
|
|
190
223
|
const translateY = numeric(y).sub(halfJunctionSize);
|
|
224
|
+
if (displayHighlight && displayHighlightColor !== null) {
|
|
225
|
+
const tmpTranslateX = numeric(x).sub(tmpHighlightExtraSize);
|
|
226
|
+
const tmpTranslateY = numeric(y).sub(tmpHighlightExtraSize);
|
|
227
|
+
mergedWireHighlightGroup.circle(highlightJunctionSize.toNumber())
|
|
228
|
+
.translate(tmpTranslateX.toNumber(), tmpTranslateY.toNumber())
|
|
229
|
+
.fill(displayHighlightColor)
|
|
230
|
+
.opacity(0.3)
|
|
231
|
+
.stroke('none');
|
|
232
|
+
}
|
|
191
233
|
mergedWireGroup.circle(junctionSize.toNumber())
|
|
192
234
|
.translate(translateX.toNumber(), translateY.toNumber())
|
|
193
|
-
.fill(
|
|
235
|
+
.fill(useJunctionColor)
|
|
194
236
|
.stroke('none');
|
|
195
237
|
});
|
|
196
238
|
});
|
package/dist/esm/utils.js
CHANGED
|
@@ -4,6 +4,7 @@ import { ClassComponent } from "./objects/ClassComponent.js";
|
|
|
4
4
|
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
5
5
|
import { SequenceAction } from './objects/ExecutionScope.js';
|
|
6
6
|
import { BlockTypes } from './globals.js';
|
|
7
|
+
import { DeclaredReference, AnyReference } from './objects/types.js';
|
|
7
8
|
export class SimpleStopwatch {
|
|
8
9
|
startTime;
|
|
9
10
|
constructor() {
|
|
@@ -325,3 +326,15 @@ export function printWarnings(warnings) {
|
|
|
325
326
|
console.log(`Warning: ${message}`);
|
|
326
327
|
});
|
|
327
328
|
}
|
|
329
|
+
export function prepareValue(value) {
|
|
330
|
+
if (isReference(value)) {
|
|
331
|
+
return value.value;
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
return value;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
export function isReference(value) {
|
|
338
|
+
return (value instanceof AnyReference ||
|
|
339
|
+
value instanceof DeclaredReference);
|
|
340
|
+
}
|