New global section `environment`

- Allows defining KiCad environment variables.

Related to INTI-CMNB/KiAuto#21
This commit is contained in:
Salvador E. Tropea 2022-06-07 10:37:14 -03:00
parent a750bb302c
commit 0deed52479
3 changed files with 86 additions and 0 deletions

View File

@ -8,10 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- New outputs:
- `navigate_results` creates web pages to browse the generated outputs.
- New globals:
- `environment` section allows defining KiCad environment variables.
(See INTI-CMNB/KiAuto#21)
### Fixed
- Components with mounting hole where excluded (#201)
- GenCAD output targets.
- Problems expanding multiple KiCad variables in the same value.
### Changed
- KiCad environment variables: more variables detected, native KiCad 6 names,

View File

@ -605,6 +605,19 @@ global:
KiCad 6: you should set this in the Board Setup -> Board Finish -> Edge card connectors.
- `edge_plating`: [boolean=false] Has the PCB a plated board edge?
KiCad 6: you should set this in the Board Setup -> Board Finish -> Plated board edge.
- `environment`: [dict] Used to define environment variables used by KiCad.
The values defined here are exported as environment variables and has
more precedence than KiCad paths defined in the GUI.
You can make reference to any OS environment variable using ${VARIABLE}.
The KIPRJMOD is also available for expansion.
* Valid keys:
- `footprints`: [string=''] System level footprints (aka modules) dir. KiCad 5: KICAD_FOOTPRINT_DIR and KISYSMOD.
KiCad 6: KICAD6_FOOTPRINT_DIR.
- `models_3d`: [string=''] System level 3D models dir. KiCad 5: KISYS3DMOD. KiCad 6: KICAD6_3DMODEL_DIR.
- `symbols`: [string=''] System level symbols dir. KiCad 5: KICAD_SYMBOL_DIR. KiCad 6: KICAD6_SYMBOL_DIR.
- `templates`: [string=''] System level templates dir. KiCad 5: KICAD_TEMPLATE_DIR. KiCad 6: KICAD6_TEMPLATE_DIR.
- `third_party`: [string=''] 3rd party dir. KiCad 6: KICAD6_3RD_PARTY.
- `user_templates`: [string=''] User level templates dir. KiCad 5/6: KICAD_USER_TEMPLATE_DIR.
- `extra_pth_drill`: [number=0.1] How many millimeters the manufacturer will add to plated holes.
This is because the plating reduces the hole, so you need to use a bigger drill.
For more information consult: https://www.eurocircuits.com/pcb-design-guidelines/drilled-holes/.

View File

@ -5,6 +5,8 @@
# Project: KiBot (formerly KiPlot)
import os
from .gs import GS
from .optionable import Optionable
from .kicad.config import expand_env
from .macros import macros, document # noqa: F401
from .pre_filters import FiltersOptions
from .log import get_logger, set_filters
@ -13,6 +15,67 @@ from .kicad.sexpdata import load, SExpData, sexp_iter, Symbol
from .kicad.v6_sch import PCBLayer
class Environment(Optionable):
""" Used to define the KiCad environment vars """
def __init__(self):
super().__init__()
self._unkown_is_error = True
with document:
self.symbols = ''
""" System level symbols dir. KiCad 5: KICAD_SYMBOL_DIR. KiCad 6: KICAD6_SYMBOL_DIR """
self.footprints = ''
""" System level footprints (aka modules) dir. KiCad 5: KICAD_FOOTPRINT_DIR and KISYSMOD.
KiCad 6: KICAD6_FOOTPRINT_DIR """
self.models_3d = ''
""" System level 3D models dir. KiCad 5: KISYS3DMOD. KiCad 6: KICAD6_3DMODEL_DIR """
self.templates = ''
""" System level templates dir. KiCad 5: KICAD_TEMPLATE_DIR. KiCad 6: KICAD6_TEMPLATE_DIR """
self.user_templates = ''
""" User level templates dir. KiCad 5/6: KICAD_USER_TEMPLATE_DIR """
self.third_party = ''
""" 3rd party dir. KiCad 6: KICAD6_3RD_PARTY """
def config(self, parent):
super().config(parent)
defs = {}
if GS.ki5():
if self.symbols:
defs['KICAD_SYMBOL_DIR'] = self.symbols
if self.footprints:
defs['KICAD_FOOTPRINT_DIR'] = self.symbols
defs['KISYSMOD'] = self.symbols
if self.models_3d:
defs['KISYS3DMOD'] = self.models_3d
if self.templates:
defs['KICAD_TEMPLATE_DIR'] = self.templates
if self.user_templates:
defs['KICAD_USER_TEMPLATE_DIR'] = self.user_templates
else:
if self.symbols:
defs['KICAD6_SYMBOL_DIR'] = self.symbols
if self.footprints:
defs['KICAD6_FOOTPRINT_DIR'] = self.symbols
if self.models_3d:
defs['KICAD6_3DMODEL_DIR'] = self.models_3d
if self.templates:
defs['KICAD6_TEMPLATE_DIR'] = self.templates
if self.user_templates:
defs['KICAD_USER_TEMPLATE_DIR'] = self.user_templates
if self.third_party:
defs['KICAD6_3RD_PARTY'] = self.third_party
if len(defs):
logger.debug('Defining environment vars from the global section')
env = {}
if GS.pcb_file:
env['KIPRJMOD'] = os.path.dirname(GS.pcb_file)
elif GS.sch_file:
env['KIPRJMOD'] = os.path.dirname(GS.sch_file)
for n, v in defs.items():
v = expand_env(v, env, os.environ)
logger.debug('- {} = "{}"'.format(n, v))
os.environ[n] = v
class Globals(FiltersOptions):
""" Global options """
def __init__(self):
@ -97,6 +160,12 @@ class Globals(FiltersOptions):
""" Default variant to apply to all outputs """
self.out_dir = ''
""" Base output dir, same as command line `--out-dir` """
self.environment = Environment
""" [dict] Used to define environment variables used by KiCad.
The values defined here are exported as environment variables and has
more precedence than KiCad paths defined in the GUI.
You can make reference to any OS environment variable using ${VARIABLE}.
The KIPRJMOD is also available for expansion """
self.set_doc('filters', " [list(dict)] KiBot warnings to be ignored ")
self._filter_what = 'KiBot warnings'
self._unkown_is_error = True