Footprint generators in Python: add a rounding method to put a coordinate on a grid (PutOnGridMM and PutOnGridMils) .
This commit is contained in:
parent
fb17b3fa17
commit
c2fd462dd6
|
@ -279,6 +279,24 @@ class HelpfulFootprintWizardPlugin(pcbnew.FootprintWizardPlugin,
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def PutOnGridMM(self, value, gridSizeMM=0.05):
|
||||||
|
"""
|
||||||
|
Round the value (in KiCAD internal units 1nm) according to the
|
||||||
|
provided gridSize in mm.
|
||||||
|
"""
|
||||||
|
thresh = pcbnew.FromMM(gridSizeMM)
|
||||||
|
res = round(value/thresh)*thresh
|
||||||
|
return res
|
||||||
|
|
||||||
|
def PutOnGridMils(self, value, gridSizeMil=2):
|
||||||
|
"""
|
||||||
|
Round the value (in KiCAD internal units 1nm) according to the
|
||||||
|
provided gridSize in mil.
|
||||||
|
"""
|
||||||
|
thresh = pcbnew.FromMils(gridSizeMil)
|
||||||
|
res = round(value/thresh)*thresh
|
||||||
|
return res
|
||||||
|
|
||||||
def BuildThisFootprint(self):
|
def BuildThisFootprint(self):
|
||||||
"""
|
"""
|
||||||
Draw the footprint.
|
Draw the footprint.
|
||||||
|
|
|
@ -86,6 +86,9 @@ class BGAWizard(HFPW.HelpfulFootprintWizardPlugin):
|
||||||
self.draw.SetLayer(pcbnew.F_CrtYd)
|
self.draw.SetLayer(pcbnew.F_CrtYd)
|
||||||
sizex = (ssx + cmargin) * 2
|
sizex = (ssx + cmargin) * 2
|
||||||
sizey = (ssy + cmargin) * 2
|
sizey = (ssy + cmargin) * 2
|
||||||
|
# round size to nearest 0.1mm, rectangle will thus land on a 0.05mm grid
|
||||||
|
sizex = self.PutOnGridMM(sizex, 0.1)
|
||||||
|
sizey = self.PutOnGridMM(sizey, 0.1)
|
||||||
# set courtyard line thickness to the one defined in KLC
|
# set courtyard line thickness to the one defined in KLC
|
||||||
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
|
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
|
||||||
self.draw.Box(0, 0, sizex, sizey)
|
self.draw.Box(0, 0, sizex, sizey)
|
||||||
|
|
|
@ -113,6 +113,9 @@ class QFPWizard(HelpfulFootprintWizardPlugin.HelpfulFootprintWizardPlugin):
|
||||||
self.draw.SetLayer(pcbnew.F_CrtYd)
|
self.draw.SetLayer(pcbnew.F_CrtYd)
|
||||||
sizex = (lim_x + cmargin) * 2 + pad_length
|
sizex = (lim_x + cmargin) * 2 + pad_length
|
||||||
sizey = (lim_y + cmargin) * 2 + pad_length
|
sizey = (lim_y + cmargin) * 2 + pad_length
|
||||||
|
# round size to nearest 0.1mm, rectangle will thus land on a 0.05mm grid
|
||||||
|
sizex = self.PutOnGridMM(sizex, 0.1)
|
||||||
|
sizey = self.PutOnGridMM(sizey, 0.1)
|
||||||
# set courtyard line thickness to the one defined in KLC
|
# set courtyard line thickness to the one defined in KLC
|
||||||
thick = self.draw.GetLineThickness()
|
thick = self.draw.GetLineThickness()
|
||||||
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
|
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
|
||||||
|
|
|
@ -109,6 +109,9 @@ class RowedFootprint(HFPW.HelpfulFootprintWizardPlugin):
|
||||||
self.draw.SetLayer(pcbnew.F_CrtYd)
|
self.draw.SetLayer(pcbnew.F_CrtYd)
|
||||||
sizex = (ssx + cmargin) * 2
|
sizex = (ssx + cmargin) * 2
|
||||||
sizey = (ssy + cmargin) * 2
|
sizey = (ssy + cmargin) * 2
|
||||||
|
# round size to nearest 0.1mm, rectangle will thus land on a 0.05mm grid
|
||||||
|
sizex = self.PutOnGridMM(sizex, 0.1)
|
||||||
|
sizey = self.PutOnGridMM(sizey, 0.1)
|
||||||
# set courtyard line thickness to the one defined in KLC
|
# set courtyard line thickness to the one defined in KLC
|
||||||
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
|
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
|
||||||
self.draw.Box(0, 0, sizex, sizey)
|
self.draw.Box(0, 0, sizex, sizey)
|
||||||
|
|
|
@ -102,10 +102,13 @@ class RowedFootprint(HFPW.HelpfulFootprintWizardPlugin):
|
||||||
cmarginx = body[self.courtyard_x_margin_key]
|
cmarginx = body[self.courtyard_x_margin_key]
|
||||||
cmarginy = body[self.courtyard_y_margin_key]
|
cmarginy = body[self.courtyard_y_margin_key]
|
||||||
self.draw.SetLayer(pcbnew.F_CrtYd)
|
self.draw.SetLayer(pcbnew.F_CrtYd)
|
||||||
# set courtyard line thickness to the one defined in KLC
|
|
||||||
thick = self.draw.GetLineThickness()
|
thick = self.draw.GetLineThickness()
|
||||||
sizex = (pin1posX + cmarginx) * 2 + pad_Hsize + thick
|
sizex = (pin1posX + cmarginx) * 2 + pad_Hsize + thick
|
||||||
sizey = (pin1posY + cmarginy) * 2 + pad_Vsize + thick
|
sizey = (pin1posY + cmarginy) * 2 + pad_Vsize + thick
|
||||||
|
# round size to nearest 0.1mm, rectangle will thus land on a 0.05mm grid
|
||||||
|
sizex = self.PutOnGridMM(sizex, 0.1)
|
||||||
|
sizey = self.PutOnGridMM(sizey, 0.1)
|
||||||
|
# set courtyard line thickness to the one defined in KLC
|
||||||
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
|
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
|
||||||
self.draw.Box(0, 0, sizex, sizey)
|
self.draw.Box(0, 0, sizex, sizey)
|
||||||
# restore line thickness to previous value
|
# restore line thickness to previous value
|
||||||
|
|
Loading…
Reference in New Issue