netgraph

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netgraph assembles a pin-level netlist from schematic geometry. Both the xschem and gEDA readers reduce their format to the same neutral inputs, expressed as integer grid points: wire segments (optionally carrying a net name), named net anchors (power taps, port/label markers), and component pin placements. netgraph unions everything that shares a grid point, names each resulting net, and reports which component pins land on it.

It is format-agnostic and coordinate-agnostic. The caller quantizes its native units to an integer grid so that endpoints meant to touch compare equal. Two connection points at the same grid point are the same node; a wire additionally unions its two endpoints.

Index

Constants

View Source
const (
	// AttrPowerDriven marks a net asserted as fed (a PWR_FLAG or equivalent directive).
	AttrPowerDriven = "power_driven"
	// AttrNoConnect marks a net a pin's no-connect flag lands on, the designer's own statement that
	// the open pin is deliberate (see Net.NoConnect).
	AttrNoConnect = "no_connect"
	// AttrExternal marks a net that continues into something the read did NOT cover, a by-name
	// connection (global label, power symbol) whose other ends may live in unread files. It is
	// about READ SCOPE, not sheet membership, so a net spanning ten sheets of a completely-read
	// design carries no marking.
	AttrExternal = "external"
	// AttrGlobal marks a named rail on a completely-read design (AttrExternal, resolved).
	AttrGlobal = "global"
	// AttrAliases carries every distinct label a net arrived with, when there is more than one,
	// as "rank:name" entries joined by the US separator (names contain commas and slashes, and
	// \x1f does not occur in EDA names). Rank is the label's Anchor.Rank, which for KiCad is 0
	// for design-wide (global label, power rail) and 1 for sheet-scoped. The naming pass
	// collapses aliases to one Net.Name, and the conflict rules (duplicate labels, rival rail
	// taps) read this to see what was collapsed. Parse with ParseAliases.
	AttrAliases = "aliases"
	// AttrSheets lists the sheet instance ids a net touches, in sheet order, joined by the US
	// separator (a KiCad Sheetname may contain a comma). It is the one membership fact the
	// solver stamps (WS9-028), because a wireless single-pin net on a sub-sheet has no wire
	// geometry to join, so the finding-panel sheet badge has no other source. Only a
	// multi-sheet read populates it, from the hierarchy walk's sheet bands. Parse with
	// ParseSheets.
	AttrSheets = "sheets"
)

Net fact attributes (ir.Net.attributes keys) emitted and resolved here. They are FACTS the check layer reads, kept in the open attributes map rather than typed Net fields because C9 admits a typed field only once a second format populates it (WS3-004 designs the typed fact base). The constants keep producers and consumers typo-safe without closing the schema.

Variables

This section is empty.

Functions

func Build

func Build(wires []Wire, anchors []Anchor, pins []Pin, terminals []Point, opts ...Options) ([]Net, []Dangle, map[string]NetRef)

Build assembles nets from schematic geometry in two stages. First it unions connection points by grid coincidence (a wire also unions its two endpoints), giving geometric nodes. Then it unions nodes by EVERY label they carry, since schematic net labels and power taps connect by name across the whole sheet, not only where wires physically touch, so every "0" ground tap is one net regardless of geometry. A node carrying two labels aliases them into one net, which is how the KiCad hierarchy walk stitches a parent sheet pin to its child hierarchical label. The merged net's name is its lowest-ranked label (wire labels first, then Anchor.Rank, ties by input order). Unnamed geometric nodes stay separate and get a synthetic "N$<n>" name numbered by first appearance; an unnamed, pinless node is dropped as drawing noise. Conns within a net are deduplicated and sorted.

It also returns the dangling endpoints (see Dangle), each a wire endpoint whose grid point holds nothing else (no pin, anchor, terminal, or second wire endpoint). terminals are the points a format marks as a legitimate wire end, a junction dot or a no-connect flag; formats with neither pass nil. Dangles are sorted.

The third return maps each identified wire (by Wire.Id) to the net its endpoints resolved to, which the geometry sidecar uses to draw a KiCad wire by net (WS1-022). Only wires with a native id populate it; a wire whose node is drawing noise is omitted.

func BuildWithPoints

func BuildWithPoints(wires []Wire, anchors []Anchor, pins []Pin, terminals []Point, opts ...Options) ([]Net, []Dangle, map[string]NetRef, map[Point]NetRef)

