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,222 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
import { Layer } from "./Layer"
|
|
4
|
+
import { SegmentEnd } from "./SegmentEnd"
|
|
5
|
+
import { SegmentLocked } from "./SegmentLocked"
|
|
6
|
+
import { SegmentNet } from "./SegmentNet"
|
|
7
|
+
import { SegmentStart } from "./SegmentStart"
|
|
8
|
+
import { Uuid } from "./Uuid"
|
|
9
|
+
import { Width } from "./Width"
|
|
10
|
+
|
|
11
|
+
const SUPPORTED_SINGLE_TOKENS = new Set([
|
|
12
|
+
"start",
|
|
13
|
+
"end",
|
|
14
|
+
"width",
|
|
15
|
+
"layer",
|
|
16
|
+
"net",
|
|
17
|
+
"uuid",
|
|
18
|
+
"locked",
|
|
19
|
+
])
|
|
20
|
+
|
|
21
|
+
export class Segment extends SxClass {
|
|
22
|
+
static override token = "segment"
|
|
23
|
+
override token = "segment"
|
|
24
|
+
|
|
25
|
+
private _sxStart?: SegmentStart
|
|
26
|
+
private _sxEnd?: SegmentEnd
|
|
27
|
+
private _sxWidth?: Width
|
|
28
|
+
private _sxLayer?: Layer
|
|
29
|
+
private _sxNet?: SegmentNet
|
|
30
|
+
private _sxUuid?: Uuid
|
|
31
|
+
private _sxLocked?: SegmentLocked
|
|
32
|
+
|
|
33
|
+
static override fromSexprPrimitives(
|
|
34
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
35
|
+
): Segment {
|
|
36
|
+
const segment = new Segment()
|
|
37
|
+
|
|
38
|
+
const { propertyMap, arrayPropertyMap } =
|
|
39
|
+
SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
|
|
40
|
+
|
|
41
|
+
const unexpectedSingleTokens = Object.keys(propertyMap).filter(
|
|
42
|
+
(token) => !SUPPORTED_SINGLE_TOKENS.has(token),
|
|
43
|
+
)
|
|
44
|
+
if (unexpectedSingleTokens.length > 0) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Unsupported child tokens inside segment expression: ${unexpectedSingleTokens.join(", ")}`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const [token, entries] of Object.entries(arrayPropertyMap)) {
|
|
51
|
+
if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Unsupported child tokens inside segment expression: ${token}`,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
if (entries.length > 1) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Segment does not support repeated child tokens: ${token}`,
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
segment._sxStart =
|
|
64
|
+
(arrayPropertyMap.start?.[0] as SegmentStart | undefined) ??
|
|
65
|
+
(propertyMap.start as SegmentStart | undefined)
|
|
66
|
+
segment._sxEnd =
|
|
67
|
+
(arrayPropertyMap.end?.[0] as SegmentEnd | undefined) ??
|
|
68
|
+
(propertyMap.end as SegmentEnd | undefined)
|
|
69
|
+
segment._sxWidth =
|
|
70
|
+
(arrayPropertyMap.width?.[0] as Width | undefined) ??
|
|
71
|
+
(propertyMap.width as Width | undefined)
|
|
72
|
+
segment._sxLayer =
|
|
73
|
+
(arrayPropertyMap.layer?.[0] as Layer | undefined) ??
|
|
74
|
+
(propertyMap.layer as Layer | undefined)
|
|
75
|
+
segment._sxNet =
|
|
76
|
+
(arrayPropertyMap.net?.[0] as SegmentNet | undefined) ??
|
|
77
|
+
(propertyMap.net as SegmentNet | undefined)
|
|
78
|
+
const locked =
|
|
79
|
+
(arrayPropertyMap.locked?.[0] as SegmentLocked | undefined) ??
|
|
80
|
+
(propertyMap.locked as SegmentLocked | undefined)
|
|
81
|
+
segment._sxLocked = locked && locked.value ? locked : undefined
|
|
82
|
+
segment._sxUuid =
|
|
83
|
+
(arrayPropertyMap.uuid?.[0] as Uuid | undefined) ??
|
|
84
|
+
(propertyMap.uuid as Uuid | undefined)
|
|
85
|
+
|
|
86
|
+
return segment
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get start(): SegmentStart | undefined {
|
|
90
|
+
return this._sxStart
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
set start(value: SegmentStart | { x: number; y: number } | undefined) {
|
|
94
|
+
this._sxStart = this.normalizeStart(value)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get end(): SegmentEnd | undefined {
|
|
98
|
+
return this._sxEnd
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
set end(value: SegmentEnd | { x: number; y: number } | undefined) {
|
|
102
|
+
this._sxEnd = this.normalizeEnd(value)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get startPoint(): { x: number; y: number } | undefined {
|
|
106
|
+
return this._sxStart?.toObject()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get endPoint(): { x: number; y: number } | undefined {
|
|
110
|
+
return this._sxEnd?.toObject()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get width(): number | undefined {
|
|
114
|
+
return this._sxWidth?.value
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
set width(value: Width | number | undefined) {
|
|
118
|
+
if (value === undefined) {
|
|
119
|
+
this._sxWidth = undefined
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
this._sxWidth = value instanceof Width ? value : new Width(value)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get widthClass(): Width | undefined {
|
|
126
|
+
return this._sxWidth
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
set widthClass(value: Width | undefined) {
|
|
130
|
+
this._sxWidth = value
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get layer(): Layer | undefined {
|
|
134
|
+
return this._sxLayer
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
set layer(value: Layer | string | Array<string | number> | undefined) {
|
|
138
|
+
if (value === undefined) {
|
|
139
|
+
this._sxLayer = undefined
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
if (value instanceof Layer) {
|
|
143
|
+
this._sxLayer = value
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
const names = Array.isArray(value) ? value : [value]
|
|
147
|
+
this._sxLayer = new Layer(names)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get net(): SegmentNet | undefined {
|
|
151
|
+
return this._sxNet
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
set net(value: SegmentNet | { id: number; name?: string } | undefined) {
|
|
155
|
+
if (value === undefined) {
|
|
156
|
+
this._sxNet = undefined
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
if (value instanceof SegmentNet) {
|
|
160
|
+
this._sxNet = value
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
this._sxNet = new SegmentNet(value.id, value.name)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get uuid(): Uuid | undefined {
|
|
167
|
+
return this._sxUuid
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
set uuid(value: Uuid | string | undefined) {
|
|
171
|
+
if (value === undefined) {
|
|
172
|
+
this._sxUuid = undefined
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
get locked(): boolean {
|
|
179
|
+
return this._sxLocked?.value ?? false
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
set locked(value: boolean) {
|
|
183
|
+
this._sxLocked = value ? new SegmentLocked(true) : undefined
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
override getChildren(): SxClass[] {
|
|
187
|
+
const children: SxClass[] = []
|
|
188
|
+
if (this._sxStart) children.push(this._sxStart)
|
|
189
|
+
if (this._sxEnd) children.push(this._sxEnd)
|
|
190
|
+
if (this._sxWidth) children.push(this._sxWidth)
|
|
191
|
+
if (this._sxLayer) children.push(this._sxLayer)
|
|
192
|
+
if (this._sxNet) children.push(this._sxNet)
|
|
193
|
+
if (this._sxLocked) children.push(this._sxLocked)
|
|
194
|
+
if (this._sxUuid) children.push(this._sxUuid)
|
|
195
|
+
return children
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private normalizeStart(
|
|
199
|
+
value: SegmentStart | { x: number; y: number } | undefined,
|
|
200
|
+
): SegmentStart | undefined {
|
|
201
|
+
if (value === undefined) {
|
|
202
|
+
return undefined
|
|
203
|
+
}
|
|
204
|
+
if (value instanceof SegmentStart) {
|
|
205
|
+
return value
|
|
206
|
+
}
|
|
207
|
+
return new SegmentStart(value.x, value.y)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private normalizeEnd(
|
|
211
|
+
value: SegmentEnd | { x: number; y: number } | undefined,
|
|
212
|
+
): SegmentEnd | undefined {
|
|
213
|
+
if (value === undefined) {
|
|
214
|
+
return undefined
|
|
215
|
+
}
|
|
216
|
+
if (value instanceof SegmentEnd) {
|
|
217
|
+
return value
|
|
218
|
+
}
|
|
219
|
+
return new SegmentEnd(value.x, value.y)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
SxClass.register(Segment)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
import { toNumberValue } from "../utils/toNumberValue"
|
|
4
|
+
|
|
5
|
+
export class SegmentEnd extends SxClass {
|
|
6
|
+
static override token = "end"
|
|
7
|
+
static override parentToken = "segment"
|
|
8
|
+
override token = "end"
|
|
9
|
+
|
|
10
|
+
private _x: number
|
|
11
|
+
private _y: number
|
|
12
|
+
|
|
13
|
+
constructor(x: number, y: number) {
|
|
14
|
+
super()
|
|
15
|
+
this._x = x
|
|
16
|
+
this._y = y
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static override fromSexprPrimitives(
|
|
20
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
21
|
+
): SegmentEnd {
|
|
22
|
+
const [rawX, rawY] = primitiveSexprs
|
|
23
|
+
const x = toNumberValue(rawX)
|
|
24
|
+
const y = toNumberValue(rawY)
|
|
25
|
+
if (x === undefined || y === undefined) {
|
|
26
|
+
throw new Error("end expects two numeric arguments")
|
|
27
|
+
}
|
|
28
|
+
return new SegmentEnd(x, y)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get x(): number {
|
|
32
|
+
return this._x
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set x(value: number) {
|
|
36
|
+
this._x = value
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get y(): number {
|
|
40
|
+
return this._y
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set y(value: number) {
|
|
44
|
+
this._y = value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toObject(): { x: number; y: number } {
|
|
48
|
+
return { x: this._x, y: this._y }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override getChildren(): SxClass[] {
|
|
52
|
+
return []
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override getString(): string {
|
|
56
|
+
return `(end ${this._x} ${this._y})`
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
SxClass.register(SegmentEnd)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
|
|
3
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
4
|
+
|
|
5
|
+
const truthyStrings = new Set(["true", "yes", "1"])
|
|
6
|
+
|
|
7
|
+
export class SegmentLocked extends SxPrimitiveBoolean {
|
|
8
|
+
static override token = "locked"
|
|
9
|
+
static override parentToken = "segment"
|
|
10
|
+
override token = "locked"
|
|
11
|
+
|
|
12
|
+
constructor(value: boolean) {
|
|
13
|
+
super(value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static override fromSexprPrimitives(
|
|
17
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
18
|
+
): SegmentLocked {
|
|
19
|
+
const [rawValue] = primitiveSexprs
|
|
20
|
+
if (typeof rawValue === "boolean") {
|
|
21
|
+
return new SegmentLocked(rawValue)
|
|
22
|
+
}
|
|
23
|
+
if (typeof rawValue === "string") {
|
|
24
|
+
return new SegmentLocked(truthyStrings.has(rawValue.toLowerCase()))
|
|
25
|
+
}
|
|
26
|
+
return new SegmentLocked(false)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override getString(): string {
|
|
30
|
+
return `(locked ${this.value ? "yes" : "no"})`
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
SxClass.register(SegmentLocked)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
import { quoteSExprString } from "../utils/quoteSExprString"
|
|
4
|
+
import { toNumberValue } from "../utils/toNumberValue"
|
|
5
|
+
import { toStringValue } from "../utils/toStringValue"
|
|
6
|
+
|
|
7
|
+
export class SegmentNet extends SxClass {
|
|
8
|
+
static override token = "net"
|
|
9
|
+
static override parentToken = "segment"
|
|
10
|
+
override token = "net"
|
|
11
|
+
|
|
12
|
+
private _id: number
|
|
13
|
+
private _name?: string
|
|
14
|
+
|
|
15
|
+
constructor(id: number, name?: string) {
|
|
16
|
+
super()
|
|
17
|
+
this._id = id
|
|
18
|
+
this._name = name
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static override fromSexprPrimitives(
|
|
22
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
23
|
+
): SegmentNet {
|
|
24
|
+
const [rawId, rawName] = primitiveSexprs
|
|
25
|
+
const id = toNumberValue(rawId)
|
|
26
|
+
if (id === undefined) {
|
|
27
|
+
throw new Error("net expects a numeric identifier")
|
|
28
|
+
}
|
|
29
|
+
const name = rawName === undefined ? undefined : toStringValue(rawName)
|
|
30
|
+
return new SegmentNet(id, name ?? undefined)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get id(): number {
|
|
34
|
+
return this._id
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
set id(value: number) {
|
|
38
|
+
this._id = value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get name(): string | undefined {
|
|
42
|
+
return this._name
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
set name(value: string | undefined) {
|
|
46
|
+
this._name = value === "" ? undefined : value
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toObject(): { id: number; name?: string } {
|
|
50
|
+
return this._name === undefined ? { id: this._id } : { id: this._id, name: this._name }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override getChildren(): SxClass[] {
|
|
54
|
+
return []
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
override getString(): string {
|
|
58
|
+
const namePart = this._name ? ` ${quoteSExprString(this._name)}` : ""
|
|
59
|
+
return `(net ${this._id}${namePart})`
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
SxClass.register(SegmentNet)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
+
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
+
import { toNumberValue } from "../utils/toNumberValue"
|
|
4
|
+
|
|
5
|
+
export class SegmentStart extends SxClass {
|
|
6
|
+
static override token = "start"
|
|
7
|
+
static override parentToken = "segment"
|
|
8
|
+
override token = "start"
|
|
9
|
+
|
|
10
|
+
private _x: number
|
|
11
|
+
private _y: number
|
|
12
|
+
|
|
13
|
+
constructor(x: number, y: number) {
|
|
14
|
+
super()
|
|
15
|
+
this._x = x
|
|
16
|
+
this._y = y
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static override fromSexprPrimitives(
|
|
20
|
+
primitiveSexprs: PrimitiveSExpr[],
|
|
21
|
+
): SegmentStart {
|
|
22
|
+
const [rawX, rawY] = primitiveSexprs
|
|
23
|
+
const x = toNumberValue(rawX)
|
|
24
|
+
const y = toNumberValue(rawY)
|
|
25
|
+
if (x === undefined || y === undefined) {
|
|
26
|
+
throw new Error("start expects two numeric arguments")
|
|
27
|
+
}
|
|
28
|
+
return new SegmentStart(x, y)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get x(): number {
|
|
32
|
+
return this._x
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set x(value: number) {
|
|
36
|
+
this._x = value
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get y(): number {
|
|
40
|
+
return this._y
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
set y(value: number) {
|
|
44
|
+
this._y = value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toObject(): { x: number; y: number } {
|
|
48
|
+
return { x: this._x, y: this._y }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override getChildren(): SxClass[] {
|
|
52
|
+
return []
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override getString(): string {
|
|
56
|
+
return `(start ${this._x} ${this._y})`
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
SxClass.register(SegmentStart)
|