Skip to main content

Module schematic

Module schematic 

Source
Expand description

A SCHEMATIC IN RUST — the circuit’s own schematic sheet, declared as the nodes the CommandAGI circuit editor draws and edits (sch.symbol.*, sch.wire, sch.junction, sch.label), and a netlist circuit’s parts and nets. The same declarations, node for node, as the TypeScript SDK’s JSX schematic (sheet.ts) and the Python SDK’s (schematic.py). Each element is one constructor call, its attributes the methods chained on it, a group’s elements an array:

use commandagi::design::schematic::*;

fn document() -> El {
    group("Divider", [
        voltagesource("V1").voltage("9").sch_x(114.3).sch_y(114.3),
        resistor("R1").resistance("3k").sch_x(114.3).sch_y(88.9),
        resistor("R2").resistance("1.5k").sch_x(139.7).sch_y(88.9).sch_rotation(90),
        ground("#PWR1").sch_x(139.7).sch_y(114.3),
        trace(".V1 > .pos", ".R1 > .pin1"),
        netlabel("OUT", ".R1 > .pin2"),
    ])
}

The elements:

group(name, [ … ])                                                        the schematic (the root)
resistor|capacitor|inductor(name).resistance|capacitance|inductance(…)   an ideal two-terminal part
voltagesource|currentsource(name).voltage|current(…).excitation(json(…)) an ideal source: pin 1 (`pos`) is +
ground(name)                                                              a ground symbol (name "#PWR1"): net GND
… .sch_x(…).sch_y(…).sch_rotation(…).sch_mirror(…).sch_style(…)           where its symbol sits on the sheet
junction(name).sch_x(…).sch_y(…)                                          a wire vertex
trace(from, to)                                                           a wire between two selectors:
                                                                          ".R1 > .pin2", ".J1" (a junction),
                                                                          "net.GND" (a label naming that net);
                                                                          `.path([from, …, to])`: wires through
                                                                          more selectors
netlabel(net, connection)                                                 a label naming the net of a pin
part(name).symbol("Lib:Name").library("x.kicad_sym").value(…)            a library part: its symbol named by its
                                                                          library ref in a .kicad_sym, by path
unit(part, n).sch_x(…).sch_y(…).sch_style(…)                              where unit n (2 or more) of a part sits;
                                                                          the part's own sch_x, sch_y place unit 1
code(name).source(path).inputs(json(…)).suppressed(…)                    a code part: the parts another file
                                                                          declares, run with these inputs; a
                                                                          suppressed one (true) is not run and
                                                                          declares nothing
