Text substitution with hierarchical sheets has unpredictable behaviour for simulator
Description
In a project using hierarchical sheets where one of the component properties in the child sheet is defined by a text substitution, when trying to simulate the circuit with the in built SPICE simulator the text substitution is not always correctly applied:
- When viewing the root sheet in the main window, the text substitution is not applied and;
- When viewing the child sheet in the main window, the text substitution is correctly applied.
To view if the text substitution was correctly applied, I opened the SPICE netlist from the simulator window and by inspecting the line of the component in question it was possible to immediately view if the text substitution was applied or not. This leads to incorrect simulation behaviour, depending on the currently viewed sheet in the hierarchy.
I did not test with more hierarchy levels or additional sheets, so I do not know if the issue is that the text substitution is only applied to the current level in the hierarchy or if the text substitution is only applied to the currently viewed sheet.
Steps to reproduce
- Create a new project and add a simple circuit to simulate with the SPICE simulator (I used an RC circuit to simulate in the time domain; R=2k and C=100n); I also added a pulse source to serve as the input stimulus
- Create a hierarchical sheet, add a field to the sheet properties to use the text substitution with (I used a field called Resistor and set it to the resistor value)
- In the child sheet repeat the circuit from the root sheet but set one of the component values to use the text substitution (I used the resistor component from the RC circuit)
- Create and connect the hierarchical pins from the child sheet to the root sheet so that both circuits have the same input and same ground, also expose the output of the child sheet to the root sheet
- Open the simulator and configure the simulation so that the waveforms can be well seen
- Run the simulator while the child sheet is open
- Run the simulator while the root sheet is open, the simulation result will be different from before and the SPICE netlist can be viewed in both situations to verify that the text substitution failed in this second case
KiCad Version
Application: KiCad Schematic Editor x86_64 on x86_64
Version: 7.0.2-0, release build
Libraries:
wxWidgets 3.2.2
FreeType 2.12.1
HarfBuzz 5.3.1
FontConfig 2.14.0
libcurl/7.79.1 SecureTransport (LibreSSL/3.3.6) zlib/1.2.11 nghttp2/1.45.1
Platform: macOS Monterey Version 12.6 (Build 21G115), 64 bit, Little endian, wxMac
Build Info:
Date: Apr 17 2023 08:25:19
wxWidgets: 3.2.2 (wchar_t,wx containers)
Boost: 1.80.0
OCC: 7.6.3
Curl: 7.77.0
ngspice: 38
Compiler: Clang 13.0.0 with C++ ABI 1002
Build settings:
KICAD_SPICE=ON