Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a9cbef7
Add native schematic and symbol editors with part metadata and fitted…
David-Bascom05 Nov 26, 2026
8458c19
Integrate current schematic backend and retain both regression suites
David-Bascom05 Nov 26, 2026
f5b1086
Merge remote-tracking branch 'origin/feature/schematic-backend' into …
David-Bascom05 Nov 26, 2026
eb3453f
Use the WASI-safe scratch directory and process ID for PDF tests
David-Bascom05 Nov 26, 2026
6b6b201
Insert roles before all local symbols and keep empty footprints grouped
David-Bascom05 Nov 26, 2026
3aec731
Improve schematic fields, label drawings and power symbols
David-Bascom05 Nov 26, 2026
b36b571
Merge branch 'feature/schematic-backend' of https://github.com/David-…
David-Bascom05 Nov 26, 2026
73c5ac6
Move, rotate and mirror the gate that owns the displayed pin
David-Bascom05 Nov 26, 2026
5f4a913
Add schematic pin inspection, signal overlays and grid-aware drawing …
David-Bascom05 Nov 26, 2026
f8e55d6
Use the bundled font for the schematic readability warning
David-Bascom05 Nov 26, 2026
bc28101
Merge remote-tracking branch 'origin/main' into HEAD
David-Bascom05 Nov 26, 2026
8b89433
Toggle schematic no-connect markers on the selected pin
David-Bascom05 Nov 26, 2026
da01a8e
Show pin checklist on selection and highlight the connected rail
David-Bascom05 Nov 26, 2026
e138e62
Make pin role checklists editable in the properties dock
David-Bascom05 Nov 26, 2026
8a53245
Design datasheet-aware pin requirements and alternate functions
David-Bascom05 Nov 26, 2026
cd35c4d
Edit pin names, directions and symbol reference prefixes
David-Bascom05 Nov 26, 2026
dcd6bdf
Check pin voltage wants against connected supply guarantees
David-Bascom05 Nov 26, 2026
31601bf
Show passing and out-of-range supply checks in both editors
David-Bascom05 Nov 26, 2026
e9d1f7c
Assign application-specific connector roles on schematic placements
David-Bascom05 Nov 26, 2026
495e509
Align schematic component controls in the Properties inspector
David-Bascom05 Nov 26, 2026
4c27e95
Check pin-to-pin wants through typed components and named terminal paths
David-Bascom05 Nov 26, 2026
3ca2466
Allow connection wants to refer to pins resolved after placement
David-Bascom05 Nov 26, 2026
59a35f9
Register schematic role editing in language coverage
David-Bascom05 Nov 26, 2026
18a3f6f
Support nested electronics libraries and occurrence-aware schematic c…
David-Bascom05 Nov 26, 2026
0c28ffe
Add library hierarchy, block editing and project review to schematic …
David-Bascom05 Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 151 additions & 4 deletions docs/schematic.md

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions examples/electronics/analog/analog-symbols.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
symbol_library

supply_voltage = role(kind: "power", voltage_range_v: [1.8, 5.5])
bypass = role(kind: "bypass", prefer: 3mm, key: "analog.local_bypass")

