pcbnew.SaveBoard from scripting console or an action plugin messes up underlying data structures
Description
This is a weird one. I hope I traced it down to underlying bug. And I probably did not name the issue correctly.
When saving a current board using scripting console or an action plugin saves the file correctly. But if one loads this file within the same python session as another board object instance it succeeds but it actual loads the original board. Thus any operations on the loaded board object are actually made on original board object. Furthermore when closing KiCad, and opening it again it opens a project of the saved board, even though when closing it primary project was active.
If one only load anther board which was created previously, I can not observe any non expected behaviour
I've done same things in KiCad 5.1.x and I did not have any issues then.
Steps to reproduce
- Open KiCad.
- Open an existing project
- Open layout
- Open the scripting console and run the following code
import pcbnew
import os
b1 = pcbnew.GetBoard()
dir = os.path.dirname(b1.GetFileName())
temp_name = os.path.join(dir, "temp_file.kicad_pcb")
pcbnew.SaveBoard(temp_name, b1)
b2 = pcbnew.LoadBoard(temp_name)
b2.GetFileName()
b1.GetFileName()
- observe as filename for b1 (original layout file) and filename for b2 (just saved file) are the same. b2 filename should be temp_file.kicad_pcb
- close scripting console, close layout, close KiCad
- open kicad and observe which project it opened.
KiCad Version
Application: KiCad
Version: (6.0.4-76-g455ec428f2), release build
Libraries:
wxWidgets 3.0.4
libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Platform: Linux 5.4.0-107-generic x86_64, 64 bit, Little endian, wxGTK, KDE, x11
Build Info:
Date: Apr 3 2022 17:59:58
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
Boost: 1.71.0
OCC: 7.5.2
Curl: 7.68.0
ngspice: 31
Compiler: GCC 9.4.0 with C++ ABI 1013
Build settings:
KICAD_USE_OCC=ON
KICAD_SPICE=ON