BuildWithPoints is Build plus a point->net-name map covering every input point (both wire endpoints, each anchor, each pin). The KiCad hierarchy walk offsets each sheet instance into its own grid band (WS9-028) and uses this map to attribute each net to the sheets it touches. A point on drawing noise (unnamed, pinless) is omitted, as in the wire map.

func EncodeSheets

func EncodeSheets(ids []string) string

EncodeSheets joins sheet ids into an AttrSheets value, empty for none (the caller then stamps nothing). The hierarchy reader uses it so it writes the encoding ParseSheets reads.

func ExpandBusName

func ExpandBusName(name string) []string

ExpandBusName expands a RANGE bus name into its member signal names in WRITTEN order: `DATA[7:0]` -> [DATA7 DATA6 ... DATA0], `A[0:3]` -> [A0 A1 A2 A3], `AN[0..7]` -> [AN0 AN1 ... AN7]. The member name is the prefix concatenated with the index, matching KiCad's bus-member naming and the tap labels. It returns nil for a name that is not a range bus (a scalar net, or an alias-named bus whose members the caller supplies). Written order lets a diagram read bits as drawn.

func IRDangles

func IRDangles(ds []Dangle, src, idKind string) []*ir.DanglingEndpoint

IRDangles maps the solver's dangling endpoints onto the IR diagnostic. idKind names the wire id's format (e.g. "kicad-uuid"); it and the id are omitted for formats with no per-wire id.

func IRNets

func IRNets(nets []Net, src string) []*ir.Net

IRNets maps assembled nets onto the IR wire form, the one place a solver Net becomes an ir.Net. Driven, External and multiple Aliases surface as the power_driven, external and aliases attributes the check rules read, and a net with none of them carries no attributes. Nets with no connections are kept, since a labeled wire whose pins did not resolve still names a net. A reader whose source tool omits pinless nets filters before calling.

func IsBusName

func IsBusName(name string) bool

IsBusName reports whether name carries an index range in either dialect's spelling. It is the geometry-free bus detector the readers share.

func ParseSheets

func ParseSheets(v string) []string

ParseSheets decodes an AttrSheets value into its ordered sheet ids. Empty or absent decodes to nil, as for any single-sheet or non-hierarchical read.

func ResolveExternal

func ResolveExternal(d *ir.Design)

ResolveExternal downgrades external to global on every net of a completely-read design (WS1-017). Once a read covered the whole design (a KiCad .kicad_pro whose root has no unread sub-sheets), external is stale and would guard rules such as decoupling-present off the rails they exist for, while global keeps "is a named rail" queryable. Only the completeness judgment stays in each reader, since only the reader knows what its source references versus what it opened. See docsite/content/architecture/net-solving.md#the-hierarchy-walk.

func StampNetIDs

func StampNetIDs(d *ir.Design)

StampNetIDs fills ir.Net.id (WS9) for every net that lacks one, hashing its connection set the same way the solver does (hashPairs). A reader that builds ir.Net directly, as EDIF does, gets the same per-instance identity a netgraph-based reader gets from IRNets. It is idempotent and leaves a set id alone. A pinless net keeps its empty id.

Types

type Alias

type Alias struct {
	Name string
	Rank int
}

Alias is one label a net carries, with the Anchor.Rank it arrived with (wire labels use the wire rank, below every anchor).

func ParseAliases

func ParseAliases(v string) []Alias

ParseAliases decodes an AttrAliases value back into the solver's alias list. Empty or absent values decode to nil (single-named nets carry no attribute).

type Anchor

type Anchor struct {
	At       Point
	Label    string
	Driver   bool
	External bool
	// Rank orders naming when a net carries several labels. The lowest-ranked label names the
	// net, ties keep input order, and a wire label beats every anchor. Single-sheet callers
	// leave it zero. The KiCad hierarchy walk ranks a bare global/power name (0) over an
	// instance-qualified local name (1) over a synthetic hier-join label (2), which exists only
	// to union a parent sheet pin with its child hierarchical label.
	Rank int
}

Anchor names the net passing through a grid point, such as a power/ground tap or a port/label marker. It contributes a name but no pin. Driver marks an anchor that asserts the net is driven without being a pin (a KiCad PWR_FLAG), so a rail fed only by a flag is not read as undriven; it sets Net.Driven. External marks an anchor that continues the net onto another sheet (a global/hierarchical label or a global power rail); it sets Net.External.

type Conn

type Conn struct{ Comp, Pin, Dir string }

Conn is a pin's membership in a net.

type Dangle

