Skip to content

Commit

Permalink
Fix compatibility with v8
Browse files Browse the repository at this point in the history
  • Loading branch information
qu1ck committed Jan 25, 2024
1 parent d8bc5cd commit 2415e50
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions TransformIt/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def _setup_logging(self, board_file: str):
logging.Formatter('%(asctime)s %(levelname)s: %(message)s'))
self.logger.addHandler(self.log_handler)
self.logger.setLevel(logging.DEBUG)
self.logger.info("Log handlers: %s", self.logger.handlers)

def _transform_point(self,
point: pcbnew.VECTOR2I,
Expand Down Expand Up @@ -117,7 +116,9 @@ def _transform_shape(self,

shape.SetWidth(int(shape.GetWidth() * self.config.shape_width))

def _transform_fp_shape(self, shape: pcbnew.FP_SHAPE):
# this method has no type hint because kicad 8 does not have FP_SHAPE
# it will be called only for FP_SHAPE in kicad 7
def _transform_fp_shape(self, shape):
shape_type = shape.GetShape()
self.logger.debug("Transforminig footprint shape type %d", shape_type)

Expand Down Expand Up @@ -161,7 +162,7 @@ def _transform_track(
track.SetWidth(int(track.GetWidth() * self.config.track_width))

def _transform_text(self, text: pcbnew.PCB_TEXT, center: pcbnew.VECTOR2I):
self.logger.debug("Transforming text '%s'", text.GetShownText())
self.logger.debug("Transforming text '%s'", text.GetText())

text.SetPosition(self._transform_point(text.GetPosition(), center))
text.SetMirrored(bool(text.IsMirrored()) ^
Expand All @@ -173,8 +174,18 @@ def _transform_text(self, text: pcbnew.PCB_TEXT, center: pcbnew.VECTOR2I):
def _transform_pad(self, pad: pcbnew.PAD):
self.logger.debug("Transforming pad '%s'", pad.GetPadName())

pad.SetPos0(self._transform_point(pad.GetPos0(), self.ORIGIN))
pad.SetDrawCoord()
if hasattr(pad, "SetPos0"):
pad.SetPos0(self._transform_point(pad.GetPos0(), self.ORIGIN))
pad.SetDrawCoord()
else:
parent_pos: pcbnew.VECTOR2I = pad.GetParent().GetPosition()
pad_pos: pcbnew.VECTOR2I = pad.GetPosition()
rel_pos = pcbnew.VECTOR2I(
pad_pos.x - parent_pos.x, pad_pos.y - parent_pos.y)
rel_pos = self._transform_point(rel_pos, self.ORIGIN)
pad_pos = pcbnew.VECTOR2I(
parent_pos.x + rel_pos.x, parent_pos.y + rel_pos.y)
pad.SetPosition(pad_pos)

pad.Rotate(
pad.GetPosition(),
Expand All @@ -187,7 +198,8 @@ def _transform_drawing(self,
"Transforming drawing type %s (%s) at %s",
drawing.Type(), drawing.GetTypeDesc(), drawing.GetPosition())

if isinstance(drawing, pcbnew.FP_SHAPE):
if (hasattr(pcbnew, "FP_SHAPE")
and isinstance(drawing, pcbnew.FP_SHAPE)):
self.logger.debug("Drawing is FP_SHAPE")
self._transform_fp_shape(drawing)

Expand All @@ -212,7 +224,8 @@ def _transform_drawing(self,
pcbnew.EDA_ANGLE(-self.config.rotation, pcbnew.RADIANS_T))

elif (isinstance(drawing, pcbnew.PCB_TEXT) or
isinstance(drawing, pcbnew.FP_TEXT)):
(hasattr(pcbnew, "FP_TEXT") and
isinstance(drawing, pcbnew.FP_TEXT))):
self.logger.debug("Drawing is FP/PCB_TEXT")
self._transform_text(drawing, center)

Expand Down

0 comments on commit 2415e50

Please sign in to comment.