circuitscript 0.0.13 → 0.0.15
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/.gitlab-ci.yml +22 -19
- package/__tests__/helpers.ts +12 -0
- package/__tests__/renderData/script1.cst.svg +1 -1
- package/__tests__/renderData/script2.cst.svg +1 -1
- package/__tests__/renderData/script3.cst.svg +1 -1
- package/__tests__/renderData/script4.cst +27 -5
- package/__tests__/renderData/script4.cst.svg +1 -1
- package/__tests__/renderData/script5.cst.svg +1 -1
- package/__tests__/testParse.ts +37 -2
- package/build/src/draw_symbols.js +209 -67
- package/build/src/geometry.js +35 -4
- package/build/src/globals.js +2 -1
- package/build/src/helpers.js +73 -0
- package/build/src/layout.js +30 -17
- package/build/src/main.js +2 -69
- package/build/src/regenerate-tests.js +2 -2
- package/build/src/sizing.js +4 -10
- package/build/src/visitor.js +12 -4
- package/examples/example_arduino_uno.cst +390 -120
- package/examples/lib.cst +25 -28
- package/libs/lib.cst +23 -28
- package/package.json +1 -1
- package/src/draw_symbols.ts +273 -71
- package/src/geometry.ts +48 -6
- package/src/globals.ts +3 -1
- package/src/helpers.ts +114 -0
- package/src/layout.ts +42 -21
- package/src/main.ts +2 -112
- package/src/regenerate-tests.ts +2 -2
- package/src/sizing.ts +5 -8
- package/src/visitor.ts +16 -4
package/build/src/main.js
CHANGED
|
@@ -3,15 +3,9 @@ import { program } from 'commander';
|
|
|
3
3
|
import figlet from 'figlet';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
|
-
import { readFileSync, watch
|
|
7
|
-
import { MainVisitor } from './visitor.js';
|
|
6
|
+
import { readFileSync, watch } from 'fs';
|
|
8
7
|
import { prepareSizing } from './sizing.js';
|
|
9
|
-
import {
|
|
10
|
-
import { generateSVG2 } from './render.js';
|
|
11
|
-
import { SequenceAction } from './objects/ExecutionScope.js';
|
|
12
|
-
import { parseFileWithVisitor } from './parser.js';
|
|
13
|
-
import { generateKiCADNetList } from './export.js';
|
|
14
|
-
import { SimpleStopwatch } from './utils.js';
|
|
8
|
+
import { renderScript } from './helpers.js';
|
|
15
9
|
export default async function main() {
|
|
16
10
|
const toolSrcPath = fileURLToPath(import.meta.url);
|
|
17
11
|
const toolDirectory = path.dirname(toolSrcPath) + '/../../';
|
|
@@ -84,65 +78,4 @@ export default async function main() {
|
|
|
84
78
|
});
|
|
85
79
|
}
|
|
86
80
|
}
|
|
87
|
-
export function renderScript(scriptData, outputPath, options) {
|
|
88
|
-
const { currentDirectory = null, defaultLibsPath, dumpNets = false, dumpData = false, kicadNetlistPath = null, showStats = false } = options;
|
|
89
|
-
const visitor = new MainVisitor(true);
|
|
90
|
-
visitor.onImportFile = visitor.createImportFileHandler(currentDirectory, defaultLibsPath);
|
|
91
|
-
visitor.print('reading file');
|
|
92
|
-
visitor.print('done reading file');
|
|
93
|
-
const { tree, parser, hasParseError, hasError, parserTimeTaken, lexerTimeTaken } = parseFileWithVisitor(visitor, scriptData);
|
|
94
|
-
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
95
|
-
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
96
|
-
dumpNets && console.log(visitor.dumpNets());
|
|
97
|
-
dumpData && writeFileSync('dump/tree.lisp', tree.toStringTree(null, parser));
|
|
98
|
-
dumpData && writeFileSync('dump/raw-parser.txt', visitor.logger.dump());
|
|
99
|
-
if (hasError || hasParseError) {
|
|
100
|
-
console.log('Error while parsing');
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
visitor.annotateComponents();
|
|
104
|
-
if (kicadNetlistPath) {
|
|
105
|
-
const kicadNetList = generateKiCADNetList(visitor.getNetList());
|
|
106
|
-
writeFileSync(kicadNetlistPath, kicadNetList);
|
|
107
|
-
console.log('Generated KiCad netlist file');
|
|
108
|
-
}
|
|
109
|
-
const { sequence, nets } = visitor.getGraph();
|
|
110
|
-
const tmpSequence = sequence.map(item => {
|
|
111
|
-
const tmp = [...item];
|
|
112
|
-
const action = tmp[0];
|
|
113
|
-
if (action === SequenceAction.Wire) {
|
|
114
|
-
tmp[2] = tmp[2].map(item2 => {
|
|
115
|
-
return [item2.direction, item2.value].join(",");
|
|
116
|
-
}).join(" ");
|
|
117
|
-
}
|
|
118
|
-
else if (action === SequenceAction.Frame) {
|
|
119
|
-
tmp[1] = item[1].frameId;
|
|
120
|
-
}
|
|
121
|
-
else if (action !== SequenceAction.WireJump) {
|
|
122
|
-
tmp[1] = item[1].instanceName;
|
|
123
|
-
}
|
|
124
|
-
return tmp.join(" | ");
|
|
125
|
-
});
|
|
126
|
-
dumpData && writeFileSync('dump/raw-sequence.txt', tmpSequence.join('\n'));
|
|
127
|
-
let svgOutput = null;
|
|
128
|
-
try {
|
|
129
|
-
const layoutEngine = new LayoutEngine();
|
|
130
|
-
const layoutTimer = new SimpleStopwatch();
|
|
131
|
-
const graph = layoutEngine.runLayout(sequence, nets);
|
|
132
|
-
layoutEngine.printWarnings();
|
|
133
|
-
showStats && console.log('Layout took:', layoutTimer.lap());
|
|
134
|
-
dumpData && writeFileSync('dump/raw-layout.txt', layoutEngine.logger.dump());
|
|
135
|
-
const generateSvgTimer = new SimpleStopwatch();
|
|
136
|
-
svgOutput = generateSVG2(graph);
|
|
137
|
-
showStats && console.log('Render took:', generateSvgTimer.lap());
|
|
138
|
-
if (outputPath) {
|
|
139
|
-
writeFileSync(outputPath, svgOutput);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
console.log('Failed to render:');
|
|
144
|
-
console.log(err);
|
|
145
|
-
}
|
|
146
|
-
return svgOutput;
|
|
147
|
-
}
|
|
148
81
|
main();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import { renderScript } from './
|
|
2
|
+
import { renderScript } from './helpers.js';
|
|
3
3
|
const mainDir = './__tests__/renderData/';
|
|
4
4
|
const cstFiles = [];
|
|
5
5
|
const files = fs.readdirSync(mainDir);
|
|
@@ -14,5 +14,5 @@ cstFiles.forEach(file => {
|
|
|
14
14
|
const scriptData = fs.readFileSync(inputPath, { encoding: 'utf-8' });
|
|
15
15
|
const outputPath = inputPath + '.svg';
|
|
16
16
|
renderScript(scriptData, outputPath, { currentDirectory: useCurrentDir });
|
|
17
|
-
console.log('generated ',
|
|
17
|
+
console.log('generated ', outputPath);
|
|
18
18
|
});
|
package/build/src/sizing.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { SVG, registerWindow } from '@svgdotjs/svg.js';
|
|
2
2
|
import { config, createSVGWindow } from 'svgdom';
|
|
3
3
|
import { HorizontalAlign, VerticalAlign } from './geometry.js';
|
|
4
|
+
import { defaultFont } from './globals.js';
|
|
4
5
|
let MainCanvas = null;
|
|
5
|
-
const supportedFonts = {
|
|
6
|
-
'Inter': 'Inter-Regular.ttf',
|
|
7
|
-
'Inter-Bold': 'Inter-Bold.ttf',
|
|
8
|
-
};
|
|
6
|
+
const supportedFonts = {};
|
|
9
7
|
export async function prepareSizing(fontsPath) {
|
|
10
8
|
await config.setFontDir(fontsPath)
|
|
11
9
|
.setFontFamilyMappings(supportedFonts)
|
|
@@ -39,17 +37,13 @@ export function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regul
|
|
|
39
37
|
dominantBaseline = 'text-top';
|
|
40
38
|
break;
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
fontFamily = 'Inter-Bold';
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
fontFamily = 'Inter-Regular';
|
|
47
|
-
}
|
|
40
|
+
fontFamily = defaultFont;
|
|
48
41
|
const tmpTextElement = MainCanvas.text(text).font({
|
|
49
42
|
family: fontFamily,
|
|
50
43
|
size: fontSize,
|
|
51
44
|
anchor: anchor,
|
|
52
45
|
'dominant-baseline': dominantBaseline,
|
|
46
|
+
weight: fontWeight,
|
|
53
47
|
}).fill('#333');
|
|
54
48
|
const textbox = tmpTextElement.bbox();
|
|
55
49
|
const { width, height } = textbox;
|
package/build/src/visitor.js
CHANGED
|
@@ -914,8 +914,8 @@ export class MainVisitor extends ParseTreeVisitor {
|
|
|
914
914
|
continue;
|
|
915
915
|
}
|
|
916
916
|
if (instance.typeProp === null) {
|
|
917
|
-
this.print('Instance has no type:', instance.instanceName);
|
|
918
|
-
|
|
917
|
+
this.print('Instance has no type:', instance.instanceName, ' assuming connector');
|
|
918
|
+
instance.typeProp = 'conn';
|
|
919
919
|
}
|
|
920
920
|
if (instance.parameters.has('refdes')) {
|
|
921
921
|
const refdes = instance.parameters.get('refdes');
|
|
@@ -1065,8 +1065,16 @@ class ComponentAnnotater {
|
|
|
1065
1065
|
this.counter['?'] = 1;
|
|
1066
1066
|
}
|
|
1067
1067
|
getAnnotation(type) {
|
|
1068
|
-
if (this.counter[type] === undefined) {
|
|
1069
|
-
|
|
1068
|
+
if (this.counter[type] === undefined && type.length <= 2) {
|
|
1069
|
+
for (const [, value] of Object.entries(ComponentRefDesPrefixes)) {
|
|
1070
|
+
if (value === type) {
|
|
1071
|
+
throw "Refdes prefix is already in use!";
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
if (ComponentRefDesPrefixes[type] === undefined) {
|
|
1075
|
+
ComponentRefDesPrefixes[type] = type;
|
|
1076
|
+
this.counter[type] = 1;
|
|
1077
|
+
}
|
|
1070
1078
|
}
|
|
1071
1079
|
let attempts = 100;
|
|
1072
1080
|
let proposedName;
|