render

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: 10 Imported by: 1 module, 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 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

View Source
const DefaultHighlightColor = "#ed1cb8"

DefaultHighlightColor is the color a highlight spec with no color gets, a saturated magenta that stands out against the schematic palette. It lives here so every drawable color stays in one file (C12), and the web mirror is DEFAULT_HIGHLIGHT_COLOR in web/src/highlights.ts.

View Source
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. Arial leads because the authoring tools this engine reads print in it. 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

View Source
var DarkStyle = Style{
	Wire:           "#4ade80",
	Bus:            "#60a5fa",
	Symbol:         "#e5e5e5",
	Pin:            "#f87171",
	Frame:          "#b0895a",
	Free:           "#bbbbbb",
	Field:          "#7aa2f7",
	Label:          "#aaaaaa",
	Annotation:     "#dddddd",
	Ruler:          "#b0895a",
	PinName:        "#5eead4",
	ShapeFill:      "#1a1a1a",
	Page:           "#111111",
	BoardOutline:   "#b0895a",
	CopperFront:    "#f87171",
	CopperBack:     "#7aa2f7",
	CopperInner:    "#9aa0a6",
	Via:            "#c0c6cc",
	Silk:           "#aab0bb",
	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.

View Source
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",
	ShapeFill:      "#fdf6d0",
	Page:           "#fdfdfb",
	BoardOutline:   "#8a6d3b",
	CopperFront:    "#c83434",
	CopperBack:     "#3050c8",
	CopperInner:    "#8a8a8a",
	Via:            "#9aa0a6",
	Silk:           "#7a7f88",
	TitleBlockFill: "#fffef8",
	Font:           SchematicFontStack,
}

DefaultStyle is the built-in palette and font. Override per render call with WithStyle.

View Source
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 BoardSVG

func BoardSVG(b *geom.BoardGeometry, opts ...Option) string

BoardSVG renders a board (the WS1-006 geometry sidecar) to a standalone SVG document, the board analogue of SheetSVG (the packed/WebGL tier is WS7-035). 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 layer visibility is client-side CSS with no re-render, and HighlightBoardSVG overlays share the same frame.

Coordinates are the sidecar's, nanometers and Y-up (the reader flips). Rotations arrive already in the Y-up frame (see padWorld) and are negated 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, so a caller rendering per-sheet (a review report annotating only the sheets its findings land on) can skip a sheet no finding touches instead of writing an unannotated copy. It reuses collectEntities, so "would highlight" agrees with what SheetSVGHighlighted draws.

func HighlightBoardSVG

func HighlightBoardSVG(b *geom.BoardGeometry, specs []*geom.HighlightSpec) 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). 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 and returns, per spec (same order), the indices of the primitives it selects plus the spec's style. The caller redraws those primitives above the base geometry; no vertices are duplicated, the group joins PackedSheet.vertices/primitives by index. An element matched by several specs belongs to each matching group; paint order (later spec wins) is the renderer's job.

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 its entities draw with (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: rebased int32 vertices (sheet-relative to the min corner, so GLSL ES's 32-bit attributes are exact), a fixed-width primitives table, and PrimitiveKeys back to ref_des/net for picking. 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. It 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, so a static render (a report image, a shared file) carries its annotations with no separate overlay. It is the base render (drawSheetContent) plus the same projection (drawHighlights) the HighlightSheet rpc serves as an overlay, on one canvas since both share frameSheet. Highlights draw LAST, above the schematic, so the marked entity reads through the translucent shapes.

Types

type Option

type Option func(*Style)

Option configures one render call. With no options a render uses DefaultStyle.

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). Options apply in order and WithStyle replaces the whole Style, so pass this after any WithStyle or the preset turns the dots back off.

func WithStyle

func WithStyle(s Style) Option

WithStyle overrides the palette and font for one render call.

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)

	// 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, and
	// inner layers share one muted tone. Via colors the barrel ring and through-hole pad lands,
	// and a drill hole is drawn in Page.
	BoardOutline string // Edge.Cuts outline
	CopperFront  string // F.Cu segments, SMD pads on the front
	CopperBack   string // B.Cu
	CopperInner  string // any other signal layer
	Via          string // via rings + through-hole pad lands
	Silk         string // silkscreen / fab body-outline graphics (WS7)

	// 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. See docsite/content/architecture/web-picking.md.
	PickTargets bool
}

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

func (s Style) GroupColor(group uint8) string

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.

Jump to

Keyboard shortcuts

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