From 5d0b5e16ffe41a81b495066ad44b8bf4c36d6d14 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Wed, 12 Apr 2023 16:04:07 +0100 Subject: [PATCH] Remove python-based board_item duplicate method This method shadows the C++ method, and doesn't properly handle updating the duplicated object's KIID to be unique. Also add tests to ensure the KIIDs are unique after duplication. Fixes https://gitlab.com/kicad/code/kicad/issues/14460 --- pcbnew/python/swig/board_item.i | 7 ------- qa/testcases/test_004_tracks.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pcbnew/python/swig/board_item.i b/pcbnew/python/swig/board_item.i index 1a731650af..28313dd953 100644 --- a/pcbnew/python/swig/board_item.i +++ b/pcbnew/python/swig/board_item.i @@ -166,13 +166,6 @@ static PCB_BITMAP* Cast_to_PCB_BITMAP( BOARD_ITEM* ); else: raise TypeError("Unsupported drawing class: %s" % ct) - def Duplicate(self): - ct = self.GetClass() - if ct=="BOARD": - return None - else: - return Cast_to_BOARD_ITEM(self.Clone()).Cast() - def SetPos(self,p): self.SetPosition(p) self.SetPos0(p) diff --git a/qa/testcases/test_004_tracks.py b/qa/testcases/test_004_tracks.py index 01a282eff6..8b9c53b6d2 100644 --- a/qa/testcases/test_004_tracks.py +++ b/qa/testcases/test_004_tracks.py @@ -15,6 +15,10 @@ class TestTracks(unittest.TestCase): self.assertEqual(250000, track.GetWidth()) self.assertEqual('McNetty', track.GetNetname()) + dup_track = track.Duplicate() + self.assertTrue( dup_track.m_Uuid != track.m_Uuid ) + + def test_arcs(self): arcs = [t.Cast() for t in self.pcb.Tracks() if t.GetClass() == 'PCB_ARC'] self.assertEqual(13, len(arcs)) @@ -24,9 +28,15 @@ class TestTracks(unittest.TestCase): round(arc.GetArcAngleEnd().AsTenthsOfADegree())]) self.assertEqual(2414200, round(arc.GetRadius())) + dup_arc = arc.Duplicate() + self.assertTrue( dup_arc.m_Uuid != arc.m_Uuid ) + def test_vias(self): vias = [t.Cast() for t in self.pcb.Tracks() if t.GetClass() == 'PCB_VIA'] self.assertEqual(2, len(vias)) via = sorted(vias, key=lambda t: [t.GetStart()[0], t.GetStart()[1]])[0] self.assertEqual([29000000, 41000000], [via.GetStart()[0], via.GetStart()[1]]) self.assertEqual(400000, via.GetDrillValue()) + + dup_via = via.Duplicate() + self.assertTrue( dup_via.m_Uuid != via.m_Uuid )