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