From c2fd462dd6318676dbc9a7babb90810c1d701ce9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 18 Feb 2016 18:53:39 +0100 Subject: [PATCH] Footprint generators in Python: add a rounding method to put a coordinate on a grid (PutOnGridMM and PutOnGridMils) . --- .../plugins/HelpfulFootprintWizardPlugin.py | 18 ++++++++++++++++++ pcbnew/scripting/plugins/bga_wizard.py | 3 +++ pcbnew/scripting/plugins/qfp_wizard.py | 3 +++ pcbnew/scripting/plugins/sdip_wizard.py | 3 +++ pcbnew/scripting/plugins/zip_wizard.py | 5 ++++- 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pcbnew/scripting/plugins/HelpfulFootprintWizardPlugin.py b/pcbnew/scripting/plugins/HelpfulFootprintWizardPlugin.py index 6c4c54e125..a74206780e 100644 --- a/pcbnew/scripting/plugins/HelpfulFootprintWizardPlugin.py +++ b/pcbnew/scripting/plugins/HelpfulFootprintWizardPlugin.py @@ -279,6 +279,24 @@ class HelpfulFootprintWizardPlugin(pcbnew.FootprintWizardPlugin, """ 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): """ Draw the footprint. diff --git a/pcbnew/scripting/plugins/bga_wizard.py b/pcbnew/scripting/plugins/bga_wizard.py index cc93984725..8ce17e6a6b 100644 --- a/pcbnew/scripting/plugins/bga_wizard.py +++ b/pcbnew/scripting/plugins/bga_wizard.py @@ -86,6 +86,9 @@ class BGAWizard(HFPW.HelpfulFootprintWizardPlugin): self.draw.SetLayer(pcbnew.F_CrtYd) sizex = (ssx + 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 self.draw.SetLineThickness(pcbnew.FromMM(0.05)) self.draw.Box(0, 0, sizex, sizey) diff --git a/pcbnew/scripting/plugins/qfp_wizard.py b/pcbnew/scripting/plugins/qfp_wizard.py index ec35ea47c8..04664aa5f4 100644 --- a/pcbnew/scripting/plugins/qfp_wizard.py +++ b/pcbnew/scripting/plugins/qfp_wizard.py @@ -113,6 +113,9 @@ class QFPWizard(HelpfulFootprintWizardPlugin.HelpfulFootprintWizardPlugin): self.draw.SetLayer(pcbnew.F_CrtYd) sizex = (lim_x + 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 thick = self.draw.GetLineThickness() self.draw.SetLineThickness(pcbnew.FromMM(0.05)) diff --git a/pcbnew/scripting/plugins/sdip_wizard.py b/pcbnew/scripting/plugins/sdip_wizard.py index 2cf9d1591b..fad99f1dbe 100644 --- a/pcbnew/scripting/plugins/sdip_wizard.py +++ b/pcbnew/scripting/plugins/sdip_wizard.py @@ -109,6 +109,9 @@ class RowedFootprint(HFPW.HelpfulFootprintWizardPlugin): self.draw.SetLayer(pcbnew.F_CrtYd) sizex = (ssx + 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 self.draw.SetLineThickness(pcbnew.FromMM(0.05)) self.draw.Box(0, 0, sizex, sizey) diff --git a/pcbnew/scripting/plugins/zip_wizard.py b/pcbnew/scripting/plugins/zip_wizard.py index 338728145f..4ffa7f1523 100644 --- a/pcbnew/scripting/plugins/zip_wizard.py +++ b/pcbnew/scripting/plugins/zip_wizard.py @@ -102,10 +102,13 @@ class RowedFootprint(HFPW.HelpfulFootprintWizardPlugin): cmarginx = body[self.courtyard_x_margin_key] cmarginy = body[self.courtyard_y_margin_key] self.draw.SetLayer(pcbnew.F_CrtYd) - # set courtyard line thickness to the one defined in KLC thick = self.draw.GetLineThickness() sizex = (pin1posX + cmarginx) * 2 + pad_Hsize + 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.Box(0, 0, sizex, sizey) # restore line thickness to previous value