Hi Jean-Pierre, Here is a new patch with two methods respectively called PutOnGridMM and PutOnGridMils.
Regards, Mikael On Thu, Feb 18, 2016 at 6:36 AM, jp charras <jp.char...@wanadoo.fr> wrote: > Le 16/02/2016 19:33, Mikael Arguedas a écrit : > > Hi guys, > > > > Here is the rounding function patch > > > > Cheers, > > Mikael > > > > OK. > > I noticed the rounding grid parameter is only in mm. > It could be worth having the possibility to use inches and mils, or > using a name like PutOnGridMM instead of just PutOnGrid, to avoid mistakes. > > Thanks. > > -- > Jean-Pierre CHARRAS >
=== modified file 'pcbnew/scripting/plugins/HelpfulFootprintWizardPlugin.py' --- pcbnew/scripting/plugins/HelpfulFootprintWizardPlugin.py 2016-02-14 09:47:07 +0000 +++ pcbnew/scripting/plugins/HelpfulFootprintWizardPlugin.py 2016-02-18 17:20:15 +0000 @@ -279,6 +279,24 @@ """ 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. === modified file 'pcbnew/scripting/plugins/bga_wizard.py' --- pcbnew/scripting/plugins/bga_wizard.py 2016-02-18 14:29:30 +0000 +++ pcbnew/scripting/plugins/bga_wizard.py 2016-02-18 17:20:32 +0000 @@ -86,6 +86,9 @@ 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) === modified file 'pcbnew/scripting/plugins/qfp_wizard.py' --- pcbnew/scripting/plugins/qfp_wizard.py 2016-02-18 14:29:30 +0000 +++ pcbnew/scripting/plugins/qfp_wizard.py 2016-02-18 17:21:31 +0000 @@ -113,6 +113,9 @@ 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)) === modified file 'pcbnew/scripting/plugins/sdip_wizard.py' --- pcbnew/scripting/plugins/sdip_wizard.py 2016-02-18 14:29:30 +0000 +++ pcbnew/scripting/plugins/sdip_wizard.py 2016-02-18 17:22:18 +0000 @@ -109,6 +109,9 @@ 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) === modified file 'pcbnew/scripting/plugins/zip_wizard.py' --- pcbnew/scripting/plugins/zip_wizard.py 2016-02-18 14:29:30 +0000 +++ pcbnew/scripting/plugins/zip_wizard.py 2016-02-18 17:23:40 +0000 @@ -102,10 +102,13 @@ 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
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp