Skip to content

Commit

Permalink
Update JLC PCB footprint orientation handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx committed Jan 26, 2025
1 parent 5de2b13 commit 8c980f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions kikit/fab/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import csv
from dataclasses import dataclass
from enum import Enum
import re
from typing import OrderedDict
from kikit.project import KiCADProject
Expand Down Expand Up @@ -61,6 +62,10 @@ def hasNonSMDPins(footprint):
class FormatError(Exception):
pass

class FootprintOrientationHandling(Enum):
KiCad = 0
MirrorBottom = 1

@dataclass
class CorrectionPattern:
"""Single correction pattern to match a component against."""
Expand All @@ -85,8 +90,16 @@ 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, orientation: FootprintOrientationHandling = FootprintOrientationHandling.KiCad):
if orientation == FootprintOrientationHandling.KiCad:
return (footprint.GetOrientation().AsDegrees() + compensation[2]) % 360
if orientation == FootprintOrientationHandling.MirrorBottom:
if layerToSide(footprint.GetLayer()) == "B":
return (180 - footprint.GetOrientation().AsDegrees() + compensation[2]) % 360
else:
return (footprint.GetOrientation().AsDegrees() + compensation[2]) % 360

raise AssertionError("Invalid orientation handling")

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

def collectPosData(board, correctionFields, posFilter=lambda x : True,
footprintX=defaultFootprintX, footprintY=defaultFootprintY, bom=None,
correctionFile=None):
correctionFile=None, orientationHandling: FootprintOrientationHandling = FootprintOrientationHandling.KiCad):
"""
Extract position data of the footprints.
Expand Down Expand Up @@ -204,7 +217,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), orientationHandling)) for footprint in footprints]

def posDataToFile(posData, filename):
with open(filename, "w", newline="", encoding="utf-8") as csvfile:
Expand Down
3 changes: 2 additions & 1 deletion kikit/fab/jlcpcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ 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,
orientationHandling=FootprintOrientationHandling.MirrorBottom)
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 8c980f3

Please sign in to comment.