ViaStitching 1.2: KiCad 10 support, remember last values
- numeric KiCad version check (string compare broke on 10.x) - GetBoardPolygonOutlines, PCB_VIA.GetWidth, PAD.GetEffectivePolygon: KiCad 10 API - default grid 2.5 mm - dialog values saved to ViaStitching.json in KiCad user settings dir - net list: only nets with a zone, GND first and preselected - add metadata.json - README: KiCad 10
This commit is contained in:
1 parent
46e744d886
commit
ae5f101eda
4 files changed
+171
-18
No files matched your search
@@ -23,18 +23,87 @@ import wx
|
||||
from . import FillArea
|
||||
from . import FillAreaDialog
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
def PopulateNets(anet, dlg):
|
||||
netnames = list(set([zone.GetNetname() for zone in pcbnew.GetBoard().Zones()]))
|
||||
netnames.sort()
|
||||
"""Fill the net list with nets that have a zone (GND first).
|
||||
|
||||
Preselects GND; if the board has no GND zone, falls back to anet
|
||||
(last used net), then to the first net in the list.
|
||||
"""
|
||||
netnames = sorted(set(zone.GetNetname() for zone in pcbnew.GetBoard().Zones()) - {""})
|
||||
if "GND" in netnames:
|
||||
netnames.remove("GND")
|
||||
netnames.insert(0, "GND")
|
||||
dlg.m_cbNet.Set(netnames)
|
||||
if anet is not None:
|
||||
index = dlg.m_cbNet.FindString(anet)
|
||||
dlg.m_cbNet.Select(index)
|
||||
for name in ("GND", anet):
|
||||
if name:
|
||||
index = dlg.m_cbNet.FindString(name)
|
||||
if index != wx.NOT_FOUND:
|
||||
dlg.m_cbNet.SetSelection(index)
|
||||
return
|
||||
if netnames:
|
||||
dlg.m_cbNet.SetSelection(0)
|
||||
#
|
||||
|
||||
|
||||
def SettingsFile():
|
||||
"""Path to the JSON file with the last used dialog values."""
|
||||
try:
|
||||
base = pcbnew.SETTINGS_MANAGER.GetUserSettingsPath()
|
||||
except Exception:
|
||||
base = os.path.dirname(os.path.realpath(__file__))
|
||||
return os.path.join(base, "ViaStitching.json")
|
||||
|
||||
|
||||
def LoadSettings():
|
||||
try:
|
||||
with open(SettingsFile(), "r") as f:
|
||||
data = json.load(f)
|
||||
return data if isinstance(data, dict) else {}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def SaveSettings(dlg):
|
||||
data = {
|
||||
"size": dlg.m_SizeMM.GetValue(),
|
||||
"drill": dlg.m_DrillMM.GetValue(),
|
||||
"clearance": dlg.m_ClearanceMM.GetValue(),
|
||||
"step": dlg.m_StepMM.GetValue(),
|
||||
"net": dlg.m_cbNet.GetStringSelection(),
|
||||
"fill_type": dlg.m_cbFillType.GetStringSelection(),
|
||||
"grid_type": dlg.m_cbGridType.GetStringSelection(),
|
||||
"random": dlg.m_Random.IsChecked(),
|
||||
"only_selected": dlg.m_only_selected.IsChecked(),
|
||||
"via_through_areas": dlg.m_viaThroughAreas.IsChecked(),
|
||||
"same_net_tracks": dlg.m_sameNetTracks.IsChecked(),
|
||||
}
|
||||
try:
|
||||
with open(SettingsFile(), "w") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
except Exception as e:
|
||||
wx.LogMessage("ViaStitching: cannot save settings: {}".format(e))
|
||||
|
||||
|
||||
def ApplySettings(dlg, data):
|
||||
for key, ctrl in (("size", dlg.m_SizeMM), ("drill", dlg.m_DrillMM),
|
||||
("clearance", dlg.m_ClearanceMM), ("step", dlg.m_StepMM)):
|
||||
if isinstance(data.get(key), str) and data[key].strip():
|
||||
ctrl.SetValue(data[key])
|
||||
for key, ctrl in (("random", dlg.m_Random), ("only_selected", dlg.m_only_selected),
|
||||
("via_through_areas", dlg.m_viaThroughAreas),
|
||||
("same_net_tracks", dlg.m_sameNetTracks)):
|
||||
if isinstance(data.get(key), bool):
|
||||
ctrl.SetValue(data[key])
|
||||
for key, ctrl in (("fill_type", dlg.m_cbFillType), ("grid_type", dlg.m_cbGridType)):
|
||||
if isinstance(data.get(key), str):
|
||||
index = ctrl.FindString(data[key])
|
||||
if index != wx.NOT_FOUND:
|
||||
ctrl.SetSelection(index)
|
||||
|
||||
|
||||
class FillAreaDialogEx(FillAreaDialog.FillAreaDialog):
|
||||
|
||||
def onDeleteClick(self, event):
|
||||
@@ -44,7 +113,7 @@ class FillAreaDialogEx(FillAreaDialog.FillAreaDialog):
|
||||
class FillAreaAction(pcbnew.ActionPlugin):
|
||||
|
||||
def defaults(self):
|
||||
self.name = "Via Stitching Generator 1.1"
|
||||
self.name = "Via Stitching Generator 1.2"
|
||||
self.category = "Modify PCB"
|
||||
self.description = "Via Stitching for PCB Zone"
|
||||
self.icon_file_name = os.path.join(os.path.dirname(__file__), "./stitching-vias.png")
|
||||
@@ -53,7 +122,7 @@ class FillAreaAction(pcbnew.ActionPlugin):
|
||||
def Run(self):
|
||||
a = FillAreaDialogEx(None)
|
||||
# a.m_SizeMM.SetValue("0.8")
|
||||
a.m_StepMM.SetValue("2.54")
|
||||
a.m_StepMM.SetValue("2.5")
|
||||
# a.m_DrillMM.SetValue("0.3")
|
||||
# a.m_Netname.SetValue("GND")
|
||||
# a.m_ClearanceMM.SetValue("0.2")
|
||||
@@ -65,10 +134,14 @@ class FillAreaAction(pcbnew.ActionPlugin):
|
||||
a.m_ClearanceMM.SetValue(str(pcbnew.ToMM(self.boardDesignSettings.GetSmallestClearanceValue())))
|
||||
a.SetMinSize(a.GetSize())
|
||||
|
||||
PopulateNets("GND", a)
|
||||
settings = LoadSettings()
|
||||
ApplySettings(a, settings)
|
||||
last_net = settings.get("net")
|
||||
PopulateNets(last_net if isinstance(last_net, str) else None, a)
|
||||
modal_result = a.ShowModal()
|
||||
if modal_result == wx.ID_OK:
|
||||
wx.LogMessage('Via Stitching')
|
||||
SaveSettings(a)
|
||||
if 1: # try:
|
||||
fill = FillArea.FillArea()
|
||||
fill.SetStepMM(float(a.m_StepMM.GetValue().replace(',', '.')))
|
||||
|
||||
Reference in new issue
Block a user