circuitscript 0.1.4 → 0.1.7
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 +149 -80
- package/dist/cjs/SemanticTokenVisitor.js +19 -13
- package/dist/cjs/antlr/CircuitScriptParser.js +711 -671
- package/dist/cjs/builtinMethods.js +48 -22
- package/dist/cjs/draw_symbols.js +4 -1
- package/dist/cjs/environment.js +118 -0
- package/dist/cjs/execute.js +98 -46
- package/dist/cjs/geometry.js +1 -0
- package/dist/cjs/globals.js +14 -7
- package/dist/cjs/helpers.js +142 -150
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/layout.js +39 -14
- package/dist/cjs/main.js +34 -21
- package/dist/cjs/objects/ClassComponent.js +4 -1
- package/dist/cjs/objects/ExecutionScope.js +40 -2
- package/dist/cjs/objects/ParamDefinition.js +15 -15
- package/dist/cjs/parser.js +27 -21
- package/dist/cjs/regenerate-tests.js +9 -6
- package/dist/cjs/render.js +3 -1
- package/dist/cjs/sizing.js +10 -60
- package/dist/cjs/utils.js +148 -17
- package/dist/cjs/validate/SymbolTable.js +96 -0
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +14 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +170 -0
- package/dist/cjs/validate.js +52 -44
- package/dist/cjs/visitor.js +149 -31
- package/dist/esm/{BaseVisitor.mjs → BaseVisitor.js} +124 -56
- package/dist/esm/{SemanticTokenVisitor.mjs → SemanticTokenVisitor.js} +17 -11
- package/dist/esm/antlr/{CircuitScriptParser.mjs → CircuitScriptParser.js} +711 -671
- package/dist/esm/{builtinMethods.mjs → builtinMethods.js} +40 -14
- package/dist/esm/{draw_symbols.mjs → draw_symbols.js} +11 -8
- package/dist/esm/environment.js +110 -0
- package/dist/esm/{execute.mjs → execute.js} +111 -58
- package/dist/esm/{export.mjs → export.js} +2 -2
- package/dist/esm/{geometry.mjs → geometry.js} +6 -5
- package/dist/esm/{globals.mjs → globals.js} +9 -2
- package/dist/esm/helpers.js +377 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/{layout.mjs → layout.js} +44 -22
- package/dist/esm/{lexer.mjs → lexer.js} +2 -2
- package/dist/esm/{main.mjs → main.js} +36 -23
- package/dist/esm/objects/{ClassComponent.mjs → ClassComponent.js} +9 -5
- package/dist/esm/objects/{ExecutionScope.mjs → ExecutionScope.js} +40 -2
- package/dist/esm/objects/{Frame.mjs → Frame.js} +1 -1
- package/dist/esm/objects/{ParamDefinition.mjs → ParamDefinition.js} +1 -1
- package/dist/esm/objects/{PinDefinition.mjs → PinDefinition.js} +1 -1
- package/dist/esm/parser.js +71 -0
- package/dist/esm/{regenerate-tests.mjs → regenerate-tests.js} +10 -7
- package/dist/esm/{render.mjs → render.js} +11 -9
- package/dist/esm/{sizing.mjs → sizing.js} +11 -36
- package/dist/esm/utils.js +286 -0
- package/dist/esm/validate/SymbolTable.js +90 -0
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +10 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +163 -0
- package/dist/esm/validate.js +86 -0
- package/dist/esm/{visitor.mjs → visitor.js} +160 -42
- package/dist/fonts/Arial.ttf +0 -0
- package/dist/fonts/Inter-Bold.ttf +0 -0
- package/dist/fonts/Inter-Regular.ttf +0 -0
- package/dist/fonts/OpenSans-Regular.ttf +0 -0
- package/dist/fonts/Roboto-Regular.ttf +0 -0
- package/dist/libs/lib.cst +423 -0
- package/dist/types/BaseVisitor.d.ts +36 -22
- package/dist/types/SemanticTokenVisitor.d.ts +6 -5
- package/dist/types/antlr/CircuitScriptParser.d.ts +4 -2
- package/dist/types/builtinMethods.d.ts +3 -2
- package/dist/types/draw_symbols.d.ts +2 -6
- package/dist/types/environment.d.ts +31 -0
- package/dist/types/execute.d.ts +2 -3
- package/dist/types/globals.d.ts +7 -2
- package/dist/types/helpers.d.ts +12 -14
- package/dist/types/index.d.ts +5 -0
- package/dist/types/objects/ClassComponent.d.ts +2 -3
- package/dist/types/objects/ExecutionScope.d.ts +20 -6
- package/dist/types/objects/types.d.ts +6 -1
- package/dist/types/parser.d.ts +7 -11
- package/dist/types/sizing.d.ts +0 -3
- package/dist/types/utils.d.ts +33 -4
- package/dist/types/validate/SymbolTable.d.ts +40 -0
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +7 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +32 -0
- package/dist/types/validate.d.ts +1 -1
- package/libs/lib.cst +12 -22
- package/package.json +14 -13
- package/dist/cjs/SymbolValidatorVisitor.js +0 -233
- package/dist/esm/SymbolValidatorVisitor.mjs +0 -222
- package/dist/esm/helpers.mjs +0 -380
- package/dist/esm/index.mjs +0 -15
- package/dist/esm/parser.mjs +0 -64
- package/dist/esm/utils.mjs +0 -169
- package/dist/esm/validate.mjs +0 -74
- package/dist/types/SymbolValidatorVisitor.d.ts +0 -61
- package/dist/types/layout.d.ts +0 -148
- /package/dist/esm/antlr/{CircuitScriptLexer.mjs → CircuitScriptLexer.js} +0 -0
- /package/dist/esm/antlr/{CircuitScriptVisitor.mjs → CircuitScriptVisitor.js} +0 -0
- /package/dist/esm/{fonts.mjs → fonts.js} +0 -0
- /package/dist/esm/{logger.mjs → logger.js} +0 -0
- /package/dist/esm/objects/{Net.mjs → Net.js} +0 -0
- /package/dist/esm/objects/{PinTypes.mjs → PinTypes.js} +0 -0
- /package/dist/esm/objects/{Wire.mjs → Wire.js} +0 -0
- /package/dist/esm/objects/{types.mjs → types.js} +0 -0
- /package/dist/esm/{server.mjs → server.js} +0 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
|
-
import { numeric, NumericValue } from "./objects/ParamDefinition";
|
|
3
|
-
import { resolveToNumericValue } from "./utils";
|
|
2
|
+
import { numeric, NumericValue } from "./objects/ParamDefinition.js";
|
|
3
|
+
import { resolveToNumericValue } from "./utils.js";
|
|
4
|
+
const builtInMethods = [
|
|
5
|
+
['enumerate', enumerate],
|
|
6
|
+
['toMils', toMils],
|
|
7
|
+
['range', range],
|
|
8
|
+
['len', objectLength],
|
|
9
|
+
['arrayPush', arrayPush],
|
|
10
|
+
['arrayGet', arrayGet],
|
|
11
|
+
['print', null],
|
|
12
|
+
];
|
|
13
|
+
export const buildInMethodNamesList = builtInMethods.map(item => item[0]);
|
|
4
14
|
export function linkBuiltInMethods(context, visitor) {
|
|
5
15
|
context.createFunction('print', (params) => {
|
|
6
16
|
const args = getPositionParams(params);
|
|
@@ -12,18 +22,14 @@ export function linkBuiltInMethods(context, visitor) {
|
|
|
12
22
|
visitor.printStream.push(printedValue);
|
|
13
23
|
return [visitor, printedValue];
|
|
14
24
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const args = getPositionParams(params);
|
|
24
|
-
const functionReturn = functionImpl(...args);
|
|
25
|
-
return [visitor, functionReturn];
|
|
26
|
-
});
|
|
25
|
+
builtInMethods.forEach(([functionName, functionImpl]) => {
|
|
26
|
+
if (functionImpl !== null) {
|
|
27
|
+
context.createFunction(functionName, params => {
|
|
28
|
+
const args = getPositionParams(params);
|
|
29
|
+
const functionReturn = functionImpl(...args);
|
|
30
|
+
return [visitor, functionReturn];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
27
33
|
});
|
|
28
34
|
}
|
|
29
35
|
function range(...args) {
|
|
@@ -80,6 +86,26 @@ function objectLength(obj) {
|
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
}
|
|
89
|
+
function arrayPush(arrayObject, valueToPush) {
|
|
90
|
+
if (!Array.isArray(arrayObject)) {
|
|
91
|
+
throw "Invalid array object to push";
|
|
92
|
+
}
|
|
93
|
+
arrayObject.push(valueToPush);
|
|
94
|
+
return arrayObject;
|
|
95
|
+
}
|
|
96
|
+
function arrayGet(arrayObject, index) {
|
|
97
|
+
if (!Array.isArray(arrayObject)) {
|
|
98
|
+
throw "Invalid array object to get";
|
|
99
|
+
}
|
|
100
|
+
let useValue;
|
|
101
|
+
if (index instanceof NumericValue) {
|
|
102
|
+
useValue = index.toNumber();
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
useValue = index;
|
|
106
|
+
}
|
|
107
|
+
return arrayObject[useValue];
|
|
108
|
+
}
|
|
83
109
|
function getPositionParams(params) {
|
|
84
110
|
return params.map(([, , value]) => value);
|
|
85
111
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { milsToMM } from "./helpers.
|
|
2
|
-
import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, RenderFlags, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "./globals.
|
|
3
|
-
import { Geometry, GeometryProp, HorizontalAlign, HorizontalAlignProp, Textbox, VerticalAlign, VerticalAlignProp } from "./geometry.
|
|
4
|
-
import { PinTypes } from "./objects/PinTypes.
|
|
5
|
-
import { roundValue, throwWithContext } from "./utils.
|
|
6
|
-
import { DeclaredReference, UndeclaredReference } from "./objects/types.
|
|
7
|
-
import { numeric, NumericValue } from "./objects/ParamDefinition.
|
|
1
|
+
import { milsToMM } from "./helpers.js";
|
|
2
|
+
import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, RenderFlags, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "./globals.js";
|
|
3
|
+
import { Geometry, GeometryProp, HorizontalAlign, HorizontalAlignProp, Textbox, VerticalAlign, VerticalAlignProp } from "./geometry.js";
|
|
4
|
+
import { PinTypes } from "./objects/PinTypes.js";
|
|
5
|
+
import { roundValue, throwWithContext } from "./utils.js";
|
|
6
|
+
import { DeclaredReference, UndeclaredReference } from "./objects/types.js";
|
|
7
|
+
import { numeric, NumericValue } from "./objects/ParamDefinition.js";
|
|
8
8
|
export class SymbolGraphic {
|
|
9
9
|
drawPortsName = true;
|
|
10
10
|
displayBounds = false;
|
|
@@ -789,7 +789,10 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
789
789
|
calculateSize() {
|
|
790
790
|
const tmpPinSpacing = this.pinSpacing.toNumber();
|
|
791
791
|
const tmpPinLength = this.pinLength.toNumber();
|
|
792
|
-
const
|
|
792
|
+
const maxTopPins = this.pinMaxPositions.get(SymbolPinSide.Top);
|
|
793
|
+
const maxBottomPins = this.pinMaxPositions.get(SymbolPinSide.Bottom);
|
|
794
|
+
const maxLeftPins = this.pinMaxPositions.get(SymbolPinSide.Left);
|
|
795
|
+
const maxRightPins = this.pinMaxPositions.get(SymbolPinSide.Right);
|
|
793
796
|
const bodyWidthFromPins = numeric((1 + Math.max(maxTopPins, maxBottomPins)) * tmpPinSpacing);
|
|
794
797
|
const bodyWidth = Math.max(bodyWidthFromPins.toNumber(), this.bodyWidth.toNumber());
|
|
795
798
|
let tmpBodyHeight = 0;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { registerWindow, SVG } from "@svgdotjs/svg.js";
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { TOOL_VERSION } from "./globals.js";
|
|
5
|
+
import { RuntimeExecutionError } from "./utils.js";
|
|
6
|
+
export class NodeScriptEnvironment {
|
|
7
|
+
static _instance = null;
|
|
8
|
+
static setInstance(instance) {
|
|
9
|
+
NodeScriptEnvironment._instance = instance;
|
|
10
|
+
}
|
|
11
|
+
static getInstance() {
|
|
12
|
+
return NodeScriptEnvironment._instance;
|
|
13
|
+
}
|
|
14
|
+
useModuleDirectoryPath = null;
|
|
15
|
+
useDefaultLibsPath = null;
|
|
16
|
+
globalCreateSVGWindow = null;
|
|
17
|
+
supportedFonts = {
|
|
18
|
+
'Arial': 'Arial.ttf',
|
|
19
|
+
};
|
|
20
|
+
setModuleDirectory(path) {
|
|
21
|
+
this.useModuleDirectoryPath = path;
|
|
22
|
+
}
|
|
23
|
+
setDefaultLibsPath(path) {
|
|
24
|
+
this.useDefaultLibsPath = path;
|
|
25
|
+
}
|
|
26
|
+
getPackageVersion() {
|
|
27
|
+
return TOOL_VERSION;
|
|
28
|
+
}
|
|
29
|
+
getModuleDirectory() {
|
|
30
|
+
if (this.useModuleDirectoryPath !== null) {
|
|
31
|
+
return this.useModuleDirectoryPath;
|
|
32
|
+
}
|
|
33
|
+
if (typeof __dirname !== 'undefined') {
|
|
34
|
+
return __dirname;
|
|
35
|
+
}
|
|
36
|
+
const stackLine = new Error().stack?.split('\n')[1];
|
|
37
|
+
if (stackLine) {
|
|
38
|
+
const fileMatch = stackLine.match(/\((.+)\:[\d]+\:[\d]+\)/);
|
|
39
|
+
if (fileMatch) {
|
|
40
|
+
const filePath = fileMatch[1].replace('file://', '');
|
|
41
|
+
return path.dirname(filePath);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw new RuntimeExecutionError("Failed to get current module directory");
|
|
45
|
+
}
|
|
46
|
+
getRelativeToModule(filePath) {
|
|
47
|
+
return path.join(this.getModuleDirectory(), filePath);
|
|
48
|
+
}
|
|
49
|
+
getRelativeToDefaultLibs(filePath) {
|
|
50
|
+
return path.join(this.getDefaultLibsPath(), filePath);
|
|
51
|
+
}
|
|
52
|
+
getToolsPath() {
|
|
53
|
+
return path.normalize(this.getModuleDirectory() + '/../');
|
|
54
|
+
}
|
|
55
|
+
getFontsPath() {
|
|
56
|
+
return path.normalize(this.getToolsPath() + "fonts");
|
|
57
|
+
}
|
|
58
|
+
getDefaultLibsPath() {
|
|
59
|
+
if (this.useDefaultLibsPath !== null) {
|
|
60
|
+
return this.useDefaultLibsPath;
|
|
61
|
+
}
|
|
62
|
+
return path.normalize(this.getToolsPath() + "libs");
|
|
63
|
+
}
|
|
64
|
+
async prepareSVGEnvironmentInternal(fontsPath) {
|
|
65
|
+
try {
|
|
66
|
+
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
67
|
+
const { config, createSVGWindow } = await dynamicImport('svgdom');
|
|
68
|
+
this.globalCreateSVGWindow = createSVGWindow;
|
|
69
|
+
if (fontsPath !== null) {
|
|
70
|
+
await config.setFontDir(fontsPath)
|
|
71
|
+
.setFontFamilyMappings(this.supportedFonts)
|
|
72
|
+
.preloadFonts();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new Error(`Failed to load svgdom ESM module: ${error}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
createSVGWindow() {
|
|
80
|
+
if (this.globalCreateSVGWindow === null) {
|
|
81
|
+
throw new Error("SVG environment is not set up yet. Call prepareSVGEnvironment() first.");
|
|
82
|
+
}
|
|
83
|
+
return this.globalCreateSVGWindow();
|
|
84
|
+
}
|
|
85
|
+
textMeasurementCanvas;
|
|
86
|
+
getCanvasWindow() {
|
|
87
|
+
if (this.textMeasurementCanvas === undefined) {
|
|
88
|
+
const window = this.createSVGWindow();
|
|
89
|
+
const { document } = window;
|
|
90
|
+
registerWindow(window, document);
|
|
91
|
+
this.textMeasurementCanvas = SVG(document.documentElement);
|
|
92
|
+
}
|
|
93
|
+
return this.textMeasurementCanvas;
|
|
94
|
+
}
|
|
95
|
+
prepareSVGEnvironment() {
|
|
96
|
+
return this.prepareSVGEnvironmentInternal(this.getFontsPath());
|
|
97
|
+
}
|
|
98
|
+
async readFile(path, options) {
|
|
99
|
+
return fs.promises.readFile(path, options);
|
|
100
|
+
}
|
|
101
|
+
async exists(path) {
|
|
102
|
+
try {
|
|
103
|
+
fs.promises.access(path, fs.constants.F_OK);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { BlockTypes, ComponentTypes, GlobalNames, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide } from './globals.
|
|
2
|
-
import { ClassComponent, ModuleComponent } from './objects/ClassComponent.
|
|
3
|
-
import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.
|
|
4
|
-
import { Net } from './objects/Net.
|
|
5
|
-
import { numeric } from './objects/ParamDefinition.
|
|
6
|
-
import { PortSide } from './objects/PinDefinition.
|
|
7
|
-
import { DeclaredReference, Direction } from './objects/types.
|
|
8
|
-
import { Wire } from './objects/Wire.
|
|
9
|
-
import { Frame } from './objects/Frame.
|
|
10
|
-
import { CalculatePinPositions } from './layout.
|
|
11
|
-
import { UnitDimension } from './helpers.
|
|
12
|
-
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.
|
|
1
|
+
import { BlockTypes, ComponentTypes, Delimiter1, GlobalNames, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide } from './globals.js';
|
|
2
|
+
import { ClassComponent, ModuleComponent } from './objects/ClassComponent.js';
|
|
3
|
+
import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.js';
|
|
4
|
+
import { Net } from './objects/Net.js';
|
|
5
|
+
import { numeric } from './objects/ParamDefinition.js';
|
|
6
|
+
import { PortSide } from './objects/PinDefinition.js';
|
|
7
|
+
import { DeclaredReference, Direction } from './objects/types.js';
|
|
8
|
+
import { Wire } from './objects/Wire.js';
|
|
9
|
+
import { Frame } from './objects/Frame.js';
|
|
10
|
+
import { CalculatePinPositions } from './layout.js';
|
|
11
|
+
import { UnitDimension } from './helpers.js';
|
|
12
|
+
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
|
|
13
|
+
import { getBlockTypeString, RuntimeExecutionError } from './utils.js';
|
|
13
14
|
export class ExecutionContext {
|
|
14
15
|
name;
|
|
15
16
|
namespace;
|
|
@@ -18,6 +19,7 @@ export class ExecutionContext {
|
|
|
18
19
|
scope;
|
|
19
20
|
tmpPointId = 0;
|
|
20
21
|
resolveNet = null;
|
|
22
|
+
resolveComponentPinNet;
|
|
21
23
|
stopFurtherExpressions = false;
|
|
22
24
|
returnValue = null;
|
|
23
25
|
silent = false;
|
|
@@ -34,13 +36,6 @@ export class ExecutionContext {
|
|
|
34
36
|
this.scope = ExecutionScope.create();
|
|
35
37
|
this.scope.indentLevel = indentLevel;
|
|
36
38
|
this.setupRoot();
|
|
37
|
-
if (name === '__') {
|
|
38
|
-
this.scope.sequence.push([
|
|
39
|
-
SequenceAction.At,
|
|
40
|
-
this.scope.componentRoot,
|
|
41
|
-
this.scope.currentPin
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
39
|
this.silent = silent;
|
|
45
40
|
this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
|
|
46
41
|
this.parentContext = parent;
|
|
@@ -66,12 +61,12 @@ export class ExecutionContext {
|
|
|
66
61
|
this.scope.componentRoot = componentRoot;
|
|
67
62
|
}
|
|
68
63
|
getUniqueInstanceName() {
|
|
69
|
-
const tmpName =
|
|
64
|
+
const tmpName = `COMP${Delimiter1}${this.scope.unnamedCounter}`;
|
|
70
65
|
this.scope.unnamedCounter += 1;
|
|
71
66
|
return tmpName;
|
|
72
67
|
}
|
|
73
68
|
getUniqueNetName() {
|
|
74
|
-
const tmpName =
|
|
69
|
+
const tmpName = `NET${Delimiter1}${this.scope.netCounter}`;
|
|
75
70
|
this.scope.netCounter++;
|
|
76
71
|
return tmpName;
|
|
77
72
|
}
|
|
@@ -81,7 +76,7 @@ export class ExecutionContext {
|
|
|
81
76
|
linkComponentPinNet(component1, component1Pin, component2, component2Pin) {
|
|
82
77
|
const net1 = this.scope.getNet(component1, component1Pin);
|
|
83
78
|
const net2 = this.scope.getNet(component2, component2Pin);
|
|
84
|
-
this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
|
|
79
|
+
this.log('link nets', component1, component1Pin, net1, 'priority:' + net1?.priority, 'to', component2, component2Pin, net2, 'priority:' + net2?.priority);
|
|
85
80
|
let returnNet;
|
|
86
81
|
if (net1 === null && net2 === null) {
|
|
87
82
|
const tmpNet = new Net(this.netNamespace, this.getUniqueNetName());
|
|
@@ -105,7 +100,7 @@ export class ExecutionContext {
|
|
|
105
100
|
returnNet = net1;
|
|
106
101
|
}
|
|
107
102
|
}
|
|
108
|
-
this.log('final net after link: ', returnNet);
|
|
103
|
+
this.log('final net after link: ', returnNet, returnNet.priority);
|
|
109
104
|
return returnNet;
|
|
110
105
|
}
|
|
111
106
|
mergeNets(net1, net2) {
|
|
@@ -166,8 +161,9 @@ export class ExecutionContext {
|
|
|
166
161
|
tmpNet = new Net(this.netNamespace, netName, priority);
|
|
167
162
|
this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
|
|
168
163
|
}
|
|
169
|
-
|
|
170
|
-
this.
|
|
164
|
+
const defaultPin = 1;
|
|
165
|
+
this.scope.setNet(component, defaultPin, tmpNet);
|
|
166
|
+
this.log('set net', netName, 'component', component, defaultPin);
|
|
171
167
|
}
|
|
172
168
|
const { pins: pinSides, maxPositions } = getPortSide(component.pins, component.arrangeProps);
|
|
173
169
|
component.pinsMaxPositions = maxPositions;
|
|
@@ -209,14 +205,13 @@ export class ExecutionContext {
|
|
|
209
205
|
this.atComponent(component, nextPin, {
|
|
210
206
|
addSequence: true
|
|
211
207
|
});
|
|
212
|
-
this.printPoint();
|
|
213
208
|
return this.getCurrentPoint();
|
|
214
209
|
}
|
|
215
210
|
toComponent(component, pinId, options) {
|
|
216
211
|
this.log('to component');
|
|
217
212
|
const { addSequence = false } = options ?? {};
|
|
218
213
|
if (!(component instanceof ClassComponent)) {
|
|
219
|
-
throw "Not a valid component!";
|
|
214
|
+
throw new RuntimeExecutionError("Not a valid component!");
|
|
220
215
|
}
|
|
221
216
|
if (pinId === null) {
|
|
222
217
|
pinId = component.getDefaultPin();
|
|
@@ -227,7 +222,7 @@ export class ExecutionContext {
|
|
|
227
222
|
}
|
|
228
223
|
else {
|
|
229
224
|
console.trace();
|
|
230
|
-
throw ('Invalid pin number ' +
|
|
225
|
+
throw new RuntimeExecutionError('Invalid pin number ' +
|
|
231
226
|
pinId +
|
|
232
227
|
' in ' +
|
|
233
228
|
component.instanceName);
|
|
@@ -283,6 +278,7 @@ export class ExecutionContext {
|
|
|
283
278
|
return this.getCurrentPoint();
|
|
284
279
|
}
|
|
285
280
|
copyComponent(component) {
|
|
281
|
+
this.log('create clone of net component:', component);
|
|
286
282
|
let componentCopy = null;
|
|
287
283
|
if (!this.scope.copyIDs.has(component.instanceName)) {
|
|
288
284
|
this.scope.copyIDs.set(component.instanceName, 0);
|
|
@@ -295,14 +291,24 @@ export class ExecutionContext {
|
|
|
295
291
|
const cloneInstanceName = component.instanceName + ':' + idNum;
|
|
296
292
|
this.scope.instances.set(cloneInstanceName, componentCopy);
|
|
297
293
|
componentCopy.instanceName = cloneInstanceName;
|
|
298
|
-
|
|
294
|
+
const defaultPin = 1;
|
|
295
|
+
if (this.scope.getNet(component, defaultPin) === null) {
|
|
296
|
+
const foundNet = this.resolveComponentPinNet(component, defaultPin);
|
|
297
|
+
if (foundNet !== null) {
|
|
298
|
+
this.log('found net in upper scopes', foundNet);
|
|
299
|
+
this.scope.setNet(component, defaultPin, foundNet);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
this.linkComponentPinNet(component, defaultPin, componentCopy, defaultPin);
|
|
299
303
|
this.log('created clone of net component:', cloneInstanceName);
|
|
300
304
|
return componentCopy;
|
|
301
305
|
}
|
|
302
306
|
enterBlocks(blockType) {
|
|
303
|
-
if (blockType === BlockTypes.Point
|
|
304
|
-
|
|
305
|
-
|
|
307
|
+
if (blockType === BlockTypes.Point
|
|
308
|
+
|| blockType === BlockTypes.Parallel
|
|
309
|
+
|| blockType === BlockTypes.Branch) {
|
|
310
|
+
const key = getBlockTypeString(blockType);
|
|
311
|
+
this.addPoint(`${Delimiter1}${key}.${this.name}.${this.tmpPointId}`, false);
|
|
306
312
|
this.tmpPointId += 1;
|
|
307
313
|
}
|
|
308
314
|
this.scope.blockStack.set(this.scope.indentLevel, {
|
|
@@ -341,6 +347,7 @@ export class ExecutionContext {
|
|
|
341
347
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
342
348
|
stackRef['block_index'] = blockIndex;
|
|
343
349
|
const { type: blockType } = stackRef;
|
|
350
|
+
const blockTypeName = getBlockTypeString(blockType);
|
|
344
351
|
stackRef['inner_blocks'].set(blockIndex, {
|
|
345
352
|
last_net: null,
|
|
346
353
|
ignore_last_net: false,
|
|
@@ -353,7 +360,7 @@ export class ExecutionContext {
|
|
|
353
360
|
const { entered_at: [component, pin,] } = stackRef;
|
|
354
361
|
this.atComponent(component, pin, { addSequence: true });
|
|
355
362
|
}
|
|
356
|
-
this.log(`enter inner block of type (${
|
|
363
|
+
this.log(`enter inner block of type (${blockTypeName}) >>>`);
|
|
357
364
|
this.scope.indentLevel += 1;
|
|
358
365
|
}
|
|
359
366
|
exitBlock(blockIndex) {
|
|
@@ -377,7 +384,7 @@ export class ExecutionContext {
|
|
|
377
384
|
}
|
|
378
385
|
else if (blockType === BlockTypes.Join || blockType === BlockTypes.Parallel) {
|
|
379
386
|
if (blockIndex === 0) {
|
|
380
|
-
const pointIdName = (blockType
|
|
387
|
+
const pointIdName = `${Delimiter1}${getBlockTypeString(blockType)}`;
|
|
381
388
|
this.addPoint(`${pointIdName}.${this.name}.${this.tmpPointId}`, false);
|
|
382
389
|
this.tmpPointId += 1;
|
|
383
390
|
stackRef['final_point'] = [
|
|
@@ -411,7 +418,7 @@ export class ExecutionContext {
|
|
|
411
418
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
|
|
412
419
|
const { entered_at } = stackRef;
|
|
413
420
|
const component = entered_at[0];
|
|
414
|
-
if (component.instanceName.startsWith(
|
|
421
|
+
if (component.instanceName.startsWith(`${Delimiter1}point.`)) {
|
|
415
422
|
return entered_at;
|
|
416
423
|
}
|
|
417
424
|
}
|
|
@@ -526,14 +533,12 @@ export class ExecutionContext {
|
|
|
526
533
|
const currentComponent = this.scope.currentComponent;
|
|
527
534
|
const currentPin = this.scope.currentPin;
|
|
528
535
|
const currentWireId = this.scope.currentWireId;
|
|
529
|
-
const gndCopyIdOffset = 0;
|
|
530
536
|
const tmpInstances = childScope.instances;
|
|
531
537
|
const tmpNets = childScope.getNets();
|
|
532
538
|
for (const [instanceName, component] of tmpInstances) {
|
|
533
539
|
const newInstanceName = `${namespace}.${instanceName}`;
|
|
534
540
|
component.instanceName = newInstanceName;
|
|
535
|
-
if (component === childScope.
|
|
536
|
-
component === childScope.componentRoot) {
|
|
541
|
+
if (component === childScope.componentRoot) {
|
|
537
542
|
continue;
|
|
538
543
|
}
|
|
539
544
|
if (!this.scope.instances.has(newInstanceName)) {
|
|
@@ -543,6 +548,16 @@ export class ExecutionContext {
|
|
|
543
548
|
throw "Invalid instance name to merge into parent scope!";
|
|
544
549
|
}
|
|
545
550
|
}
|
|
551
|
+
const childScopeUniqueNets = new Set(tmpNets.map(([, , net]) => net));
|
|
552
|
+
childScopeUniqueNets.forEach(net => {
|
|
553
|
+
if (net.priority === 0
|
|
554
|
+
&& this.scope.getNetWithNamespacePath(net.namespace, net.name) !== null) {
|
|
555
|
+
this.log('net namespace and name already used in parent scope', net);
|
|
556
|
+
const newNetName = this.getUniqueNetName();
|
|
557
|
+
net.name = newNetName;
|
|
558
|
+
this.log('assigned new name: ', net);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
546
561
|
tmpNets.forEach(([component, pin, net]) => {
|
|
547
562
|
this.scope.setNet(component, pin, net);
|
|
548
563
|
});
|
|
@@ -557,7 +572,6 @@ export class ExecutionContext {
|
|
|
557
572
|
this.scope.setNet(currentComponent, currentPin, netConnectedToRoot);
|
|
558
573
|
currentNet = tmpNet;
|
|
559
574
|
}
|
|
560
|
-
netConnectedToRoot.priority = currentNet.priority - 1;
|
|
561
575
|
this.toComponent(tmpRoot, 1);
|
|
562
576
|
}
|
|
563
577
|
}
|
|
@@ -646,25 +660,65 @@ export class ExecutionContext {
|
|
|
646
660
|
this.log('Warning: ' + pointId + ' is being redefined');
|
|
647
661
|
}
|
|
648
662
|
const useName = userDefined ? 'point.' + pointId : pointId;
|
|
649
|
-
const componentPoint = ClassComponent.simple(useName, 1
|
|
650
|
-
componentPoint.displayProp = this.getPointSymbol();
|
|
663
|
+
const componentPoint = ClassComponent.simple(useName, 1);
|
|
664
|
+
componentPoint.displayProp = this.getPointSymbol(useName);
|
|
651
665
|
componentPoint.typeProp = ComponentTypes.net;
|
|
666
|
+
let usePointLinkComponent = null;
|
|
667
|
+
if (this.scope.currentComponent._pointLinkComponent) {
|
|
668
|
+
usePointLinkComponent = this.scope.currentComponent._pointLinkComponent;
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
usePointLinkComponent = this.scope.currentComponent;
|
|
672
|
+
}
|
|
673
|
+
componentPoint._pointLinkComponent = usePointLinkComponent;
|
|
652
674
|
this.scope.instances.set(pointId, componentPoint);
|
|
653
675
|
this.toComponent(componentPoint, 1, { addSequence: true });
|
|
654
676
|
return this.getCurrentPoint();
|
|
655
677
|
}
|
|
656
|
-
getPointSymbol() {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
[
|
|
660
|
-
|
|
661
|
-
|
|
678
|
+
getPointSymbol(name = "") {
|
|
679
|
+
const commands = [
|
|
680
|
+
[PlaceHolderCommands.pin,
|
|
681
|
+
[numeric(1), numeric(0), numeric(0),
|
|
682
|
+
numeric(0), numeric(0)],
|
|
683
|
+
new Map([
|
|
684
|
+
["display_pin_id", false]
|
|
685
|
+
]),
|
|
686
|
+
null
|
|
687
|
+
]
|
|
688
|
+
];
|
|
689
|
+
if (false) {
|
|
690
|
+
commands.push(...[
|
|
691
|
+
[PlaceHolderCommands.lineColor,
|
|
692
|
+
["red"],
|
|
693
|
+
new Map(), null
|
|
694
|
+
],
|
|
695
|
+
[PlaceHolderCommands.hline,
|
|
696
|
+
[numeric(-25), numeric(0), numeric(50)],
|
|
697
|
+
new Map(),
|
|
698
|
+
null
|
|
699
|
+
],
|
|
700
|
+
[PlaceHolderCommands.vline,
|
|
701
|
+
[numeric(0), numeric(-25), numeric(50)],
|
|
702
|
+
new Map(),
|
|
703
|
+
null
|
|
704
|
+
],
|
|
705
|
+
[PlaceHolderCommands.hline,
|
|
706
|
+
[numeric(0), numeric(0),
|
|
707
|
+
numeric(10)],
|
|
708
|
+
new Map([]), null
|
|
709
|
+
],
|
|
710
|
+
[PlaceHolderCommands.text,
|
|
711
|
+
[],
|
|
662
712
|
new Map([
|
|
663
|
-
["
|
|
713
|
+
["content", name],
|
|
714
|
+
["fontSize", numeric(10)],
|
|
664
715
|
]),
|
|
665
716
|
null
|
|
666
717
|
]
|
|
667
|
-
];
|
|
718
|
+
]);
|
|
719
|
+
}
|
|
720
|
+
return new SymbolDrawingCommands(() => {
|
|
721
|
+
return commands;
|
|
668
722
|
});
|
|
669
723
|
}
|
|
670
724
|
setProperty(nameWithProp, value) {
|
|
@@ -800,12 +854,11 @@ function isWireSegmentsEndAuto(segments) {
|
|
|
800
854
|
}
|
|
801
855
|
export function getPortSide(pins, arrangeProps) {
|
|
802
856
|
const result = [];
|
|
803
|
-
const maxPositions =
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
};
|
|
857
|
+
const maxPositions = new Map();
|
|
858
|
+
maxPositions.set(SymbolPinSide.Left, 0);
|
|
859
|
+
maxPositions.set(SymbolPinSide.Right, 0);
|
|
860
|
+
maxPositions.set(SymbolPinSide.Top, 0);
|
|
861
|
+
maxPositions.set(SymbolPinSide.Bottom, 0);
|
|
809
862
|
if (arrangeProps === null) {
|
|
810
863
|
let counter = 0;
|
|
811
864
|
for (const [pinId] of pins) {
|
|
@@ -823,8 +876,8 @@ export function getPortSide(pins, arrangeProps) {
|
|
|
823
876
|
const rightSideItems = result.filter(item => {
|
|
824
877
|
return item.side === PortSide.EAST;
|
|
825
878
|
});
|
|
826
|
-
maxPositions
|
|
827
|
-
maxPositions
|
|
879
|
+
maxPositions.set(SymbolPinSide.Left, leftSideItems.length);
|
|
880
|
+
maxPositions.set(SymbolPinSide.Right, rightSideItems.length);
|
|
828
881
|
}
|
|
829
882
|
else {
|
|
830
883
|
let counter = pins.size;
|
|
@@ -871,7 +924,7 @@ export function getPortSide(pins, arrangeProps) {
|
|
|
871
924
|
}
|
|
872
925
|
}
|
|
873
926
|
});
|
|
874
|
-
maxPositions
|
|
927
|
+
maxPositions.set(key, position);
|
|
875
928
|
}
|
|
876
929
|
}
|
|
877
930
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComponentTypes, NoNetText } from "./globals.
|
|
2
|
-
import { NumericValue } from "./objects/ParamDefinition.
|
|
1
|
+
import { ComponentTypes, NoNetText } from "./globals.js";
|
|
2
|
+
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
3
3
|
export function generateKiCADNetList(netlist) {
|
|
4
4
|
const componentsList = [];
|
|
5
5
|
const nets = {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Flatten from '@flatten-js/core';
|
|
2
|
-
import { measureTextSize2 } from './sizing.
|
|
3
|
-
import { defaultFont, fontDisplayScale, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical } from './globals.
|
|
4
|
-
import { numeric, NumericValue } from './objects/ParamDefinition.
|
|
5
|
-
import { AllPinTypes, PinTypes } from './objects/PinTypes.
|
|
6
|
-
import { roundValue } from './utils.
|
|
2
|
+
import { measureTextSize2 } from './sizing.js';
|
|
3
|
+
import { defaultFont, fontDisplayScale, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical } from './globals.js';
|
|
4
|
+
import { numeric, NumericValue } from './objects/ParamDefinition.js';
|
|
5
|
+
import { AllPinTypes, PinTypes } from './objects/PinTypes.js';
|
|
6
|
+
import { roundValue } from './utils.js';
|
|
7
7
|
export class Textbox extends Flatten.Polygon {
|
|
8
8
|
id;
|
|
9
9
|
text;
|
|
@@ -384,6 +384,7 @@ export class Geometry {
|
|
|
384
384
|
replaceSegments(existingSegments, j, splitCurrentSegments);
|
|
385
385
|
replaceSegments(newSegments, k, splitNewSegments);
|
|
386
386
|
j = Math.max(0, j - 1);
|
|
387
|
+
break;
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { numeric } from "./objects/ParamDefinition";
|
|
1
|
+
import { numeric } from "./objects/ParamDefinition.js";
|
|
2
|
+
export const TOOL_VERSION = '0.1.5';
|
|
3
|
+
export const Delimiter1 = '-';
|
|
4
|
+
export const DoubleDelimiter1 = `${Delimiter1}${Delimiter1}`;
|
|
2
5
|
export var GlobalNames;
|
|
3
6
|
(function (GlobalNames) {
|
|
4
|
-
GlobalNames["__root"] = "
|
|
7
|
+
GlobalNames["__root"] = "--root";
|
|
5
8
|
GlobalNames["symbol"] = "symbol";
|
|
6
9
|
})(GlobalNames || (GlobalNames = {}));
|
|
7
10
|
export const NoNetText = 'NO_NET';
|
|
@@ -26,6 +29,9 @@ export var SymbolPinSide;
|
|
|
26
29
|
SymbolPinSide["Top"] = "top";
|
|
27
30
|
SymbolPinSide["Bottom"] = "bottom";
|
|
28
31
|
})(SymbolPinSide || (SymbolPinSide = {}));
|
|
32
|
+
export const ValidPinSides = [
|
|
33
|
+
SymbolPinSide.Left, SymbolPinSide.Right, SymbolPinSide.Top, SymbolPinSide.Bottom
|
|
34
|
+
];
|
|
29
35
|
export var LengthUnit;
|
|
30
36
|
(function (LengthUnit) {
|
|
31
37
|
LengthUnit["mm"] = "mm";
|
|
@@ -108,3 +114,4 @@ export const RenderFlags = {
|
|
|
108
114
|
ShowLabelBoxBounds: false,
|
|
109
115
|
ShowLabelOrigin: false,
|
|
110
116
|
};
|
|
117
|
+
export const SymbolValidatorContext = '_sym';
|