[Globals] Added options to control which stuff is changed on PCB variants

- cross_footprints_for_dnp
- remove_adhesive_for_dnp
- remove_solder_paste_for_dnp
- hide_excluded (default value)

Related to #270
This commit is contained in:
Salvador E. Tropea 2022-09-13 10:44:07 -03:00
parent 661677608e
commit 6f2c4ccf24
11 changed files with 92 additions and 49 deletions

View File

@ -11,8 +11,14 @@ 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)
- Global options:
- Support for changing text variables with variants during outputs creation.
Option `set_text_variables_before_output`. (See #233)
- Options to control which stuff is changed on PCB variants: (See #270)
- cross_footprints_for_dnp
- remove_adhesive_for_dnp
- remove_solder_paste_for_dnp
- hide_excluded (default value)
- Diff: mechanism to compare using a variant (See #278)
- Sch Variant:
- Option to copy the project. Needed for text variables.

View File

@ -644,6 +644,7 @@ global:
- *copper_finish*: Alias for pcb_finish.
- `copper_thickness`: [number|string] Copper thickness in micrometers (1 Oz is 35 micrometers).
KiCad 6: you should set this in the Board Setup -> Physical Stackup.
- `cross_footprints_for_dnp`: [boolean=true] Draw a cross for excluded components in the `Fab` layer.
- `cross_no_body`: [boolean=false] Cross components even when they don't have a body. Only for KiCad 6.
- `date_format`: [string='%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).
@ -688,6 +689,7 @@ global:
- `number`: [number=0] Error number we want to exclude. KiCad 5 only.
- `regex`: [string=''] Regular expression to match the text for the error we want to exclude.
- *regexp*: Alias for regex.
- `hide_excluded`: [boolean=false] Default value for the `hide_excluded` option of various PCB outputs.
- `impedance_controlled`: [boolean=false] The PCB needs specific dielectric characteristics.
KiCad 6: you should set this in the Board Setup -> Physical Stackup.
- `kiauto_time_out_scale`: [number=0.0] Time-out multiplier for KiAuto operations.
@ -700,6 +702,8 @@ global:
Immersion Ag, ImAu, Immersion Gold, Immersion Au, Immersion Tin, Immersion Nickel, OSP and HT_OSP.
- `pcb_material`: [string='FR4'] PCB core material. Currently used for documentation and to choose default colors.
Currently known are FR1 to FR5.
- `remove_adhesive_for_dnp`: [boolean=true] When applying filters and variants remove the adhesive (glue) for components that won't be included.
- `remove_solder_paste_for_dnp`: [boolean=true] When applying filters and variants remove the solder paste for components that won't be included.
- `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.
@ -2305,6 +2309,7 @@ Notes:
plot: uses KiCad Python API. Only available for KiCad 6.
You get the default frame and some substitutions doesn't work.
- `hide_excluded`: [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant.
Affected by global options.
- `keep_temporal_files`: [boolean=false] Store the temporal page and layer files in the output dir and don't delete them.
- `micro_via_color`: [string=''] Color used for micro `colored_vias`.
- `pad_color`: [string=''] Color used for `colored_pads`.
@ -2347,6 +2352,7 @@ Notes:
- `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.
- `hide_excluded`: [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant.
Affected by global options.
- `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.
@ -2530,6 +2536,7 @@ Notes:
KiCad 5 forces it by default, and you can't control it from config files.
Same for KiCad 6 when printing to separated pages.
- `hide_excluded`: [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant.
Affected by global options.
- `mirror`: [boolean=false] Print mirrored (X axis inverted). ONLY for KiCad 6.
- `monochrome`: [boolean=false] Print in black and white.
- `output`: [string='%f-%i%I%v.%x'] Filename for the output PDF (%i=layers, %x=pdf). Affected by global options.
@ -3021,6 +3028,7 @@ Notes:
KiCad 5 forces it by default, and you can't control it from config files.
Same for KiCad 6 when printing to separated pages.
- `hide_excluded`: [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant.
Affected by global options.
- `mirror`: [boolean=false] Print mirrored (X axis inverted). ONLY for KiCad 6.
- `monochrome`: [boolean=false] Print in black and white.
- `title`: [string=''] Text used to replace the sheet title. %VALUE expansions are allowed.

View File

@ -1160,7 +1160,8 @@ outputs:
# plot: uses KiCad Python API. Only available for KiCad 6.
# You get the default frame and some substitutions doesn't work
frame_plot_mechanism: 'internal'
# [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant
# [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant.
# Affected by global options
hide_excluded: false
# [boolean=false] Store the temporal page and layer files in the output dir and don't delete them
keep_temporal_files: false
@ -1257,7 +1258,8 @@ outputs:
# [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
dnf_filter: '_none'
# [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant
# [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant.
# Affected by global options
hide_excluded: false
# [string='%f-%i%I%v.%x'] Filename for the output (%i=variant, %x=kicad_pcb). Affected by global options
output: '%f-%i%I%v.%x'
@ -1408,7 +1410,8 @@ outputs:
# KiCad 5 forces it by default, and you can't control it from config files.
# Same for KiCad 6 when printing to separated pages
force_edge_cuts: true
# [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant
# [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant.
# Affected by global options
hide_excluded: false
# [boolean=false] Print mirrored (X axis inverted). ONLY for KiCad 6
mirror: false
@ -1867,7 +1870,8 @@ outputs:
# KiCad 5 forces it by default, and you can't control it from config files.
# Same for KiCad 6 when printing to separated pages
force_edge_cuts: true
# [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant
# [boolean=false] Hide components in the Fab layer that are marked as excluded by a variant.
# Affected by global options
hide_excluded: false
# [boolean=false] Print mirrored (X axis inverted). ONLY for KiCad 6
mirror: false

View File

@ -100,6 +100,8 @@ class Globals(FiltersOptions):
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.cross_footprints_for_dnp = True
""" Draw a cross for excluded components in the `Fab` layer """
self.cross_no_body = False
""" Cross components even when they don't have a body. Only for KiCad 6 """
self.date_format = '%Y-%m-%d'
@ -130,6 +132,8 @@ class Globals(FiltersOptions):
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.hide_excluded = False
""" Default value for the `hide_excluded` option of various PCB outputs """
self.kiauto_time_out_scale = 0.0
""" Time-out multiplier for KiAuto operations """
self.kiauto_wait_start = 0
@ -147,6 +151,10 @@ class Globals(FiltersOptions):
self.pcb_material = 'FR4'
""" PCB core material. Currently used for documentation and to choose default colors.
Currently known are FR1 to FR5 """
self.remove_solder_paste_for_dnp = True
""" When applying filters and variants remove the solder paste for components that won't be included """
self.remove_adhesive_for_dnp = True
""" When applying filters and variants remove the adhesive (glue) for components that won't be included """
self.restore_project = False
""" Restore the KiCad project after execution.
Note that this option will undo operations like `set_text_variables` """

View File

@ -99,6 +99,7 @@ class GS(object):
class_for_global_opts = None
global_castellated_pads = None
global_copper_thickness = None
global_cross_footprints_for_dnp = None
global_cross_no_body = None
global_date_format = None
global_date_time_format = None
@ -109,6 +110,7 @@ class GS(object):
global_edge_plating = None
global_extra_pth_drill = None
global_field_3D_model = None
global_hide_excluded = None
global_kiauto_time_out_scale = None
global_kiauto_wait_start = None
global_impedance_controlled = None
@ -118,6 +120,8 @@ class GS(object):
global_output = None
global_pcb_finish = None
global_pcb_material = None
global_remove_solder_paste_for_dnp = None
global_remove_adhesive_for_dnp = None
global_restore_project = None
global_set_text_variables_before_output = None
global_silk_screen_color = None

View File

@ -43,7 +43,7 @@ class Optionable(object):
self._expand_id = ''
self._expand_ext = ''
super().__init__()
for var in ['output', 'variant', 'units']:
for var in ['output', 'variant', 'units', 'hide_excluded']:
glb = getattr(GS, 'global_'+var)
if glb and hasattr(self, var):
setattr(self, var, glb)

View File

@ -34,7 +34,8 @@ class Any_PCB_PrintOptions(VariantOptions):
self.mirror = False
""" Print mirrored (X axis inverted). ONLY for KiCad 6 """
self.hide_excluded = False
""" Hide components in the Fab layer that are marked as excluded by a variant """
""" Hide components in the Fab layer that are marked as excluded by a variant.
Affected by global options """
self.title = ''
""" Text used to replace the sheet title. %VALUE expansions are allowed.
If it starts with `+` the text is concatenated """

View File

@ -252,7 +252,7 @@ class VariantOptions(BaseOptions):
def cross_modules(self, board, comps_hash):
""" Draw a cross in all 'not fitted' modules using *.Fab layer """
if comps_hash is None:
if comps_hash is None or not GS.global_cross_footprints_for_dnp:
return
# Cross the affected components
ffab = board.GetLayerID('F.Fab')
@ -289,7 +289,7 @@ class VariantOptions(BaseOptions):
def uncross_modules(self, board, comps_hash):
""" Undo the crosses in *.Fab layer """
if comps_hash is None:
if comps_hash is None or not GS.global_cross_footprints_for_dnp:
return
# Undo the drawings
for m in GS.get_modules_board(board):
@ -307,7 +307,7 @@ class VariantOptions(BaseOptions):
def remove_paste_and_glue(self, board, comps_hash):
""" Remove from solder paste layers the filtered components. """
if comps_hash is None:
if comps_hash is None or not (GS.global_remove_solder_paste_for_dnp or GS.global_remove_adhesive_for_dnp):
return
exclude = LSET()
fpaste = board.GetLayerID('F.Paste')
@ -327,28 +327,30 @@ class VariantOptions(BaseOptions):
c = comps_hash.get(ref, None)
if c and c.included and not c.fitted:
# Remove all pads from *.Paste
old_c_layers = []
for p in m.Pads():
pad_layers = p.GetLayerSet()
is_front = fpaste in pad_layers.Seq()
old_c_layers.append(pad_layers.FmtHex())
pad_layers.removeLayerSet(exclude)
if len(pad_layers.Seq()) == 0:
# No layers at all. Ridiculous, but happends.
# At least add an F.Mask
pad_layers.addLayer(fmask if is_front else bmask)
logger.warning(W_WRONGPASTE+'Pad with solder paste, but no copper or solder mask aperture in '+ref)
p.SetLayerSet(pad_layers)
old_layers.append(old_c_layers)
if GS.global_remove_solder_paste_for_dnp:
old_c_layers = []
for p in m.Pads():
pad_layers = p.GetLayerSet()
is_front = fpaste in pad_layers.Seq()
old_c_layers.append(pad_layers.FmtHex())
pad_layers.removeLayerSet(exclude)
if len(pad_layers.Seq()) == 0:
# No layers at all. Ridiculous, but happends.
# At least add an F.Mask
pad_layers.addLayer(fmask if is_front else bmask)
logger.warning(W_WRONGPASTE+'Pad with solder paste, but no copper or solder mask aperture in '+ref)
p.SetLayerSet(pad_layers)
old_layers.append(old_c_layers)
# Remove any graphical item in the *.Adhes layers
for gi in m.GraphicalItems():
l_gi = gi.GetLayer()
if l_gi == fadhes:
gi.SetLayer(rescue)
old_fadhes.append(gi)
if l_gi == badhes:
gi.SetLayer(rescue)
old_badhes.append(gi)
if GS.global_remove_adhesive_for_dnp:
for gi in m.GraphicalItems():
l_gi = gi.GetLayer()
if l_gi == fadhes:
gi.SetLayer(rescue)
old_fadhes.append(gi)
if l_gi == badhes:
gi.SetLayer(rescue)
old_badhes.append(gi)
# Store the data to undo the above actions
self.old_layers = old_layers
self.old_fadhes = old_fadhes
@ -360,20 +362,22 @@ class VariantOptions(BaseOptions):
def restore_paste_and_glue(self, board, comps_hash):
if comps_hash is None:
return
for m in GS.get_modules_board(board):
ref = m.GetReference()
c = comps_hash.get(ref, None)
if c and c.included and not c.fitted:
restore = self.old_layers.pop(0)
for p in m.Pads():
pad_layers = p.GetLayerSet()
res = restore.pop(0)
pad_layers.ParseHex(res, len(res))
p.SetLayerSet(pad_layers)
for gi in self.old_fadhes:
gi.SetLayer(self.fadhes)
for gi in self.old_badhes:
gi.SetLayer(self.badhes)
if GS.global_remove_solder_paste_for_dnp:
for m in GS.get_modules_board(board):
ref = m.GetReference()
c = comps_hash.get(ref, None)
if c and c.included and not c.fitted:
restore = self.old_layers.pop(0)
for p in m.Pads():
pad_layers = p.GetLayerSet()
res = restore.pop(0)
pad_layers.ParseHex(res, len(res))
p.SetLayerSet(pad_layers)
if GS.global_remove_adhesive_for_dnp:
for gi in self.old_fadhes:
gi.SetLayer(self.fadhes)
for gi in self.old_badhes:
gi.SetLayer(self.badhes)
def remove_fab(self, board, comps_hash):
""" Remove from Fab the excluded components. """

View File

@ -229,7 +229,8 @@ class PCB_PrintOptions(VariantOptions):
""" When enabled the %i is always `assembly`, the %x will be NN.FORMAT (i.e. 01.png).
Note: page numbers can be customized using the `page_id` option for each page """
self.hide_excluded = False
""" Hide components in the Fab layer that are marked as excluded by a variant """
""" Hide components in the Fab layer that are marked as excluded by a variant.
Affected by global options """
self.color_theme = '_builtin_classic'
""" *Selects the color theme. Only applies to KiCad 6.
To use the KiCad 6 default colors select `_builtin_default`.

View File

@ -15,7 +15,8 @@ class PCB_Variant_Options(VariantOptions):
def __init__(self):
with document:
self.hide_excluded = False
""" Hide components in the Fab layer that are marked as excluded by a variant """
""" Hide components in the Fab layer that are marked as excluded by a variant.
Affected by global options """
self.output = GS.def_global_output
""" *Filename for the output (%i=variant, %x=kicad_pcb) """
self.copy_project = True

View File

@ -2,6 +2,12 @@
kibot:
version: 1
global:
# remove_solder_paste_for_dnp: false
# remove_adhesive_for_dnp: false
# cross_footprints_for_dnp: false
hide_excluded: true
variants:
- name: 'production'
comment: 'Production variant'
@ -45,7 +51,7 @@ outputs:
- name: 'diff_pcb'
comment: "PCB difference with variant"
type: diff
layers: ['F.Cu', 'F.Fab']
layers: ['F.Cu', 'F.Fab', 'F.Adhes', 'F.Paste']
options:
# old: pcb_default
# old_type: output