Skip to content

Commit 1ffce27

Browse files
committed
Allow multiple sheet_instances in KicadSch
1 parent a3a54a6 commit 1ffce27

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/sexpr/classes/KicadSch.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const SINGLE_CHILD_TOKENS = new Set([
2626
"paper",
2727
"title_block",
2828
"lib_symbols",
29-
"sheet_instances",
3029
"embedded_fonts",
3130
])
3231

@@ -39,6 +38,7 @@ const MULTI_CHILD_TOKENS = new Set([
3938
"label",
4039
"junction",
4140
"wire",
41+
"sheet_instances",
4242
])
4343

4444
const SUPPORTED_CHILD_TOKENS = new Set([
@@ -54,7 +54,7 @@ export interface KicadSchConstructorParams {
5454
paper?: Paper
5555
titleBlock?: TitleBlock
5656
libSymbols?: LibSymbols
57-
sheetInstances?: SheetInstances
57+
sheetInstances?: SheetInstances | SheetInstances[]
5858
embeddedFonts?: EmbeddedFonts
5959
properties?: Property[]
6060
images?: Image[]
@@ -77,7 +77,7 @@ export class KicadSch extends SxClass {
7777
private _sxPaper?: Paper
7878
private _sxTitleBlock?: TitleBlock
7979
private _sxLibSymbols?: LibSymbols
80-
private _sxSheetInstances?: SheetInstances
80+
private _sheetInstances: SheetInstances[] = []
8181
private _sxEmbeddedFonts?: EmbeddedFonts
8282
private _properties: Property[] = []
8383
private _images: Image[] = []
@@ -216,7 +216,9 @@ export class KicadSch extends SxClass {
216216
paper: propertyMap.paper as Paper | undefined,
217217
titleBlock: propertyMap.title_block as TitleBlock | undefined,
218218
libSymbols: propertyMap.lib_symbols as LibSymbols | undefined,
219-
sheetInstances: propertyMap.sheet_instances as SheetInstances | undefined,
219+
sheetInstances: arrayPropertyMap.sheet_instances as
220+
| SheetInstances[]
221+
| undefined,
220222
embeddedFonts: propertyMap.embedded_fonts as EmbeddedFonts | undefined,
221223
properties: (arrayPropertyMap.property as Property[]) ?? [],
222224
images: (arrayPropertyMap.image as Image[]) ?? [],
@@ -292,12 +294,16 @@ export class KicadSch extends SxClass {
292294
this._sxLibSymbols = value
293295
}
294296

295-
get sheetInstances(): SheetInstances | undefined {
296-
return this._sxSheetInstances
297+
get sheetInstances(): SheetInstances[] {
298+
return [...this._sheetInstances]
297299
}
298300

299-
set sheetInstances(value: SheetInstances | undefined) {
300-
this._sxSheetInstances = value
301+
set sheetInstances(value: SheetInstances | SheetInstances[] | undefined) {
302+
if (value === undefined) {
303+
this._sheetInstances = []
304+
return
305+
}
306+
this._sheetInstances = Array.isArray(value) ? [...value] : [value]
301307
}
302308

303309
get embeddedFonts(): EmbeddedFonts | undefined {
@@ -381,7 +387,7 @@ export class KicadSch extends SxClass {
381387
if (this._sxPaper) children.push(this._sxPaper)
382388
if (this._sxTitleBlock) children.push(this._sxTitleBlock)
383389
if (this._sxLibSymbols) children.push(this._sxLibSymbols)
384-
if (this._sxSheetInstances) children.push(this._sxSheetInstances)
390+
children.push(...this._sheetInstances)
385391
if (this._sxEmbeddedFonts) children.push(this._sxEmbeddedFonts)
386392
children.push(...this._properties)
387393
children.push(...this._images)

0 commit comments

Comments
 (0)