Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate centroid based on footprint type #117

Merged
merged 1 commit into from
Feb 21, 2024
Merged

Calculate centroid based on footprint type #117

merged 1 commit into from
Feb 21, 2024

Conversation

dzid26
Copy link
Contributor

@dzid26 dzid26 commented Feb 15, 2024

Rationale

This helps with positioning of thruhole and unspecified component footprint types.
image

Description

Unlike the smd type, thru hole components in kicad library have their anchor on pin 1. This is an issue because it always requires adding position offset to thru hole components before exporting position file. This update uses bounding box center instead of the default anchor to solve this.

Additionally, I compute bounding box center based on copper pads for unspecified footprint types.

It could be done that way for all type of footprints, as I did in this PR Bouni/kicad-jlcpcb-tools#381 but there they were using bounding box center anyways so the change was less drastic. Here we may still want to use kicad anchor for smt for some compatibility reasons.

I decided to use bounding box center based on copper pads for unspecified footprint types, because I know this type of computation is needed for footprints in projects imported from Altium (which by default are set as unspecified and always have an anchor on pin 1 regardless being SMT or thruhole).

Testing

I tested the change on kicad 7 and 8.

Here is an example of the thru-hole components test.zip from #101:
Before:
image
After:
image

Also, as mentioned, I use this change on a project that uses a lot of unspecified footprints imported from Altium and also few SMT components from kicad library.

Compatibility

The most affected projects will be those that used thru-hole components before the change. When regenerating position files with this update, they will most likely have to remove position offset.

Copy link
Owner

@bennymeg bennymeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks great.

@bennymeg bennymeg merged commit 6729b56 into bennymeg:master Feb 21, 2024
@dzid26 dzid26 deleted the centroid branch February 21, 2024 10:25
@bleroy
Copy link

bleroy commented Apr 16, 2024

Hi. Just a comment on this change, which was breaking for me.
I had built my footprints setting the footprint anchor where I wanted the component placed. This change moves what was deliberately designed by me to some point at the center of all pads in the component, over which I have no control other than manually adding a hard to compute offset to each component. I have no control over the bounding box as far as I can tell.
Looks like a great change for some components, not so great when you need to be specific about the origin.
Really loving the plugin in general otherwise.

@dzid26
Copy link
Contributor Author

dzid26 commented Apr 17, 2024

I had built my footprints setting the footprint anchor where I wanted the component placed.

Please explain how moving the anchor is easier than using offset feature. (I agree that calculating offset based on JLC render is not easy for some reason).
Moving the anchor has a disadvantage that it also moves the footprint in Kicad pcb design. (Unless they changed it in Kicad 8).

Btw, the anchor is still used for SMD type components - this is because they were usually not a problem (the anchor is usually in the center anyway).

@bleroy
Copy link

bleroy commented Apr 17, 2024

Moving the anchor is literally two clicks. To use offset, I have to figure out the coordinates of the center of all existing pads, then edit symbol fields and add the opposite offset to every occurrence of that component.
Let's take as an example a 1U MX switch with a LED footprint. There are two through-hole pads, two SMD pads for the LED and three drills:
image
With the current version, the center of all pads is an entirely meaningless point somewhere near (but not at) the middle of the central drill, because of how asymmetrical switches are.
With the previous version, I had set the center to where it most makes sense for fabrication: in the center of the SMD pads, which is where JLC will assemble the LED.
I set the anchor when I created the footprint, before I design the PCB. Having to design around the anchor is no problem, I usually move the grid origin while I'm working on those components to take it into account.
So I have tried yesterday to change the footprints to be marked as SMD, because I thought that would help, but it didn't. Maybe I forgot to do something to have it acknowledged but I don't think I did: I changed the footprint type, updated the footprints and regenerated the fabrication files, and the switch LEDs were still offset.
My current workaround is that I edited the two lines in the plugin code locally to restore the old formula. That works for the moment, but I'll have to re-patch every time I get an updated plugin...
Thanks for looking into this, much appreciated, and again, the plugin is such a great time saver!

@dzid26
Copy link
Contributor Author

dzid26 commented Apr 17, 2024

@bleroy I am going make some assumptions, so excuse me if I am mistaken. It seems that you or someone created a footprint that contains two parts - smd LED and PTH MX switch.
If you split them in two separate components you wouldn't have the issue. (although your schematic would need to be probably changed too). If you wanted JLC to hand-solder the switch and the LED, you would need to split those two footprints anyway.

Another solution, as I mentioned previously, is to change this footprint type to the SMD image then the anchor should be used. This is probably preferred for you.

Typically, for more complex footprints (horizontal USB-C ports, etc) it is not clear where the fabrication center should be placed so it requires a back and forth with JLC render to either place the anchor or add offset in BOM.

@bleroy
Copy link

bleroy commented Apr 17, 2024

Splitting the footprint would be a huge hassle, as I would have to position two components where I have one today, and I move these around a lot when working on a keyboard layout. I can try to change it into a SMD footprint again, but as I said in my previous message that didn't work when I tried it. Ideally we'd have a setting to specify what position mode to use, between anchor and pad center...

@grodnay
Copy link
Contributor

grodnay commented Dec 3, 2024

I am quite sure JLCPB expects center of pads and not center of footprint bounding box for thourgh-hole-it doesnot work right with bounding box. So we can make it center of pads for anything which is not SMD. (pads center does not always work right for SMD, so it is better the way it is now)
Also, I can add a footprint field, or a plugin option, "use foorprint anchor". When importing footprint from easy-eda, you get the anchor using "impartGUI" plugin, as I always do, you get the anchor in the correct position for JLCPCB placment. what do you think?

@dzid26
Copy link
Contributor Author

dzid26 commented Dec 3, 2024

If "use foorprint anchor" is a global setting, then Kicad library THT components (with anchor on pin 1) wouldn’t work good. But it still could be beneficial for 3rd party libraries. :)

@bleroy
Copy link

bleroy commented Dec 3, 2024

A "use footprint anchor" footprint field would work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants