k 5.14 compatibility (py2&3)

Fix compatibilty issues with:
KiCAD 5.1.4
Py2
Py3
Added Net Combo box
Added button icon image
This commit is contained in:
easyw
2019-09-26 23:34:59 +02:00
parent c3f4dfbc25
commit 8c29a5f573
6 changed files with 239 additions and 58 deletions

76
ViaStitching/FillArea.py Executable file → Normal file
View File

@ -28,6 +28,16 @@ import shutil
import os
import random
import pprint
import wx
def wxPrint(msg):
wx.LogMessage(msg)
#
if sys.version[0] == '2': #maui
xrange
else:
xrange = range
"""
# This script fills all areas of a specific net with Vias (Via Stitching)
@ -126,7 +136,7 @@ class FillArea:
self.SetPCB(LoadBoard(self.filename))
def SetDebug(self):
print("Set debug")
wxPrint("Set debug")
self.debug = True
return self
@ -146,7 +156,8 @@ class FillArea:
return self
def SetNetname(self, netname):
self.netname = netname.upper()
self.netname = netname #.upper()
#wx.LogMessage(self.netname)
return self
def SetStepMM(self, s):
@ -222,8 +233,9 @@ STEP = '-'
m.SetViaType(VIA_THROUGH)
m.SetDrill(int(self.drill))
m.SetWidth(int(self.size))
# No more possible to mark via as own since no timestamp_t binding
#m.SetTimeStamp(33) # USE 33 as timestamp to mark this via as generated
# again possible to mark via as own since no timestamp_t binding kicad v5.1.4
m.SetTimeStamp(33) # USE 33 as timestamp to mark this via as generated by this script
#wx.LogMessage('adding vias')
self.pcb.Add(m)
def RefillBoardAreas(self):
@ -244,7 +256,8 @@ STEP = '-'
area_clearance = area.GetClearance()
area_priority = area.GetPriority()
is_keepout_area = area.GetIsKeepout()
is_target_net = (area.GetNetname().upper() == self.netname)
is_target_net = (area.GetNetname() == self.netname) #(area.GetNetname().upper() == self.netname)
wx.LogMessage(area.GetNetname()) #wx.LogMessage(area.GetNetname().upper())
if (not is_target_net): # Only process areas that are not in the target net
offset = max(self.clearance, area_clearance) + self.size / 2 # Offset is half the size of the via plus the clearance of the via or the area
@ -253,7 +266,7 @@ STEP = '-'
point_to_test = wxPoint(via.PosX + dx, via.PosY + dy)
hit_test_area = area.HitTestFilledArea(point_to_test) # Collides with a filled area
hit_test_edge = area.HitTestForEdge(point_to_test) # Collides with an edge/corner
hit_test_edge = area.HitTestForEdge(point_to_test,1) # Collides with an edge/corner
hit_test_zone = area.HitTestInsideZone(point_to_test) # Is inside a zone (e.g. KeepOut)
if is_keepout_area and (hit_test_area or hit_test_edge or hit_test_zone):
@ -264,7 +277,8 @@ STEP = '-'
elif hit_test_zone:
# Check if the zone is higher priority than other zones of the target net in the same point
target_areas_on_same_layer = filter(lambda x: ((x.GetPriority() > area_priority) and (x.GetLayer() == area_layer) and (x.GetNetname().upper() == self.netname)), all_areas)
#target_areas_on_same_layer = filter(lambda x: ((x.GetPriority() > area_priority) and (x.GetLayer() == area_layer) and (x.GetNetname().upper() == self.netname)), all_areas)
target_areas_on_same_layer = filter(lambda x: ((x.GetPriority() > area_priority) and (x.GetLayer() == area_layer) and (x.GetNetname() == self.netname)), all_areas)
for area_with_higher_priority in target_areas_on_same_layer:
if area_with_higher_priority.HitTestInsideZone(point_to_test):
break # Area of target net has higher priority on this layer
@ -318,15 +332,16 @@ STEP = '-'
target_tracks = self.pcb.GetTracks()
if self.delete_vias:
# timestmap no more available
# target_tracks = filter(lambda x: (x.GetNetname().upper() == self.netname), self.pcb.GetTracks())
# for via in target_tracks:
# pprint.pprint(via.GetTimeStamp())
# if via.Type() == PCB_VIA_T:
# if via.GetTimeStamp() == 33:
# self.pcb.RemoveNative(via)
# self.RefillBoardAreas()
return # no need to run the rest of logic
# timestmap again available
#target_tracks = filter(lambda x: (x.GetNetname().upper() == self.netname), self.pcb.GetTracks())
target_tracks = filter(lambda x: (x.GetNetname() == self.netname), self.pcb.GetTracks())
for via in target_tracks:
#pprint.pprint(via.GetTimeStamp())
if via.Type() == PCB_VIA_T:
if via.GetTimeStamp() == 33:
self.pcb.RemoveNative(via)
self.RefillBoardAreas()
return # no need to run the rest of logic
lboard = self.pcb.ComputeBoundingBox(True)
origin = lboard.GetPosition()
@ -343,14 +358,15 @@ STEP = '-'
all_tracks = self.pcb.GetTracks()
all_drawings = filter(lambda x: x.GetClass() == 'PTEXT' and self.pcb.GetLayerID(x.GetLayerName()) in (F_Cu, B_Cu), self.pcb.DrawingsList())
all_areas = [self.pcb.GetArea(i) for i in xrange(self.pcb.GetAreaCount())]
target_areas = filter(lambda x: (x.GetNetname().upper() == self.netname), all_areas) # KeepOuts are filtered because they have no name
#target_areas = filter(lambda x: (x.GetNetname().upper() == self.netname), all_areas) # KeepOuts are filtered because they have no name
target_areas = filter(lambda x: (x.GetNetname() == self.netname), all_areas) # KeepOuts are filtered because they have no name
via_list = [] # Create a list of existing vias => faster than scanning through the whole rectangle
max_target_area_clearance = 0
# Enum all target areas (Search possible positions for vias on the target net)
for area in target_areas:
print ("Processing Target Area: %s, LayerName: %s..." % (area.GetNetname(), area.GetLayerName()))
wxPrint ("Processing Target Area: %s, LayerName: %s..." % (area.GetNetname(), area.GetLayerName()))
is_selected_area = area.IsSelected()
area_clearance = area.GetClearance()
@ -381,22 +397,22 @@ STEP = '-'
via_list.append(via_obj)
if self.debug:
print("\nPost target areas:")
wxPrint("\nPost target areas:")
self.PrintRect(rectangle)
# Enum all vias
print ("Processing all vias of target area...")
wxPrint ("Processing all vias of target area...")
for via in via_list:
reason = self.CheckViaInAllAreas(via, all_areas)
if reason != self.REASON_OK:
rectangle[via.X][via.Y] = reason
if self.debug:
print("\nPost areas:")
wxPrint("\nPost areas:")
self.PrintRect(rectangle)
# Same job with all pads => all pads on all layers
print ("Processing all pads...")
wxPrint ("Processing all pads...")
for pad in all_pads:
local_offset = max(pad.GetClearance(), self.clearance, max_target_area_clearance) + (self.size / 2)
max_size = max(pad.GetSize().x, pad.GetSize().y)
@ -417,11 +433,11 @@ STEP = '-'
rectangle[x][y] = self.REASON_PAD
if self.debug:
print("\nPost pads:")
wxPrint("\nPost pads:")
self.PrintRect(rectangle)
# Same job with tracks => all tracks on all layers
print ("Processing all tracks...")
wxPrint ("Processing all tracks...")
for track in all_tracks:
start_x = track.GetStart().x
start_y = track.GetStart().y
@ -462,11 +478,11 @@ STEP = '-'
rectangle[x][y] = self.REASON_TRACK
if self.debug:
print("\nPost tracks:")
wxPrint("\nPost tracks:")
self.PrintRect(rectangle)
# Same job with existing text
print ("Processing all existing drawings...")
wxPrint ("Processing all existing drawings...")
for draw in all_drawings:
inter = float(self.clearance + self.size)
bbox = draw.GetBoundingBox()
@ -482,10 +498,10 @@ STEP = '-'
rectangle[x][y] = self.REASON_DRAWING
if self.debug:
print("Post Drawnings:")
wxPrint("Post Drawnings:")
self.PrintRect(rectangle)
print ("Remove vias to guarantee step size...")
wxPrint ("Remove vias to guarantee step size...")
clear_distance = 0
if self.step != 0.0:
clear_distance = int((self.step+l_clearance) / l_clearance) # How much "via steps" should be removed around a via (round up)
@ -507,14 +523,14 @@ STEP = '-'
self.AddVia(wxPoint(via.PosX + ran_x, via.PosY + ran_y), via.X, via.Y)
if self.debug:
print("\nFinal result:")
wxPrint("\nFinal result:")
self.PrintRect(rectangle)
self.RefillBoardAreas()
if self.filename:
self.pcb.Save(self.filename)
print ("Done!")
wxPrint ("Done!")
if __name__ == '__main__':
if len(sys.argv) < 2:

View File

@ -22,8 +22,18 @@ import pcbnew
import wx
from . import FillArea
from . import FillAreaDialog
import os
def PopulateNets(anet,dlg):
nets = pcbnew.GetBoard().GetNetsByName()
for netname, net in nets.items():
netname = net.GetNetname()
if netname != None and netname != "":
dlg.m_cbNet.Append(netname)
if anet != None:
index = dlg.m_cbNet.FindString(anet)
dlg.m_cbNet.Select(index)
#
class FillAreaDialogEx(FillAreaDialog.FillAreaDialog):
def onDeleteClick(self, event):
@ -33,27 +43,33 @@ class FillAreaDialogEx(FillAreaDialog.FillAreaDialog):
class FillAreaAction(pcbnew.ActionPlugin):
def defaults(self):
self.name = "Via stitching WX"
self.category = "Undefined"
self.description = ""
self.name = "Via Stitching"
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")
def Run(self):
a = FillAreaDialogEx(None)
a.m_SizeMM.SetValue("0.46")
a.m_SizeMM.SetValue("0.8")
a.m_StepMM.SetValue("2.54")
a.m_DrillMM.SetValue("0.2")
a.m_Netname.SetValue("GND")
a.m_DrillMM.SetValue("0.3")
#a.m_Netname.SetValue("GND")
a.m_ClearanceMM.SetValue("0.2")
a.m_Star.SetValue(True)
self.board = pcbnew.GetBoard()
PopulateNets("GND",a)
modal_result = a.ShowModal()
if modal_result == wx.ID_OK:
try:
wx.LogMessage('Via Stitching: Version 1.3')
if 1: #try:
fill = FillArea.FillArea()
fill.SetStepMM(float(a.m_StepMM.GetValue()))
fill.SetSizeMM(float(a.m_SizeMM.GetValue()))
fill.SetDrillMM(float(a.m_DrillMM.GetValue()))
fill.SetClearanceMM(float(a.m_ClearanceMM.GetValue()))
fill.SetNetname(a.m_Netname.GetValue())
#fill.SetNetname(a.m_Netname.GetValue())
netname = a.m_cbNet.GetStringSelection()
fill.SetNetname(netname)
if a.m_Debug.IsChecked():
fill.SetDebug()
if a.m_Random.IsChecked():
@ -63,17 +79,17 @@ class FillAreaAction(pcbnew.ActionPlugin):
if a.m_only_selected.IsChecked():
fill.OnlyOnSelectedArea()
fill.Run()
except Exception:
else: #except Exception:
wx.MessageDialog(None, "Invalid parameter")
elif modal_result == wx.ID_DELETE:
try:
if 1: #try:
fill = FillArea.FillArea()
fill.SetNetname(a.m_Netname.GetValue())
fill.SetNetname(a.m_cbNet.GetStringSelection()) #a.m_Netname.GetValue())
if a.m_Debug.IsChecked():
fill.SetDebug()
fill.DeleteVias()
fill.Run()
except Exception:
else: #except Exception:
wx.MessageDialog(None, "Invalid parameter for delete")
else:
print("Cancel")

View File

@ -17,9 +17,14 @@ import wx.xrc
class FillAreaDialog ( wx.Dialog ):
def __init__( self, parent ):
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Fill Area parameters", pos = wx.DefaultPosition, size = wx.Size( 369,389 ), style = wx.DEFAULT_DIALOG_STYLE )
wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Fill Area parameters", pos = wx.DefaultPosition, size = wx.Size( 402,487 ), style = wx.DEFAULT_DIALOG_STYLE )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
import sys
if sys.version_info[0] == 2:
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
else:
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
#self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer3 = wx.BoxSizer( wx.VERTICAL )
@ -54,8 +59,9 @@ class FillAreaDialog ( wx.Dialog ):
self.m_staticText6.Wrap( -1 )
fgSizer1.Add( self.m_staticText6, 1, wx.ALL|wx.EXPAND, 5 )
self.m_Netname = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
fgSizer1.Add( self.m_Netname, 1, wx.ALL|wx.EXPAND, 5 )
m_cbNetChoices = []
self.m_cbNet = wx.ComboBox( self, wx.ID_ANY, u"GND", wx.DefaultPosition, wx.DefaultSize, m_cbNetChoices, 0 )
fgSizer1.Add( self.m_cbNet, 0, wx.ALL, 5 )
self.m_staticText2 = wx.StaticText( self, wx.ID_ANY, u"Step between via", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText2.Wrap( -1 )

View File

@ -44,7 +44,7 @@
<property name="minimum_size"></property>
<property name="name">FillAreaDialog</property>
<property name="pos"></property>
<property name="size">369,389</property>
<property name="size">402,487</property>
<property name="style">wxDEFAULT_DIALOG_STYLE</property>
<property name="subclass"></property>
<property name="title">Fill Area parameters</property>
@ -714,11 +714,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxTextCtrl" expanded="0">
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxComboBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -732,6 +732,7 @@
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="choices"></property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
@ -749,12 +750,11 @@
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_Netname</property>
<property name="name">m_cbNet</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -762,6 +762,7 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="selection">-1</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
@ -772,11 +773,14 @@
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="value">GND</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnChar"></event>
<event name="OnCombobox"></event>
<event name="OnComboboxCloseup"></event>
<event name="OnComboboxDropdown"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnKeyDown"></event>
@ -800,8 +804,6 @@
<event name="OnSize"></event>
<event name="OnText"></event>
<event name="OnTextEnter"></event>
<event name="OnTextMaxLen"></event>
<event name="OnTextURL"></event>
<event name="OnUpdateUI"></event>
</object>
</object>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="27.733334"
width="27.733334"
version="1.1"
id="svg2"
inkscape:version="0.92.3 (2405546, 2018-03-11)"
sodipodi:docname="stitching-vias-light-2.svg"
viewBox="0 0 26 26"
inkscape:export-filename="/home/mau/.kicad_plugins/ViaStitching/stitching-vias.png"
inkscape:export-xdpi="110.76923"
inkscape:export-ydpi="110.76923">
<metadata
id="metadata40">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1600"
inkscape:window-height="824"
id="namedview38"
showgrid="true"
inkscape:snap-to-guides="false"
inkscape:snap-grids="true"
inkscape:zoom="3.8691149"
inkscape:cx="-70.189363"
inkscape:cy="6.1701956"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg2"
showguides="true"
inkscape:guide-bbox="true">
<inkscape:grid
type="xygrid"
id="grid3017"
empspacing="2"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
spacingx="0.5"
spacingy="0.5"
originx="0"
originy="0" />
</sodipodi:namedview>
<defs
id="defs4">
<filter
id="c"
height="1.3651"
width="1.2097"
y="-0.18257"
x="-0.10484"
style="color-interpolation-filters:sRGB">
<feGaussianBlur
stdDeviation="1.5978799"
id="feGaussianBlur7" />
</filter>
<filter
id="d"
height="1.4696"
width="1.4809999"
y="-0.23481999"
x="-0.24049"
style="color-interpolation-filters:sRGB">
<feGaussianBlur
stdDeviation="1.5978799"
id="feGaussianBlur10" />
</filter>
</defs>
<rect
style="opacity:0.25;fill:#008000;fill-opacity:1;stroke:#b3b3b3;stroke-width:2.24165964;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:1.99997282;stroke-opacity:1"
id="rect4737"
width="26"
height="26"
x="-0.00085260201"
y="1.7193647e-08"
inkscape:export-filename="C:\kicad-wb-1602\msys64\home\userC\RF-round-diff\new-solder-mask\bitmaps_png\sources\stitching-vias.png"
inkscape:export-xdpi="101.97701"
inkscape:export-ydpi="101.97701" />
<g
transform="matrix(1.6382539,0,0,1.5572263,1.2572207,0.36314149)"
id="g16"
inkscape:export-xdpi="101.97701"
inkscape:export-ydpi="101.97701"
inkscape:export-filename="C:\kicad-wb-1602\msys64\home\userC\RF-round-diff\new-solder-mask\bitmaps_png\sources\stitching-vias.png">
<rect
height="16"
width="16"
y="0"
x="0"
id="rect18"
style="fill-opacity:0" />
</g>
<path
d="m 9.5,7.625 c 0,-1.932997 1.567003,-3.4999999 3.5,-3.4999999 1.932997,0 3.5,1.5670029 3.5,3.4999999 0,1.932997 -1.567003,3.5 -3.5,3.5 -1.932997,0 -3.5,-1.567003 -3.5,-3.5 z"
style="opacity:1;fill:none;fill-opacity:1;stroke:#ffcc00;stroke-width:2.4375;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3867-9-4"
inkscape:connector-curvature="0"
inkscape:export-xdpi="82.105263"
inkscape:export-ydpi="82.105263"
sodipodi:nodetypes="sssss" />
<path
d="m 15.25,18.25 c 0,-1.932997 1.567003,-3.5 3.5,-3.5 1.932997,0 3.5,1.567003 3.5,3.5 0,1.932997 -1.567003,3.5 -3.5,3.5 -1.932997,0 -3.5,-1.567003 -3.5,-3.5 z"
style="opacity:1;fill:none;fill-opacity:1;stroke:#ffcc00;stroke-width:2.4375;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3867-9-4-6"
inkscape:connector-curvature="0"
inkscape:export-xdpi="82.105263"
inkscape:export-ydpi="82.105263"
sodipodi:nodetypes="sssss" />
<path
d="m 3.75,18.375 c 0,-1.932997 1.567003,-3.5 3.5,-3.5 1.932997,0 3.5,1.567003 3.5,3.5 0,1.932997 -1.567003,3.5 -3.5,3.5 -1.932997,0 -3.5,-1.567003 -3.5,-3.5 z"
style="opacity:1;fill:none;fill-opacity:1;stroke:#ffcc00;stroke-width:2.4375;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3867-9-4-3"
inkscape:connector-curvature="0"
inkscape:export-xdpi="82.105263"
inkscape:export-ydpi="82.105263"
sodipodi:nodetypes="sssss" />
</svg>

After

Width:  |  Height:  |  Size: 5.1 KiB