Reformat + set parameters of VECTOR2I as int

This commit is contained in:
Jean-Samuel REYNAUD
2024-01-21 15:00:05 +01:00
parent 54a4b78d19
commit a7120d73d4

View File

@ -39,7 +39,7 @@ def wxPrint(msg):
#
if sys.version[0] == '2': # maui
if sys.version[0] == "2": # maui
None
else:
xrange = range
@ -233,12 +233,13 @@ class FillArea:
"""
print("_" * (len(rectangle) + 2))
for y in range(len(rectangle[0])):
print("|", end='')
print("|", end="")
for x in range(len(rectangle)):
print("%s" % self.GetReasonSymbol(rectangle[x][y]), end='')
print("%s" % self.GetReasonSymbol(rectangle[x][y]), end="")
print("|")
print("_" * (len(rectangle) + 2))
print('''
print(
"""
OK = 'X'
NO_SIGNAL = ' '
OTHER_SIGNAL = 'O'
@ -247,7 +248,8 @@ TRACK = 'T'
PAD = 'P'
DRAWING = 'D'
STEP = '-'
''')
"""
)
def AddVia(self, position, x, y):
if self.parent_area:
@ -273,7 +275,7 @@ STEP = '-'
for i in range(self.pcb.GetAreaCount()):
area = self.pcb.GetArea(i)
# No more making a real refill since it's crashing KiCad
if Version() < '7':
if Version() < "7":
None
else:
area.SetNeedRefill(True)
@ -282,9 +284,9 @@ STEP = '-'
# filler.Fill(self.pcb.Zones())
def CheckViaInAllAreas(self, via, all_areas):
'''
"""
Checks if an existing Via collides with another area
'''
"""
# Enum all area
for area in all_areas:
area_layer = area.GetLayer()
@ -292,20 +294,20 @@ STEP = '-'
area_priority = area.GetAssignedPriority()
is_rules_area = area.GetIsRuleArea()
is_rule_exclude_via_area = area.GetIsRuleArea() and area.GetDoNotAllowVias()
is_target_net = (area.GetNetname() == self.netname) # (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 or is_rule_exclude_via_area): # Only process areas that are not in the target net or is a rule area that could exlude vias
if not is_target_net or is_rule_exclude_via_area: # Only process areas that are not in the target net or is a rule area that could exlude vias
# print("Process...")
# 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]:
# All 4 corners of the via are testet (upper, lower, left, right) but not the center
for dy in [-offset, offset]:
point_to_test = VECTOR2I(via.PosX + dx, via.PosY + dy)
point_to_test = VECTOR2I(int(via.PosX + dx), int(via.PosY + dy))
hit_test_area = False
if Version() < '7':
if Version() < "7":
# below 7.0.0
for layer_id in area.GetLayerSet().CuStack():
hit_test_area = hit_test_area or area.HitTestFilledArea(layer_id, point_to_test) # Collides with a filled area
@ -335,8 +337,9 @@ STEP = '-'
elif (not self.via_through_areas) and hit_test_zone and not is_rules_area:
# 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() == 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
@ -347,7 +350,7 @@ STEP = '-'
return self.REASON_OK
def ClearViaInStepSize(self, rectangle, x, y, distance):
'''
"""
Stepsize==0
O O O O O O O O O
O O O O O O O O O
@ -374,7 +377,7 @@ STEP = '-'
O O O O O
O O O O
O O O O O
'''
"""
for x_pos in range(x - distance, x + distance + 1):
if (x_pos >= 0) and (x_pos < len(rectangle)):
# Star or Standard shape
@ -434,7 +437,7 @@ STEP = '-'
for zone in zones:
if zone.IsOnLayer(layer_id):
if poly_set is not None or not self.only_selected_area or zone.IsSelected():
if Version() < '7':
if Version() < "7":
# below 7.0.0
poly_set_layer.Append(zone.RawPolysList(layer_id))
else:
@ -507,7 +510,8 @@ STEP = '-'
if self.delete_vias:
# Do not perform a real delete since exposed function in python are not safe for deletion
wx.MessageBox(
"To delete vias:\n - select one of the generated via to select the group of vias named {}\n - hit delete key\n - That's all !".format(VIA_GROUP_NAME), "Information")
"To delete vias:\n - select one of the generated via to select the group of vias named {}\n - hit delete key\n - That's all !".format(VIA_GROUP_NAME), "Information"
)
"""
if self.pcb_group is not None:
@ -553,14 +557,11 @@ STEP = '-'
x_limit = int((lboard.GetWidth() + l_clearance) / l_clearance) + 1
y_limit = int((lboard.GetHeight() + l_clearance) / l_clearance) + 1
if self.debug:
print("l_clearance : {}; step : {}; size: {}; clearance: {}; x/y_limit ({} {}),board size : {} {}".format(l_clearance,
self.step,
self.size,
self.clearance,
x_limit,
y_limit,
lboard.GetWidth(),
lboard.GetHeight()))
print(
"l_clearance : {}; step : {}; size: {}; clearance: {}; x/y_limit ({} {}),board size : {} {}".format(
l_clearance, self.step, self.size, self.clearance, x_limit, y_limit, lboard.GetWidth(), lboard.GetHeight()
)
)
rectangle = [[self.REASON_NO_SIGNAL] * y_limit for i in xrange(x_limit)]
if self.debug:
@ -572,11 +573,9 @@ STEP = '-'
if self.debug:
print("%s: Line %u" % (time.time(), currentframe().f_lineno))
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:
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")
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
@ -624,10 +623,9 @@ STEP = '-'
offset = 0 # Use an exact zone match
point_to_test = VECTOR2I(int(current_x), int(current_y))
hit_test_area = False
if Version() < '7':
if Version() < "7":
# below 7.0.0
hit_test_area = area.HitTestFilledArea(
area.GetLayer(), VECTOR2I(point_to_test), int(offset)) # Collides with a filled area
hit_test_area = area.HitTestFilledArea(area.GetLayer(), VECTOR2I(point_to_test), int(offset)) # Collides with a filled area
else:
# 7.0.0 and above
for i in range(0, area.Outline().OutlineCount()):
@ -636,9 +634,9 @@ STEP = '-'
# Collides with an edge/corner
hit_test_edge = area.HitTestForEdge(point_to_test, int(max(area_clearance, offset)))
# 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)
test_result = hit_test_area and not hit_test_edge
test_result = (test_result and board_edge.Collide(point_to_test)) # check if inside board outline
test_result = test_result and board_edge.Collide(point_to_test) # check if inside board outline
if test_result:
# Create a via object with information about the via and place it in the rectangle
@ -681,8 +679,7 @@ STEP = '-'
for y in range(start_y, stop_y + 1):
try:
if isinstance(rectangle[x][y], ViaObject):
start_rect = VECTOR2I(origin.x + (l_clearance * x) - local_offset,
origin.y + (l_clearance * y) - local_offset)
start_rect = VECTOR2I(origin.x + (l_clearance * x) - local_offset, origin.y + (l_clearance * y) - local_offset)
size_rect = VECTOR2I(2 * local_offset, 2 * local_offset)
if pad.HitTest(BOX2I(start_rect, size_rect), False):
rectangle[x][y] = self.REASON_PAD
@ -729,8 +726,7 @@ STEP = '-'
opx = stop_x
opy = stop_y
clearance = max(track.GetOwnClearance(UNDEFINED_LAYER, ""), self.clearance, max_target_area_clearance) + \
(self.size / 2) + (track.GetWidth() / 2)
clearance = max(track.GetOwnClearance(UNDEFINED_LAYER, ""), self.clearance, max_target_area_clearance) + (self.size / 2) + (track.GetWidth() / 2)
start_x = int(floor(((start_x - clearance) - origin.x) / l_clearance))
stop_x = int(ceil(((stop_x + clearance) - origin.x) / l_clearance))
@ -742,8 +738,7 @@ STEP = '-'
for y in range(start_y, stop_y + 1):
try:
if isinstance(rectangle[x][y], ViaObject):
start_rect = VECTOR2I(origin.x + (l_clearance * x) - clearance,
origin.y + (l_clearance * y) - clearance)
start_rect = VECTOR2I(origin.x + (l_clearance * x) - clearance, origin.y + (l_clearance * y) - clearance)
size_rect = VECTOR2I(2 * clearance, 2 * clearance)
if track.HitTest(BOX2I(start_rect, size_rect), False):
rectangle[x][y] = self.REASON_TRACK
@ -814,9 +809,10 @@ STEP = '-'
wxPrint(msg)
if __name__ == '__main__':
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: %s <KiCad pcb filename>" % sys.argv[0])
else:
import sys
FillArea(sys.argv[1]).SetDebug().Run()