diff --git a/kibot/PcbDraw/README.md b/kibot/PcbDraw/README.md index 4ec1eec2..3ae27e15 100644 --- a/kibot/PcbDraw/README.md +++ b/kibot/PcbDraw/README.md @@ -240,3 +240,5 @@ index f8990722..17f90185 100644 - Find the index of the smaller element (1 line code) - I added a replacemt for the `array` function, it just makes all matrix elements float +- Allow constructing PcbPlotter() using an already loaded board + - So we don't load it again diff --git a/kibot/PcbDraw/plot.py b/kibot/PcbDraw/plot.py index 5bb5aee1..ee8c794c 100644 --- a/kibot/PcbDraw/plot.py +++ b/kibot/PcbDraw/plot.py @@ -1033,12 +1033,15 @@ class PcbPlotter(): mainly serves as a builder (to step-by-step specify all options) and also to avoid passing many arguments between auxiliary functions """ - def __init__(self, boardFile: str): + def __init__(self, boardFile: Union[str, pcbnew.BOARD]): self._unique_counter: int = 1 - try: - self.board: pcbnew.BOARD = pcbnew.LoadBoard(boardFile) - except IOError: - raise IOError(f"Cannot open board '{boardFile}'") from None + if isinstance(boardFile, str): + try: + self.board: pcbnew.BOARD = pcbnew.LoadBoard(boardFile) + except IOError: + raise IOError(f"Cannot open board '{boardFile}'") from None + else: + self.board = boardFile self.render_back: bool = False self.mirror: bool = False self.plot_plan: List[PlotInterface] = [ diff --git a/kibot/out_pcb_print.py b/kibot/out_pcb_print.py index 1f533b3a..37473136 100644 --- a/kibot/out_pcb_print.py +++ b/kibot/out_pcb_print.py @@ -773,8 +773,7 @@ class PCB_PrintOptions(VariantOptions): def pcbdraw_by_module(self, pcbdraw_file, back): # Run PcbDraw to make the heavy work (find the Edge.Cuts path and create masks) try: - # TODO: Avoid loading the PCB again - plotter = PcbPlotter(GS.pcb_file) + plotter = PcbPlotter(GS.board) # TODO: Review the paths, most probably add the system KiBot dir # Read libs from current dir # plotter.setup_arbitrary_data_path(".") diff --git a/kibot/out_pcbdraw.py b/kibot/out_pcbdraw.py index cbfaa825..73ae33b6 100644 --- a/kibot/out_pcbdraw.py +++ b/kibot/out_pcbdraw.py @@ -293,8 +293,7 @@ class PcbDrawOptions(VariantOptions): save_output_format = 'png' try: - # TODO: Avoid loading the PCB again - plotter = PcbPlotter(GS.pcb_file) + plotter = PcbPlotter(GS.board) # TODO: Review the paths, most probably add the system KiBot dir # Read libs from current dir # plotter.setup_arbitrary_data_path(".")