Amplifier = symbol(
datasheet: "https://www.ti.com/lit/ds/symlink/tlv9001.pdf",
fields: {Manufacturer: "Texas Instruments", MPN: "TLV9001IDBVR"},
pins: {
INP: pin(description: "Noninverting analog input. Connect the filtered sensor signal here.", number: "3", kind: "input", at: (-7, 3)),
INM: pin(description: "Inverting analog input. Connect the feedback network here.", number: "4", kind: "input", at: (-7, -3)),
OUT: pin(description: "Analog output. Feeds the load and feedback path.", number: "1", kind: "output", at: (9, 0)),
VDD: pin(description: "Positive supply. Bypass to VSS with a capacitor close to the device.", number: "5", kind: "power_in", at: (0, 8), wants: [supply_voltage, bypass]),
VSS: pin(description: "Negative supply. Connect to ground for single-supply operation.", number: "2", kind: "passive", at: (0, -8))
},
graphics: [
polyline(points: [(-4, 6), (7, 0), (-4, -6), (-4, 6)]),
text(at: (-3.2, 2.5), value: "+"), text(at: (-3.2, -3.5), value: "-"),
line(from: (-7, 3), to: (-4, 3)), line(from: (-7, -3), to: (-4, -3)),
line(from: (7, 0), to: (9, 0)), line(from: (0, 8), to: (0, 3.8)),
line(from: (0, -8), to: (0, -3.8))
]
)
Resistor = symbol(part_kind: "resistor", ref_prefix: "R", pins: {
A: pin(number: "1", kind: "passive", at: (-6, 0)),
B: pin(number: "2", kind: "passive", at: (6, 0))
}, graphics: [rect(from: (-3,-1), to: (3,1)), line(from: (-6,0),to:(-3,0)), line(from: (3,0),to:(6,0))])
Capacitor = symbol(part_kind: "capacitor", ref_prefix: "C", pins: {
P: pin(description: "Connect to the rail being bypassed.", number: "1", kind: "passive", at: (0, 4), gives: [bypass]),
N: pin(description: "Connect to the local return.", number: "2", kind: "passive", at: (0, -4))
}, graphics: [line(from:(0,4),to:(0,0.55)),line(from:(-2.5,0.55),to:(2.5,0.55)),
line(from:(-2.5,-0.55),to:(2.5,-0.55)),line(from:(0,-0.55),to:(0,-4))])
Connector2 = symbol(ref_prefix: "J", pins: {
P1: pin(number: "1", kind: "passive", at: (4,0)),
P2: pin(number: "2", kind: "passive", at: (4,-5))
}, graphics: [rect(from: (-3,-7), to: (2,2)), line(from: (2,0), to: (4,0)), line(from: (2,-5), to: (4,-5))])
29 changes: 29 additions & 0 deletions examples/electronics/analog/filter-sheets.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
schematic

analog = library(file: "analog-symbols.fg")
main = sheet(title: "Dual sensor input")
filter_cell = sheet(title: "RC input filter")
left_filter = subsheet(sheet: main, of: filter_cell, at: (-20, 0))
right_filter = subsheet(sheet: main, of: filter_cell, at: (12, 0))

input = port(sheet: filter_cell, at: (-28, 0))
output = port(sheet: filter_cell, at: (22, 0))
power = library(file: "forge:power")
R1 = place(sheet: filter_cell, symbol: analog.Resistor, value: "10 k", at: (-10, 0))
C1 = place(sheet: filter_cell, symbol: analog.Capacitor, value: "10 nF", at: (4, -8))
ground = place(sheet: filter_cell, symbol: power.GND, at: (4, -16))
tap = junction(sheet: filter_cell, at: (4, 0))
w1 = wire(sheet: filter_cell, from: input, to: R1.A)
w2 = wire(sheet: filter_cell, from: R1.B, to: tap)
w3 = wire(sheet: filter_cell, from: tap, to: output)
w4 = wire(sheet: filter_cell, from: tap, to: C1.P)
w5 = wire(sheet: filter_cell, from: C1.N, to: ground.net)
incoming = flow(sheet: filter_cell, from: input, to: R1.A)
filtered = flow(sheet: filter_cell, from: R1.B, to: output)

outline = rect(sheet: filter_cell, from: (-39, -23), to: (33, 15), width: 0.3mm)
heading = note(sheet: filter_cell, at: (-36, 10), value: "Analog input filter", size: 2.8mm, bold: true)
rule = line(sheet: filter_cell, from: (-36, 8), to: (30, 8), width: 0.45mm)
callout = circle(sheet: filter_cell, at: (-27, -13), radius: 2.1mm, width: 0.3mm)
index = note(sheet: filter_cell, at: (-27.6, -13.8), value: "1", size: 1.6mm, bold: true)
caption = note(sheet: filter_cell, at: (-23.8, -13.8), value: "Signal return", size: 1.6mm)
30 changes: 30 additions & 0 deletions examples/electronics/analog/pin-connections.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
schematic

analog = library(file: "analog-symbols.fg")
power = library(file: "forge:power")
main = sheet(title: "Amplifier input and feedback")
supply_voltage = role(kind: "power", voltage_mv: 3300)
feedback = role(kind: "feedback", connect_to: OUT)
input_filter = role(kind: "signal", connect_to: J1.P1, through: analog.Resistor, value_range: ["2.2 kΩ", "4.7 kΩ"])

J1 = place(sheet: main, symbol: analog.Connector2, at: (-34,3))
R1 = place(sheet: main, symbol: analog.Resistor, value: "4.7 kΩ", at: (-15,3))
U1 = place(sheet: main, symbol: analog.Amplifier, at: (6,0), ref_offset: (2.3,5.65), value_offset: (2.3,3.4), wants: {INP: [input_filter], INM: [feedback]})
input_wire = wire(sheet: main, from: J1.P1, to: R1.A)
filtered_wire = wire(sheet: main, from: R1.B, to: U1.INP)
feedback_wire = wire(sheet: main, from: U1.OUT, to: U1.INM, via: [(21,0), (21,-12), (-3,-12), (-3,-3)])

# The sheet receives 3.3 V from the project supply.
supply = place(sheet: main, symbol: power.V3V3, gives: {net: [supply_voltage]}, at: (6,24))
gnd = place(sheet: main, symbol: power.GND, at: (6,-21))
connector_gnd = place(sheet: main, symbol: power.GND, at: (-28,-9))
C1 = place(sheet: main, symbol: analog.Capacitor, value: "100 nF", at: (27,14))
cap_gnd = place(sheet: main, symbol: power.GND, at: (27,7))
rail = junction(sheet: main, at: (6,18))
supply_wire = wire(sheet: main, from: supply.net, to: rail)
vdd_wire = wire(sheet: main, from: rail, to: U1.VDD)
cap_wire = wire(sheet: main, from: rail, to: C1.P)
ground_wire = wire(sheet: main, from: U1.VSS, to: gnd.net)
return_wire = wire(sheet: main, from: J1.P2, to: connector_gnd.net, via: [(-28,-2)])
cap_return = wire(sheet: main, from: C1.N, to: cap_gnd.net)
local_bypass = fulfill(sheet: main, want: U1.VDD, give: C1.P, role: analog.bypass, return_from: C1.N, return_to: U1.VSS)
22 changes: 22 additions & 0 deletions examples/electronics/analog/powered-amplifier.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
schematic

analog = library(file: "analog-symbols.fg")
power = library(file: "forge:power")
main = sheet(title: "Amplifier supply check")

source = role(kind: "power", voltage_mv: 3300)

J1 = place(sheet: main, symbol: analog.Connector2, gives: {P1: [source]}, at: (-23,16))
U1 = place(sheet: main, symbol: analog.Amplifier, at: (3,0), ref_offset: (2.3,5.65), value_offset: (2.3,3.4))
C1 = place(sheet: main, symbol: analog.Capacitor, value: "100 nF", at: (23,12))
vdd = junction(sheet: main, at: (3,16))
gnd = place(sheet: main, symbol: power.GND, at: (3,-16))
source_return = place(sheet: main, symbol: power.GND, at: (-15,8))
cap_return = place(sheet: main, symbol: power.GND, at: (23,6))
feed = wire(sheet: main, from: J1.P1, to: vdd)
input_supply = wire(sheet: main, from: vdd, to: U1.VDD)
bypass_supply = wire(sheet: main, from: vdd, to: C1.P)
input_return = wire(sheet: main, from: U1.VSS, to: gnd.net)
supply_return = wire(sheet: main, from: J1.P2, to: source_return.net, via: [(-15,11)])
bypass_return = wire(sheet: main, from: C1.N, to: cap_return.net)
local_cap = fulfill(sheet: main, want: U1.VDD, give: C1.P, role: analog.bypass, return_from: C1.N, return_to: U1.VSS)
38 changes: 38 additions & 0 deletions examples/electronics/analog/sensor-interface.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
schematic

analog = library(file: "analog-symbols.fg")
power = library(file: "forge:power")
main = sheet(title: "Sensor interface")

R1 = place(sheet: main, symbol: analog.Resistor, value: "10k", footprint: "R_0603", at: (-27, 3))
C1 = place(sheet: main, symbol: analog.Capacitor, value: "10 nF", footprint: "C_0603", at: (-15, -7))
U1 = place(sheet: main, symbol: analog.Amplifier, value: "TLV9001", footprint: "SOT-23-5", ref_offset: (2.3,5.65), value_offset: (2.3,3.4), at: (4, 0))
C2 = place(sheet: main, symbol: analog.Capacitor, value: "100 nF", footprint: "C_0603", at: (23, 18))

