circuitscript 0.0.12 → 0.0.14
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 +1 -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.svg +1 -1
- package/__tests__/renderData/script5.cst +23 -0
- package/__tests__/renderData/script5.cst.svg +1 -0
- package/__tests__/testCLI.ts +68 -0
- package/__tests__/testRender.ts +2 -1
- package/build/src/draw_symbols.js +5 -6
- package/build/src/globals.js +2 -1
- package/build/src/helpers.js +69 -0
- package/build/src/main.js +5 -74
- package/build/src/parser.js +0 -6
- package/build/src/regenerate-tests.js +1 -1
- package/build/src/sizing.js +4 -10
- package/examples/example_arduino_uno.cst +159 -138
- package/package.json +1 -1
- package/src/draw_symbols.ts +7 -9
- package/src/geometry.ts +2 -1
- package/src/globals.ts +3 -1
- package/src/helpers.ts +111 -0
- package/src/main.ts +6 -121
- package/src/parser.ts +6 -6
- package/src/regenerate-tests.ts +1 -1
- package/src/sizing.ts +5 -8
- /package/{server.js → server.cjs} +0 -0
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;
|
|
@@ -42,6 +42,10 @@ def solder_bridge():
|
|
|
42
42
|
return create component:
|
|
43
43
|
pins: 2
|
|
44
44
|
|
|
45
|
+
gnd = dgnd()
|
|
46
|
+
v3v3 = supply("3V3")
|
|
47
|
+
v5v = supply("5V")
|
|
48
|
+
|
|
45
49
|
atmega = create component:
|
|
46
50
|
pins:
|
|
47
51
|
1: "XTAL1"
|
|
@@ -189,7 +193,7 @@ at atmega:
|
|
|
189
193
|
wire left 40
|
|
190
194
|
branch:
|
|
191
195
|
wire up 20
|
|
192
|
-
to
|
|
196
|
+
to v5v
|
|
193
197
|
wire down 20
|
|
194
198
|
branch:
|
|
195
199
|
wire auto
|
|
@@ -223,7 +227,7 @@ at atmega:
|
|
|
223
227
|
to icsp_conn2 pin 5
|
|
224
228
|
|
|
225
229
|
branch:
|
|
226
|
-
at
|
|
230
|
+
at v5v
|
|
227
231
|
wire down 20 left 20
|
|
228
232
|
to icsp_conn2 pin 2
|
|
229
233
|
point tmp4
|
|
@@ -393,19 +397,19 @@ at atmega:
|
|
|
393
397
|
wire right 40
|
|
394
398
|
add label("RXLED")
|
|
395
399
|
wire right 100 down 100 right 60
|
|
396
|
-
add led("yellow") pin
|
|
400
|
+
add led("yellow") pin 2 right
|
|
397
401
|
wire right 20
|
|
398
402
|
add res(1k)
|
|
399
403
|
wire right 20 up 80
|
|
400
404
|
point tmp6
|
|
401
405
|
wire up 20
|
|
402
|
-
to
|
|
406
|
+
to v5v
|
|
403
407
|
|
|
404
408
|
11:
|
|
405
409
|
wire right 40
|
|
406
410
|
add label("TXLED")
|
|
407
411
|
wire right 120 down 40 right 40
|
|
408
|
-
add led("yellow") pin
|
|
412
|
+
add led("yellow") pin 2 right
|
|
409
413
|
wire right 20
|
|
410
414
|
add res(1k)
|
|
411
415
|
wire auto
|
|
@@ -419,11 +423,11 @@ power_conn2 = create component:
|
|
|
419
423
|
|
|
420
424
|
at power_conn2:
|
|
421
425
|
2:
|
|
422
|
-
wire left
|
|
423
|
-
add
|
|
426
|
+
wire left 60 up 80
|
|
427
|
+
add v3v3
|
|
424
428
|
3:
|
|
425
|
-
wire left
|
|
426
|
-
to
|
|
429
|
+
wire left 100 up 100
|
|
430
|
+
to v5v
|
|
427
431
|
|
|
428
432
|
4:
|
|
429
433
|
wire left 20 down 20
|
|
@@ -446,7 +450,7 @@ at atmega8:
|
|
|
446
450
|
wire up 20
|
|
447
451
|
add res(10k) pin 2 ..angle=90
|
|
448
452
|
wire up 20
|
|
449
|
-
to
|
|
453
|
+
to v5v
|
|
450
454
|
branch:
|
|
451
455
|
wire left 40 up 420 right 120
|
|
452
456
|
to power_conn2 pin 1
|
|
@@ -482,7 +486,7 @@ at atmega8:
|
|
|
482
486
|
wire left 40
|
|
483
487
|
branch:
|
|
484
488
|
wire up 20
|
|
485
|
-
to
|
|
489
|
+
to v5v
|
|
486
490
|
wire down 20
|
|
487
491
|
add cap(100n)
|
|
488
492
|
wire down 20
|
|
@@ -626,7 +630,7 @@ at icsp_conn:
|
|
|
626
630
|
to gnd
|
|
627
631
|
2:
|
|
628
632
|
wire right 20 up 20
|
|
629
|
-
to
|
|
633
|
+
to v5v
|
|
630
634
|
|
|
631
635
|
5:
|
|
632
636
|
wire left 140
|
|
@@ -649,23 +653,6 @@ at icsp_conn:
|
|
|
649
653
|
to gnd
|
|
650
654
|
|
|
651
655
|
|
|
652
|
-
# Block for 5V leds
|
|
653
|
-
at net("5V")
|
|
654
|
-
wire down 20
|
|
655
|
-
branch:
|
|
656
|
-
wire right 20
|
|
657
|
-
add res(1k)
|
|
658
|
-
wire right 20
|
|
659
|
-
point tmp9
|
|
660
|
-
wire right 20
|
|
661
|
-
add led("green") pin 2
|
|
662
|
-
wire right 20 down 20
|
|
663
|
-
to gnd
|
|
664
|
-
wire down 40 right 20
|
|
665
|
-
add res(1k)
|
|
666
|
-
wire auto_
|
|
667
|
-
to tmp9
|
|
668
|
-
|
|
669
656
|
# 3V3 output converter
|
|
670
657
|
dcdc_3v3 = create component:
|
|
671
658
|
pins:
|
|
@@ -724,123 +711,157 @@ fet = create component:
|
|
|
724
711
|
param:
|
|
725
712
|
manufacturer_pn: "FDN304V"
|
|
726
713
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
wire right
|
|
736
|
-
add
|
|
737
|
-
wire right 20
|
|
738
|
-
to opamp_1 pin 3
|
|
739
|
-
|
|
740
|
-
at label("3V3")
|
|
741
|
-
wire right 40
|
|
742
|
-
to opamp_1 pin 2
|
|
743
|
-
|
|
744
|
-
at label("USBVCC")
|
|
745
|
-
wire right 40 to fet pin 1
|
|
746
|
-
|
|
747
|
-
at opamp_1 pin 1
|
|
748
|
-
wire right 80 down 100 left 20
|
|
749
|
-
to fet pin 2
|
|
750
|
-
|
|
751
|
-
at fet pin 3
|
|
752
|
-
wire right 60
|
|
753
|
-
branch:
|
|
754
|
-
wire up 20
|
|
755
|
-
to net("5V")
|
|
756
|
-
wire right 60
|
|
757
|
-
branch:
|
|
758
|
-
wire right 20
|
|
759
|
-
to dcdc_3v3 pin 1
|
|
760
|
-
wire auto_
|
|
761
|
-
to dcdc_3v3 pin 3
|
|
762
|
-
|
|
763
|
-
at dcdc_3v3:
|
|
764
|
-
2:
|
|
765
|
-
wire left 20 down 20
|
|
766
|
-
to gnd
|
|
767
|
-
|
|
768
|
-
5:
|
|
769
|
-
wire right 20
|
|
770
|
-
add label("3V3")
|
|
771
|
-
wire right 20 down 20
|
|
772
|
-
add cap(1u)
|
|
773
|
-
to gnd
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
# Block for 5V power
|
|
778
|
-
power_conn = create component:
|
|
779
|
-
pins: 3
|
|
780
|
-
arrange:
|
|
781
|
-
left: 1,3
|
|
782
|
-
right: 2
|
|
783
|
-
|
|
784
|
-
at power_conn:
|
|
785
|
-
1:
|
|
786
|
-
wire left 20 down 20
|
|
787
|
-
branch:
|
|
788
|
-
wire auto
|
|
789
|
-
to power_conn pin 3
|
|
714
|
+
frame:
|
|
715
|
+
..title = "Supply generation"
|
|
716
|
+
..direction = "row"
|
|
717
|
+
|
|
718
|
+
frame:
|
|
719
|
+
..title = "3V3 power"
|
|
720
|
+
|
|
721
|
+
at label("VIN")
|
|
722
|
+
wire right 40 down 20
|
|
723
|
+
add res(10k) ..angle=90
|
|
790
724
|
wire down 20
|
|
791
|
-
to gnd
|
|
792
|
-
2:
|
|
793
|
-
wire right 20
|
|
794
|
-
add label("PWRIN")
|
|
795
|
-
wire right 40
|
|
796
|
-
add diode()
|
|
797
|
-
wire right 40
|
|
798
725
|
branch:
|
|
799
726
|
wire down 20
|
|
800
|
-
add
|
|
727
|
+
add res(10k) ..angle=90
|
|
801
728
|
to gnd
|
|
729
|
+
wire right 80
|
|
730
|
+
add label("CMP")
|
|
802
731
|
wire right 20
|
|
803
|
-
|
|
732
|
+
to opamp_1 pin 3
|
|
804
733
|
|
|
805
|
-
at
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
to gnd
|
|
809
|
-
3:
|
|
810
|
-
wire left 80
|
|
811
|
-
to tmp10
|
|
734
|
+
at v3v3 left
|
|
735
|
+
wire right 20
|
|
736
|
+
to opamp_1 pin 2
|
|
812
737
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
wire right
|
|
822
|
-
point tmp11
|
|
738
|
+
at label("USBVCC")
|
|
739
|
+
wire right 40 to fet pin 1
|
|
740
|
+
|
|
741
|
+
at opamp_1 pin 1
|
|
742
|
+
wire right 80 down 100 left 20
|
|
743
|
+
to fet pin 2
|
|
744
|
+
|
|
745
|
+
at fet pin 3
|
|
746
|
+
wire right 60
|
|
823
747
|
branch:
|
|
824
|
-
wire
|
|
825
|
-
|
|
826
|
-
to gnd
|
|
748
|
+
wire up 20
|
|
749
|
+
to v5v
|
|
827
750
|
wire right 60
|
|
828
751
|
branch:
|
|
829
|
-
wire
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
752
|
+
wire right 20
|
|
753
|
+
to dcdc_3v3 pin 1
|
|
754
|
+
wire auto_
|
|
755
|
+
to dcdc_3v3 pin 3
|
|
756
|
+
|
|
757
|
+
at dcdc_3v3:
|
|
758
|
+
2:
|
|
759
|
+
wire left 20 down 20
|
|
760
|
+
to gnd
|
|
761
|
+
|
|
762
|
+
5:
|
|
763
|
+
wire right 40
|
|
764
|
+
branch:
|
|
765
|
+
wire up 20
|
|
766
|
+
to v3v3
|
|
767
|
+
wire down 20
|
|
768
|
+
add cap(1u)
|
|
769
|
+
to gnd
|
|
770
|
+
|
|
835
771
|
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
772
|
+
frame:
|
|
773
|
+
..title = "5V power"
|
|
774
|
+
|
|
775
|
+
# Block for 5V power
|
|
776
|
+
power_conn = create component:
|
|
777
|
+
pins: 3
|
|
778
|
+
arrange:
|
|
779
|
+
left: 1,3
|
|
780
|
+
right: 2
|
|
781
|
+
|
|
782
|
+
at power_conn:
|
|
783
|
+
1:
|
|
784
|
+
wire left 20 down 20
|
|
785
|
+
branch:
|
|
786
|
+
wire auto
|
|
787
|
+
to power_conn pin 3
|
|
788
|
+
wire down 20
|
|
789
|
+
to gnd
|
|
790
|
+
2:
|
|
791
|
+
wire right 20
|
|
792
|
+
add label("PWRIN")
|
|
793
|
+
wire right 40
|
|
794
|
+
add diode()
|
|
795
|
+
wire right 40
|
|
796
|
+
branch:
|
|
797
|
+
wire down 20
|
|
798
|
+
add cap(47u)
|
|
799
|
+
to gnd
|
|
800
|
+
wire right 20
|
|
801
|
+
point tmp10
|
|
802
|
+
|
|
803
|
+
at dcdc_5V:
|
|
804
|
+
1:
|
|
805
|
+
wire left 20 down 20
|
|
806
|
+
to gnd
|
|
807
|
+
3:
|
|
808
|
+
wire left 80
|
|
809
|
+
to tmp10
|
|
810
|
+
|
|
811
|
+
wire up 20
|
|
812
|
+
branch:
|
|
813
|
+
wire right 20
|
|
814
|
+
add label("VIN")
|
|
815
|
+
wire right 40
|
|
816
|
+
wire up 100 right 80
|
|
817
|
+
to dcdc_5V_2 pin 3
|
|
818
|
+
2:
|
|
819
|
+
wire right 40
|
|
820
|
+
point tmp11
|
|
821
|
+
branch:
|
|
822
|
+
wire down 20
|
|
823
|
+
add cap(47u)
|
|
824
|
+
to gnd
|
|
825
|
+
wire right 60
|
|
826
|
+
branch:
|
|
827
|
+
wire down 20
|
|
828
|
+
add cap(100n)
|
|
829
|
+
to gnd
|
|
830
|
+
wire right 20 up 20
|
|
831
|
+
to v5v
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
at dcdc_5V_2:
|
|
835
|
+
1:
|
|
836
|
+
wire left 20 down 20
|
|
837
|
+
to gnd
|
|
838
|
+
4:
|
|
839
|
+
wire right 20 down 20
|
|
840
|
+
branch:
|
|
841
|
+
wire auto
|
|
842
|
+
to dcdc_5V_2 pin 2
|
|
843
|
+
wire auto
|
|
844
|
+
to tmp11
|
|
845
|
+
|
|
846
|
+
frame:
|
|
847
|
+
..title = "5V indication"
|
|
848
|
+
..border = 0
|
|
849
|
+
|
|
850
|
+
# Block for 5V leds
|
|
851
|
+
at v5v
|
|
852
|
+
wire down 20
|
|
853
|
+
branch:
|
|
854
|
+
wire right 20
|
|
855
|
+
add res(1k)
|
|
856
|
+
wire right 20
|
|
857
|
+
point tmp9
|
|
858
|
+
wire right 20
|
|
859
|
+
|
|
860
|
+
add led("green")
|
|
861
|
+
wire right 20 down 20
|
|
862
|
+
to gnd
|
|
863
|
+
|
|
864
|
+
wire down 40 right 20
|
|
865
|
+
add res(1k)
|
|
866
|
+
wire auto_
|
|
867
|
+
to tmp9
|
package/package.json
CHANGED
package/src/draw_symbols.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { G } from "@svgdotjs/svg.js";
|
|
2
2
|
|
|
3
|
-
import { SymbolPinSide, bodyColor, defaultFont } from "./globals.js";
|
|
3
|
+
import { SymbolPinSide, bodyColor, defaultFontBold, defaultFont } from "./globals.js";
|
|
4
4
|
import { Feature, Geometry, GeometryProp, HorizontalAlign, Label, LabelStyle, VerticalAlign } from "./geometry.js";
|
|
5
5
|
import { Logger } from "./logger.js";
|
|
6
6
|
|
|
@@ -160,7 +160,9 @@ export abstract class SymbolGraphic {
|
|
|
160
160
|
let dominantBaseline = 'auto';
|
|
161
161
|
|
|
162
162
|
let useAnchor = anchor;
|
|
163
|
-
|
|
163
|
+
const isRotation180 = Math.abs(this.angle) === 180;
|
|
164
|
+
|
|
165
|
+
if (isRotation180){
|
|
164
166
|
// Special case to flip the text instead of rotating
|
|
165
167
|
useAnchor = this.flipTextAnchor(anchor);
|
|
166
168
|
}
|
|
@@ -194,11 +196,7 @@ export abstract class SymbolGraphic {
|
|
|
194
196
|
}
|
|
195
197
|
|
|
196
198
|
const position = tmpLabel.getLabelPosition();
|
|
197
|
-
|
|
198
|
-
let useFont = defaultFont;
|
|
199
|
-
if (fontWeight === 'bold'){
|
|
200
|
-
useFont = 'Inter-Bold';
|
|
201
|
-
}
|
|
199
|
+
const useFont = defaultFont;
|
|
202
200
|
|
|
203
201
|
const text = group.text(tmpLabel.text)
|
|
204
202
|
.fill('#333')
|
|
@@ -207,10 +205,10 @@ export abstract class SymbolGraphic {
|
|
|
207
205
|
size: fontSize,
|
|
208
206
|
anchor: anchorStyle,
|
|
209
207
|
'dominant-baseline': dominantBaseline,
|
|
210
|
-
|
|
208
|
+
weight: fontWeight,
|
|
211
209
|
});
|
|
212
210
|
|
|
213
|
-
if (
|
|
211
|
+
if (isRotation180){
|
|
214
212
|
text.translate(-position[0], position[1]);
|
|
215
213
|
} else {
|
|
216
214
|
text.translate(position[0], position[1])
|
package/src/geometry.ts
CHANGED
|
@@ -68,7 +68,8 @@ export class Label extends Flatten.Polygon {
|
|
|
68
68
|
fontWeight = 'regular',
|
|
69
69
|
} = style ?? {};
|
|
70
70
|
|
|
71
|
-
// Determine the size of the text
|
|
71
|
+
// Determine the size of the text, this is needed to determine the
|
|
72
|
+
// bounding box of the text for layout purposes.
|
|
72
73
|
const { width, height, box } =
|
|
73
74
|
measureTextSize2(text, defaultFont, fontSize, fontWeight,
|
|
74
75
|
anchor, vanchor);
|
package/src/globals.ts
CHANGED
|
@@ -33,7 +33,9 @@ export enum SymbolPinSide {
|
|
|
33
33
|
export const portWidth = 20;
|
|
34
34
|
export const portHeight = 2;
|
|
35
35
|
|
|
36
|
-
export const defaultFont = '
|
|
36
|
+
export const defaultFont = 'Open Sans-Regular, Arial';
|
|
37
|
+
export const defaultFontBold = 'Open Sans-Bold, Arial-Bold, Arial';
|
|
38
|
+
|
|
37
39
|
export const defaultFontSize = 10;
|
|
38
40
|
|
|
39
41
|
export const bodyColor = '#FFFEAF';
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { writeFileSync } from "fs";
|
|
2
|
+
import { generateKiCADNetList } from "./export.js";
|
|
3
|
+
import { LayoutEngine } from "./layout.js";
|
|
4
|
+
import { SequenceAction } from "./objects/ExecutionScope.js";
|
|
5
|
+
import { parseFileWithVisitor } from "./parser.js";
|
|
6
|
+
import { generateSVG2 } from "./render.js";
|
|
7
|
+
import { SimpleStopwatch } from "./utils.js";
|
|
8
|
+
import { MainVisitor } from "./visitor.js";
|
|
9
|
+
|
|
10
|
+
export function renderScript(scriptData: string, outputPath: string, options): string {
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
currentDirectory = null,
|
|
14
|
+
defaultLibsPath,
|
|
15
|
+
dumpNets = false,
|
|
16
|
+
dumpData = false,
|
|
17
|
+
kicadNetlistPath = null,
|
|
18
|
+
showStats = false} = options;
|
|
19
|
+
|
|
20
|
+
const visitor = new MainVisitor(true);
|
|
21
|
+
|
|
22
|
+
visitor.onImportFile = visitor.createImportFileHandler(currentDirectory, defaultLibsPath);
|
|
23
|
+
|
|
24
|
+
visitor.print('reading file');
|
|
25
|
+
visitor.print('done reading file');
|
|
26
|
+
|
|
27
|
+
const { tree, parser,
|
|
28
|
+
hasParseError, hasError,
|
|
29
|
+
parserTimeTaken,
|
|
30
|
+
lexerTimeTaken } = parseFileWithVisitor(visitor, scriptData);
|
|
31
|
+
|
|
32
|
+
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
33
|
+
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
34
|
+
dumpNets && console.log(visitor.dumpNets());
|
|
35
|
+
|
|
36
|
+
dumpData && writeFileSync('dump/tree.lisp', tree.toStringTree(null, parser));
|
|
37
|
+
dumpData && writeFileSync('dump/raw-parser.txt', visitor.logger.dump());
|
|
38
|
+
|
|
39
|
+
if (hasError || hasParseError) {
|
|
40
|
+
console.log('Error while parsing');
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
visitor.annotateComponents();
|
|
45
|
+
|
|
46
|
+
if (kicadNetlistPath) {
|
|
47
|
+
const kicadNetList = generateKiCADNetList(visitor.getNetList());
|
|
48
|
+
writeFileSync(kicadNetlistPath, kicadNetList);
|
|
49
|
+
console.log('Generated KiCad netlist file');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// await writeFile('dump/raw-netlist.json', JSON.stringify(visitor.dump2(), null, 2));
|
|
54
|
+
|
|
55
|
+
const { sequence, nets } = visitor.getGraph();
|
|
56
|
+
|
|
57
|
+
// const tmpInstances = visitor.getExecutor().scope.instances;
|
|
58
|
+
// for (const [instanceName, instance] of tmpInstances){
|
|
59
|
+
// console.log(instanceName);
|
|
60
|
+
// console.log(instance.pinNets);
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const tmpSequence = sequence.map(item => {
|
|
65
|
+
const tmp = [...item];
|
|
66
|
+
|
|
67
|
+
const action = tmp[0];
|
|
68
|
+
|
|
69
|
+
if (action === SequenceAction.Wire) {
|
|
70
|
+
tmp[2] = tmp[2].map(item2 => {
|
|
71
|
+
return [item2.direction, item2.value].join(",");
|
|
72
|
+
}).join(" ");
|
|
73
|
+
} else if (action === SequenceAction.Frame) {
|
|
74
|
+
tmp[1] = item[1].frameId;
|
|
75
|
+
|
|
76
|
+
} else if (action !== SequenceAction.WireJump) {
|
|
77
|
+
tmp[1] = item[1].instanceName;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return tmp.join(" | ");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
dumpData && writeFileSync('dump/raw-sequence.txt', tmpSequence.join('\n'));
|
|
84
|
+
let svgOutput: string = null;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const layoutEngine = new LayoutEngine();
|
|
88
|
+
const layoutTimer = new SimpleStopwatch();
|
|
89
|
+
|
|
90
|
+
const graph = layoutEngine.runLayout(sequence, nets);
|
|
91
|
+
|
|
92
|
+
layoutEngine.printWarnings();
|
|
93
|
+
|
|
94
|
+
showStats && console.log('Layout took:', layoutTimer.lap());
|
|
95
|
+
|
|
96
|
+
dumpData && writeFileSync('dump/raw-layout.txt', layoutEngine.logger.dump());
|
|
97
|
+
|
|
98
|
+
const generateSvgTimer = new SimpleStopwatch();
|
|
99
|
+
svgOutput = generateSVG2(graph);
|
|
100
|
+
showStats && console.log('Render took:', generateSvgTimer.lap());
|
|
101
|
+
|
|
102
|
+
if (outputPath){
|
|
103
|
+
writeFileSync(outputPath, svgOutput);
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.log('Failed to render:');
|
|
107
|
+
console.log(err)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return svgOutput;
|
|
111
|
+
}
|