Foot gen: updated silkscreen of board outline to not intersect with the
courtyards of any parts
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from copy import deepcopy
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -70,6 +71,10 @@ for item in pcb.GetDrawings():
|
|||||||
brd_drawings.append(item)
|
brd_drawings.append(item)
|
||||||
# print("Text: ", item.GetText())
|
# print("Text: ", item.GetText())
|
||||||
# print("Layer: ", item.GetLayerName())
|
# print("Layer: ", item.GetLayerName())
|
||||||
|
elif "F.Courtyard" in item.GetLayerName():
|
||||||
|
brd_drawings.append(item)
|
||||||
|
# print("Text: ", item.GetText())
|
||||||
|
# print("Layer: ", item.GetLayerName())
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
print("New Footprint List: ", new_foots)
|
print("New Footprint List: ", new_foots)
|
||||||
@@ -191,22 +196,88 @@ kicad_mod.setTags("example")
|
|||||||
kicad_mod.append(Text(type='reference', text='REF**', at=[0,-3], layer='F.SilkS'))
|
kicad_mod.append(Text(type='reference', text='REF**', at=[0,-3], layer='F.SilkS'))
|
||||||
kicad_mod.append(Text(type='value', text=foot_name, at=[1.5,3], layer='F.Fab'))
|
kicad_mod.append(Text(type='value', text=foot_name, at=[1.5,3], layer='F.Fab'))
|
||||||
|
|
||||||
# create silscreen
|
|
||||||
kicad_mod.append(RectLine(start=[-brd_width/2,-brd_height/2], end=[brd_width/2,brd_height/2], layer='F.SilkS', width=0.15))
|
|
||||||
|
|
||||||
# create courtyard
|
# create courtyard
|
||||||
kicad_mod.append(RectLine(start=[-brd_width/2,-brd_height/2], end=[brd_width/2,brd_height/2], layer='F.CrtYd', width=0.05, offset=0.5))
|
# for [foot, pad_map] in sorted_foots:
|
||||||
|
|
||||||
|
# kicad_mod.append(RectLine(start=[-brd_width/2,-brd_height/2], end=[brd_width/2,brd_height/2], layer='F.CrtYd', width=0.05, offset=0.5))
|
||||||
|
|
||||||
# create pads
|
# create pads
|
||||||
print(sorted_foots)
|
print(sorted_foots)
|
||||||
|
keepouts = []
|
||||||
pad_cnt = 0
|
pad_cnt = 0
|
||||||
for [foot, pad_map] in sorted_foots:
|
for [foot, pad_map] in sorted_foots:
|
||||||
|
local_box = foot.GetBoundingBox(False,False)
|
||||||
|
local_cent = ToMM(local_box.GetCenter() - brd_cent)
|
||||||
|
local_size = ToMM(local_box.GetSize())
|
||||||
|
print("Bounding: ", local_cent, local_size)
|
||||||
|
keepouts.append([local_cent, local_size])
|
||||||
mounting_flag = "mounting" in str(foot.GetKeywords()).lower()
|
mounting_flag = "mounting" in str(foot.GetKeywords()).lower()
|
||||||
custom_paste_flag = False
|
custom_paste_flag = False
|
||||||
if mounting_flag:
|
if mounting_flag:
|
||||||
for pad in foot.Pads():
|
for pad in foot.Pads():
|
||||||
if pad.IsAperturePad():
|
if pad.IsAperturePad():
|
||||||
custom_paste_flag = True
|
custom_paste_flag = True
|
||||||
|
# size = foot.GetBoundingBox(False,False).GetSize()
|
||||||
|
# cent = foot.GetCenter() - brd_cent
|
||||||
|
# x_flag = abs(cent.x) - brd_width/2 > -size.x/2
|
||||||
|
# y_flag = abs(cent.y) - brd_height/2 > -size.y/2
|
||||||
|
# if x_flag or y_flag:
|
||||||
|
# shape_type = foot.GetEffectiveShape()
|
||||||
|
# cent_mm = ToMM(cent)
|
||||||
|
# size_mm = ToMM(size)
|
||||||
|
# start_x = brd_width/2
|
||||||
|
# start_y = brd_height/2
|
||||||
|
# if cent.x < 0:
|
||||||
|
# start_x = -1*start_x
|
||||||
|
# if cent.y < 0:
|
||||||
|
# start_y = -1*start_y
|
||||||
|
# if not x_flag:
|
||||||
|
# start_x = cent_mm[0]
|
||||||
|
# if not y_flag:
|
||||||
|
# start_y = cent_mm[1]
|
||||||
|
# print("Silk: ", cent_mm, size_mm)
|
||||||
|
# if shape_type == pcbnew.SHAPE_T_RECT:
|
||||||
|
# start = [start_x, start_y + size_mm[1]/2]
|
||||||
|
# end = [start[0] + size_mm[0]/2, start[1]]
|
||||||
|
# kicad_mod.append(Line(start=start, end=end, layer='F.Silkscreen', width=0.05))
|
||||||
|
# start = [end[0], end[1]]
|
||||||
|
# end = [start[0], start[1] - size[1]]
|
||||||
|
# kicad_mod.append(Line(start=start, end=end, layer='F.Silkscreen', width=0.05))
|
||||||
|
# start = [end[0], end[1]]
|
||||||
|
# end = [start[0] - size[0]/2, start[1]]
|
||||||
|
# kicad_mod.append(Line(start=start, end=end, layer='F.Silkscreen', width=0.05))
|
||||||
|
# start = [cent_mm[0] - size_mm[0], cent_mm[1] - size_mm[1]]
|
||||||
|
# end = [cent_mm[0] + size_mm[0], cent_mm[1] + size_mm[1]]
|
||||||
|
# kicad_mod.append(RectLine(start=start, end=end, layer='F.Silkscreen', width=0.05, offset=0.2))
|
||||||
|
# elif shape_type == pcbnew.SHAPE_T_CIRCLE:
|
||||||
|
# start = [cent_mm[0], cent_mm[1] + size_mm[1]/2]
|
||||||
|
# end = [start[0], start[1]]
|
||||||
|
# radius = size.x/2
|
||||||
|
# kicad_mod.append(Arc(center=cent, start=radius, layer='F.Silkscreen', width=0.05))
|
||||||
|
# radius = size_mm[0]/2 + 0.2
|
||||||
|
# kicad_mod.append(Circle(center=cent_mm, radius=radius, layer='F.Silkscreen', width=0.05))
|
||||||
|
|
||||||
|
for d in foot.GraphicalItems():
|
||||||
|
if type(d) is pcbnew.FP_SHAPE and "F.Courtyard" in d.GetLayerName():
|
||||||
|
shape_type = d.GetShape()
|
||||||
|
cent = d.GetCenter() - brd_cent
|
||||||
|
print("Courtyard: ", cent, shape_type)
|
||||||
|
if shape_type == pcbnew.SHAPE_T_SEGMENT:
|
||||||
|
start = d.GetStart() - brd_cent
|
||||||
|
end = d.GetEnd() - brd_cent
|
||||||
|
print("Seg: ", ToMM(start), ToMM(end))
|
||||||
|
kicad_mod.append(Line(start=ToMM(start), end=ToMM(end), layer='F.CrtYd', width=0.05))
|
||||||
|
elif shape_type == pcbnew.SHAPE_T_RECT:
|
||||||
|
start = d.GetStart() - brd_cent
|
||||||
|
end = d.GetEnd() - brd_cent
|
||||||
|
print("Rect: ", ToMM(start), ToMM(end))
|
||||||
|
kicad_mod.append(RectLine(start=ToMM(start), end=ToMM(end), layer='F.CrtYd', width=0.05))
|
||||||
|
elif shape_type == pcbnew.SHAPE_T_CIRCLE:
|
||||||
|
radius = ToMM(d.GetRadius())
|
||||||
|
cent = ToMM(cent)
|
||||||
|
print("Circ: ", cent, radius)
|
||||||
|
kicad_mod.append(Circle(center=cent, radius=radius, layer='F.CrtYd', width=0.05))
|
||||||
|
|
||||||
|
|
||||||
real_pads = 0
|
real_pads = 0
|
||||||
for pad in foot.Pads():
|
for pad in foot.Pads():
|
||||||
@@ -278,6 +349,59 @@ for [foot, pad_map] in sorted_foots:
|
|||||||
pad_cnt += real_pads
|
pad_cnt += real_pads
|
||||||
|
|
||||||
|
|
||||||
|
# create silkscreen
|
||||||
|
print("keepouts: ", keepouts)
|
||||||
|
corners = [[-brd_width/2, -brd_height/2], [-brd_width/2, brd_height/2], [brd_width/2, brd_height/2], [brd_width/2, -brd_height/2]]
|
||||||
|
for i in range(len(corners)):
|
||||||
|
if i == len(corners)-1:
|
||||||
|
j = 0
|
||||||
|
else:
|
||||||
|
j = i+1
|
||||||
|
start = deepcopy(corners[i])
|
||||||
|
end = deepcopy(start)
|
||||||
|
x_dir = True
|
||||||
|
if corners[i][0] == corners[j][0]:
|
||||||
|
x_dir = False
|
||||||
|
sign = -1
|
||||||
|
if corners[j][not x_dir] > corners[i][not x_dir]:
|
||||||
|
sign = 1
|
||||||
|
# Find intersections with keepouts
|
||||||
|
intersects = []
|
||||||
|
if x_dir:
|
||||||
|
for k in keepouts:
|
||||||
|
if abs(start[1] - k[0][1]) < k[1][1]/2:
|
||||||
|
intersects.append(k)
|
||||||
|
intersects.sort(key=lambda k: abs(start[0] - k[0][0]))
|
||||||
|
else:
|
||||||
|
for k in keepouts:
|
||||||
|
if abs(start[0] - k[0][0]) < k[1][0]/2:
|
||||||
|
intersects.append(k)
|
||||||
|
intersects.sort(key=lambda k: abs(start[1] - k[0][1]))
|
||||||
|
|
||||||
|
|
||||||
|
print("Start: ", start)
|
||||||
|
print("end: ", corners[j])
|
||||||
|
print("Flag: ", x_dir)
|
||||||
|
print("intersects: ", intersects)
|
||||||
|
for intersect in intersects:
|
||||||
|
if x_dir:
|
||||||
|
end[0] = intersect[0][0] - sign * intersect[1][0]/2
|
||||||
|
else:
|
||||||
|
end[1] = intersect[0][1] - sign * intersect[1][1]/2
|
||||||
|
|
||||||
|
print("Silk: ", start, end)
|
||||||
|
kicad_mod.append(Line(start=start, end=end, layer='F.SilkS', width=0.1))
|
||||||
|
if x_dir:
|
||||||
|
start[0] = intersect[0][0] + sign * intersect[1][0]/2
|
||||||
|
else:
|
||||||
|
start[1] = intersect[0][1] + sign * intersect[1][1]/2
|
||||||
|
|
||||||
|
kicad_mod.append(Line(start=start, end=corners[j], layer='F.SilkS', width=0.1))
|
||||||
|
|
||||||
|
|
||||||
|
# kicad_mod.append(RectLine(start=[-brd_width/2,-brd_height/2], end=[brd_width/2,brd_height/2], layer='F.SilkS', width=0.15))
|
||||||
|
|
||||||
|
|
||||||
final_model_path = "${KIPRJMOD}/../libs/melon3d/" + foot_path + ".3dshapes/" + foot_name + ".step"
|
final_model_path = "${KIPRJMOD}/../libs/melon3d/" + foot_path + ".3dshapes/" + foot_name + ".step"
|
||||||
kicad_mod.append(Model(filename=final_model_path
|
kicad_mod.append(Model(filename=final_model_path
|
||||||
,at=[0,0,-1.6]
|
,at=[0,0,-1.6]
|
||||||
|
|||||||
Reference in New Issue
Block a user