FIX: #17: random was alway enabled

This commit is contained in:
Jean-Samuel Reynaud
2019-10-22 13:35:00 +02:00
parent 4f2738ac1b
commit a56313f509
2 changed files with 29 additions and 26 deletions

View File

@ -128,7 +128,7 @@ class FillArea:
break break
self.netname = None self.netname = None
self.debug = False self.debug = False
self.random = True self.random = False
self.star = False self.star = False
if self.netname is None: if self.netname is None:
self.SetNetname("GND") self.SetNetname("GND")
@ -145,9 +145,9 @@ class FillArea:
self.debug = True self.debug = True
return self return self
def SetRandom(self): def SetRandom(self, r):
random.seed() random.seed()
self.random = True self.random = r
return self return self
def SetStar(self): def SetStar(self):
@ -567,7 +567,8 @@ STEP = '-'
if self.filename: if self.filename:
self.pcb.Save(self.filename) self.pcb.Save(self.filename)
msg = "{:d} vias placed\n".format(via_placed) msg = "{:d} vias placed\n".format(via_placed)
wxPrint (msg+"Done!") wxPrint(msg+"Done!")
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 2: if len(sys.argv) < 2:

View File

@ -24,7 +24,8 @@ from . import FillArea
from . import FillAreaDialog from . import FillAreaDialog
import os import os
def PopulateNets(anet,dlg):
def PopulateNets(anet, dlg):
nets = pcbnew.GetBoard().GetNetsByName() nets = pcbnew.GetBoard().GetNetsByName()
for netname, net in nets.items(): for netname, net in nets.items():
netname = net.GetNetname() netname = net.GetNetname()
@ -32,8 +33,10 @@ def PopulateNets(anet,dlg):
dlg.m_cbNet.Append(netname) dlg.m_cbNet.Append(netname)
if anet != None: if anet != None:
index = dlg.m_cbNet.FindString(anet) index = dlg.m_cbNet.FindString(anet)
dlg.m_cbNet.Select(index) dlg.m_cbNet.Select(index)
# #
class FillAreaDialogEx(FillAreaDialog.FillAreaDialog): class FillAreaDialogEx(FillAreaDialog.FillAreaDialog):
def onDeleteClick(self, event): def onDeleteClick(self, event):
@ -48,56 +51,55 @@ class FillAreaAction(pcbnew.ActionPlugin):
self.description = "Via Stitching for PCB Zone" self.description = "Via Stitching for PCB Zone"
self.icon_file_name = os.path.join(os.path.dirname(__file__), "./stitching-vias.png") self.icon_file_name = os.path.join(os.path.dirname(__file__), "./stitching-vias.png")
self.show_toolbar_button = True self.show_toolbar_button = True
def Run(self): def Run(self):
a = FillAreaDialogEx(None) a = FillAreaDialogEx(None)
#a.m_SizeMM.SetValue("0.8") # a.m_SizeMM.SetValue("0.8")
a.m_StepMM.SetValue("2.54") a.m_StepMM.SetValue("2.54")
#a.m_DrillMM.SetValue("0.3") # a.m_DrillMM.SetValue("0.3")
#a.m_Netname.SetValue("GND") # a.m_Netname.SetValue("GND")
#a.m_ClearanceMM.SetValue("0.2") # a.m_ClearanceMM.SetValue("0.2")
a.m_Star.SetValue(True) a.m_Star.SetValue(True)
a.m_bitmapStitching.SetBitmap(wx.Bitmap( os.path.join(os.path.dirname(os.path.realpath(__file__)), "stitching-vias-help.png") ) ) a.m_bitmapStitching.SetBitmap(wx.Bitmap(os.path.join(os.path.dirname(os.path.realpath(__file__)), "stitching-vias-help.png")))
self.board = pcbnew.GetBoard() self.board = pcbnew.GetBoard()
self.boardDesignSettings = self.board.GetDesignSettings() self.boardDesignSettings = self.board.GetDesignSettings()
a.m_SizeMM.SetValue(str(pcbnew.ToMM(self.boardDesignSettings.GetCurrentViaSize()))) a.m_SizeMM.SetValue(str(pcbnew.ToMM(self.boardDesignSettings.GetCurrentViaSize())))
a.m_DrillMM.SetValue(str(pcbnew.ToMM(self.boardDesignSettings.GetCurrentViaDrill()))) a.m_DrillMM.SetValue(str(pcbnew.ToMM(self.boardDesignSettings.GetCurrentViaDrill())))
a.m_ClearanceMM.SetValue(str(pcbnew.ToMM(self.boardDesignSettings.GetDefault().GetClearance()))) a.m_ClearanceMM.SetValue(str(pcbnew.ToMM(self.boardDesignSettings.GetDefault().GetClearance())))
a.SetMinSize(a.GetSize()) a.SetMinSize(a.GetSize())
PopulateNets("GND",a) PopulateNets("GND", a)
modal_result = a.ShowModal() modal_result = a.ShowModal()
if modal_result == wx.ID_OK: if modal_result == wx.ID_OK:
wx.LogMessage('Via Stitching: Version 1.4') wx.LogMessage('Via Stitching: Version 1.4')
if 1: #try: if 1: # try:
fill = FillArea.FillArea() fill = FillArea.FillArea()
fill.SetStepMM(float(a.m_StepMM.GetValue().replace(',','.'))) fill.SetStepMM(float(a.m_StepMM.GetValue().replace(',', '.')))
fill.SetSizeMM(float(a.m_SizeMM.GetValue().replace(',','.'))) fill.SetSizeMM(float(a.m_SizeMM.GetValue().replace(',', '.')))
fill.SetDrillMM(float(a.m_DrillMM.GetValue().replace(',','.'))) fill.SetDrillMM(float(a.m_DrillMM.GetValue().replace(',', '.')))
fill.SetClearanceMM(float(a.m_ClearanceMM.GetValue().replace(',','.'))) fill.SetClearanceMM(float(a.m_ClearanceMM.GetValue().replace(',', '.')))
#fill.SetNetname(a.m_Netname.GetValue()) # fill.SetNetname(a.m_Netname.GetValue())
netname = a.m_cbNet.GetStringSelection() netname = a.m_cbNet.GetStringSelection()
fill.SetNetname(netname) fill.SetNetname(netname)
if a.m_Debug.IsChecked(): if a.m_Debug.IsChecked():
fill.SetDebug() fill.SetDebug()
if a.m_Random.IsChecked(): fill.SetRandom(a.m_Random.IsChecked())
fill.SetRandom()
if a.m_Star.IsChecked(): if a.m_Star.IsChecked():
fill.SetStar() fill.SetStar()
if a.m_only_selected.IsChecked(): if a.m_only_selected.IsChecked():
fill.OnlyOnSelectedArea() fill.OnlyOnSelectedArea()
fill.Run() fill.Run()
else: #except Exception: else: # except Exception:
wx.MessageDialog(None, "Invalid parameter") wx.MessageDialog(None, "Invalid parameter")
elif modal_result == wx.ID_DELETE: elif modal_result == wx.ID_DELETE:
if 1: #try: if 1: # try:
fill = FillArea.FillArea() fill = FillArea.FillArea()
fill.SetNetname(a.m_cbNet.GetStringSelection()) #a.m_Netname.GetValue()) fill.SetNetname(a.m_cbNet.GetStringSelection()) # a.m_Netname.GetValue())
if a.m_Debug.IsChecked(): if a.m_Debug.IsChecked():
fill.SetDebug() fill.SetDebug()
fill.DeleteVias() fill.DeleteVias()
fill.Run() fill.Run()
else: #except Exception: else: # except Exception:
wx.MessageDialog(None, "Invalid parameter for delete") wx.MessageDialog(None, "Invalid parameter for delete")
else: else:
print("Cancel") print("Cancel")