Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/kicad/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Stroke,
TitleBlock,
expand_text_vars,
EmbeddedFile,
StrokeParams,
type HasNetName,
type HasUniqueID,
Expand All @@ -34,7 +35,11 @@ export class KicadPCB {
project?: Project;
version: number;
generator?: string;
general?: { thickness: number };
generator_version?: string;
general? = {
thickness: 1.6,
legacy_teardrops: false,
};
paper?: Paper;
title_block = new TitleBlock();
setup?: Setup;
Expand All @@ -47,6 +52,8 @@ export class KicadPCB {
vias: Via[] = [];
drawings: Drawing[] = [];
groups: Group[] = [];
embedded_fonts: boolean = false;
embedded_files: EmbeddedFile[] = [];

constructor(
public filename: string,
Expand All @@ -59,7 +66,13 @@ export class KicadPCB {
P.start("kicad_pcb"),
P.pair("version", T.number),
P.pair("generator", T.string),
P.object("general", {}, P.pair("thickness", T.number)),
P.pair("generator_version", T.string),
P.object(
"general",
{},
P.pair("thickness", T.number),
P.pair("legacy_teardrops", T.boolean),
),
P.item("paper", Paper),
P.item("title_block", TitleBlock),
P.list("layers", T.item(Layer)),
Expand Down Expand Up @@ -88,6 +101,8 @@ export class KicadPCB {
P.collection("drawings", "gr_rect", T.item(GrRect, this)),
P.collection("drawings", "gr_text", T.item(GrText, this)),
P.collection("groups", "group", T.item(Group)),
P.pair("embedded_fonts", T.boolean),
P.list("embedded_files", T.item(EmbeddedFile)),
),
);

Expand Down Expand Up @@ -854,6 +869,8 @@ export class Footprint implements HasUniqueID {
#pads_by_number = new Map<string, Pad>();
zones: Zone[] = [];
models: Model[] = [];
embedded_fonts: boolean = false;
embedded_files: EmbeddedFile[] = [];
#bbox: BBox;

constructor(
Expand Down Expand Up @@ -911,6 +928,8 @@ export class Footprint implements HasUniqueID {
P.collection("zones", "zone", T.item(Zone, this)),
P.collection("models", "model", T.item(Model)),
P.collection("pads", "pad", T.item(Pad, this)),
P.pair("embedded_fonts", T.boolean),
P.list("embedded_files", T.item(EmbeddedFile)),
),
);

Expand Down Expand Up @@ -1763,9 +1782,10 @@ export class Model {
}
}

export class Group {
export class Group implements HasUniqueID {
name: string;
id: string;
id?: string;
uuid?: string;
locked = false;
members: string[];

Expand All @@ -1778,8 +1798,13 @@ export class Group {
P.positional("name", T.string),
P.atom("locked"),
P.pair("id", T.string),
P.pair("uuid", T.string),
P.list("members", T.string),
),
);
}

get unique_id(): string | undefined {
return this.uuid ?? this.id;
}
}
42 changes: 42 additions & 0 deletions src/kicad/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,48 @@ export class Stroke {
}
}

export enum EmbeddedFileType {
Datasheet = "datasheet",
Font = "font",
Model = "model",
Worksheet = "worksheet",
Other = "other",
}

export class EmbeddedFile {
name: string;
type: EmbeddedFileType;
data?: string;
checksum: string;

constructor(expr: Parseable) {
Object.assign(
this,
parse_expr(
expr,
P.start("file"),
P.pair("name", T.string),
P.pair("type", T.string),
P.pair("data", T.string),
P.pair("checksum", T.string),
),
);
}

async decompress_file(): Promise<File | undefined> {
// see also:
// https://gitlab.com/kicad/code/kicad/-/blob/master/common/embedded_files.cpp#L253
if (!this.data) {
// need be found in the board file
return undefined;
}

// TODO

return undefined;
}
}

/** Stroke and additional parameters for dashed lines. */
export class StrokeParams {
stroke: Stroke;
Expand Down
11 changes: 11 additions & 0 deletions src/kicad/schematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Paper,
Stroke,
TitleBlock,
EmbeddedFile,
expand_text_vars,
unescape_string,
} from "./common";
Expand Down Expand Up @@ -59,6 +60,7 @@ export class KicadSch {
project?: Project;
version: number;
generator?: string;
generator_version?: string;
uuid: string;
paper?: Paper;
title_block = new TitleBlock();
Expand All @@ -78,6 +80,8 @@ export class KicadSch {
sheet_instances?: SheetInstances;
symbol_instances?: SymbolInstances;
sheets: SchematicSheet[] = [];
embedded_fonts: boolean = false;
embedded_files: EmbeddedFile[] = [];

constructor(
public filename: string,
Expand All @@ -90,6 +94,7 @@ export class KicadSch {
P.start("kicad_sch"),
P.pair("version", T.number),
P.pair("generator", T.string),
P.pair("generator_version", T.string),
P.pair("uuid", T.string),
P.item("paper", Paper),
P.item("title_block", TitleBlock),
Expand Down Expand Up @@ -126,6 +131,8 @@ export class KicadSch {
P.item("sheet_instances", SheetInstances),
P.item("symbol_instances", SymbolInstances),
P.collection("sheets", "sheet", T.item(SchematicSheet, this)),
P.pair("embedded_fonts", T.boolean),
P.list("embedded_files", T.item(EmbeddedFile)),
),
);

Expand Down Expand Up @@ -812,6 +819,8 @@ export class LibSymbol {
drawings: Drawing[] = [];
pins: PinDefinition[] = [];
units: Map<number, LibSymbol[]> = new Map();
embedded_fonts = false;
embedded_files: EmbeddedFile[] = [];

#pins_by_number: Map<string, PinDefinition> = new Map();
#properties_by_id: Map<number, Property> = new Map();
Expand Down Expand Up @@ -852,6 +861,8 @@ export class LibSymbol {
P.collection("drawings", "rectangle", T.item(Rectangle, this)),
P.collection("drawings", "text", T.item(LibText, this)),
P.collection("drawings", "textbox", T.item(TextBox, this)),
P.pair("embedded_fonts", T.boolean),
P.collection("embedded_files", "file", T.item(EmbeddedFile)),
),
);

Expand Down