circuit-json-to-spice 0.0.23 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,190 @@
1
+ [
2
+ {
3
+ "type": "source_project_metadata",
4
+ "source_project_metadata_id": "source_project_metadata_0",
5
+ "software_used_string": "@tscircuit/core@0.0.874"
6
+ },
7
+ {
8
+ "type": "source_group",
9
+ "source_group_id": "source_group_0",
10
+ "is_subcircuit": true,
11
+ "was_automatically_named": true,
12
+ "subcircuit_id": "subcircuit_source_group_0"
13
+ },
14
+ {
15
+ "type": "source_port",
16
+ "source_port_id": "source_port_0",
17
+ "name": "pin1",
18
+ "pin_number": 1,
19
+ "port_hints": ["pin1", "anode", "pos", "left", "1"],
20
+ "source_component_id": "source_component_0",
21
+ "subcircuit_id": "subcircuit_source_group_0"
22
+ },
23
+ {
24
+ "type": "source_port",
25
+ "source_port_id": "source_port_1",
26
+ "name": "pin2",
27
+ "pin_number": 2,
28
+ "port_hints": ["pin2", "cathode", "neg", "right", "2"],
29
+ "source_component_id": "source_component_0",
30
+ "subcircuit_id": "subcircuit_source_group_0",
31
+ "subcircuit_connectivity_map_key": "unnamedsubcircuit4_connectivity_net0"
32
+ },
33
+ {
34
+ "type": "source_component",
35
+ "source_component_id": "source_component_0",
36
+ "ftype": "simple_resistor",
37
+ "name": "R1",
38
+ "resistance": 1000,
39
+ "display_resistance": "1kΩ",
40
+ "are_pins_interchangeable": true,
41
+ "source_group_id": "source_group_0"
42
+ },
43
+ {
44
+ "type": "source_net",
45
+ "source_net_id": "source_net_0",
46
+ "name": "GND",
47
+ "member_source_group_ids": [],
48
+ "is_ground": true,
49
+ "is_power": false,
50
+ "is_positive_voltage_source": false,
51
+ "subcircuit_id": "subcircuit_source_group_0",
52
+ "subcircuit_connectivity_map_key": "unnamedsubcircuit4_connectivity_net0"
53
+ },
54
+ {
55
+ "type": "source_board",
56
+ "source_board_id": "source_board_0",
57
+ "source_group_id": "source_group_0"
58
+ },
59
+ {
60
+ "type": "source_trace",
61
+ "source_trace_id": "source_trace_0",
62
+ "connected_source_port_ids": ["source_port_1"],
63
+ "connected_source_net_ids": ["source_net_0"],
64
+ "subcircuit_id": "subcircuit_source_group_0",
65
+ "display_name": ".R1 > .pin2 to net.GND",
66
+ "subcircuit_connectivity_map_key": "unnamedsubcircuit4_connectivity_net0"
67
+ },
68
+ {
69
+ "type": "source_pin_missing_trace_warning",
70
+ "source_pin_missing_trace_warning_id": "source_pin_missing_trace_warning_0",
71
+ "message": "Port pin1 on R1 is missing a trace",
72
+ "source_component_id": "source_component_0",
73
+ "source_port_id": "source_port_0",
74
+ "subcircuit_id": "subcircuit_source_group_0",
75
+ "warning_type": "source_pin_missing_trace_warning"
76
+ },
77
+ {
78
+ "type": "schematic_component",
79
+ "schematic_component_id": "schematic_component_0",
80
+ "center": {
81
+ "x": 0,
82
+ "y": 0
83
+ },
84
+ "size": {
85
+ "width": 1.1,
86
+ "height": 0.388910699999999
87
+ },
88
+ "source_component_id": "source_component_0",
89
+ "is_box_with_pins": true,
90
+ "symbol_name": "boxresistor_right",
91
+ "symbol_display_value": "1kΩ",
92
+ "schematic_group_id": "schematic_group_0"
93
+ },
94
+ {
95
+ "type": "schematic_group",
96
+ "schematic_group_id": "schematic_group_0",
97
+ "is_subcircuit": true,
98
+ "subcircuit_id": "subcircuit_source_group_0",
99
+ "name": "unnamed_board1",
100
+ "center": {
101
+ "x": 0,
102
+ "y": 0
103
+ },
104
+ "width": 0,
105
+ "height": 0,
106
+ "schematic_component_ids": [],
107
+ "source_group_id": "source_group_0"
108
+ },
109
+ {
110
+ "type": "schematic_port",
111
+ "schematic_port_id": "schematic_port_0",
112
+ "schematic_component_id": "schematic_component_0",
113
+ "center": {
114
+ "x": -0.55,
115
+ "y": 0
116
+ },
117
+ "source_port_id": "source_port_0",
118
+ "facing_direction": "left",
119
+ "distance_from_component_edge": 0.4,
120
+ "pin_number": 1,
121
+ "display_pin_label": "anode",
122
+ "is_connected": false
123
+ },
124
+ {
125
+ "type": "schematic_port",
126
+ "schematic_port_id": "schematic_port_1",
127
+ "schematic_component_id": "schematic_component_0",
128
+ "center": {
129
+ "x": 0.55,
130
+ "y": 0
131
+ },
132
+ "source_port_id": "source_port_1",
133
+ "facing_direction": "right",
134
+ "distance_from_component_edge": 0.4,
135
+ "pin_number": 2,
136
+ "display_pin_label": "cathode",
137
+ "is_connected": false
138
+ },
139
+ {
140
+ "type": "schematic_net_label",
141
+ "schematic_net_label_id": "schematic_net_label_0",
142
+ "text": "GND",
143
+ "anchor_position": {
144
+ "x": 0.55,
145
+ "y": 0
146
+ },
147
+ "center": {
148
+ "x": 0.7000000000000001,
149
+ "y": 0
150
+ },
151
+ "anchor_side": "left",
152
+ "source_net_id": "source_net_0"
153
+ },
154
+ {
155
+ "type": "pcb_component",
156
+ "pcb_component_id": "pcb_component_0",
157
+ "center": {
158
+ "x": 0,
159
+ "y": 0
160
+ },
161
+ "width": 0,
162
+ "height": 0,
163
+ "layer": "top",
164
+ "rotation": 0,
165
+ "source_component_id": "source_component_0",
166
+ "subcircuit_id": "subcircuit_source_group_0",
167
+ "do_not_place": false,
168
+ "obstructs_within_bounds": true
169
+ },
170
+ {
171
+ "type": "pcb_missing_footprint_error",
172
+ "pcb_missing_footprint_error_id": "pcb_missing_footprint_error_0",
173
+ "message": "No footprint found for component: <resistor#0 name=\".R1\" />",
174
+ "source_component_id": "source_component_0",
175
+ "error_type": "pcb_missing_footprint_error"
176
+ },
177
+ {
178
+ "type": "pcb_board",
179
+ "pcb_board_id": "pcb_board_0",
180
+ "center": {
181
+ "x": 0,
182
+ "y": 0
183
+ },
184
+ "thickness": 1.4,
185
+ "num_layers": 2,
186
+ "width": 0,
187
+ "height": 0,
188
+ "material": "fr4"
189
+ }
190
+ ]
@@ -1,8 +1,9 @@
1
1
  import { test, expect } from "bun:test"
