From 3a1d5d06527ea10d915a2cd15adaaa7cab31534f Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 1 Jul 2020 11:11:33 -0300 Subject: [PATCH] Added pen_number and pen_speed HPGL options --- CHANGELOG.md | 3 ++ kiplot/out_base.py | 31 ++++++++++++++----- kiplot/out_hpgl.py | 10 ++++-- tests/test_plot/test_yaml_errors.py | 8 +++++ .../error_hpgl_pen_num.kiplot.yaml | 31 +++++++++++++++++++ tests/yaml_samples/hpgl.kiplot.yaml | 2 ++ 6 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 tests/yaml_samples/error_hpgl_pen_num.kiplot.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index dce518df..ca3e6f47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --help-output) - Help for the supported preflights (--help-preflights) - Better YAML validation. +- Added HPGL options: + - pen_number + - pen_speed - Added the following InteractiveHtmlBom options: - dark_mode - hide_pads diff --git a/kiplot/out_base.py b/kiplot/out_base.py index efa7f2a7..ea858c40 100644 --- a/kiplot/out_base.py +++ b/kiplot/out_base.py @@ -1,4 +1,5 @@ import inspect +from re import (compile, match) from .error import KiPlotConfigurationError from . import log @@ -21,6 +22,7 @@ class BaseOutput(object): def _perform_config_mapping(self): """ Map the options to class attributes """ attrs = BaseOutput.get_attrs_for(self) + num_range_re = compile(r"\[number=.*\] \[(-?\d+),(-?\d+)\]") for k, v in self._options.items(): # Map known attributes and avoid mapping private ones if (k[0] == '_') or (k not in attrs): @@ -28,14 +30,27 @@ class BaseOutput(object): logger.warning("Unknown option `{}`".format(k)) continue # Check the data type - cur_val = self.__getattribute__(k) - if isinstance(cur_val, bool) and not isinstance(v, bool): - raise KiPlotConfigurationError("Option `{}` must be true/false".format(k)) - if isinstance(cur_val, (int, float)) and not isinstance(v, (int, float)): - raise KiPlotConfigurationError("Option `{}` must be a number".format(k)) - if isinstance(cur_val, str) and not isinstance(v, str): - raise KiPlotConfigurationError("Option `{}` must be a string".format(k)) - if isinstance(v, list): + cur_val = getattr(self, k) + cur_doc = getattr(self, '_help_'+k).lstrip() + if isinstance(cur_val, bool): + if not isinstance(v, bool): + raise KiPlotConfigurationError("Option `{}` must be true/false".format(k)) + elif isinstance(cur_val, (int, float)): + # Note: booleans are also instance of int + if not isinstance(v, (int, float)): + raise KiPlotConfigurationError("Option `{}` must be a number".format(k)) + # If the docstring specifies a range in the form [from-to] enforce it + m = num_range_re.match(cur_doc) + if m: + logger.debug('Verificando') + min = float(m.group(1)) + max = float(m.group(2)) + if vmax: + raise KiPlotConfigurationError("Option `{}` outside its range [{},{}]".format(k, min, max)) + elif isinstance(cur_val, str): + if not isinstance(v, str): + raise KiPlotConfigurationError("Option `{}` must be a string".format(k)) + elif isinstance(v, list): raise KiPlotConfigurationError("list not yet supported for `{}`".format(k)) # Seems to be ok, map it setattr(self, k, v) diff --git a/kiplot/out_hpgl.py b/kiplot/out_hpgl.py index d525f7ee..007bc406 100644 --- a/kiplot/out_hpgl.py +++ b/kiplot/out_hpgl.py @@ -21,8 +21,12 @@ class HPGL(AnyLayer, DrillMarks): """ don't fill objects, just draw the outline """ self.scaling = 0 """ scale factor (0 means autoscaling) """ - self.pen_width = 0.5 - """ pen diameter in MILS, useful to fill areas. However, it is in mm in HPGL files """ # pragma: no cover + self.pen_number = 1 + """ [1,16] pen number """ + self.pen_speed = 20 + """ [1,99] pen speed """ + self.pen_width = 15 + """ [0,100] pen diameter in MILS, useful to fill areas. However, it is in mm in HPGL files """ # pragma: no cover def config(self, outdir, options, layers): AnyLayer.config(self, outdir, options, layers) @@ -31,3 +35,5 @@ class HPGL(AnyLayer, DrillMarks): def _configure_plot_ctrl(self, po, output_dir): super()._configure_plot_ctrl(po, output_dir) po.SetHPGLPenDiameter(self.pen_width) + po.SetHPGLPenNum(self.pen_number) + po.SetHPGLPenSpeed(self.pen_speed) diff --git a/tests/test_plot/test_yaml_errors.py b/tests/test_plot/test_yaml_errors.py index c7be3266..53d5c18e 100644 --- a/tests/test_plot/test_yaml_errors.py +++ b/tests/test_plot/test_yaml_errors.py @@ -36,6 +36,7 @@ Tests various errors in the config file - Wrong type for entry (run_drc) - YAML syntax - Unknown section +- HPGL wrong pen_number For debug information use: pytest-3 --log-cli-level debug @@ -320,3 +321,10 @@ def test_unk_section(): ctx.run(EXIT_BAD_CONFIG) assert ctx.search_err("Unknown section .?bogus.? in config") ctx.clean_up() + + +def test_error_hpgl_pen_num(): + ctx = context.TestContext('HPGLPenNum', PRJ, 'error_hpgl_pen_num', '') + ctx.run(EXIT_BAD_CONFIG) + assert ctx.search_err("Option .?pen_number.? outside its range") + ctx.clean_up() diff --git a/tests/yaml_samples/error_hpgl_pen_num.kiplot.yaml b/tests/yaml_samples/error_hpgl_pen_num.kiplot.yaml new file mode 100644 index 00000000..b3c489f9 --- /dev/null +++ b/tests/yaml_samples/error_hpgl_pen_num.kiplot.yaml @@ -0,0 +1,31 @@ +kiplot: + version: 1 + +outputs: + - name: HPGL + comment: "HPGL files" + type: hpgl + dir: HPGL + options: + exclude_edge_layer: false + exclude_pads_from_silkscreen: false + plot_sheet_reference: false + plot_footprint_refs: true + plot_footprint_values: true + force_plot_invisible_refs_vals: false + tent_vias: true + + # HPGL options + drill_marks: full + mirror_plot: true + sketch_plot: false + scaling: 0 # auto + pen_number: 17 + pen_speed: 50 + pen_width: 0.5 + layers: + - layer: F.Cu + suffix: F_Cu + - layer: B.SilkS + suffix: B_Silks + diff --git a/tests/yaml_samples/hpgl.kiplot.yaml b/tests/yaml_samples/hpgl.kiplot.yaml index 48b13cc4..13087bcd 100644 --- a/tests/yaml_samples/hpgl.kiplot.yaml +++ b/tests/yaml_samples/hpgl.kiplot.yaml @@ -20,6 +20,8 @@ outputs: mirror_plot: true sketch_plot: false scaling: 0 # auto + pen_number: 2 + pen_speed: 50 pen_width: 0.5 layers: - layer: F.Cu