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.
Files changed (195) hide show
  1. package/dist/index.d.ts +4466 -0
  2. package/dist/index.js +14253 -0
  3. package/package.json +5 -2
  4. package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
  5. package/.github/workflows/bun-formatcheck.yml +0 -26
  6. package/.github/workflows/bun-pver-release.yml +0 -70
  7. package/.github/workflows/bun-test.yml +0 -32
  8. package/.github/workflows/bun-typecheck.yml +0 -26
  9. package/.vscode/settings.json +0 -16
  10. package/AGENTS.md +0 -31
  11. package/TODO.md +0 -46
  12. package/biome.json +0 -93
  13. package/bunfig.toml +0 -5
  14. package/lib/index.ts +0 -1
  15. package/lib/sexpr/base-classes/SxClass.ts +0 -164
  16. package/lib/sexpr/base-classes/SxPrimitiveBoolean.ts +0 -35
  17. package/lib/sexpr/base-classes/SxPrimitiveNumber.ts +0 -26
  18. package/lib/sexpr/base-classes/SxPrimitiveString.ts +0 -26
  19. package/lib/sexpr/classes/At.ts +0 -53
  20. package/lib/sexpr/classes/Bus.ts +0 -103
  21. package/lib/sexpr/classes/BusEntry.ts +0 -169
  22. package/lib/sexpr/classes/Color.ts +0 -29
  23. package/lib/sexpr/classes/Dnp.ts +0 -8
  24. package/lib/sexpr/classes/EmbeddedFonts.ts +0 -68
  25. package/lib/sexpr/classes/ExcludeFromSim.ts +0 -8
  26. package/lib/sexpr/classes/FieldsAutoplaced.ts +0 -8
  27. package/lib/sexpr/classes/Footprint.ts +0 -849
  28. package/lib/sexpr/classes/FootprintAttr.ts +0 -104
  29. package/lib/sexpr/classes/FootprintAutoplaceCost180.ts +0 -9
  30. package/lib/sexpr/classes/FootprintAutoplaceCost90.ts +0 -9
  31. package/lib/sexpr/classes/FootprintClearance.ts +0 -9
  32. package/lib/sexpr/classes/FootprintDescr.ts +0 -44
  33. package/lib/sexpr/classes/FootprintLocked.ts +0 -32
  34. package/lib/sexpr/classes/FootprintModel.ts +0 -142
  35. package/lib/sexpr/classes/FootprintNetTiePadGroups.ts +0 -52
  36. package/lib/sexpr/classes/FootprintPad.ts +0 -857
  37. package/lib/sexpr/classes/FootprintPath.ts +0 -44
  38. package/lib/sexpr/classes/FootprintPlaced.ts +0 -32
  39. package/lib/sexpr/classes/FootprintPrivateLayers.ts +0 -56
  40. package/lib/sexpr/classes/FootprintSheetfile.ts +0 -44
  41. package/lib/sexpr/classes/FootprintSheetname.ts +0 -44
  42. package/lib/sexpr/classes/FootprintSolderMaskMargin.ts +0 -9
  43. package/lib/sexpr/classes/FootprintSolderPasteMargin.ts +0 -9
  44. package/lib/sexpr/classes/FootprintSolderPasteRatio.ts +0 -9
  45. package/lib/sexpr/classes/FootprintTags.ts +0 -44
  46. package/lib/sexpr/classes/FootprintTedit.ts +0 -21
  47. package/lib/sexpr/classes/FootprintThermalGap.ts +0 -9
  48. package/lib/sexpr/classes/FootprintThermalWidth.ts +0 -9
  49. package/lib/sexpr/classes/FootprintZoneConnect.ts +0 -9
  50. package/lib/sexpr/classes/FpArc.ts +0 -312
  51. package/lib/sexpr/classes/FpCircle.ts +0 -314
  52. package/lib/sexpr/classes/FpLine.ts +0 -316
  53. package/lib/sexpr/classes/FpPoly.ts +0 -286
  54. package/lib/sexpr/classes/FpPolyFill.ts +0 -48
  55. package/lib/sexpr/classes/FpPolyLocked.ts +0 -40
  56. package/lib/sexpr/classes/FpRect.ts +0 -314
  57. package/lib/sexpr/classes/FpText.ts +0 -375
  58. package/lib/sexpr/classes/FpTextBox.ts +0 -450
  59. package/lib/sexpr/classes/GrLine.ts +0 -264
  60. package/lib/sexpr/classes/GrLineAngle.ts +0 -32
  61. package/lib/sexpr/classes/GrLineEnd.ts +0 -61
  62. package/lib/sexpr/classes/GrLineLocked.ts +0 -40
  63. package/lib/sexpr/classes/GrLineStart.ts +0 -61
  64. package/lib/sexpr/classes/GrText.ts +0 -228
  65. package/lib/sexpr/classes/Image.ts +0 -283
  66. package/lib/sexpr/classes/InBom.ts +0 -8
  67. package/lib/sexpr/classes/Junction.ts +0 -166
  68. package/lib/sexpr/classes/KicadPcb.ts +0 -361
  69. package/lib/sexpr/classes/KicadSch.ts +0 -397
  70. package/lib/sexpr/classes/KicadSchGenerator.ts +0 -32
  71. package/lib/sexpr/classes/KicadSchGeneratorVersion.ts +0 -30
  72. package/lib/sexpr/classes/KicadSchVersion.ts +0 -22
  73. package/lib/sexpr/classes/Label.ts +0 -176
  74. package/lib/sexpr/classes/Layer.ts +0 -51
  75. package/lib/sexpr/classes/Layers.ts +0 -47
  76. package/lib/sexpr/classes/LibSymbols.ts +0 -61
  77. package/lib/sexpr/classes/NoConnect.ts +0 -90
  78. package/lib/sexpr/classes/OnBoard.ts +0 -8
  79. package/lib/sexpr/classes/PadChamfer.ts +0 -50
  80. package/lib/sexpr/classes/PadChamferRatio.ts +0 -9
  81. package/lib/sexpr/classes/PadClearance.ts +0 -9
  82. package/lib/sexpr/classes/PadDieLength.ts +0 -9
  83. package/lib/sexpr/classes/PadDrill.ts +0 -145
  84. package/lib/sexpr/classes/PadDrillOffset.ts +0 -54
  85. package/lib/sexpr/classes/PadLayers.ts +0 -71
  86. package/lib/sexpr/classes/PadNet.ts +0 -56
  87. package/lib/sexpr/classes/PadOptions.ts +0 -181
  88. package/lib/sexpr/classes/PadPinFunction.ts +0 -9
  89. package/lib/sexpr/classes/PadPinType.ts +0 -9
  90. package/lib/sexpr/classes/PadPrimitiveGrArc.ts +0 -272
  91. package/lib/sexpr/classes/PadPrimitiveGrCircle.ts +0 -298
  92. package/lib/sexpr/classes/PadPrimitiveGrLine.ts +0 -126
  93. package/lib/sexpr/classes/PadPrimitives.ts +0 -291
  94. package/lib/sexpr/classes/PadRectDelta.ts +0 -57
  95. package/lib/sexpr/classes/PadRoundrectRratio.ts +0 -9
  96. package/lib/sexpr/classes/PadSize.ts +0 -69
  97. package/lib/sexpr/classes/PadSolderMaskMargin.ts +0 -9
  98. package/lib/sexpr/classes/PadSolderPasteMargin.ts +0 -9
  99. package/lib/sexpr/classes/PadSolderPasteMarginRatio.ts +0 -9
  100. package/lib/sexpr/classes/PadTeardrops.ts +0 -210
  101. package/lib/sexpr/classes/PadThermalBridgeAngle.ts +0 -9
  102. package/lib/sexpr/classes/PadThermalGap.ts +0 -9
  103. package/lib/sexpr/classes/PadThermalWidth.ts +0 -9
  104. package/lib/sexpr/classes/PadZoneConnect.ts +0 -9
  105. package/lib/sexpr/classes/Paper.ts +0 -119
  106. package/lib/sexpr/classes/PcbGeneral.ts +0 -82
  107. package/lib/sexpr/classes/PcbGeneralLegacyTeardrops.ts +0 -44
  108. package/lib/sexpr/classes/PcbGeneralThickness.ts +0 -9
  109. package/lib/sexpr/classes/PcbGenerator.ts +0 -16
  110. package/lib/sexpr/classes/PcbGeneratorVersion.ts +0 -16
  111. package/lib/sexpr/classes/PcbLayerDefinition.ts +0 -106
  112. package/lib/sexpr/classes/PcbLayers.ts +0 -34
  113. package/lib/sexpr/classes/PcbNet.ts +0 -56
  114. package/lib/sexpr/classes/PcbVersion.ts +0 -9
  115. package/lib/sexpr/classes/Property.ts +0 -301
  116. package/lib/sexpr/classes/PropertyHide.ts +0 -9
  117. package/lib/sexpr/classes/PropertyUnlocked.ts +0 -9
  118. package/lib/sexpr/classes/Pts.ts +0 -67
  119. package/lib/sexpr/classes/RenderCache.ts +0 -221
  120. package/lib/sexpr/classes/SchematicText.ts +0 -171
  121. package/lib/sexpr/classes/Segment.ts +0 -243
  122. package/lib/sexpr/classes/SegmentEnd.ts +0 -59
  123. package/lib/sexpr/classes/SegmentLocked.ts +0 -33
  124. package/lib/sexpr/classes/SegmentNet.ts +0 -64
  125. package/lib/sexpr/classes/SegmentStart.ts +0 -59
  126. package/lib/sexpr/classes/Setup/PcbPlotParams.ts +0 -689
  127. package/lib/sexpr/classes/Setup/PcbPlotParamsBase.ts +0 -9
  128. package/lib/sexpr/classes/Setup/PcbPlotParamsNumericProperties.ts +0 -105
  129. package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesA.ts +0 -104
  130. package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesB.ts +0 -105
  131. package/lib/sexpr/classes/Setup/Setup.ts +0 -574
  132. package/lib/sexpr/classes/Setup/SetupPropertyTypes.ts +0 -119
  133. package/lib/sexpr/classes/Setup/Stackup.ts +0 -135
  134. package/lib/sexpr/classes/Setup/StackupLayer.ts +0 -233
  135. package/lib/sexpr/classes/Setup/StackupLayerProperties.ts +0 -80
  136. package/lib/sexpr/classes/Setup/StackupProperties.ts +0 -40
  137. package/lib/sexpr/classes/Setup/base.ts +0 -165
  138. package/lib/sexpr/classes/Setup/index.ts +0 -14
  139. package/lib/sexpr/classes/Setup/setupMultiValueProperties.ts +0 -53
  140. package/lib/sexpr/classes/Setup/setupNumericProperties.ts +0 -151
  141. package/lib/sexpr/classes/Setup/setupPropertyHandlers.ts +0 -90
  142. package/lib/sexpr/classes/Setup/setupStringProperties.ts +0 -75
  143. package/lib/sexpr/classes/Sheet.ts +0 -287
  144. package/lib/sexpr/classes/SheetFill.ts +0 -44
  145. package/lib/sexpr/classes/SheetInstances.ts +0 -168
  146. package/lib/sexpr/classes/SheetInstancesRoot.ts +0 -165
  147. package/lib/sexpr/classes/SheetPin.ts +0 -125
  148. package/lib/sexpr/classes/SheetProperty.ts +0 -115
  149. package/lib/sexpr/classes/SheetSize.ts +0 -44
  150. package/lib/sexpr/classes/Stroke.ts +0 -58
  151. package/lib/sexpr/classes/StrokeType.ts +0 -34
  152. package/lib/sexpr/classes/Symbol.ts +0 -1666
  153. package/lib/sexpr/classes/TextEffects.ts +0 -461
  154. package/lib/sexpr/classes/TitleBlock.ts +0 -369
  155. package/lib/sexpr/classes/Unit.ts +0 -28
  156. package/lib/sexpr/classes/Uuid.ts +0 -8
  157. package/lib/sexpr/classes/Via.ts +0 -363
  158. package/lib/sexpr/classes/ViaNet.ts +0 -60
  159. package/lib/sexpr/classes/Width.ts +0 -8
  160. package/lib/sexpr/classes/Wire.ts +0 -111
  161. package/lib/sexpr/classes/Xy.ts +0 -33
  162. package/lib/sexpr/classes/Zone.ts +0 -39
  163. package/lib/sexpr/index.ts +0 -130
  164. package/lib/sexpr/parseKicadSexpr.ts +0 -5
  165. package/lib/sexpr/parseToPrimitiveSExpr.ts +0 -245
  166. package/lib/sexpr/utils/indentLines.ts +0 -3
  167. package/lib/sexpr/utils/parseYesNo.ts +0 -12
  168. package/lib/sexpr/utils/quoteSExprString.ts +0 -8
  169. package/lib/sexpr/utils/strokeFromArgs.ts +0 -18
  170. package/lib/sexpr/utils/toNumberValue.ts +0 -13
  171. package/lib/sexpr/utils/toStringValue.ts +0 -11
  172. package/scripts/download-references.ts +0 -68
  173. package/tests/fixtures/expectEqualPrimitiveSExpr.ts +0 -199
  174. package/tests/fixtures/png-matcher.ts +0 -109
  175. package/tests/fixtures/preload.ts +0 -1
  176. package/tests/sexpr/KicadPcbDemos.test.ts +0 -48
  177. package/tests/sexpr/KicadSchDemos.test.ts +0 -49
  178. package/tests/sexpr/classes/Footprint.test.ts +0 -277
  179. package/tests/sexpr/classes/FootprintPad.test.ts +0 -78
  180. package/tests/sexpr/classes/FpArc.test.ts +0 -45
  181. package/tests/sexpr/classes/FpCircle.test.ts +0 -39
  182. package/tests/sexpr/classes/FpPoly.test.ts +0 -43
  183. package/tests/sexpr/classes/FpRect.test.ts +0 -40
  184. package/tests/sexpr/classes/FpTextBox.test.ts +0 -84
  185. package/tests/sexpr/classes/Image.test.ts +0 -58
  186. package/tests/sexpr/classes/KicadSch.test.ts +0 -95
  187. package/tests/sexpr/classes/Paper.test.ts +0 -30
  188. package/tests/sexpr/classes/Property.test.ts +0 -48
  189. package/tests/sexpr/classes/Setup.test.ts +0 -188
  190. package/tests/sexpr/classes/Sheet.test.ts +0 -107
  191. package/tests/sexpr/classes/Stroke.test.ts +0 -15
  192. package/tests/sexpr/classes/Symbol.test.ts +0 -96
  193. package/tests/sexpr/classes/TextEffects.test.ts +0 -56
  194. package/tests/sexpr/classes/TitleBlock.test.ts +0 -40
  195. package/tsconfig.json +0 -35