2
2
  import { circuitJsonToSpice } from "lib/circuitJsonToSpice"
3
3
  import type { AnyCircuitElement } from "circuit-json"
4
- import { getTestFixture } from "tests/fixtures/getTestFixture"
5
- import { sel } from "tscircuit"
4
+ import singleResistorCircuit from "./assets/single-resistor-circuit.json"
5
+ import rcCircuitWithTrace from "./assets/RC-circuit-with-trace.json"
6
+ import circuitWithSimulationVoltageSource from "./assets/circuit-with-simulation-voltage-source.json"
6
7
 
7
8
  test("empty circuit JSON", () => {
8
9
  const circuitJson: AnyCircuitElement[] = []
@@ -16,18 +17,7 @@ test("empty circuit JSON", () => {
16
17
  })
17
18
 
18
19
  test("single resistor circuit", async () => {
19
- const { circuit } = await getTestFixture()
20
-
21
- circuit.add(
22
- <board>
23
- <resistor name="R1" resistance="1k" />
24
- <trace from="net.GND" to={sel.R1.pin2} />
25
- </board>,
26
- )
27
-
28
- await circuit.renderUntilSettled()
29
-
30
- const circuitJson = circuit.getCircuitJson()
20
+ const circuitJson = singleResistorCircuit as any
31
21
  const netlist = circuitJsonToSpice(circuitJson)
32
22
 
33
23
  expect(netlist.components).toHaveLength(1)
@@ -39,21 +29,7 @@ test("single resistor circuit", async () => {
39
29
  })
40
30
 
41
31
  test("RC circuit with trace", async () => {
42
- const { circuit } = await getTestFixture()
43
-
44
- circuit.add(
45
- <board>
46
- <resistor name="R1" resistance="1k" />
47
- <capacitor name="C1" capacitance="1uF" />
48
- <trace from={sel.R1.pin2} to={sel.C1.pin1} />
49
- <trace from="net.GND1" to={sel.R1.pin1} />
50
- <trace from="net.GND2" to={sel.C1.pin2} />
51
- </board>,
52
- )
53
-
54
- await circuit.renderUntilSettled()
55
-
56
- const circuitJson = circuit.getCircuitJson()
32
+ const circuitJson = rcCircuitWithTrace as any
57
33
  const netlist = circuitJsonToSpice(circuitJson)
58
34
 
59
35
  expect(netlist.components).toHaveLength(2)
@@ -66,33 +42,7 @@ test("RC circuit with trace", async () => {
66
42
  })
67
43
 
68
44
  test("circuit with simulation voltage source", async () => {
69
- const { circuit } = await getTestFixture()
70
-
71
- circuit.add(
72
- <board>
73
- <resistor name="R1" resistance="1k" />
74
- <chip
75
- name="U1"
76
- footprint="soic8"
77
- pinLabels={{
78
- pin2: "GND",
79
- pin3: "VOUT",
80
- }}
81
- pinAttributes={{
82
- VOUT: { providesPower: true, providesVoltage: 5 },
83
- GND: { providesGround: true },
84
- }}
85
- />
86
- <trace from={"net.VCC"} to={sel<"VOUT">("U1").VOUT} />
87
- <trace from={"net.GND"} to={sel<"GND">("U1").GND} />
88
- <trace from={"net.VCC"} to={sel.R1.pin1} />
89
- <trace from={"net.GND"} to={sel.R1.pin2} />
90
- </board>,
91
- )
92
-
93
- await circuit.renderUntilSettled()
94
-
95
- const circuitJson = circuit.getCircuitJson()
45
+ const circuitJson = circuitWithSimulationVoltageSource as any
96
46
  const netlist = circuitJsonToSpice(circuitJson)
97
47
 
98
48
  expect(netlist.components).toHaveLength(2)
@@ -118,7 +68,7 @@ test("simple switch uses simulation switch control", () => {
118
68
  source_component_id: "SW1",
119
69
  name: "SW1",
120
70
  ftype: "simple_switch",
121
- } as AnyCircuitElement,
71
+ },
122
72
  {
123
73
  type: "source_net",
124
74
  source_net_id: "net_gnd",
@@ -81,7 +81,7 @@ test("voltage probe with source_port_id creates .PRINT statement", () => {
81
81
  const netlist = circuitJsonToSpice(circuitJson)
82
82
  const spiceString = netlist.toSpiceString()
83
83
 
84
- expect(spiceString).toContain(`.PRINT TRAN V(vout)`)
84
+ expect(spiceString).toContain(`.PRINT TRAN V(VOUT)`)
85
85
  expect(spiceString).toContain(`RR1 N1 VOUT 1K`)
86
86
  expect(spiceString).toContain(`RR2 VOUT N2 1K`)
87
87
  })
@@ -99,7 +99,7 @@ test("voltage probe with source_net_id creates .PRINT statement", () => {
99
99
  const netlist = circuitJsonToSpice(circuitJson)
100
100
  const spiceString = netlist.toSpiceString()
101
101
 
102
- expect(spiceString).toContain(`.PRINT TRAN V(vout)`)
102
+ expect(spiceString).toContain(`.PRINT TRAN V(VOUT)`)
103
103
  expect(spiceString).toContain(`RR1 N1 VOUT 1K`)
104
104
  expect(spiceString).toContain(`RR2 VOUT N2 1K`)
105
105
  })
@@ -153,7 +153,7 @@ test("voltage probe on ground node is ignored, but other probes are not", () =>
153
153
 
154
154
  // `R2_p2` is now connected to GND, so it's node 0 and should be ignored
155
155
  // `R1_p2` is a non-gnd node and should be printed.
156
- expect(spiceString).toContain(`.PRINT TRAN V(vout)`)
156
+ expect(spiceString).toContain(`.PRINT TRAN V(VOUT)`)
157
157
  expect(spiceString).not.toContain("V(0)")
158
158
  expect(spiceString).toContain("RR1 N1 VOUT 1K")
159
159
  expect(spiceString).toContain("RR2 VOUT 0 1K")
@@ -183,8 +183,8 @@ test("multiple voltage probes create single .PRINT statement", () => {
183
183
 
184
184
  // The order of probes in the .PRINT statement is not guaranteed
185
185
  expect(spiceString).toContain(".PRINT TRAN")
186
- expect(spiceString).toContain("V(n1)")
187
- expect(spiceString).toContain("V(vout)")
186
+ expect(spiceString).toContain("V(N1)")
187
+ expect(spiceString).toContain("V(VOUT)")
188
188
  })
189
189
 
190
190
  test("probes with N-style names don't conflict with auto-generated names", () => {
@@ -367,9 +367,9 @@ test("probes with N-style names don't conflict with auto-generated names", () =>
367
367
 
368
368
  // The order of probes in the .PRINT statement is not guaranteed
369
369
  expect(spiceString).toContain(".PRINT TRAN")
370
- expect(spiceString).toContain("V(n1)")
371
- expect(spiceString).toContain("V(n2)")
372
- expect(spiceString).toContain("V(n4)")
370
+ expect(spiceString).toContain("V(N1)")
371
+ expect(spiceString).toContain("V(N2)")
372
+ expect(spiceString).toContain("V(N4)")
373
373
  expect(spiceString).not.toContain("V(n3)")
374
374
  expect(spiceString).not.toContain("V(n5)")
375
375
  })
@@ -1,7 +0,0 @@
1
- import { RootCircuit } from "tscircuit"
2
-
3
- export const getTestFixture = () => {
4
- const circuit = new RootCircuit()
5
-
6
- return { circuit }
7
- }