type Dangle struct {
	At     Point
	WireId string
}

Dangle is a wire endpoint that terminates on nothing (no pin, anchor/label, junction, or other wire endpoint shares its grid point). At is the endpoint and WireId the Wire.Id it belongs to, "" when unknown. A wire end landing mid-span on another wire without a junction (a T-tap missing its dot) is not reported here; that is WS1-012 and needs point-on-segment geometry.

type Net

type Net struct {
	Name string
	// ID is a hash of the sorted connection set (see netID), independent of Name, so two
	// distinct nets sharing a Name get distinct IDs. It is EPHEMERAL, recomputed every solve
	// and stable only while connectivity is unchanged, so it is a within-load join key and never
	// a durable handle for saved work. Empty for a pinless net; consumers fall back to Name.
	ID       string
	Conns    []Conn
	Driven   bool
	External bool
	// NoConnect is true when a pin on the net carries the format's no-connect flag, which is the
	// designer saying the open pin is deliberate. A net's name never says so: KiCad names every
	// unlabelled one-pin net "unconnected-(...)", flagged or not (agni issue 1019).
	NoConnect bool
	Aliases   []Alias
}

Net is one assembled net, a name and the pins on it, with Conns sorted. Driven is true when a driver anchor (a PWR_FLAG) landed on the net. External is true when the net continues onto another sheet, so an absence-based rule (nothing drives this, only inputs here) knows its view is incomplete and can decline to fire. Aliases lists EVERY distinct label that landed on the net (Name included) with its rank, in first-appearance order, so naming-conflict rules can see what the naming pass collapsed (taps spelled "+3V3" and "+3.3V" on one net). Empty for unnamed nets.

type NetRef

type NetRef struct {
	Name string
	ID   string
}

NetRef identifies the net a wire or point resolved to by its display Name and the deterministic ID (see Net.ID). The wire/point maps carry both so the geometry sidecar can draw a wire by name AND join a highlight to the specific net instance by id, even when two nets share a name.

type Options added in v0.2.2

type Options struct {
	// AlphaTies breaks a tie between labels of equal rank by name rather than input order, and
	// picks a pin-derived AutoName the same way, preferring a name that does not end in a pad
	// number. KiCad names nets this way, so a read that follows it agrees with KiCad's netlist.
	AlphaTies bool
}

Options adjusts how Build names nets. The zero value is the shared behaviour every format without its own naming rules uses.

type Pin

type Pin struct {
	At        Point
	Comp, Pin string
	NoConnect bool
	// Dir is the pin's electrical direction in the check vocabulary ("power_in",
	// "power_out", ...), set only for a pin on a VIRTUAL component (a KiCad power symbol,
	// WS1-014) that never enters Components, since no part-type pin exists to resolve it
	// from. Empty for ordinary pins, whose direction resolves via the part type.
	Dir string
	// AutoName is the name the format's own tool gives a net no label names, when this pin is
	// the one it is named after (KiCad's "Net-(R1-Pad2)"), and NCName the name it gives a
	// no-connect-flagged pin's lone stub ("unconnected-(J1A-MID0-PadK40)"). A format that sets
	// neither gets the synthetic "N$<n>" and "unconnected-(REF-PadN)" names.
	AutoName, NCName string
}

Pin is one component pin placed at a grid point. Comp is the component ref_des and Pin is the pin designator on that component. NoConnect marks a pin whose connect point carries the format's no-connect flag (a KiCad no_connect marker placed ON the pin, WS1-019). The caller detects the coincidence, and Build names that pin's LONE stub net in the tool-marker vocabulary ("unconnected-(REF-Pad)") instead of "N$<n>", so existing no-connect consumers (intentionallyUnconnected, the NC channel) recognise it with no new IR field. A marked pin on a multi-pin net keeps normal naming, because that is an nc-pin-connected problem rather than an intentional stub.

type Point

type Point struct{ X, Y int64 }

Point is a connection location on the caller's integer grid. The caller is responsible for quantizing native coordinates (e.g. xschem half-integers scaled by 2) so that points meant to coincide are exactly equal.

type Wire

type Wire struct {
	A, B  Point
	Label string
	Id    string
}

Wire is a net segment between two grid points. Label is the net name the segment carries inline (xschem "lab="), or "" when the format leaves wires unnamed (gEDA). Id is the source's native id for the wire (e.g. a KiCad uuid), carried through so a dangling-endpoint diagnostic can point back at the offending wire; "" when the format has no per-wire id.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL