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
.PEextracts 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 Xplus the transmission linesT(ideal) andO(LTRA), the controlled sourcesE F G H, the mutual inductanceK(D-0026) and the MESFETZ; - pins are
circle invis rad 0shapes labeledP/N,C/B/E(+ the optional substrateS),D/G/S/B,Inp/Inm/Out(the op-ampX),P1…PN(a genericXof N nodes),Cp/Cn,P1/N1/P2/N2that are direct children of the element block (D-0020 §c); aKblock has no pins, only aMutualmarker; - 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 genericXof N pins, the 2nd of an element centered on anAtanchor; all three arguments of aK,L1 L2 k), read verbatim from the call in the user’s source (1e-9stays1e-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/arrowpaths outside element and ground blocks; dots are explicit junctions; connectivity rules are in [connect]; - nets (D-0004 §3): a
ground(P)block makes node0; 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 aren1, n2, …in order of first appearance (lowest shape index); - directives (D-0004 §4): column-1
.lines (rpic’sDrawing.passthrough, the troff rule), with their column-1+continuations, pass through to the netlist in source order; a user.endis dropped and one is appended.
The figure must set spice = 1 (D-0004 §5) or extraction refuses.
Structs§
- Canvas
Overlay - The page frame of the SVG
render_svgdraws (issue #19): what maps a point of the compiled drawing —PinOverlay::x/y, in pic inches with y up — to SVG user units (the rootviewBoxspace, 96 per inch, y down). Exactly: - Element
Overlay - One element’s shapes in the compiled drawing (ids
sNof the SVG). - Extract
Options - 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).
- Overlay
Map - Map from netlist names back to rpic objects, for result overlays.
- Param
Span Overlay - 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 byline[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.
- Value
Span Overlay ElementOverlay::value: the value argument’s range and its text.
Enums§
- PicDiag
Kind - What a
PicDiagnosticis 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
OverlayMaprefers to. Does not requirespice = 1.