1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
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()
for module in pcb.GetFootprints():
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)
for module in pcb.GetFootprints():
pcb.RemoveNative(module)
for track in pcb.GetTracks():
pcb.RemoveNative(track)
for draw in pcb.GetDrawings():
pcb.RemoveNative(draw)
class testundoredo2(ActionPlugin):
def defaults(self):
self.name = "Test Undo/Redo: Generate random content"
self.category = "Test Undo/Redo"
self.description = ""
def createFPCXFootprint(self,pads):
size_025_160mm = VECTOR2I_MM(0.25,1.6)
size_150_200mm = VECTOR2I_MM(1.50,2.0)
# create a new footprint, its parent is our previously created pcb
footprint = FOOTPRINT(self.pcb)
footprint.SetReference("FPC"+str(pads)) # give it a reference name
footprint.Reference().SetPosition(VECTOR2I_MM(-1,-1))
self.pcb.Add(footprint) # add it to our pcb
m_pos = VECTOR2I_MM(0,0) #random.randint(10,200),random.randint(10,200))
footprint.SetPosition(m_pos)
# create a pad array and add it to the footprint
def smdRectPad(footprint,size,pos,name):
pad = PAD(footprint)
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):
pad = smdRectPad( footprint,size_025_160mm, VECTOR2I_MM(0.5*n,0), str(n+1) )
footprint.Add(pad)
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")
footprint.Add(pad_s0)
footprint.Add(pad_s1)
e = PCB_SHAPE(footprint)
e.SetStart(VECTOR2I_MM(-1,0))
e.SetEnd(VECTOR2I_MM(0,0))
e.SetWidth(FromMM(0.2))
e.SetLayer(F_SilkS)
e.SetShape(S_SEGMENT)
footprint.Add(e)
footprint.SetPosition(VECTOR2I_MM(random.randint(20,200),random.randint(20,150)))
return footprint
def Run(self):
self.pcb = GetBoard()
random.seed()
for i in range(10):
seg = PCB_SHAPE()
seg.SetLayer( random.choice([Edge_Cuts,Cmts_User,Eco1_User,Eco2_User]) )
seg.SetStart( VECTOR2I_MM( random.randint(10,100),
random.randint(10,100) ) )
seg.SetEnd( VECTOR2I_MM( random.randint(10,100),
random.randint(10,100) ) )
self.pcb.Add( seg )
if i%2 == 0:
t = PCB_TRACK(None)
else:
t = PCB_VIA(None)
#t.SetLayerPair(segments['layerPair'][0],segments['layerPair'][1])
t.SetViaType(VIATYPE_THROUGH)
t.SetDrill(FromMM(random.randint(1,20)/10.0))
t.SetStart(VECTOR2I_MM(random.randint(100,150),random.randint(100,150)))
t.SetEnd(VECTOR2I_MM(random.randint(100,150),random.randint(100,150)))
t.SetWidth(FromMM(random.randint(1,15)/10.0))
t.SetLayer(random.choice([F_Cu,B_Cu]))
self.pcb.Add(t)
self.createFPCXFootprint(random.randint(2,40))
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)
area.Move(VECTOR2I_MM(random.randint(-20,20),random.randint(-20,20)))
for footprint in pcb.GetFootprints():
footprint.Move(VECTOR2I_MM(random.randint(-20,20),random.randint(-20,20)))
if random.randint(0,10) > 5:
footprint.Flip(footprint.GetPosition(), True)
for track in pcb.GetTracks():
track.Move(VECTOR2I_MM(random.randint(-20,20),random.randint(-20,20)))
for draw in pcb.GetDrawings():
draw.Move(VECTOR2I_MM(random.randint(-20,20),random.randint(-20,20)))
testundoredo0().register()
testundoredo1().register()
testundoredo2().register()
testundoredo3().register()
|