diff --git a/kibot/PcbDraw/README.md b/kibot/PcbDraw/README.md index 2610801b..b9c8bc50 100644 --- a/kibot/PcbDraw/README.md +++ b/kibot/PcbDraw/README.md @@ -172,3 +172,6 @@ index f8990722..17f90185 100644 pos = track.GetPosition() holes.append(Hole( ``` + +- Changed `pcbnewTransition` to be locally included. + - Just 2.8 kiB no worth the effort of pulling a dependency diff --git a/kibot/PcbDraw/pcbnew_transition.py b/kibot/PcbDraw/pcbnew_transition.py new file mode 100644 index 00000000..b6bdb2c9 --- /dev/null +++ b/kibot/PcbDraw/pcbnew_transition.py @@ -0,0 +1,91 @@ +# Author: Jan Mrázek +# License: MIT +import pcbnew +import types + +# KiCAD 6 renames some of the types, ensure compatibility by introducing aliases +# when KiCAD 5 is used + +def getVersion(): + try: + v = [int(x) for x in pcbnew.GetMajorMinorVersion().split(".")] + return tuple(v) + except AttributeError: + # KiCAD 5 does not have such function, assume it version 5.something + return 5, 0 + +def boardGetProperties(self): + return {} + +def boardSetProperties(self, p): + pass + +def GetBoundingBox(self, includeText=True, includeInvisibleText=True): + if not includeText and not includeInvisibleText: + return self.GetFootprintRect() + if includeText and includeInvisibleText: + return self._GetBoundingBox() + raise NotImplementedError("Incompatible v5 and v6 API") + +def getAuxOrigin(self): + return self.m_AuxOrigin + +def setAuxOrigin(self, o): + self.m_AuxOrigin = o + +def NewBoard(filename): + return pcbnew.BOARD() + +KICAD_VERSION = getVersion() + +def isV6(version=KICAD_VERSION): + if version[0] == 5 and version[1] == 99: + return True + return version[0] == 6 + +if not isV6(KICAD_VERSION): + # Introduce new functions + pcbnew.NewBoard = NewBoard + + # Introduce type aliases + pcbnew.PCB_SHAPE = pcbnew.DRAWSEGMENT + pcbnew.FP_SHAPE = pcbnew.EDGE_MODULE + pcbnew.PCB_TEXT = pcbnew.TEXTE_PCB + pcbnew.FP_TEXT = pcbnew.TEXTE_MODULE + pcbnew.ZONE = pcbnew.ZONE_CONTAINER + pcbnew.ZONES = pcbnew.ZONE_CONTAINERS + pcbnew.DXF_UNITS_MILLIMETERS = pcbnew.DXF_PLOTTER.DXF_UNIT_MILLIMETERS + + # Introduce renamed functions + pcbnew.BOARD.GetFootprints = pcbnew.BOARD.GetModules + pcbnew.BOARD.FindFootprintByReference = pcbnew.BOARD.FindModuleByReference + + pcbnew.MODULE._GetBoundingBox = pcbnew.MODULE.GetBoundingBox + pcbnew.MODULE.GetBoundingBox = GetBoundingBox + + # Add board properties + pcbnew.BOARD.GetProperties = boardGetProperties + pcbnew.BOARD.SetProperties = boardSetProperties + pcbnew.BOARD_DESIGN_SETTINGS.GetAuxOrigin = getAuxOrigin + pcbnew.BOARD_DESIGN_SETTINGS.SetAuxOrigin = setAuxOrigin + + # NETINFO_ITEM + pcbnew.NETINFO_ITEM.GetNetCode = pcbnew.NETINFO_ITEM.GetNet + + # PCB_SHAPE + pcbnew.PCB_SHAPE.GetArcAngle = pcbnew.DRAWSEGMENT.GetAngle + + # PLOTTING ENUMS + pcbnew.PLOT_TEXT_MODE_STROKE = pcbnew.PLOTTEXTMODE_STROKE + pcbnew.PLOT_TEXT_MODE_DEFAULT = pcbnew.PLOTTEXTMODE_DEFAULT + pcbnew.PLOT_TEXT_MODE_NATIVE = pcbnew.PLOTTEXTMODE_NATIVE + pcbnew.PLOT_TEXT_MODE_PHANTOM = pcbnew.PLOTTEXTMODE_PHANTOM + + pcbnew.PCB_PLOT_PARAMS.SetSketchPadLineWidth = pcbnew.PCB_PLOT_PARAMS.SetLineWidth + + # ZONE + pcbnew.ZONE.SetIsRuleArea = pcbnew.ZONE.SetIsKeepout + + # PCB_TEXT + pcbnew.PCB_TEXT.SetTextThickness = pcbnew.PCB_TEXT.SetThickness + diff --git a/kibot/PcbDraw/plot.py b/kibot/PcbDraw/plot.py index 17f90185..2ab20fac 100644 --- a/kibot/PcbDraw/plot.py +++ b/kibot/PcbDraw/plot.py @@ -30,7 +30,7 @@ except ImportError: from .unit import read_resistance # import svgpathtools # type: ignore from lxml import etree, objectify # type: ignore -from pcbnewTransition import KICAD_VERSION, isV6, pcbnew # type: ignore +from .pcbnew_transition import KICAD_VERSION, isV6, pcbnew # type: ignore T = TypeVar("T") Numeric = Union[int, float] diff --git a/kibot/out_pcbdraw.py b/kibot/out_pcbdraw.py index 1e959698..e1417e9f 100644 --- a/kibot/out_pcbdraw.py +++ b/kibot/out_pcbdraw.py @@ -3,7 +3,7 @@ # Copyright (c) 2020-2022 Instituto Nacional de Tecnología Industrial # License: GPL-3.0 # Project: KiBot (formerly KiPlot) -# TODO: PIL dependency? pcbnewTransition? numpy? +# TODO: PIL dependency? numpy? # TODO: Package resources # TODO: replace unit.py # """