2017-02-06 07:39:32 +00:00
|
|
|
|
|
|
|
from pcbnew import *
|
|
|
|
import random
|
|
|
|
import pprint
|
|
|
|
|
|
|
|
|
|
|
|
class testundoredo0(ActionPlugin):
|
|
|
|
|
|
|
|
def defaults(self):
|
|
|
|
self.name = "Test Undo/Redo: Remove footprints"
|
|
|
|
self.category = "Test Undo/Redo"
|
|
|
|
self.description = ""
|
|
|
|
|
|
|
|
def Run(self):
|
|
|
|
pcb = GetBoard()
|
|
|
|
|
2020-11-13 23:03:36 +00:00
|
|
|
for module in pcb.GetFootprints():
|
2017-02-06 07:39:32 +00:00
|
|
|
pcb.RemoveNative(module)
|
|
|
|
|
|
|
|
|
|
|
|
class testundoredo1(ActionPlugin):
|
|
|
|
|
|
|
|
def defaults(self):
|
|
|
|
self.name = "Test Undo/Redo: Remove all board items"
|
|
|
|
self.category = "Test Undo/Redo"
|
|
|
|
self.description = ""
|
|
|
|
|
|
|
|
def Run(self):
|
|
|
|
pcb = GetBoard()
|
|
|
|
|
|
|
|
while pcb.GetAreaCount() > 0:
|
|
|
|
area = pcb.GetArea(0)
|
|
|
|
pcb.RemoveNative(area)
|
|
|
|
|
2020-11-13 23:03:36 +00:00
|
|
|
for module in pcb.GetFootprints():
|
2017-02-06 07:39:32 +00:00
|
|
|
pcb.RemoveNative(module)
|
|
|
|
|
|
|
|
for track in pcb.GetTracks():
|
|
|
|
pcb.RemoveNative(track)
|
|
|
|
|
2022-01-02 17:26:27 +00:00
|
|
|
for draw in pcb.GetDrawings():
|
2017-02-06 07:39:32 +00:00
|
|
|
pcb.RemoveNative(draw)
|
|
|
|
|
|
|
|
|
|
|
|
class testundoredo2(ActionPlugin):
|
|
|
|
|
|
|
|
def defaults(self):
|
|
|
|
self.name = "Test Undo/Redo: Generate random content"
|
|
|
|
self.category = "Test Undo/Redo"
|
|
|
|
self.description = ""
|
|
|
|
|
2020-11-13 23:10:45 +00:00
|
|
|
def createFPCXFootprint(self,pads):
|
2023-06-02 11:23:50 +00:00
|
|
|
size_025_160mm = VECTOR2I_MM(0.25,1.6)
|
|
|
|
size_150_200mm = VECTOR2I_MM(1.50,2.0)
|
Fix source comment/doc typos (follow-up)
Found via `codespell -q 3 -S *.po,./thirdparty -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,dout,einstance,modul,ot,overide,serie,te,,tesselate,tesselator,tht`
2021-07-03 22:37:31 +00:00
|
|
|
# create a new footprint, its parent is our previously created pcb
|
2020-11-13 23:10:45 +00:00
|
|
|
footprint = FOOTPRINT(self.pcb)
|
|
|
|
footprint.SetReference("FPC"+str(pads)) # give it a reference name
|
2023-06-02 11:23:50 +00:00
|
|
|
footprint.Reference().SetPosition(VECTOR2I_MM(-1,-1))
|
2020-11-13 23:10:45 +00:00
|
|
|
self.pcb.Add(footprint) # add it to our pcb
|
2023-06-02 11:23:50 +00:00
|
|
|
m_pos = VECTOR2I_MM(0,0) #random.randint(10,200),random.randint(10,200))
|
2020-11-13 23:10:45 +00:00
|
|
|
footprint.SetPosition(m_pos)
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2020-11-13 23:10:45 +00:00
|
|
|
# create a pad array and add it to the footprint
|
2017-02-06 07:39:32 +00:00
|
|
|
|
|
|
|
|
2020-11-13 23:10:45 +00:00
|
|
|
def smdRectPad(footprint,size,pos,name):
|
2020-11-14 01:06:05 +00:00
|
|
|
pad = PAD(footprint)
|
2017-02-06 07:39:32 +00:00
|
|
|
pad.SetSize(size)
|
|
|
|
pad.SetShape(PAD_SHAPE_RECT)
|
|
|
|
pad.SetAttribute(PAD_ATTRIB_SMD)
|
|
|
|
pad.SetLayerSet(pad.SMDMask())
|
|
|
|
pad.SetPosition(pos)
|
|
|
|
pad.SetPadName(name)
|
|
|
|
return pad
|
|
|
|
|
|
|
|
for n in range (0,pads):
|
2023-06-02 11:23:50 +00:00
|
|
|
pad = smdRectPad( footprint,size_025_160mm, VECTOR2I_MM(0.5*n,0), str(n+1) )
|
2020-11-13 23:10:45 +00:00
|
|
|
footprint.Add(pad)
|
2017-02-06 07:39:32 +00:00
|
|
|
|
|
|
|
|
2023-06-02 11:23:50 +00:00
|
|
|
pad_s0 = smdRectPad(footprint,size_150_200mm,VECTOR2I_MM(-1.6,1.3), "0")
|
|
|
|
pad_s1 = smdRectPad(footprint,size_150_200mm,VECTOR2I_MM((pads-1)*0.5+1.6,1.3), "0")
|
2020-11-13 23:10:45 +00:00
|
|
|
footprint.Add(pad_s0)
|
|
|
|
footprint.Add(pad_s1)
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2023-06-02 11:23:50 +00:00
|
|
|
e = PCB_SHAPE(footprint)
|
|
|
|
e.SetStart(VECTOR2I_MM(-1,0))
|
|
|
|
e.SetEnd(VECTOR2I_MM(0,0))
|
2017-02-06 07:39:32 +00:00
|
|
|
e.SetWidth(FromMM(0.2))
|
|
|
|
e.SetLayer(F_SilkS)
|
|
|
|
e.SetShape(S_SEGMENT)
|
2022-01-02 17:26:27 +00:00
|
|
|
footprint.Add(e)
|
2023-06-02 11:23:50 +00:00
|
|
|
footprint.SetPosition(VECTOR2I_MM(random.randint(20,200),random.randint(20,150)))
|
2022-01-02 17:26:27 +00:00
|
|
|
return footprint
|
2017-02-06 07:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Run(self):
|
|
|
|
self.pcb = GetBoard()
|
|
|
|
random.seed()
|
|
|
|
|
|
|
|
for i in range(10):
|
2022-01-02 17:26:27 +00:00
|
|
|
seg = PCB_SHAPE()
|
2017-02-06 07:39:32 +00:00
|
|
|
seg.SetLayer( random.choice([Edge_Cuts,Cmts_User,Eco1_User,Eco2_User]) )
|
2023-06-02 11:23:50 +00:00
|
|
|
seg.SetStart( VECTOR2I_MM( random.randint(10,100),
|
2017-02-06 07:39:32 +00:00
|
|
|
random.randint(10,100) ) )
|
2023-06-02 11:23:50 +00:00
|
|
|
seg.SetEnd( VECTOR2I_MM( random.randint(10,100),
|
2017-02-06 07:39:32 +00:00
|
|
|
random.randint(10,100) ) )
|
|
|
|
self.pcb.Add( seg )
|
|
|
|
|
|
|
|
if i%2 == 0:
|
2022-01-02 17:26:27 +00:00
|
|
|
t = PCB_TRACK(None)
|
2017-02-06 07:39:32 +00:00
|
|
|
else:
|
2022-01-02 17:26:27 +00:00
|
|
|
t = PCB_VIA(None)
|
2017-02-06 07:39:32 +00:00
|
|
|
#t.SetLayerPair(segments['layerPair'][0],segments['layerPair'][1])
|
2022-01-02 17:26:27 +00:00
|
|
|
t.SetViaType(VIATYPE_THROUGH)
|
2017-02-06 07:39:32 +00:00
|
|
|
t.SetDrill(FromMM(random.randint(1,20)/10.0))
|
2023-06-02 11:23:50 +00:00
|
|
|
|
|
|
|
t.SetStart(VECTOR2I_MM(random.randint(100,150),random.randint(100,150)))
|
|
|
|
t.SetEnd(VECTOR2I_MM(random.randint(100,150),random.randint(100,150)))
|
2017-02-06 07:39:32 +00:00
|
|
|
t.SetWidth(FromMM(random.randint(1,15)/10.0))
|
|
|
|
t.SetLayer(random.choice([F_Cu,B_Cu]))
|
|
|
|
self.pcb.Add(t)
|
|
|
|
|
2022-01-02 17:26:27 +00:00
|
|
|
self.createFPCXFootprint(random.randint(2,40))
|
2017-02-06 07:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class testundoredo3(ActionPlugin):
|
|
|
|
|
|
|
|
def defaults(self):
|
|
|
|
self.name = "Test Undo/Redo: Move elements randomly"
|
|
|
|
self.category = "Test Undo/Redo"
|
|
|
|
self.description = ""
|
|
|
|
|
|
|
|
def Run(self):
|
|
|
|
pcb = GetBoard()
|
|
|
|
|
|
|
|
for i in range(0,pcb.GetAreaCount()):
|
|
|
|
area = pcb.GetArea(i)
|
2023-06-02 11:23:50 +00:00
|
|
|
area.Move(VECTOR2I_MM(random.randint(-20,20),random.randint(-20,20)))
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2022-01-02 17:26:27 +00:00
|
|
|
for footprint in pcb.GetFootprints():
|
2023-06-02 11:23:50 +00:00
|
|
|
footprint.Move(VECTOR2I_MM(random.randint(-20,20),random.randint(-20,20)))
|
2017-02-06 07:39:32 +00:00
|
|
|
if random.randint(0,10) > 5:
|
2022-01-02 17:26:27 +00:00
|
|
|
footprint.Flip(footprint.GetPosition(), True)
|
2017-02-06 07:39:32 +00:00
|
|
|
|
|
|
|
for track in pcb.GetTracks():
|
2023-06-02 11:23:50 +00:00
|
|
|
track.Move(VECTOR2I_MM(random.randint(-20,20),random.randint(-20,20)))
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2022-01-02 17:26:27 +00:00
|
|
|
for draw in pcb.GetDrawings():
|
2023-06-02 11:23:50 +00:00
|
|
|
draw.Move(VECTOR2I_MM(random.randint(-20,20),random.randint(-20,20)))
|
2017-02-06 07:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testundoredo0().register()
|
|
|
|
testundoredo1().register()
|
|
|
|
testundoredo2().register()
|
|
|
|
testundoredo3().register()
|