Adding a choice for number of segments

This commit is contained in:
Jean-Samuel Reynaud
2017-06-27 19:28:26 +02:00
parent 0b89e4a63c
commit b0c1540eb1
3 changed files with 340 additions and 184 deletions

View File

@ -11,10 +11,10 @@ class CircularZone(pcbnew.ActionPlugin):
self.category = "Undefined"
self.description = ""
def build(self, center_x, center_y, radius, keepout):
def build(self, center_x, center_y, radius, keepout, edge_count):
sp = pcbnew.SHAPE_POLY_SET()
sp.NewOutline()
cnt = 100
cnt = edge_count
for i in range(cnt):
x = int(center_x + radius * cos(i * 2 * pi / cnt))
y = int(center_y + radius * sin(i * 2 * pi / cnt))
@ -28,6 +28,24 @@ class CircularZone(pcbnew.ActionPlugin):
zone.thisown = 0
self.pcb.Add(zone)
def Warn(self, message, caption='Warning!'):
dlg = wx.MessageDialog(
None, message, caption, wx.OK | wx.ICON_WARNING)
dlg.ShowModal()
dlg.Destroy()
def CheckInput(self, value, data):
val = None
try:
val = int(value)
if val < 1:
raise Exception("Invalid")
except:
self.Warn(
"Invalid parameter for %s: Must be a positive number" % data)
val = None
return val
def Run(self):
self.pcb = pcbnew.GetBoard()
a = CircularZoneDlg(None)
@ -47,9 +65,17 @@ class CircularZone(pcbnew.ActionPlugin):
a.m_radiusMM.SetValue("10")
modal_result = a.ShowModal()
if modal_result == wx.ID_OK:
self.build(x, y, pcbnew.FromMM(
int(a.m_radiusMM.GetValue())), a.m_radio_out.GetValue())
segment = self.CheckInput(
a.m_textCtrl_seg.GetValue(), "segment number")
radius = self.CheckInput(a.m_radiusMM.GetValue(), "radius")
if segment is not None and radius is not None:
if modal_result == wx.ID_OK:
self.build(x, y, pcbnew.FromMM(
radius), a.m_radio_out.GetValue(), segment)
else:
None # Cancel
else:
print "Cancel"
None # Invalid input
a.Destroy()