Skip to main content

Crate dune_pic

Crate dune_pic 

Source
Expand description

SPICE netlist extraction from rpic figures (PLAN §2.5; D-0003, D-0004, D-0019, D-0020).

A figure is ordinary pic, compiled by rpic_core as a library, with the spice.pic prelude (embedded; src/spice.pic) loaded after rpic’s std circuit library. The prelude wraps every D-0019 element in a labeled block:

.PS
spice = 1
In: (0,1); Out: (2,1)
V1: vsource(In, (0,0), DC 5)
R1: resistor(In, Out, 1k)
C1: capacitor(Out, (2,0), 1u)
line from C1.N to V1.N; ground(V1.N)
.tran 10u 5m
.PE

extracts to V1 In 0 DC 5, R1 In Out 1k, C1 Out 0 1u, .tran 10u 5m, .end.

Conventions (the contract between the prelude and this crate):

  • refdes = block label; its first letter picks the card type (D-0004 §1), restricted to the D-0019 set R C L V I D Q M J S W X plus the transmission lines T (ideal) and O (LTRA), the controlled sources E F G H, the mutual inductance K (D-0026) and the MESFET Z;
  • pins are circle invis rad 0 shapes labeled P/N, C/B/E (+ the optional substrate S), D/G/S/B, Inp/Inm/Out (the op-amp X), P1 … PN (a generic X of N nodes), Cp/Cn, P1/N1/P2/N2 that are direct children of the element block (D-0020 §c); a K block has no pins, only a Mutual marker;
  • value/model = the macro argument after the pin positions (D-0004 §2: the 3rd of a two-terminal, the 5th of the four-point E/G, the (N+1)th of a generic X of N pins, the 2nd of an element centered on an At anchor; all three arguments of a K, L1 L2 k), read verbatim from the call in the user’s source (1e-9 stays 1e-9). The prelude also draws it (the first text shape in the block); that drawing is presentation, read only as a fallback when the block has no usable call (an inline block, or a wrapper macro whose arguments are not the element’s) and, normalized by pic, to check that the call’s argument really is the element’s value;
  • wires are the visible line/arrow paths outside element and ground blocks; dots are explicit junctions; connectivity rules are in [connect];
  • nets (D-0004 §3): a ground(P) block makes node 0; a named place (Vout: (2,1), Vin: R1.P) that coincides with a net names it — places that share a label are one SPICE node; the rest are n1, n2, … in order of first appearance (lowest shape index);
  • directives (D-0004 §4): column-1 . lines (rpic’s Drawing.passthrough, the troff rule), with their column-1 + continuations, pass through to the netlist in source order; a user .end is dropped and one is appended.

The figure must set spice = 1 (D-0004 §5) or extraction refuses.

Structs§

CanvasOverlay
The page frame of the SVG render_svg draws (issue #19): what maps a point of the compiled drawing — PinOverlay::x/y, in pic inches with y up — to SVG user units (the root viewBox space, 96 per inch, y down). Exactly:
ElementOverlay
One element’s shapes in the compiled drawing (ids sN of the SVG).
ExtractOptions
Options for extract.
Extraction
The result of extract.
NetOverlay
One net’s drawn shapes: its wires and dots, and the ground blocks on it (named places draw nothing).
OverlayMap
Map from netlist names back to rpic objects, for result overlays.
ParamSpanOverlay
One entry of ElementOverlay::params.
PicDiagnostic
A structured extraction diagnostic.
PicRange
A range of the user’s figure source (never the prelude): 1-based lines and columns, as the diagnostics’ PicSpan, from (line, col) to (end_line, end_col), end exclusive. Columns count chars (Unicode scalar values) from the start of the line — not bytes, not UTF-16 code units: a JavaScript consumer indexes a line by code point (Array.from(line)), not by line[i], when the line holds characters outside the BMP. Lines are split at \n.
PicSpan
A position in the figure source (1-based line/column, end exclusive).
PinOverlay
One terminal of an element: where it is drawn and the net it is on.
ValueSpanOverlay
ElementOverlay::value: the value argument’s range and its text.

Enums§

PicDiagKind
What a PicDiagnostic is about.
PicError
Why no netlist could be produced at all.
PicSeverity
Diagnostic severity.

Constants§

DEFAULT_SNAP
Default snap tolerance, in pic inches (PLAN §2.5).
PRELUDE
The embedded dune prelude (src/spice.pic, inside the crate so the packaged crate — the Python sdist, the R vendor tarball — carries it).

Functions§

extract
Extract a SPICE3 netlist from a pic figure.
render_svg
Compile a figure with the prelude and render it to SVG — the drawing whose shape ids OverlayMap refers to. Does not require spice = 1.