diff --git a/CircularZone/CircularZone.py b/CircularZone/CircularZone.py
index 5c0a442..533c4da 100644
--- a/CircularZone/CircularZone.py
+++ b/CircularZone/CircularZone.py
@@ -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()
diff --git a/CircularZone/CircularZoneDlg.fbp b/CircularZone/CircularZoneDlg.fbp
index 44e2e77..0d77b0e 100644
--- a/CircularZone/CircularZoneDlg.fbp
+++ b/CircularZone/CircularZoneDlg.fbp
@@ -44,7 +44,7 @@
CircularZoneDlg
- 373,219
+ 373,290
wxDEFAULT_DIALOG_STYLE
Circular zone parameters
@@ -178,7 +178,7 @@