input = port(sheet: main, at: (-42,3))
output = port(sheet: main, at: (38,0))
supply = place(sheet: main, symbol: power.V3V3, at: (4,25))
ground = place(sheet: main, symbol: power.GND, at: (4,-19))
cap_ground = place(sheet: main, symbol: power.GND, at: (23,11))
filter = junction(sheet: main, at: (-15,3))
feedback = junction(sheet: main, at: (19,0))
vdd = junction(sheet: main, at: (4,22))
gnd = junction(sheet: main, at: (4,-15))

w1 = wire(sheet: main, from: input, to: R1.A)
w2 = wire(sheet: main, from: R1.B, to: filter)
w3 = wire(sheet: main, from: filter, to: U1.INP)
w4 = wire(sheet: main, from: filter, to: C1.P)
w5 = wire(sheet: main, from: C1.N, to: gnd, via: [(-15,-15)])
w6 = wire(sheet: main, from: U1.OUT, to: feedback)
w7 = wire(sheet: main, from: feedback, to: output)
w8 = wire(sheet: main, from: feedback, to: U1.INM, via: [(19,-11),(-5,-11),(-5,-3)])
w9 = wire(sheet: main, from: U1.VDD, to: vdd)
w10 = wire(sheet: main, from: supply.net, to: vdd)
w11 = wire(sheet: main, from: vdd, to: C2.P)
w12 = wire(sheet: main, from: U1.VSS, to: gnd)
w13 = wire(sheet: main, from: gnd, to: ground.net)
w14 = wire(sheet: main, from: C2.N, to: cap_ground.net)
local_cap = fulfill(sheet: main, want: U1.VDD, give: C2.P, role: analog.bypass, return_from: C2.N, return_to: U1.VSS)
input_stage = flow(sheet: main, from: input, to: R1.A)
filter_stage = flow(sheet: main, from: R1.B, to: U1.INP)
36 changes: 36 additions & 0 deletions examples/electronics/analog/switched-load.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
schematic

analog = library(file: "analog-symbols.fg")
main = sheet(title: "Switched load connections")
load_return = role(kind: "return", connect_to: P2, through: "mosfet", part_path: "channel")
output_cap = role(kind: "bypass", connect_to: P2, through: "capacitor", value: "10 nF")
load_coil = role(kind: "signal", connect_to: J1.P1, through: "inductor", value_range: ["90 uH", "110 uH"])

Switch = symbol(ref_prefix: "Q", part_kind: "mosfet", paths: {channel: [D, S]}, pins: {
D: pin(number: "3", kind: "passive", at: (0,5)),
G: pin(number: "1", kind: "input", at: (-5,0)),
S: pin(number: "2", kind: "passive", at: (0,-5))
}, graphics: [line(from:(0,5),to:(0,2)), line(from:(0,2),to:(-1,2)), line(from:(-1,2),to:(-1,-2)),
line(from:(-1,-2),to:(0,-2)), line(from:(0,-2),to:(0,-5)), line(from:(-2,2),to:(-2,-2)),
line(from:(-5,0),to:(-2,0))])
Coil = symbol(ref_prefix: "L", part_kind: "inductor", pins: {
A: pin(number: "1", kind: "passive", at: (-6,0)), B: pin(number: "2", kind: "passive", at: (6,0))
}, graphics: [line(from:(-6,0),to:(-3,0)),arc(from:(-3,0),mid:(-2,1),to:(-1,0)),
arc(from:(-1,0),mid:(0,1),to:(1,0)),arc(from:(1,0),mid:(2,1),to:(3,0)),line(from:(3,0),to:(6,0))])

