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.
Files changed (188) hide show
  1. package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +111 -0
  2. package/.vscode/settings.json +16 -0
  3. package/AGENTS.md +30 -0
  4. package/README.md +206 -0
  5. package/biome.json +93 -0
  6. package/bun.lock +48 -0
  7. package/bunfig.toml +5 -0
  8. package/lib/index.ts +1 -0
  9. package/lib/sexpr/base-classes/SxClass.ts +164 -0
  10. package/lib/sexpr/base-classes/SxPrimitiveBoolean.ts +35 -0
  11. package/lib/sexpr/base-classes/SxPrimitiveNumber.ts +26 -0
  12. package/lib/sexpr/base-classes/SxPrimitiveString.ts +26 -0
  13. package/lib/sexpr/classes/At.ts +38 -0
  14. package/lib/sexpr/classes/Bus.ts +83 -0
  15. package/lib/sexpr/classes/BusEntry.ts +142 -0
  16. package/lib/sexpr/classes/Color.ts +29 -0
  17. package/lib/sexpr/classes/Dnp.ts +8 -0
  18. package/lib/sexpr/classes/EmbeddedFonts.ts +70 -0
  19. package/lib/sexpr/classes/ExcludeFromSim.ts +8 -0
  20. package/lib/sexpr/classes/FieldsAutoplaced.ts +8 -0
  21. package/lib/sexpr/classes/Footprint.ts +719 -0
  22. package/lib/sexpr/classes/FootprintAttr.ts +102 -0
  23. package/lib/sexpr/classes/FootprintAutoplaceCost180.ts +9 -0
  24. package/lib/sexpr/classes/FootprintAutoplaceCost90.ts +9 -0
  25. package/lib/sexpr/classes/FootprintClearance.ts +9 -0
  26. package/lib/sexpr/classes/FootprintDescr.ts +44 -0
  27. package/lib/sexpr/classes/FootprintLocked.ts +32 -0
  28. package/lib/sexpr/classes/FootprintModel.ts +145 -0
  29. package/lib/sexpr/classes/FootprintNetTiePadGroups.ts +50 -0
  30. package/lib/sexpr/classes/FootprintPad.ts +705 -0
  31. package/lib/sexpr/classes/FootprintPath.ts +44 -0
  32. package/lib/sexpr/classes/FootprintPlaced.ts +32 -0
  33. package/lib/sexpr/classes/FootprintPrivateLayers.ts +56 -0
  34. package/lib/sexpr/classes/FootprintSheetfile.ts +44 -0
  35. package/lib/sexpr/classes/FootprintSheetname.ts +44 -0
  36. package/lib/sexpr/classes/FootprintSolderMaskMargin.ts +9 -0
  37. package/lib/sexpr/classes/FootprintSolderPasteMargin.ts +9 -0
  38. package/lib/sexpr/classes/FootprintSolderPasteRatio.ts +9 -0
  39. package/lib/sexpr/classes/FootprintTags.ts +44 -0
  40. package/lib/sexpr/classes/FootprintTedit.ts +21 -0
  41. package/lib/sexpr/classes/FootprintThermalGap.ts +9 -0
  42. package/lib/sexpr/classes/FootprintThermalWidth.ts +9 -0
  43. package/lib/sexpr/classes/FootprintZoneConnect.ts +9 -0
  44. package/lib/sexpr/classes/FpArc.ts +289 -0
  45. package/lib/sexpr/classes/FpCircle.ts +293 -0
  46. package/lib/sexpr/classes/FpLine.ts +288 -0
  47. package/lib/sexpr/classes/FpPoly.ts +266 -0
  48. package/lib/sexpr/classes/FpPolyFill.ts +48 -0
  49. package/lib/sexpr/classes/FpPolyLocked.ts +40 -0
  50. package/lib/sexpr/classes/FpRect.ts +293 -0
  51. package/lib/sexpr/classes/FpText.ts +341 -0
  52. package/lib/sexpr/classes/FpTextBox.ts +412 -0
  53. package/lib/sexpr/classes/GrLine.ts +245 -0
  54. package/lib/sexpr/classes/GrLineAngle.ts +32 -0
  55. package/lib/sexpr/classes/GrLineEnd.ts +61 -0
  56. package/lib/sexpr/classes/GrLineLocked.ts +40 -0
  57. package/lib/sexpr/classes/GrLineStart.ts +61 -0
  58. package/lib/sexpr/classes/GrText.ts +202 -0
  59. package/lib/sexpr/classes/Image.ts +256 -0
  60. package/lib/sexpr/classes/InBom.ts +8 -0
  61. package/lib/sexpr/classes/Junction.ts +134 -0
  62. package/lib/sexpr/classes/KicadPcb.ts +313 -0
  63. package/lib/sexpr/classes/KicadSch.ts +303 -0
  64. package/lib/sexpr/classes/KicadSchGenerator.ts +32 -0
  65. package/lib/sexpr/classes/KicadSchGeneratorVersion.ts +30 -0
  66. package/lib/sexpr/classes/KicadSchVersion.ts +22 -0
  67. package/lib/sexpr/classes/Label.ts +136 -0
  68. package/lib/sexpr/classes/Layer.ts +51 -0
  69. package/lib/sexpr/classes/Layers.ts +47 -0
  70. package/lib/sexpr/classes/LibSymbols.ts +61 -0
  71. package/lib/sexpr/classes/NoConnect.ts +73 -0
  72. package/lib/sexpr/classes/OnBoard.ts +8 -0
  73. package/lib/sexpr/classes/PadChamfer.ts +50 -0
  74. package/lib/sexpr/classes/PadChamferRatio.ts +9 -0
  75. package/lib/sexpr/classes/PadClearance.ts +9 -0
  76. package/lib/sexpr/classes/PadDieLength.ts +9 -0
  77. package/lib/sexpr/classes/PadDrill.ts +145 -0
  78. package/lib/sexpr/classes/PadDrillOffset.ts +54 -0
  79. package/lib/sexpr/classes/PadLayers.ts +59 -0
  80. package/lib/sexpr/classes/PadNet.ts +56 -0
  81. package/lib/sexpr/classes/PadOptions.ts +182 -0
  82. package/lib/sexpr/classes/PadPinFunction.ts +9 -0
  83. package/lib/sexpr/classes/PadPinType.ts +9 -0
  84. package/lib/sexpr/classes/PadPrimitiveGrArc.ts +254 -0
  85. package/lib/sexpr/classes/PadPrimitiveGrCircle.ts +279 -0
  86. package/lib/sexpr/classes/PadPrimitiveGrLine.ts +126 -0
  87. package/lib/sexpr/classes/PadPrimitives.ts +289 -0
  88. package/lib/sexpr/classes/PadRectDelta.ts +57 -0
  89. package/lib/sexpr/classes/PadRoundrectRratio.ts +9 -0
  90. package/lib/sexpr/classes/PadSize.ts +54 -0
  91. package/lib/sexpr/classes/PadSolderMaskMargin.ts +9 -0
  92. package/lib/sexpr/classes/PadSolderPasteMargin.ts +9 -0
  93. package/lib/sexpr/classes/PadSolderPasteMarginRatio.ts +9 -0
  94. package/lib/sexpr/classes/PadTeardrops.ts +208 -0
  95. package/lib/sexpr/classes/PadThermalBridgeAngle.ts +9 -0
  96. package/lib/sexpr/classes/PadThermalGap.ts +9 -0
  97. package/lib/sexpr/classes/PadThermalWidth.ts +9 -0
  98. package/lib/sexpr/classes/PadZoneConnect.ts +9 -0
  99. package/lib/sexpr/classes/Paper.ts +119 -0
  100. package/lib/sexpr/classes/PcbGeneral.ts +75 -0
  101. package/lib/sexpr/classes/PcbGeneralLegacyTeardrops.ts +44 -0
  102. package/lib/sexpr/classes/PcbGeneralThickness.ts +9 -0
  103. package/lib/sexpr/classes/PcbGenerator.ts +16 -0
  104. package/lib/sexpr/classes/PcbGeneratorVersion.ts +16 -0
  105. package/lib/sexpr/classes/PcbLayerDefinition.ts +102 -0
  106. package/lib/sexpr/classes/PcbLayers.ts +34 -0
  107. package/lib/sexpr/classes/PcbNet.ts +56 -0
  108. package/lib/sexpr/classes/PcbVersion.ts +9 -0
  109. package/lib/sexpr/classes/Property.ts +246 -0
  110. package/lib/sexpr/classes/PropertyHide.ts +9 -0
  111. package/lib/sexpr/classes/PropertyUnlocked.ts +9 -0
  112. package/lib/sexpr/classes/Pts.ts +65 -0
  113. package/lib/sexpr/classes/RenderCache.ts +221 -0
  114. package/lib/sexpr/classes/SchematicText.ts +141 -0
  115. package/lib/sexpr/classes/Segment.ts +222 -0
  116. package/lib/sexpr/classes/SegmentEnd.ts +59 -0
  117. package/lib/sexpr/classes/SegmentLocked.ts +33 -0
  118. package/lib/sexpr/classes/SegmentNet.ts +62 -0
  119. package/lib/sexpr/classes/SegmentStart.ts +59 -0
  120. package/lib/sexpr/classes/Setup/PcbPlotParams.ts +729 -0
  121. package/lib/sexpr/classes/Setup/PcbPlotParamsBase.ts +9 -0
  122. package/lib/sexpr/classes/Setup/PcbPlotParamsNumericProperties.ts +105 -0
  123. package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesA.ts +104 -0
  124. package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesB.ts +105 -0
  125. package/lib/sexpr/classes/Setup/Setup.ts +573 -0
  126. package/lib/sexpr/classes/Setup/SetupPropertyTypes.ts +119 -0
  127. package/lib/sexpr/classes/Setup/Stackup.ts +140 -0
  128. package/lib/sexpr/classes/Setup/StackupLayer.ts +233 -0
  129. package/lib/sexpr/classes/Setup/StackupLayerProperties.ts +78 -0
  130. package/lib/sexpr/classes/Setup/StackupProperties.ts +41 -0
  131. package/lib/sexpr/classes/Setup/base.ts +167 -0
  132. package/lib/sexpr/classes/Setup/index.ts +14 -0
  133. package/lib/sexpr/classes/Setup/setupMultiValueProperties.ts +54 -0
  134. package/lib/sexpr/classes/Setup/setupNumericProperties.ts +151 -0
  135. package/lib/sexpr/classes/Setup/setupPropertyHandlers.ts +90 -0
  136. package/lib/sexpr/classes/Setup/setupStringProperties.ts +75 -0
  137. package/lib/sexpr/classes/Sheet.ts +205 -0
  138. package/lib/sexpr/classes/SheetFill.ts +44 -0
  139. package/lib/sexpr/classes/SheetInstances.ts +168 -0
  140. package/lib/sexpr/classes/SheetInstancesRoot.ts +165 -0
  141. package/lib/sexpr/classes/SheetPin.ts +122 -0
  142. package/lib/sexpr/classes/SheetProperty.ts +115 -0
  143. package/lib/sexpr/classes/SheetSize.ts +44 -0
  144. package/lib/sexpr/classes/Stroke.ts +58 -0
  145. package/lib/sexpr/classes/StrokeType.ts +34 -0
  146. package/lib/sexpr/classes/Symbol.ts +1541 -0
  147. package/lib/sexpr/classes/TextEffects.ts +444 -0
  148. package/lib/sexpr/classes/TitleBlock.ts +352 -0
  149. package/lib/sexpr/classes/Unit.ts +28 -0
  150. package/lib/sexpr/classes/Uuid.ts +8 -0
  151. package/lib/sexpr/classes/Via.ts +328 -0
  152. package/lib/sexpr/classes/ViaNet.ts +59 -0
  153. package/lib/sexpr/classes/Width.ts +8 -0
  154. package/lib/sexpr/classes/Wire.ts +91 -0
  155. package/lib/sexpr/classes/Xy.ts +35 -0
  156. package/lib/sexpr/classes/Zone.ts +41 -0
  157. package/lib/sexpr/index.ts +130 -0
  158. package/lib/sexpr/parseKicadSexpr.ts +5 -0
  159. package/lib/sexpr/parseToPrimitiveSExpr.ts +240 -0
  160. package/lib/sexpr/utils/indentLines.ts +3 -0
  161. package/lib/sexpr/utils/parseYesNo.ts +12 -0
  162. package/lib/sexpr/utils/quoteSExprString.ts +8 -0
  163. package/lib/sexpr/utils/strokeFromArgs.ts +19 -0
  164. package/lib/sexpr/utils/toNumberValue.ts +13 -0
  165. package/lib/sexpr/utils/toStringValue.ts +10 -0
  166. package/package.json +26 -0
  167. package/scripts/download-references.ts +66 -0
  168. package/tests/fixtures/expectEqualPrimitiveSExpr.ts +200 -0
  169. package/tests/sexpr/KicadPcbDemos.test.ts +48 -0
  170. package/tests/sexpr/KicadSchDemos.test.ts +49 -0
  171. package/tests/sexpr/classes/Footprint.test.ts +277 -0
  172. package/tests/sexpr/classes/FootprintPad.test.ts +71 -0
  173. package/tests/sexpr/classes/FpArc.test.ts +45 -0
  174. package/tests/sexpr/classes/FpCircle.test.ts +39 -0
  175. package/tests/sexpr/classes/FpPoly.test.ts +43 -0
  176. package/tests/sexpr/classes/FpRect.test.ts +40 -0
  177. package/tests/sexpr/classes/FpTextBox.test.ts +84 -0
  178. package/tests/sexpr/classes/Image.test.ts +50 -0
  179. package/tests/sexpr/classes/KicadSch.test.ts +97 -0
  180. package/tests/sexpr/classes/Paper.test.ts +30 -0
  181. package/tests/sexpr/classes/Property.test.ts +48 -0
  182. package/tests/sexpr/classes/Setup.test.ts +189 -0
  183. package/tests/sexpr/classes/Sheet.test.ts +107 -0
  184. package/tests/sexpr/classes/Stroke.test.ts +15 -0
  185. package/tests/sexpr/classes/Symbol.test.ts +96 -0
  186. package/tests/sexpr/classes/TextEffects.test.ts +56 -0
  187. package/tests/sexpr/classes/TitleBlock.test.ts +40 -0
  188. 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)