Added a simple output to generate filtered schematics.

They can display DNF components crossed!
This commit is contained in:
Salvador E. Tropea 2020-08-31 20:51:20 -03:00
parent 4cc8a0916f
commit 744aa3b9c5
3 changed files with 117 additions and 0 deletions

View File

@ -94,6 +94,7 @@ has_macro = [
'out_pdf_sch_print',
'out_position',
'out_ps',
'out_sch_variant',
'out_step',
'out_svg',
'out_svg_sch_print',

53
kibot/out_sch_variant.py Normal file
View File

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020 Salvador E. Tropea
# Copyright (c) 2020 Instituto Nacional de Tecnología Industrial
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
from .error import KiPlotConfigurationError
from .gs import GS
from .optionable import BaseOptions
from .registrable import RegOutput
from .macros import macros, document, output_class # noqa: F401
from . import log
logger = log.get_logger(__name__)
class Sch_Variant_Options(BaseOptions):
def __init__(self):
with document:
self.variant = ''
""" Board variant(s) to apply """
super().__init__()
def config(self):
super().config()
if self.variant:
if not RegOutput.is_variant(self.variant):
raise KiPlotConfigurationError("Unknown variant name `{}`".format(self.variant))
self.variant = RegOutput.get_variant(self.variant)
else:
self.variant = None
def run(self, output_dir, board):
if self.variant:
# Get the components list from the schematic
comps = GS.sch.get_components()
# Apply the variant
self.variant.filter(comps)
# Create the schematic
GS.sch.save_variant(output_dir)
@output_class
class Sch_Variant(BaseOutput): # noqa: F821
""" Schematic with variant generator
Creates a copy of the schematic with all the filters and variants applied.
This copy isn't intended for development.
Is just a tweaked version of the original where you can look at the results. """
def __init__(self):
super().__init__()
with document:
self.options = Sch_Variant_Options
""" [dict] Options for the `sch_variant` output """
self._sch_related = True

View File

@ -0,0 +1,63 @@
# Example KiBot config file
kibot:
version: 1
variants:
- name: 't1_v1'
comment: 'Test 1 Variant V1'
type: kibom
file_id: '_(V1)'
variant: V1
dnf_filter: '_kibom_dnf'
- name: 't1_v2'
comment: 'Test 1 Variant V2'
type: kibom
file_id: '_(V2)'
variant: V2
- name: 't1_v3'
comment: 'Test 1 Variant V3'
type: kibom
file_id: '_V3'
variant: V3
- name: 'bla bla'
comment: 'Test 1 Variant V1+V3'
type: kibom
file_id: '_bla_bla'
variant: ['V1', 'V3']
outputs:
- name: 'dummy'
comment: "Copy the Schematic"
type: sch_variant
dir: Copy
- name: 't1_v1'
comment: "V1 applied"
type: sch_variant
dir: V1
options:
variant: t1_v1
- name: 't1_v2'
comment: "V2 applied"
type: sch_variant
dir: V2
options:
variant: t1_v2
- name: 't1_v3'
comment: "V3 applied"
type: sch_variant
dir: V3
options:
variant: t1_v3
- name: 't1_v1v3'
comment: "V1+V3 applied"
type: sch_variant
dir: V1V3
options:
variant: 'bla bla'