← Back to team overview

kicad-developers team mailing list archive

Re: PATCH: Set SMD attribute in footprint wizard

 

Hi guys,

Here is the rounding function patch

Cheers,
Mikael

On Tue, Feb 16, 2016 at 10:05 AM, Mikael Arguedas <mikael.arguedas@xxxxxxxxx
> wrote:

> I agree with that, most of my small components dont comply with this KLC
> rule and I live very well with it.
>
> I split this patch in two. Here is the part which takes care of setting
> the attributes. I'll submit the rounding function patch later today.
>
> Cheers,
> Mikael
>
> On Tue, Feb 16, 2016 at 10:00 AM, jp charras <jp.charras@xxxxxxxxxx>
> wrote:
>
>> Le 16/02/2016 18:05, Mikael Arguedas a écrit :
>> > What can be done is add a parameter to this ceiling function which
>> default
>> > value would be 0.05 but that people can provide if they want a different
>> > value.
>> >
>> > Regarding the ceiling function itself, I designed it only for the
>> current
>> > use of the python scripts drawing courtyard so I dealt only positive
>> values
>> > but if people can specify coordinates or lines in grid space it makes a
>> lot
>> > of sense to handle negative values.
>> >
>> > Finally, Jean-Pierre by doing a put on grid function, would you like to
>> > have the option to chose between near ceil or floor ? or do you want
>> this
>> > ceiling function to be named "round on grid" to allow us to change the
>> > rounding later without changing the method name ?
>> >
>> > Cheers,
>> > Mikael
>> >
>>
>> I do not have a strong opinion about that.
>> In many cases the best choice is not easy to know, especially for
>> coordinates.
>>
>> So, for me: the simpler the best:
>> round on grid to near (usual rounding) is the simpler.
>> And if the rounding error can create issues for small components, it
>> means the grid is too large.
>>
>> Therefore round on grid to nearest with a grid size as parameter could
>> be the best.
>>
>> (For very small footprints why to round coordinates or sizes ? This is
>> not useful)
>>
>> --
>> 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-16 18:27:03 +0000
@@ -279,6 +279,15 @@
         """
         pass
 
+    def PutOnGrid(self, value, threshold=0.05):
+        """
+        Round the value (in KiCAD internal units 1nm) according to the 
+        provided threshold.
+        """
+        thresh = pcbnew.FromMM(threshold)
+        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-11 15:02:37 +0000
+++ pcbnew/scripting/plugins/bga_wizard.py	2016-02-16 18:26:20 +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.PutOnGrid(sizex, 0.1)
+        sizey = self.PutOnGrid(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-11 15:02:37 +0000
+++ pcbnew/scripting/plugins/qfp_wizard.py	2016-02-16 18:24:47 +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.PutOnGrid(sizex, 0.1)
+        sizey = self.PutOnGrid(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-14 09:47:07 +0000
+++ pcbnew/scripting/plugins/sdip_wizard.py	2016-02-16 18:26:23 +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.PutOnGrid(sizex, 0.1)
+        sizey = self.PutOnGrid(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-11 15:02:37 +0000
+++ pcbnew/scripting/plugins/zip_wizard.py	2016-02-16 18:29:28 +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.PutOnGrid(sizex, 0.1)
+        sizey = self.PutOnGrid(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


Follow ups

References