Added pen_number and pen_speed HPGL options

This commit is contained in:
Salvador E. Tropea 2020-07-01 11:11:33 -03:00
parent be8339ddff
commit 3a1d5d0652
6 changed files with 75 additions and 10 deletions

View File

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

View File

@ -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 v<min or v>max:
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)

View File

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

View File

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

View File

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

View File

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