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 @@ 5 - wxEXPAND + 0 @@ -365,197 +365,314 @@ 5 wxEXPAND 1 - - wxID_ANY - Type of Zone + - sbSizer1 - wxVERTICAL - 1 + bSizer4 + wxHORIZONTAL none - 5 - wxALL|wxALIGN_CENTER_VERTICAL + wxEXPAND 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 + wxID_ANY - Standard - - 0 - - - 0 + Type of Zone - 1 - m_radio_std - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - + sbSizer1 + wxVERTICAL + 1 + none + + 5 + wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Standard + + 0 + + + 0 + + 1 + m_radio_std + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Keepout + + 0 + + + 0 + + 1 + m_radio_out + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 - wxALL|wxALIGN_CENTER_VERTICAL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 + wxEXPAND + 1 + wxID_ANY - Keepout - - 0 - - - 0 + Number of segments - 1 - m_radio_out - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - + sbSizer2 + wxVERTICAL + 1 + none + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_textCtrl_seg + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 - wxEXPAND|wxALIGN_RIGHT - 1 + wxALIGN_RIGHT|wxEXPAND + 0 bSizer1 diff --git a/CircularZone/CircularZoneDlg.py b/CircularZone/CircularZoneDlg.py index 99867ca..855299c 100644 --- a/CircularZone/CircularZoneDlg.py +++ b/CircularZone/CircularZoneDlg.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ########################################################################### -## Python code generated with wxFormBuilder (version Feb 16 2016) +## Python code generated with wxFormBuilder (version Dec 21 2016) ## http://www.wxformbuilder.org/ ## ## PLEASE DO "NOT" EDIT THIS FILE! @@ -17,7 +17,7 @@ import wx.xrc class CircularZoneDlg ( wx.Dialog ): def __init__( self, parent ): - wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Circular zone parameters", pos = wx.DefaultPosition, size = wx.Size( 373,219 ), style = wx.DEFAULT_DIALOG_STYLE ) + wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Circular zone parameters", pos = wx.DefaultPosition, size = wx.Size( 373,290 ), style = wx.DEFAULT_DIALOG_STYLE ) self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize ) @@ -39,18 +39,31 @@ class CircularZoneDlg ( wx.Dialog ): bSizer31.Add( self.m_radiusMM, 1, wx.ALL|wx.EXPAND, 5 ) - bSizer3.Add( bSizer31, 0, wx.EXPAND, 5 ) + bSizer3.Add( bSizer31, 0, 0, 5 ) + + bSizer4 = wx.BoxSizer( wx.HORIZONTAL ) sbSizer1 = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Type of Zone" ), wx.VERTICAL ) self.m_radio_std = wx.RadioButton( sbSizer1.GetStaticBox(), wx.ID_ANY, u"Standard", wx.DefaultPosition, wx.DefaultSize, 0 ) - sbSizer1.Add( self.m_radio_std, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) + sbSizer1.Add( self.m_radio_std, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 5 ) self.m_radio_out = wx.RadioButton( sbSizer1.GetStaticBox(), wx.ID_ANY, u"Keepout", wx.DefaultPosition, wx.DefaultSize, 0 ) sbSizer1.Add( self.m_radio_out, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) - bSizer3.Add( sbSizer1, 1, wx.EXPAND, 5 ) + bSizer4.Add( sbSizer1, 1, wx.EXPAND, 5 ) + + sbSizer2 = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Number of segments" ), wx.VERTICAL ) + + self.m_textCtrl_seg = wx.TextCtrl( sbSizer2.GetStaticBox(), wx.ID_ANY, u"64", wx.DefaultPosition, wx.DefaultSize, 0 ) + sbSizer2.Add( self.m_textCtrl_seg, 0, wx.ALL|wx.EXPAND, 5 ) + + + bSizer4.Add( sbSizer2, 1, wx.EXPAND, 5 ) + + + bSizer3.Add( bSizer4, 1, wx.EXPAND, 5 ) bSizer1 = wx.BoxSizer( wx.HORIZONTAL ) @@ -66,7 +79,7 @@ class CircularZoneDlg ( wx.Dialog ): bSizer1.Add( self.m_button2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) - bSizer3.Add( bSizer1, 1, wx.EXPAND|wx.ALIGN_RIGHT, 5 ) + bSizer3.Add( bSizer1, 0, wx.ALIGN_RIGHT|wx.EXPAND, 5 ) self.SetSizer( bSizer3 )