Track created via python track.Duplicate() has same UUID as the original
Description
When a track is duplicated via the python Duplciate() method the duplicated track has the same UUID as the original - see the python example code below. This can cause problems if the original track is part of a group as both the original and duplicate track will be part of the group.
If you close the PCB Editor and then reopen the pcb, make a further change to the pcb and save it, Kicad will replace the UUID for one of the tracks with the same UUID with a new, unique one. This again causes problems if the track is part of a group. Note: similarly, zones duplicated via python Duplicate() method also have the same UUID as the original.
Expected behaviour is that the duplicated track has the same properties of the original track but a different UUID.
Python example code:
from pcbnew import *
board = pcbnew.GetBoard()
track = board.Tracks()[0]
track.m_Uuid.AsString()
# outputs '7e1b2742-06d6-47e8-9ebf-9143d81884de'
dup_track = track.Duplicate()
dup_track.m_Uuid.AsString()
# outputs '7e1b2742-06d6-47e8-9ebf-9143d81884de'
Workaround: If I make the following changes to C:\Program Files\KiCad\7.0\bin\Lib\site-packages\pcbnew.py then the python Duplicate() methods function as expected.
line 9493: original
def Duplicate(self):
r"""Duplicate(BOARD_ITEM self) -> BOARD_ITEM"""
return _pcbnew.BOARD_ITEM_Duplicate(self)
workaround
def Duplicate2(self):
r"""Duplicate2(BOARD_ITEM self) -> BOARD_ITEM"""
return _pcbnew.BOARD_ITEM_Duplicate(self)
line 9601 original
def Duplicate(self):
ct = self.GetClass()
if ct=="BOARD":
return None
else:
return Cast_to_BOARD_ITEM(self.Clone()).Cast()
workaround
def Duplicate(self):
ct = self.GetClass()
if ct=="BOARD":
return None
else:
return Cast_to_BOARD_ITEM(self.Duplicate2()).Cast()
Steps to reproduce
- Open the PCB Editor
- Create a single track
- Open the Scripting Console
- Duplicate the track via the Duplicate() python method on the PCB_TRACK
- Print both the original track's and duplicated track's UUID
KiCad Version
Version: 7.0.1, release build
Libraries:
wxWidgets 3.2.2
FreeType 2.12.1
HarfBuzz 5.0.1
FontConfig 2.14.1
libcurl/7.83.1-DEV Schannel zlib/1.2.13
Platform: Windows 11 (build 22621), 64-bit edition, 64 bit, Little endian, wxMSW
Build Info:
Date: Mar 11 2023 03:41:46
wxWidgets: 3.2.2 (wchar_t,wx containers)
Boost: 1.80.0
OCC: 7.6.2
Curl: 7.83.1-DEV
ngspice: 39
Compiler: Visual C++ 1934 without C++ ABI
Build settings:
KICAD_SPICE=ON