Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Extract footprint-center from F.Fab outline #260

Merged
merged 5 commits into from Jul 18, 2020
Merged

Extract footprint-center from F.Fab outline #260

merged 5 commits into from Jul 18, 2020

Conversation

ghost
Copy link

@ghost ghost commented Sep 19, 2018

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

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.
@evanshultz
Copy link
Collaborator

This should apply only to SMT footprints, since THT footprints have the origin at pin 1.

I didn't look at the code, but I'm not sure what you described above is the best approach. Consider this footprint:
image

The center of the pads and fab lines need to be considered together. Either one separately wouldn't work. This might be a nice incremental improvement and I'm not against merging it, just saying that it's not a comprehensive fix to consider only pads or only fab lines.

@Ratfink
Copy link
Collaborator

Ratfink commented Sep 19, 2018

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.

@ghost
Copy link
Author

ghost commented Sep 19, 2018

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.

$ ../kicad-library-utils/pcb/check_kicad_mod.py Connector_HDMI.pretty/HDMI_A_Contact_Technology_HDMI-19APL2_Horizontal.kicad_mod -vv
Checking footprint 'HDMI_A_Contact_Technology_HDMI-19APL2_Horizontal':
  Violating F6.2
    For surface-mount devices, footprint anchor is placed in the middle of the footprint (IPC-7351).
    Footprint centers of pads and F.Fab do not match
     - Footprint center calculated as Pad: (0.0,0.0)mm F.Fab: (0.0, 6.55)mm

@ghost
Copy link
Author

ghost commented Feb 7, 2019

This has been idle quite some time.
Does anybody want to review/merge it?
I still consider this a small but usefull addition.

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]
Copy link
Collaborator

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?

Copy link
Author

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)

Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Collaborator

@poeschlr poeschlr left a 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

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")
Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Collaborator

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.

Copy link
Author

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.

New look:
grafik

@poeschlr poeschlr self-assigned this Mar 7, 2020
@ghost
Copy link
Author

ghost commented Mar 12, 2020

A good testcase is LED-L1T2_LUMILEDS in LED_SMD (which should get fixed).

@poeschlr poeschlr added Ready for review Use this to mark pull requests that are updated but you could not review instantly and removed Pending changes labels Apr 26, 2020
Carsten Presser added 2 commits June 16, 2020 11:58
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.
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")
Copy link
Collaborator

@poeschlr poeschlr Jul 18, 2020

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.

@poeschlr
Copy link
Collaborator

Thanks looks good now (ignore my last comment made as i seem to have misclicked and looked on an outdated diff)

@poeschlr poeschlr merged commit 0084a5f into KiCad:master Jul 18, 2020
@antoniovazquezblanco antoniovazquezblanco removed the Ready for review Use this to mark pull requests that are updated but you could not review instantly label Jul 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants