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
64 changes: 52 additions & 12 deletions src/kicad/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TitleBlock,
expand_text_vars,
StrokeParams,
type HasNetName,
type HasUniqueID,
type HasStrokeParams,
} from "./common";
Expand Down Expand Up @@ -75,10 +76,10 @@ export class KicadPCB {
"footprint",
T.item(Footprint, this),
),
P.collection("zones", "zone", T.item(Zone)),
P.collection("segments", "segment", T.item(LineSegment)),
P.collection("segments", "arc", T.item(ArcSegment)),
P.collection("vias", "via", T.item(Via)),
P.collection("zones", "zone", T.item(Zone, this)),
P.collection("segments", "segment", T.item(LineSegment, this)),
P.collection("segments", "arc", T.item(ArcSegment, this)),
P.collection("vias", "via", T.item(Via, this)),
P.collection("drawings", "dimension", T.item(Dimension, this)),
P.collection("drawings", "gr_line", T.item(GrLine, this)),
P.collection("drawings", "gr_circle", T.item(GrCircle, this)),
Expand All @@ -89,6 +90,9 @@ export class KicadPCB {
P.collection("groups", "group", T.item(Group)),
),
);

// sort the array by net_number
this.nets.sort((a, b) => a.number - b.number);
}

*items() {
Expand Down Expand Up @@ -130,6 +134,10 @@ export class KicadPCB {
}
return null;
}

get_netname_by_number(net_number: number): string | undefined {
return this.nets[net_number]?.name;
}
}

export class Property {
Expand All @@ -149,7 +157,7 @@ export class Property {
}
}

export class LineSegment implements HasUniqueID {
export class LineSegment implements HasUniqueID, HasNetName {
start: Vec2;
end: Vec2;
width: number;
Expand All @@ -159,7 +167,10 @@ export class LineSegment implements HasUniqueID {
uuid?: string;
tstamp?: string;

constructor(expr: Parseable) {
constructor(
expr: Parseable,
public parent: KicadPCB,
) {
/*
(segment
(start 119.1 82.943)
Expand Down Expand Up @@ -189,19 +200,27 @@ export class LineSegment implements HasUniqueID {
get unique_id(): string | undefined {
return this.uuid ?? this.tstamp;
}

get netname(): string | undefined {
return this.parent.get_netname_by_number(this.net);
}
}

export class ArcSegment {
export class ArcSegment implements HasUniqueID, HasNetName {
start: Vec2;
mid: Vec2;
end: Vec2;
width: number;
layer: string;
net: number;
locked = false;
tstamp: string;
tstamp?: string;
uuid?: string;

constructor(expr: Parseable) {
constructor(
expr: Parseable,
public parent: KicadPCB,
) {
/*
(arc
(start 115.25 59.05)
Expand All @@ -225,12 +244,21 @@ export class ArcSegment {
P.pair("net", T.number),
P.atom("locked"),
P.pair("tstamp", T.string),
P.pair("uuid", T.string),
),
);
}

get unique_id(): string | undefined {
return this.uuid ?? this.tstamp;
}

get netname(): string | undefined {
return this.parent.get_netname_by_number(this.net);
}
}

export class Via implements HasUniqueID {
export class Via implements HasUniqueID, HasNetName {
type: "blind" | "micro" | "through-hole" = "through-hole";
at: At;
size: number;
Expand All @@ -244,7 +272,10 @@ export class Via implements HasUniqueID {
tstamp?: string;
uuid?: string;

constructor(expr: Parseable) {
constructor(
expr: Parseable,
public parent: KicadPCB,
) {
Object.assign(
this,
parse_expr(
Expand All @@ -269,6 +300,10 @@ export class Via implements HasUniqueID {
get unique_id(): string | undefined {
return this.uuid ?? this.tstamp;
}

get netname(): string | undefined {
return this.parent.get_netname_by_number(this.net);
}
}

export class Zone implements HasUniqueID {
Expand Down Expand Up @@ -1506,7 +1541,7 @@ export class GrText extends Text {
}
}

export class Pad implements HasUniqueID {
export class Pad implements HasUniqueID, HasNetName {
number: string; // I hate this
type: "thru_hole" | "smd" | "connect" | "np_thru_hole" = "thru_hole";
shape: "circle" | "rect" | "oval" | "trapezoid" | "roundrect" | "custom";
Expand Down Expand Up @@ -1604,6 +1639,11 @@ export class Pad implements HasUniqueID {
get unique_id(): string | undefined {
return this.uuid ?? this.tstamp;
}

get netname(): string | undefined {
// assert: pcb.net[this.net.number] !== undefined
return this.net?.name;
}
}

export class PadDrill {
Expand Down
5 changes: 5 additions & 0 deletions src/kicad/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,8 @@ export class StrokeParams {
export interface HasStrokeParams {
get stroke_params(): StrokeParams;
}

/** Items which has netname */
export interface HasNetName {
get netname(): string | undefined;
}
32 changes: 30 additions & 2 deletions src/viewers/board/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ export enum LayerNames {
anchors = ":Anchors",
non_plated_holes = ":NonPlatedHoles",
via_holes = ":Via:Holes",
pad_holes_netname = ":Pad:Holes:NetName",
pad_holes = ":Pad:Holes",
pad_holewalls = ":Pad:HoleWalls",
via_holewalls = ":Via:HoleWalls",
pads_front_netname = ":Pads:Front:NetName",
pads_front = ":Pads:Front",
f_cu = "F.Cu",
f_mask = "F.Mask",
Expand Down Expand Up @@ -81,6 +83,7 @@ export enum LayerNames {
in28_cu = "In28.Cu",
in29_cu = "In29.Cu",
in30_cu = "In30.Cu",
pads_back_netname = ":Pads:Back:NetName",
pads_back = ":Pads:Back",
b_cu = "B.Cu",
b_mask = "B.Mask",
Expand Down Expand Up @@ -216,15 +219,28 @@ export class LayerSet extends BaseLayerSet {
}

// Pad layers require that the front or back layer is visible.
if (layer_name == LayerNames.pads_front) {
if (
layer_name == LayerNames.pads_front ||
layer_name == LayerNames.pads_front_netname
) {
visible = () => this.by_name(LayerNames.f_cu)!.visible;
interactive = true;
}
if (layer_name == LayerNames.pads_back) {

if (
layer_name == LayerNames.pads_back ||
layer_name == LayerNames.pads_back_netname
) {
visible = () => this.by_name(LayerNames.b_cu)!.visible;
interactive = true;
}

// Pad hole netname require that the pad holes layer is visible
if (layer_name == LayerNames.pad_holes_netname) {
visible = () => this.by_name(LayerNames.pad_holes)!.visible;
interactive = true;
}

// Copper layers require additional virual layers for zones and
// blind/buried vias. Those are generated here.
// Zone virtual layers for copper layers require that the referenced
Expand Down Expand Up @@ -309,6 +325,15 @@ export class LayerSet extends BaseLayerSet {
return (this.theme["background"] as Color) ?? Color.white;
case LayerNames.pad_holewalls:
return (this.theme["pad_through_hole"] as Color) ?? Color.white;
case LayerNames.pads_front_netname:
// TODO theme?
return Color.white.with_alpha(0.8);
case LayerNames.pads_back_netname:
// TODO theme?
return Color.white.with_alpha(0.8);
case LayerNames.pad_holes_netname:
// TODO theme?
return Color.white.with_alpha(0.8);
}

let name = layer_name;
Expand Down Expand Up @@ -415,12 +440,15 @@ export class LayerSet extends BaseLayerSet {
}

*pad_layers() {
yield this.by_name(LayerNames.pads_front_netname)!;
yield this.by_name(LayerNames.pads_front)!;
yield this.by_name(LayerNames.pads_back_netname)!;
yield this.by_name(LayerNames.pads_back)!;
}

*pad_hole_layers() {
yield this.by_name(LayerNames.pad_holes)!;
yield this.by_name(LayerNames.pad_holes_netname)!;
yield this.by_name(LayerNames.pad_holewalls)!;
}

Expand Down
Loading