From 0c63d67544d80c511d7ff4163cbed5e3cd704011 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 13 Jun 2023 15:34:04 -0700 Subject: [PATCH 1/2] Fix text thickness and add mirrored --- kicad/pcbnew/board.py | 4 ++-- kicad/pcbnew/drawing.py | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/kicad/pcbnew/board.py b/kicad/pcbnew/board.py index 3e1d0ea..7192760 100644 --- a/kicad/pcbnew/board.py +++ b/kicad/pcbnew/board.py @@ -258,9 +258,9 @@ def add_arc(self, center, radius, start_angle, stop_angle, drawing.Arc(center, radius, start_angle, stop_angle, layer, width, board=self)) - def add_text(self, position, text, layer='F.SilkS', size=1.0, thickness=0.15): + def add_text(self, position, text, layer='F.SilkS', size=1.0, thickness=0.15, mirrored=False): return self.add( - drawing.TextPCB(position, text, layer, size, thickness, board=self)) + drawing.TextPCB(position, text, layer, size, thickness, mirrored=mirrored, board=self)) def remove(self, element, permanent=False): ''' Makes it so Ctrl-Z works. diff --git a/kicad/pcbnew/drawing.py b/kicad/pcbnew/drawing.py index 0aa6b5b..b94ae43 100644 --- a/kicad/pcbnew/drawing.py +++ b/kicad/pcbnew/drawing.py @@ -290,7 +290,7 @@ def __init__(self, *args, **kwargs): class TextPCB(Drawing, HasPosition): - def __init__(self, position, text=None, layer='F.SilkS', size=1.0, thickness=0.15, board=None): + def __init__(self, position, text=None, layer='F.SilkS', size=1.0, thickness=0.15, mirrored=False, board=None): self._obj = SWIGtype.Text(board and board.native_obj) self.position = position if text: @@ -298,6 +298,7 @@ def __init__(self, position, text=None, layer='F.SilkS', size=1.0, thickness=0.1 self.layer = layer self.size = size self.thickness = thickness + self.mirrored = mirrored @property def text(self): @@ -307,13 +308,29 @@ def text(self): def text(self, value): return self._obj.SetText(value) + @property + def mirrored(self): + return self._obj.IsMirrored() + + @mirrored.setter + def mirrored(self, value): + return self._obj.SetMirrored(value) + @property def thickness(self): - return float(self._obj.GetThickness()) / units.DEFAULT_UNIT_IUS + if SWIG_version >= 7: + thickness = self._obj.GetTextThickness() + else: + thickness = self._obj.GetThickness() + return float() / units.DEFAULT_UNIT_IUS @thickness.setter def thickness(self, value): - return self._obj.SetThickness(int(value * units.DEFAULT_UNIT_IUS)) + thickness = int(value * units.DEFAULT_UNIT_IUS) + + if SWIG_version >= 7: + return self._obj.SetTextThickness(thickness) + return self._obj.SetThickness(thickness) @property def size(self): From afa804f806d80e4e884426beb02c151029038de6 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 6 Jul 2023 14:26:31 -0700 Subject: [PATCH 2/2] Fix reading thickness --- kicad/pcbnew/drawing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kicad/pcbnew/drawing.py b/kicad/pcbnew/drawing.py index b94ae43..4618d7a 100644 --- a/kicad/pcbnew/drawing.py +++ b/kicad/pcbnew/drawing.py @@ -322,7 +322,7 @@ def thickness(self): thickness = self._obj.GetTextThickness() else: thickness = self._obj.GetThickness() - return float() / units.DEFAULT_UNIT_IUS + return float(thickness) / units.DEFAULT_UNIT_IUS @thickness.setter def thickness(self, value):