J1 = place(sheet: main, symbol: analog.Connector2, at: (16,10), wants: {P1: [load_return, output_cap]})
J2 = place(sheet: main, symbol: analog.Connector2, at: (-35,10), wants: {P1: [load_coil]})
L1 = place(sheet: main, symbol: Coil, at: (-14,10), value: "0.1 mH")
Q1 = place(sheet: main, symbol: Switch, at: (0,0))
C1 = place(sheet: main, symbol: analog.Capacitor, at: (28,0), value: "10 nF")
drain = junction(sheet: main, at: (0,10))
ret = junction(sheet: main, at: (0,-10))
supply = wire(sheet: main, from: J2.P1, to: L1.A)
load = wire(sheet: main, from: L1.B, to: drain)
switch_drain = wire(sheet: main, from: drain, to: Q1.D)
gate_drive = wire(sheet: main, from: J2.P2, to: Q1.G, via: [(-25,5),(-25,0)])
switch_source = wire(sheet: main, from: Q1.S, to: ret)
switched = wire(sheet: main, from: drain, to: J1.P1, via: [(0,17),(23,17),(23,10)])
ground = wire(sheet: main, from: J1.P2, to: ret, via: [(24,5),(24,-10)])
cap_high = wire(sheet: main, from: J1.P1, to: C1.P, via: [(28,10)])
cap_low = wire(sheet: main, from: C1.N, to: ret, via: [(28,-10)])
6 changes: 6 additions & 0 deletions examples/electronics/load-switch/components/catalog.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
symbol_library
discrete = library(file: "discrete/catalog.fg")
Connector = symbol(ref_prefix: "J", part_kind: "connector", pins: {
IN: pin(number: "1", kind: "passive", at: (4,2)),
OUT: pin(number: "2", kind: "passive", at: (4,-2))
}, graphics: [rect(from: (-3,-4), to: (0,4)), line(from: (0,2), to: (4,2)), line(from: (0,-2), to: (4,-2))])
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
symbol_library
switches = library(file: "switches.fg")
13 changes: 13 additions & 0 deletions examples/electronics/load-switch/components/discrete/switches.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
symbol_library
PowerFET = symbol(ref_prefix: "Q", part_kind: "mosfet", paths: {channel: [drain, source]}, fields: {Family: "load switch"}, pins: {
drain: pin(number: "2", pads: ["2","EP"], kind: "passive", at: (-6,0)),
source: pin(number: "3", kind: "passive", at: (6,0)),
gate_in: pin(number: "1", kind: "input", at: (0,-6), description: "Gate drive relative to source.")
}, graphics: [
line(from: (-6,0), to: (-2,0)), line(from: (-2,0), to: (-2,-2)),
line(from: (2,0), to: (6,0)), line(from: (2,0), to: (2,-2)),
line(from: (-2.6,-2), to: (-1.4,-2)), line(from: (-0.6,-2), to: (0.6,-2)),
line(from: (1.4,-2), to: (2.6,-2)), line(from: (-2.6,-2.7), to: (2.6,-2.7)),
line(from: (0,-2.7), to: (0,-6)), line(from: (2,0), to: (0,0)),
line(from: (0,0), to: (0,-2)), polyline(points: [(-0.45,-0.9),(0,-1.8),(0.45,-0.9)])
])
13 changes: 13 additions & 0 deletions examples/electronics/load-switch/switch-card.fg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
schematic
components = library(file: "components/catalog.fg")
frames = library(file: "forge:frames")
switch_path = role(kind: "signal", connect_to: OUT, through: "fet", part_path: "channel")
overview = sheet(title: "Dual load switch", template: frames.A4)
channel = sheet(title: "Load switch channel", template: frames.A4)
left = subsheet(sheet: overview, of: channel, at: (-30,0))
right = subsheet(sheet: overview, of: channel, at: (30,0))
J1 = place(sheet: channel, symbol: components.Connector, at: (-18,0), wants: {IN: [switch_path]})
Q1 = place(sheet: channel, symbol: components.discrete.switches.PowerFET, at: (8,2), footprint: "DFN-3-EP", value: "N-channel")
supply = wire(sheet: channel, from: J1.IN, to: Q1.drain)
load = wire(sheet: channel, from: Q1.source, to: J1.OUT, via: [(19,2),(19,-12),(-10,-12),(-10,-2)])
prototype = variant(omit: ["overview/right/Q1"])
7 changes: 5 additions & 2 deletions examples/electronics/power-symbols.fg
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ MCU = symbol(
vdd: pin(number: "14", kind: "power_in", at: (0, 4), wants: [local_bypass, supply_3v3]),
vss: pin(number: "7", kind: "passive", at: (0, -4))
},
graphics: [rect(from: (-3, -3), to: (3, 3)), text(at: (0, 0), value: "MCU")]
graphics: [rect(from: (-3, -3), to: (3, 3)), line(from: (0, 4), to: (0, 3)),
line(from: (0, -4), to: (0, -3)), text(at: (0, 0), value: "MCU")]
)
Cap = symbol(
ref_prefix: "C",
pins: {
plus: pin(number: "1", kind: "passive", at: (0, 2), gives: [local_bypass]),
minus: pin(number: "2", kind: "passive", at: (0, -2))
},
graphics: [line(from: (-1, 0.3), to: (1, 0.3)), line(from: (-1, -0.3), to: (1, -0.3))]
graphics: [line(from: (-1, 0.3), to: (1, 0.3)), line(from: (-1, -0.3), to: (1, -0.3)),
line(from: (0, 2), to: (0, 0.3)), line(from: (0, -2), to: (0, -0.3))]
)
Reg = symbol(pins: {
out: pin(number: "3", kind: "power_out", at: (2, 0), gives: [supply_3v3], wants: [local_bypass]),
Expand Down
49 changes: 48 additions & 1 deletion interface/forge-cli/src/fg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ impl Session {
}

fn schematic_reply(&mut self, path: &Path, src: &str, words: &[String]) -> Reply {
if words == ["pdf"] {
let result = forge_lang::schematic::compile(src, path.parent(), self.root.as_deref())
.and_then(|(d, c)| forge_lang::schematic::sheet_pdf(&d, &c));
return match result {
Ok(bytes) => Reply {
ok: true,
text: format!("{} bytes", bytes.len()),
json: Json::obj(vec![
("ok", true.into()),
("media_type", "application/pdf".into()),
("mime", "application/pdf".into()),
("format", "pdf".into()),
("version", version(src).into()),
]),
png: Some(bytes),
},
Err(e) => Reply {
ok: false,
text: e.message.clone(),
json: e.json(),
png: None,
},
};
}
let result = self.schematic.query(path, self.root.as_deref(), src, words);
let ok = result.is_ok();
let mut json = result.unwrap_or_else(|err| err.json());
Expand Down Expand Up @@ -423,7 +447,11 @@ impl Session {
post: p.post.clone(),
text: p.text.clone(),
error: p.error.clone(),
certified: if p.text.is_none() { "no".into() } else { cert.clone() },
certified: if p.text.is_none() {
"no".into()
} else {
cert.clone()
},
setup: None,
})
.collect()
Expand Down Expand Up @@ -1153,6 +1181,25 @@ impl Session {
let Some(other) = a.words.first() else {
return Err("diff takes two parts: diff A B [volume]".into());
};
let (path, src) = self.read(&a.file)?;
if forge_lang::schematic::is_document(&src) {
let (other_path, other_src) = self.read(other)?;
let read = |p: &Path, s: &str| {
forge_lang::schematic::compile(s, p.parent(), self.root.as_deref())
.map_err(|e| format!("{} · {}", e.kind, e.message))
};
let (old, oc) = read(&path, &src)?;
let (new, nc) = read(&other_path, &other_src)?;
let changes =
forge_lang::schematic::electrical_diff((&old, &oc), (&new, &nc)).map_err(|e| e.message)?;
let json = Json::obj(vec![("ok", true.into()), ("changes", changes)]);
return Ok(Reply {
ok: true,
text: json.to_string(),
json,
png: None,
});
}
let side = |file: &str| -> Result<forge_lang::compare::Side, String> {
let (p, text) = self.read(file)?;
let opts = Options {
Expand Down
12 changes: 8 additions & 4 deletions interface/forge-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,23 +784,27 @@ fn command(cmd: &str, argv: &[String]) -> ExitCode {
let r = fg::Session::new(None, true).run(cmd, &a, &forge_agent::json::Json::Null);
let mut text = if json { r.json.to_string() } else { r.text };
if cmd == "schematic"
&& matches!(a.words.first().map(String::as_str), Some("svg" | "symbol-svg"))
&& let Some(svg) = r.json.get("result").and_then(forge_agent::json::Json::str)
&& matches!(
a.words.first().map(String::as_str),
Some("svg" | "symbol-svg" | "bom-csv")
)
&& let Some(content) = r.json.get("result").and_then(forge_agent::json::Json::str)
{
if let Some(path) = out.as_deref() {
if let Err(e) = std::fs::write(path, svg) {
if let Err(e) = std::fs::write(path, content) {
eprintln!("writing {path}: {e}");
return ExitCode::FAILURE;
}
if !json {
text = format!("wrote {path}");
}
} else if !json {
text = svg.to_owned();
text = content.to_owned();
}
}
if let Some(png) = &r.png {
let ext = match cmd {
"schematic" if a.words == ["pdf"] => "pdf",
"export" if a.words.first().is_some_and(|w| w == "dxf") => "dxf",
"export" if a.words.first().is_some_and(|w| w == "dwg") => "dwg",
"export" if a.words.first().is_some_and(|w| w == "stl") => "stl",
Expand Down
Loading
Loading