Documentation
¶
Overview ¶
Package render turns the geometry sidecar (agni.v1.geom) into drawable output. It is core, runtime-agnostic Go (CONSTRAINTS C1), taking the geom proto and returning bytes or strings with no syscall/js, no file paths, and no DB handles. The same code backs the SVG dumper, the netlist-vs-geometry oracle, and the WebGL vertex packer (pack.go). Placement transform math lives in internal/geomath, shared with the readers that compute pin world positions (C17).
Index ¶
- Constants
- Variables
- func BoardLayers(b *geom.BoardGeometry, opts ...Option) []*geom.BoardLayerRow
- func BoardSVG(b *geom.BoardGeometry, opts ...Option) string
- func HasHighlights(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, ...) bool
- func HighlightBoardSVG(b *geom.BoardGeometry, specs []*geom.HighlightSpec, opts ...Option) string
- func HighlightPacked(sheet *geom.PackedSheet, specs []*geom.HighlightSpec) *geom.PackedHighlight
- func HighlightSVG(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, ...) string
- func PackBoard(b *geom.BoardGeometry, opts ...Option) *geom.PackedSheet
- func PackSheet(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, opts ...Option) *geom.PackedSheet
- func PickSheet(g *geom.SchematicGeometry, sel string) (*geom.SheetGeometry, error)
- func SheetIndex(g *geom.SchematicGeometry, sheet *geom.SheetGeometry) int
- func SheetSVG(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, opts ...Option) string
- func SheetSVGHighlighted(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, ...) string
- type BoardNet
- type NetIDFunc
- type Option
- type Style
Constants ¶
const DefaultHighlightColor = "#ed1cb8"
DefaultHighlightColor is the color of a highlight spec that names none. It is a saturated magenta that stands out against the schematic palette. It lives here so every drawable color is in one file (C12), and the web mirror is DEFAULT_HIGHLIGHT_COLOR in web/src/highlights.ts.
const SchematicFontStack = "Arial, 'Liberation Sans', Helvetica, sans-serif"
SchematicFontStack is the default font-family for schematic text, a CSS fallback chain the viewer resolves locally. This engine reads files from authoring tools that print in Arial, so Arial leads. Liberation Sans is metric-compatible with Arial, so a machine without Arial lays text out at identical advance widths. See docsite/content/architecture/geometry-and-rendering.md#the-font-is-a-name-never-a-file.
Family names are SINGLE-quoted because svg.Attr writes its value verbatim inside double quotes, so a double-quoted name would emit invalid XML on the SVG root element.
Variables ¶
var DarkStyle = Style{ Wire: "#4ade80", Bus: "#60a5fa", Symbol: "#e5e5e5", Pin: "#f87171", Frame: "#b0895a", Free: "#bbbbbb", DNP: "#f87171", Field: "#7aa2f7", Label: "#aaaaaa", Annotation: "#dddddd", Ruler: "#b0895a", PinName: "#5eead4", ShapeFill: "#1a1a1a", Page: "#111111", BoardOutline: "#b0895a", CopperFront: "#f87171", CopperBack: "#7aa2f7", CopperInner: "#9aa0a6", CopperInners: [6]string{"#f5b942", "#4fc98a", "#b98ae0", "#4ec3cf", "#e0955a", "#b3c25a"}, Via: "#c0c6cc", Silk: "#aab0bb", Fab: "#6b717c", TitleBlockFill: "#1a1a1a", Font: SchematicFontStack, }
DarkStyle is a dark-background preset. A WithStyle override recolors every surface (SVG, WebGL geometry and the text overlay) from one palette.
var DefaultStyle = Style{ Wire: "#0a7d2c", Bus: "#1a4de0", Symbol: "#222222", Pin: "#dd1111", Frame: "#8a6d3b", Field: "#1560bd", Label: "#555555", Annotation: "#333333", Ruler: "#8a6d3b", PinName: "#2a7d5a", Free: "#333333", DNP: "#d42020", ShapeFill: "#fdf6d0", Page: "#fdfdfb", BoardOutline: "#8a6d3b", CopperFront: "#c83434", CopperBack: "#3050c8", CopperInner: "#8a8a8a", CopperInners: [6]string{"#c08a1e", "#2f8f5b", "#8a4fb0", "#1f8a96", "#a8642f", "#6f7d2a"}, Via: "#9aa0a6", Silk: "#7a7f88", Fab: "#b4b8bf", TitleBlockFill: "#fffef8", Font: SchematicFontStack, }
DefaultStyle is the built-in palette and font. Override per render call with WithStyle.
var Themes = map[string]Style{"default": DefaultStyle, "dark": DarkStyle}
Themes maps a theme name to its Style, for the `agni serve --theme` knob.
Functions ¶
func BoardLayers ¶ added in v0.6.0
func BoardLayers(b *geom.BoardGeometry, opts ...Option) []*geom.BoardLayerRow
BoardLayers lists a board's layer rows, in the order the viewer's Sheets panel shows them. Each row carries the selector and the packed groups that hide it in BoardSVG's and PackBoard's output under the same style.
func BoardSVG ¶
func BoardSVG(b *geom.BoardGeometry, opts ...Option) string
BoardSVG renders a board to a standalone SVG document. The board is the WS1-006 geometry sidecar, and BoardSVG is the board analogue of SheetSVG. WS7-035 is the packed/WebGL tier. Copper draws per layer back-to-front so the front side reads on top. Every stratum goes into a classed <g> (edge, copper-front, copper-back, copper-inner, through, zones-*, silk, labels), so client-side CSS sets layer visibility with no re-render. HighlightBoardSVG overlays share the same frame.
Coordinates are the sidecar's, in nanometers and Y-up, because the reader flips them. Rotations arrive already in the Y-up frame (see padWorld), and BoardSVG negates them only for the SVG transform. Pad positions are footprint-local per the proto contract.
func HasHighlights ¶
func HasHighlights(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, specs []*geom.HighlightSpec) bool
HasHighlights reports whether any spec matches at least one entity drawn on this sheet. A caller rendering per sheet can then skip a sheet that no finding touches, instead of writing an unannotated copy. A review report does this, and annotates only the sheets that show its findings. HasHighlights reuses collectEntities, so "would highlight" agrees with what SheetSVGHighlighted draws.
func HighlightBoardSVG ¶
func HighlightBoardSVG(b *geom.BoardGeometry, specs []*geom.HighlightSpec, opts ...Option) string
HighlightBoardSVG resolves highlight specs against a board and returns a transparent SVG overlay framed like BoardSVG (both use frameBoard), which a client stacks above the base document. It is the board face of the WS9-016 highlight contract. A listed NET matches its routed copper (segments re-stroked wider, vias ringed) and every pad on it, a listed COMPONENT matches all its pads plus a marker ring at the placement origin, and a listed pin matches that (ref_des, pad number). A net listed by id matches through the render's WithNetIDs, since the board names its nets and holds no schematic ids. Specs paint in order, later wins.
func HighlightPacked ¶
func HighlightPacked(sheet *geom.PackedSheet, specs []*geom.HighlightSpec) *geom.PackedHighlight
HighlightPacked resolves highlight specs against one packed sheet. For each spec, in the same order, it returns the indices of the primitives the spec selects plus the spec's style. The caller redraws those primitives above the base geometry. No vertices are duplicated, because the group joins PackedSheet.vertices/primitives by index. An element matched by several specs belongs to each matching group. The renderer owns paint order, where a later spec wins.
func HighlightSVG ¶
func HighlightSVG(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, specs []*geom.HighlightSpec) string
HighlightSVG resolves highlight specs against one tier-1 sheet and returns a standalone transparent SVG overlay with the exact size, viewBox, and world->pixel mapping of SheetSVG (both use frameSheet), so it stacks or composites onto the base document. Specs paint in order, so a later spec wins where selections overlap. Each spec's shape picks the strategy that draws its entities (outline when unset).
func PackBoard ¶
func PackBoard(b *geom.BoardGeometry, opts ...Option) *geom.PackedSheet
PackBoard projects the board sidecar into the tier-2 packed form (WS7-035), the board analogue of PackSheet in the same envelope. Copper is keyed by net and pads by (ref_des, pad number, net), so HighlightPacked and the web's resolveHighlights join unchanged. The front/back/inner strata are distinct groups, so a renderer hides a layer by skipping its group. See docsite/content/architecture/geometry-and-rendering.md#board-geometry-sidecar.
func PackSheet ¶
func PackSheet(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, opts ...Option) *geom.PackedSheet
PackSheet projects one tier-1 sheet into the tier-2 PackedSheet columnar form. That form holds rebased int32 vertices, a fixed-width primitives table, and PrimitiveKeys back to ref_des/net for picking. The vertices are relative to the sheet's min corner, so GLSL ES's 32-bit attributes are exact. This is a derived projection of the sidecar, computed on demand, not stored.
func PickSheet ¶
func PickSheet(g *geom.SchematicGeometry, sel string) (*geom.SheetGeometry, error)
PickSheet resolves a sheet selector (a numeric index, a sheet id or a sheet name) against a schematic's sheets. An id or name match wins over an index, so a single-sheet format that ids its page "1" is still selectable by that id. It does no I/O, and both the CLI render command and the web design service call it.
func SheetIndex ¶
func SheetIndex(g *geom.SchematicGeometry, sheet *geom.SheetGeometry) int
SheetIndex returns the 0-based position of sheet in the geometry's sheet list, or 0 if not found. It maps a selected sheet to a tool's 1-based page order (the native renderer).
func SheetSVG ¶
func SheetSVG(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, opts ...Option) string
SheetSVG renders one schematic sheet to a standalone SVG document, resolving each placement against the design's symbol library. SheetSVG and the WebGL2 path (WS7-001) are both backends over the same render layer, so nothing here is WebGL- or format-bound. Coordinates are framed by frameSheet, which normalizes them to pixels and flips Y.
func SheetSVGHighlighted ¶
func SheetSVGHighlighted(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, specs []*geom.HighlightSpec, opts ...Option) string
SheetSVGHighlighted renders one sheet and BAKES the highlight specs into a single SVG document. A static render, such as a report image or a shared file, then holds its annotations with no separate overlay. SheetSVGHighlighted runs the base render (drawSheetContent) and then drawHighlights, the projection the HighlightSheet rpc serves as an overlay. Both share frameSheet, so they draw on one canvas. Highlights draw LAST, above the schematic, so the marked entity reads through the translucent shapes.
Types ¶
type BoardNet ¶ added in v0.6.1
BoardNet is one board net as a NetIDFunc sees it. Name is the net's name on the board. Pins lists every pad on the net as (ref-des, pad number), sorted, so a resolver can join the net by its connections when the name does not join it.
type NetIDFunc ¶ added in v0.6.1
NetIDFunc answers the schematic net id (ir.Net.id) of one board net, or "" when it cannot say which net that is. A board file names its nets and carries no schematic id, so a board render asks the caller, which holds the design (agni issue 1440). A net answered "" keeps its name as its only key, as before.
type Option ¶
type Option func(*Style)
Option configures one render call. With no options a render uses DefaultStyle.
func WithNetIDs ¶ added in v0.6.1
WithNetIDs has a board render ask f for each net's schematic net id, and key the net's copper and pads with it (see NetIDFunc).
func WithPickTargets ¶ added in v0.2.0
func WithPickTargets() Option
WithPickTargets emits the invisible per-pin pick targets (see Style.PickTargets). The served viewer asks for them; a render destined for a file or a report does not.
func WithPinDots ¶
func WithPinDots() Option
WithPinDots turns the per-pin verification dots on for one render call (see Style.PinDots).
type Style ¶
type Style struct {
// Geometry line/stroke colors.
Wire string // wire polylines
Bus string // bus trunks / entries (WS7-042), drawn thicker than a wire
Symbol string // symbol graphics stroke (and dots)
Pin string // pin connect dots
Frame string // worksheet frame + zone-ruler tick lines
Free string // sheet-level free graphics (junction dots, no-connects, notes)
DNP string // the cross over a do-not-populate part (agni 1344)
// Text colors.
Field string // ref-des / value / custom placement fields
Label string // sheet labels (net labels, page text)
Annotation string // symbol annotations and title-block field text
Ruler string // zone-ruler numbers/letters and pin numbers
PinName string // pin names
// Fill colors.
ShapeFill string // default fill for a filled symbol shape
Page string // page background
TitleBlockFill string // title-block box fill
// Board colors (WS7-034). Copper follows KiCad's habit of front red and back blue. Each inner
// layer takes the next colour of CopperInners in stack order, so In1.Cu and In2.Cu read apart
// (agni issue 1401). CopperInner colours a layer past the packed group limit, and every inner
// layer when CopperInners is empty. Via colors the barrel ring and through-hole pad lands, and a
// drill hole is drawn in Page. CopperInners is an array rather than a slice, so a Style still
// compares with ==, and a blank entry ends the palette.
BoardOutline string // Edge.Cuts outline
CopperFront string // F.Cu segments, SMD pads on the front
CopperBack string // B.Cu
CopperInner string // an inner layer with no colour of its own
CopperInners [6]string // the inner layers' colours, from the front, repeating past the last set one
Via string // via rings + through-hole pad lands
Silk string // silkscreen graphics and text (WS7)
Fab string // fab-layer graphics and text, such as body outlines and values (agni issue 1366)
// Font is the default font-family for all text, a CSS family list rather than one face
// (see SchematicFontStack). There is no per-element font.
Font string
// PinDots draws a dot at every pin connect-point in the Pin color, a verification aid for
// the pin-on-wire eyeball check. Off by default because Eeschema draws no such dots and a
// hardware engineer reads them as noise (WS7-017). Real junction dots are sheet Shapes and
// draw regardless.
PinDots bool
// PickTargets emits an invisible, keyed circle at every pin so a viewer can CLICK a pin,
// plus a wide invisible companion stroke per wire. Off by default because a pin has no drawn
// element of its own, so the targets are ADDED elements, one per pin, and on a large sheet
// they are the biggest single contributor to document size. Only the served viewer asks for
// them. On a board it keys every pad, track, via, zone and footprint graphic, and adds one
// invisible rect per footprint (BoardSVG). See docsite/content/architecture/web-picking.md.
PickTargets bool
// contains filtered or unexported fields
}
Style is the render layer's color palette and default font. The SVG backend and the WebGL path both resolve colors from one Style, and a caller overrides the defaults (theming, dark mode, accessibility) with WithStyle. Colors are "#rrggbb" and Font is a CSS/SVG font-family.
func (Style) GroupColor ¶
GroupColor returns the geometry color for a schematic primitive group (groupSymbol through groupFrame, and groupBus). The SVG backend picks per shape and the packer sends the set to WebGL as PackedSheet.group_colors. Unknown groups, including the board strata, fall back to Symbol; boards use boardGroupColors.