Bouni / kicad-jlcpcb-tools

Plugin to generate BOM + CPL files for JLCPCB, assigning LCSC part numbers directly from the plugin, query the JLCPCB parts database, lookup datasheets and much more.
MIT License
1.21k stars 110 forks source link

Center finding not accurate due to silk screen #379

Open dzid26 opened 1 year ago

dzid26 commented 1 year ago

I wanted this to work, because for my footprint anchors are defined at pin1. Unfortunately, it seems GetBoundingBox takes the silk screen into account. https://github.com/Bouni/kicad-jlcpcb-tools/blob/eca019d8366539c363e5b429c2e8e5bf4560052a/fabrication.py#L118

As a result for a footprint like this with dot on silk:

image

the calculated center is too low.

dzid26 commented 1 year ago

For Kicad 7.99, this seems to work for some reason without even selecting copper layers:

footprint.GetLayerBoundingBox(footprint.GetLayerSet()).GetCenter()

Alternatively combining boundboxes of each pad works with Kicad 7:

                pads: list[pcbnew.PAD] = footprint.Pads()
                bbox : pcbnew.BOX2I = pads[0].GetBoundingBox()
                for pad in pads:
                    bbox.Merge(pad.GetBoundingBox())
                return bbox.GetCenter()
Bouni commented 1 year ago

@dzid26 are you submitting a PR for this?

Is your approach with combining the bounding boxes of all pads working for V7 and V7.99?

dzid26 commented 1 year ago

I can submit the PR.

Bounding box logic will work with 7.0.

Should the same logic be applied to SMD components though? https://github.com/Bouni/kicad-jlcpcb-tools/blob/eca019d8366539c363e5b429c2e8e5bf4560052a/fabrication.py#L116 I tested it on my old board with SMD footprints as well and it works.

  1. On one hand, I can imagine people having footprints with SMD property set and the anchor at pin 1 (like mine), so they would benefit from the bounding box calculation.
  2. On the other hand, moving anchor relative to footprints can be used to offset component placement in relation to the pads. With the bounding box logic, this would not be possible. However, this would become a moot point if we had a translation correction similar to rotations. It doesn't matter to me, because my crappy footprints (imported from Altium) have this property unspecified, so the new logic will apply regardless.
dzid26 commented 1 year ago

In the PR, I prioritized point 1. (I removed if get_smd(footprint)) so that if people have an anchor not in the center, the plugin will help them. Point 2. I assume that eventually will be solved with translations - moving anchor on the footprint is a big pain anyway in kicad.