From 0a8e177d053386f832bcb8a9b74b2b8b3d6a96c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk?= Date: Sun, 15 Nov 2026 09:03:49 +0100 Subject: [PATCH] CircularZone 2.0: layer selection, zone centered on selected pad --- CircularZone/CircularZone.py | 80 ++- CircularZone/CircularZoneDlg.fbp | 945 ------------------------------- CircularZone/CircularZoneDlg.py | 73 +-- 3 files changed, 101 insertions(+), 997 deletions(-) delete mode 100644 CircularZone/CircularZoneDlg.fbp diff --git a/CircularZone/CircularZone.py b/CircularZone/CircularZone.py index ed29d36..e43badf 100644 --- a/CircularZone/CircularZone.py +++ b/CircularZone/CircularZone.py @@ -4,17 +4,19 @@ from .CircularZoneDlg import CircularZoneDlg import wx import os +___version__ = "2.0" + class CircularZone(pcbnew.ActionPlugin): def defaults(self): - self.name = "Circular Zone\nKeepout Zone Generator" + self.name = "Circular Zone - Keepout Zone Generator\nversion " + ___version__ self.category = "Modify PCB" - self.description = "Create a Circular Zone\nor a Circular Keepout Zone" + self.description = "Create a Circular Zone or a Circular Keepout Zone\nversion " + ___version__ self.icon_file_name = os.path.join(os.path.dirname(__file__), "./round_keepout_area.png") self.show_toolbar_button = True - def build(self, center_x, center_y, radius, keepout, edge_count): + def build(self, center_x, center_y, radius, keepout, edge_count, layer_id): sp = pcbnew.SHAPE_POLY_SET() sp.NewOutline() cnt = int(edge_count) @@ -22,17 +24,13 @@ class CircularZone(pcbnew.ActionPlugin): x = int(center_x + radius * cos(i * 2 * pi / cnt)) y = int(center_y + radius * sin(i * 2 * pi / cnt)) sp.Append(x, y) - # sp.OutlineCount() sp.thisown = 0 zone = pcbnew.ZONE(self.pcb) zone.SetOutline(sp) - zone.SetLayer(pcbnew.F_Cu) + zone.SetLayer(layer_id) zone.SetIsRuleArea(keepout) - zone.SetDoNotAllowCopperPour(keepout) - zone.SetDoNotAllowFootprints(keepout) - zone.SetDoNotAllowPads(keepout) - zone.SetDoNotAllowTracks(keepout) - zone.SetDoNotAllowVias(keepout) + if keepout: + zone.SetDoNotAllowFootprints(True) zone.thisown = 0 self.pcb.Add(zone) @@ -61,30 +59,74 @@ class CircularZone(pcbnew.ActionPlugin): x = 0 y = 0 reference = None + + for module in self.pcb.Footprints(): + for pad in module.Pads(): + if pad.IsSelected(): + pad_pos = pad.GetPosition() + if pad_pos.x == 0 and pad_pos.y == 0: + fp_pos = module.GetPosition() + x = fp_pos.x + y = fp_pos.y + else: + x = pad_pos.x + y = pad_pos.y + pad_name = pad.GetPadName() + pad_num = pad.GetNumber() + if pad_name and pad_name != "": + reference = module.GetReference() + " pad " + str(pad_name) + else: + reference = module.GetReference() + " pad " + str(pad_num) + break + if reference: + break + for module in self.pcb.Footprints(): if module.IsSelected(): x = module.GetPosition().x y = module.GetPosition().y reference = module.GetReference() break + if reference is None: - a.m_comment.SetLabel("No reference position: start at origin") + a.m_comment.SetLabel("No reference position: start at origin [0,0]") + font = a.m_comment.GetFont() + font.SetWeight(wx.FONTWEIGHT_BOLD) + a.m_comment.SetFont(font) + a.m_comment.SetForegroundColour(wx.RED) else: a.m_comment.SetLabel("Using %s as position reference" % reference) + font = a.m_comment.GetFont() + font.SetWeight(wx.FONTWEIGHT_BOLD) + a.m_comment.SetFont(font) + a.m_comment.SetForegroundColour(wx.BLACK) a.m_radiusMM.SetValue("10") + + for l in range(pcbnew.PCB_LAYER_ID_COUNT): + a.m_comboBoxLayer.Append(pcbnew.GetBoard().GetLayerName(l)) + a.m_comboBoxLayer.Select(0) + modal_result = a.ShowModal() segment = self.CheckInput( a.m_textCtrl_seg.GetValue(), "segment number") - radius = self.CheckInput(a.m_radiusMM.GetValue(), "radius") + + dimension_value = self.CheckInput(a.m_radiusMM.GetValue(), "dimension value") + + is_diameter = a.m_radio_diameter.GetValue() - if segment is not None and radius is not None: + if segment is not None and dimension_value 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: - None # Invalid input + keepout = a.m_radio_out.GetValue() + layer_name = a.m_comboBoxLayer.GetStringSelection() + layer_id = a.m_comboBoxLayer.FindString(layer_name) + if is_diameter: + radius = dimension_value / 2.0 + else: + radius = dimension_value + self.build(x, y, int(radius * 1e6), keepout, segment, layer_id) a.Destroy() + + +CircularZone().register() diff --git a/CircularZone/CircularZoneDlg.fbp b/CircularZone/CircularZoneDlg.fbp deleted file mode 100644 index 0d77b0e..0000000 --- a/CircularZone/CircularZoneDlg.fbp +++ /dev/null @@ -1,945 +0,0 @@ - - - - - - Python - 1 - source_name - 0 - 0 - res - UTF-8 - connect - CircularZoneDlg - 1000 - none - 0 - CircularZoneDlg - - . - - 1 - 1 - 1 - 1 - UI - 0 - 0 - - 0 - wxAUI_MGR_DEFAULT - - wxBOTH - - 1 - 1 - impl_virtual - - - - 0 - wxID_ANY - - - CircularZoneDlg - - 373,290 - wxDEFAULT_DIALOG_STYLE - - Circular zone parameters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bSizer3 - wxVERTICAL - 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_comment - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - - 0 - - - bSizer31 - wxHORIZONTAL - none - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Radius (mm) - - 0 - - - 0 - - 1 - m_staticText3 - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - - 0 - 1000,-1 - 1 - m_radiusMM - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxTextValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxEXPAND - 1 - - - bSizer4 - wxHORIZONTAL - none - - 5 - wxEXPAND - 1 - - wxID_ANY - Type of Zone - - 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 - wxEXPAND - 1 - - wxID_ANY - Number of segments - - 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 - wxALIGN_RIGHT|wxEXPAND - 0 - - - bSizer1 - wxHORIZONTAL - none - - 5 - wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - - 0 - - - 0 - - 1 - m_staticText101 - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALL|wxALIGN_CENTER_VERTICAL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 0 - - 1 - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_OK - Create - - 0 - - - 0 - - 1 - m_button1 - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALL|wxALIGN_CENTER_VERTICAL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_CANCEL - Cancel - - 0 - - - 0 - - 1 - m_button2 - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/CircularZone/CircularZoneDlg.py b/CircularZone/CircularZoneDlg.py index 855299c..9da1dde 100644 --- a/CircularZone/CircularZoneDlg.py +++ b/CircularZone/CircularZoneDlg.py @@ -1,25 +1,15 @@ # -*- coding: utf-8 -*- -########################################################################### -## Python code generated with wxFormBuilder (version Dec 21 2016) -## http://www.wxformbuilder.org/ -## -## PLEASE DO "NOT" EDIT THIS FILE! -########################################################################### - import wx import wx.xrc -########################################################################### -## Class CircularZoneDlg -########################################################################### 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,290 ), 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( -1,-1 ), style = wx.DEFAULT_DIALOG_STYLE ) - self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize ) + self.SetMinSize( wx.Size( 250, 410 ) ) bSizer3 = wx.BoxSizer( wx.VERTICAL ) @@ -27,21 +17,32 @@ class CircularZoneDlg ( wx.Dialog ): self.m_comment.Wrap( -1 ) bSizer3.Add( self.m_comment, 0, wx.ALL|wx.EXPAND, 5 ) - bSizer31 = wx.BoxSizer( wx.HORIZONTAL ) + sbSizerDim = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Dimension Type" ), wx.VERTICAL ) - self.m_staticText3 = wx.StaticText( self, wx.ID_ANY, u"Radius (mm)", wx.DefaultPosition, wx.DefaultSize, 0 ) - self.m_staticText3.Wrap( -1 ) - bSizer31.Add( self.m_staticText3, 1, wx.ALL|wx.EXPAND, 5 ) + self.m_radio_radius = wx.RadioButton( sbSizerDim.GetStaticBox(), wx.ID_ANY, u"Radius", wx.DefaultPosition, wx.DefaultSize, 0 ) + self.m_radio_radius.SetValue(True) + sbSizerDim.Add( self.m_radio_radius, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) - self.m_radiusMM = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 ) - self.m_radiusMM.SetMinSize( wx.Size( 1000,-1 ) ) + self.m_radio_diameter = wx.RadioButton( sbSizerDim.GetStaticBox(), wx.ID_ANY, u"Diameter", wx.DefaultPosition, wx.DefaultSize, 0 ) + sbSizerDim.Add( self.m_radio_diameter, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) - bSizer31.Add( self.m_radiusMM, 1, wx.ALL|wx.EXPAND, 5 ) + bSizer3.Add( sbSizerDim, 0, wx.ALL|wx.EXPAND, 5 ) + sbSizerValue = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Radius (mm)" ), wx.HORIZONTAL ) + self.sbSizerValue = sbSizerValue - bSizer3.Add( bSizer31, 0, 0, 5 ) + self.m_radiusMM = wx.TextCtrl( sbSizerValue.GetStaticBox(), wx.ID_ANY, u"10", wx.DefaultPosition, wx.Size( 100,-1 ), 0 ) + sbSizerValue.Add( self.m_radiusMM, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) - bSizer4 = wx.BoxSizer( wx.HORIZONTAL ) + bSizer3.Add( sbSizerValue, 0, wx.ALL|wx.EXPAND, 5 ) + + sbSizerLayer = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Layer" ), wx.HORIZONTAL ) + + m_comboBoxLayerChoices = [] + self.m_comboBoxLayer = wx.ComboBox( sbSizerLayer.GetStaticBox(), wx.ID_ANY, u"Combo!", wx.DefaultPosition, wx.Size( 200,-1 ), m_comboBoxLayerChoices, 0 ) + sbSizerLayer.Add( self.m_comboBoxLayer, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND, 5 ) + + bSizer3.Add( sbSizerLayer, 0, wx.ALL|wx.EXPAND, 5 ) sbSizer1 = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Type of Zone" ), wx.VERTICAL ) @@ -51,19 +52,14 @@ class CircularZoneDlg ( wx.Dialog ): 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 ) - - bSizer4.Add( sbSizer1, 1, wx.EXPAND, 5 ) + bSizer3.Add( sbSizer1, 0, wx.ALL|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 ) + self.m_textCtrl_seg = wx.TextCtrl( sbSizer2.GetStaticBox(), wx.ID_ANY, u"64", wx.DefaultPosition, wx.Size( 200,-1 ), 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 ) + bSizer3.Add( sbSizer2, 0, wx.ALL|wx.EXPAND, 5 ) bSizer1 = wx.BoxSizer( wx.HORIZONTAL ) @@ -78,16 +74,27 @@ class CircularZoneDlg ( wx.Dialog ): self.m_button2 = wx.Button( self, wx.ID_CANCEL, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0 ) bSizer1.Add( self.m_button2, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 ) - bSizer3.Add( bSizer1, 0, wx.ALIGN_RIGHT|wx.EXPAND, 5 ) - self.SetSizer( bSizer3 ) self.Layout() + self.Fit() self.Centre( wx.BOTH ) + + self.m_radio_radius.Bind(wx.EVT_RADIOBUTTON, self.OnDimToggle) + self.m_radio_diameter.Bind(wx.EVT_RADIOBUTTON, self.OnDimToggle) + + def OnDimToggle(self, event): + if self.m_radio_radius.GetValue(): + new_label = u"Radius (mm)" + else: + new_label = u"Diameter (mm)" + + self.sbSizerValue.GetStaticBox().SetLabel(new_label) + self.sbSizerValue.Layout() + self.Refresh() + event.Skip() def __del__( self ): pass - -