From 50babb3aabe7d1bfd95275e0be1929767486bd27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20H=C3=A4mmerling?= Date: Thu, 21 Nov 2024 20:53:10 +0100 Subject: [PATCH] For JLCPCB, flip orientation (incl. compensation angle) for bottom parts Fixes #664 --- kikit/fab/common.py | 12 ++++++++---- kikit/fab/jlcpcb.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kikit/fab/common.py b/kikit/fab/common.py index a72fde34..72f0092a 100644 --- a/kikit/fab/common.py +++ b/kikit/fab/common.py @@ -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(";") @@ -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. @@ -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: diff --git a/kikit/fab/jlcpcb.py b/kikit/fab/jlcpcb.py index 5fee1e7e..45eb693e 100644 --- a/kikit/fab/jlcpcb.py +++ b/kikit/fab/jlcpcb.py @@ -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}