PEP8 + use a complete boundary box
This commit is contained in:
@ -30,8 +30,11 @@ import random
|
|||||||
import pprint
|
import pprint
|
||||||
import wx
|
import wx
|
||||||
|
|
||||||
|
|
||||||
def wxPrint(msg):
|
def wxPrint(msg):
|
||||||
wx.LogMessage(msg)
|
wx.LogMessage(msg)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
if sys.version[0] == '2': # maui
|
if sys.version[0] == '2': # maui
|
||||||
xrange
|
xrange
|
||||||
@ -70,6 +73,7 @@ FillArea.FillArea().SetDebug().SetNetname("GND").SetStepMM(1.27).SetSizeMM(0.6).
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class ViaObject:
|
class ViaObject:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -82,6 +86,7 @@ class ViaObject:
|
|||||||
self.PosX = pos_x
|
self.PosX = pos_x
|
||||||
self.PosY = pos_y
|
self.PosY = pos_y
|
||||||
|
|
||||||
|
|
||||||
class FillArea:
|
class FillArea:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -243,7 +248,7 @@ STEP = '-'
|
|||||||
area = self.pcb.GetArea(i)
|
area = self.pcb.GetArea(i)
|
||||||
area.ClearFilledPolysList()
|
area.ClearFilledPolysList()
|
||||||
area.UnFill()
|
area.UnFill()
|
||||||
filler = ZONE_FILLER(self.pcb);
|
filler = ZONE_FILLER(self.pcb)
|
||||||
filler.Fill(self.pcb.Zones())
|
filler.Fill(self.pcb.Zones())
|
||||||
|
|
||||||
def CheckViaInAllAreas(self, via, all_areas):
|
def CheckViaInAllAreas(self, via, all_areas):
|
||||||
@ -260,9 +265,11 @@ STEP = '-'
|
|||||||
# wx.LogMessage(area.GetNetname()) #wx.LogMessage(area.GetNetname().upper())
|
# wx.LogMessage(area.GetNetname()) #wx.LogMessage(area.GetNetname().upper())
|
||||||
|
|
||||||
if (not is_target_net): # Only process areas that are not in the target net
|
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
|
# Offset is half the size of the via plus the clearance of the via or the area
|
||||||
|
offset = max(self.clearance, area_clearance) + self.size / 2
|
||||||
for dx in [-offset, offset]:
|
for dx in [-offset, offset]:
|
||||||
for dy in [-offset, offset]: # All 4 corners of the via are testet (upper, lower, left, right) but not the center
|
# All 4 corners of the via are testet (upper, lower, left, right) but not the center
|
||||||
|
for dy in [-offset, offset]:
|
||||||
point_to_test = wxPoint(via.PosX + dx, via.PosY + dy)
|
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_area = area.HitTestFilledArea(point_to_test) # Collides with a filled area
|
||||||
@ -277,17 +284,20 @@ STEP = '-'
|
|||||||
return self.REASON_KEEPOUT # Collides with keepout
|
return self.REASON_KEEPOUT # Collides with keepout
|
||||||
|
|
||||||
elif (hit_test_area or hit_test_edge):
|
elif (hit_test_area or hit_test_edge):
|
||||||
return self.REASON_OTHER_SIGNAL # Collides with another signal (e.g. on another layer)
|
# Collides with another signal (e.g. on another layer)
|
||||||
|
return self.REASON_OTHER_SIGNAL
|
||||||
|
|
||||||
elif hit_test_zone:
|
elif hit_test_zone:
|
||||||
# Check if the zone is higher priority than other zones of the target net in the same point
|
# 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)
|
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:
|
for area_with_higher_priority in target_areas_on_same_layer:
|
||||||
if area_with_higher_priority.HitTestInsideZone(point_to_test):
|
if area_with_higher_priority.HitTestInsideZone(point_to_test):
|
||||||
break # Area of target net has higher priority on this layer
|
break # Area of target net has higher priority on this layer
|
||||||
else:
|
else:
|
||||||
return self.REASON_OTHER_SIGNAL # Collides with another signal (e.g. on another layer)
|
# Collides with another signal (e.g. on another layer)
|
||||||
|
return self.REASON_OTHER_SIGNAL
|
||||||
|
|
||||||
return self.REASON_OK
|
return self.REASON_OK
|
||||||
|
|
||||||
@ -347,7 +357,7 @@ STEP = '-'
|
|||||||
self.RefillBoardAreas()
|
self.RefillBoardAreas()
|
||||||
return # no need to run the rest of logic
|
return # no need to run the rest of logic
|
||||||
|
|
||||||
lboard = self.pcb.ComputeBoundingBox(True)
|
lboard = self.pcb.ComputeBoundingBox(False)
|
||||||
origin = lboard.GetPosition()
|
origin = lboard.GetPosition()
|
||||||
|
|
||||||
# Create an initial rectangle: all is set to "REASON_NO_SIGNAL"
|
# Create an initial rectangle: all is set to "REASON_NO_SIGNAL"
|
||||||
@ -361,13 +371,16 @@ STEP = '-'
|
|||||||
all_pads = self.pcb.GetPads()
|
all_pads = self.pcb.GetPads()
|
||||||
all_tracks = self.pcb.GetTracks()
|
all_tracks = self.pcb.GetTracks()
|
||||||
try:
|
try:
|
||||||
all_drawings = filter(lambda x: x.GetClass() == 'PTEXT' and self.pcb.GetLayerID(x.GetLayerName()) in (F_Cu, B_Cu), self.pcb.DrawingsList())
|
all_drawings = filter(lambda x: x.GetClass() == 'PTEXT' and self.pcb.GetLayerID(
|
||||||
|
x.GetLayerName()) in (F_Cu, B_Cu), self.pcb.DrawingsList())
|
||||||
except:
|
except:
|
||||||
all_drawings = filter(lambda x: x.GetClass() == 'PTEXT' and self.pcb.GetLayerID(x.GetLayerName()) in (F_Cu, B_Cu), self.pcb.Drawings())
|
all_drawings = filter(lambda x: x.GetClass() == 'PTEXT' and self.pcb.GetLayerID(
|
||||||
|
x.GetLayerName()) in (F_Cu, B_Cu), self.pcb.Drawings())
|
||||||
#wxPrint("exception on missing BOARD.DrawingsList")
|
#wxPrint("exception on missing BOARD.DrawingsList")
|
||||||
all_areas = [self.pcb.GetArea(i) for i in xrange(self.pcb.GetAreaCount())]
|
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
|
# KeepOuts are filtered because they have no name
|
||||||
|
target_areas = filter(lambda x: (x.GetNetname() == self.netname), all_areas)
|
||||||
|
|
||||||
via_list = [] # Create a list of existing vias => faster than scanning through the whole rectangle
|
via_list = [] # Create a list of existing vias => faster than scanning through the whole rectangle
|
||||||
max_target_area_clearance = 0
|
max_target_area_clearance = 0
|
||||||
@ -382,25 +395,32 @@ STEP = '-'
|
|||||||
max_target_area_clearance = area_clearance
|
max_target_area_clearance = area_clearance
|
||||||
|
|
||||||
if (not self.only_selected_area) or (self.only_selected_area and is_selected_area): # All areas or only the selected area
|
if (not self.only_selected_area) or (self.only_selected_area and is_selected_area): # All areas or only the selected area
|
||||||
for x in xrange(len(rectangle)): # Check every possible point in the virtual coordinate system
|
# Check every possible point in the virtual coordinate system
|
||||||
|
for x in xrange(len(rectangle)):
|
||||||
for y in xrange(len(rectangle[0])):
|
for y in xrange(len(rectangle[0])):
|
||||||
if rectangle[x][y] == self.REASON_NO_SIGNAL: # No other "target area" found yet => go on with processing
|
# No other "target area" found yet => go on with processing
|
||||||
|
if rectangle[x][y] == self.REASON_NO_SIGNAL:
|
||||||
current_x = origin.x + (x * l_clearance) # Center of the via
|
current_x = origin.x + (x * l_clearance) # Center of the via
|
||||||
current_y = origin.y + (y * l_clearance)
|
current_y = origin.y + (y * l_clearance)
|
||||||
|
|
||||||
test_result = True # Start with true, if a check fails, it is set to false
|
test_result = True # Start with true, if a check fails, it is set to false
|
||||||
|
|
||||||
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
|
# Offset is half the size of the via plus the clearance of the via or the area
|
||||||
|
offset = max(self.clearance, area_clearance) + self.size / 2
|
||||||
for dx in [-offset, offset]:
|
for dx in [-offset, offset]:
|
||||||
for dy in [-offset, offset]: # All 4 corners of the via are testet (upper, lower, left, right) but not the center
|
# All 4 corners of the via are testet (upper, lower, left, right) but not the center
|
||||||
|
for dy in [-offset, offset]:
|
||||||
point_to_test = wxPoint(current_x + dx, current_y + dy)
|
point_to_test = wxPoint(current_x + dx, current_y + dy)
|
||||||
hit_test_area = area.HitTestFilledArea(point_to_test) # Collides with a filled area
|
hit_test_area = area.HitTestFilledArea(point_to_test) # Collides with a filled area
|
||||||
hit_test_edge = area.HitTestForEdge(point_to_test,area_clearance) # Collides with an edge/corner
|
# Collides with an edge/corner
|
||||||
|
hit_test_edge = area.HitTestForEdge(point_to_test, area_clearance)
|
||||||
|
|
||||||
test_result &= (hit_test_area and not hit_test_edge) # test_result only remains true if the via is inside an area and not on an edge
|
# test_result only remains true if the via is inside an area and not on an edge
|
||||||
|
test_result &= (hit_test_area and not hit_test_edge)
|
||||||
|
|
||||||
if test_result:
|
if test_result:
|
||||||
via_obj = ViaObject(x=x, y=y, pos_x=current_x, pos_y=current_y) # Create a via object with information about the via and place it in the rectangle
|
# Create a via object with information about the via and place it in the rectangle
|
||||||
|
via_obj = ViaObject(x=x, y=y, pos_x=current_x, pos_y=current_y)
|
||||||
rectangle[x][y] = via_obj
|
rectangle[x][y] = via_obj
|
||||||
via_list.append(via_obj)
|
via_list.append(via_obj)
|
||||||
|
|
||||||
@ -480,12 +500,15 @@ STEP = '-'
|
|||||||
|
|
||||||
for x in range(start_x, stop_x + 1):
|
for x in range(start_x, stop_x + 1):
|
||||||
for y in range(start_y, stop_y + 1):
|
for y in range(start_y, stop_y + 1):
|
||||||
|
try:
|
||||||
if isinstance(rectangle[x][y], ViaObject):
|
if isinstance(rectangle[x][y], ViaObject):
|
||||||
start_rect = wxPoint(origin.x + (l_clearance * x) - clearance,
|
start_rect = wxPoint(origin.x + (l_clearance * x) - clearance,
|
||||||
origin.y + (l_clearance * y) - clearance)
|
origin.y + (l_clearance * y) - clearance)
|
||||||
size_rect = wxSize(2 * clearance, 2 * clearance)
|
size_rect = wxSize(2 * clearance, 2 * clearance)
|
||||||
if track.HitTest(EDA_RECT(start_rect, size_rect), False):
|
if track.HitTest(EDA_RECT(start_rect, size_rect), False):
|
||||||
rectangle[x][y] = self.REASON_TRACK
|
rectangle[x][y] = self.REASON_TRACK
|
||||||
|
except:
|
||||||
|
wxPrint("exception on Processing all tracks...")
|
||||||
|
|
||||||
if self.debug:
|
if self.debug:
|
||||||
wxPrint("\nPost tracks:")
|
wxPrint("\nPost tracks:")
|
||||||
@ -514,7 +537,8 @@ STEP = '-'
|
|||||||
wxPrint("Remove vias to guarantee step size...")
|
wxPrint("Remove vias to guarantee step size...")
|
||||||
clear_distance = 0
|
clear_distance = 0
|
||||||
if self.step != 0.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)
|
# How much "via steps" should be removed around a via (round up)
|
||||||
|
clear_distance = int((self.step+l_clearance) / l_clearance)
|
||||||
|
|
||||||
for x in xrange(len(rectangle)):
|
for x in xrange(len(rectangle)):
|
||||||
for y in xrange(len(rectangle[0])):
|
for y in xrange(len(rectangle[0])):
|
||||||
@ -542,6 +566,7 @@ STEP = '-'
|
|||||||
self.pcb.Save(self.filename)
|
self.pcb.Save(self.filename)
|
||||||
wxPrint("Done!")
|
wxPrint("Done!")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print("Usage: %s <KiCad pcb filename>" % sys.argv[0])
|
print("Usage: %s <KiCad pcb filename>" % sys.argv[0])
|
||||||
|
Reference in New Issue
Block a user