CircularZone 2.0: layer selection, zone centered on selected pad
This commit is contained in:
1 parent
fa76f5e4e2
commit
0a8e177d05
3 files changed
+101
-997
No files matched your search
@@ -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()
|
||||
Reference in new issue
Block a user