From b347a6ca304d917d8ec5ec8b3d30fecc4cf59f8f Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 15 Jan 2021 14:14:17 -0300 Subject: [PATCH] The board object is no longer passed to run methodes. The global GS.board is used instead. --- kibot/kiplot.py | 13 +++++++------ kibot/out_any_drill.py | 10 +++++----- kibot/out_any_layer.py | 16 ++++++++-------- kibot/out_base.py | 6 +++--- kibot/out_bom.py | 2 +- kibot/out_compress.py | 4 +--- kibot/out_ibom.py | 4 ++-- kibot/out_kibom.py | 2 +- kibot/out_pcbdraw.py | 4 ++-- kibot/out_pdf_pcb_print.py | 10 +++++----- kibot/out_pdf_sch_print.py | 4 ++-- kibot/out_position.py | 14 +++++++------- kibot/out_sch_variant.py | 4 ++-- kibot/out_step.py | 4 ++-- kibot/out_svg_sch_print.py | 4 ++-- tests/test_plot/test_pcbdraw.py | 4 ++-- 16 files changed, 52 insertions(+), 53 deletions(-) diff --git a/kibot/kiplot.py b/kibot/kiplot.py index 164b66ee..be6cdeeb 100644 --- a/kibot/kiplot.py +++ b/kibot/kiplot.py @@ -124,6 +124,9 @@ def exec_with_retry(cmd): def load_board(pcb_file=None): + if GS.board is not None: + # Already loaded + return GS.board import pcbnew if not pcb_file: GS.check_pcb() @@ -172,8 +175,7 @@ def get_board_comps_data(comps): Note that we do it every time the function is called to reset transformation filters like rot_footprint. """ if not GS.pcb_file: return - if not GS.board: - load_board() + load_board() comps_hash = {c.ref: c for c in comps} for m in GS.board.GetModules(): ref = m.GetReference() @@ -256,19 +258,18 @@ def generate_outputs(outputs, target, invert, skip_pre): logger.debug('Skipping all outputs') return # Generate outputs - board = None for out in outputs: if (n == 0) or ((out.name in target) ^ invert): # Should we load the PCB? - if out.is_pcb() and (board is None): - board = load_board() + if out.is_pcb(): + load_board() if out.is_sch(): load_sch() config_output(out) logger.info('- '+str(out)) GS.current_output = out.name try: - out.run(get_output_dir(out.dir), board) + out.run(get_output_dir(out.dir)) except PlotError as e: logger.error("In output `"+str(out)+"`: "+str(e)) exit(PLOT_ERROR) diff --git a/kibot/out_any_drill.py b/kibot/out_any_drill.py index ba864bbc..ef0c5059 100644 --- a/kibot/out_any_drill.py +++ b/kibot/out_any_drill.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2020 Salvador E. Tropea -# Copyright (c) 2020 Instituto Nacional de TecnologĂ­a Industrial +# Copyright (c) 2020-2021 Salvador E. Tropea +# Copyright (c) 2020-2021 Instituto Nacional de TecnologĂ­a Industrial # License: GPL-3.0 # Project: KiBot (formerly KiPlot) import os @@ -102,13 +102,13 @@ class AnyDrill(BaseOptions): # PTH return self.pth_id if self.pth_id is not None else d+'_drill' - def run(self, output_dir, board): + def run(self, output_dir): # dialog_gendrill.cpp:357 if self.use_aux_axis_as_origin: - offset = get_aux_origin(board) + offset = get_aux_origin(GS.board) else: offset = wxPoint(0, 0) - drill_writer, ext = self._configure_writer(board, offset) + drill_writer, ext = self._configure_writer(GS.board, offset) logger.debug("Generating drill files in "+output_dir) gen_map = self.map is not None diff --git a/kibot/out_any_layer.py b/kibot/out_any_layer.py index a6fa7d09..fbf8f5be 100644 --- a/kibot/out_any_layer.py +++ b/kibot/out_any_layer.py @@ -96,10 +96,10 @@ class AnyLayerOptions(VariantOptions): self.uncross_modules(board, self.comps_hash) self.restore_paste_and_glue(board, self.comps_hash) - def run(self, output_dir, board, layers): - super().run(output_dir, board) + def run(self, output_dir, layers): + super().run(output_dir) # fresh plot controller - plot_ctrl = PLOT_CONTROLLER(board) + plot_ctrl = PLOT_CONTROLLER(GS.board) # set up plot options for the whole output po = plot_ctrl.GetPlotOptions() self._configure_plot_ctrl(po, output_dir) @@ -107,10 +107,10 @@ class AnyLayerOptions(VariantOptions): # We need to assist KiCad create_job = po.GetCreateGerberJobFile() if create_job: - jobfile_writer = GERBER_JOBFILE_WRITER(board) + jobfile_writer = GERBER_JOBFILE_WRITER(GS.board) plot_ctrl.SetColorMode(True) # Apply the variants and filters - exclude = self.filter_components(board) + exclude = self.filter_components(GS.board) # Plot every layer in the output generated = {} layers = Layer.solve(layers) @@ -179,7 +179,7 @@ class AnyLayerOptions(VariantOptions): f.write(content) # Restore the eliminated layers if exclude: - self.unfilter_components(board) + self.unfilter_components(GS.board) def read_vals_from_po(self, po): # excludeedgelayer @@ -213,5 +213,5 @@ class AnyLayer(BaseOutput): if isinstance(self.layers, type): raise KiPlotConfigurationError("Missing `layers` list") - def run(self, output_dir, board): - self.options.run(output_dir, board, self.layers) + def run(self, output_dir): + self.options.run(output_dir, self.layers) diff --git a/kibot/out_base.py b/kibot/out_base.py index f17deffc..0ef988e0 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -55,8 +55,8 @@ class BaseOutput(RegOutput): # Configure them using an empty tree self.options.config() - def run(self, output_dir, board): - self.options.run(output_dir, board) + def run(self, output_dir): + self.options.run(output_dir) class BoMRegex(Optionable): @@ -253,7 +253,7 @@ class VariantOptions(BaseOptions): for gi in self.old_badhes: gi.SetLayer(self.badhes) - def run(self, output_dir, board): + def run(self, output_dir): """ Makes the list of components available """ if not self.dnf_filter and not self.variant: return diff --git a/kibot/out_bom.py b/kibot/out_bom.py index 73f7cfa1..c6385d5b 100644 --- a/kibot/out_bom.py +++ b/kibot/out_bom.py @@ -384,7 +384,7 @@ class BoMOptions(BaseOptions): # This is the ordered list with the case style defined by the user self.columns = columns - def run(self, output_dir, board): + def run(self, output_dir): format = self.format.lower() output = self.expand_filename_sch(output_dir, self.output, 'bom', format) # Add some info needed for the output to the config object. diff --git a/kibot/out_compress.py b/kibot/out_compress.py index 0d4ccb86..005d3d72 100644 --- a/kibot/out_compress.py +++ b/kibot/out_compress.py @@ -104,10 +104,8 @@ class CompressOptions(BaseOptions): ext += '.'+sub_ext return ext - def run(self, output_dir, board): + def run(self, output_dir): # Output file name - logger.debug('output_dir '+output_dir) - logger.debug('GS.out_dir '+GS.out_dir) output = self.expand_filename(output_dir, self.output, GS.current_output, self.solve_extension()) logger.debug('Collecting files') output_real = os.path.realpath(output) diff --git a/kibot/out_ibom.py b/kibot/out_ibom.py index c0b9adc4..4bbc0dc8 100644 --- a/kibot/out_ibom.py +++ b/kibot/out_ibom.py @@ -89,8 +89,8 @@ class IBoMOptions(VariantOptions): super().config() self.netlist_file = self.expand_filename('', self.netlist_file, 'ibom', 'xml') - def run(self, output_dir, board): - super().run(output_dir, board) + def run(self, output_dir): + super().run(output_dir) check_script(CMD_IBOM, URL_IBOM) logger.debug('Doing Interactive BoM') # Tell ibom we don't want to use the screen diff --git a/kibot/out_kibom.py b/kibot/out_kibom.py index 2903b9a3..ee0cba38 100644 --- a/kibot/out_kibom.py +++ b/kibot/out_kibom.py @@ -355,7 +355,7 @@ class KiBoMOptions(BaseOptions): self.conf.save(conf) self.conf = conf - def run(self, output_dir, board): + def run(self, output_dir): check_script(CMD_KIBOM, URL_KIBOM, '1.8.0') format = self.format.lower() prj = GS.sch_no_ext diff --git a/kibot/out_pcbdraw.py b/kibot/out_pcbdraw.py index 2b98c246..bb0483ec 100644 --- a/kibot/out_pcbdraw.py +++ b/kibot/out_pcbdraw.py @@ -227,8 +227,8 @@ class PcbDrawOptions(VariantOptions): cmd.append(svg) return svg - def run(self, output_dir, board): - super().run(output_dir, board) + def run(self, output_dir): + super().run(output_dir) check_script(PCBDRAW, URL_PCBDRAW, '0.6.0') # Output file name output = self.expand_filename(output_dir, self.output, 'bottom' if self.bottom else 'top', self.format) diff --git a/kibot/out_pdf_pcb_print.py b/kibot/out_pdf_pcb_print.py index 06ae819d..6c25ab6c 100644 --- a/kibot/out_pdf_pcb_print.py +++ b/kibot/out_pdf_pcb_print.py @@ -85,8 +85,8 @@ class PDF_Pcb_PrintOptions(VariantOptions): self.restore_paste_and_glue(board, comps_hash) return fname, fproj - def run(self, output_dir, board, layers): - super().run(board, layers) + def run(self, output_dir, layers): + super().run(layers) check_script(CMD_PCBNEW_PRINT_LAYERS, URL_PCBNEW_PRINT_LAYERS, '1.5.2') layers = Layer.solve(layers) # Output file name @@ -104,7 +104,7 @@ class PDF_Pcb_PrintOptions(VariantOptions): cmd.append('--separate') if self.mirror: cmd.append('--mirror') - board_name, proj_name = self.filter_components(board) + board_name, proj_name = self.filter_components(GS.board) cmd.extend([board_name, output_dir]) if GS.debug_enabled: cmd.insert(1, '-vv') @@ -146,5 +146,5 @@ class PDF_Pcb_Print(BaseOutput): # noqa: F821 if isinstance(self.layers, type): raise KiPlotConfigurationError("Missing `layers` list") - def run(self, output_dir, board): - self.options.run(output_dir, board, self.layers) + def run(self, output_dir): + self.options.run(output_dir, self.layers) diff --git a/kibot/out_pdf_sch_print.py b/kibot/out_pdf_sch_print.py index dd1c837b..ea11b426 100644 --- a/kibot/out_pdf_sch_print.py +++ b/kibot/out_pdf_sch_print.py @@ -24,8 +24,8 @@ class PDF_Sch_PrintOptions(VariantOptions): super().__init__() self.add_to_doc('variant', "Not fitted components are crossed") - def run(self, output_dir, board): - super().run(output_dir, board) + def run(self, output_dir): + super().run(output_dir) check_eeschema_do() if self._comps: # Save it to a temporal dir diff --git a/kibot/out_position.py b/kibot/out_position.py index 7df14c73..919bd296 100644 --- a/kibot/out_position.py +++ b/kibot/out_position.py @@ -87,7 +87,7 @@ class PositionOptions(VariantOptions): new_columns[new_col] = new_name self.columns = new_columns - def _do_position_plot_ascii(self, board, output_dir, columns, modulesStr, maxSizes): + def _do_position_plot_ascii(self, output_dir, columns, modulesStr, maxSizes): topf = None botf = None bothf = None @@ -145,7 +145,7 @@ class PositionOptions(VariantOptions): if bothf is not None: bothf.close() - def _do_position_plot_csv(self, board, output_dir, columns, modulesStr): + def _do_position_plot_csv(self, output_dir, columns, modulesStr): topf = None botf = None bothf = None @@ -200,8 +200,8 @@ class PositionOptions(VariantOptions): return PositionOptions.is_pure_smd_5, PositionOptions.is_not_virtual_5 return PositionOptions.is_pure_smd_6, PositionOptions.is_not_virtual_6 - def run(self, output_dir, board): - super().run(output_dir, board) + def run(self, output_dir): + super().run(output_dir) columns = self.columns.values() # Note: the parser already checked the units are milimeters or inches conv = 1.0 @@ -214,7 +214,7 @@ class PositionOptions(VariantOptions): modules = [] is_pure_smd, is_not_virtual = self.get_attr_tests() quote_char = '"' if self.format == 'CSV' else '' - for m in sorted(board.GetModules(), key=lambda c: _ref_key(c.GetReference())): + for m in sorted(GS.board.GetModules(), key=lambda c: _ref_key(c.GetReference())): ref = m.GetReference() value = None # Apply any filter or variant data @@ -265,9 +265,9 @@ class PositionOptions(VariantOptions): maxlengths.append(max_l) # Note: the parser already checked the format is ASCII or CSV if self.format == 'ASCII': - self._do_position_plot_ascii(board, output_dir, columns, modules, maxlengths) + self._do_position_plot_ascii(output_dir, columns, modules, maxlengths) else: # if self.format == 'CSV': - self._do_position_plot_csv(board, output_dir, columns, modules) + self._do_position_plot_csv(output_dir, columns, modules) @output_class diff --git a/kibot/out_sch_variant.py b/kibot/out_sch_variant.py index 84e5d9ed..117a1cb8 100644 --- a/kibot/out_sch_variant.py +++ b/kibot/out_sch_variant.py @@ -12,8 +12,8 @@ class Sch_Variant_Options(VariantOptions): def __init__(self): super().__init__() - def run(self, output_dir, board): - super().run(output_dir, board) + def run(self, output_dir): + super().run(output_dir) # Create the schematic GS.sch.save_variant(output_dir) diff --git a/kibot/out_step.py b/kibot/out_step.py index 6effc35b..f4b7db39 100644 --- a/kibot/out_step.py +++ b/kibot/out_step.py @@ -185,8 +185,8 @@ class STEPOptions(VariantOptions): models.push_front(model) return fname - def run(self, output_dir, board): - super().run(output_dir, board) + def run(self, output_dir): + super().run(output_dir) # Output file name output = self.expand_filename(output_dir, self.output, '3D', 'step') # Make units explicit diff --git a/kibot/out_svg_sch_print.py b/kibot/out_svg_sch_print.py index 615318f9..5161d379 100644 --- a/kibot/out_svg_sch_print.py +++ b/kibot/out_svg_sch_print.py @@ -25,8 +25,8 @@ class SVG_Sch_PrintOptions(VariantOptions): super().__init__() self.add_to_doc('variant', "Not fitted components are crossed") - def run(self, output_dir, board): - super().run(output_dir, board) + def run(self, output_dir): + super().run(output_dir) check_eeschema_do() if self._comps: # Save it to a temporal dir diff --git a/tests/test_plot/test_pcbdraw.py b/tests/test_plot/test_pcbdraw.py index c3a9a096..9851e8e2 100644 --- a/tests/test_plot/test_pcbdraw.py +++ b/tests/test_plot/test_pcbdraw.py @@ -72,7 +72,7 @@ def test_pcbdraw_miss_rsvg(caplog, monkeypatch): o.config() cov.load() cov.start() - o.run('', None) + o.run('') cov.stop() cov.save() assert 'using unreliable PNG/JPG' in caplog.text, caplog.text @@ -91,7 +91,7 @@ def test_pcbdraw_miss_convert(caplog, monkeypatch): o.config() cov.load() cov.start() - o.run('', None) + o.run('') cov.stop() cov.save() assert 'using unreliable PNG/JPG' in caplog.text, caplog.text