Extract footprint-center from F.Fab outline #260
Conversation
Some footprints have weird pad shapes, making the F6.2 test fail. To fix this, we can also calculate the center of the F.Fab layer. Of those two possible center-locations, the one closer to (0,0) is selected. If Pads-center and F.Fab-center differ a warning is displayed.
I'd just like to pop in to point out that barring some miracle (like all manufacturers providing drawings in a standardized machine-readable format), there is no comprehensive fix. This is because a drawing can specify any pick-and-place origin, which need not be the center of any features of the footprint. The best we can hope for is an improved heuristic, resulting in fewer false negatives. So in short, if this is better, of course it should be accepted. I haven't taken a look at the patch though, so take everything I wrote above as a general statement, not as a recommendation to merge. |
Hello, It does not apply to non SMD-Footprints, see Line24. I have not touched that :) But you are right, this is not a comprehensive fix. There are still valid footprints which will fail. But less will fail with that changeset. Example: the mentioned HDMI-Footprint the check will not fail, but display a warning.
|
This has been idle quite some time. |
pcb/rules/F6_2.py
Outdated
diff_pads = sqrt(center_pads['x']**2 + center_pads['y']**2) | ||
diff_fab = sqrt(center_fab['x']**2 + center_fab['y']**2) | ||
x = (center_pads['x'], center_fab['x'])[diff_pads > diff_fab] | ||
y = (center_pads['y'], center_fab['y'])[diff_pads > diff_fab] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the rationale behind this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 43 & 44 do calculate the euclidic distance of the pads & fab centers to the origin.
Then the one closes to the origin is selected. (45-46)
That the acutal idea of the patch. Look at the center of the F.Fab lines the one calculated from the Pads.
- If they are not the same, display a warning (line 31-37)
- If they are not the same, select the one that is closer to the footprint origin (line 43-36)
- Then check if the one selected above is to far from the origin (lines 48-52)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a stylistic point: Python has a conditional operator true_value if condition else false_value
that would be better to use than subscripting a tuple on lines 45-46. But since there are two lines with the same condition, using a normal if
block could be considered as the more DRY option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh. I don't know why I have written it this way. After the question from poeschlr I had to look twice myself. This is a good indication that the code-quality is shitty.
A simple if-statement is way more readable. Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the long delay, this repo is often forgotten
pcb/rules/F6_2.py
Outdated
center_fab = module.geometricBoundingBox("F.Fab").center | ||
|
||
if center_pads['x'] != center_fab['x'] or center_pads['y'] != center_fab['y']: | ||
self.warning("Footprint centers of pads and F.Fab do not match") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not call this a warning. A lot of footprints would result in this and it would just confuse users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving the warning output into the code-path that displays the error (if there is any). Then the user has the additional info on which two origins were checked.
Otherwise it will be a mystery for the user why exactly the check failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well if the check fails then i would assume your script knows why and can generate a clear output (you could for example word it such that it is clear which options you checked). This warning on its own however might be read as "i need to ensure the centers are equal" which is not the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spend some time on better wording, but could not come up with something good.
Actually I don't know why I introduced it in the first place. There is no real use-case for it.
Now one line is shown for each calculated center. This has all the information the user needs. Its also much clearer than the previous version that had all coordinates in one line.
A good testcase is |
The warning "Footprint centers of pads and F.Fab do not match" was not usefull. It could be understood as 'this needs to be fixed'. Also there is no real use-case where this warning actually helps the user. Instead now one line for each check is output which shows the calculated centers. This way easier to read than the previous solution which had all the coordinates in the same line.
pcb/rules/F6_2.py
Outdated
xf = round(center_fab['x'], 5), | ||
yf = round(center_fab['y'], 5))) | ||
if center_pads['x'] != center_fab['x'] or center_pads['y'] != center_fab['y']: | ||
self.errorExtra("Footprint centers of pads and F.Fab do not match") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is still here. It still suggests that the user needs for some reason ensure pads and fab need to be on the same center.
Edit: hm it seems i looked at an outdated diff here.
Thanks looks good now (ignore my last comment made as i seem to have misclicked and looked on an outdated diff) |
Some footprints have weird pad shapes, making the F6.2 test fail.
To fix this, we can also calculate the center of the F.Fab layer. Of those
two possible center-locations, the one closer to (0,0) is
selected.
If Pads-center and F.Fab-center differ a warning is displayed.
This fixes the travis error for this PR KiCad/kicad-footprints#951