bennymeg / Fabrication-Toolkit

An JLC PCB Fabrication Plugin for KiCad
Apache License 2.0
280 stars 49 forks source link

Calculate centroid based on footprint type #117

Closed dzid26 closed 5 months ago

dzid26 commented 5 months ago

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 https://github.com/Bouni/kicad-jlcpcb-tools/pull/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 https://github.com/bennymeg/JLC-Plugin-for-KiCad/issues/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.

bleroy commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

@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 commented 3 months ago

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...