Simplified the global vars handling
- The main class also applies the command line options - Is more clear how defaults are handled - Also added global config for the 3D field name
This commit is contained in:
parent
7ddb9f5892
commit
01c015eb27
|
|
@ -244,7 +244,7 @@ def main():
|
|||
logger.error('Malformed global-redef option, must be VARIABLE=VALUE ({})'.format(redef))
|
||||
sys.exit(EXIT_BAD_ARGS)
|
||||
var = redef.split('=')[0]
|
||||
GS.global_from_cli[var] = redef[len(var)+1:]
|
||||
GS.cli_global_defs[var] = redef[len(var)+1:]
|
||||
|
||||
# Output dir: relative to CWD (absolute path overrides)
|
||||
GS.out_dir = os.path.join(os.getcwd(), args.out_dir)
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ class CfgYamlReader(object):
|
|||
gb.update(self.imported_globals)
|
||||
logger.debug("Global options + imported: {}".format(gb))
|
||||
# Parse all keys inside it
|
||||
glb = GS.global_opts_class()
|
||||
glb = GS.class_for_global_opts()
|
||||
glb.set_tree(gb)
|
||||
try:
|
||||
glb.config(None)
|
||||
|
|
@ -374,20 +374,6 @@ class CfgYamlReader(object):
|
|||
:param fstream: file stream of a config YAML file
|
||||
"""
|
||||
data = self.load_yaml(fstream)
|
||||
# Transfer command line global overwrites
|
||||
GS.global_output = GS.global_from_cli.get('output', None)
|
||||
GS.global_dir = GS.global_from_cli.get('dir', None)
|
||||
GS.global_variant = GS.global_from_cli.get('variant', None)
|
||||
GS.global_units = GS.global_from_cli.get('units', None)
|
||||
GS.global_date_time_format = GS.global_from_cli.get('date_time_format', None)
|
||||
GS.global_date_format = GS.global_from_cli.get('date_format', None)
|
||||
GS.global_time_format = GS.global_from_cli.get('time_format', None)
|
||||
GS.global_kiauto_wait_start = GS.global_from_cli.get('kiauto_wait_start', None)
|
||||
GS.global_kiauto_time_out_scale = GS.global_from_cli.get('kiauto_time_out_scale', None)
|
||||
GS.global_pcb_material = GS.global_from_cli.get('pcb_material', None)
|
||||
GS.global_solder_mask_color = GS.global_from_cli.get('solder_mask_color', None)
|
||||
GS.global_silk_screen_color = GS.global_from_cli.get('silk_screen_color', None)
|
||||
GS.global_pcb_finish = GS.global_from_cli.get('pcb_finish', None)
|
||||
# List of outputs
|
||||
version = None
|
||||
globals_found = False
|
||||
|
|
@ -562,7 +548,7 @@ def print_filters_help():
|
|||
|
||||
|
||||
def print_global_options_help():
|
||||
print_output_options('Global options', GS.global_opts_class, 2)
|
||||
print_output_options('Global options', GS.class_for_global_opts, 2)
|
||||
|
||||
|
||||
def quoted(val):
|
||||
|
|
|
|||
139
kibot/globals.py
139
kibot/globals.py
|
|
@ -18,44 +18,54 @@ class Globals(FiltersOptions):
|
|||
def __init__(self):
|
||||
super().__init__()
|
||||
with document:
|
||||
self.output = ''
|
||||
""" Default pattern for output file names """
|
||||
self.dir = ''
|
||||
""" Default pattern for the output directories """
|
||||
self.out_dir = ''
|
||||
""" Base output dir, same as command line `--out-dir` """
|
||||
self.variant = ''
|
||||
""" Default variant to apply to all outputs """
|
||||
self.units = ''
|
||||
""" [millimeters,inches,mils] Default units. Affects `position` and `bom` outputs. Also KiCad 6 dimensions """
|
||||
self.kiauto_wait_start = 0
|
||||
""" Time to wait for KiCad in KiAuto operations """
|
||||
self.kiauto_time_out_scale = 0.0
|
||||
""" Time-out multiplier for KiAuto operations """
|
||||
self.date_time_format = '%Y-%m-%d_%H-%M-%S'
|
||||
""" Format used for the PCB and schematic date when using the file timestamp. Uses the `strftime` format """
|
||||
self.castellated_pads = False
|
||||
""" Has the PCB castelletad pads?
|
||||
KiCad 6: you should set this in the Board Setup -> Board Finish -> Has castellated pads """
|
||||
self.copper_finish = None
|
||||
""" {pcb_finish} """
|
||||
self.copper_thickness = 35
|
||||
""" [number|string] Copper thickness in micrometers (1 Oz is 35 micrometers).
|
||||
KiCad 6: you should set this in the Board Setup -> Physical Stackup """
|
||||
self.date_format = '%Y-%m-%d'
|
||||
""" Format used for the day we started the script.
|
||||
Is also used for the PCB/SCH date formatting when `time_reformat` is enabled (default behavior).
|
||||
Uses the `strftime` format """
|
||||
self.time_format = '%H-%M-%S'
|
||||
""" Format used for the time we started the script. Uses the `strftime` format """
|
||||
self.time_reformat = True
|
||||
""" Tries to reformat the PCB/SCH date using the `date_format`.
|
||||
This assumes you let KiCad fill this value and hence the time is in ISO format (YY-MM-DD) """
|
||||
self.date_time_format = '%Y-%m-%d_%H-%M-%S'
|
||||
""" Format used for the PCB and schematic date when using the file timestamp. Uses the `strftime` format """
|
||||
self.dir = ''
|
||||
""" Default pattern for the output directories """
|
||||
self.drill_size_increment = 0.05
|
||||
""" This is the difference between drill tools in millimeters.
|
||||
A manufacturer with 0.05 of increment has drills for 0.1, 0.15, 0.2, 0.25, etc. """
|
||||
self.edge_connector = 'no'
|
||||
""" [yes,no,bevelled] Has the PCB edge connectors?
|
||||
KiCad 6: you should set this in the Board Setup -> Board Finish -> Edge card connectors """
|
||||
self.edge_plating = False
|
||||
""" Has the PCB a plated board edge?
|
||||
KiCad 6: you should set this in the Board Setup -> Board Finish -> Plated board edge """
|
||||
self.extra_pth_drill = 0.1
|
||||
""" How many millimeters the manufacturer will add to plated holes.
|
||||
This is because the plating reduces the hole, so you need to use a bigger drill.
|
||||
For more information consult: https://www.eurocircuits.com/pcb-design-guidelines/drilled-holes/ """
|
||||
self.field_3D_model = '_3D_model'
|
||||
""" Name for the field controlling the 3D models used for a component """
|
||||
self.kiauto_time_out_scale = 0.0
|
||||
""" Time-out multiplier for KiAuto operations """
|
||||
self.kiauto_wait_start = 0
|
||||
""" Time to wait for KiCad in KiAuto operations """
|
||||
self.impedance_controlled = False
|
||||
""" The PCB needs specific dielectric characteristics.
|
||||
KiCad 6: you should set this in the Board Setup -> Physical Stackup """
|
||||
self.output = GS.def_global_output
|
||||
""" Default pattern for output file names """
|
||||
self.pcb_finish = 'HAL'
|
||||
""" Finishing used to protect pads. Currently used for documentation and to choose default colors.
|
||||
KiCad 6: you should set this in the Board Setup -> Board Finish -> Copper Finish option.
|
||||
Currently known are None, HAL, HASL, HAL SnPb, HAL lead-free, ENIG, ENEPIG, Hard gold, ImAg, Immersion Silver,
|
||||
Immersion Ag, ImAu, Immersion Gold, Immersion Au, Immersion Tin, Immersion Nickel, OSP and HT_OSP """
|
||||
self.pcb_material = 'FR4'
|
||||
""" PCB core material. Currently used for documentation and to choose default colors.
|
||||
Currently known are FR1 to FR5 """
|
||||
self.solder_mask_color = 'green'
|
||||
""" Color for the solder mask. Currently used for documentation and to choose default colors.
|
||||
KiCad 6: you should set this in the Board Setup -> Physical Stackup.
|
||||
Currently known are green, black, white, yellow, purple, blue and red """
|
||||
self.solder_mask_color_top = ''
|
||||
""" Color for the top solder mask. When not defined `solder_mask_color` is used.
|
||||
Read `solder_mask_color` help """
|
||||
self.solder_mask_color_bottom = ''
|
||||
""" Color for the bottom solder mask. When not defined `solder_mask_color` is used.
|
||||
Read `solder_mask_color` help """
|
||||
self.silk_screen_color = 'white'
|
||||
""" Color for the markings. Currently used for documentation and to choose default colors.
|
||||
KiCad 6: you should set this in the Board Setup -> Physical Stackup.
|
||||
|
|
@ -66,49 +76,40 @@ class Globals(FiltersOptions):
|
|||
self.silk_screen_color_bottom = ''
|
||||
""" Color for the bottom silk screen. When not defined `silk_screen_color` is used.
|
||||
Read `silk_screen_color` help """
|
||||
self.pcb_finish = 'HAL'
|
||||
""" Finishing used to protect pads. Currently used for documentation and to choose default colors.
|
||||
KiCad 6: you should set this in the Board Setup -> Board Finish -> Copper Finish option.
|
||||
Currently known are None, HAL, HASL, HAL SnPb, HAL lead-free, ENIG, ENEPIG, Hard gold, ImAg, Immersion Silver,
|
||||
Immersion Ag, ImAu, Immersion Gold, Immersion Au, Immersion Tin, Immersion Nickel, OSP and HT_OSP """
|
||||
self.edge_connector = 'no'
|
||||
""" [yes,no,bevelled] Has the PCB edge connectors?
|
||||
KiCad 6: you should set this in the Board Setup -> Board Finish -> Edge card connectors """
|
||||
self.castellated_pads = False
|
||||
""" Has the PCB castelletad pads?
|
||||
KiCad 6: you should set this in the Board Setup -> Board Finish -> Has castellated pads """
|
||||
self.edge_plating = False
|
||||
""" Has the PCB a plated board edge?
|
||||
KiCad 6: you should set this in the Board Setup -> Board Finish -> Plated board edge """
|
||||
self.copper_finish = None
|
||||
""" {pcb_finish} """
|
||||
self.copper_thickness = 35
|
||||
""" [number|string] Copper thickness in micrometers (1 Oz is 35 micrometers).
|
||||
KiCad 6: you should set this in the Board Setup -> Physical Stackup """
|
||||
self.impedance_controlled = False
|
||||
""" The PCB needs specific dielectric characteristics.
|
||||
KiCad 6: you should set this in the Board Setup -> Physical Stackup """
|
||||
self.extra_pth_drill = 0.1
|
||||
""" How many millimeters the manufacturer will add to plated holes.
|
||||
This is because the plating reduces the hole, so you need to use a bigger drill.
|
||||
For more information consult: https://www.eurocircuits.com/pcb-design-guidelines/drilled-holes/ """
|
||||
self.drill_size_increment = 0.05
|
||||
""" This is the difference between drill tools in millimeters.
|
||||
A manufacturer with 0.05 of increment has drills for 0.1, 0.15, 0.2, 0.25, etc. """
|
||||
self.solder_mask_color = 'green'
|
||||
""" Color for the solder mask. Currently used for documentation and to choose default colors.
|
||||
KiCad 6: you should set this in the Board Setup -> Physical Stackup.
|
||||
Currently known are green, black, white, yellow, purple, blue and red """
|
||||
self.solder_mask_color_top = ''
|
||||
""" Color for the top solder mask. When not defined `solder_mask_color` is used.
|
||||
Read `solder_mask_color` help """
|
||||
self.solder_mask_color_bottom = ''
|
||||
""" Color for the bottom solder mask. When not defined `solder_mask_color` is used.
|
||||
Read `solder_mask_color` help """
|
||||
self.time_format = '%H-%M-%S'
|
||||
""" Format used for the time we started the script. Uses the `strftime` format """
|
||||
self.time_reformat = True
|
||||
""" Tries to reformat the PCB/SCH date using the `date_format`.
|
||||
This assumes you let KiCad fill this value and hence the time is in ISO format (YY-MM-DD) """
|
||||
self.units = ''
|
||||
""" [millimeters,inches,mils] Default units. Affects `position` and `bom` outputs. Also KiCad 6 dimensions """
|
||||
self.variant = ''
|
||||
""" Default variant to apply to all outputs """
|
||||
self.out_dir = ''
|
||||
""" Base output dir, same as command line `--out-dir` """
|
||||
self.set_doc('filters', " [list(dict)] KiBot warnings to be ignored ")
|
||||
self._filter_what = 'KiBot warnings'
|
||||
self._unkown_is_error = True
|
||||
self._error_context = 'global '
|
||||
|
||||
def set_global(self, opt):
|
||||
current = getattr(GS, 'global_'+opt)
|
||||
new_val = getattr(self, opt)
|
||||
if current is not None:
|
||||
logger.info('Using command line value `{}` for global option `{}`'.format(current, opt))
|
||||
return current
|
||||
if new_val:
|
||||
return new_val
|
||||
return current
|
||||
# Command Line value has more priority
|
||||
cli_val = GS.cli_global_defs.get(opt, None)
|
||||
if cli_val is not None:
|
||||
logger.info('Using command line value `{}` for global option `{}`'.format(cli_val, opt))
|
||||
return cli_val
|
||||
# Now try to apply our default
|
||||
return getattr(self, opt)
|
||||
|
||||
def get_data_from_layer(self, ly, materials, thicknesses):
|
||||
if ly.name == "F.SilkS":
|
||||
|
|
@ -234,4 +235,4 @@ class Globals(FiltersOptions):
|
|||
|
||||
|
||||
logger = get_logger(__name__)
|
||||
GS.global_opts_class = Globals
|
||||
GS.class_for_global_opts = Globals
|
||||
|
|
|
|||
61
kibot/gs.py
61
kibot/gs.py
|
|
@ -83,43 +83,48 @@ class GS(object):
|
|||
outputs = None
|
||||
# Name for the output we are generating
|
||||
current_output = None
|
||||
test_boolean = True
|
||||
stackup = None
|
||||
#
|
||||
# Global defaults
|
||||
#
|
||||
# Options from command line
|
||||
cli_global_defs = {}
|
||||
# The variant value, but already solved
|
||||
solved_global_variant = None
|
||||
# This is used as default value for classes supporting "output" option
|
||||
def_global_output = '%f-%i%I%v.%x'
|
||||
# The class that controls the global options
|
||||
class_for_global_opts = None
|
||||
global_castellated_pads = None
|
||||
global_copper_thickness = None
|
||||
global_date_format = None
|
||||
global_date_time_format = None
|
||||
global_dir = None
|
||||
global_drill_size_increment = None
|
||||
global_edge_connector = None
|
||||
global_edge_plating = None
|
||||
global_extra_pth_drill = None
|
||||
global_field_3D_model = None
|
||||
global_kiauto_time_out_scale = None
|
||||
global_kiauto_wait_start = None
|
||||
global_impedance_controlled = None
|
||||
# This value will overwrite GS.def_global_output if defined
|
||||
# Classes supporting global "output" option must call super().__init__()
|
||||
# after defining its own options to allow Optionable do the overwrite.
|
||||
global_from_cli = {}
|
||||
global_output = None
|
||||
global_dir = None
|
||||
global_variant = None
|
||||
global_units = None
|
||||
solved_global_variant = None
|
||||
global_kiauto_wait_start = None
|
||||
global_kiauto_time_out_scale = None
|
||||
global_opts_class = None
|
||||
global_3D_model_field = '_3D_model'
|
||||
global_date_time_format = None
|
||||
global_date_format = None
|
||||
global_pcb_finish = None
|
||||
global_pcb_material = None
|
||||
global_silk_screen_color = None
|
||||
global_silk_screen_color_bottom = None
|
||||
global_silk_screen_color_top = None
|
||||
global_solder_mask_color = None
|
||||
global_solder_mask_color_bottom = None
|
||||
global_solder_mask_color_top = None
|
||||
global_time_format = None
|
||||
global_time_reformat = None
|
||||
global_pcb_material = None
|
||||
global_solder_mask_color = None
|
||||
global_solder_mask_color_top = None
|
||||
global_solder_mask_color_bottom = None
|
||||
global_silk_screen_color = None
|
||||
global_silk_screen_color_top = None
|
||||
global_silk_screen_color_bottom = None
|
||||
global_pcb_finish = None
|
||||
global_copper_thickness = None
|
||||
global_edge_connector = None
|
||||
global_castellated_pads = None
|
||||
global_edge_plating = None
|
||||
global_impedance_controlled = None
|
||||
global_extra_pth_drill = None
|
||||
global_drill_size_increment = None
|
||||
test_boolean = True
|
||||
stackup = None
|
||||
global_units = None
|
||||
global_variant = None
|
||||
|
||||
@staticmethod
|
||||
def set_sch(name):
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class Optionable(object):
|
|||
super().__init__()
|
||||
for var in ['output', 'variant', 'units']:
|
||||
glb = getattr(GS, 'global_'+var)
|
||||
if glb is not None and hasattr(self, var):
|
||||
if glb and hasattr(self, var):
|
||||
setattr(self, var, glb)
|
||||
if GS.debug_level > 2:
|
||||
logger.debug('Using global `{}`=`{}`'.format(var, glb))
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ class Base3DOptions(VariantOptions):
|
|||
rem_models.append(rem_m_models)
|
||||
else:
|
||||
# Fitted
|
||||
new_model = c.get_field_value(GS.global_3D_model_field)
|
||||
new_model = c.get_field_value(GS.global_field_3D_model)
|
||||
if new_model:
|
||||
# We will change the 3D model
|
||||
self.replace_models(models, new_model, c)
|
||||
|
|
|
|||
Loading…
Reference in New Issue