Skip to content

Commit

Permalink
For JLCPCB, flip orientation (incl. compensation angle) for bottom parts
Browse files Browse the repository at this point in the history
Fixes #664
  • Loading branch information
markh-de committed Nov 21, 2024
1 parent f972993 commit 50babb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions kikit/fab/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ def footprintPosition(footprint, placeOffset, compensation):
pos += VECTOR2I(fromMm(x), fromMm(y))
return pos

def footprintOrientation(footprint, compensation):
return (footprint.GetOrientation().AsDegrees() + compensation[2]) % 360
def footprintOrientation(footprint, compensation, flipBottomOrientation=False):
if flipBottomOrientation and layerToSide(footprint.GetLayer()) == "B":
angle = 180 - footprint.GetOrientation().AsDegrees()
else:
angle = footprint.GetOrientation().AsDegrees()
return (angle + compensation[2]) % 360

def parseCompensation(compensation):
compParts = compensation.split(";")
Expand Down Expand Up @@ -158,7 +162,7 @@ def noFilter(footprint):

def collectPosData(board, correctionFields, posFilter=lambda x : True,
footprintX=defaultFootprintX, footprintY=defaultFootprintY, bom=None,
correctionFile=None):
correctionFile=None, flipBottomOrientation=False):
"""
Extract position data of the footprints.
Expand Down Expand Up @@ -204,7 +208,7 @@ def getCompensation(footprint):
footprintX(footprint, placeOffset, getCompensation(footprint)),
footprintY(footprint, placeOffset, getCompensation(footprint)),
layerToSide(footprint.GetLayer()),
footprintOrientation(footprint, getCompensation(footprint))) for footprint in footprints]
footprintOrientation(footprint, getCompensation(footprint), flipBottomOrientation)) for footprint in footprints]

def posDataToFile(posData, filename):
with open(filename, "w", newline="", encoding="utf-8") as csvfile:
Expand Down
2 changes: 1 addition & 1 deletion kikit/fab/jlcpcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def exportJlcpcb(board, outputdir, assembly, schematic, ignore, field,
bom_components = [c for c in components if getReference(c) in bom_refs]

posData = collectPosData(loadedBoard, correctionFields,
bom=bom_components, posFilter=noFilter, correctionFile=correctionpatterns)
bom=bom_components, posFilter=noFilter, correctionFile=correctionpatterns, flipBottomOrientation=True)
boardReferences = set([x[0] for x in posData])
bom = {key: [v for v in val if v in boardReferences] for key, val in bom.items()}
bom = {key: val for key, val in bom.items() if len(val) > 0}
Expand Down

0 comments on commit 50babb3

Please sign in to comment.