The board object is no longer passed to run methodes.
The global GS.board is used instead.
This commit is contained in:
parent
159e8996e8
commit
b347a6ca30
|
|
@ -124,6 +124,9 @@ def exec_with_retry(cmd):
|
||||||
|
|
||||||
|
|
||||||
def load_board(pcb_file=None):
|
def load_board(pcb_file=None):
|
||||||
|
if GS.board is not None:
|
||||||
|
# Already loaded
|
||||||
|
return GS.board
|
||||||
import pcbnew
|
import pcbnew
|
||||||
if not pcb_file:
|
if not pcb_file:
|
||||||
GS.check_pcb()
|
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. """
|
Note that we do it every time the function is called to reset transformation filters like rot_footprint. """
|
||||||
if not GS.pcb_file:
|
if not GS.pcb_file:
|
||||||
return
|
return
|
||||||
if not GS.board:
|
load_board()
|
||||||
load_board()
|
|
||||||
comps_hash = {c.ref: c for c in comps}
|
comps_hash = {c.ref: c for c in comps}
|
||||||
for m in GS.board.GetModules():
|
for m in GS.board.GetModules():
|
||||||
ref = m.GetReference()
|
ref = m.GetReference()
|
||||||
|
|
@ -256,19 +258,18 @@ def generate_outputs(outputs, target, invert, skip_pre):
|
||||||
logger.debug('Skipping all outputs')
|
logger.debug('Skipping all outputs')
|
||||||
return
|
return
|
||||||
# Generate outputs
|
# Generate outputs
|
||||||
board = None
|
|
||||||
for out in outputs:
|
for out in outputs:
|
||||||
if (n == 0) or ((out.name in target) ^ invert):
|
if (n == 0) or ((out.name in target) ^ invert):
|
||||||
# Should we load the PCB?
|
# Should we load the PCB?
|
||||||
if out.is_pcb() and (board is None):
|
if out.is_pcb():
|
||||||
board = load_board()
|
load_board()
|
||||||
if out.is_sch():
|
if out.is_sch():
|
||||||
load_sch()
|
load_sch()
|
||||||
config_output(out)
|
config_output(out)
|
||||||
logger.info('- '+str(out))
|
logger.info('- '+str(out))
|
||||||
GS.current_output = out.name
|
GS.current_output = out.name
|
||||||
try:
|
try:
|
||||||
out.run(get_output_dir(out.dir), board)
|
out.run(get_output_dir(out.dir))
|
||||||
except PlotError as e:
|
except PlotError as e:
|
||||||
logger.error("In output `"+str(out)+"`: "+str(e))
|
logger.error("In output `"+str(out)+"`: "+str(e))
|
||||||
exit(PLOT_ERROR)
|
exit(PLOT_ERROR)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2020 Salvador E. Tropea
|
# Copyright (c) 2020-2021 Salvador E. Tropea
|
||||||
# Copyright (c) 2020 Instituto Nacional de Tecnología Industrial
|
# Copyright (c) 2020-2021 Instituto Nacional de Tecnología Industrial
|
||||||
# License: GPL-3.0
|
# License: GPL-3.0
|
||||||
# Project: KiBot (formerly KiPlot)
|
# Project: KiBot (formerly KiPlot)
|
||||||
import os
|
import os
|
||||||
|
|
@ -102,13 +102,13 @@ class AnyDrill(BaseOptions):
|
||||||
# PTH
|
# PTH
|
||||||
return self.pth_id if self.pth_id is not None else d+'_drill'
|
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
|
# dialog_gendrill.cpp:357
|
||||||
if self.use_aux_axis_as_origin:
|
if self.use_aux_axis_as_origin:
|
||||||
offset = get_aux_origin(board)
|
offset = get_aux_origin(GS.board)
|
||||||
else:
|
else:
|
||||||
offset = wxPoint(0, 0)
|
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)
|
logger.debug("Generating drill files in "+output_dir)
|
||||||
gen_map = self.map is not None
|
gen_map = self.map is not None
|
||||||
|
|
|
||||||
|
|
@ -96,10 +96,10 @@ class AnyLayerOptions(VariantOptions):
|
||||||
self.uncross_modules(board, self.comps_hash)
|
self.uncross_modules(board, self.comps_hash)
|
||||||
self.restore_paste_and_glue(board, self.comps_hash)
|
self.restore_paste_and_glue(board, self.comps_hash)
|
||||||
|
|
||||||
def run(self, output_dir, board, layers):
|
def run(self, output_dir, layers):
|
||||||
super().run(output_dir, board)
|
super().run(output_dir)
|
||||||
# fresh plot controller
|
# fresh plot controller
|
||||||
plot_ctrl = PLOT_CONTROLLER(board)
|
plot_ctrl = PLOT_CONTROLLER(GS.board)
|
||||||
# set up plot options for the whole output
|
# set up plot options for the whole output
|
||||||
po = plot_ctrl.GetPlotOptions()
|
po = plot_ctrl.GetPlotOptions()
|
||||||
self._configure_plot_ctrl(po, output_dir)
|
self._configure_plot_ctrl(po, output_dir)
|
||||||
|
|
@ -107,10 +107,10 @@ class AnyLayerOptions(VariantOptions):
|
||||||
# We need to assist KiCad
|
# We need to assist KiCad
|
||||||
create_job = po.GetCreateGerberJobFile()
|
create_job = po.GetCreateGerberJobFile()
|
||||||
if create_job:
|
if create_job:
|
||||||
jobfile_writer = GERBER_JOBFILE_WRITER(board)
|
jobfile_writer = GERBER_JOBFILE_WRITER(GS.board)
|
||||||
plot_ctrl.SetColorMode(True)
|
plot_ctrl.SetColorMode(True)
|
||||||
# Apply the variants and filters
|
# Apply the variants and filters
|
||||||
exclude = self.filter_components(board)
|
exclude = self.filter_components(GS.board)
|
||||||
# Plot every layer in the output
|
# Plot every layer in the output
|
||||||
generated = {}
|
generated = {}
|
||||||
layers = Layer.solve(layers)
|
layers = Layer.solve(layers)
|
||||||
|
|
@ -179,7 +179,7 @@ class AnyLayerOptions(VariantOptions):
|
||||||
f.write(content)
|
f.write(content)
|
||||||
# Restore the eliminated layers
|
# Restore the eliminated layers
|
||||||
if exclude:
|
if exclude:
|
||||||
self.unfilter_components(board)
|
self.unfilter_components(GS.board)
|
||||||
|
|
||||||
def read_vals_from_po(self, po):
|
def read_vals_from_po(self, po):
|
||||||
# excludeedgelayer
|
# excludeedgelayer
|
||||||
|
|
@ -213,5 +213,5 @@ class AnyLayer(BaseOutput):
|
||||||
if isinstance(self.layers, type):
|
if isinstance(self.layers, type):
|
||||||
raise KiPlotConfigurationError("Missing `layers` list")
|
raise KiPlotConfigurationError("Missing `layers` list")
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
self.options.run(output_dir, board, self.layers)
|
self.options.run(output_dir, self.layers)
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ class BaseOutput(RegOutput):
|
||||||
# Configure them using an empty tree
|
# Configure them using an empty tree
|
||||||
self.options.config()
|
self.options.config()
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
self.options.run(output_dir, board)
|
self.options.run(output_dir)
|
||||||
|
|
||||||
|
|
||||||
class BoMRegex(Optionable):
|
class BoMRegex(Optionable):
|
||||||
|
|
@ -253,7 +253,7 @@ class VariantOptions(BaseOptions):
|
||||||
for gi in self.old_badhes:
|
for gi in self.old_badhes:
|
||||||
gi.SetLayer(self.badhes)
|
gi.SetLayer(self.badhes)
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
""" Makes the list of components available """
|
""" Makes the list of components available """
|
||||||
if not self.dnf_filter and not self.variant:
|
if not self.dnf_filter and not self.variant:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -384,7 +384,7 @@ class BoMOptions(BaseOptions):
|
||||||
# This is the ordered list with the case style defined by the user
|
# This is the ordered list with the case style defined by the user
|
||||||
self.columns = columns
|
self.columns = columns
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
format = self.format.lower()
|
format = self.format.lower()
|
||||||
output = self.expand_filename_sch(output_dir, self.output, 'bom', format)
|
output = self.expand_filename_sch(output_dir, self.output, 'bom', format)
|
||||||
# Add some info needed for the output to the config object.
|
# Add some info needed for the output to the config object.
|
||||||
|
|
|
||||||
|
|
@ -104,10 +104,8 @@ class CompressOptions(BaseOptions):
|
||||||
ext += '.'+sub_ext
|
ext += '.'+sub_ext
|
||||||
return ext
|
return ext
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
# Output file name
|
# 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())
|
output = self.expand_filename(output_dir, self.output, GS.current_output, self.solve_extension())
|
||||||
logger.debug('Collecting files')
|
logger.debug('Collecting files')
|
||||||
output_real = os.path.realpath(output)
|
output_real = os.path.realpath(output)
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,8 @@ class IBoMOptions(VariantOptions):
|
||||||
super().config()
|
super().config()
|
||||||
self.netlist_file = self.expand_filename('', self.netlist_file, 'ibom', 'xml')
|
self.netlist_file = self.expand_filename('', self.netlist_file, 'ibom', 'xml')
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
super().run(output_dir, board)
|
super().run(output_dir)
|
||||||
check_script(CMD_IBOM, URL_IBOM)
|
check_script(CMD_IBOM, URL_IBOM)
|
||||||
logger.debug('Doing Interactive BoM')
|
logger.debug('Doing Interactive BoM')
|
||||||
# Tell ibom we don't want to use the screen
|
# Tell ibom we don't want to use the screen
|
||||||
|
|
|
||||||
|
|
@ -355,7 +355,7 @@ class KiBoMOptions(BaseOptions):
|
||||||
self.conf.save(conf)
|
self.conf.save(conf)
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
check_script(CMD_KIBOM, URL_KIBOM, '1.8.0')
|
check_script(CMD_KIBOM, URL_KIBOM, '1.8.0')
|
||||||
format = self.format.lower()
|
format = self.format.lower()
|
||||||
prj = GS.sch_no_ext
|
prj = GS.sch_no_ext
|
||||||
|
|
|
||||||
|
|
@ -227,8 +227,8 @@ class PcbDrawOptions(VariantOptions):
|
||||||
cmd.append(svg)
|
cmd.append(svg)
|
||||||
return svg
|
return svg
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
super().run(output_dir, board)
|
super().run(output_dir)
|
||||||
check_script(PCBDRAW, URL_PCBDRAW, '0.6.0')
|
check_script(PCBDRAW, URL_PCBDRAW, '0.6.0')
|
||||||
# Output file name
|
# Output file name
|
||||||
output = self.expand_filename(output_dir, self.output, 'bottom' if self.bottom else 'top', self.format)
|
output = self.expand_filename(output_dir, self.output, 'bottom' if self.bottom else 'top', self.format)
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,8 @@ class PDF_Pcb_PrintOptions(VariantOptions):
|
||||||
self.restore_paste_and_glue(board, comps_hash)
|
self.restore_paste_and_glue(board, comps_hash)
|
||||||
return fname, fproj
|
return fname, fproj
|
||||||
|
|
||||||
def run(self, output_dir, board, layers):
|
def run(self, output_dir, layers):
|
||||||
super().run(board, layers)
|
super().run(layers)
|
||||||
check_script(CMD_PCBNEW_PRINT_LAYERS, URL_PCBNEW_PRINT_LAYERS, '1.5.2')
|
check_script(CMD_PCBNEW_PRINT_LAYERS, URL_PCBNEW_PRINT_LAYERS, '1.5.2')
|
||||||
layers = Layer.solve(layers)
|
layers = Layer.solve(layers)
|
||||||
# Output file name
|
# Output file name
|
||||||
|
|
@ -104,7 +104,7 @@ class PDF_Pcb_PrintOptions(VariantOptions):
|
||||||
cmd.append('--separate')
|
cmd.append('--separate')
|
||||||
if self.mirror:
|
if self.mirror:
|
||||||
cmd.append('--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])
|
cmd.extend([board_name, output_dir])
|
||||||
if GS.debug_enabled:
|
if GS.debug_enabled:
|
||||||
cmd.insert(1, '-vv')
|
cmd.insert(1, '-vv')
|
||||||
|
|
@ -146,5 +146,5 @@ class PDF_Pcb_Print(BaseOutput): # noqa: F821
|
||||||
if isinstance(self.layers, type):
|
if isinstance(self.layers, type):
|
||||||
raise KiPlotConfigurationError("Missing `layers` list")
|
raise KiPlotConfigurationError("Missing `layers` list")
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
self.options.run(output_dir, board, self.layers)
|
self.options.run(output_dir, self.layers)
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ class PDF_Sch_PrintOptions(VariantOptions):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.add_to_doc('variant', "Not fitted components are crossed")
|
self.add_to_doc('variant', "Not fitted components are crossed")
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
super().run(output_dir, board)
|
super().run(output_dir)
|
||||||
check_eeschema_do()
|
check_eeschema_do()
|
||||||
if self._comps:
|
if self._comps:
|
||||||
# Save it to a temporal dir
|
# Save it to a temporal dir
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class PositionOptions(VariantOptions):
|
||||||
new_columns[new_col] = new_name
|
new_columns[new_col] = new_name
|
||||||
self.columns = new_columns
|
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
|
topf = None
|
||||||
botf = None
|
botf = None
|
||||||
bothf = None
|
bothf = None
|
||||||
|
|
@ -145,7 +145,7 @@ class PositionOptions(VariantOptions):
|
||||||
if bothf is not None:
|
if bothf is not None:
|
||||||
bothf.close()
|
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
|
topf = None
|
||||||
botf = None
|
botf = None
|
||||||
bothf = 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_5, PositionOptions.is_not_virtual_5
|
||||||
return PositionOptions.is_pure_smd_6, PositionOptions.is_not_virtual_6
|
return PositionOptions.is_pure_smd_6, PositionOptions.is_not_virtual_6
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
super().run(output_dir, board)
|
super().run(output_dir)
|
||||||
columns = self.columns.values()
|
columns = self.columns.values()
|
||||||
# Note: the parser already checked the units are milimeters or inches
|
# Note: the parser already checked the units are milimeters or inches
|
||||||
conv = 1.0
|
conv = 1.0
|
||||||
|
|
@ -214,7 +214,7 @@ class PositionOptions(VariantOptions):
|
||||||
modules = []
|
modules = []
|
||||||
is_pure_smd, is_not_virtual = self.get_attr_tests()
|
is_pure_smd, is_not_virtual = self.get_attr_tests()
|
||||||
quote_char = '"' if self.format == 'CSV' else ''
|
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()
|
ref = m.GetReference()
|
||||||
value = None
|
value = None
|
||||||
# Apply any filter or variant data
|
# Apply any filter or variant data
|
||||||
|
|
@ -265,9 +265,9 @@ class PositionOptions(VariantOptions):
|
||||||
maxlengths.append(max_l)
|
maxlengths.append(max_l)
|
||||||
# Note: the parser already checked the format is ASCII or CSV
|
# Note: the parser already checked the format is ASCII or CSV
|
||||||
if self.format == 'ASCII':
|
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':
|
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
|
@output_class
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ class Sch_Variant_Options(VariantOptions):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
super().run(output_dir, board)
|
super().run(output_dir)
|
||||||
# Create the schematic
|
# Create the schematic
|
||||||
GS.sch.save_variant(output_dir)
|
GS.sch.save_variant(output_dir)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,8 +185,8 @@ class STEPOptions(VariantOptions):
|
||||||
models.push_front(model)
|
models.push_front(model)
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
super().run(output_dir, board)
|
super().run(output_dir)
|
||||||
# Output file name
|
# Output file name
|
||||||
output = self.expand_filename(output_dir, self.output, '3D', 'step')
|
output = self.expand_filename(output_dir, self.output, '3D', 'step')
|
||||||
# Make units explicit
|
# Make units explicit
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ class SVG_Sch_PrintOptions(VariantOptions):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.add_to_doc('variant', "Not fitted components are crossed")
|
self.add_to_doc('variant', "Not fitted components are crossed")
|
||||||
|
|
||||||
def run(self, output_dir, board):
|
def run(self, output_dir):
|
||||||
super().run(output_dir, board)
|
super().run(output_dir)
|
||||||
check_eeschema_do()
|
check_eeschema_do()
|
||||||
if self._comps:
|
if self._comps:
|
||||||
# Save it to a temporal dir
|
# Save it to a temporal dir
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ def test_pcbdraw_miss_rsvg(caplog, monkeypatch):
|
||||||
o.config()
|
o.config()
|
||||||
cov.load()
|
cov.load()
|
||||||
cov.start()
|
cov.start()
|
||||||
o.run('', None)
|
o.run('')
|
||||||
cov.stop()
|
cov.stop()
|
||||||
cov.save()
|
cov.save()
|
||||||
assert 'using unreliable PNG/JPG' in caplog.text, caplog.text
|
assert 'using unreliable PNG/JPG' in caplog.text, caplog.text
|
||||||
|
|
@ -91,7 +91,7 @@ def test_pcbdraw_miss_convert(caplog, monkeypatch):
|
||||||
o.config()
|
o.config()
|
||||||
cov.load()
|
cov.load()
|
||||||
cov.start()
|
cov.start()
|
||||||
o.run('', None)
|
o.run('')
|
||||||
cov.stop()
|
cov.stop()
|
||||||
cov.save()
|
cov.save()
|
||||||
assert 'using unreliable PNG/JPG' in caplog.text, caplog.text
|
assert 'using unreliable PNG/JPG' in caplog.text, caplog.text
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue