kicadts 0.0.2 → 0.0.4
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/index.d.ts +4466 -0
- package/dist/index.js +14253 -0
- package/package.json +5 -2
- package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
- package/.github/workflows/bun-formatcheck.yml +0 -26
- package/.github/workflows/bun-pver-release.yml +0 -70
- package/.github/workflows/bun-test.yml +0 -32
- package/.github/workflows/bun-typecheck.yml +0 -26
- package/.vscode/settings.json +0 -16
- package/AGENTS.md +0 -31
- package/TODO.md +0 -46
- package/biome.json +0 -93
- package/bunfig.toml +0 -5
- package/lib/index.ts +0 -1
- package/lib/sexpr/base-classes/SxClass.ts +0 -164
- package/lib/sexpr/base-classes/SxPrimitiveBoolean.ts +0 -35
- package/lib/sexpr/base-classes/SxPrimitiveNumber.ts +0 -26
- package/lib/sexpr/base-classes/SxPrimitiveString.ts +0 -26
- package/lib/sexpr/classes/At.ts +0 -53
- package/lib/sexpr/classes/Bus.ts +0 -103
- package/lib/sexpr/classes/BusEntry.ts +0 -169
- package/lib/sexpr/classes/Color.ts +0 -29
- package/lib/sexpr/classes/Dnp.ts +0 -8
- package/lib/sexpr/classes/EmbeddedFonts.ts +0 -68
- package/lib/sexpr/classes/ExcludeFromSim.ts +0 -8
- package/lib/sexpr/classes/FieldsAutoplaced.ts +0 -8
- package/lib/sexpr/classes/Footprint.ts +0 -849
- package/lib/sexpr/classes/FootprintAttr.ts +0 -104
- package/lib/sexpr/classes/FootprintAutoplaceCost180.ts +0 -9
- package/lib/sexpr/classes/FootprintAutoplaceCost90.ts +0 -9
- package/lib/sexpr/classes/FootprintClearance.ts +0 -9
- package/lib/sexpr/classes/FootprintDescr.ts +0 -44
- package/lib/sexpr/classes/FootprintLocked.ts +0 -32
- package/lib/sexpr/classes/FootprintModel.ts +0 -142
- package/lib/sexpr/classes/FootprintNetTiePadGroups.ts +0 -52
- package/lib/sexpr/classes/FootprintPad.ts +0 -857
- package/lib/sexpr/classes/FootprintPath.ts +0 -44
- package/lib/sexpr/classes/FootprintPlaced.ts +0 -32
- package/lib/sexpr/classes/FootprintPrivateLayers.ts +0 -56
- package/lib/sexpr/classes/FootprintSheetfile.ts +0 -44
- package/lib/sexpr/classes/FootprintSheetname.ts +0 -44
- package/lib/sexpr/classes/FootprintSolderMaskMargin.ts +0 -9
- package/lib/sexpr/classes/FootprintSolderPasteMargin.ts +0 -9
- package/lib/sexpr/classes/FootprintSolderPasteRatio.ts +0 -9
- package/lib/sexpr/classes/FootprintTags.ts +0 -44
- package/lib/sexpr/classes/FootprintTedit.ts +0 -21
- package/lib/sexpr/classes/FootprintThermalGap.ts +0 -9
- package/lib/sexpr/classes/FootprintThermalWidth.ts +0 -9
- package/lib/sexpr/classes/FootprintZoneConnect.ts +0 -9
- package/lib/sexpr/classes/FpArc.ts +0 -312
- package/lib/sexpr/classes/FpCircle.ts +0 -314
- package/lib/sexpr/classes/FpLine.ts +0 -316
- package/lib/sexpr/classes/FpPoly.ts +0 -286
- package/lib/sexpr/classes/FpPolyFill.ts +0 -48
- package/lib/sexpr/classes/FpPolyLocked.ts +0 -40
- package/lib/sexpr/classes/FpRect.ts +0 -314
- package/lib/sexpr/classes/FpText.ts +0 -375
- package/lib/sexpr/classes/FpTextBox.ts +0 -450
- package/lib/sexpr/classes/GrLine.ts +0 -264
- package/lib/sexpr/classes/GrLineAngle.ts +0 -32
- package/lib/sexpr/classes/GrLineEnd.ts +0 -61
- package/lib/sexpr/classes/GrLineLocked.ts +0 -40
- package/lib/sexpr/classes/GrLineStart.ts +0 -61
- package/lib/sexpr/classes/GrText.ts +0 -228
- package/lib/sexpr/classes/Image.ts +0 -283
- package/lib/sexpr/classes/InBom.ts +0 -8
- package/lib/sexpr/classes/Junction.ts +0 -166
- package/lib/sexpr/classes/KicadPcb.ts +0 -361
- package/lib/sexpr/classes/KicadSch.ts +0 -397
- package/lib/sexpr/classes/KicadSchGenerator.ts +0 -32
- package/lib/sexpr/classes/KicadSchGeneratorVersion.ts +0 -30
- package/lib/sexpr/classes/KicadSchVersion.ts +0 -22
- package/lib/sexpr/classes/Label.ts +0 -176
- package/lib/sexpr/classes/Layer.ts +0 -51
- package/lib/sexpr/classes/Layers.ts +0 -47
- package/lib/sexpr/classes/LibSymbols.ts +0 -61
- package/lib/sexpr/classes/NoConnect.ts +0 -90
- package/lib/sexpr/classes/OnBoard.ts +0 -8
- package/lib/sexpr/classes/PadChamfer.ts +0 -50
- package/lib/sexpr/classes/PadChamferRatio.ts +0 -9
- package/lib/sexpr/classes/PadClearance.ts +0 -9
- package/lib/sexpr/classes/PadDieLength.ts +0 -9
- package/lib/sexpr/classes/PadDrill.ts +0 -145
- package/lib/sexpr/classes/PadDrillOffset.ts +0 -54
- package/lib/sexpr/classes/PadLayers.ts +0 -71
- package/lib/sexpr/classes/PadNet.ts +0 -56
- package/lib/sexpr/classes/PadOptions.ts +0 -181
- package/lib/sexpr/classes/PadPinFunction.ts +0 -9
- package/lib/sexpr/classes/PadPinType.ts +0 -9
- package/lib/sexpr/classes/PadPrimitiveGrArc.ts +0 -272
- package/lib/sexpr/classes/PadPrimitiveGrCircle.ts +0 -298
- package/lib/sexpr/classes/PadPrimitiveGrLine.ts +0 -126
- package/lib/sexpr/classes/PadPrimitives.ts +0 -291
- package/lib/sexpr/classes/PadRectDelta.ts +0 -57
- package/lib/sexpr/classes/PadRoundrectRratio.ts +0 -9
- package/lib/sexpr/classes/PadSize.ts +0 -69
- package/lib/sexpr/classes/PadSolderMaskMargin.ts +0 -9
- package/lib/sexpr/classes/PadSolderPasteMargin.ts +0 -9
- package/lib/sexpr/classes/PadSolderPasteMarginRatio.ts +0 -9
- package/lib/sexpr/classes/PadTeardrops.ts +0 -210
- package/lib/sexpr/classes/PadThermalBridgeAngle.ts +0 -9
- package/lib/sexpr/classes/PadThermalGap.ts +0 -9
- package/lib/sexpr/classes/PadThermalWidth.ts +0 -9
- package/lib/sexpr/classes/PadZoneConnect.ts +0 -9
- package/lib/sexpr/classes/Paper.ts +0 -119
- package/lib/sexpr/classes/PcbGeneral.ts +0 -82
- package/lib/sexpr/classes/PcbGeneralLegacyTeardrops.ts +0 -44
- package/lib/sexpr/classes/PcbGeneralThickness.ts +0 -9
- package/lib/sexpr/classes/PcbGenerator.ts +0 -16
- package/lib/sexpr/classes/PcbGeneratorVersion.ts +0 -16
- package/lib/sexpr/classes/PcbLayerDefinition.ts +0 -106
- package/lib/sexpr/classes/PcbLayers.ts +0 -34
- package/lib/sexpr/classes/PcbNet.ts +0 -56
- package/lib/sexpr/classes/PcbVersion.ts +0 -9
- package/lib/sexpr/classes/Property.ts +0 -301
- package/lib/sexpr/classes/PropertyHide.ts +0 -9
- package/lib/sexpr/classes/PropertyUnlocked.ts +0 -9
- package/lib/sexpr/classes/Pts.ts +0 -67
- package/lib/sexpr/classes/RenderCache.ts +0 -221
- package/lib/sexpr/classes/SchematicText.ts +0 -171
- package/lib/sexpr/classes/Segment.ts +0 -243
- package/lib/sexpr/classes/SegmentEnd.ts +0 -59
- package/lib/sexpr/classes/SegmentLocked.ts +0 -33
- package/lib/sexpr/classes/SegmentNet.ts +0 -64
- package/lib/sexpr/classes/SegmentStart.ts +0 -59
- package/lib/sexpr/classes/Setup/PcbPlotParams.ts +0 -689
- package/lib/sexpr/classes/Setup/PcbPlotParamsBase.ts +0 -9
- package/lib/sexpr/classes/Setup/PcbPlotParamsNumericProperties.ts +0 -105
- package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesA.ts +0 -104
- package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesB.ts +0 -105
- package/lib/sexpr/classes/Setup/Setup.ts +0 -574
- package/lib/sexpr/classes/Setup/SetupPropertyTypes.ts +0 -119
- package/lib/sexpr/classes/Setup/Stackup.ts +0 -135
- package/lib/sexpr/classes/Setup/StackupLayer.ts +0 -233
- package/lib/sexpr/classes/Setup/StackupLayerProperties.ts +0 -80
- package/lib/sexpr/classes/Setup/StackupProperties.ts +0 -40
- package/lib/sexpr/classes/Setup/base.ts +0 -165
- package/lib/sexpr/classes/Setup/index.ts +0 -14
- package/lib/sexpr/classes/Setup/setupMultiValueProperties.ts +0 -53
- package/lib/sexpr/classes/Setup/setupNumericProperties.ts +0 -151
- package/lib/sexpr/classes/Setup/setupPropertyHandlers.ts +0 -90
- package/lib/sexpr/classes/Setup/setupStringProperties.ts +0 -75
- package/lib/sexpr/classes/Sheet.ts +0 -287
- package/lib/sexpr/classes/SheetFill.ts +0 -44
- package/lib/sexpr/classes/SheetInstances.ts +0 -168
- package/lib/sexpr/classes/SheetInstancesRoot.ts +0 -165
- package/lib/sexpr/classes/SheetPin.ts +0 -125
- package/lib/sexpr/classes/SheetProperty.ts +0 -115
- package/lib/sexpr/classes/SheetSize.ts +0 -44
- package/lib/sexpr/classes/Stroke.ts +0 -58
- package/lib/sexpr/classes/StrokeType.ts +0 -34
- package/lib/sexpr/classes/Symbol.ts +0 -1666
- package/lib/sexpr/classes/TextEffects.ts +0 -461
- package/lib/sexpr/classes/TitleBlock.ts +0 -369
- package/lib/sexpr/classes/Unit.ts +0 -28
- package/lib/sexpr/classes/Uuid.ts +0 -8
- package/lib/sexpr/classes/Via.ts +0 -363
- package/lib/sexpr/classes/ViaNet.ts +0 -60
- package/lib/sexpr/classes/Width.ts +0 -8
- package/lib/sexpr/classes/Wire.ts +0 -111
- package/lib/sexpr/classes/Xy.ts +0 -33
- package/lib/sexpr/classes/Zone.ts +0 -39
- package/lib/sexpr/index.ts +0 -130
- package/lib/sexpr/parseKicadSexpr.ts +0 -5
- package/lib/sexpr/parseToPrimitiveSExpr.ts +0 -245
- package/lib/sexpr/utils/indentLines.ts +0 -3
- package/lib/sexpr/utils/parseYesNo.ts +0 -12
- package/lib/sexpr/utils/quoteSExprString.ts +0 -8
- package/lib/sexpr/utils/strokeFromArgs.ts +0 -18
- package/lib/sexpr/utils/toNumberValue.ts +0 -13
- package/lib/sexpr/utils/toStringValue.ts +0 -11
- package/scripts/download-references.ts +0 -68
- package/tests/fixtures/expectEqualPrimitiveSExpr.ts +0 -199
- package/tests/fixtures/png-matcher.ts +0 -109
- package/tests/fixtures/preload.ts +0 -1
- package/tests/sexpr/KicadPcbDemos.test.ts +0 -48
- package/tests/sexpr/KicadSchDemos.test.ts +0 -49
- package/tests/sexpr/classes/Footprint.test.ts +0 -277
- package/tests/sexpr/classes/FootprintPad.test.ts +0 -78
- package/tests/sexpr/classes/FpArc.test.ts +0 -45
- package/tests/sexpr/classes/FpCircle.test.ts +0 -39
- package/tests/sexpr/classes/FpPoly.test.ts +0 -43
- package/tests/sexpr/classes/FpRect.test.ts +0 -40
- package/tests/sexpr/classes/FpTextBox.test.ts +0 -84
- package/tests/sexpr/classes/Image.test.ts +0 -58
- package/tests/sexpr/classes/KicadSch.test.ts +0 -95
- package/tests/sexpr/classes/Paper.test.ts +0 -30
- package/tests/sexpr/classes/Property.test.ts +0 -48
- package/tests/sexpr/classes/Setup.test.ts +0 -188
- package/tests/sexpr/classes/Sheet.test.ts +0 -107
- package/tests/sexpr/classes/Stroke.test.ts +0 -15
- package/tests/sexpr/classes/Symbol.test.ts +0 -96
- package/tests/sexpr/classes/TextEffects.test.ts +0 -56
- package/tests/sexpr/classes/TitleBlock.test.ts +0 -40
- package/tsconfig.json +0 -35
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
-
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
-
import { toStringValue } from "../utils/toStringValue"
|
|
4
|
-
|
|
5
|
-
export type PadOptionsClearanceType = "outline" | "convexhull"
|
|
6
|
-
export type PadOptionsAnchorShape = "rect" | "circle"
|
|
7
|
-
|
|
8
|
-
const CLEARANCE_TYPES: PadOptionsClearanceType[] = ["outline", "convexhull"]
|
|
9
|
-
|
|
10
|
-
const ANCHOR_SHAPES: PadOptionsAnchorShape[] = ["rect", "circle"]
|
|
11
|
-
|
|
12
|
-
export class PadOptions extends SxClass {
|
|
13
|
-
static override token = "options"
|
|
14
|
-
static override parentToken = "pad"
|
|
15
|
-
override token = "options"
|
|
16
|
-
|
|
17
|
-
private _sxClearance?: PadOptionsClearance
|
|
18
|
-
private _sxAnchor?: PadOptionsAnchor
|
|
19
|
-
|
|
20
|
-
static override fromSexprPrimitives(
|
|
21
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
22
|
-
): PadOptions {
|
|
23
|
-
const options = new PadOptions()
|
|
24
|
-
|
|
25
|
-
for (const primitive of primitiveSexprs) {
|
|
26
|
-
if (!Array.isArray(primitive) || primitive.length === 0) {
|
|
27
|
-
throw new Error(
|
|
28
|
-
`pad options encountered invalid child expression: ${JSON.stringify(primitive)}`,
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const parsed = SxClass.parsePrimitiveSexpr(primitive, {
|
|
33
|
-
parentToken: this.token,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
if (!(parsed instanceof SxClass)) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
`pad options child did not resolve to an SxClass: ${JSON.stringify(primitive)}`,
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (parsed instanceof PadOptionsClearance) {
|
|
43
|
-
if (options._sxClearance) {
|
|
44
|
-
throw new Error("pad options encountered duplicate clearance tokens")
|
|
45
|
-
}
|
|
46
|
-
options._sxClearance = parsed
|
|
47
|
-
continue
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (parsed instanceof PadOptionsAnchor) {
|
|
51
|
-
if (options._sxAnchor) {
|
|
52
|
-
throw new Error("pad options encountered duplicate anchor tokens")
|
|
53
|
-
}
|
|
54
|
-
options._sxAnchor = parsed
|
|
55
|
-
continue
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
throw new Error(
|
|
59
|
-
`pad options encountered unsupported token "${parsed.token}"`,
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return options
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get clearance(): PadOptionsClearanceType | undefined {
|
|
67
|
-
return this._sxClearance?.type
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
set clearance(value: PadOptionsClearanceType | undefined) {
|
|
71
|
-
this._sxClearance = value ? new PadOptionsClearance(value) : undefined
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get anchor(): PadOptionsAnchorShape | undefined {
|
|
75
|
-
return this._sxAnchor?.shape
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
set anchor(value: PadOptionsAnchorShape | undefined) {
|
|
79
|
-
this._sxAnchor = value ? new PadOptionsAnchor(value) : undefined
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
override getChildren(): SxClass[] {
|
|
83
|
-
const children: SxClass[] = []
|
|
84
|
-
if (this._sxClearance) children.push(this._sxClearance)
|
|
85
|
-
if (this._sxAnchor) children.push(this._sxAnchor)
|
|
86
|
-
return children
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
SxClass.register(PadOptions)
|
|
90
|
-
|
|
91
|
-
class PadOptionsClearance extends SxClass {
|
|
92
|
-
static override token = "clearance"
|
|
93
|
-
static override parentToken = "options"
|
|
94
|
-
override token = "clearance"
|
|
95
|
-
|
|
96
|
-
private _type: PadOptionsClearanceType
|
|
97
|
-
|
|
98
|
-
constructor(type: PadOptionsClearanceType) {
|
|
99
|
-
super()
|
|
100
|
-
this._type = type
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static override fromSexprPrimitives(
|
|
104
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
105
|
-
): PadOptionsClearance {
|
|
106
|
-
const [raw] = primitiveSexprs
|
|
107
|
-
const stringValue = toStringValue(raw)
|
|
108
|
-
if (stringValue === undefined) {
|
|
109
|
-
throw new Error("pad options clearance requires a string value")
|
|
110
|
-
}
|
|
111
|
-
if (!CLEARANCE_TYPES.includes(stringValue as PadOptionsClearanceType)) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
`pad options clearance must be one of ${CLEARANCE_TYPES.join(", ")}`,
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
return new PadOptionsClearance(stringValue as PadOptionsClearanceType)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
get type(): PadOptionsClearanceType {
|
|
120
|
-
return this._type
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
set type(value: PadOptionsClearanceType) {
|
|
124
|
-
this._type = value
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
override getChildren(): SxClass[] {
|
|
128
|
-
return []
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
override getString(): string {
|
|
132
|
-
return `(clearance ${this._type})`
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
SxClass.register(PadOptionsClearance)
|
|
136
|
-
|
|
137
|
-
class PadOptionsAnchor extends SxClass {
|
|
138
|
-
static override token = "anchor"
|
|
139
|
-
static override parentToken = "options"
|
|
140
|
-
override token = "anchor"
|
|
141
|
-
|
|
142
|
-
private _shape: PadOptionsAnchorShape
|
|
143
|
-
|
|
144
|
-
constructor(shape: PadOptionsAnchorShape) {
|
|
145
|
-
super()
|
|
146
|
-
this._shape = shape
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
static override fromSexprPrimitives(
|
|
150
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
151
|
-
): PadOptionsAnchor {
|
|
152
|
-
const [raw] = primitiveSexprs
|
|
153
|
-
const stringValue = toStringValue(raw)
|
|
154
|
-
if (stringValue === undefined) {
|
|
155
|
-
throw new Error("pad options anchor requires a string value")
|
|
156
|
-
}
|
|
157
|
-
if (!ANCHOR_SHAPES.includes(stringValue as PadOptionsAnchorShape)) {
|
|
158
|
-
throw new Error(
|
|
159
|
-
`pad options anchor must be one of ${ANCHOR_SHAPES.join(", ")}`,
|
|
160
|
-
)
|
|
161
|
-
}
|
|
162
|
-
return new PadOptionsAnchor(stringValue as PadOptionsAnchorShape)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
get shape(): PadOptionsAnchorShape {
|
|
166
|
-
return this._shape
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
set shape(value: PadOptionsAnchorShape) {
|
|
170
|
-
this._shape = value
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
override getChildren(): SxClass[] {
|
|
174
|
-
return []
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
override getString(): string {
|
|
178
|
-
return `(anchor ${this._shape})`
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
SxClass.register(PadOptionsAnchor)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SxPrimitiveString } from "../base-classes/SxPrimitiveString"
|
|
2
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
3
|
-
|
|
4
|
-
export class PadPinFunction extends SxPrimitiveString {
|
|
5
|
-
static override token = "pinfunction"
|
|
6
|
-
static override parentToken = "pad"
|
|
7
|
-
token = "pinfunction"
|
|
8
|
-
}
|
|
9
|
-
SxClass.register(PadPinFunction)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SxPrimitiveString } from "../base-classes/SxPrimitiveString"
|
|
2
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
3
|
-
|
|
4
|
-
export class PadPinType extends SxPrimitiveString {
|
|
5
|
-
static override token = "pintype"
|
|
6
|
-
static override parentToken = "pad"
|
|
7
|
-
token = "pintype"
|
|
8
|
-
}
|
|
9
|
-
SxClass.register(PadPinType)
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
-
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
-
import { Width } from "./Width"
|
|
4
|
-
import { toNumberValue } from "../utils/toNumberValue"
|
|
5
|
-
|
|
6
|
-
const SUPPORTED_TOKENS = new Set(["start", "mid", "end", "width"])
|
|
7
|
-
|
|
8
|
-
export interface PadPrimitiveGrArcConstructorParams {
|
|
9
|
-
start?: PadPrimitiveGrArcStart | { x: number; y: number }
|
|
10
|
-
mid?: PadPrimitiveGrArcMid | { x: number; y: number }
|
|
11
|
-
end?: PadPrimitiveGrArcEnd | { x: number; y: number }
|
|
12
|
-
width?: Width | number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class PadPrimitiveGrArc extends SxClass {
|
|
16
|
-
static override token = "gr_arc"
|
|
17
|
-
static override parentToken = "primitives"
|
|
18
|
-
override token = "gr_arc"
|
|
19
|
-
|
|
20
|
-
private _sxStart?: PadPrimitiveGrArcStart
|
|
21
|
-
private _sxMid?: PadPrimitiveGrArcMid
|
|
22
|
-
private _sxEnd?: PadPrimitiveGrArcEnd
|
|
23
|
-
private _sxWidth?: Width
|
|
24
|
-
|
|
25
|
-
constructor(params: PadPrimitiveGrArcConstructorParams = {}) {
|
|
26
|
-
super()
|
|
27
|
-
if (params.start !== undefined) this.start = params.start
|
|
28
|
-
if (params.mid !== undefined) this.mid = params.mid
|
|
29
|
-
if (params.end !== undefined) this.end = params.end
|
|
30
|
-
if (params.width !== undefined) this.width = params.width
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static override fromSexprPrimitives(
|
|
34
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
35
|
-
): PadPrimitiveGrArc {
|
|
36
|
-
const arc = new PadPrimitiveGrArc()
|
|
37
|
-
|
|
38
|
-
const { propertyMap, arrayPropertyMap } =
|
|
39
|
-
SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
|
|
40
|
-
|
|
41
|
-
for (const token of Object.keys(propertyMap)) {
|
|
42
|
-
if (!SUPPORTED_TOKENS.has(token)) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`pad primitive gr_arc encountered unsupported child token "${token}"`,
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
for (const [token, entries] of Object.entries(arrayPropertyMap)) {
|
|
50
|
-
if (!SUPPORTED_TOKENS.has(token)) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`pad primitive gr_arc encountered unsupported child token "${token}"`,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
if (entries.length > 1) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`pad primitive gr_arc does not support repeated "${token}" tokens`,
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
arc._sxStart = propertyMap.start as PadPrimitiveGrArcStart | undefined
|
|
63
|
-
arc._sxMid = propertyMap.mid as PadPrimitiveGrArcMid | undefined
|
|
64
|
-
arc._sxEnd = propertyMap.end as PadPrimitiveGrArcEnd | undefined
|
|
65
|
-
arc._sxWidth = propertyMap.width as Width | undefined
|
|
66
|
-
|
|
67
|
-
if (!arc._sxStart) {
|
|
68
|
-
throw new Error("pad primitive gr_arc requires a start child token")
|
|
69
|
-
}
|
|
70
|
-
if (!arc._sxMid) {
|
|
71
|
-
throw new Error("pad primitive gr_arc requires a mid child token")
|
|
72
|
-
}
|
|
73
|
-
if (!arc._sxEnd) {
|
|
74
|
-
throw new Error("pad primitive gr_arc requires an end child token")
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return arc
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
get start(): PadPrimitiveGrArcStart | undefined {
|
|
81
|
-
return this._sxStart
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
set start(value:
|
|
85
|
-
| PadPrimitiveGrArcStart
|
|
86
|
-
| { x: number; y: number }
|
|
87
|
-
| undefined,) {
|
|
88
|
-
this._sxStart = normalizeArcPoint(value, PadPrimitiveGrArcStart)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
get mid(): PadPrimitiveGrArcMid | undefined {
|
|
92
|
-
return this._sxMid
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
set mid(value: PadPrimitiveGrArcMid | { x: number; y: number } | undefined) {
|
|
96
|
-
this._sxMid = normalizeArcPoint(value, PadPrimitiveGrArcMid)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get end(): PadPrimitiveGrArcEnd | undefined {
|
|
100
|
-
return this._sxEnd
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
set end(value: PadPrimitiveGrArcEnd | { x: number; y: number } | undefined) {
|
|
104
|
-
this._sxEnd = normalizeArcPoint(value, PadPrimitiveGrArcEnd)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
get width(): number | undefined {
|
|
108
|
-
return this._sxWidth?.value
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
set width(value: Width | number | undefined) {
|
|
112
|
-
if (value === undefined) {
|
|
113
|
-
this._sxWidth = undefined
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
this._sxWidth = value instanceof Width ? value : new Width(value)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
get widthClass(): Width | undefined {
|
|
120
|
-
return this._sxWidth
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
override getChildren(): SxClass[] {
|
|
124
|
-
const children: SxClass[] = []
|
|
125
|
-
if (this._sxStart) children.push(this._sxStart)
|
|
126
|
-
if (this._sxMid) children.push(this._sxMid)
|
|
127
|
-
if (this._sxEnd) children.push(this._sxEnd)
|
|
128
|
-
if (this._sxWidth) children.push(this._sxWidth)
|
|
129
|
-
return children
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
override getString(): string {
|
|
133
|
-
const lines = ["(gr_arc"]
|
|
134
|
-
if (this._sxStart) lines.push(this._sxStart.getStringIndented())
|
|
135
|
-
if (this._sxMid) lines.push(this._sxMid.getStringIndented())
|
|
136
|
-
if (this._sxEnd) lines.push(this._sxEnd.getStringIndented())
|
|
137
|
-
if (this._sxWidth) lines.push(this._sxWidth.getStringIndented())
|
|
138
|
-
lines.push(")")
|
|
139
|
-
return lines.join("\n")
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
SxClass.register(PadPrimitiveGrArc)
|
|
143
|
-
|
|
144
|
-
type ArcPointConstructor<T extends PadPrimitiveGrArcPoint> = new (
|
|
145
|
-
x: number,
|
|
146
|
-
y: number,
|
|
147
|
-
) => T
|
|
148
|
-
|
|
149
|
-
const normalizeArcPoint = <T extends PadPrimitiveGrArcPoint>(
|
|
150
|
-
value: T | { x: number; y: number } | undefined,
|
|
151
|
-
Constructor: ArcPointConstructor<T>,
|
|
152
|
-
): T | undefined => {
|
|
153
|
-
if (value === undefined) {
|
|
154
|
-
return undefined
|
|
155
|
-
}
|
|
156
|
-
if (value instanceof Constructor) {
|
|
157
|
-
return value
|
|
158
|
-
}
|
|
159
|
-
return new Constructor(value.x, value.y)
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
abstract class PadPrimitiveGrArcPoint extends SxClass {
|
|
163
|
-
protected _x: number
|
|
164
|
-
protected _y: number
|
|
165
|
-
|
|
166
|
-
protected constructor(x: number, y: number) {
|
|
167
|
-
super()
|
|
168
|
-
this._x = x
|
|
169
|
-
this._y = y
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
get x(): number {
|
|
173
|
-
return this._x
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
set x(value: number) {
|
|
177
|
-
this._x = value
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
get y(): number {
|
|
181
|
-
return this._y
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
set y(value: number) {
|
|
185
|
-
this._y = value
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
override getChildren(): SxClass[] {
|
|
189
|
-
return []
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
override getString(): string {
|
|
193
|
-
return `(${this.token} ${this._x} ${this._y})`
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
class PadPrimitiveGrArcStart extends PadPrimitiveGrArcPoint {
|
|
198
|
-
static override token = "start"
|
|
199
|
-
static override parentToken = "gr_arc"
|
|
200
|
-
override token = "start"
|
|
201
|
-
|
|
202
|
-
constructor(x: number, y: number) {
|
|
203
|
-
super(x, y)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
static override fromSexprPrimitives(
|
|
207
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
208
|
-
): PadPrimitiveGrArcStart {
|
|
209
|
-
const [rawX, rawY] = primitiveSexprs
|
|
210
|
-
const x = toNumberValue(rawX)
|
|
211
|
-
const y = toNumberValue(rawY)
|
|
212
|
-
|
|
213
|
-
if (x === undefined || y === undefined) {
|
|
214
|
-
throw new Error(
|
|
215
|
-
"pad primitive gr_arc start expects two numeric arguments",
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return new PadPrimitiveGrArcStart(x, y)
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
SxClass.register(PadPrimitiveGrArcStart)
|
|
223
|
-
|
|
224
|
-
class PadPrimitiveGrArcMid extends PadPrimitiveGrArcPoint {
|
|
225
|
-
static override token = "mid"
|
|
226
|
-
static override parentToken = "gr_arc"
|
|
227
|
-
override token = "mid"
|
|
228
|
-
|
|
229
|
-
constructor(x: number, y: number) {
|
|
230
|
-
super(x, y)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
static override fromSexprPrimitives(
|
|
234
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
235
|
-
): PadPrimitiveGrArcMid {
|
|
236
|
-
const [rawX, rawY] = primitiveSexprs
|
|
237
|
-
const x = toNumberValue(rawX)
|
|
238
|
-
const y = toNumberValue(rawY)
|
|
239
|
-
|
|
240
|
-
if (x === undefined || y === undefined) {
|
|
241
|
-
throw new Error("pad primitive gr_arc mid expects two numeric arguments")
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return new PadPrimitiveGrArcMid(x, y)
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
SxClass.register(PadPrimitiveGrArcMid)
|
|
248
|
-
|
|
249
|
-
class PadPrimitiveGrArcEnd extends PadPrimitiveGrArcPoint {
|
|
250
|
-
static override token = "end"
|
|
251
|
-
static override parentToken = "gr_arc"
|
|
252
|
-
override token = "end"
|
|
253
|
-
|
|
254
|
-
constructor(x: number, y: number) {
|
|
255
|
-
super(x, y)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
static override fromSexprPrimitives(
|
|
259
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
260
|
-
): PadPrimitiveGrArcEnd {
|
|
261
|
-
const [rawX, rawY] = primitiveSexprs
|
|
262
|
-
const x = toNumberValue(rawX)
|
|
263
|
-
const y = toNumberValue(rawY)
|
|
264
|
-
|
|
265
|
-
if (x === undefined || y === undefined) {
|
|
266
|
-
throw new Error("pad primitive gr_arc end expects two numeric arguments")
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return new PadPrimitiveGrArcEnd(x, y)
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
SxClass.register(PadPrimitiveGrArcEnd)
|