kicadts 0.0.1
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/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +111 -0
- package/.vscode/settings.json +16 -0
- package/AGENTS.md +30 -0
- package/README.md +206 -0
- package/biome.json +93 -0
- package/bun.lock +48 -0
- package/bunfig.toml +5 -0
- package/lib/index.ts +1 -0
- package/lib/sexpr/base-classes/SxClass.ts +164 -0
- package/lib/sexpr/base-classes/SxPrimitiveBoolean.ts +35 -0
- package/lib/sexpr/base-classes/SxPrimitiveNumber.ts +26 -0
- package/lib/sexpr/base-classes/SxPrimitiveString.ts +26 -0
- package/lib/sexpr/classes/At.ts +38 -0
- package/lib/sexpr/classes/Bus.ts +83 -0
- package/lib/sexpr/classes/BusEntry.ts +142 -0
- package/lib/sexpr/classes/Color.ts +29 -0
- package/lib/sexpr/classes/Dnp.ts +8 -0
- package/lib/sexpr/classes/EmbeddedFonts.ts +70 -0
- package/lib/sexpr/classes/ExcludeFromSim.ts +8 -0
- package/lib/sexpr/classes/FieldsAutoplaced.ts +8 -0
- package/lib/sexpr/classes/Footprint.ts +719 -0
- package/lib/sexpr/classes/FootprintAttr.ts +102 -0
- package/lib/sexpr/classes/FootprintAutoplaceCost180.ts +9 -0
- package/lib/sexpr/classes/FootprintAutoplaceCost90.ts +9 -0
- package/lib/sexpr/classes/FootprintClearance.ts +9 -0
- package/lib/sexpr/classes/FootprintDescr.ts +44 -0
- package/lib/sexpr/classes/FootprintLocked.ts +32 -0
- package/lib/sexpr/classes/FootprintModel.ts +145 -0
- package/lib/sexpr/classes/FootprintNetTiePadGroups.ts +50 -0
- package/lib/sexpr/classes/FootprintPad.ts +705 -0
- package/lib/sexpr/classes/FootprintPath.ts +44 -0
- package/lib/sexpr/classes/FootprintPlaced.ts +32 -0
- package/lib/sexpr/classes/FootprintPrivateLayers.ts +56 -0
- package/lib/sexpr/classes/FootprintSheetfile.ts +44 -0
- package/lib/sexpr/classes/FootprintSheetname.ts +44 -0
- package/lib/sexpr/classes/FootprintSolderMaskMargin.ts +9 -0
- package/lib/sexpr/classes/FootprintSolderPasteMargin.ts +9 -0
- package/lib/sexpr/classes/FootprintSolderPasteRatio.ts +9 -0
- package/lib/sexpr/classes/FootprintTags.ts +44 -0
- package/lib/sexpr/classes/FootprintTedit.ts +21 -0
- package/lib/sexpr/classes/FootprintThermalGap.ts +9 -0
- package/lib/sexpr/classes/FootprintThermalWidth.ts +9 -0
- package/lib/sexpr/classes/FootprintZoneConnect.ts +9 -0
- package/lib/sexpr/classes/FpArc.ts +289 -0
- package/lib/sexpr/classes/FpCircle.ts +293 -0
- package/lib/sexpr/classes/FpLine.ts +288 -0
- package/lib/sexpr/classes/FpPoly.ts +266 -0
- package/lib/sexpr/classes/FpPolyFill.ts +48 -0
- package/lib/sexpr/classes/FpPolyLocked.ts +40 -0
- package/lib/sexpr/classes/FpRect.ts +293 -0
- package/lib/sexpr/classes/FpText.ts +341 -0
- package/lib/sexpr/classes/FpTextBox.ts +412 -0
- package/lib/sexpr/classes/GrLine.ts +245 -0
- package/lib/sexpr/classes/GrLineAngle.ts +32 -0
- package/lib/sexpr/classes/GrLineEnd.ts +61 -0
- package/lib/sexpr/classes/GrLineLocked.ts +40 -0
- package/lib/sexpr/classes/GrLineStart.ts +61 -0
- package/lib/sexpr/classes/GrText.ts +202 -0
- package/lib/sexpr/classes/Image.ts +256 -0
- package/lib/sexpr/classes/InBom.ts +8 -0
- package/lib/sexpr/classes/Junction.ts +134 -0
- package/lib/sexpr/classes/KicadPcb.ts +313 -0
- package/lib/sexpr/classes/KicadSch.ts +303 -0
- package/lib/sexpr/classes/KicadSchGenerator.ts +32 -0
- package/lib/sexpr/classes/KicadSchGeneratorVersion.ts +30 -0
- package/lib/sexpr/classes/KicadSchVersion.ts +22 -0
- package/lib/sexpr/classes/Label.ts +136 -0
- package/lib/sexpr/classes/Layer.ts +51 -0
- package/lib/sexpr/classes/Layers.ts +47 -0
- package/lib/sexpr/classes/LibSymbols.ts +61 -0
- package/lib/sexpr/classes/NoConnect.ts +73 -0
- package/lib/sexpr/classes/OnBoard.ts +8 -0
- package/lib/sexpr/classes/PadChamfer.ts +50 -0
- package/lib/sexpr/classes/PadChamferRatio.ts +9 -0
- package/lib/sexpr/classes/PadClearance.ts +9 -0
- package/lib/sexpr/classes/PadDieLength.ts +9 -0
- package/lib/sexpr/classes/PadDrill.ts +145 -0
- package/lib/sexpr/classes/PadDrillOffset.ts +54 -0
- package/lib/sexpr/classes/PadLayers.ts +59 -0
- package/lib/sexpr/classes/PadNet.ts +56 -0
- package/lib/sexpr/classes/PadOptions.ts +182 -0
- package/lib/sexpr/classes/PadPinFunction.ts +9 -0
- package/lib/sexpr/classes/PadPinType.ts +9 -0
- package/lib/sexpr/classes/PadPrimitiveGrArc.ts +254 -0
- package/lib/sexpr/classes/PadPrimitiveGrCircle.ts +279 -0
- package/lib/sexpr/classes/PadPrimitiveGrLine.ts +126 -0
- package/lib/sexpr/classes/PadPrimitives.ts +289 -0
- package/lib/sexpr/classes/PadRectDelta.ts +57 -0
- package/lib/sexpr/classes/PadRoundrectRratio.ts +9 -0
- package/lib/sexpr/classes/PadSize.ts +54 -0
- package/lib/sexpr/classes/PadSolderMaskMargin.ts +9 -0
- package/lib/sexpr/classes/PadSolderPasteMargin.ts +9 -0
- package/lib/sexpr/classes/PadSolderPasteMarginRatio.ts +9 -0
- package/lib/sexpr/classes/PadTeardrops.ts +208 -0
- package/lib/sexpr/classes/PadThermalBridgeAngle.ts +9 -0
- package/lib/sexpr/classes/PadThermalGap.ts +9 -0
- package/lib/sexpr/classes/PadThermalWidth.ts +9 -0
- package/lib/sexpr/classes/PadZoneConnect.ts +9 -0
- package/lib/sexpr/classes/Paper.ts +119 -0
- package/lib/sexpr/classes/PcbGeneral.ts +75 -0
- package/lib/sexpr/classes/PcbGeneralLegacyTeardrops.ts +44 -0
- package/lib/sexpr/classes/PcbGeneralThickness.ts +9 -0
- package/lib/sexpr/classes/PcbGenerator.ts +16 -0
- package/lib/sexpr/classes/PcbGeneratorVersion.ts +16 -0
- package/lib/sexpr/classes/PcbLayerDefinition.ts +102 -0
- package/lib/sexpr/classes/PcbLayers.ts +34 -0
- package/lib/sexpr/classes/PcbNet.ts +56 -0
- package/lib/sexpr/classes/PcbVersion.ts +9 -0
- package/lib/sexpr/classes/Property.ts +246 -0
- package/lib/sexpr/classes/PropertyHide.ts +9 -0
- package/lib/sexpr/classes/PropertyUnlocked.ts +9 -0
- package/lib/sexpr/classes/Pts.ts +65 -0
- package/lib/sexpr/classes/RenderCache.ts +221 -0
- package/lib/sexpr/classes/SchematicText.ts +141 -0
- package/lib/sexpr/classes/Segment.ts +222 -0
- package/lib/sexpr/classes/SegmentEnd.ts +59 -0
- package/lib/sexpr/classes/SegmentLocked.ts +33 -0
- package/lib/sexpr/classes/SegmentNet.ts +62 -0
- package/lib/sexpr/classes/SegmentStart.ts +59 -0
- package/lib/sexpr/classes/Setup/PcbPlotParams.ts +729 -0
- package/lib/sexpr/classes/Setup/PcbPlotParamsBase.ts +9 -0
- package/lib/sexpr/classes/Setup/PcbPlotParamsNumericProperties.ts +105 -0
- package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesA.ts +104 -0
- package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesB.ts +105 -0
- package/lib/sexpr/classes/Setup/Setup.ts +573 -0
- package/lib/sexpr/classes/Setup/SetupPropertyTypes.ts +119 -0
- package/lib/sexpr/classes/Setup/Stackup.ts +140 -0
- package/lib/sexpr/classes/Setup/StackupLayer.ts +233 -0
- package/lib/sexpr/classes/Setup/StackupLayerProperties.ts +78 -0
- package/lib/sexpr/classes/Setup/StackupProperties.ts +41 -0
- package/lib/sexpr/classes/Setup/base.ts +167 -0
- package/lib/sexpr/classes/Setup/index.ts +14 -0
- package/lib/sexpr/classes/Setup/setupMultiValueProperties.ts +54 -0
- package/lib/sexpr/classes/Setup/setupNumericProperties.ts +151 -0
- package/lib/sexpr/classes/Setup/setupPropertyHandlers.ts +90 -0
- package/lib/sexpr/classes/Setup/setupStringProperties.ts +75 -0
- package/lib/sexpr/classes/Sheet.ts +205 -0
- package/lib/sexpr/classes/SheetFill.ts +44 -0
- package/lib/sexpr/classes/SheetInstances.ts +168 -0
- package/lib/sexpr/classes/SheetInstancesRoot.ts +165 -0
- package/lib/sexpr/classes/SheetPin.ts +122 -0
- package/lib/sexpr/classes/SheetProperty.ts +115 -0
- package/lib/sexpr/classes/SheetSize.ts +44 -0
- package/lib/sexpr/classes/Stroke.ts +58 -0
- package/lib/sexpr/classes/StrokeType.ts +34 -0
- package/lib/sexpr/classes/Symbol.ts +1541 -0
- package/lib/sexpr/classes/TextEffects.ts +444 -0
- package/lib/sexpr/classes/TitleBlock.ts +352 -0
- package/lib/sexpr/classes/Unit.ts +28 -0
- package/lib/sexpr/classes/Uuid.ts +8 -0
- package/lib/sexpr/classes/Via.ts +328 -0
- package/lib/sexpr/classes/ViaNet.ts +59 -0
- package/lib/sexpr/classes/Width.ts +8 -0
- package/lib/sexpr/classes/Wire.ts +91 -0
- package/lib/sexpr/classes/Xy.ts +35 -0
- package/lib/sexpr/classes/Zone.ts +41 -0
- package/lib/sexpr/index.ts +130 -0
- package/lib/sexpr/parseKicadSexpr.ts +5 -0
- package/lib/sexpr/parseToPrimitiveSExpr.ts +240 -0
- package/lib/sexpr/utils/indentLines.ts +3 -0
- package/lib/sexpr/utils/parseYesNo.ts +12 -0
- package/lib/sexpr/utils/quoteSExprString.ts +8 -0
- package/lib/sexpr/utils/strokeFromArgs.ts +19 -0
- package/lib/sexpr/utils/toNumberValue.ts +13 -0
- package/lib/sexpr/utils/toStringValue.ts +10 -0
- package/package.json +26 -0
- package/scripts/download-references.ts +66 -0
- package/tests/fixtures/expectEqualPrimitiveSExpr.ts +200 -0
- package/tests/sexpr/KicadPcbDemos.test.ts +48 -0
- package/tests/sexpr/KicadSchDemos.test.ts +49 -0
- package/tests/sexpr/classes/Footprint.test.ts +277 -0
- package/tests/sexpr/classes/FootprintPad.test.ts +71 -0
- package/tests/sexpr/classes/FpArc.test.ts +45 -0
- package/tests/sexpr/classes/FpCircle.test.ts +39 -0
- package/tests/sexpr/classes/FpPoly.test.ts +43 -0
- package/tests/sexpr/classes/FpRect.test.ts +40 -0
- package/tests/sexpr/classes/FpTextBox.test.ts +84 -0
- package/tests/sexpr/classes/Image.test.ts +50 -0
- package/tests/sexpr/classes/KicadSch.test.ts +97 -0
- package/tests/sexpr/classes/Paper.test.ts +30 -0
- package/tests/sexpr/classes/Property.test.ts +48 -0
- package/tests/sexpr/classes/Setup.test.ts +189 -0
- package/tests/sexpr/classes/Sheet.test.ts +107 -0
- package/tests/sexpr/classes/Stroke.test.ts +15 -0
- package/tests/sexpr/classes/Symbol.test.ts +96 -0
- package/tests/sexpr/classes/TextEffects.test.ts +56 -0
- package/tests/sexpr/classes/TitleBlock.test.ts +40 -0
- package/tsconfig.json +35 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
2
|
+
import { SxClass } from "./SxClass"
|
|
3
|
+
|
|
4
|
+
export abstract class SxPrimitiveBoolean extends SxClass {
|
|
5
|
+
value: boolean
|
|
6
|
+
|
|
7
|
+
constructor(v: boolean) {
|
|
8
|
+
super()
|
|
9
|
+
this.value = v
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
set(value: boolean) {
|
|
13
|
+
this.value = value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static override fromSexprPrimitives(
|
|
17
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
18
|
+
): SxPrimitiveBoolean {
|
|
19
|
+
const [rawVal] = primitiveSexprs
|
|
20
|
+
let booleanVal: boolean
|
|
21
|
+
if (typeof rawVal === "boolean") {
|
|
22
|
+
booleanVal = rawVal
|
|
23
|
+
} else if (typeof rawVal === "string") {
|
|
24
|
+
booleanVal = rawVal === "true" || rawVal === "yes"
|
|
25
|
+
} else {
|
|
26
|
+
booleanVal = false
|
|
27
|
+
}
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
return new this(booleanVal)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override getString() {
|
|
33
|
+
return `(${this.token} ${this.value ? "yes" : "no"})`
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
2
|
+
import { SxClass } from "./SxClass"
|
|
3
|
+
|
|
4
|
+
export abstract class SxPrimitiveNumber extends SxClass {
|
|
5
|
+
value: number
|
|
6
|
+
|
|
7
|
+
constructor(v: number) {
|
|
8
|
+
super()
|
|
9
|
+
this.value = v
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
set(value: number) {
|
|
13
|
+
this.value = value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static override fromSexprPrimitives(
|
|
17
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
18
|
+
): SxPrimitiveNumber {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
return new this(primitiveSexprs[0] as number)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override getString() {
|
|
24
|
+
return `(${this.token} ${this.value})`
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
2
|
+
import { SxClass } from "./SxClass"
|
|
3
|
+
|
|
4
|
+
export abstract class SxPrimitiveString extends SxClass {
|
|
5
|
+
value: string
|
|
6
|
+
|
|
7
|
+
constructor(v: string) {
|
|
8
|
+
super()
|
|
9
|
+
this.value = v
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
set(value: string) {
|
|
13
|
+
this.value = value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static override fromSexprPrimitives(
|
|
17
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
18
|
+
): SxPrimitiveString {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
return new this(primitiveSexprs[0] as string)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override getString() {
|
|
24
|
+
return `(${this.token} ${this.value})`
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
|
|
4
|
+
export class At extends SxClass {
|
|
5
|
+
static override token = "at"
|
|
6
|
+
token = "at"
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
args: [x: number, y: number, angle?: number],
|
|
10
|
+
opts: { isTextSymbol?: boolean } = {},
|
|
11
|
+
) {
|
|
12
|
+
super()
|
|
13
|
+
this.x = args[0]
|
|
14
|
+
this.y = args[1]
|
|
15
|
+
this.angle = args[2]
|
|
16
|
+
if (this.angle && opts.isTextSymbol) {
|
|
17
|
+
this.angle *= 10
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
x: number
|
|
22
|
+
y: number
|
|
23
|
+
angle?: number
|
|
24
|
+
|
|
25
|
+
static override fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): At {
|
|
26
|
+
const [x, y, angle] = primitiveSexprs
|
|
27
|
+
return new At([x as number, y as number, angle as number])
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override getString(): string {
|
|
31
|
+
const parts: Array<string | number> = [this.x, this.y]
|
|
32
|
+
if (this.angle !== undefined) {
|
|
33
|
+
parts.push(this.angle)
|
|
34
|
+
}
|
|
35
|
+
return `(at ${parts.join(" ")})`
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
SxClass.register(At)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
import { Pts } from "./Pts"
|
|
4
|
+
import { Stroke } from "./Stroke"
|
|
5
|
+
import { Uuid } from "./Uuid"
|
|
6
|
+
|
|
7
|
+
const SUPPORTED_TOKENS = new Set(["pts", "stroke", "uuid"])
|
|
8
|
+
|
|
9
|
+
export class Bus extends SxClass {
|
|
10
|
+
static override token = "bus"
|
|
11
|
+
static override parentToken = "kicad_sch"
|
|
12
|
+
override token = "bus"
|
|
13
|
+
|
|
14
|
+
private _sxPts?: Pts
|
|
15
|
+
private _sxStroke?: Stroke
|
|
16
|
+
private _sxUuid?: Uuid
|
|
17
|
+
|
|
18
|
+
static override fromSexprPrimitives(
|
|
19
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
20
|
+
): Bus {
|
|
21
|
+
const bus = new Bus()
|
|
22
|
+
|
|
23
|
+
const { propertyMap, arrayPropertyMap } =
|
|
24
|
+
SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
|
|
25
|
+
|
|
26
|
+
if (Object.keys(arrayPropertyMap).length > 0) {
|
|
27
|
+
const tokens = Object.keys(arrayPropertyMap).join(", ")
|
|
28
|
+
throw new Error(`bus does not support repeated child tokens: ${tokens}`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const unsupportedTokens = Object.keys(propertyMap).filter(
|
|
32
|
+
(token) => !SUPPORTED_TOKENS.has(token),
|
|
33
|
+
)
|
|
34
|
+
if (unsupportedTokens.length > 0) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Unsupported child tokens inside bus expression: ${unsupportedTokens.join(", ")}`,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
bus._sxPts = propertyMap.pts as Pts | undefined
|
|
41
|
+
bus._sxStroke = propertyMap.stroke as Stroke | undefined
|
|
42
|
+
bus._sxUuid = propertyMap.uuid as Uuid | undefined
|
|
43
|
+
|
|
44
|
+
return bus
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get points(): Pts | undefined {
|
|
48
|
+
return this._sxPts
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set points(value: Pts | undefined) {
|
|
52
|
+
this._sxPts = value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get stroke(): Stroke | undefined {
|
|
56
|
+
return this._sxStroke
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
set stroke(value: Stroke | undefined) {
|
|
60
|
+
this._sxStroke = value
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get uuid(): Uuid | undefined {
|
|
64
|
+
return this._sxUuid
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
set uuid(value: Uuid | string | undefined) {
|
|
68
|
+
if (value === undefined) {
|
|
69
|
+
this._sxUuid = undefined
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override getChildren(): SxClass[] {
|
|
76
|
+
const children: SxClass[] = []
|
|
77
|
+
if (this._sxPts) children.push(this._sxPts)
|
|
78
|
+
if (this._sxStroke) children.push(this._sxStroke)
|
|
79
|
+
if (this._sxUuid) children.push(this._sxUuid)
|
|
80
|
+
return children
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
SxClass.register(Bus)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
import { At } from "./At"
|
|
4
|
+
import { Stroke } from "./Stroke"
|
|
5
|
+
import { Uuid } from "./Uuid"
|
|
6
|
+
|
|
7
|
+
const SUPPORTED_TOKENS = new Set(["at", "size", "stroke", "uuid"])
|
|
8
|
+
|
|
9
|
+
export class BusEntry extends SxClass {
|
|
10
|
+
static override token = "bus_entry"
|
|
11
|
+
static override parentToken = "kicad_sch"
|
|
12
|
+
override token = "bus_entry"
|
|
13
|
+
|
|
14
|
+
private _sxAt?: At
|
|
15
|
+
private _sxSize?: BusEntrySize
|
|
16
|
+
private _sxStroke?: Stroke
|
|
17
|
+
private _sxUuid?: Uuid
|
|
18
|
+
|
|
19
|
+
static override fromSexprPrimitives(
|
|
20
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
21
|
+
): BusEntry {
|
|
22
|
+
const entry = new BusEntry()
|
|
23
|
+
|
|
24
|
+
const { propertyMap, arrayPropertyMap } =
|
|
25
|
+
SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
|
|
26
|
+
|
|
27
|
+
if (Object.keys(arrayPropertyMap).length > 0) {
|
|
28
|
+
const tokens = Object.keys(arrayPropertyMap).join(", ")
|
|
29
|
+
throw new Error(
|
|
30
|
+
`bus_entry does not support repeated child tokens: ${tokens}`,
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const unsupportedTokens = Object.keys(propertyMap).filter(
|
|
35
|
+
(token) => !SUPPORTED_TOKENS.has(token),
|
|
36
|
+
)
|
|
37
|
+
if (unsupportedTokens.length > 0) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Unsupported child tokens inside bus_entry expression: ${unsupportedTokens.join(", ")}`,
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
entry._sxAt = propertyMap.at as At | undefined
|
|
44
|
+
entry._sxSize = propertyMap.size as BusEntrySize | undefined
|
|
45
|
+
entry._sxStroke = propertyMap.stroke as Stroke | undefined
|
|
46
|
+
entry._sxUuid = propertyMap.uuid as Uuid | undefined
|
|
47
|
+
|
|
48
|
+
return entry
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get at(): At | undefined {
|
|
52
|
+
return this._sxAt
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set at(value: At | undefined) {
|
|
56
|
+
this._sxAt = value
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get size(): { x: number; y: number } | undefined {
|
|
60
|
+
return this._sxSize?.toObject()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
set size(value: BusEntrySize | { x: number; y: number } | undefined) {
|
|
64
|
+
if (value === undefined) {
|
|
65
|
+
this._sxSize = undefined
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
if (value instanceof BusEntrySize) {
|
|
69
|
+
this._sxSize = value
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
this._sxSize = new BusEntrySize(value.x, value.y)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get stroke(): Stroke | undefined {
|
|
76
|
+
return this._sxStroke
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
set stroke(value: Stroke | undefined) {
|
|
80
|
+
this._sxStroke = value
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get uuid(): Uuid | undefined {
|
|
84
|
+
return this._sxUuid
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
set uuid(value: Uuid | string | undefined) {
|
|
88
|
+
if (value === undefined) {
|
|
89
|
+
this._sxUuid = undefined
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override getChildren(): SxClass[] {
|
|
96
|
+
const children: SxClass[] = []
|
|
97
|
+
if (this._sxAt) children.push(this._sxAt)
|
|
98
|
+
if (this._sxSize) children.push(this._sxSize)
|
|
99
|
+
if (this._sxStroke) children.push(this._sxStroke)
|
|
100
|
+
if (this._sxUuid) children.push(this._sxUuid)
|
|
101
|
+
return children
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
SxClass.register(BusEntry)
|
|
105
|
+
|
|
106
|
+
export class BusEntrySize extends SxClass {
|
|
107
|
+
static override token = "size"
|
|
108
|
+
static override parentToken = "bus_entry"
|
|
109
|
+
override token = "size"
|
|
110
|
+
|
|
111
|
+
private _x: number
|
|
112
|
+
private _y: number
|
|
113
|
+
|
|
114
|
+
constructor(x: number, y: number) {
|
|
115
|
+
super()
|
|
116
|
+
this._x = x
|
|
117
|
+
this._y = y
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static override fromSexprPrimitives(
|
|
121
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
122
|
+
): BusEntrySize {
|
|
123
|
+
const [rawX, rawY] = primitiveSexprs
|
|
124
|
+
if (typeof rawX !== "number" || typeof rawY !== "number") {
|
|
125
|
+
throw new Error("bus_entry size expects two numeric arguments")
|
|
126
|
+
}
|
|
127
|
+
return new BusEntrySize(rawX, rawY)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
toObject(): { x: number; y: number } {
|
|
131
|
+
return { x: this._x, y: this._y }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
override getChildren(): SxClass[] {
|
|
135
|
+
return []
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
override getString(): string {
|
|
139
|
+
return `(size ${this._x} ${this._y})`
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
SxClass.register(BusEntrySize)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
|
|
4
|
+
export type RGBAColor = { r: number; g: number; b: number; a: number }
|
|
5
|
+
|
|
6
|
+
export class Color extends SxClass {
|
|
7
|
+
static override token = "color"
|
|
8
|
+
token = "color"
|
|
9
|
+
|
|
10
|
+
color: RGBAColor
|
|
11
|
+
|
|
12
|
+
constructor(args: [r: number, g: number, b: number, a: number]) {
|
|
13
|
+
super()
|
|
14
|
+
this.color = { r: args[0], g: args[1], b: args[2], a: args[3] }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static override fromSexprPrimitives(
|
|
18
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
19
|
+
): Color {
|
|
20
|
+
return new Color(
|
|
21
|
+
primitiveSexprs as [r: number, g: number, b: number, a: number],
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override getString() {
|
|
26
|
+
return `(color ${this.color.r} ${this.color.g} ${this.color.b} ${this.color.a})`
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
SxClass.register(Color)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
|
|
4
|
+
export class EmbeddedFonts extends SxClass {
|
|
5
|
+
static override token = "embedded_fonts"
|
|
6
|
+
override token = "embedded_fonts"
|
|
7
|
+
|
|
8
|
+
private _enabled = false
|
|
9
|
+
|
|
10
|
+
constructor(enabled = false) {
|
|
11
|
+
super()
|
|
12
|
+
this._enabled = enabled
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static override fromSexprPrimitives(
|
|
16
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
17
|
+
): EmbeddedFonts {
|
|
18
|
+
if (primitiveSexprs.length === 0) {
|
|
19
|
+
return new EmbeddedFonts(false)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (primitiveSexprs.length > 1) {
|
|
23
|
+
throw new Error("embedded_fonts accepts at most a single value")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const [raw] = primitiveSexprs
|
|
27
|
+
|
|
28
|
+
if (raw === undefined) {
|
|
29
|
+
return new EmbeddedFonts(false)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof raw === "boolean") {
|
|
33
|
+
return new EmbeddedFonts(raw)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof raw === "string") {
|
|
37
|
+
const normalized = raw.toLowerCase()
|
|
38
|
+
if (normalized === "yes") {
|
|
39
|
+
return new EmbeddedFonts(true)
|
|
40
|
+
}
|
|
41
|
+
if (normalized === "no") {
|
|
42
|
+
return new EmbeddedFonts(false)
|
|
43
|
+
}
|
|
44
|
+
throw new Error(
|
|
45
|
+
`embedded_fonts expects "yes" or "no", received "${raw}"`,
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
throw new Error(
|
|
50
|
+
`embedded_fonts encountered unsupported value ${JSON.stringify(raw)}`,
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get enabled(): boolean {
|
|
55
|
+
return this._enabled
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
set enabled(value: boolean) {
|
|
59
|
+
this._enabled = value
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override getChildren(): SxClass[] {
|
|
63
|
+
return []
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override getString(): string {
|
|
67
|
+
return `(embedded_fonts ${this._enabled ? "yes" : "no"})`
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
SxClass.register(EmbeddedFonts)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
|
|
3
|
+
|
|
4
|
+
export class ExcludeFromSim extends SxPrimitiveBoolean {
|
|
5
|
+
static override token = "exclude_from_sim"
|
|
6
|
+
token = "exclude_from_sim"
|
|
7
|
+
}
|
|
8
|
+
SxClass.register(ExcludeFromSim)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
|
|
3
|
+
|
|
4
|
+
export class FieldsAutoplaced extends SxPrimitiveBoolean {
|
|
5
|
+
static override token = "fields_autoplaced"
|
|
6
|
+
token = "fields_autoplaced"
|
|
7
|
+
}
|
|
8
|
+
SxClass.register(FieldsAutoplaced)
|