@@ -1,1666 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
3
- import { SxPrimitiveNumber } from "../base-classes/SxPrimitiveNumber"
4
- import { quoteSExprString } from "../utils/quoteSExprString"
5
- import { indentLines } from "../utils/indentLines"
6
- import { toNumberValue } from "../utils/toNumberValue"
7
- import { toStringValue } from "../utils/toStringValue"
8
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
9
- import { At, type AtInput } from "./At"
10
- import { Dnp } from "./Dnp"
11
- import { EmbeddedFonts } from "./EmbeddedFonts"
12
- import { ExcludeFromSim } from "./ExcludeFromSim"
13
- import { InBom } from "./InBom"
14
- import { OnBoard } from "./OnBoard"
15
- import { FieldsAutoplaced } from "./FieldsAutoplaced"
16
- import { TextEffects } from "./TextEffects"
17
- import { Uuid } from "./Uuid"
18
- import { Pts } from "./Pts"
19
- import { Stroke } from "./Stroke"
20
-
21
- export class SymbolUnit extends SxPrimitiveNumber {
22
- static override token = "unit"
23
- static override parentToken = "symbol"
24
- token = "unit"
25
-
26
- static from(value: number | SymbolUnit): SymbolUnit {
27
- if (value instanceof SymbolUnit) {
28
- return value
29
- }
30
- return new SymbolUnit(value)
31
- }
32
- }
33
- SxClass.register(SymbolUnit)
34
-
35
- export class SymbolLibId extends SxClass {
36
- static override token = "lib_id"
37
- static override parentToken = "symbol"
38
- token = "lib_id"
39
-
40
- value: string
41
-
42
- constructor(value: string) {
43
- super()
44
- this.value = value
45
- }
46
-
47
- static override fromSexprPrimitives(
48
- primitiveSexprs: PrimitiveSExpr[],
49
- ): SymbolLibId {
50
- const [valuePrimitive] = primitiveSexprs
51
- const value = toStringValue(valuePrimitive)
52
- if (value === undefined) {
53
- throw new Error("lib_id expects a string value")
54
- }
55
- return new SymbolLibId(value)
56
- }
57
-
58
- override getChildren(): SxClass[] {
59
- return []
60
- }
61
-
62
- override getString(): string {
63
- return `(lib_id ${quoteSExprString(this.value)})`
64
- }
65
- }
66
- SxClass.register(SymbolLibId)
67
-
68
- export class SymbolDuplicatePinNumbersAreJumpers extends SxPrimitiveBoolean {
69
- static override token = "duplicate_pin_numbers_are_jumpers"
70
- static override parentToken = "symbol"
71
- token = "duplicate_pin_numbers_are_jumpers"
72
- }
73
- SxClass.register(SymbolDuplicatePinNumbersAreJumpers)
74
-
75
- export class SymbolPinNumbers extends SxClass {
76
- static override token = "pin_numbers"
77
- static override parentToken = "symbol"
78
- token = "pin_numbers"
79
-
80
- private _sxHide?: SymbolPinNumbersHide
81
-
82
- static override fromSexprPrimitives(
83
- primitiveSexprs: PrimitiveSExpr[],
84
- ): SymbolPinNumbers {
85
- const pinNumbers = new SymbolPinNumbers()
86
- const primitiveStrings: string[] = []
87
- const primitiveNodes: PrimitiveSExpr[] = []
88
- for (const primitive of primitiveSexprs) {
89
- if (typeof primitive === "string") {
90
- primitiveStrings.push(primitive)
91
- continue
92
- }
93
- primitiveNodes.push(primitive)
94
- }
95
-
96
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
97
- primitiveNodes,
98
- this.token,
99
- )
100
-
101
- pinNumbers._sxHide = propertyMap.hide as SymbolPinNumbersHide
102
-
103
- for (const flag of primitiveStrings) {
104
- if (flag === "hide") {
105
- pinNumbers._sxHide = new SymbolPinNumbersHide(true, { inline: true })
106
- continue
107
- }
108
- throw new Error(
109
- `symbol pin_numbers encountered unsupported flag "${flag}"`,
110
- )
111
- }
112
-
113
- return pinNumbers
114
- }
115
-
116
- get hide(): boolean {
117
- return this._sxHide?.value ?? false
118
- }
119
-
120
- set hide(value: boolean) {
121
- this._sxHide = new SymbolPinNumbersHide(value)
122
- }
123
-
124
- override getChildren(): SxClass[] {
125
- return this._sxHide ? [this._sxHide] : []
126
- }
127
- }
128
- SxClass.register(SymbolPinNumbers)
129
-
130
- export class SymbolPinNumbersHide extends SxPrimitiveBoolean {
131
- static override token = "hide"
132
- static override parentToken = "pin_numbers"
133
- token = "hide"
134
-
135
- private inline = false
136
-
137
- constructor(value?: boolean, options: { inline?: boolean } = {}) {
138
- super(value ?? true)
139
- this.inline = options.inline ?? false
140
- }
141
-
142
- override getString(): string {
143
- if (this.inline) {
144
- return this.value ? "hide" : "(hide no)"
145
- }
146
- return super.getString()
147
- }
148
- }
149
- SxClass.register(SymbolPinNumbersHide)
150
-
151
- export class SymbolPinNames extends SxClass {
152
- static override token = "pin_names"
153
- static override parentToken = "symbol"
154
- token = "pin_names"
155
-
156
- private _sxOffset?: SymbolPinNamesOffset
157
- private _sxHide?: SymbolPinNamesHide
158
-
159
- static override fromSexprPrimitives(
160
- primitiveSexprs: PrimitiveSExpr[],
161
- ): SymbolPinNames {
162
- const pinNames = new SymbolPinNames()
163
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
164
- primitiveSexprs,
165
- this.token,
166
- )
167
-
168
- pinNames._sxOffset = propertyMap.offset as SymbolPinNamesOffset
169
- pinNames._sxHide = propertyMap.hide as SymbolPinNamesHide
170
-
171
- return pinNames
172
- }
173
-
174
- get offset(): number | undefined {
175
- return this._sxOffset?.value
176
- }
177
-
178
- set offset(value: number | undefined) {
179
- if (value === undefined) {
180
- this._sxOffset = undefined
181
- return
182
- }
183
- this._sxOffset = new SymbolPinNamesOffset(value)
184
- }
185
-
186
- get hide(): boolean {
187
- return this._sxHide?.value ?? false
188
- }
189
-
190
- set hide(value: boolean) {
191
- this._sxHide = new SymbolPinNamesHide(value)
192
- }
193
-
194
- override getChildren(): SxClass[] {
195
- const children: SxClass[] = []
196
- if (this._sxOffset) children.push(this._sxOffset)
197
- if (this._sxHide) children.push(this._sxHide)
198
- return children
199
- }
200
- }
201
- SxClass.register(SymbolPinNames)
202
-
203
- export class SymbolPinNamesOffset extends SxClass {
204
- static override token = "offset"
205
- static override parentToken = "pin_names"
206
- token = "offset"
207
-
208
- value: number
209
-
210
- constructor(value: number) {
211
- super()
212
- this.value = value
213
- }
214
-
215
- static override fromSexprPrimitives(
216
- primitiveSexprs: PrimitiveSExpr[],
217
- ): SymbolPinNamesOffset {
218
- const [valuePrimitive] = primitiveSexprs
219
- const value = toNumberValue(valuePrimitive)
220
- if (value === undefined) {
221
- throw new Error("pin_names offset expects a numeric value")
222
- }
223
- return new SymbolPinNamesOffset(value)
224
- }
225
-
226
- override getChildren(): SxClass[] {
227
- return []
228
- }
229
-
230
- override getString(): string {
231
- return `(offset ${this.value})`
232
- }
233
- }
234
- SxClass.register(SymbolPinNamesOffset)
235
-
236
- export class SymbolPinNamesHide extends SxPrimitiveBoolean {
237
- static override token = "hide"
238
- static override parentToken = "pin_names"
239
- token = "hide"
240
- }
241
- SxClass.register(SymbolPinNamesHide)
242
-
243
- abstract class SymbolPointBase extends SxClass {
244
- protected _x: number
245
- protected _y: number
246
-
247
- constructor(x: number, y: number) {
248
- super()
249
- this._x = x
250
- this._y = y
251
- }
252
-
253
- static override fromSexprPrimitives(
254
- primitiveSexprs: PrimitiveSExpr[],
255
- ): SymbolPointBase {
256
- const [rawX, rawY] = primitiveSexprs
257
- const x = toNumberValue(rawX)
258
- const y = toNumberValue(rawY)
259
- if (x === undefined || y === undefined) {
260
- throw new Error(`${this.name} expects two numeric arguments`)
261
- }
262
- const Ctor = this as unknown as new (
263
- x: number,
264
- y: number,
265
- ) => SymbolPointBase
266
- return new Ctor(x, y)
267
- }
268
-
269
- get x(): number {
270
- return this._x
271
- }
272
-
273
- set x(value: number) {
274
- this._x = value
275
- }
276
-
277
- get y(): number {
278
- return this._y
279
- }
280
-
281
- set y(value: number) {
282
- this._y = value
283
- }
284
-
285
- toObject(): { x: number; y: number } {
286
- return { x: this._x, y: this._y }
287
- }
288
-
289
- override getChildren(): SxClass[] {
290
- return []
291
- }
292
-
293
- override getString(): string {
294
- return `(${this.token} ${this._x} ${this._y})`
295
- }
296
- }
297
-
298
- export class SymbolRectangleStart extends SymbolPointBase {
299
- static override token = "start"
300
- static override parentToken = "rectangle"
301
- token = "start"
302
- }
303
- SxClass.register(SymbolRectangleStart)
304
-
305
- export class SymbolRectangleEnd extends SymbolPointBase {
306
- static override token = "end"
307
- static override parentToken = "rectangle"
308
- token = "end"
309
- }
310
- SxClass.register(SymbolRectangleEnd)
311
-
312
- export class SymbolArcStart extends SymbolPointBase {
313
- static override token = "start"
314
- static override parentToken = "arc"
315
- token = "start"
316
- }
317
- SxClass.register(SymbolArcStart)
318
-
319
- export class SymbolArcMid extends SymbolPointBase {
320
- static override token = "mid"
321
- static override parentToken = "arc"
322
- token = "mid"
323
- }
324
- SxClass.register(SymbolArcMid)
325
-
326
- export class SymbolArcEnd extends SymbolPointBase {
327
- static override token = "end"
328
- static override parentToken = "arc"
329
- token = "end"
330
- }
331
- SxClass.register(SymbolArcEnd)
332
-
333
- export class SymbolCircleCenter extends SymbolPointBase {
334
- static override token = "center"
335
- static override parentToken = "circle"
336
- token = "center"
337
- }
338
- SxClass.register(SymbolCircleCenter)
339
-
340
- export class SymbolCircleRadius extends SxPrimitiveNumber {
341
- static override token = "radius"
342
- static override parentToken = "circle"
343
- token = "radius"
344
- }
345
- SxClass.register(SymbolCircleRadius)
346
-
347
- abstract class SymbolFillBase extends SxClass {
348
- protected _sxType?: SymbolFillType
349
-
350
- static override fromSexprPrimitives(
351
- primitiveSexprs: PrimitiveSExpr[],
352
- ): SymbolFillBase {
353
- const fill = new (this as unknown as new () => SymbolFillBase)()
354
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
355
- primitiveSexprs,
356
- "fill",
357
- )
358
- fill._sxType = propertyMap.type as SymbolFillType
359
- return fill
360
- }
361
-
362
- get type(): string | undefined {
363
- return this._sxType?.value
364
- }
365
-
366
- set type(value: string | undefined) {
367
- if (value === undefined) {
368
- this._sxType = undefined
369
- return
370
- }
371
- this._sxType = new SymbolFillType(value)
372
- }
373
-
374
- override getChildren(): SxClass[] {
375
- return this._sxType ? [this._sxType] : []
376
- }
377
- }
378
-
379
- export class SymbolPolylineFill extends SymbolFillBase {
380
- static override token = "fill"
381
- static override parentToken = "polyline"
382
- token = "fill"
383
- }
384
- SxClass.register(SymbolPolylineFill)
385
-
386
- export class SymbolRectangleFill extends SymbolFillBase {
387
- static override token = "fill"
388
- static override parentToken = "rectangle"
389
- token = "fill"
390
- }
391
- SxClass.register(SymbolRectangleFill)
392
-
393
- export class SymbolCircleFill extends SymbolFillBase {
394
- static override token = "fill"
395
- static override parentToken = "circle"
396
- token = "fill"
397
- }
398
- SxClass.register(SymbolCircleFill)
399
-
400
- export class SymbolArcFill extends SymbolFillBase {
401
- static override token = "fill"
402
- static override parentToken = "arc"
403
- token = "fill"
404
- }
405
- SxClass.register(SymbolArcFill)
406
-
407
- export class SymbolFillType extends SxClass {
408
- static override token = "type"
409
- static override parentToken = "fill"
410
- token = "type"
411
-
412
- value: string
413
-
414
- constructor(value: string) {
415
- super()
416
- this.value = value
417
- }
418
-
419
- static override fromSexprPrimitives(
420
- primitiveSexprs: PrimitiveSExpr[],
421
- ): SymbolFillType {
422
- const [valuePrimitive] = primitiveSexprs
423
- const value = toStringValue(valuePrimitive)
424
- if (value === undefined) {
425
- throw new Error("fill type expects a string value")
426
- }
427
- return new SymbolFillType(value)
428
- }
429
-
430
- override getChildren(): SxClass[] {
431
- return []
432
- }
433
-
434
- override getString(): string {
435
- return `(type ${this.value})`
436
- }
437
- }
438
- SxClass.register(SymbolFillType)
439
-
440
- export class SymbolPolyline extends SxClass {
441
- static override token = "polyline"
442
- static override parentToken = "symbol"
443
- token = "polyline"
444
-
445
- private _sxPts?: Pts
446
- private _sxStroke?: Stroke
447
- private _sxFill?: SymbolPolylineFill
448
-
449
- static override fromSexprPrimitives(
450
- primitiveSexprs: PrimitiveSExpr[],
451
- ): SymbolPolyline {
452
- const polyline = new SymbolPolyline()
453
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
454
- primitiveSexprs,
455
- this.token,
456
- )
457
-
458
- polyline._sxPts = propertyMap.pts as Pts
459
- polyline._sxStroke = propertyMap.stroke as Stroke
460
- polyline._sxFill = propertyMap.fill as SymbolPolylineFill
461
-
462
- return polyline
463
- }
464
-
465
- get points(): Pts | undefined {
466
- return this._sxPts
467
- }
468
-
469
- set points(value: Pts | undefined) {
470
- this._sxPts = value
471
- }
472
-
473
- get stroke(): Stroke | undefined {
474
- return this._sxStroke
475
- }
476
-
477
- set stroke(value: Stroke | undefined) {
478
- this._sxStroke = value
479
- }
480
-
481
- get fill(): SymbolPolylineFill | undefined {
482
- return this._sxFill
483
- }
484
-
485
- set fill(value: SymbolPolylineFill | undefined) {
486
- this._sxFill = value
487
- }
488
-
489
- override getChildren(): SxClass[] {
490
- const children: SxClass[] = []
491
- if (this._sxPts) children.push(this._sxPts)
492
- if (this._sxStroke) children.push(this._sxStroke)
493
- if (this._sxFill) children.push(this._sxFill)
494
- return children
495
- }
496
- }
497
- SxClass.register(SymbolPolyline)
498
-
499
- export class SymbolRectangle extends SxClass {
500
- static override token = "rectangle"
501
- static override parentToken = "symbol"
502
- token = "rectangle"
503
-
504
- private _sxStart?: SymbolRectangleStart
505
- private _sxEnd?: SymbolRectangleEnd
506
- private _sxStroke?: Stroke
507
- private _sxFill?: SymbolRectangleFill
508
-
509
- static override fromSexprPrimitives(
510
- primitiveSexprs: PrimitiveSExpr[],
511
- ): SymbolRectangle {
512
- const rectangle = new SymbolRectangle()
513
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
514
- primitiveSexprs,
515
- this.token,
516
- )
517
-
518
- rectangle._sxStart = propertyMap.start as SymbolRectangleStart
519
- rectangle._sxEnd = propertyMap.end as SymbolRectangleEnd
520
- rectangle._sxStroke = propertyMap.stroke as Stroke
521
- rectangle._sxFill = propertyMap.fill as SymbolRectangleFill
522
-
523
- return rectangle
524
- }
525
-
526
- override getChildren(): SxClass[] {
527
- const children: SxClass[] = []
528
- if (this._sxStart) children.push(this._sxStart)
529
- if (this._sxEnd) children.push(this._sxEnd)
530
- if (this._sxStroke) children.push(this._sxStroke)
531
- if (this._sxFill) children.push(this._sxFill)
532
- return children
533
- }
534
- }
535
- SxClass.register(SymbolRectangle)
536
-
537
- export class SymbolCircle extends SxClass {
538
- static override token = "circle"
539
- static override parentToken = "symbol"
540
- token = "circle"
541
-
542
- private _sxCenter?: SymbolCircleCenter
543
- private _sxRadius?: SymbolCircleRadius
544
- private _sxStroke?: Stroke
545
- private _sxFill?: SymbolCircleFill
546
-
547
- static override fromSexprPrimitives(
548
- primitiveSexprs: PrimitiveSExpr[],
549
- ): SymbolCircle {
550
- const circle = new SymbolCircle()
551
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
552
- primitiveSexprs,
553
- this.token,
554
- )
555
-
556
- circle._sxCenter = propertyMap.center as SymbolCircleCenter
557
- circle._sxRadius = propertyMap.radius as SymbolCircleRadius
558
- circle._sxStroke = propertyMap.stroke as Stroke
559
- circle._sxFill = propertyMap.fill as SymbolCircleFill
560
-
561
- return circle
562
- }
563
-
564
- override getChildren(): SxClass[] {
565
- const children: SxClass[] = []
566
- if (this._sxCenter) children.push(this._sxCenter)
567
- if (this._sxRadius) children.push(this._sxRadius)
568
- if (this._sxStroke) children.push(this._sxStroke)
569
- if (this._sxFill) children.push(this._sxFill)
570
- return children
571
- }
572
- }
573
- SxClass.register(SymbolCircle)
574
-
575
- export class SymbolArc extends SxClass {
576
- static override token = "arc"
577
- static override parentToken = "symbol"
578
- token = "arc"
579
-
580
- private _sxStart?: SymbolArcStart
581
- private _sxMid?: SymbolArcMid
582
- private _sxEnd?: SymbolArcEnd
583
- private _sxStroke?: Stroke
584
- private _sxFill?: SymbolArcFill
585
-
586
- static override fromSexprPrimitives(
587
- primitiveSexprs: PrimitiveSExpr[],
588
- ): SymbolArc {
589
- const arc = new SymbolArc()
590
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
591
- primitiveSexprs,
592
- this.token,
593
- )
594
-
595
- arc._sxStart = propertyMap.start as SymbolArcStart
596
- arc._sxMid = propertyMap.mid as SymbolArcMid
597
- arc._sxEnd = propertyMap.end as SymbolArcEnd
598
- arc._sxStroke = propertyMap.stroke as Stroke
599
- arc._sxFill = propertyMap.fill as SymbolArcFill
600
-
601
- return arc
602
- }
603
-
604
- override getChildren(): SxClass[] {
605
- const children: SxClass[] = []
606
- if (this._sxStart) children.push(this._sxStart)
607
- if (this._sxMid) children.push(this._sxMid)
608
- if (this._sxEnd) children.push(this._sxEnd)
609
- if (this._sxStroke) children.push(this._sxStroke)
610
- if (this._sxFill) children.push(this._sxFill)
611
- return children
612
- }
613
- }
614
- SxClass.register(SymbolArc)
615
-
616
- export class SymbolText extends SxClass {
617
- static override token = "text"
618
- static override parentToken = "symbol"
619
- token = "text"
620
-
621
- private _value = ""
622
- private _sxAt?: At
623
- private _sxEffects?: TextEffects
624
-
625
- static override fromSexprPrimitives(
626
- primitiveSexprs: PrimitiveSExpr[],
627
- ): SymbolText {
628
- const [valuePrimitive, ...rest] = primitiveSexprs
629
- const value = toStringValue(valuePrimitive)
630
- if (value === undefined) {
631
- throw new Error("text expects a string value")
632
- }
633
-
634
- const text = new SymbolText()
635
- text._value = value
636
-
637
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
638
- rest,
639
- this.token,
640
- )
641
-
642
- text._sxAt = propertyMap.at as At
643
- text._sxEffects = propertyMap.effects as TextEffects
644
-
645
- return text
646
- }
647
-
648
- get value(): string {
649
- return this._value
650
- }
651
-
652
- set value(newValue: string) {
653
- this._value = newValue
654
- }
655
-
656
- get at(): At | undefined {
657
- return this._sxAt
658
- }
659
-
660
- set at(value: AtInput | undefined) {
661
- this._sxAt = value !== undefined ? At.from(value) : undefined
662
- }
663
-
664
- get effects(): TextEffects | undefined {
665
- return this._sxEffects
666
- }
667
-
668
- set effects(value: TextEffects | undefined) {
669
- this._sxEffects = value
670
- }
671
-
672
- override getChildren(): SxClass[] {
673
- const children: SxClass[] = []
674
- if (this._sxAt) children.push(this._sxAt)
675
- if (this._sxEffects) children.push(this._sxEffects)
676
- return children
677
- }
678
-
679
- override getString(): string {
680
- const lines = [`(text ${quoteSExprString(this._value)}`]
681
- for (const child of this.getChildren()) {
682
- lines.push(child.getStringIndented())
683
- }
684
- lines.push(")")
685
- return lines.join("\n")
686
- }
687
- }
688
- SxClass.register(SymbolText)
689
-
690
- export class SymbolPower extends SxClass {
691
- static override token = "power"
692
- static override parentToken = "symbol"
693
- token = "power"
694
-
695
- static override fromSexprPrimitives(): SymbolPower {
696
- return new SymbolPower()
697
- }
698
-
699
- override getChildren(): SxClass[] {
700
- return []
701
- }
702
-
703
- override getString(): string {
704
- return "(power)"
705
- }
706
- }
707
- SxClass.register(SymbolPower)
708
-
709
- export interface SchematicSymbolConstructorParams {
710
- libraryId?: string
711
- at?: AtInput
712
- unit?: number | SymbolUnit
713
- pinNumbers?: SymbolPinNumbers
714
- pinNames?: SymbolPinNames
715
- excludeFromSim?: boolean
716
- inBom?: boolean
717
- onBoard?: boolean
718
- dnp?: boolean
719
- uuid?: string
720
- duplicatePinNumbersAreJumpers?: boolean
721
- fieldsAutoplaced?: boolean
722
- properties?: SymbolProperty[]
723
- pins?: SymbolPin[]
724
- subSymbols?: SchematicSymbol[]
725
- polylines?: SymbolPolyline[]
726
- rectangles?: SymbolRectangle[]
727
- circles?: SymbolCircle[]
728
- arcs?: SymbolArc[]
729
- texts?: SymbolText[]
730
- embeddedFonts?: EmbeddedFonts
731
- instances?: SymbolInstances
732
- }
733
-
734
- export class SchematicSymbol extends SxClass {
735
- static override token = "symbol"
736
- token = "symbol"
737
-
738
- private _sxLibId?: SymbolLibId
739
- _sxAt?: At
740
- _sxUnit?: SymbolUnit
741
- _sxPinNumbers?: SymbolPinNumbers
742
- _sxPinNames?: SymbolPinNames
743
- _sxExcludeFromSim?: ExcludeFromSim
744
- _sxInBom?: InBom
745
- _sxOnBoard?: OnBoard
746
- _sxDnp?: Dnp
747
- _sxUuid?: Uuid
748
- _sxDuplicatePinNumbersAreJumpers?: SymbolDuplicatePinNumbersAreJumpers
749
- _sxFieldsAutoplaced?: FieldsAutoplaced
750
- properties: SymbolProperty[] = []
751
- pins: SymbolPin[] = []
752
- subSymbols: SchematicSymbol[] = []
753
- polylines: SymbolPolyline[] = []
754
- rectangles: SymbolRectangle[] = []
755
- circles: SymbolCircle[] = []
756
- arcs: SymbolArc[] = []
757
- texts: SymbolText[] = []
758
- _sxPower?: SymbolPower
759
- _sxEmbeddedFonts?: EmbeddedFonts
760
- _sxInstances?: SymbolInstances
761
- private _inlineLibId?: string
762
-
763
- constructor(params: SchematicSymbolConstructorParams = {}) {
764
- super()
765
-
766
- if (params.libraryId !== undefined) this.libraryId = params.libraryId
767
- if (params.at !== undefined) this.at = params.at
768
- if (params.unit !== undefined)
769
- this.unit =
770
- typeof params.unit === "number" ? params.unit : params.unit.value
771
- if (params.pinNumbers !== undefined) this.pinNumbers = params.pinNumbers
772
- if (params.pinNames !== undefined) this.pinNames = params.pinNames
773
- if (params.excludeFromSim !== undefined)
774
- this.excludeFromSim = params.excludeFromSim
775
- if (params.inBom !== undefined) this.inBom = params.inBom
776
- if (params.onBoard !== undefined) this.onBoard = params.onBoard
777
- if (params.dnp !== undefined) this.dnp = params.dnp
778
- if (params.uuid !== undefined) this.uuid = params.uuid
779
- if (params.duplicatePinNumbersAreJumpers !== undefined)
780
- this.duplicatePinNumbersAreJumpers = params.duplicatePinNumbersAreJumpers
781
- if (params.fieldsAutoplaced !== undefined)
782
- this.fieldsAutoplaced = params.fieldsAutoplaced
783
- if (params.properties !== undefined) this.properties = params.properties
784
- if (params.pins !== undefined) this.pins = params.pins
785
- if (params.subSymbols !== undefined) this.subSymbols = params.subSymbols
786
- if (params.polylines !== undefined) this.polylines = params.polylines
787
- if (params.rectangles !== undefined) this.rectangles = params.rectangles
788
- if (params.circles !== undefined) this.circles = params.circles
789
- if (params.arcs !== undefined) this.arcs = params.arcs
790
- if (params.texts !== undefined) this.texts = params.texts
791
- if (params.embeddedFonts !== undefined)
792
- this._sxEmbeddedFonts = params.embeddedFonts
793
- if (params.instances !== undefined) this.instances = params.instances
794
- }
795
-
796
- get libraryId(): string | undefined {
797
- return this._sxLibId?.value ?? this._inlineLibId
798
- }
799
-
800
- set libraryId(value: string | undefined) {
801
- if (value === undefined || value === "") {
802
- this._inlineLibId = undefined
803
- if (this._sxLibId) {
804
- this._sxLibId = undefined
805
- }
806
- return
807
- }
808
- this._inlineLibId = value
809
- this._sxLibId = undefined
810
- }
811
-
812
- get at(): At | undefined {
813
- return this._sxAt
814
- }
815
-
816
- set at(value: AtInput | undefined) {
817
- this._sxAt = value !== undefined ? At.from(value) : undefined
818
- }
819
-
820
- get unit(): number | undefined {
821
- return this._sxUnit?.value
822
- }
823
-
824
- set unit(value: number | undefined) {
825
- this._sxUnit = value === undefined ? undefined : SymbolUnit.from(value)
826
- }
827
-
828
- get pinNumbers(): SymbolPinNumbers | undefined {
829
- return this._sxPinNumbers
830
- }
831
-
832
- set pinNumbers(value: SymbolPinNumbers | undefined) {
833
- this._sxPinNumbers = value
834
- }
835
-
836
- get pinNames(): SymbolPinNames | undefined {
837
- return this._sxPinNames
838
- }
839
-
840
- set pinNames(value: SymbolPinNames | undefined) {
841
- this._sxPinNames = value
842
- }
843
-
844
- get inBom(): boolean | undefined {
845
- return this._sxInBom?.value
846
- }
847
-
848
- set inBom(value: boolean | undefined) {
849
- this._sxInBom = value === undefined ? undefined : new InBom(value)
850
- }
851
-
852
- get excludeFromSim(): boolean {
853
- return this._sxExcludeFromSim?.value ?? false
854
- }
855
-
856
- set excludeFromSim(value: boolean) {
857
- this._sxExcludeFromSim = new ExcludeFromSim(value)
858
- }
859
-
860
- get onBoard(): boolean | undefined {
861
- return this._sxOnBoard?.value
862
- }
863
-
864
- set onBoard(value: boolean | undefined) {
865
- this._sxOnBoard = value === undefined ? undefined : new OnBoard(value)
866
- }
867
-
868
- get dnp(): boolean {
869
- return this._sxDnp?.value ?? false
870
- }
871
-
872
- set dnp(value: boolean) {
873
- this._sxDnp = new Dnp(value)
874
- }
875
-
876
- get fieldsAutoplaced(): boolean {
877
- return this._sxFieldsAutoplaced?.value ?? false
878
- }
879
-
880
- set fieldsAutoplaced(value: boolean) {
881
- this._sxFieldsAutoplaced = new FieldsAutoplaced(value)
882
- }
883
-
884
- get uuid(): string | undefined {
885
- return this._sxUuid?.value
886
- }
887
-
888
- set uuid(value: string | undefined) {
889
- this._sxUuid = value === undefined ? undefined : new Uuid(value)
890
- }
891
-
892
- get duplicatePinNumbersAreJumpers(): boolean {
893
- return this._sxDuplicatePinNumbersAreJumpers?.value ?? false
894
- }
895
-
896
- set duplicatePinNumbersAreJumpers(value: boolean | undefined) {
897
- if (value === undefined) {
898
- this._sxDuplicatePinNumbersAreJumpers = undefined
899
- return
900
- }
901
- this._sxDuplicatePinNumbersAreJumpers =
902
- new SymbolDuplicatePinNumbersAreJumpers(value)
903
- }
904
-
905
- get instances(): SymbolInstances | undefined {
906
- return this._sxInstances
907
- }
908
-
909
- set instances(value: SymbolInstances | undefined) {
910
- this._sxInstances = value
911
- }
912
-
913
- static override fromSexprPrimitives(
914
- primitiveSexprs: PrimitiveSExpr[],
915
- ): SchematicSymbol {
916
- const symbol = new SchematicSymbol()
917
-
918
- let remaining = primitiveSexprs
919
- let inlineId: string | undefined
920
- if (remaining.length > 0) {
921
- const first = remaining[0]
922
- inlineId = toStringValue(first)
923
- if (inlineId !== undefined) {
924
- symbol._inlineLibId = inlineId
925
- remaining = remaining.slice(1)
926
- }
927
- }
928
-
929
- const { propertyMap, arrayPropertyMap } =
930
- SxClass.parsePrimitivesToClassProperties(remaining, this.token)
931
-
932
- const libIdClass = propertyMap.lib_id as SymbolLibId | undefined
933
- if (libIdClass) {
934
- symbol._sxLibId = libIdClass
935
- } else if (inlineId !== undefined) {
936
- symbol._inlineLibId = inlineId
937
- }
938
- symbol._sxAt = propertyMap.at as At
939
- symbol._sxUnit = propertyMap.unit as SymbolUnit
940
- symbol._sxPinNumbers = propertyMap.pin_numbers as SymbolPinNumbers
941
- symbol._sxPinNames = propertyMap.pin_names as SymbolPinNames
942
- symbol._sxExcludeFromSim = propertyMap.exclude_from_sim as ExcludeFromSim
943
- symbol._sxInBom = propertyMap.in_bom as InBom
944
- symbol._sxOnBoard = propertyMap.on_board as OnBoard
945
- symbol._sxDnp = propertyMap.dnp as Dnp
946
- symbol._sxUuid = propertyMap.uuid as Uuid
947
- symbol._sxDuplicatePinNumbersAreJumpers =
948
- propertyMap.duplicate_pin_numbers_are_jumpers as SymbolDuplicatePinNumbersAreJumpers
949
- symbol._sxFieldsAutoplaced =
950
- propertyMap.fields_autoplaced as FieldsAutoplaced
951
- symbol._sxPower = propertyMap.power as SymbolPower
952
- symbol._sxEmbeddedFonts = propertyMap.embedded_fonts as EmbeddedFonts
953
- symbol.properties = (arrayPropertyMap.property as SymbolProperty[]) ?? []
954
- symbol.pins = (arrayPropertyMap.pin as SymbolPin[]) ?? []
955
- symbol.subSymbols = (arrayPropertyMap.symbol as SchematicSymbol[]) ?? []
956
- symbol.polylines = (arrayPropertyMap.polyline as SymbolPolyline[]) ?? []
957
- symbol.rectangles = (arrayPropertyMap.rectangle as SymbolRectangle[]) ?? []
958
- symbol.circles = (arrayPropertyMap.circle as SymbolCircle[]) ?? []
959
- symbol.arcs = (arrayPropertyMap.arc as SymbolArc[]) ?? []
960
- symbol.texts = (arrayPropertyMap.text as SymbolText[]) ?? []
961
- symbol._sxInstances = propertyMap.instances as SymbolInstances
962
-
963
- return symbol
964
- }
965
-
966
- override getChildren(): SxClass[] {
967
- const children: SxClass[] = []
968
- if (this._sxLibId) children.push(this._sxLibId)
969
- if (this._sxAt) children.push(this._sxAt)
970
- if (this._sxUnit) children.push(this._sxUnit)
971
- if (this._sxPinNumbers) children.push(this._sxPinNumbers)
972
- if (this._sxPinNames) children.push(this._sxPinNames)
973
- if (this._sxExcludeFromSim) children.push(this._sxExcludeFromSim)
974
- if (this._sxInBom) children.push(this._sxInBom)
975
- if (this._sxOnBoard) children.push(this._sxOnBoard)
976
- if (this._sxDnp) children.push(this._sxDnp)
977
- if (this._sxUuid) children.push(this._sxUuid)
978
- if (this._sxDuplicatePinNumbersAreJumpers) {
979
- children.push(this._sxDuplicatePinNumbersAreJumpers)
980
- }
981
- if (this._sxFieldsAutoplaced) children.push(this._sxFieldsAutoplaced)
982
- children.push(...this.properties)
983
- children.push(...this.pins)
984
- children.push(...this.subSymbols)
985
- children.push(...this.polylines)
986
- children.push(...this.rectangles)
987
- children.push(...this.circles)
988
- children.push(...this.arcs)
989
- children.push(...this.texts)
990
- if (this._sxPower) children.push(this._sxPower)
991
- if (this._sxEmbeddedFonts) children.push(this._sxEmbeddedFonts)
992
- if (this._sxInstances) children.push(this._sxInstances)
993
- return children
994
- }
995
-
996
- override getString() {
997
- const inlineLibId = this._sxLibId ? undefined : this.libraryId
998
- const lines =
999
- inlineLibId !== undefined && inlineLibId !== ""
1000
- ? [`(symbol ${quoteSExprString(inlineLibId)}`]
1001
- : ["(symbol"]
1002
-
1003
- for (const child of this.getChildren()) {
1004
- lines.push(child.getStringIndented())
1005
- }
1006
-
1007
- lines.push(")")
1008
- return lines.join("\n")
1009
- }
1010
- }
1011
- SxClass.register(SchematicSymbol)
1012
-
1013
- export class SymbolPropertyId extends SxPrimitiveNumber {
1014
- static override token = "id"
1015
- static override parentToken = "property"
1016
- token = "id"
1017
-
1018
- static from(value: number | SymbolPropertyId): SymbolPropertyId {
1019
- if (value instanceof SymbolPropertyId) {
1020
- return value
1021
- }
1022
- return new SymbolPropertyId(value)
1023
- }
1024
- }
1025
- SxClass.register(SymbolPropertyId)
1026
-
1027
- export class SymbolProperty extends SxClass {
1028
- static override token = "property"
1029
- static override parentToken = "symbol"
1030
- token = "property"
1031
-
1032
- key: string
1033
- value: string
1034
- _sxId?: SymbolPropertyId
1035
- _sxAt?: At
1036
- _sxEffects?: TextEffects
1037
-
1038
- constructor(params: {
1039
- key: string
1040
- value: string
1041
- id?: number | SymbolPropertyId
1042
- at?: AtInput
1043
- effects?: TextEffects
1044
- }) {
1045
- super()
1046
- this.key = params.key
1047
- this.value = params.value
1048
- this._sxId =
1049
- params.id !== undefined ? SymbolPropertyId.from(params.id) : undefined
1050
- this._sxAt = params.at !== undefined ? At.from(params.at) : undefined
1051
- this._sxEffects = params.effects
1052
- }
1053
-
1054
- static override fromSexprPrimitives(
1055
- primitiveSexprs: PrimitiveSExpr[],
1056
- ): SymbolProperty {
1057
- const [inputKey, inputValue, ...rest] = primitiveSexprs
1058
-
1059
- const key = toStringValue(inputKey) ?? ""
1060
- const value = toStringValue(inputValue) ?? ""
1061
-
1062
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
1063
- rest,
1064
- this.token,
1065
- )
1066
-
1067
- return new SymbolProperty({
1068
- key,
1069
- value,
1070
- id: propertyMap.id as SymbolPropertyId,
1071
- at: propertyMap.at as At,
1072
- effects: propertyMap.effects as TextEffects,
1073
- })
1074
- }
1075
-
1076
- get id(): number | undefined {
1077
- return this._sxId?.value
1078
- }
1079
-
1080
- set id(value: number | undefined) {
1081
- this._sxId = value === undefined ? undefined : SymbolPropertyId.from(value)
1082
- }
1083
-
1084
- get at(): At | undefined {
1085
- return this._sxAt
1086
- }
1087
-
1088
- set at(value: AtInput | undefined) {
1089
- this._sxAt = value !== undefined ? At.from(value) : undefined
1090
- }
1091
-
1092
- get effects(): TextEffects | undefined {
1093
- return this._sxEffects
1094
- }
1095
-
1096
- set effects(value: TextEffects | undefined) {
1097
- this._sxEffects = value
1098
- }
1099
-
1100
- override getChildren(): SxClass[] {
1101
- const children: SxClass[] = []
1102
- if (this._sxId) children.push(this._sxId)
1103
- if (this._sxAt) children.push(this._sxAt)
1104
- if (this._sxEffects) children.push(this._sxEffects)
1105
- return children
1106
- }
1107
-
1108
- override getString() {
1109
- const lines = [
1110
- `(property ${quoteSExprString(this.key)} ${quoteSExprString(this.value)}`,
1111
- ]
1112
-
1113
- if (this._sxId) {
1114
- lines.push(...indentLines(this._sxId.getString()))
1115
- }
1116
- if (this._sxAt) {
1117
- lines.push(...indentLines(this._sxAt.getString()))
1118
- }
1119
- if (this._sxEffects) {
1120
- lines.push(...indentLines(this._sxEffects.getString()))
1121
- }
1122
-
1123
- lines.push(")")
1124
- return lines.join("\n")
1125
- }
1126
- }
1127
- SxClass.register(SymbolProperty)
1128
-
1129
- type PinElectricalType =
1130
- | "input"
1131
- | "output"
1132
- | "bidirectional"
1133
- | "tri_state"
1134
- | "passive"
1135
- | "free"
1136
- | "unspecified"
1137
- | "power_in"
1138
- | "power_out"
1139
- | "open_collector"
1140
- | "open_emitter"
1141
- | "no_connect"
1142
-
1143
- type PinGraphicStyle =
1144
- | "line"
1145
- | "inverted"
1146
- | "clock"
1147
- | "inverted_clock"
1148
- | "input_low"
1149
- | "clock_low"
1150
- | "output_low"
1151
- | "edge_clock_high"
1152
- | "non_logic"
1153
-
1154
- const electricalTypeSet = new Set<PinElectricalType>([
1155
- "input",
1156
- "output",
1157
- "bidirectional",
1158
- "tri_state",
1159
- "passive",
1160
- "free",
1161
- "unspecified",
1162
- "power_in",
1163
- "power_out",
1164
- "open_collector",
1165
- "open_emitter",
1166
- "no_connect",
1167
- ])
1168
- const graphicStyleSet = new Set<PinGraphicStyle>([
1169
- "line",
1170
- "inverted",
1171
- "clock",
1172
- "inverted_clock",
1173
- "input_low",
1174
- "clock_low",
1175
- "output_low",
1176
- "edge_clock_high",
1177
- "non_logic",
1178
- ])
1179
-
1180
- export class SymbolPinLength extends SxPrimitiveNumber {
1181
- static override token = "length"
1182
- static override parentToken = "pin"
1183
- token = "length"
1184
- }
1185
- SxClass.register(SymbolPinLength)
1186
-
1187
- export class SymbolPinName extends SxClass {
1188
- static override token = "name"
1189
- static override parentToken = "pin"
1190
- token = "name"
1191
-
1192
- value: string
1193
- _sxEffects?: TextEffects
1194
-
1195
- constructor(params: { value: string; effects?: TextEffects }) {
1196
- super()
1197
- this.value = params.value
1198
- this._sxEffects = params.effects
1199
- }
1200
-
1201
- static override fromSexprPrimitives(
1202
- primitiveSexprs: PrimitiveSExpr[],
1203
- ): SymbolPinName {
1204
- const [valuePrimitive, ...rest] = primitiveSexprs
1205
- const value = toStringValue(valuePrimitive) ?? ""
1206
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
1207
- rest,
1208
- this.token,
1209
- )
1210
-
1211
- return new SymbolPinName({
1212
- value,
1213
- effects: propertyMap.effects as TextEffects,
1214
- })
1215
- }
1216
-
1217
- get effects(): TextEffects | undefined {
1218
- return this._sxEffects
1219
- }
1220
-
1221
- set effects(value: TextEffects | undefined) {
1222
- this._sxEffects = value
1223
- }
1224
-
1225
- override getChildren(): SxClass[] {
1226
- return this._sxEffects ? [this._sxEffects] : []
1227
- }
1228
-
1229
- override getString(): string {
1230
- const lines = [`(name ${quoteSExprString(this.value)}`]
1231
- if (this._sxEffects) {
1232
- lines.push(...indentLines(this._sxEffects.getString()))
1233
- }
1234
- lines.push(")")
1235
- return lines.join("\n")
1236
- }
1237
- }
1238
- SxClass.register(SymbolPinName)
1239
-
1240
- export class SymbolPinNumber extends SxClass {
1241
- static override token = "number"
1242
- static override parentToken = "pin"
1243
- token = "number"
1244
-
1245
- value: string
1246
- _sxEffects?: TextEffects
1247
-
1248
- constructor(params: { value: string; effects?: TextEffects }) {
1249
- super()
1250
- this.value = params.value
1251
- this._sxEffects = params.effects
1252
- }
1253
-
1254
- static override fromSexprPrimitives(
1255
- primitiveSexprs: PrimitiveSExpr[],
1256
- ): SymbolPinNumber {
1257
- const [valuePrimitive, ...rest] = primitiveSexprs
1258
- const value = toStringValue(valuePrimitive) ?? ""
1259
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
1260
- rest,
1261
- this.token,
1262
- )
1263
-
1264
- return new SymbolPinNumber({
1265
- value,
1266
- effects: propertyMap.effects as TextEffects,
1267
- })
1268
- }
1269
-
1270
- get effects(): TextEffects | undefined {
1271
- return this._sxEffects
1272
- }
1273
-
1274
- set effects(value: TextEffects | undefined) {
1275
- this._sxEffects = value
1276
- }
1277
-
1278
- override getChildren(): SxClass[] {
1279
- return this._sxEffects ? [this._sxEffects] : []
1280
- }
1281
-
1282
- override getString(): string {
1283
- const lines = [`(number ${quoteSExprString(this.value)}`]
1284
- if (this._sxEffects) {
1285
- lines.push(...indentLines(this._sxEffects.getString()))
1286
- }
1287
- lines.push(")")
1288
- return lines.join("\n")
1289
- }
1290
- }
1291
- SxClass.register(SymbolPinNumber)
1292
-
1293
- export class SymbolPin extends SxClass {
1294
- static override token = "pin"
1295
- static override parentToken = "symbol"
1296
- token = "pin"
1297
-
1298
- pinElectricalType?: PinElectricalType
1299
- pinGraphicStyle?: PinGraphicStyle
1300
- _sxAt?: At
1301
- _sxLength?: SymbolPinLength
1302
- _sxName?: SymbolPinName
1303
- _sxNumber?: SymbolPinNumber
1304
- _sxUuid?: Uuid
1305
- private inlineNumber?: string
1306
- private _sxHide?: SymbolPinHide
1307
-
1308
- static override fromSexprPrimitives(args: PrimitiveSExpr[]): SymbolPin {
1309
- const symbolPin = new SymbolPin()
1310
-
1311
- let index = 0
1312
- const first = args[0]
1313
- const firstString = toStringValue(first)
1314
-
1315
- if (
1316
- firstString &&
1317
- electricalTypeSet.has(firstString as PinElectricalType)
1318
- ) {
1319
- symbolPin.pinElectricalType = firstString as PinElectricalType
1320
- index = 1
1321
- const second = args[1]
1322
- const secondString = toStringValue(second)
1323
- if (
1324
- secondString &&
1325
- graphicStyleSet.has(secondString as PinGraphicStyle)
1326
- ) {
1327
- symbolPin.pinGraphicStyle = secondString as PinGraphicStyle
1328
- index = 2
1329
- }
1330
- } else if (firstString !== undefined && !Array.isArray(first)) {
1331
- symbolPin.inlineNumber = firstString
1332
- index = 1
1333
- }
1334
-
1335
- const remaining = args.slice(index)
1336
-
1337
- const primitiveStrings: string[] = []
1338
- const primitiveNodes: PrimitiveSExpr[] = []
1339
- for (const primitive of remaining) {
1340
- if (typeof primitive === "string") {
1341
- primitiveStrings.push(primitive)
1342
- continue
1343
- }
1344
- primitiveNodes.push(primitive)
1345
- }
1346
-
1347
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
1348
- primitiveNodes,
1349
- this.token,
1350
- )
1351
-
1352
- symbolPin._sxAt = propertyMap.at as At
1353
- symbolPin._sxLength = propertyMap.length as SymbolPinLength
1354
- symbolPin._sxName = propertyMap.name as SymbolPinName
1355
- symbolPin._sxNumber = propertyMap.number as SymbolPinNumber
1356
- symbolPin._sxUuid = propertyMap.uuid as Uuid
1357
- symbolPin._sxHide = propertyMap.hide as SymbolPinHide | undefined
1358
-
1359
- for (const flag of primitiveStrings) {
1360
- if (flag === "hide") {
1361
- symbolPin._sxHide = new SymbolPinHide(true, { inline: true })
1362
- continue
1363
- }
1364
- throw new Error(`symbol pin encountered unsupported flag "${flag}"`)
1365
- }
1366
-
1367
- return symbolPin
1368
- }
1369
-
1370
- get at(): At | undefined {
1371
- return this._sxAt
1372
- }
1373
-
1374
- set at(value: AtInput | undefined) {
1375
- this._sxAt = value !== undefined ? At.from(value) : undefined
1376
- }
1377
-
1378
- get length(): number | undefined {
1379
- return this._sxLength?.value
1380
- }
1381
-
1382
- set length(value: number | undefined) {
1383
- this._sxLength =
1384
- value === undefined ? undefined : new SymbolPinLength(value)
1385
- }
1386
-
1387
- get name(): string | undefined {
1388
- return this._sxName?.value
1389
- }
1390
-
1391
- set name(value: string | undefined) {
1392
- if (value === undefined) {
1393
- this._sxName = undefined
1394
- return
1395
- }
1396
- this._sxName = new SymbolPinName({ value })
1397
- }
1398
-
1399
- get numberString(): string | undefined {
1400
- return this._sxNumber?.value ?? this.inlineNumber
1401
- }
1402
-
1403
- set numberString(value: string | undefined) {
1404
- if (value === undefined) {
1405
- this._sxNumber = undefined
1406
- this.inlineNumber = undefined
1407
- return
1408
- }
1409
- this.inlineNumber = value
1410
- this._sxNumber = undefined
1411
- }
1412
-
1413
- get uuid(): string | undefined {
1414
- return this._sxUuid?.value
1415
- }
1416
-
1417
- set uuid(value: string | undefined) {
1418
- this._sxUuid = value === undefined ? undefined : new Uuid(value)
1419
- }
1420
-
1421
- get hidden(): boolean {
1422
- return this._sxHide?.value ?? false
1423
- }
1424
-
1425
- set hidden(value: boolean) {
1426
- this._sxHide = value ? new SymbolPinHide(value) : undefined
1427
- }
1428
-
1429
- override getChildren(): SxClass[] {
1430
- const children: SxClass[] = []
1431
- if (this._sxAt) children.push(this._sxAt)
1432
- if (this._sxLength) children.push(this._sxLength)
1433
- if (this._sxName) children.push(this._sxName)
1434
- if (this._sxNumber) children.push(this._sxNumber)
1435
- if (this._sxUuid) children.push(this._sxUuid)
1436
- if (this._sxHide) children.push(this._sxHide)
1437
- return children
1438
- }
1439
-
1440
- override getString() {
1441
- if (this.pinElectricalType) {
1442
- const headerParts = ["(pin", this.pinElectricalType]
1443
- if (this.pinGraphicStyle) {
1444
- headerParts.push(this.pinGraphicStyle)
1445
- }
1446
- const lines = [headerParts.join(" ")]
1447
- for (const child of this.getChildren()) {
1448
- lines.push(...indentLines(child.getString()))
1449
- }
1450
- lines.push(")")
1451
- return lines.join("\n")
1452
- }
1453
-
1454
- const number = this.numberString ?? ""
1455
- const lines = [`(pin ${quoteSExprString(number)}`]
1456
- if (this._sxUuid) {
1457
- lines.push(...indentLines(this._sxUuid.getString()))
1458
- }
1459
- lines.push(")")
1460
- return lines.join("\n")
1461
- }
1462
- }
1463
- SxClass.register(SymbolPin)
1464
-
1465
- export class SymbolInstances extends SxClass {
1466
- static override token = "instances"
1467
- static override parentToken = "symbol"
1468
- token = "instances"
1469
-
1470
- projects: SymbolInstancesProject[] = []
1471
-
1472
- static override fromSexprPrimitives(
1473
- primitiveSexprs: PrimitiveSExpr[],
1474
- ): SymbolInstances {
1475
- const symbolInstances = new SymbolInstances()
1476
- const { arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(
1477
- primitiveSexprs,
1478
- this.token,
1479
- )
1480
-
1481
- symbolInstances.projects =
1482
- (arrayPropertyMap.project as SymbolInstancesProject[]) ?? []
1483
-
1484
- return symbolInstances
1485
- }
1486
-
1487
- override getChildren(): SxClass[] {
1488
- return [...this.projects]
1489
- }
1490
-
1491
- override getString() {
1492
- const lines = ["(instances"]
1493
- for (const project of this.projects) {
1494
- lines.push(project.getStringIndented())
1495
- }
1496
- lines.push(")")
1497
- return lines.join("\n")
1498
- }
1499
- }
1500
- SxClass.register(SymbolInstances)
1501
-
1502
- class SymbolPinHide extends SxPrimitiveBoolean {
1503
- static override token = "hide"
1504
- static override parentToken = "pin"
1505
- token = "hide"
1506
-
1507
- private inline = false
1508
-
1509
- constructor(value?: boolean, options: { inline?: boolean } = {}) {
1510
- super(value ?? true)
1511
- this.inline = options.inline ?? false
1512
- }
1513
-
1514
- override getString(): string {
1515
- if (this.inline) {
1516
- return this.value ? "hide" : "(hide no)"
1517
- }
1518
- return this.value ? "(hide yes)" : "(hide no)"
1519
- }
1520
- }
1521
- SxClass.register(SymbolPinHide)
1522
-
1523
- export class SymbolInstancesProject extends SxClass {
1524
- static override token = "project"
1525
- static override parentToken = "instances"
1526
- token = "project"
1527
-
1528
- name: string
1529
- paths: SymbolInstancePath[] = []
1530
-
1531
- constructor(name: string) {
1532
- super()
1533
- this.name = name
1534
- }
1535
-
1536
- static override fromSexprPrimitives(
1537
- primitiveSexprs: PrimitiveSExpr[],
1538
- ): SymbolInstancesProject {
1539
- const [namePrimitive, ...rest] = primitiveSexprs
1540
- const name = toStringValue(namePrimitive) ?? ""
1541
- const project = new SymbolInstancesProject(name)
1542
-
1543
- const { arrayPropertyMap } = SxClass.parsePrimitivesToClassProperties(
1544
- rest,
1545
- this.token,
1546
- )
1547
-
1548
- project.paths = (arrayPropertyMap.path as SymbolInstancePath[]) ?? []
1549
-
1550
- return project
1551
- }
1552
-
1553
- override getChildren(): SxClass[] {
1554
- return [...this.paths]
1555
- }
1556
-
1557
- override getString() {
1558
- const lines = [`(project ${quoteSExprString(this.name)}`]
1559
- for (const path of this.paths) {
1560
- lines.push(path.getStringIndented())
1561
- }
1562
- lines.push(")")
1563
- return lines.join("\n")
1564
- }
1565
- }
1566
- SxClass.register(SymbolInstancesProject)
1567
-
1568
- export class SymbolInstancePath extends SxClass {
1569
- static override token = "path"
1570
- static override parentToken = "project"
1571
- token = "path"
1572
-
1573
- value: string
1574
- _sxReference?: SymbolInstanceReference
1575
- _sxUnit?: SymbolInstanceUnit
1576
-
1577
- constructor(value: string) {
1578
- super()
1579
- this.value = value
1580
- }
1581
-
1582
- static override fromSexprPrimitives(
1583
- primitiveSexprs: PrimitiveSExpr[],
1584
- ): SymbolInstancePath {
1585
- const [pathPrimitive, ...rest] = primitiveSexprs
1586
- const value = toStringValue(pathPrimitive) ?? ""
1587
- const path = new SymbolInstancePath(value)
1588
-
1589
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
1590
- rest,
1591
- this.token,
1592
- )
1593
-
1594
- path._sxReference = propertyMap.reference as SymbolInstanceReference
1595
- path._sxUnit = propertyMap.unit as SymbolInstanceUnit
1596
-
1597
- return path
1598
- }
1599
-
1600
- get reference(): string | undefined {
1601
- return this._sxReference?.value
1602
- }
1603
-
1604
- set reference(value: string | undefined) {
1605
- this._sxReference =
1606
- value === undefined ? undefined : new SymbolInstanceReference(value)
1607
- }
1608
-
1609
- get unit(): number | undefined {
1610
- return this._sxUnit?.value
1611
- }
1612
-
1613
- set unit(value: number | undefined) {
1614
- this._sxUnit =
1615
- value === undefined ? undefined : new SymbolInstanceUnit(value)
1616
- }
1617
-
1618
- override getChildren(): SxClass[] {
1619
- const children: SxClass[] = []
1620
- if (this._sxReference) children.push(this._sxReference)
1621
- if (this._sxUnit) children.push(this._sxUnit)
1622
- return children
1623
- }
1624
-
1625
- override getString() {
1626
- const lines = [`(path ${quoteSExprString(this.value)}`]
1627
- for (const child of this.getChildren()) {
1628
- lines.push(child.getStringIndented())
1629
- }
1630
- lines.push(")")
1631
- return lines.join("\n")
1632
- }
1633
- }
1634
- SxClass.register(SymbolInstancePath)
1635
-
1636
- export class SymbolInstanceReference extends SxClass {
1637
- static override token = "reference"
1638
- static override parentToken = "path"
1639
- token = "reference"
1640
-
1641
- value: string
1642
-
1643
- constructor(value: string) {
1644
- super()
1645
- this.value = value
1646
- }
1647
-
1648
- static override fromSexprPrimitives(
1649
- primitiveSexprs: PrimitiveSExpr[],
1650
- ): SymbolInstanceReference {
1651
- const [valuePrimitive] = primitiveSexprs
1652
- return new SymbolInstanceReference(toStringValue(valuePrimitive) ?? "")
1653
- }
1654
-
1655
- override getString(): string {
1656
- return `(reference ${quoteSExprString(this.value)})`
1657
- }
1658
- }
1659
- SxClass.register(SymbolInstanceReference)
1660
-
1661
- export class SymbolInstanceUnit extends SxPrimitiveNumber {
1662
- static override token = "unit"
1663
- static override parentToken = "path"
1664
- token = "unit"
1665
- }
1666
- SxClass.register(SymbolInstanceUnit)