TousstNicolas / JLC2KiCad_lib

JLC2KICAD_lib is a python script that generate a component library (schematic, footprint and 3D model ) for KiCad from the JLCPCB/easyEDA library.
MIT License
228 stars 42 forks source link

Proper Arc support for schematic and footprint #33

Closed TousstNicolas closed 1 year ago

TousstNicolas commented 1 year ago

The arcs for the schematic and footprint are rarely properly placed. It needs to be correctly handled.

I pushed some work on the Fix_ARC branch, but I cannot figure out how to draw them, there are always components for which it does not work.

For now, I tried to use the GetCenterParam function, which is reversed from https://easyeda.com/editor/6.5.5/js/editorPCB.min.js This function seems to return the coordinates of the center (or possibly the midpoint in some occasions ? ), and two angles, but when using theses to calculate the start point, end point and center, the result is inconsistent, sometimes it works, sometimes it doesn't.

The schematic equivalent is more consistent and seems to have less issues.

The following components have an arc in their footprint and could be used to test: C55684 C185659 C86002 C312983 C1341701 C307522 C689358 C403695 C602208 C152951 C688068 C163798 C661330

This concern the h_ARC function in the footprint : https://github.com/TousstNicolas/JLC2KiCad_lib/blob/b5c38c2beff6f710eb8ac427622384717539ce84/JLC2KiCadLib/footprint/footprint_handlers.py#L174-L278

Xyntexx commented 1 year ago

I made my version of the code and it seems to be working pretty well so far: https://github.com/Xyntexx/JLC2KiCad_lib/tree/my_ARC_Fixes

TousstNicolas commented 1 year ago

Seems to be working flawlessly. Good job.

However, I think it might not be required to redefined the wheel by creating a new vector2D class. Most methods are already available with the vector2D class from KicadModTree :

from that, rewritten the concern part without the need to create a new class :

        # find the midpoint of start and end
        mid = [(start[0] + end[0]) / 2, (start[1] + end[1]) / 2]
        # create vector from start to mid:
        vec1 = Vector2D(mid[0] - start[0], mid[1] - start[1])
        # create vector that's normal to vec1:

        length_squared = pow(midX, 2) - pow(vec1.distance_to((0,0)), 2)
        if length_squared < 0:
            length_squared = 0
            reversed = "1"

        if reversed == "1":
            vec2 = vec1.rotate(-90)
            magnitude = sqrt(vec2[0]**2 + vec2[1]**2)
            vec2 = Vector2D(vec2[0]/magnitude, vec2[1]/magnitude)
        else:
            vec2 = vec1.rotate(90)
            magnitude = sqrt(vec2[0]**2 + vec2[1]**2)
            vec2 = Vector2D(vec2[0]/magnitude, vec2[1]/magnitude)

        # calculate the lenght from mid to centre using pythagoras:
        length = sqrt(length_squared)
        # calculate the centre using mid and vec2 with the correct length:
        cen = Vector2D(mid) + vec2 * length

        cen_start = cen - start
        cen_end = cen - end

        # calculate angle between cen_start and cen_end
        dot_product = cen_start.x*cen_end.x + cen_start.y*cen_end.y
        angle = acos(dot_product / (cen_start.distance_to((0,0)) * cen_end.distance_to((0,0))))

Can you create a PR with just the commit you made for this issue ? It will help to keep track of the different issues and their according corrections.

TousstNicolas commented 1 year ago

Thanks a lot for your work, merged in 12c6860aecd43dd8b4262347f74a3bb06de85959