From aa760406bafe9d370832cb8bb92b0bbbf4412e5e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 26 Nov 2023 13:44:31 +0100 Subject: [PATCH] Fix old python examples and a compatibility issue in pcb_shape.i. Fixes #16158 https://gitlab.com/kicad/code/kicad/-/issues/16158 --- pcbnew/python/examples/createPcb.py | 16 +++++++--------- pcbnew/python/examples/listPcb.py | 11 +++++++---- pcbnew/python/swig/pcb_shape.i | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pcbnew/python/examples/createPcb.py b/pcbnew/python/examples/createPcb.py index c3d5fccd8a..826c2a3528 100644 --- a/pcbnew/python/examples/createPcb.py +++ b/pcbnew/python/examples/createPcb.py @@ -12,8 +12,8 @@ def fromUTF8Text( aText ): return aText def GenerateBoard(): - size_0_6mm = wxSizeMM(0.6,0.6) - size_1_0mm = wxSizeMM(1.0,1.0) + size_0_6mm = VECTOR2I_MM(0.6,0.6) + size_1_0mm = VECTOR2I_MM(1.0,1.0) # create a blank board pcb = CreateEmptyBoard() @@ -21,11 +21,10 @@ def GenerateBoard(): # create a new footprint, it's parent is our previously created pcb footprint = FOOTPRINT(pcb) footprint.SetReference("M1") # give it a reference name - footprint.Reference().SetPos0(wxPointMM(6,-2)) - footprint.Reference().SetDrawCoord() + footprint.Reference().SetPos(VECTOR2I_MM(3,-2)) pcb.Add(footprint) # add it to our pcb - m_pos = wxPointMM(50,50) - footprint.SetPosition(m_pos) + mod_pos = VECTOR2I_MM(50,50) + footprint.SetPosition(mod_pos) # create a pad array and add it to the footprint n = 1 @@ -34,9 +33,8 @@ def GenerateBoard(): pad = PAD(footprint) pad.SetDrillSize(size_0_6mm) pad.SetSize(size_1_0mm) - pt = wxPointMM(1.27*x,1.27*y) - pad.SetPos0(pt); - pad.SetDrawCoord() + pt = VECTOR2I_MM(1.27*x,1.27*y) + footprint.GetPosition() + pad.SetPosition(pt); pad.SetName(str(n)) footprint.Add(pad) n+=1 diff --git a/pcbnew/python/examples/listPcb.py b/pcbnew/python/examples/listPcb.py index 6d354255f6..6df2d61ee9 100644 --- a/pcbnew/python/examples/listPcb.py +++ b/pcbnew/python/examples/listPcb.py @@ -25,20 +25,23 @@ print("List vias:") for item in pcb.GetTracks(): if type(item) is PCB_VIA: - pos = item.GetPosition() drill = item.GetDrillValue() width = item.GetWidth() print(" * Via: %s - %f/%f " % (ToUnits(pos), ToUnits(drill), ToUnits(width))) elif type(item) is PCB_TRACK: - start = item.GetStart() end = item.GetEnd() width = item.GetWidth() - print(" * Track: %s to %s, width %f" % (ToUnits(start), ToUnits(end), ToUnits(width))) + elif type(item) is PCB_ARC: + start = item.GetStart() + end = item.GetEnd() + width = item.GetWidth() + print(" * Track arc: %s to %s, width %f" % (ToUnits(start), ToUnits(end), ToUnits(width))) + else: print("Unknown type %s" % type(item)) @@ -69,4 +72,4 @@ print("List zones:", pcb.GetAreaCount()) for idx in range(0, pcb.GetAreaCount()): zone=pcb.GetArea(idx) - print("zone:", idx, "priority:", zone.GetPriority(), "netname", fromUTF8Text( zone.GetNetname() ) ) + print("zone:", idx, "priority:", zone.GetAssignedPriority(), "netname", fromUTF8Text( zone.GetNetname() ) ) diff --git a/pcbnew/python/swig/pcb_shape.i b/pcbnew/python/swig/pcb_shape.i index ee319f8405..670b7d8d47 100644 --- a/pcbnew/python/swig/pcb_shape.i +++ b/pcbnew/python/swig/pcb_shape.i @@ -54,7 +54,7 @@ %pythoncode %{ def GetShapeStr(self): - return self.ShowShape(self.GetShape()) + return self.ShowShape() %} }