Added support for changing text variables with variants

- During outputs creation.
- Option `set_text_variables_before_output`.

Related to #233
This commit is contained in:
Salvador E. Tropea 2022-09-12 13:35:40 -03:00
parent 9a70f2e141
commit 1f1a56e5ac
9 changed files with 165 additions and 15 deletions

View File

@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- File_Copy: used to copy files to the output directory. (#279)
- Support for Eurocircuits drill adjust to fix small OARs.
Option `eurocircuits_reduce_holes`. (#227)
- Support for changing text variables with variants during outputs creation.
Option `set_text_variables_before_output`. (See #233)
- Diff: mechanism to compare using a variant (See #278)
- Sch Variant:
- Option to copy the project. Needed for text variables.

View File

@ -702,6 +702,10 @@ global:
Currently known are FR1 to FR5.
- `restore_project`: [boolean=false] Restore the KiCad project after execution.
Note that this option will undo operations like `set_text_variables`.
- `set_text_variables_before_output`: [boolean=false] Run the `set_text_variables` preflight before running each output that involves variants.
This can be used when a text variable uses the variant and you want to create more than
one variant in the same run. Note that this could be slow because it forces a board
reload each time you run an output that uses variants.
- `silk_screen_color`: [string='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.
Currently known are black and white.
@ -1634,7 +1638,10 @@ Notes:
- **`name`**: [string=''] Used to identify this particular output definition.
- **`options`**: [dict] Options for the `dxf` output.
* Valid keys:
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
For this reason you must avoid generating two variants at the same directory when one of
them uses the default KiCad name. Affected by global options.
- **`plot_sheet_reference`**: [boolean=false] Include the frame and title block. Only available for KiCad 6 and you get a poor result
The `pcb_print` output can do a better job for PDF, SVG, PS, EPS and PNG outputs.
- `custom_reports`: [list(dict)] A list of customized reports for the manufacturer.
@ -1801,7 +1808,10 @@ Notes:
* Valid keys:
- **`create_gerber_job_file`**: [boolean=true] Creates a file with information about all the generated gerbers.
You can use it in gerbview to load all gerbers at once.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
For this reason you must avoid generating two variants at the same directory when one of
them uses the default KiCad name. Affected by global options.
- **`plot_sheet_reference`**: [boolean=false] Include the frame and title block. Only available for KiCad 6 and you get a poor result
The `pcb_print` output can do a better job for PDF, SVG, PS, EPS and PNG outputs.
- **`subtract_mask_from_silk`**: [boolean=false] Subtract the solder mask from the silk screen.
@ -1860,7 +1870,10 @@ Notes:
- **`name`**: [string=''] Used to identify this particular output definition.
- **`options`**: [dict] Options for the `hpgl` output.
* Valid keys:
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
For this reason you must avoid generating two variants at the same directory when one of
them uses the default KiCad name. Affected by global options.
- **`plot_sheet_reference`**: [boolean=false] Include the frame and title block. Only available for KiCad 6 and you get a poor result
The `pcb_print` output can do a better job for PDF, SVG, PS, EPS and PNG outputs.
- `custom_reports`: [list(dict)] A list of customized reports for the manufacturer.
@ -2413,7 +2426,10 @@ Notes:
- **`name`**: [string=''] Used to identify this particular output definition.
- **`options`**: [dict] Options for the `pdf` output.
* Valid keys:
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
For this reason you must avoid generating two variants at the same directory when one of
them uses the default KiCad name. Affected by global options.
- **`plot_sheet_reference`**: [boolean=false] Include the frame and title block. Only available for KiCad 6 and you get a poor result
The `pcb_print` output can do a better job for PDF, SVG, PS, EPS and PNG outputs.
- `custom_reports`: [list(dict)] A list of customized reports for the manufacturer.
@ -2439,7 +2455,10 @@ Notes:
- `tent_vias`: [boolean=true] Cover the vias.
- `uppercase_extensions`: [boolean=false] Use uppercase names for the extensions.
- `variant`: [string=''] Board variant to apply.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
For this reason you must avoid generating two variants at the same directory when one of
them uses the default KiCad name. Affected by global options.
- **`plot_sheet_reference`**: [boolean=false] Include the frame and title block. Only available for KiCad 6 and you get a poor result
The `pcb_print` output can do a better job for PDF, SVG, PS, EPS and PNG outputs.
- `category`: [string|list(string)=''] The category for this output. If not specified an internally defined category is used.
@ -2643,7 +2662,10 @@ Notes:
- **`name`**: [string=''] Used to identify this particular output definition.
- **`options`**: [dict] Options for the `ps` output.
* Valid keys:
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
For this reason you must avoid generating two variants at the same directory when one of
them uses the default KiCad name. Affected by global options.
- **`plot_sheet_reference`**: [boolean=false] Include the frame and title block. Only available for KiCad 6 and you get a poor result
The `pcb_print` output can do a better job for PDF, SVG, PS, EPS and PNG outputs.
- **`scaling`**: [number=1] Scale factor (0 means autoscaling).
@ -2918,7 +2940,10 @@ Notes:
- **`name`**: [string=''] Used to identify this particular output definition.
- **`options`**: [dict] Options for the `svg` output.
* Valid keys:
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options.
- **`output`**: [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
For this reason you must avoid generating two variants at the same directory when one of
them uses the default KiCad name. Affected by global options.
- **`plot_sheet_reference`**: [boolean=false] Include the frame and title block. Only available for KiCad 6 and you get a poor result
The `pcb_print` output can do a better job for PDF, SVG, PS, EPS and PNG outputs.
- `custom_reports`: [list(dict)] A list of customized reports for the manufacturer.

View File

@ -550,7 +550,10 @@ outputs:
inner_extension_pattern: ''
# [boolean=false] Use mm instead of inches
metric_units: false
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
# IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
# For this reason you must avoid generating two variants at the same directory when one of
# them uses the default KiCad name. Affected by global options
output: '%f-%i%I%v.%x'
# [boolean=true] Include the footprint references
plot_footprint_refs: true
@ -705,7 +708,10 @@ outputs:
inner_extension_pattern: ''
# [number=0.1] [0.02,2] Line_width for objects without width [mm] (KiCad 5)
line_width: 0.1
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
# IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
# For this reason you must avoid generating two variants at the same directory when one of
# them uses the default KiCad name. Affected by global options
output: '%f-%i%I%v.%x'
# [boolean=true] Include the footprint references
plot_footprint_refs: true
@ -764,7 +770,10 @@ outputs:
inner_extension_pattern: ''
# [boolean=false] Plot mirrored
mirror_plot: false
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
# IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
# For this reason you must avoid generating two variants at the same directory when one of
# them uses the default KiCad name. Affected by global options
output: '%f-%i%I%v.%x'
# [number=1] [1,16] Pen number
pen_number: 1
@ -1351,7 +1360,10 @@ outputs:
mirror_plot: false
# [boolean=false] Invert black and white
negative_plot: false
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
# IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
# For this reason you must avoid generating two variants at the same directory when one of
# them uses the default KiCad name. Affected by global options
output: '%f-%i%I%v.%x'
# [boolean=true] Include the footprint references
plot_footprint_refs: true
@ -1531,7 +1543,10 @@ outputs:
mirror_plot: false
# [boolean=false] Invert black and white
negative_plot: false
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
# IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
# For this reason you must avoid generating two variants at the same directory when one of
# them uses the default KiCad name. Affected by global options
output: '%f-%i%I%v.%x'
# [boolean=true] Include the footprint references
plot_footprint_refs: true
@ -1801,7 +1816,10 @@ outputs:
mirror_plot: false
# [boolean=false] Invert black and white
negative_plot: false
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty. Affected by global options
# [string='%f-%i%I%v.%x'] Output file name, the default KiCad name if empty.
# IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
# For this reason you must avoid generating two variants at the same directory when one of
# them uses the default KiCad name. Affected by global options
output: '%f-%i%I%v.%x'
# [boolean=true] Include the footprint references
plot_footprint_refs: true

View File

@ -150,6 +150,11 @@ class Globals(FiltersOptions):
self.restore_project = False
""" Restore the KiCad project after execution.
Note that this option will undo operations like `set_text_variables` """
self.set_text_variables_before_output = False
""" Run the `set_text_variables` preflight before running each output that involves variants.
This can be used when a text variable uses the variant and you want to create more than
one variant in the same run. Note that this could be slow because it forces a board
reload each time you run an output that uses variants """
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.

View File

@ -119,6 +119,7 @@ class GS(object):
global_pcb_finish = None
global_pcb_material = None
global_restore_project = None
global_set_text_variables_before_output = None
global_silk_screen_color = None
global_silk_screen_color_bottom = None
global_silk_screen_color_top = None

View File

@ -375,6 +375,12 @@ def config_output(out, dry=False, dont_stop=False):
def run_output(out, dont_stop=False):
if out._done:
return
if GS.global_set_text_variables_before_output and hasattr(out.options, 'variant'):
pre = BasePreFlight.get_preflight('set_text_variables')
if pre:
pre._variant = out.options.variant
pre.apply()
load_board()
GS.current_output = out.name
try:
out.run(get_output_dir(out.dir, out))

View File

@ -58,7 +58,10 @@ class AnyLayerOptions(VariantOptions):
self.force_plot_invisible_refs_vals = False
""" Include references and values even when they are marked as invisible """
self.output = GS.def_global_output
""" *Output file name, the default KiCad name if empty """
""" *Output file name, the default KiCad name if empty.
IMPORTANT! KiCad will always create the file using its own name and then we can rename it.
For this reason you must avoid generating two variants at the same directory when one of
them uses the default KiCad name """
self.tent_vias = True
""" Cover the vias """
self.uppercase_extensions = False
@ -152,7 +155,7 @@ class AnyLayerOptions(VariantOptions):
logger.debug("Plotting layer `{}` to `{}`".format(la, filename))
plot_ctrl.PlotLayer()
plot_ctrl.ClosePlot()
if self.output:
if self.output and k_filename != filename:
os.rename(k_filename, filename)
if create_job:
jobfile_writer.AddGbrFile(id, os.path.basename(filename))

View File

@ -139,10 +139,14 @@ class BasePreFlight(Registrable):
def _find_variant(self):
# Preflights doesn't have a variant, but we could have one global default
if hasattr(self, '_variant') and self._variant:
return self._variant.file_id
return Optionable._find_global_variant()
def _find_variant_name(self):
# Preflights doesn't have a variant, but we could have one global default
if hasattr(self, '_variant') and self._variant:
return self._variant.name
return Optionable._find_global_variant_name()
def ensure_tool(self, name):

View File

@ -0,0 +1,86 @@
# Example KiBot config file
kibot:
version: 1
global:
set_text_variables_before_output: true
variants:
- name: 'production'
comment: 'Production variant'
type: ibom
file_id: '_(production)'
variants_blacklist: T2
- name: 'test'
comment: 'Test variant'
type: ibom
file_id: '_(test)'
variants_blacklist: T1
- name: 'default'
comment: 'Default variant'
type: ibom
variants_blacklist: T2,T3
preflight:
set_text_variables:
- name: VARIANT
text: '%V'
outputs:
- name: 'pcb_default'
comment: "PCB w/default variant"
type: pcb_variant
options:
variant: default
title: 'Hello %V'
- name: 'pcb_production'
comment: "PCB w/production variant"
type: pcb_variant
options:
variant: production
title: 'Hello %V'
- name: 'gerber_production'
comment: "Gerber w/production variant"
type: gerber
layers: ['F.Cu']
options:
variant: production
- name: 'pcb_test'
comment: "PCB w/test variant"
type: pcb_variant
options:
variant: test
title: 'Hello %V'
- name: 'gerber_test'
comment: "Gerber w/test variant"
type: gerber
layers: ['F.Cu']
options:
variant: test
- name: 'gerber_default'
comment: "Gerber w/default variant"
type: gerber
layers: ['F.Cu']
options:
variant: default
- name: 'diff_pcb'
comment: "PCB difference with variant"
type: diff
layers: ['F.Cu', 'F.Fab']
options:
# old: pcb_default
# old_type: output
old: ''
old_type: multivar
new: [pcb_default, pcb_production, pcb_test]
new_type: multivar
cache_dir: .cache
# add_link_id: true