kicadts 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4466 -0
- package/dist/index.js +14253 -0
- package/package.json +5 -2
- package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
- package/.github/workflows/bun-formatcheck.yml +0 -26
- package/.github/workflows/bun-pver-release.yml +0 -70
- package/.github/workflows/bun-test.yml +0 -32
- package/.github/workflows/bun-typecheck.yml +0 -26
- package/.vscode/settings.json +0 -16
- package/AGENTS.md +0 -31
- package/TODO.md +0 -46
- package/biome.json +0 -93
- package/bunfig.toml +0 -5
- package/lib/index.ts +0 -1
- package/lib/sexpr/base-classes/SxClass.ts +0 -164
- package/lib/sexpr/base-classes/SxPrimitiveBoolean.ts +0 -35
- package/lib/sexpr/base-classes/SxPrimitiveNumber.ts +0 -26
- package/lib/sexpr/base-classes/SxPrimitiveString.ts +0 -26
- package/lib/sexpr/classes/At.ts +0 -53
- package/lib/sexpr/classes/Bus.ts +0 -103
- package/lib/sexpr/classes/BusEntry.ts +0 -169
- package/lib/sexpr/classes/Color.ts +0 -29
- package/lib/sexpr/classes/Dnp.ts +0 -8
- package/lib/sexpr/classes/EmbeddedFonts.ts +0 -68
- package/lib/sexpr/classes/ExcludeFromSim.ts +0 -8
- package/lib/sexpr/classes/FieldsAutoplaced.ts +0 -8
- package/lib/sexpr/classes/Footprint.ts +0 -849
- package/lib/sexpr/classes/FootprintAttr.ts +0 -104
- package/lib/sexpr/classes/FootprintAutoplaceCost180.ts +0 -9
- package/lib/sexpr/classes/FootprintAutoplaceCost90.ts +0 -9
- package/lib/sexpr/classes/FootprintClearance.ts +0 -9
- package/lib/sexpr/classes/FootprintDescr.ts +0 -44
- package/lib/sexpr/classes/FootprintLocked.ts +0 -32
- package/lib/sexpr/classes/FootprintModel.ts +0 -142
- package/lib/sexpr/classes/FootprintNetTiePadGroups.ts +0 -52
- package/lib/sexpr/classes/FootprintPad.ts +0 -857
- package/lib/sexpr/classes/FootprintPath.ts +0 -44
- package/lib/sexpr/classes/FootprintPlaced.ts +0 -32
- package/lib/sexpr/classes/FootprintPrivateLayers.ts +0 -56
- package/lib/sexpr/classes/FootprintSheetfile.ts +0 -44
- package/lib/sexpr/classes/FootprintSheetname.ts +0 -44
- package/lib/sexpr/classes/FootprintSolderMaskMargin.ts +0 -9
- package/lib/sexpr/classes/FootprintSolderPasteMargin.ts +0 -9
- package/lib/sexpr/classes/FootprintSolderPasteRatio.ts +0 -9
- package/lib/sexpr/classes/FootprintTags.ts +0 -44
- package/lib/sexpr/classes/FootprintTedit.ts +0 -21
- package/lib/sexpr/classes/FootprintThermalGap.ts +0 -9
- package/lib/sexpr/classes/FootprintThermalWidth.ts +0 -9
- package/lib/sexpr/classes/FootprintZoneConnect.ts +0 -9
- package/lib/sexpr/classes/FpArc.ts +0 -312
- package/lib/sexpr/classes/FpCircle.ts +0 -314
- package/lib/sexpr/classes/FpLine.ts +0 -316
- package/lib/sexpr/classes/FpPoly.ts +0 -286
- package/lib/sexpr/classes/FpPolyFill.ts +0 -48
- package/lib/sexpr/classes/FpPolyLocked.ts +0 -40
- package/lib/sexpr/classes/FpRect.ts +0 -314
- package/lib/sexpr/classes/FpText.ts +0 -375
- package/lib/sexpr/classes/FpTextBox.ts +0 -450
- package/lib/sexpr/classes/GrLine.ts +0 -264
- package/lib/sexpr/classes/GrLineAngle.ts +0 -32
- package/lib/sexpr/classes/GrLineEnd.ts +0 -61
- package/lib/sexpr/classes/GrLineLocked.ts +0 -40
- package/lib/sexpr/classes/GrLineStart.ts +0 -61
- package/lib/sexpr/classes/GrText.ts +0 -228
- package/lib/sexpr/classes/Image.ts +0 -283
- package/lib/sexpr/classes/InBom.ts +0 -8
- package/lib/sexpr/classes/Junction.ts +0 -166
- package/lib/sexpr/classes/KicadPcb.ts +0 -361
- package/lib/sexpr/classes/KicadSch.ts +0 -397
- package/lib/sexpr/classes/KicadSchGenerator.ts +0 -32
- package/lib/sexpr/classes/KicadSchGeneratorVersion.ts +0 -30
- package/lib/sexpr/classes/KicadSchVersion.ts +0 -22
- package/lib/sexpr/classes/Label.ts +0 -176
- package/lib/sexpr/classes/Layer.ts +0 -51
- package/lib/sexpr/classes/Layers.ts +0 -47
- package/lib/sexpr/classes/LibSymbols.ts +0 -61
- package/lib/sexpr/classes/NoConnect.ts +0 -90
- package/lib/sexpr/classes/OnBoard.ts +0 -8
- package/lib/sexpr/classes/PadChamfer.ts +0 -50
- package/lib/sexpr/classes/PadChamferRatio.ts +0 -9
- package/lib/sexpr/classes/PadClearance.ts +0 -9
- package/lib/sexpr/classes/PadDieLength.ts +0 -9
- package/lib/sexpr/classes/PadDrill.ts +0 -145
- package/lib/sexpr/classes/PadDrillOffset.ts +0 -54
- package/lib/sexpr/classes/PadLayers.ts +0 -71
- package/lib/sexpr/classes/PadNet.ts +0 -56
- package/lib/sexpr/classes/PadOptions.ts +0 -181
- package/lib/sexpr/classes/PadPinFunction.ts +0 -9
- package/lib/sexpr/classes/PadPinType.ts +0 -9
- package/lib/sexpr/classes/PadPrimitiveGrArc.ts +0 -272
- package/lib/sexpr/classes/PadPrimitiveGrCircle.ts +0 -298
- package/lib/sexpr/classes/PadPrimitiveGrLine.ts +0 -126
- package/lib/sexpr/classes/PadPrimitives.ts +0 -291
- package/lib/sexpr/classes/PadRectDelta.ts +0 -57
- package/lib/sexpr/classes/PadRoundrectRratio.ts +0 -9
- package/lib/sexpr/classes/PadSize.ts +0 -69
- package/lib/sexpr/classes/PadSolderMaskMargin.ts +0 -9
- package/lib/sexpr/classes/PadSolderPasteMargin.ts +0 -9
- package/lib/sexpr/classes/PadSolderPasteMarginRatio.ts +0 -9
- package/lib/sexpr/classes/PadTeardrops.ts +0 -210
- package/lib/sexpr/classes/PadThermalBridgeAngle.ts +0 -9
- package/lib/sexpr/classes/PadThermalGap.ts +0 -9
- package/lib/sexpr/classes/PadThermalWidth.ts +0 -9
- package/lib/sexpr/classes/PadZoneConnect.ts +0 -9
- package/lib/sexpr/classes/Paper.ts +0 -119
- package/lib/sexpr/classes/PcbGeneral.ts +0 -82
- package/lib/sexpr/classes/PcbGeneralLegacyTeardrops.ts +0 -44
- package/lib/sexpr/classes/PcbGeneralThickness.ts +0 -9
- package/lib/sexpr/classes/PcbGenerator.ts +0 -16
- package/lib/sexpr/classes/PcbGeneratorVersion.ts +0 -16
- package/lib/sexpr/classes/PcbLayerDefinition.ts +0 -106
- package/lib/sexpr/classes/PcbLayers.ts +0 -34
- package/lib/sexpr/classes/PcbNet.ts +0 -56
- package/lib/sexpr/classes/PcbVersion.ts +0 -9
- package/lib/sexpr/classes/Property.ts +0 -301
- package/lib/sexpr/classes/PropertyHide.ts +0 -9
- package/lib/sexpr/classes/PropertyUnlocked.ts +0 -9
- package/lib/sexpr/classes/Pts.ts +0 -67
- package/lib/sexpr/classes/RenderCache.ts +0 -221
- package/lib/sexpr/classes/SchematicText.ts +0 -171
- package/lib/sexpr/classes/Segment.ts +0 -243
- package/lib/sexpr/classes/SegmentEnd.ts +0 -59
- package/lib/sexpr/classes/SegmentLocked.ts +0 -33
- package/lib/sexpr/classes/SegmentNet.ts +0 -64
- package/lib/sexpr/classes/SegmentStart.ts +0 -59
- package/lib/sexpr/classes/Setup/PcbPlotParams.ts +0 -689
- package/lib/sexpr/classes/Setup/PcbPlotParamsBase.ts +0 -9
- package/lib/sexpr/classes/Setup/PcbPlotParamsNumericProperties.ts +0 -105
- package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesA.ts +0 -104
- package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesB.ts +0 -105
- package/lib/sexpr/classes/Setup/Setup.ts +0 -574
- package/lib/sexpr/classes/Setup/SetupPropertyTypes.ts +0 -119
- package/lib/sexpr/classes/Setup/Stackup.ts +0 -135
- package/lib/sexpr/classes/Setup/StackupLayer.ts +0 -233
- package/lib/sexpr/classes/Setup/StackupLayerProperties.ts +0 -80
- package/lib/sexpr/classes/Setup/StackupProperties.ts +0 -40
- package/lib/sexpr/classes/Setup/base.ts +0 -165
- package/lib/sexpr/classes/Setup/index.ts +0 -14
- package/lib/sexpr/classes/Setup/setupMultiValueProperties.ts +0 -53
- package/lib/sexpr/classes/Setup/setupNumericProperties.ts +0 -151
- package/lib/sexpr/classes/Setup/setupPropertyHandlers.ts +0 -90
- package/lib/sexpr/classes/Setup/setupStringProperties.ts +0 -75
- package/lib/sexpr/classes/Sheet.ts +0 -287
- package/lib/sexpr/classes/SheetFill.ts +0 -44
- package/lib/sexpr/classes/SheetInstances.ts +0 -168
- package/lib/sexpr/classes/SheetInstancesRoot.ts +0 -165
- package/lib/sexpr/classes/SheetPin.ts +0 -125
- package/lib/sexpr/classes/SheetProperty.ts +0 -115
- package/lib/sexpr/classes/SheetSize.ts +0 -44
- package/lib/sexpr/classes/Stroke.ts +0 -58
- package/lib/sexpr/classes/StrokeType.ts +0 -34
- package/lib/sexpr/classes/Symbol.ts +0 -1666
- package/lib/sexpr/classes/TextEffects.ts +0 -461
- package/lib/sexpr/classes/TitleBlock.ts +0 -369
- package/lib/sexpr/classes/Unit.ts +0 -28
- package/lib/sexpr/classes/Uuid.ts +0 -8
- package/lib/sexpr/classes/Via.ts +0 -363
- package/lib/sexpr/classes/ViaNet.ts +0 -60
- package/lib/sexpr/classes/Width.ts +0 -8
- package/lib/sexpr/classes/Wire.ts +0 -111
- package/lib/sexpr/classes/Xy.ts +0 -33
- package/lib/sexpr/classes/Zone.ts +0 -39
- package/lib/sexpr/index.ts +0 -130
- package/lib/sexpr/parseKicadSexpr.ts +0 -5
- package/lib/sexpr/parseToPrimitiveSExpr.ts +0 -245
- package/lib/sexpr/utils/indentLines.ts +0 -3
- package/lib/sexpr/utils/parseYesNo.ts +0 -12
- package/lib/sexpr/utils/quoteSExprString.ts +0 -8
- package/lib/sexpr/utils/strokeFromArgs.ts +0 -18
- package/lib/sexpr/utils/toNumberValue.ts +0 -13
- package/lib/sexpr/utils/toStringValue.ts +0 -11
- package/scripts/download-references.ts +0 -68
- package/tests/fixtures/expectEqualPrimitiveSExpr.ts +0 -199
- package/tests/fixtures/png-matcher.ts +0 -109
- package/tests/fixtures/preload.ts +0 -1
- package/tests/sexpr/KicadPcbDemos.test.ts +0 -48
- package/tests/sexpr/KicadSchDemos.test.ts +0 -49
- package/tests/sexpr/classes/Footprint.test.ts +0 -277
- package/tests/sexpr/classes/FootprintPad.test.ts +0 -78
- package/tests/sexpr/classes/FpArc.test.ts +0 -45
- package/tests/sexpr/classes/FpCircle.test.ts +0 -39
- package/tests/sexpr/classes/FpPoly.test.ts +0 -43
- package/tests/sexpr/classes/FpRect.test.ts +0 -40
- package/tests/sexpr/classes/FpTextBox.test.ts +0 -84
- package/tests/sexpr/classes/Image.test.ts +0 -58
- package/tests/sexpr/classes/KicadSch.test.ts +0 -95
- package/tests/sexpr/classes/Paper.test.ts +0 -30
- package/tests/sexpr/classes/Property.test.ts +0 -48
- package/tests/sexpr/classes/Setup.test.ts +0 -188
- package/tests/sexpr/classes/Sheet.test.ts +0 -107
- package/tests/sexpr/classes/Stroke.test.ts +0 -15
- package/tests/sexpr/classes/Symbol.test.ts +0 -96
- package/tests/sexpr/classes/TextEffects.test.ts +0 -56
- package/tests/sexpr/classes/TitleBlock.test.ts +0 -40
- package/tsconfig.json +0 -35
|
@@ -1,221 +0,0 @@
|
|
|
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
|
-
import { Pts } from "./Pts"
|
|
7
|
-
|
|
8
|
-
type RenderCacheElement = RenderCachePolygon
|
|
9
|
-
|
|
10
|
-
export class RenderCache extends SxClass {
|
|
11
|
-
static override token = "render_cache"
|
|
12
|
-
override token = "render_cache"
|
|
13
|
-
|
|
14
|
-
private _text: string
|
|
15
|
-
private _angle?: number
|
|
16
|
-
private _offsetX?: number
|
|
17
|
-
private _offsetY?: number
|
|
18
|
-
private _elements: RenderCacheElement[] = []
|
|
19
|
-
|
|
20
|
-
constructor(text = "") {
|
|
21
|
-
super()
|
|
22
|
-
this._text = text
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static override fromSexprPrimitives(
|
|
26
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
27
|
-
): RenderCache {
|
|
28
|
-
if (primitiveSexprs.length === 0) {
|
|
29
|
-
throw new Error("render_cache requires a text argument")
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const [rawText, ...rest] = primitiveSexprs
|
|
33
|
-
const text = toStringValue(rawText)
|
|
34
|
-
if (text === undefined) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
`render_cache text must be a string value, received ${JSON.stringify(rawText)}`,
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const renderCache = new RenderCache(text)
|
|
41
|
-
|
|
42
|
-
const numericParams: number[] = []
|
|
43
|
-
|
|
44
|
-
for (const primitive of rest) {
|
|
45
|
-
if (Array.isArray(primitive)) {
|
|
46
|
-
const parsed = SxClass.parsePrimitiveSexpr(primitive, {
|
|
47
|
-
parentToken: this.token,
|
|
48
|
-
})
|
|
49
|
-
if (!(parsed instanceof SxClass)) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`render_cache child did not resolve to an SxClass: ${JSON.stringify(primitive)}`,
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!(parsed instanceof RenderCachePolygon)) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`render_cache encountered unsupported child token "${parsed.token}"`,
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
renderCache._elements.push(parsed)
|
|
62
|
-
continue
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const numeric = toNumberValue(primitive)
|
|
66
|
-
if (numeric === undefined) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`render_cache encountered non-numeric parameter ${JSON.stringify(primitive)}`,
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
numericParams.push(numeric)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (numericParams.length > 0) {
|
|
75
|
-
renderCache._angle = numericParams[0]
|
|
76
|
-
}
|
|
77
|
-
if (numericParams.length > 1) {
|
|
78
|
-
renderCache._offsetX = numericParams[1]
|
|
79
|
-
}
|
|
80
|
-
if (numericParams.length > 2) {
|
|
81
|
-
renderCache._offsetY = numericParams[2]
|
|
82
|
-
}
|
|
83
|
-
if (numericParams.length > 3) {
|
|
84
|
-
throw new Error("render_cache supports at most three numeric parameters")
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return renderCache
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
get text(): string {
|
|
91
|
-
return this._text
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
set text(value: string) {
|
|
95
|
-
this._text = value
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get angle(): number | undefined {
|
|
99
|
-
return this._angle
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
set angle(value: number | undefined) {
|
|
103
|
-
this._angle = value
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
get offsetX(): number | undefined {
|
|
107
|
-
return this._offsetX
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
set offsetX(value: number | undefined) {
|
|
111
|
-
this._offsetX = value
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
get offsetY(): number | undefined {
|
|
115
|
-
return this._offsetY
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
set offsetY(value: number | undefined) {
|
|
119
|
-
this._offsetY = value
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
get elements(): RenderCacheElement[] {
|
|
123
|
-
return [...this._elements]
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
set elements(elements: RenderCacheElement[]) {
|
|
127
|
-
this._elements = [...elements]
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
addElement(element: RenderCacheElement) {
|
|
131
|
-
this._elements.push(element)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
override getChildren(): SxClass[] {
|
|
135
|
-
return [...this._elements]
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
override getString(): string {
|
|
139
|
-
const headerParts: string[] = [quoteSExprString(this._text)]
|
|
140
|
-
if (this._angle !== undefined) {
|
|
141
|
-
headerParts.push(String(this._angle))
|
|
142
|
-
}
|
|
143
|
-
if (this._offsetX !== undefined) {
|
|
144
|
-
headerParts.push(String(this._offsetX))
|
|
145
|
-
}
|
|
146
|
-
if (this._offsetY !== undefined) {
|
|
147
|
-
headerParts.push(String(this._offsetY))
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (this._elements.length === 0) {
|
|
151
|
-
return `(render_cache ${headerParts.join(" ")})`
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const lines = [`(render_cache ${headerParts.join(" ")}`]
|
|
155
|
-
for (const element of this._elements) {
|
|
156
|
-
lines.push(element.getStringIndented())
|
|
157
|
-
}
|
|
158
|
-
lines.push(")")
|
|
159
|
-
return lines.join("\n")
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
SxClass.register(RenderCache)
|
|
163
|
-
|
|
164
|
-
class RenderCachePolygon extends SxClass {
|
|
165
|
-
static override token = "polygon"
|
|
166
|
-
static override parentToken = "render_cache"
|
|
167
|
-
override token = "polygon"
|
|
168
|
-
|
|
169
|
-
private _contours: Pts[] = []
|
|
170
|
-
|
|
171
|
-
static override fromSexprPrimitives(
|
|
172
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
173
|
-
): RenderCachePolygon {
|
|
174
|
-
const polygon = new RenderCachePolygon()
|
|
175
|
-
|
|
176
|
-
for (const primitive of primitiveSexprs) {
|
|
177
|
-
if (!Array.isArray(primitive) || primitive.length === 0) {
|
|
178
|
-
throw new Error(
|
|
179
|
-
`render_cache polygon encountered invalid child: ${JSON.stringify(primitive)}`,
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const parsed = SxClass.parsePrimitiveSexpr(primitive, {
|
|
184
|
-
parentToken: this.token,
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
if (!(parsed instanceof SxClass)) {
|
|
188
|
-
throw new Error(
|
|
189
|
-
`render_cache polygon child did not resolve to an SxClass: ${JSON.stringify(primitive)}`,
|
|
190
|
-
)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (!(parsed instanceof Pts)) {
|
|
194
|
-
throw new Error(
|
|
195
|
-
`render_cache polygon encountered unsupported token "${parsed.token}"`,
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
polygon._contours.push(parsed)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (polygon._contours.length === 0) {
|
|
203
|
-
throw new Error("render_cache polygon requires at least one pts child")
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return polygon
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
get contours(): Pts[] {
|
|
210
|
-
return [...this._contours]
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
set contours(value: Pts[]) {
|
|
214
|
-
this._contours = [...value]
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
override getChildren(): SxClass[] {
|
|
218
|
-
return [...this._contours]
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
SxClass.register(RenderCachePolygon)
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
-
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
-
import { quoteSExprString } from "../utils/quoteSExprString"
|
|
4
|
-
import { toStringValue } from "../utils/toStringValue"
|
|
5
|
-
import { At, type AtInput } from "./At"
|
|
6
|
-
import { ExcludeFromSim } from "./ExcludeFromSim"
|
|
7
|
-
import { TextEffects } from "./TextEffects"
|
|
8
|
-
import { Uuid } from "./Uuid"
|
|
9
|
-
|
|
10
|
-
const SUPPORTED_TOKENS = new Set(["exclude_from_sim", "at", "effects", "uuid"])
|
|
11
|
-
|
|
12
|
-
export interface SchematicTextConstructorParams {
|
|
13
|
-
value?: string
|
|
14
|
-
excludeFromSim?: boolean | ExcludeFromSim
|
|
15
|
-
at?: AtInput
|
|
16
|
-
effects?: TextEffects
|
|
17
|
-
uuid?: string | Uuid
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class SchematicText extends SxClass {
|
|
21
|
-
static override token = "text"
|
|
22
|
-
static override parentToken = "kicad_sch"
|
|
23
|
-
override token = "text"
|
|
24
|
-
|
|
25
|
-
private _value = ""
|
|
26
|
-
private _sxExcludeFromSim?: ExcludeFromSim
|
|
27
|
-
private _sxAt?: At
|
|
28
|
-
private _sxEffects?: TextEffects
|
|
29
|
-
private _sxUuid?: Uuid
|
|
30
|
-
|
|
31
|
-
constructor(params: SchematicTextConstructorParams = {}) {
|
|
32
|
-
super()
|
|
33
|
-
|
|
34
|
-
if (params.value !== undefined) {
|
|
35
|
-
this.value = params.value
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (params.excludeFromSim !== undefined) {
|
|
39
|
-
this.excludeFromSim =
|
|
40
|
-
typeof params.excludeFromSim === "boolean"
|
|
41
|
-
? params.excludeFromSim
|
|
42
|
-
: params.excludeFromSim.value
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (params.at !== undefined) {
|
|
46
|
-
this.at = params.at
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (params.effects !== undefined) {
|
|
50
|
-
this.effects = params.effects
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (params.uuid !== undefined) {
|
|
54
|
-
this.uuid = params.uuid
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static override fromSexprPrimitives(
|
|
59
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
60
|
-
): SchematicText {
|
|
61
|
-
const [textPrimitive, ...rest] = primitiveSexprs
|
|
62
|
-
const value = toStringValue(textPrimitive)
|
|
63
|
-
if (value === undefined) {
|
|
64
|
-
throw new Error("text expects a string value")
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const text = new SchematicText()
|
|
68
|
-
text._value = value
|
|
69
|
-
|
|
70
|
-
const { propertyMap, arrayPropertyMap } =
|
|
71
|
-
SxClass.parsePrimitivesToClassProperties(rest, this.token)
|
|
72
|
-
|
|
73
|
-
const unsupportedTokens = Object.keys(propertyMap).filter(
|
|
74
|
-
(token) => !SUPPORTED_TOKENS.has(token),
|
|
75
|
-
)
|
|
76
|
-
if (unsupportedTokens.length > 0) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`Unsupported child tokens inside text expression: ${unsupportedTokens.join(", ")}`,
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
for (const [token, entries] of Object.entries(arrayPropertyMap)) {
|
|
83
|
-
if (!SUPPORTED_TOKENS.has(token)) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
`Unsupported child tokens inside text expression: ${token}`,
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
if (entries.length > 1) {
|
|
89
|
-
throw new Error(`text does not support repeated child tokens: ${token}`)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
text._sxExcludeFromSim =
|
|
94
|
-
(arrayPropertyMap.exclude_from_sim?.[0] as ExcludeFromSim | undefined) ??
|
|
95
|
-
(propertyMap.exclude_from_sim as ExcludeFromSim | undefined)
|
|
96
|
-
text._sxAt =
|
|
97
|
-
(arrayPropertyMap.at?.[0] as At | undefined) ??
|
|
98
|
-
(propertyMap.at as At | undefined)
|
|
99
|
-
text._sxEffects =
|
|
100
|
-
(arrayPropertyMap.effects?.[0] as TextEffects | undefined) ??
|
|
101
|
-
(propertyMap.effects as TextEffects | undefined)
|
|
102
|
-
text._sxUuid =
|
|
103
|
-
(arrayPropertyMap.uuid?.[0] as Uuid | undefined) ??
|
|
104
|
-
(propertyMap.uuid as Uuid | undefined)
|
|
105
|
-
|
|
106
|
-
return text
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
get value(): string {
|
|
110
|
-
return this._value
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
set value(newValue: string) {
|
|
114
|
-
this._value = newValue
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get excludeFromSim(): boolean {
|
|
118
|
-
return this._sxExcludeFromSim?.value ?? false
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
set excludeFromSim(value: boolean) {
|
|
122
|
-
this._sxExcludeFromSim = value ? new ExcludeFromSim(true) : undefined
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
get at(): At | undefined {
|
|
126
|
-
return this._sxAt
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
set at(value: AtInput | undefined) {
|
|
130
|
-
this._sxAt = value !== undefined ? At.from(value) : undefined
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
get effects(): TextEffects | undefined {
|
|
134
|
-
return this._sxEffects
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
set effects(value: TextEffects | undefined) {
|
|
138
|
-
this._sxEffects = value
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
get uuid(): Uuid | undefined {
|
|
142
|
-
return this._sxUuid
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
set uuid(value: Uuid | string | undefined) {
|
|
146
|
-
if (value === undefined) {
|
|
147
|
-
this._sxUuid = undefined
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
override getChildren(): SxClass[] {
|
|
154
|
-
const children: SxClass[] = []
|
|
155
|
-
if (this._sxExcludeFromSim) children.push(this._sxExcludeFromSim)
|
|
156
|
-
if (this._sxAt) children.push(this._sxAt)
|
|
157
|
-
if (this._sxEffects) children.push(this._sxEffects)
|
|
158
|
-
if (this._sxUuid) children.push(this._sxUuid)
|
|
159
|
-
return children
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
override getString(): string {
|
|
163
|
-
const lines = [`(text ${quoteSExprString(this._value)}`]
|
|
164
|
-
for (const child of this.getChildren()) {
|
|
165
|
-
lines.push(child.getStringIndented())
|
|
166
|
-
}
|
|
167
|
-
lines.push(")")
|
|
168
|
-
return lines.join("\n")
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
SxClass.register(SchematicText)
|
|
@@ -1,243 +0,0 @@
|
|
|
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 interface SegmentConstructorParams {
|
|
22
|
-
start?: SegmentStart | { x: number; y: number }
|
|
23
|
-
end?: SegmentEnd | { x: number; y: number }
|
|
24
|
-
width?: Width | number
|
|
25
|
-
layer?: Layer | string | Array<string | number>
|
|
26
|
-
net?: SegmentNet | { id: number; name?: string }
|
|
27
|
-
uuid?: Uuid | string
|
|
28
|
-
locked?: boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class Segment extends SxClass {
|
|
32
|
-
static override token = "segment"
|
|
33
|
-
override token = "segment"
|
|
34
|
-
|
|
35
|
-
private _sxStart?: SegmentStart
|
|
36
|
-
private _sxEnd?: SegmentEnd
|
|
37
|
-
private _sxWidth?: Width
|
|
38
|
-
private _sxLayer?: Layer
|
|
39
|
-
private _sxNet?: SegmentNet
|
|
40
|
-
private _sxUuid?: Uuid
|
|
41
|
-
private _sxLocked?: SegmentLocked
|
|
42
|
-
|
|
43
|
-
constructor(params: SegmentConstructorParams = {}) {
|
|
44
|
-
super()
|
|
45
|
-
if (params.start !== undefined) this.start = params.start
|
|
46
|
-
if (params.end !== undefined) this.end = params.end
|
|
47
|
-
if (params.width !== undefined) this.width = params.width
|
|
48
|
-
if (params.layer !== undefined) this.layer = params.layer
|
|
49
|
-
if (params.net !== undefined) this.net = params.net
|
|
50
|
-
if (params.uuid !== undefined) this.uuid = params.uuid
|
|
51
|
-
if (params.locked !== undefined) this.locked = params.locked
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static override fromSexprPrimitives(
|
|
55
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
56
|
-
): Segment {
|
|
57
|
-
const segment = new Segment()
|
|
58
|
-
|
|
59
|
-
const { propertyMap, arrayPropertyMap } =
|
|
60
|
-
SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
|
|
61
|
-
|
|
62
|
-
const unexpectedSingleTokens = Object.keys(propertyMap).filter(
|
|
63
|
-
(token) => !SUPPORTED_SINGLE_TOKENS.has(token),
|
|
64
|
-
)
|
|
65
|
-
if (unexpectedSingleTokens.length > 0) {
|
|
66
|
-
throw new Error(
|
|
67
|
-
`Unsupported child tokens inside segment expression: ${unexpectedSingleTokens.join(", ")}`,
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
for (const [token, entries] of Object.entries(arrayPropertyMap)) {
|
|
72
|
-
if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Unsupported child tokens inside segment expression: ${token}`,
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
if (entries.length > 1) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`Segment does not support repeated child tokens: ${token}`,
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
segment._sxStart =
|
|
85
|
-
(arrayPropertyMap.start?.[0] as SegmentStart | undefined) ??
|
|
86
|
-
(propertyMap.start as SegmentStart | undefined)
|
|
87
|
-
segment._sxEnd =
|
|
88
|
-
(arrayPropertyMap.end?.[0] as SegmentEnd | undefined) ??
|
|
89
|
-
(propertyMap.end as SegmentEnd | undefined)
|
|
90
|
-
segment._sxWidth =
|
|
91
|
-
(arrayPropertyMap.width?.[0] as Width | undefined) ??
|
|
92
|
-
(propertyMap.width as Width | undefined)
|
|
93
|
-
segment._sxLayer =
|
|
94
|
-
(arrayPropertyMap.layer?.[0] as Layer | undefined) ??
|
|
95
|
-
(propertyMap.layer as Layer | undefined)
|
|
96
|
-
segment._sxNet =
|
|
97
|
-
(arrayPropertyMap.net?.[0] as SegmentNet | undefined) ??
|
|
98
|
-
(propertyMap.net as SegmentNet | undefined)
|
|
99
|
-
const locked =
|
|
100
|
-
(arrayPropertyMap.locked?.[0] as SegmentLocked | undefined) ??
|
|
101
|
-
(propertyMap.locked as SegmentLocked | undefined)
|
|
102
|
-
segment._sxLocked = locked && locked.value ? locked : undefined
|
|
103
|
-
segment._sxUuid =
|
|
104
|
-
(arrayPropertyMap.uuid?.[0] as Uuid | undefined) ??
|
|
105
|
-
(propertyMap.uuid as Uuid | undefined)
|
|
106
|
-
|
|
107
|
-
return segment
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
get start(): SegmentStart | undefined {
|
|
111
|
-
return this._sxStart
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
set start(value: SegmentStart | { x: number; y: number } | undefined) {
|
|
115
|
-
this._sxStart = this.normalizeStart(value)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
get end(): SegmentEnd | undefined {
|
|
119
|
-
return this._sxEnd
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
set end(value: SegmentEnd | { x: number; y: number } | undefined) {
|
|
123
|
-
this._sxEnd = this.normalizeEnd(value)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
get startPoint(): { x: number; y: number } | undefined {
|
|
127
|
-
return this._sxStart?.toObject()
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
get endPoint(): { x: number; y: number } | undefined {
|
|
131
|
-
return this._sxEnd?.toObject()
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
get width(): number | undefined {
|
|
135
|
-
return this._sxWidth?.value
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
set width(value: Width | number | undefined) {
|
|
139
|
-
if (value === undefined) {
|
|
140
|
-
this._sxWidth = undefined
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
this._sxWidth = value instanceof Width ? value : new Width(value)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
get widthClass(): Width | undefined {
|
|
147
|
-
return this._sxWidth
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
set widthClass(value: Width | undefined) {
|
|
151
|
-
this._sxWidth = value
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
get layer(): Layer | undefined {
|
|
155
|
-
return this._sxLayer
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
set layer(value: Layer | string | Array<string | number> | undefined) {
|
|
159
|
-
if (value === undefined) {
|
|
160
|
-
this._sxLayer = undefined
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
if (value instanceof Layer) {
|
|
164
|
-
this._sxLayer = value
|
|
165
|
-
return
|
|
166
|
-
}
|
|
167
|
-
const names = Array.isArray(value) ? value : [value]
|
|
168
|
-
this._sxLayer = new Layer(names)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
get net(): SegmentNet | undefined {
|
|
172
|
-
return this._sxNet
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
set net(value: SegmentNet | { id: number; name?: string } | undefined) {
|
|
176
|
-
if (value === undefined) {
|
|
177
|
-
this._sxNet = undefined
|
|
178
|
-
return
|
|
179
|
-
}
|
|
180
|
-
if (value instanceof SegmentNet) {
|
|
181
|
-
this._sxNet = value
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
this._sxNet = new SegmentNet(value.id, value.name)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
get uuid(): Uuid | undefined {
|
|
188
|
-
return this._sxUuid
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
set uuid(value: Uuid | string | undefined) {
|
|
192
|
-
if (value === undefined) {
|
|
193
|
-
this._sxUuid = undefined
|
|
194
|
-
return
|
|
195
|
-
}
|
|
196
|
-
this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
get locked(): boolean {
|
|
200
|
-
return this._sxLocked?.value ?? false
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
set locked(value: boolean) {
|
|
204
|
-
this._sxLocked = value ? new SegmentLocked(true) : undefined
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
override getChildren(): SxClass[] {
|
|
208
|
-
const children: SxClass[] = []
|
|
209
|
-
if (this._sxStart) children.push(this._sxStart)
|
|
210
|
-
if (this._sxEnd) children.push(this._sxEnd)
|
|
211
|
-
if (this._sxWidth) children.push(this._sxWidth)
|
|
212
|
-
if (this._sxLayer) children.push(this._sxLayer)
|
|
213
|
-
if (this._sxNet) children.push(this._sxNet)
|
|
214
|
-
if (this._sxLocked) children.push(this._sxLocked)
|
|
215
|
-
if (this._sxUuid) children.push(this._sxUuid)
|
|
216
|
-
return children
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
private normalizeStart(
|
|
220
|
-
value: SegmentStart | { x: number; y: number } | undefined,
|
|
221
|
-
): SegmentStart | undefined {
|
|
222
|
-
if (value === undefined) {
|
|
223
|
-
return undefined
|
|
224
|
-
}
|
|
225
|
-
if (value instanceof SegmentStart) {
|
|
226
|
-
return value
|
|
227
|
-
}
|
|
228
|
-
return new SegmentStart(value.x, value.y)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
private normalizeEnd(
|
|
232
|
-
value: SegmentEnd | { x: number; y: number } | undefined,
|
|
233
|
-
): SegmentEnd | undefined {
|
|
234
|
-
if (value === undefined) {
|
|
235
|
-
return undefined
|
|
236
|
-
}
|
|
237
|
-
if (value instanceof SegmentEnd) {
|
|
238
|
-
return value
|
|
239
|
-
}
|
|
240
|
-
return new SegmentEnd(value.x, value.y)
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
SxClass.register(Segment)
|
|
@@ -1,59 +0,0 @@
|
|
|
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)
|