[PcbDraw] Avoid loading the PCB for each call to PcbDraw

This commit is contained in:
Salvador E. Tropea 2022-10-18 11:08:57 -03:00
parent 701824e4e4
commit 801f7f5183
4 changed files with 12 additions and 9 deletions

View File

@ -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

View File

@ -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] = [

View File

@ -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(".")

View File

@ -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(".")