part(name).pins(["1", "2"]).value(…).symbol(…)                            a part of a netlist circuit (no sheet):
                                                                          its pins by number, or
                                                                          json(r#"[{"number": "1", "name": "VBAT"}]"#);
                                                                          [] for a board-only footprint (a logo)
net(name).pins([".C1 > .pin1", ".U1 > .pin6"])                           a stored net of a netlist circuit
… .reference("POLY")                                                     on any part: KiCad's reference when another
                                                                          part has it too; the name stays the part's
                                                                          own (POLY_2). Said only when it is not
                                                                          the name
… .no_connect(["3", "4"])                                                on any part: the pins it leaves open on
                                                                          purpose, by pin NUMBER (KiCad's no-connect
                                                                          marker); the electrical rule check does
                                                                          not report them as pins on nothing
… .spice(json(r#"[{"id", "model", "terminals"}]"#))                       on any part: the vendor SPICE packages it
                                                                          binds, each formal by pin NUMBER
… .part_number(…).manufacturer(…).mpn(…).rating(…).draw("120 mA")        on any part but a ground: its engineering
  .attrs(json(r#"{"Tolerance": "1%"}"#))                                  data, each a KiCad property of the part
                                                                          (CommandAGI IPN, Manufacturer, MPN, Rating,
                                                                          its steady draw, and attrs by their own
                                                                          names): the BOM and the board's footprint
                                                                          carry them
… .pinout_verified(…).footprint_verified(…).package_dimensions(…)        on any part: how its pinout and its pads
                                                                          are known ("memory", "datasheet <url> p.
                                                                          <page>, <YYYY-MM-DD>", "measured
                                                                          <YYYY-MM-DD>[, <how>]") and its datasheet
                                                                          package ("<n> pins, pitch <mm> mm, body
                                                                          <l> x <w> mm"), read by the pinout and
                                                                          footprint checks
… .suppliers(json(…)).alternates(json(…)).need(json(…)).datasheet(…)    its logistics, as KiCad properties too
  .lifecycle(json(…)).compliance(json(…)).shipping(json(…))               (`super::part_fields`: LCSC Part, Need,
                                                                          Datasheet, RoHS, HS Code …)
attachment(name).role("schematic").file(path).mime(…)                     a KiCad file the circuit carries
check().id(…).kind("erc").severity(…)                                     a check the circuit must pass, and a
accept().id(…).check(…).rule(…).refs([…]).net(…).reason(…)               finding it accepts on purpose: kept in
                                                                          the graph's meta (`checks`, `accepted`),
                                                                          not as nodes (`super::circuit_checks`)
fragment(iter)                                                            several elements as one item (a loop)

sch_x and sch_y are the sheet’s own coordinates: millimetres, Y DOWN. sch_rotation is 0, 90, 180 or 270 degrees; sch_mirror is “x” or “y”; sch_style is the De Morgan body style the placement shows (1, the format’s default, unless the file says another). A part with neither is declared and not placed. A library part’s pins are the library’s: the editor reads them, and binds a pin named by number (“.U1 > .pin5”) to the unit that has it. A wire is a binding between two pins, never a coincidence of coordinates. Each node carries the call it came from in meta.source (super::source), so the circuit editor writes its edits back into the file. What the sheet cannot say is refused by name, never guessed.

Re-exports§

pub use super::part_fields::part_fields;
pub use super::part_fields::FACET_FIELDS;
pub use super::part_fields::PART_FIELDS;
pub use super::fragment;
pub use super::json;
pub use super::json;
pub use super::El;
pub use super::Json;
pub use super::Value;

Constants§

ATTACHMENT
A file the circuit carries for exchange (the circuit editor reads its text from file).
LIBRARY_PIN_PORT
A library part’s wire end before the editor reads its library: the part node, and the pin by number.
NET
A stored net (a netlist circuit’s): its pins on channel pins.
SCH_JUNCTION
SCH_LABEL
SCH_WIRE

Traits§

SchematicAttrs
The schematic’s attributes, chained on its elements.

Functions§

accept
A finding the circuit accepts on purpose: accept().id("tp").check("erc").rule("pin_not_connected").reason(…).
attachment
A KiCad file the circuit carries for exchange: attachment("Divider.kicad_sch").role("schematic").file(…).
capacitor
An ideal capacitor: capacitor("C1").capacitance("100n").
check
A check the circuit must pass: check().id("erc").kind("erc") (super::circuit_checks).
code
A code part: code("blinker").source("blinker.circuit.ts").inputs(json(r#"{"resistor": "330"}"#)).
currentsource
An ideal current source: currentsource("I1").current("1m"); pin 1 (pos) is +.
ground
A ground symbol (its name starts with #, as KiCad names power symbols): its net is GND.
group
The schematic: its name and its elements.
inductor
An ideal inductor: inductor("L1").inductance("10u").
junction
A wire vertex at (sch_x, sch_y).
net
A stored net of a netlist circuit: net("VCC").pins([".C1 > .pin1", ".U1 > .pin8"]).
netlabel
A label naming the net of a pin: netlabel("OUT", ".R1 > .pin2").
part
A library part (.symbol("Lib:Name").library("x.kicad_sym")), or a netlist circuit’s part (.pins([…])).
part_type_for
A part’s node type: eda.part. + FNV-1a over each pin’s id\0label, pins joined by \x01 (the engine’s rule). A pin is its id, its number and its name.
resistor
An ideal resistor: resistor("R1").resistance("3k").
sch_symbol_type_for
A placement’s node type: sch.symbol. + FNV-1a over its pin sockets joined by NUL (part of the format).
trace
A wire between two selectors: trace(".V1 > .pos", ".R1 > .pin1").
unit
Where unit unit (2 or more) of a part sits: unit("U1", 2).sch_x(101.6).sch_y(25.4).
voltagesource
An ideal voltage source: voltagesource("V1").voltage("9"); pin 1 (pos) is +.