[KiCad 7] Added some support for DNP flag

- Copied to internal `fitted`
- Can remove 3D models even when no filter/variant is applied
This commit is contained in:
Salvador E. Tropea 2023-03-08 13:13:37 -03:00
parent 143bcd5f63
commit 6801dfc7e2
7 changed files with 48 additions and 13 deletions

View File

@ -7,12 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.6.1] - UNRELEASED
### Added
- Global options:
- `allow_blind_buried_vias` and `allow_microvias` for KiCad 7 (no longer in KiCad)
- `allow_blind_buried_vias` and `allow_microvias` for KiCad 7 (no longer in
KiCad)
- `erc_grid` to specify the grid size for KiCad 7 ERC tests
- Report:
- Counters for total vias and by via type (`vias_count`, `thru_vias_count`,
`blind_vias_count` and `micro_vias_count`)
- Warnings when micro and/or blind vias aren't allowed, but we found them.
- KiCad 7 specific:
- Avoid warnings about missing coutyard for footprints marked as excluded
from courtyard tests.
- `kicad_dnp_applied` global option to use the *Do Not Populate* schematic
flag as *do not fit* for KiBot, enabled by default.
- `kicad_dnp_applies_to_3D` global option to eliminate the 3D models of
components marked as *Do Not Populate*. This option applies to the case
where no filter or variants are in use. Enabled by default. The
`kicad_dnp_applied` option also disables it.
### Fixed
- Problems to detect the schematic name when the path to the config contained a

View File

@ -184,7 +184,8 @@ def reset_filters(comps):
logger.debug('Filters reset')
for c in comps:
c.included = True
c.fitted = True
# If the global kicad_dnp_applied variable is True try to copy the DNP flag from KiCad v7
c.fitted = not GS.global_kicad_dnp_applied or c.kicad_dnp is None or not c.kicad_dnp
c.fixed = False
c.back_up_fields()

View File

@ -256,6 +256,12 @@ class Globals(FiltersOptions):
This is needed for KiCad 7 in order to run the off grid check.
Shouldn't be needed in KiCad 8.
https://gitlab.com/kicad/code/kicad/-/issues/14110 """
self.kicad_dnp_applied = True
""" The KiCad v7 PCB flag *Do Not Populate* is applied to our fitted flag before running any filter """
self.kicad_dnp_applies_to_3D = True
""" The KiCad v7 PCB flag *Do Not Populate* is applied to our fitted flag for 3D models,
even when no filter/variant is specified. Disabling `kicad_dnp_applied` also disables
this flag """
self.set_doc('filters', " [list(dict)] KiBot warnings to be ignored ")
self._filter_what = 'KiBot warnings'
self.filters = FilterOptionsKiBot

View File

@ -167,6 +167,8 @@ class GS(object):
global_allow_blind_buried_vias = None
global_allow_microvias = None
global_erc_grid = None
global_kicad_dnp_applied = None
global_kicad_dnp_applies_to_3D = None
@staticmethod
def set_sch(name):

View File

@ -859,6 +859,7 @@ class SchematicComponent(object):
- footprint_w: width of the footprint (pads only).
- footprint_h: height of the footprint (pads only)
- qty: amount of this part used.
- kicad_dnp: is the KiCad v7 DNP flag. If not defined (v5/6) is None and is like False.
"""
ref_re = re.compile(r'([^\d]+)([\?\d]+)')
@ -890,12 +891,15 @@ class SchematicComponent(object):
self.virtual = False
self.tht = False
# KiCad 6 SCH flags
self.in_bom = True
self.on_board = True
self.in_bom = True # not Exclude from bill of materials
self.on_board = True # not Exclude from BoM
# KiCad 6 PCB flags
self.in_bom_pcb = True
self.in_pos = True
self.in_pcb_only = False
self.in_bom_pcb = True # not Exclude from bill of materials
self.in_pos = True # not Exclude from position files
self.in_pcb_only = False # Not in schematic
# KiCad 7 PCB flags
self.kicad_dnp = None # Do Not Populate
# Exclude from simulation is a field Sim.Enable
def get_field_value(self, field):
field = field.lower()

View File

@ -936,7 +936,6 @@ class SchematicComponentV6(SchematicComponent):
self.convert = None
self.pin_alternates = {}
# KiCad v7:
self.kicad_dnp = None
# Instances classified by project (v7)
self.projects = None
# All instances, by path (v7)

View File

@ -7,6 +7,7 @@ from fnmatch import fnmatch
import os
import requests
from .EasyEDA.easyeda_3d import download_easyeda_3d_model
from .fil_base import reset_filters
from .misc import W_MISS3D, W_FAILDL, W_DOWN3D, DISABLE_3D_MODEL_TEXT
from .gs import GS
from .optionable import Optionable
@ -195,10 +196,6 @@ class Base3DOptions(VariantOptions):
is_copy_mode = rename_filter is not None
rel_dirs = getattr(rename_data, 'rel_dirs', [])
extra_debug = GS.debug_level > 3
# Get a list of components in the schematic. Enables downloading LCSC parts.
if all_comps is None and GS.sch_file:
GS.load_sch()
all_comps = GS.sch.get_components()
if all_comps is None:
all_comps = []
all_comps_hash = {c.ref: c for c in all_comps}
@ -289,13 +286,29 @@ class Base3DOptions(VariantOptions):
def filter_components(self, highlight=None, force_wrl=False):
if not self._comps:
# No filters, but we need to apply some stuff
all_comps = None
dnp_removed = False
# Get a list of components in the schematic. Enables downloading LCSC parts.
if GS.sch_file:
GS.load_sch()
all_comps = GS.sch.get_components()
if (GS.global_kicad_dnp_applies_to_3D and
any(map(lambda c: c.kicad_dnp is not None and c.kicad_dnp, all_comps))):
# One or more components are DNP, remove them
reset_filters(all_comps)
all_comps_hash = {c.ref: c for c in all_comps}
self.remove_3D_models(GS.board, all_comps_hash)
dnp_removed = True
# No variant/filter to apply
if self.download_models(force_wrl=force_wrl):
if self.download_models(force_wrl=force_wrl, all_comps=all_comps) or dnp_removed:
# Some missing components found and we downloaded them
# Save the fixed board
ret = self.save_tmp_board()
# Undo the changes done during download
self.undo_3d_models_rename(GS.board)
if dnp_removed:
self.restore_3D_models(GS.board, all_comps_hash)
return ret
return GS.pcb_file
self.filter_pcb_components(do_3D=True, do_2D=True, highlight=highlight)