kicad: Add copy_placement method to footprints

Moving footprints around is ugly because of kicad's really weird way of
specifying sub-object coordinates and rotations. This commit adds a
helper method to deal with that.
This commit is contained in:
jaseg 2024-07-19 19:21:24 +02:00
parent ea2664219d
commit 5f5bbccd05

View file

@ -733,6 +733,14 @@ class Footprint:
def offset(self, x=0, y=0):
self.at = self.at.with_offset(x, y)
def copy_placement(self, template):
# Fix up rotation of pads - KiCad saves each pad's rotation in *absolute* coordinates, not relative to the
# footprint. Because we overwrite the footprint's rotation below, we have to first fix all pads to match the
# new rotation.
self.rotate(math.radians(template.at.rotation - self.at.rotation))
self.at = copy.copy(template.at)
self.side = template.side
@property
def version(self):
return self._version