Added `output_id` output option to be expanded by %I

This commit is contained in:
Diego Capusotto 2021-12-14 16:19:49 -03:00
parent 3de2c8de2a
commit e2599731f7
9 changed files with 38 additions and 13 deletions

View File

@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **%sc**, **%sC1**, **%sC2**, **%sC3**, **%sC4**, **%sd**, **%sf**,
**%sF**, **%sp** and **%sr** schematic data
- **%V** the variant name
- **%I** user defined ID for this output
- Now patterns are also expanded in the out_dir name.
- Global options to control the date format.
- Outputs can use the options of other outputs as base (extend them). (#112)

View File

@ -262,6 +262,7 @@ The pattern uses the following expansions:
- **%g** the `file_id` of the global variant.
- **%G** the `name` of the global variant.
- **%i** a contextual ID, depends on the output type.
- **%I** an ID defined by the user for this output.
- **%p** pcb/sch title from pcb metadata.
- **%r** revision from pcb/sch metadata.
- **%T** time the script was started.
@ -725,6 +726,7 @@ Next time you need this list just use an alias, like this:
- `options`: [dict] Options for the `boardview` output.
* Valid keys:
- `output`: [string='%f-%i%v.%x'] Filename for the output (%i=boardview, %x=brd). Affected by global options.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* BoM (Bill of Materials)
@ -859,6 +861,7 @@ Next time you need this list just use an alias, like this:
- `max_col_width`: [number=60] [20,999] Maximum column width (characters).
- `style`: [string='modern-blue'] Head style: modern-blue, modern-green, modern-red and classic.
- `title`: [string='KiBot Bill of Materials'] BoM title.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* Archiver (files compressor)
@ -887,6 +890,7 @@ Next time you need this list just use an alias, like this:
See the `from_cwd` option.
- `format`: [string='ZIP'] [ZIP,TAR,RAR] Output file format.
- `output`: [string='%f-%i%v.%x'] Name for the generated archive (%i=name of the output %x=according to format). Affected by global options.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* DXF (Drawing Exchange Format)
@ -934,6 +938,7 @@ Next time you need this list just use an alias, like this:
- `uppercase_extensions`: [boolean=false] Use uppercase names for the extensions.
- `use_aux_axis_as_origin`: [boolean=false] Use the auxiliary axis as origin for coordinates.
- `variant`: [string=''] Board variant to apply.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* Excellon drill format
@ -971,6 +976,7 @@ Next time you need this list just use an alias, like this:
- `route_mode_for_oval_holes`: Undocumented.
- `use_aux_axis_as_origin`: [boolean=false] Use the auxiliary axis as origin for coordinates.
- `zeros_format`: [string='DECIMAL_FORMAT'] [DECIMAL_FORMAT,SUPPRESS_LEADING,SUPPRESS_TRAILING,KEEP_ZEROS] How to handle the zeros.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* Gerber drill format
@ -1000,6 +1006,7 @@ Next time you need this list just use an alias, like this:
- `filename`: [string=''] Name of the drill report. Not generated unless a name is specified.
(%i='drill_report' %x='txt').
- `use_aux_axis_as_origin`: [boolean=false] Use the auxiliary axis as origin for coordinates.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* Gerber format
@ -1053,6 +1060,7 @@ Next time you need this list just use an alias, like this:
- `use_gerber_x2_attributes`: [boolean=true] Use the extended X2 format (otherwise use X1 formerly RS-274X).
- `use_protel_extensions`: [boolean=false] Use legacy Protel file extensions.
- `variant`: [string=''] Board variant to apply.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* HPGL (Hewlett & Packard Graphics Language)
@ -1102,6 +1110,7 @@ Next time you need this list just use an alias, like this:
- `tent_vias`: [boolean=true] Cover the vias.
- `uppercase_extensions`: [boolean=false] Use uppercase names for the extensions.
- `variant`: [string=''] Board variant to apply.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* IBoM (Interactive HTML BoM)
@ -1166,6 +1175,7 @@ Next time you need this list just use an alias, like this:
IBoM option, avoid using in conjunction with KiBot variants/filters.
- `variants_whitelist`: [string=''] List of board variants to include in the BOM.
IBoM option, avoid using in conjunction with KiBot variants/filters.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* KiBoM (KiCad Bill of Materials)
@ -1263,6 +1273,7 @@ Next time you need this list just use an alias, like this:
with a BOM file exported for each variant, separate
variants with the ';' (semicolon) character.
This isn't related to the KiBot concept of variants.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* KiCost (KiCad Cost calculator)
@ -1304,6 +1315,7 @@ Next time you need this list just use an alias, like this:
- `name`: [string=''] New name.
- `variant`: [string=''] Board variant to apply.
Internal variants and filters are currently ignored.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* PcbDraw - Beautiful 2D PCB render
@ -1349,6 +1361,7 @@ Next time you need this list just use an alias, like this:
- `variant`: [string=''] Board variant to apply.
- `vcuts`: [boolean=false] Render V-CUTS on the Cmts.User layer.
- `warnings`: [string='visible'] [visible,all,none] Using visible only the warnings about components in the visible side are generated.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* PDF (Portable Document Format)
@ -1412,6 +1425,7 @@ Next time you need this list just use an alias, like this:
- `uppercase_extensions`: [boolean=false] Use uppercase names for the extensions.
- `variant`: [string=''] Board variant to apply.
- `output`: [string='%f-%i%v.%x'] Output file name, the default KiCad name if empty. Affected by global options.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `plot_footprint_refs`: [boolean=true] Include the footprint references.
- `plot_footprint_values`: [boolean=true] Include the footprint values.
- `plot_sheet_reference`: [boolean=false] Currently without effect.
@ -1454,6 +1468,7 @@ Next time you need this list just use an alias, like this:
- `title`: [string=''] Text used to replace the sheet title. %VALUE expansions are allowed.
If it starts with `+` the text is concatenated.
- `variant`: [string=''] Board variant to apply.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* PDF Schematic Print (Portable Document Format)
@ -1477,6 +1492,7 @@ Next time you need this list just use an alias, like this:
- `output`: [string='%f-%i%v.%x'] Filename for the output PDF (%i=schematic %x=pdf). Affected by global options.
- `variant`: [string=''] Board variant to apply.
Not fitted components are crossed.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* Pick & place
@ -1506,6 +1522,7 @@ Next time you need this list just use an alias, like this:
- `units`: [string='millimeters'] [millimeters,inches] Units used for the positions.
- `use_aux_axis_as_origin`: [boolean=true] Use the auxiliary axis as origin for coordinates (KiCad default).
- `variant`: [string=''] Board variant to apply.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* PS (Postscript)
@ -1559,6 +1576,7 @@ Next time you need this list just use an alias, like this:
- `variant`: [string=''] Board variant to apply.
- `width_adjust`: [number=0] This width factor is intended to compensate PS printers/plotters that do not strictly obey line width settings.
Only used to plot pads and tracks.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* 3D render of the PCB
@ -1581,7 +1599,6 @@ Next time you need this list just use an alias, like this:
A short-cut to use for simple cases where a variant is an overkill.
- `download`: [boolean=true] Downloads missing 3D models from KiCad git. Only applies to models in KISYS3DMOD.
- `height`: [number=720] Image height (aprox.).
- `id_add`: [string=''] Text to add to the %i expansion content. To differentiate variations of this output.
- `kicad_3d_url`: [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models.
- `move_x`: [number=0] Steps to move in the X axis, positive is to the right.
Just like pressing the right arrow in the 3D viewer.
@ -1605,6 +1622,7 @@ Next time you need this list just use an alias, like this:
- `width`: [number=1280] Image width (aprox.).
- `zoom`: [number=0] Zoom steps. Use positive to enlarge, get closer, and negative to reduce.
Same result as using the mouse wheel in the 3D viewer.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* Schematic with variant generator
@ -1624,6 +1642,7 @@ Next time you need this list just use an alias, like this:
- `dnf_filter`: [string|list(string)='_none'] Name of the filter to mark components as not fitted.
A short-cut to use for simple cases where a variant is an overkill.
- `variant`: [string=''] Board variant to apply.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* STEP (ISO 10303-21 Clear Text Encoding of the Exchange Structure)
@ -1652,6 +1671,7 @@ Next time you need this list just use an alias, like this:
You can define any other origin using the format 'X,Y', i.e. '3.2,-10'.
- `output`: [string='%f-%i%v.%x'] Name for the generated STEP file (%i='3D' %x='step'). Affected by global options.
- `variant`: [string=''] Board variant to apply.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* SVG (Scalable Vector Graphics)
@ -1699,6 +1719,7 @@ Next time you need this list just use an alias, like this:
- `tent_vias`: [boolean=true] Cover the vias.
- `uppercase_extensions`: [boolean=false] Use uppercase names for the extensions.
- `variant`: [string=''] Board variant to apply.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.
* SVG Schematic Print
@ -1719,6 +1740,7 @@ Next time you need this list just use an alias, like this:
- `output`: [string='%f-%i%v.%x'] Filename for the output SVG (%i=schematic %x=svg). Affected by global options.
- `variant`: [string=''] Board variant to apply.
Not fitted components are crossed.
- `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output.
- `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested.

View File

@ -204,6 +204,7 @@ The pattern uses the following expansions:
- **%g** the `file_id` of the global variant.
- **%G** the `name` of the global variant.
- **%i** a contextual ID, depends on the output type.
- **%I** an ID defined by the user for this output.
- **%p** pcb/sch title from pcb metadata.
- **%r** revision from pcb/sch metadata.
- **%T** time the script was started.

View File

@ -1087,8 +1087,6 @@ outputs:
download: true
# [number=720] Image height (aprox.)
height: 720
# [string=''] Text to add to the %i expansion content. To differentiate variations of this output
id_add: ''
# [string='https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'] Base URL for the KiCad 3D models
kicad_3d_url: 'https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'
# [number=0] Steps to move in the X axis, positive is to the right.

View File

@ -208,7 +208,7 @@ class Optionable(object):
return GS.solved_global_variant.name
return ''
def expand_filename_common(self, name):
def expand_filename_common(self, name, parent):
""" Expansions common to the PCB and Schematic """
# PCB expansions, explicit
if GS.board and '%b' in name:
@ -244,15 +244,17 @@ class Optionable(object):
name = name.replace('%v', self._find_variant())
name = name.replace('%V', self._find_variant_name())
name = name.replace('%x', self._expand_ext)
if parent and hasattr(parent, 'output_id'):
name = name.replace('%I', parent.output_id)
return name
def expand_filename_both(self, name, is_sch=True):
""" Expands %* values in filenames.
Uses data from the PCB. """
parent = None
if self and hasattr(self, '_parent'):
parent = self._parent
if GS.debug_level > 3:
parent = None
if self and hasattr(self, '_parent'):
parent = self._parent
logger.debug('Expanding `{}` in PCB context for {} parent: {}'.format(name, self, parent))
# Determine if we need to expand SCH and/or PCB related data
has_dep_exp = any(map(lambda x: x in name, ['%c', '%d', '%F', '%f', '%p', '%r', '%C1', '%C2', '%C3', '%C4']))
@ -270,7 +272,7 @@ class Optionable(object):
GS.load_sch()
GS.load_sch_title_block()
# This member can be called with a preflight object
name = Optionable.expand_filename_common(self, name)
name = Optionable.expand_filename_common(self, name, parent)
if GS.board and do_pcb:
name = name.replace('%c', GS.pcb_comp)
name = name.replace('%d', GS.pcb_date)

View File

@ -42,6 +42,8 @@ class BaseOutput(RegOutput):
self.disable_run_by_default = ''
""" Use it to disable the `run_by_default` status of other output.
Useful when this output extends another and you don't want to generate the original. """
self.output_id = ''
""" Text to use for the %I expansion content. To differentiate variations of this output """
if GS.global_dir:
self.dir = GS.global_dir
self._sch_related = False

View File

@ -73,8 +73,6 @@ class Render3DOptions(Base3DOptions):
""" Image height (aprox.) """
self.orthographic = False
""" Enable the orthographic projection mode (top view looks flat) """
self.id_add = ''
""" Text to add to the %i expansion content. To differentiate variations of this output """
super().__init__()
self._expand_ext = 'png'
@ -84,7 +82,7 @@ class Render3DOptions(Base3DOptions):
view = self._views.get(self.view, None)
if view is not None:
self.view = view
self._expand_id += '_'+self._rviews.get(self.view)+self.id_add
self._expand_id += '_'+self._rviews.get(self.view)
def run(self, output):
super().run(output)

View File

@ -853,7 +853,7 @@ def test_disable_default_1(test_dir):
prj = 'test_v5'
ctx = context.TestContext(test_dir, 'test_disable_default_1', prj, 'disable_default_1', '')
ctx.run(extra=[])
ctx.expect_out_file(POS_DIR+'/test_v5_(both_pos).csv')
ctx.expect_out_file(POS_DIR+'/test_v5_(both_pos_test).csv')
ctx.dont_expect_out_file(POS_DIR+'/test_v5_(bottom_pos).csv')
ctx.clean_up()

View File

@ -2,7 +2,7 @@ kibot:
version: 1
global:
output: '%f_(%i).%x'
output: '%f_(%i%I).%x'
outputs:
- name: 'position_mine'
@ -11,6 +11,7 @@ outputs:
dir: positiondir
extends: position
disable_run_by_default: position
output_id: '_test'
options:
separate_files_for_front_and_back: false