michaelgale / pcbflow

Python based Printed Circuit Board (PCB) layout and design package based on CuFlow.
BSD 3-Clause "New" or "Revised" License
121 stars 15 forks source link

Spacing issue with PinSocket and PinHeader holes #10

Open ghost opened 5 months ago

ghost commented 5 months ago

There's a strange issue when rendering pin holes for PinHeader and PinSocket footprints. (standard arduino headers)

esp32_motor-pcb-x3_final-pcbflow_preview_all

It seems to add an additional, invisible hole every time a hole is drilled onto the board.

So rather than going 1, 2, 3, 4 -- it'll go 1, 3, 5, etc.

Must be some kind of maths problem. Here's where the bug manifests within the footprint, I just need to be able to locate the exact logic in the code:

  (pad 1 thru_hole rect (at 0 0) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask))
  (pad 2 thru_hole oval (at 0 2.54) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask))
  (pad 3 thru_hole oval (at 0 5.08) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask))
  (pad 4 thru_hole oval (at 0 7.62) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask))
  (pad 5 thru_hole oval (at 0 10.16) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask))
  (pad 6 thru_hole oval (at 0 12.7) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask))
  (pad 7 thru_hole oval (at 0 15.24) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask))
  (pad 8 thru_hole oval (at 0 17.78) (size 1.7 1.7) (drill 1) (layers *.Cu *.Mask))

It gets the spacing right for the first two pads, but as soon as it loops through repeated hole shapes - it becomes an exponential pattern.

ghost commented 5 months ago

Fixed with the following code:

        for pad in self.pin_pads:
            diameter = pad["size"][0]
            dc.push()
            dc.goxy(*pad["xy"])
            dc.board.add_drill(dc.xy, pad["drill"])
            shape = pad["shape"]
            if shape in ["long", "circle", "octagon", "rect", "oval"]:
                n = {"long": 60, "circle": 60, "octagon": 8, "rect": 4, "oval": 60}[shape]
                if shape in ["rect", "oval"]:
                    diameter /= 1.1
                p = dc.copy()
                p.n_agon(diameter / 2, n)
                p.set_name(pad["name"])
                p.part = self.id
                self.pads.append(p)
                p.pin_pad()
                dc.pop()

I have forked a copy of pcbflow to include the fixes on my own account, since I will probably be fixing a lot of bugs, and maybe adding new features. cheers

esp32_motor-pcb-x3_final-pcbflow_preview_all

michaelgale commented 5 months ago

@khanumballz Great job! Thanks for the fix! I'd be happy to fold them into the main repo with a PR whenever you're ready.