From 5f5bbccd050414afaf01dd578198d19b4d26ef87 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 19 Jul 2024 19:21:24 +0200 Subject: 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. --- gerbonara/cad/kicad/footprints.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gerbonara/cad/kicad/footprints.py') diff --git a/gerbonara/cad/kicad/footprints.py b/gerbonara/cad/kicad/footprints.py index 43230ce..da2c61e 100644 --- a/gerbonara/cad/kicad/footprints.py +++ b/gerbonara/cad/kicad/footprints.py @@ -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 -- cgit